Skip to content

Commit e862fbf

Browse files
authored
Merge pull request #18 from dcdillon/feature/matrices
First pass at matrix stuff!
2 parents 0f9c9c2 + 4b38d5a commit e862fbf

29 files changed

+464
-165
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ before_install:
1212
- ./run.sh bootstrap
1313

1414
install:
15-
- ./run.sh install_aptget r-cran-rcpp r-cran-runit r-cran-knitr r-cran-rmarkdown
15+
- ./run.sh install_r Rcpp
16+
- ./run.sh install_aptget r-cran-runit r-cran-knitr r-cran-rmarkdown
1617

1718
script:
1819
- ./run.sh run_tests

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Description: Creates an easy way to use expression templates with R
1212
License: GPL (>= 2)
1313
LazyData: TRUE
1414
Imports:
15-
Rcpp (>= 0.12.5)
15+
Rcpp (>= 0.12.8)
1616
Suggests:
1717
RUnit,
1818
knitr,

R/plugin.R

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1-
inlineCxxPlugin <- Rcpp:::Rcpp.plugin.maker(libs =
2-
if (Sys.info()[['sysname']] != "SunOS") "-Wl,-S" else "")
1+
.getLibs <- function() {
2+
linker_pattern <- "gcc|clang|g\\+\\+"
3+
4+
shlib_ld <- system("R CMD config SHLIB_LD", intern=TRUE)
5+
shlib_cxxld <- system("R CMD config SHLIB_CXXLD", intern=TRUE)
6+
7+
shlib_ld_results <- system(paste0(shlib_ld, " --version"), intern=TRUE)
8+
shlib_cxxld_results <- system(paste0(shlib_cxxld, " --version"), intern=TRUE)
9+
10+
shlib_ld_good <- any(grepl(linker_pattern, shlib_ld_results))
11+
shlib_cxxld_good <- any(grepl(linker_pattern, shlib_cxxld_results))
12+
13+
libs <- if (shlib_ld_good && shlib_cxxld_good) "-Wl,-S" else ""
14+
15+
libs
16+
}
17+
18+
inlineCxxPlugin <- Rcpp:::Rcpp.plugin.maker(libs = .getLibs())

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
The goal is to provide full featured interoperability between any iterator based structures and `R` to reduce development time and simplify code.
88

9-
`RcppHoney` is in alpha state (so the API is still subject to change, but is way more stable than it was a week ago).
9+
`RcppHoney` is now in a beta state so the API should no longer be changing.
1010

1111
### Example
1212

