|
Go to the documentation of this file. 1 #ifndef NPSTAT_CONVOLUTIONENGINE1D_HH_
2 #define NPSTAT_CONVOLUTIONENGINE1D_HH_
21 #include "npstat/wrap/arrayNDToNumpy.hh"
22 #include "npstat/wrap/numpyArrayUtils.hh"
39 unsigned optimization = FFTW_ESTIMATE);
50 template < typename Real>
51 void setFilter( const Real* data, unsigned dataLen, unsigned shift=0);
68 template < typename Real1, typename Real2>
73 template < typename Real1, typename Real2>
88 template < typename Real>
90 const Real* data, unsigned dataLen,
101 const std::complex<double>* image, unsigned imLen);
113 template < typename Real1, typename Real2>
115 const Real1* in, Real2* out, unsigned dataLen,
119 template < typename Real1, typename Real2>
121 const Real1* in, Real2* out, unsigned dataLen,
128 template < typename Real2>
130 Real2* out, unsigned dataLen);
136 template < typename Real2>
138 Real2* out, unsigned dataLen);
157 inline bool isFilterSet() const { return validFilter_;}
158 inline unsigned filterBankSize() const { return filterMap_.size();}
161 typedef std::map<unsigned long,FourierImage*> FilterMap;
167 template < typename Real1, typename Real2>
168 void convolveWithImage( const fftw_complex* image,
169 const Real1* in, Real2* out, unsigned dataLen,
172 template < typename Real1, typename Real2>
173 void deconvolveImage( const fftw_complex* image,
174 const Real1* in, Real2* out, unsigned dataLen,
181 fftw_complex* filterImage;
186 FilterMap filterMap_;
190 inline void setFilter2(PyObject* input, unsigned shift=0)
192 if (!isNumpyShapeCompatible(input, &dataLen_, 1U)) throw std::invalid_argument(
193 "In npstat::ConvolutionEngine1D::setFilter2: incompatible array shape");
194 const int typenum = numpyArrayType(input);
195 if (typenum == NumpyTypecode<double>::code)
196 setFilter(( double*)PyArray_DATA((PyArrayObject*)input), dataLen_, shift);
197 else if (typenum == NumpyTypecode<float>::code)
198 setFilter(( float*)PyArray_DATA((PyArrayObject*)input), dataLen_, shift);
199 else if (typenum == NumpyTypecode<long long>::code)
200 setFilter(( long long*)PyArray_DATA((PyArrayObject*)input), dataLen_, shift);
201 else if (typenum == NumpyTypecode<long int>::code)
202 setFilter(( long int*)PyArray_DATA((PyArrayObject*)input), dataLen_, shift);
203 else if (typenum == NumpyTypecode<unsigned char>::code)
204 setFilter(( unsigned char*)PyArray_DATA((PyArrayObject*)input), dataLen_, shift);
205 else if (typenum == NumpyTypecode<int>::code)
206 setFilter(( int*)PyArray_DATA((PyArrayObject*)input), dataLen_, shift);
208 throw std::invalid_argument( "In npstat::ConvolutionEngine1D::setFilter2: "
209 "unsupported input array type");
212 inline void depositFilter2( unsigned long id,
213 const double* in, unsigned dataLen,
217 inline PyObject* convolveWithFilter2( const double* in, unsigned dataLen,
218 const unsigned shift = 0,
219 const bool makeNonNegative = false)
221 const int typenum = NumpyTypecode<double>::code;
222 npy_intp sh = dataLen;
223 PyObject* xarr = PyArray_SimpleNew(1, &sh, typenum);
226 double* out = ( double*)PyArray_DATA((PyArrayObject*)xarr);
231 catch ( const std::exception& e)
237 for ( unsigned i=0; i<dataLen; ++i)
244 inline PyObject* convolveWithDeposit2( const unsigned long id,
245 const double* in, unsigned dataLen,
246 const unsigned shift = 0,
247 const bool makeNonNegative = false)
249 const int typenum = NumpyTypecode<double>::code;
250 npy_intp sh = dataLen;
251 PyObject* xarr = PyArray_SimpleNew(1, &sh, typenum);
254 double* out = ( double*)PyArray_DATA((PyArrayObject*)xarr);
259 catch ( const std::exception& e)
265 for ( unsigned i=0; i<dataLen; ++i)
272 inline PyObject* convolveFilterAndDeposit2( const unsigned long id,
273 const bool makeNonNegative = false)
275 const int typenum = NumpyTypecode<double>::code;
276 npy_intp sh = dataLen_;
277 PyObject* xarr = PyArray_SimpleNew(1, &sh, typenum);
280 double* out = ( double*)PyArray_DATA((PyArrayObject*)xarr);
285 catch ( const std::exception& e)
291 for ( unsigned i=0; i<dataLen_; ++i)
301 #include "npstat/nm/ConvolutionEngine1D.icc"
Arbitrary-dimensional array template.
Memory manager for Fourier transforms produced by FFTW.
Definition: ConvolutionEngine1D.hh:31
void deconvolveDeposit(unsigned long id, const Real1 *in, Real2 *out, unsigned dataLen, unsigned shift=0)
void setFilterImage(const std::complex< double > *image, unsigned imLen)
void deconvolveFilter(const Real1 *in, Real2 *out, unsigned dataLen, unsigned shift=0)
void convolveWithDeposit(unsigned long id, const Real1 *in, Real2 *out, unsigned dataLen, unsigned shift=0)
ConvolutionEngine1D(unsigned dataLen, unsigned optimization=FFTW_ESTIMATE)
void convolveFilterAndDeposit(unsigned long id, Real2 *out, unsigned dataLen)
void setFilter(const Real *data, unsigned dataLen, unsigned shift=0)
void deconvolveFilterAndDeposit(unsigned long id, Real2 *out, unsigned dataLen)
void convolveWithFilter(const Real1 *in, Real2 *out, unsigned dataLen, unsigned shift=0)
unsigned dataLength() const Definition: ConvolutionEngine1D.hh:151
void depositFilter(unsigned long id, const Real *data, unsigned dataLen, unsigned shift=0)
unsigned imageLength() const Definition: ConvolutionEngine1D.hh:154
bool discardFilter(unsigned long id)
void depositFilterImage(unsigned long id, const std::complex< double > *image, unsigned imLen)
Definition: AbsArrayProjector.hh:14
|