cheshirekow  v0.1.0
LValue.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_CUDA_LINALG_LVALUE_H_
28 #define MPBLOCKS_CUDA_LINALG_LVALUE_H_
29 
30 namespace mpblocks {
31 namespace cuda {
32 namespace linalg {
33 
35 template <typename Scalar, class Mat>
36 class LValue
37 {
38  public:
40 
41  typedef unsigned int Size_t;
42 
45  Size_t size() const
46  {
47  return static_cast<Mat const&>(*this).size();
48  }
49 
52  Size_t rows() const
53  {
54  return static_cast<Mat const&>(*this).rows();
55  }
56 
59  Size_t cols() const
60  {
61  return static_cast<Mat const&>(*this).cols();
62  }
63 
66  Scalar& operator[]( Size_t i )
67  {
68  return static_cast<Mat&>(*this)[i];
69  }
70 
73  Scalar const& operator[]( Size_t i )const
74  {
75  return static_cast<Mat const&>(*this)[i];
76  }
77 
80  Scalar& operator()( Size_t i, Size_t j )
81  {
82  return static_cast<Mat&>(*this)(i,j);
83  }
84 
87  Scalar const& operator()( Size_t i, Size_t j )const
88  {
89  return static_cast<Mat const&>(*this)(i,j);
90  }
91 
94  Stream_t operator<<( Scalar x )
95  {
96  Stream_t stream(*this);
97  return stream << x;
98  }
99 
100  template <class Exp2>
103  {
104 // assert( rows() == B.rows() );
105 // assert( cols() == B.cols() );
106 
107  for( int i=0; i < rows(); i++)
108  for(int j=0; j < cols(); j++)
109  (*this)(i,j) = B(i,j);
110  return *this;
111  }
112 
113  template <class Exp2>
116  {
117 // assert( rows() == B.rows() );
118 // assert( cols() == B.cols() );
119 
120  for( int i=0; i < rows(); i++)
121  for(int j=0; j < cols(); j++)
122  (*this)(i,j) += B(i,j);
123  return *this;
124  }
125 
126  template <class Exp2>
129  {
130 // assert( rows() == B.rows() );
131 // assert( cols() == B.cols() );
132 
133  for( int i=0; i < rows(); i++)
134  for(int j=0; j < cols(); j++)
135  (*this)(i,j) -= B(i,j);
136  return *this;
137  }
138 
141  {
142  return RValue<Scalar, LValue<Scalar,Mat> >(*this);
143  }
144 
145 };
146 
147 
148 
149 
150 
151 
152 } // linalg
153 } // cuda
154 } // mpblocks
155 
156 
157 
158 
159 
160 #endif // MATRIXEXPRESSION_H_
__device__ __host__ Size_t cols() const
return the columns of a matrix expression
Definition: LValue.h:59
__device__ __host__ LValue< Scalar, Mat > & operator=(RValue< Scalar, Exp2 > const &B)
Definition: LValue.h:102
__device__ __host__ Scalar & operator()(Size_t i, Size_t j)
return the evaluated (i,j)'th element of a matrix expression
Definition: LValue.h:80
__device__ __host__ Scalar const & operator[](Size_t i) const
return the evaluated i'th element of a vector expression
Definition: LValue.h:73
StreamAssignment< LValue< Scalar, Mat > > Stream_t
Definition: LValue.h:39
__device__ __host__ Size_t size() const
return the size for a vector
Definition: LValue.h:45
__device__ __host__ LValue< Scalar, Mat > & operator-=(RValue< Scalar, Exp2 > const &B)
Definition: LValue.h:128
__device__ __host__ Stream_t operator<<(Scalar x)
returns a stream for assignment
Definition: LValue.h:94
expression template for rvalues
Definition: LValue.h:36
#define __device__
Definition: fakecuda.h:34
#define __host__
Definition: fakecuda.h:37
__device__ __host__ LValue< Scalar, Mat > & operator+=(RValue< Scalar, Exp2 > const &B)
Definition: LValue.h:115
__device__ __host__ Scalar & operator[](Size_t i)
return the evaluated i'th element of a vector expression
Definition: LValue.h:66
expression template for rvalues
Definition: RValue.h:41
__device__ __host__ Size_t rows() const
return the rows of a matrix expression
Definition: LValue.h:52
__device__ __host__ Scalar const & operator()(Size_t i, Size_t j) const
return the evaluated (i,j)'th element of a matrix expression
Definition: LValue.h:87