22#ifndef Rcpp__vector__Matrix_h
23#define Rcpp__vector__Matrix_h
27template <
int RTYPE,
template <
class>
class StoragePolicy = PreserveStorage >
63 template <
typename Iterator>
76 template <
bool NA,
typename MAT>
119 template <
typename U>
144 inline Proxy at(
const size_t& i,
const size_t& j) {
152 return Row( *
this, i ) ;
158 return Column( *
this, i ) ;
176 template <
typename U>
182 (*this)(i, i) =
elem;
186 template <
typename U>
193 (*this)(i, i) =
elem;
197 template <
bool NA,
typename MAT>
200 for(
int j=0; j<nc; j++){
201 for(
int i=0; i<nr; i++, ++start){
202 *start =
other(i,j) ;
217template<
template <
class>
class StoragePolicy >
221 std::ios::fmtflags
flags =
s.flags();
222 s.unsetf(std::ios::floatfield);
225 const int rows = rhs.
rows();
227 for (
int i = 0; i < rows; ++i) {
228 typename MATRIX::Row
row =
const_cast<MATRIX &
>(rhs).
row(i);
230 typename MATRIX::Row::iterator j =
row.begin();
231 typename MATRIX::Row::iterator
jend =
row.end();
234 s << std::showpoint << std::setw(
precision + 1) << (*j);
237 for ( ; j !=
jend; j++) {
238 s <<
" " << std::showpoint << std::setw(
precision + 1) << (*j);
250#define RCPP_GENERATE_MATRIX_SCALAR_OPERATOR(__OPERATOR__) \
251 template <int RTYPE, template <class> class StoragePolicy, typename T > \
252 inline typename traits::enable_if< traits::is_convertible< typename traits::remove_const_and_reference< T >::type, \
253 typename Matrix<RTYPE, StoragePolicy>::stored_type >::value, Matrix<RTYPE, StoragePolicy> >::type \
254 operator __OPERATOR__ (const Matrix<RTYPE, StoragePolicy> &lhs, const T &rhs) { \
255 Vector<RTYPE, StoragePolicy> v = static_cast<const Vector<RTYPE, StoragePolicy> &>(lhs) __OPERATOR__ rhs; \
256 v.attr("dim") = Vector<INTSXP>::create(lhs.nrow(), lhs.ncol()); \
257 return as< Matrix<RTYPE, StoragePolicy> >(v); \
265#undef RCPP_GENERATE_MATRIX_SCALAR_OPERATOR
267#define RCPP_GENERATE_SCALAR_MATRIX_OPERATOR(__OPERATOR__) \
268 template <int RTYPE, template <class> class StoragePolicy, typename T > \
269 inline typename traits::enable_if< traits::is_convertible< typename traits::remove_const_and_reference< T >::type, \
270 typename Matrix<RTYPE, StoragePolicy>::stored_type >::value, Matrix<RTYPE, StoragePolicy> >::type \
271 operator __OPERATOR__ (const T &lhs, const Matrix<RTYPE, StoragePolicy> &rhs) { \
272 Vector<RTYPE, StoragePolicy> v = lhs __OPERATOR__ static_cast<const Vector<RTYPE, StoragePolicy> &>(rhs); \
273 v.attr("dim") = Vector<INTSXP>::create(rhs.nrow(), rhs.ncol()); \
274 return as< Matrix<RTYPE, StoragePolicy> >(v); \
282#undef RCPP_GENERATE_SCALAR_MATRIX_OPERATOR
285template<
template <
class>
class StoragePolicy >
290 std::ios::fmtflags
flags =
s.flags();
294 int min = std::numeric_limits<int>::max();
295 int max = std::numeric_limits<int>::min();
297 typename VECTOR::iterator j =
static_cast<VECTOR &
>(
const_cast<MATRIX &
>(rhs)).begin();
298 typename VECTOR::iterator
jend =
static_cast<VECTOR &
>(
const_cast<MATRIX &
>(rhs)).end();
300 for ( ; j !=
jend; ++j) {
327 const int rows = rhs.
rows();
329 for (
int i = 0; i < rows; ++i) {
330 typename MATRIX::Row
row =
const_cast<MATRIX &
>(rhs).
row(i);
332 typename MATRIX::Row::iterator j =
row.begin();
333 typename MATRIX::Row::iterator
jend =
row.end();
336 s << std::setw(
digits) << (*j);
339 for ( ; j !=
jend; ++j) {
340 s <<
" " << std::setw(
digits) << (*j);
351template<
template <
class>
class StoragePolicy >
355 const int rows = rhs.
rows();
357 for (
int i = 0; i < rows; ++i) {
358 typename MATRIX::Row
row =
const_cast<MATRIX &
>(rhs).
row(i);
360 typename MATRIX::Row::iterator j =
row.begin();
361 typename MATRIX::Row::iterator
jend =
row.end();
364 s <<
"\"" << (*j) <<
"\"";
367 for ( ; j !=
jend; j++) {
368 s <<
" \"" << (*j) <<
"\"";
378template<
int RTYPE,
template <
class>
class StoragePolicy >
382 const int rows = rhs.
rows();
384 for (
int i = 0; i < rows; ++i) {
385 typename MATRIX::Row
row =
const_cast<MATRIX &
>(rhs).
row(i);
387 typename MATRIX::Row::iterator j =
row.begin();
388 typename MATRIX::Row::iterator
jend =
row.end();
394 for ( ; j !=
jend; j++) {
405template<
int RTYPE,
template <
class>
class StoragePolicy >
411 int nrow = dims[0], ncol = dims[1];
416 VECTOR
s = VECTOR(
r.get__());
417 for (
R_xlen_t i = 0, j = 0; i < len; i++, j += nrow) {
434template<
template <
class>
class StoragePolicy>
439template<
template <
class>
class StoragePolicy>
444template<
template <
class>
class StoragePolicy>
#define RCPP_GENERATE_MATRIX_SCALAR_OPERATOR(__OPERATOR__)
#define RCPP_GENERATE_SCALAR_MATRIX_OPERATOR(__OPERATOR__)
AttributeProxy attr(const std::string &name)
Sub operator()(const Range &row_range, internal::NamedPlaceHolder)
Proxy operator()(const size_t &i, const size_t &j)
ConstRow operator()(int i, internal::NamedPlaceHolder) const
ConstMatrixRow< RTYPE > ConstRow
ConstColumn operator()(internal::NamedPlaceHolder, int i) const
static Matrix diag(int size, const U &diag_value)
VECTOR::const_iterator const_iterator
ConstColumn column(int i) const
void import_matrix_expression(const MatrixBase< RTYPE, NA, MAT > &other, int nr, int nc)
Column operator()(internal::NamedPlaceHolder, int i)
ConstMatrixColumn< RTYPE > ConstColumn
Vector< RTYPE, StoragePolicy > VECTOR
const_Proxy at(const size_t &i, const size_t &j) const
MatrixColumn< RTYPE > Column
const_iterator begin() const
Row operator()(int i, internal::NamedPlaceHolder)
const_iterator cend() const
Proxy at(const size_t &i, const size_t &j)
Matrix & operator=(const Matrix &other)
void fill_diag__dispatch(traits::false_type, const U &u)
const_Proxy operator()(const size_t &i, const size_t &j) const
Matrix(const Dimension &dims)
const_Proxy operator[](R_xlen_t i) const
Matrix(const int &nrows_, const int &ncols, Iterator start)
void fill_diag__dispatch(traits::true_type, const U &u)
Sub operator()(internal::NamedPlaceHolder, const Range &col_range)
Sub operator()(const Range &row_range, const Range &col_range)
Matrix(const no_init_matrix &obj)
StoragePolicy< Matrix > Storage
const_iterator cbegin() const
VECTOR::converter_type converter_type
Matrix(const Matrix &other)
VECTOR::stored_type stored_type
Matrix(const MatrixBase< RTYPE, NA, MAT > &other)
ConstRow row(int i) const
VECTOR::const_Proxy const_Proxy
Matrix(const int &nrows_, const int &ncols)
void fill_diag(const U &u)
const_iterator end() const
R_xlen_t offset(const int i, const int j) const
VECTOR::iterator iterator
Proxy operator[](R_xlen_t i)
traits::storage_type< RTYPE >::type stored_type
traits::r_vector_const_iterator< RTYPE, StoragePolicy >::type const_iterator
traits::r_vector_iterator< RTYPE, StoragePolicy >::type iterator
traits::r_vector_const_proxy< RTYPE, StoragePolicy >::type const_Proxy
traits::r_vector_proxy< RTYPE, StoragePolicy >::type Proxy
static target get(const T &input)
std::ostream & operator<<(std::ostream &os, const Date d)
sugar::Min< RTYPE, NA, T > min(const VectorBase< RTYPE, NA, T > &x)
Matrix< REALSXP, StoragePolicy > transpose(const Matrix< REALSXP, StoragePolicy > &x)
internal::DimNameProxy rownames(SEXP x)
sugar::Max< RTYPE, NA, T > max(const VectorBase< RTYPE, NA, T > &x)
sugar::Row< RTYPE, LHS_NA, LHS_T > row(const Rcpp::MatrixBase< RTYPE, LHS_NA, LHS_T > &lhs)
internal::DimNameProxy colnames(SEXP x)
Matrix< RTYPE, StoragePolicy > tranpose_impl(const Matrix< RTYPE, StoragePolicy > &x)