@@ -60,7 +60,7 @@ namespace RcppHoney {
6060
namespace functors {
6161

6262
template< typename Iterator, bool NA >
63-
struct my_unary_functor {
63+
struct my_unary_functor : public unary_result_dims {
6464
typedef typename std::iterator_traits< Iterator >::value_type rhs_value_type;
6565
// since we're just adding a double to the input value the return type should be
6666
// the widest numeric type of rhs and double
@@ -79,7 +79,7 @@ struct my_unary_functor {
7979
};
8080

8181
template< typename LhsIterator, typename RhsIterator, bool NA = true >
82-
struct my_binary_functor {
82+
struct my_binary_functor : binary_result_dims {
8383
typedef typename std::iterator_traits< LhsIterator >::value_type lhs_value_type;
8484
typedef typename std::iterator_traits< RhsIterator >::value_type rhs_value_type;
8585

@@ -148,16 +148,22 @@ Rcpp::NumericVector rcpphoney_example() {
148148
149149
### Installation
150150
151-
RcppHoney is still in alpha state, and it is recommended you install from source
152-
as changes will be frequent.
151+
RcppHoney is now a in beta state!
153152
154-
RcppHoney is also available via the [CRAN](http://cran.r-project.org) network,
153+
RcppHoney is available via the [CRAN](http://cran.r-project.org) network,
155154
and can be installed from within R via
156155
157156
```R
158157
install.packages("RcppHoney")
159158
```
160159

160+
RcppHoney can also be installed from the github sources by running
161+
162+
```
163+
git clone [email protected]:dcdillon/RcppHoney
164+
R CMD INSTALL RcppHoney
165+
```
166+
161167
### Authors
162168

163169
Daniel C. Dillon

configure

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
MYOS=`uname -s`
2-
3-
echo $MYOS
4-
5-
if [ "$(echo "$MYOS" | cut -c1-5)" = "SunOS" ]; then
6-
cp src/platform/Makevars.solaris src/Makevars
7-
else
8-
cp src/platform/Makevars.gcc src/Makevars
9-
fi
1+
./inst/tools/stripper

inst/include/RcppHoney.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "RcppHoneyForward.hpp"
2121
#include <Rcpp.h>
22-
#include "RcppHoney/wrap.hpp"
2322
#include "RcppHoney/operators.hpp"
2423
#include "RcppHoney/functions.hpp"
2524
#include "RcppHoney/storage.hpp"

inst/include/RcppHoney/binary_operator.hpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#pragma once
1919

20-
#include <Rcpp.h>
2120
#include <iterator>
2221
#include <algorithm>
2322
#include <cstddef>
@@ -107,24 +106,23 @@ class binary_operator : public operand< binary_operator< LhsIterator, RhsIterato
107106
LhsIterator m_lhsEnd;
108107
RhsIterator m_rhsBegin;
109108
RhsIterator m_rhsEnd;
110-
std::size_t m_length;
109+
dims_t m_dims;
111110
Op m_operator;
112111

113112
public:
114-
binary_operator(LhsIterator lhsBegin, LhsIterator lhsEnd, int64_t lhsSize,
115-
RhsIterator rhsBegin, RhsIterator rhsEnd, int64_t rhsSize, const Op &op) :
113+
binary_operator(LhsIterator lhsBegin, LhsIterator lhsEnd, dims_t lhsDims,
114+
RhsIterator rhsBegin, RhsIterator rhsEnd, dims_t rhsDims, const Op &op) :
116115
m_lhsBegin(lhsBegin), m_lhsEnd(lhsEnd), m_rhsBegin(rhsBegin),
117-
m_rhsEnd(rhsEnd), m_length(std::max(lhsSize, rhsSize)),
118-
m_operator(op) {
116+
m_rhsEnd(rhsEnd), m_operator(op) {
119117

120-
if (lhsSize != rhsSize && lhsSize != -1 && rhsSize != -1) {
121-
std::cout << lhsSize << ", " << rhsSize << std::endl;
122-
throw bounds_exception();
123-
}
118+
m_dims = m_operator.result_dims(lhsDims, rhsDims);
124119
}
125120

126-
int64_t length() const {return m_length;}
127-
int64_t size() const {return m_length;}
121+
dims_t dims() const {return m_dims;}
122+
int64_t size() const {
123+
return (m_dims.second != 0) ? m_dims.first * m_dims.second
124+
: m_dims.first;
125+
}
128126
const_iterator begin() const {return const_iterator(m_lhsBegin, m_rhsBegin, &m_operator);}
129127
const_iterator end() const {return const_iterator(m_lhsEnd, m_rhsEnd, &m_operator);}
130128
};
@@ -136,8 +134,8 @@ struct make_binary_operator
136134
binary_operator< typename LHS::const_iterator, typename RHS::const_iterator, Op, NA > operator()(const LHS &lhs, const RHS &rhs, const Op &op) {
137135

138136
return binary_operator< typename LHS::const_iterator, typename RHS::const_iterator, Op, NA >(
139-
lhs.begin(), lhs.end(), hooks::extract_size(lhs),
140-
rhs.begin(), rhs.end(), hooks::extract_size(rhs),
137+
lhs.begin(), lhs.end(), hooks::extract_dims(lhs),
138+
rhs.begin(), rhs.end(), hooks::extract_dims(rhs),
141139
op);
142140
}
143141
};

inst/include/RcppHoney/default_hooks.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,43 @@ RcppHoney::traits::true_type needs_scalar_operators(const Rcpp::VectorBase< RTYP
5151
template< int RTYPE, bool NA, typename T >
5252
RcppHoney::traits::int_constant< 2 > family(const Rcpp::VectorBase< RTYPE, NA, T > &val);
5353

54+
55+
56+
57+
58+
59+
60+
// hooks for Rcpp::VectorBase
61+
template< int RTYPE, template< class > class StoragePolicy >
62+
RcppHoney::traits::true_type is_hooked(const Rcpp::Matrix< RTYPE, StoragePolicy > &val);
63+
64+
// return the appropriate NA value
65+
template< int RTYPE, template< class > class StoragePolicy >
66+
RcppHoney::traits::true_type has_na(const Rcpp::Matrix< RTYPE, StoragePolicy > &val);
67+
68+
// assert that we need to create basic operators
69+
template< int RTYPE, template< class > class StoragePolicy >
70+
RcppHoney::traits::true_type needs_basic_operators(const Rcpp::Matrix< RTYPE, StoragePolicy > &val);
71+
72+
// assert that we need to create type + scalar operators
73+
template< int RTYPE, template< class > class StoragePolicy >
74+
RcppHoney::traits::true_type needs_scalar_operators(const Rcpp::Matrix< RTYPE, StoragePolicy > &val);
75+
76+
// call this family 3
77+
template< int RTYPE, template< class > class StoragePolicy >
78+
RcppHoney::traits::int_constant< 3 > family(const Rcpp::Matrix< RTYPE, StoragePolicy > &val);
79+
80+
template< int RTYPE, template< class > class StoragePolicy >
81+
dims_t extract_dims(
82+
const Rcpp::Matrix< RTYPE, StoragePolicy > &obj)
83+
{
84+
return dims_t(obj.nrow(), obj.ncol());
85+
}
86+
87+
template< typename T, typename T_ITER, typename T_RESULT >
88+
dims_t extract_dims(const operand< T, T_ITER, T_RESULT > &obj) {
89+
return obj.dims();
90+
}
91+
5492
} // namespace hooks
5593
} // namespace RcppHoney

inst/include/RcppHoney/functions.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#pragma once
1919

20-
#include <Rcpp.h>
2120
#include "operand.hpp"
2221
#include "scalar_operator.hpp"
2322
#include "unary_operator.hpp"
@@ -264,10 +263,15 @@ RCPP_HONEY_GENERATE_BINARY_FUNCTION(signif, signif)
264263
template< typename T, typename T_ITER, typename T_RESULT >
265264
unary_operator< T_ITER, functors::diff< T_ITER, T::NA >, T::NA >
266265
diff(const operand< T, T_ITER, T_RESULT > &rhs) {
266+
267+
if (rhs.dims().second != 0) {
268+
throw bounds_exception();
269+
}
270+
267271
T_ITER begin = rhs.begin();
268272
++begin;
269273
return unary_operator< T_ITER, functors::diff< T_ITER, T::NA >, T::NA >(
270-
begin, rhs.end(), hooks::extract_size(rhs) - 1, functors::diff< T_ITER, T::NA >());
274+
begin, rhs.end(), rhs.dims(), functors::diff< T_ITER, T::NA >());
271275
}
272276

273277
template< typename T >
@@ -280,14 +284,20 @@ typename traits::enable_if<
280284
>
281285
>::type
282286
diff(const T &rhs) {
287+
dims_t dims = hooks::extract_dims(rhs);
288+
289+
if (dims.second != 0) {
290+
throw bounds_exception();
291+
}
292+
283293
typename hook< T >::const_iterator begin = rhs.begin();
284294
++begin;
285295

286296
return unary_operator<
287297
typename hook< T >::const_iterator,
288298
functors::diff< typename hook< T >::const_iterator, hook< T >::NA >,
289299
hook< T >::NA
290-
>(begin, rhs.end(), hooks::extract_size(rhs) - 1,
300+
>(begin, rhs.end(), dims,
291301
functors::diff< typename hook< T >::const_iterator, hook< T >::NA >());
292302
}
293303

0 commit comments

Comments
 (0)