cheshirekow  v0.1.0
Difference.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_LINALG2_DIFFERENCE_H_
28 #define MPBLOCKS_CUDA_LINALG2_DIFFERENCE_H_
29 
30 namespace mpblocks {
31 namespace cuda {
32 namespace linalg2 {
33 
35 template <typename Scalar, Size_t ROWS, Size_t COLS, class Exp1, class Exp2>
36 class Difference:
37  public RValue< Scalar, ROWS, COLS, Difference< Scalar, ROWS, COLS, Exp1, Exp2> >
38 {
39  Exp1 const& m_A;
40  Exp2 const& m_B;
41 
42  public:
44  Difference( Exp1 const& A, Exp2 const& B ):
45  m_A(A),
46  m_B(B)
47  {}
48 
50  template< Size_t i >
52  Scalar ve() const
53  {
54  return m_A.Exp1::template ve<i>()
55  - m_B.Exp2::template ve<i>();
56  }
57 
59  template< Size_t i, Size_t j >
61  Scalar me() const
62  {
63  return m_A.Exp1::template me<i,j>()
64  - m_B.Exp2::template me<i,j>();
65  }
66 };
67 
68 
69 
70 
71 template <typename Scalar, Size_t ROWS, Size_t COLS, class Exp1, class Exp2>
72 __device__ __host__ inline
73 Difference< Scalar, ROWS, COLS, Exp1, Exp2 >
76 {
78  static_cast< Exp1 const& >(A),
79  static_cast< Exp2 const& >(B) );
80 }
81 
82 
83 
84 
85 
86 } // linalg
87 } // cuda
88 } // mpblocks
89 
90 
91 
92 
93 
94 #endif // DIFFERENCE_H_
__device__ __host__ Difference(Exp1 const &A, Exp2 const &B)
Definition: Difference.h:44
expression template for rvalues
Definition: RValue.h:36
__device__ __host__ Scalar me() const
return the evaluated (j,i)'th element of a matrix expression
Definition: Difference.h:61
__device__ __host__ Scalar ve() const
return the evaluated i'th element of a vector expression
Definition: Difference.h:52
__device__ __host__ Difference< Scalar, ROWS, COLS, Exp1, Exp2 > operator-(RValue< Scalar, ROWS, COLS, Exp1 > const &A, RValue< Scalar, ROWS, COLS, Exp2 > const &B)
Definition: Difference.h:74
#define __device__
Definition: fakecuda.h:34
#define __host__
Definition: fakecuda.h:37
expression template for difference of two expressions
Definition: Difference.h:36