11// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
22//
3- // Matrix.h: Rcpp R/C++ interface class library -- Matrix meat
3+ // Matrix.h: Rcpp R/C++ interface class library -- Matrix meat
44//
55// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
66//
2222#ifndef Rcpp_api_meat_Matrix_h
2323#define Rcpp_api_meat_Matrix_h
2424
25- namespace Rcpp {
25+ namespace Rcpp {
2626
2727 template <int RTYPE, template <class > class StoragePolicy >
2828 Matrix<RTYPE, StoragePolicy>::Matrix(SEXP x) : VECTOR( r_cast<RTYPE>( x ) ), nrows( VECTOR::dims()[0 ] ) {}
29-
29+
3030 template <int RTYPE, template <class > class StoragePolicy >
3131 Matrix<RTYPE,StoragePolicy>::Matrix( const Dimension& dims) : VECTOR( Rf_allocMatrix( RTYPE, dims[0 ], dims[1 ] ) ), nrows(dims[0 ]) {
3232 if ( dims.size () != 2 ) throw not_compatible (" not a matrix" ) ;
3333 VECTOR::init () ;
3434 }
35-
35+
3636 template <int RTYPE, template <class > class StoragePolicy >
37- Matrix<RTYPE,StoragePolicy>::Matrix( const int & nrows_, const int & ncols) :
38- VECTOR ( Dimension( nrows_, ncols ) ),
37+ Matrix<RTYPE,StoragePolicy>::Matrix( const int & nrows_, const int & ncols) :
38+ VECTOR ( Dimension( nrows_, ncols ) ),
3939 nrows(nrows_)
4040 {}
41-
41+
4242 template <int RTYPE, template <class > class StoragePolicy >
4343 template <typename Iterator>
44- Matrix<RTYPE,StoragePolicy>::Matrix( const int & nrows_, const int & ncols, Iterator start ) :
44+ Matrix<RTYPE,StoragePolicy>::Matrix( const int & nrows_, const int & ncols, Iterator start ) :
4545 VECTOR ( start, start + (nrows_*ncols) ),
4646 nrows(nrows_)
4747 {
48- VECTOR::attr ( " dim" ) = Dimension ( nrows, ncols ) ;
48+ VECTOR::attr ( " dim" ) = Dimension ( nrows, ncols ) ;
4949 }
50-
50+
5151 template <int RTYPE, template <class > class StoragePolicy >
5252 Matrix<RTYPE,StoragePolicy>::Matrix( const int & n) : VECTOR( Dimension( n, n ) ), nrows(n) {}
53-
53+
5454 template <int RTYPE, template <class > class StoragePolicy >
5555 Matrix<RTYPE,StoragePolicy>::Matrix( const Matrix& other) : VECTOR( other.get__() ), nrows(other.nrows) {}
56-
56+
5757 template <int RTYPE, template <class > class StoragePolicy >
5858 template <bool NA, typename MAT>
5959 Matrix<RTYPE,StoragePolicy>::Matrix( const MatrixBase<RTYPE,NA,MAT>& other ) : VECTOR( Rf_allocMatrix( RTYPE, other.nrow(), other.ncol() ) ), nrows(other.nrow()) {
6060 import_matrix_expression<NA,MAT>( other, nrows, ncol () ) ;
6161 }
62-
62+
6363 template <int RTYPE, template <class > class StoragePolicy >
6464 Matrix<RTYPE, StoragePolicy>& Matrix<RTYPE,StoragePolicy>::operator =(const Matrix& other) {
6565 SEXP x = other.get__ () ;
@@ -68,56 +68,56 @@ namespace Rcpp{
6868 nrows = other.nrows ;
6969 return *this ;
7070 }
71-
71+
7272 template <int RTYPE, template <class > class StoragePolicy >
7373 template <typename U>
7474 void Matrix<RTYPE,StoragePolicy>::fill_diag( const U& u){
75- fill_diag__dispatch ( typename traits::is_trivial<RTYPE>::type (), u ) ;
75+ fill_diag__dispatch ( typename traits::is_trivial<RTYPE>::type (), u ) ;
7676 }
77-
77+
7878 template <int RTYPE, template <class > class StoragePolicy >
7979 template <typename U>
8080 Matrix<RTYPE,StoragePolicy> Matrix<RTYPE,StoragePolicy>::diag( int size, const U& diag_value ){
8181 Matrix res (size,size) ;
8282 res.fill_diag ( diag_value ) ;
8383 return res ;
8484 }
85-
85+
8686 template <int RTYPE, template <class > class StoragePolicy >
8787 inline typename Matrix<RTYPE,StoragePolicy>::Proxy Matrix<RTYPE,StoragePolicy>::operator []( int i ){
8888 return static_cast < Vector<RTYPE>* >( this )->operator []( i ) ;
8989 }
90-
90+
9191 template <int RTYPE, template <class > class StoragePolicy >
9292 inline typename Matrix<RTYPE,StoragePolicy>::const_Proxy Matrix<RTYPE,StoragePolicy>::operator []( int i ) const {
9393 return static_cast < const Vector<RTYPE>* >( this )->operator []( i ) ;
9494 }
95-
95+
9696 template <int RTYPE, template <class > class StoragePolicy >
9797 inline typename Matrix<RTYPE,StoragePolicy>::Proxy Matrix<RTYPE,StoragePolicy>::operator ()( const size_t & i, const size_t & j) {
9898 return static_cast < Vector<RTYPE>* >( this )->operator []( offset ( i, j ) ) ;
9999 }
100-
100+
101101 template <int RTYPE, template <class > class StoragePolicy >
102102 inline typename Matrix<RTYPE,StoragePolicy>::const_Proxy Matrix<RTYPE,StoragePolicy>::operator ()( const size_t & i, const size_t & j) const {
103103 return static_cast < const Vector<RTYPE>* >( this )->operator []( offset ( i, j ) ) ;
104104 }
105-
105+
106106 template <int RTYPE, template <class > class StoragePolicy >
107107 inline typename Matrix<RTYPE,StoragePolicy>::Row Matrix<RTYPE,StoragePolicy>::operator ()( int i, internal::NamedPlaceHolder ){
108108 return Row ( *this , i ) ;
109109 }
110-
110+
111111 template <int RTYPE, template <class > class StoragePolicy >
112112 inline typename Matrix<RTYPE,StoragePolicy>::Column Matrix<RTYPE,StoragePolicy>::operator ()( internal::NamedPlaceHolder, int i ){
113113 return Column ( *this , i ) ;
114114 }
115-
115+
116116 template <int RTYPE, template <class > class StoragePolicy >
117117 inline typename Matrix<RTYPE,StoragePolicy>::Column Matrix<RTYPE,StoragePolicy>::operator ()( internal::NamedPlaceHolder, int i ) const {
118118 return Column ( *this , i ) ;
119119 }
120-
120+
121121 template <int RTYPE, template <class > class StoragePolicy >
122122 inline typename Matrix<RTYPE,StoragePolicy>::Sub Matrix<RTYPE,StoragePolicy>::operator ()( const Range& row_range, const Range& col_range){
123123 return Sub ( const_cast <Matrix&>(*this ), row_range, col_range ) ;
@@ -126,12 +126,12 @@ namespace Rcpp{
126126 inline typename Matrix<RTYPE,StoragePolicy>::Sub Matrix<RTYPE,StoragePolicy>::operator ()( internal::NamedPlaceHolder, const Range& col_range){
127127 return Sub ( const_cast <Matrix&>(*this ), Range (0 ,nrow ()-1 ) , col_range ) ;
128128 }
129-
129+
130130 template <int RTYPE, template <class > class StoragePolicy >
131131 inline typename Matrix<RTYPE,StoragePolicy>::Sub Matrix<RTYPE,StoragePolicy>::operator ()( const Range& row_range, internal::NamedPlaceHolder ){
132132 return Sub ( const_cast <Matrix&>(*this ), row_range, Range (0 ,ncol ()-1 ) ) ;
133133 }
134-
134+
135135 template <int RTYPE, template <class > class StoragePolicy >
136136 template <typename U>
137137 void Matrix<RTYPE,StoragePolicy>::fill_diag__dispatch( traits::false_type, const U& u){
@@ -141,10 +141,10 @@ namespace Rcpp{
141141 iterator it ( VECTOR::begin ()) ;
142142 for ( int i=0 ; i<n; i++){
143143 *it = ::Rf_duplicate ( elem );
144- it += offset;
144+ it += offset;
145145 }
146146 }
147-
147+
148148 template <int RTYPE, template <class > class StoragePolicy >
149149 template <typename U>
150150 void Matrix<RTYPE,StoragePolicy>::fill_diag__dispatch( traits::true_type, const U& u){
@@ -154,7 +154,7 @@ namespace Rcpp{
154154 iterator it ( VECTOR::begin ()) ;
155155 for ( int i=0 ; i<n; i++){
156156 *it = elem ;
157- it += offset;
157+ it += offset;
158158 }
159159 }
160160
@@ -168,7 +168,7 @@ namespace Rcpp{
168168 }
169169 }
170170 }
171-
171+
172172} // namespace Rcpp
173173
174174#endif
0 commit comments