9 #ifndef imagingArray_hpp
10 #define imagingArray_hpp
12 #pragma GCC system_header
13 #include <Eigen/Dense>
15 #include "../math/templateBLAS.hpp"
16 #include "../math/fft/fft.hpp"
24 template<
typename Scalar>
27 Scalar * alloc(
size_t sz)
32 void free(Scalar * ptr)
56 template <
typename imageT>
57 static yes& test(
typename imageT::imagingArrayT*);
64 static const bool value =
sizeof(test<T>(0)) ==
sizeof(yes);
67 template<
typename imageT,
70 struct imagingArrayInplaceProduct
72 imagingArrayInplaceProduct()
77 void operator()(imageT & im, typeT & alpha)
79 math::scal<typename imageT::Scalar>(im.cols()*im.rows(), (typeT) alpha, im.data(), 1);
83 template<
typename imageT,
85 struct imagingArrayInplaceProduct<imageT, typeT, true>
87 imagingArrayInplaceProduct()
89 static_assert( is_imagingArray<imageT>::value,
"imagingArrayInplaceProduct template parameter 1 must be an imagingArray type");
92 void operator()(imageT & im, typeT & alpha)
94 typedef typename imageT::Scalar scalarT;
97 Eigen::Map<Eigen::Array<scalarT,-1,-1> > eigY(alpha.data(), alpha.cols(), alpha.rows());
98 Eigen::Map<Eigen::Array<scalarT,-1,-1> > eigX(im.data(), im.cols(), im.rows());
106 template<
typename imageT,
108 bool isScalar = is_imagingArray<typeT>::value>
109 struct imagingArrayInplaceDivision
111 imagingArrayInplaceDivision()
113 static_assert( is_imagingArray<imageT>::value,
"imagingArrayInplaceDivision template parameter 1 must be an imagingArray type");
116 void operator()(imageT im, typeT alpha)
118 math::scal<typename imageT::Scalar>(im.cols()*im.rows(), ((typeT) (1))/alpha, im.data(), 1);
122 template<
typename imageT,
124 struct imagingArrayInplaceDivision<imageT, typeT, true>
126 imagingArrayInplaceDivision()
128 static_assert( is_imagingArray<imageT>::value,
"imagingArrayInplaceDivision template parameter 1 must be an imagingArray type");
131 void operator()(imageT im, typeT alpha)
133 typedef typename imageT::Scalar scalarT;
134 math::hadd<scalarT>(im.cols()*im.rows(), (scalarT) 1.0, alpha.data(),1, im.data(), 1);
140 template<
typename imageT,
142 bool isScalar = is_imagingArray<typeT>::value>
143 struct imagingArrayInplaceAdd
145 imagingArrayInplaceAdd()
147 static_assert( is_imagingArray<imageT>::value,
"imagingArrayInplaceAdd template parameter 1 must be an imagingArray type");
150 void operator()(imageT & im, typeT & alpha)
152 typedef typename imageT::Scalar scalarT;
153 Eigen::Map<Eigen::Array<scalarT,-1,-1> > eigX(im.data(), im.cols(), im.rows());
158 template<
typename imageT,
160 struct imagingArrayInplaceAdd<imageT, typeT, true>
162 imagingArrayInplaceAdd()
164 static_assert( is_imagingArray<imageT>::value,
"imagingArrayInplaceAdd template parameter 1 must be an imagingArray type");
167 void operator()(imageT & im, typeT & alpha)
169 typedef typename imageT::Scalar scalarT;
172 Eigen::Map<Eigen::Array<scalarT,-1,-1> > eigY(alpha.data(), alpha.cols(), alpha.rows());
173 Eigen::Map<Eigen::Array<scalarT,-1,-1> > eigX(im.data(), im.cols(), im.rows());
182 template<
typename _Scalar,
class _allocatorT,
int cudaGPU>
185 template<
typename _Scalar,
class _allocatorT>
186 class imagingArray<_Scalar, _allocatorT, 0>
190 typedef bool imagingArrayT;
191 typedef _Scalar Scalar;
192 typedef _allocatorT allocatorT;
195 allocatorT allocator;
214 imagingArray(
int x,
int y)
224 template<
typename eigenT>
225 explicit imagingArray(eigenT & im)
238 void resize(
int szx,
int szy)
240 if(szx == _cols && szy == _rows && _owner)
return;
247 _data = allocator.alloc(_cols*_rows);
255 allocator.free(_data);
277 Scalar * data()
const
282 Scalar operator()(
int x,
int y)
const
284 return _data[x + y*_cols];
287 Scalar & operator()(
int x,
int y)
289 return _data[x + y*_cols];
292 template<
typename argT>
297 Scalar dval = (Scalar) val;
298 for(
int i=0;i<N;++i) _data[i] = dval;
308 imagingArray & operator=(
const imagingArray & arr)
310 resize(arr.rows(), arr.cols());
312 for(
int i=0; i<_rows; ++i)
314 for(
int j=0; j<_cols; ++j)
316 operator()(i,j) = arr(i,j);
325 template<
typename typeT>
326 imagingArray & operator*=(typeT & alpha)
328 imagingArrayInplaceProduct<imagingArray, typeT> prod;
334 template<
typename typeT>
335 imagingArray & operator/=(typeT alpha)
337 imagingArrayInplaceDivision<imagingArray, typeT> div;
343 template<
typename typeT>
344 imagingArray & operator+=(typeT & alpha)
346 imagingArrayInplaceAdd<imagingArray, typeT> prod;
356 for(
int i=0;i<N;++i) _sum += _data[i];
361 Eigen::Map<Eigen::Array<Scalar,-1,-1> >
eigenMap()
363 return Eigen::Map<Eigen::Array<Scalar,-1,-1> >(_data, _rows, _cols);
369 template<
typename scalarT>
370 using imagingArrayT = imagingArray<scalarT, fftwAllocator<scalarT>,0>;
Eigen::Map< Eigen::Array< scalarT, -1, -1 > > eigenMap
Definition of the eigenMap type, which is an alias for Eigen::Map<Array>.
realT * fftw_malloc(size_t n)
Call to fftw_malloc, with type cast.
void fftw_free(realT *p)
Call to fftw_free.
Test whether a type is an imagingArray by testing whether it has a typedef of "is_imagingArray".