git-svn-id: svn://db.shs.com.ru/pip@335 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -35,7 +35,7 @@ PICrypt::PICrypt() {
|
||||
randombytes_buf(key_.data(), key_.size());
|
||||
randombytes_buf(nonce_.data(), nonce_.size());
|
||||
#else
|
||||
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install sodium library and build pip with -DCRYPT=";
|
||||
piCout << "[PICrypt]" << "Warning: PICrypt is disabled, to enable install libsodium-dev library and build pip with -DCRYPT=1";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -153,6 +153,7 @@ public:
|
||||
|
||||
private:
|
||||
void operator =(const PIFFTW & );
|
||||
PIFFTW(const PIFFTW &);
|
||||
inline void newP(void *& _p) {}
|
||||
inline void deleteP(void *& _p) {}
|
||||
|
||||
@@ -167,6 +168,8 @@ template<> inline void PIFFTW<float>::preparePlan(int size, FFT_Operation op) {(
|
||||
template<> inline void PIFFTW<float>::newP(void *& _p) {_p = new _PIFFTW_P_float_();}
|
||||
template<> inline void PIFFTW<float>::deleteP(void *& _p) {if (_p) delete (_PIFFTW_P_float_*)_p; _p = 0;}
|
||||
|
||||
typedef PIFFTW<float> PIFFTWf;
|
||||
|
||||
|
||||
template<> inline const PIVector<complex<double> > & PIFFTW<double>::calcFFT(const PIVector<complex<double> > & in) {return ((_PIFFTW_P_double_*)p)->calcFFT(in);}
|
||||
template<> inline const PIVector<complex<double> > & PIFFTW<double>::calcFFT(const PIVector<double> & in) {return ((_PIFFTW_P_double_*)p)->calcFFTR(in);}
|
||||
@@ -175,7 +178,10 @@ template<> inline void PIFFTW<double>::preparePlan(int size, FFT_Operation op) {
|
||||
template<> inline void PIFFTW<double>::newP(void *& _p) {_p = new _PIFFTW_P_double_();}
|
||||
template<> inline void PIFFTW<double>::deleteP(void *& _p) {if (_p) delete (_PIFFTW_P_double_*)_p; _p = 0;}
|
||||
|
||||
typedef PIFFTW<double> PIFFTWd;
|
||||
|
||||
|
||||
#ifdef WINDOWS
|
||||
template<> inline const PIVector<complex<ldouble> > & PIFFTW<ldouble>::calcFFT(const PIVector<complex<ldouble> > & in) {return ((_PIFFTW_P_ldouble_*)p)->calcFFT(in);}
|
||||
template<> inline const PIVector<complex<ldouble> > & PIFFTW<ldouble>::calcFFT(const PIVector<ldouble> & in) {return ((_PIFFTW_P_ldouble_*)p)->calcFFTR(in);}
|
||||
template<> inline const PIVector<complex<ldouble> > & PIFFTW<ldouble>::calcFFTinverse(const PIVector<complex<ldouble> > & in) {return ((_PIFFTW_P_ldouble_*)p)->calcFFTI(in);}
|
||||
@@ -183,10 +189,7 @@ template<> inline void PIFFTW<ldouble>::preparePlan(int size, FFT_Operation op)
|
||||
template<> inline void PIFFTW<ldouble>::newP(void *& _p) {_p = new _PIFFTW_P_ldouble_();}
|
||||
template<> inline void PIFFTW<ldouble>::deleteP(void *& _p) {if (_p) delete (_PIFFTW_P_ldouble_*)_p; _p = 0;}
|
||||
|
||||
|
||||
typedef PIFFTW<float> PIFFTWf;
|
||||
typedef PIFFTW<double> PIFFTWd;
|
||||
typedef PIFFTW<ldouble> PIFFTWld;
|
||||
|
||||
#endif // WINDOWS
|
||||
|
||||
#endif // PIFFT_H
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "pivector.h"
|
||||
#include "pimutex.h"
|
||||
#include <complex.h>
|
||||
#include "picout.h"
|
||||
#ifdef PIP_FFTW
|
||||
# include "fftw3.h"
|
||||
#else
|
||||
@@ -36,106 +36,136 @@
|
||||
#endif
|
||||
|
||||
|
||||
static PIMutex __pip_fft_plan_mutex;
|
||||
|
||||
|
||||
template <typename T>
|
||||
class PIFFTW_Private
|
||||
{
|
||||
public:
|
||||
explicit PIFFTW_Private() {plan = 0; newPlan(plan);}
|
||||
~PIFFTW_Private() {deletePlan(plan);}
|
||||
explicit PIFFTW_Private() {
|
||||
plan = 0;
|
||||
#ifdef PIP_FFTW
|
||||
// fftwf_m
|
||||
#else
|
||||
piCout << "[PIFFTW]" << "Warning: PIFFTW is disabled, to enable install libfftw3-dev library and build pip with -DFFTW=1";
|
||||
#endif
|
||||
p_makeThreadSafe();
|
||||
}
|
||||
~PIFFTW_Private() {p_destroyPlan(plan);}
|
||||
|
||||
const PIVector<complex<T> > & calcFFT(const PIVector<complex<T> > & in) {
|
||||
result.resize(in.size());
|
||||
__pip_fft_plan_mutex.lock();
|
||||
createPlan_c_1d(plan, in.size_s(), in.data(), result.data(), FFTW_FORWARD, FFTW_ESTIMATE);
|
||||
__pip_fft_plan_mutex.unlock();
|
||||
executePlan(plan);
|
||||
destroyPlan(plan);
|
||||
return result;
|
||||
if (prepare != PlanParams(in.size(), fo_complex)) {
|
||||
p_out.resize(in.size());
|
||||
piCout << "[PIFFTW]" << "creating plan";
|
||||
p_createPlan_c2c_1d(plan, in.size(), in.data(), p_out.data(), FFTW_FORWARD, FFTW_ESTIMATE | FFTW_UNALIGNED);
|
||||
prepare = PlanParams(in.size(), fo_complex);
|
||||
}
|
||||
p_executePlan_c2c(plan, in.data(), p_out.data());
|
||||
return p_out;
|
||||
}
|
||||
const PIVector<complex<T> > & calcFFT(const PIVector<T> & in) {
|
||||
result.resize(in.size());
|
||||
__pip_fft_plan_mutex.lock();
|
||||
createPlan_r2c_1d(plan, in.size_s(), in.data(), result.data(), FFTW_ESTIMATE);
|
||||
__pip_fft_plan_mutex.unlock();
|
||||
executePlan(plan);
|
||||
destroyPlan(plan);
|
||||
return result;
|
||||
if (prepare != PlanParams(in.size(), fo_real)) {
|
||||
p_out.resize(in.size());
|
||||
piCout << "[PIFFTW]" << "creating plan";
|
||||
p_createPlan_r2c_1d(plan, in.size(), in.data(), p_out.data(), FFTW_ESTIMATE | FFTW_UNALIGNED);
|
||||
prepare = PlanParams(in.size(), fo_real);
|
||||
}
|
||||
p_executePlan_r2c(plan, in.data(), p_out.data());
|
||||
return p_out;
|
||||
}
|
||||
const PIVector<complex<T> > & calcFFTinverse(const PIVector<complex<T> > & in) {
|
||||
result.resize(in.size());
|
||||
__pip_fft_plan_mutex.lock();
|
||||
createPlan_c_1d(plan, in.size_s(), in.data(), result.data(), FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||
__pip_fft_plan_mutex.unlock();
|
||||
executePlan(plan);
|
||||
destroyPlan(plan);
|
||||
return result;
|
||||
if (prepare != PlanParams(in.size(), fo_inverse)) {
|
||||
p_out.resize(in.size());
|
||||
piCout << "[PIFFTW]" << "creating plan";
|
||||
p_createPlan_c2c_1d(plan, in.size(), in.data(), p_out.data(), FFTW_BACKWARD, FFTW_ESTIMATE | FFTW_UNALIGNED);
|
||||
prepare = PlanParams(in.size(), fo_inverse);
|
||||
}
|
||||
p_executePlan_c2c(plan, in.data(), p_out.data());
|
||||
return p_out;
|
||||
}
|
||||
|
||||
enum FFT_Operation {fo_real, fo_complex, fo_inverse};
|
||||
|
||||
void preparePlan(int size, int op) {
|
||||
PIVector<complex<T> > in(size), out(size);
|
||||
PIVector<T> inr(size);
|
||||
__pip_fft_plan_mutex.lock();
|
||||
p_inr.clear();
|
||||
p_in.clear();
|
||||
p_out.clear();
|
||||
switch ((FFT_Operation)op) {
|
||||
case fo_real:
|
||||
createPlan_r2c_1d(plan, in.size_s(), inr.data(), out.data(), FFTW_MEASURE);
|
||||
case fo_real:
|
||||
p_inr.resize(size);
|
||||
p_out.resize(size);
|
||||
p_createPlan_r2c_1d(plan, size, p_inr.data(), p_out.data(), FFTW_MEASURE | FFTW_UNALIGNED);
|
||||
break;
|
||||
case fo_complex:
|
||||
createPlan_c_1d(plan, in.size_s(), in.data(), out.data(), FFTW_FORWARD, FFTW_MEASURE);
|
||||
case fo_complex:
|
||||
p_in.resize(size);
|
||||
p_out.resize(size);
|
||||
p_createPlan_c2c_1d(plan, size, p_in.data(), p_out.data(), FFTW_FORWARD, FFTW_MEASURE | FFTW_UNALIGNED);
|
||||
break;
|
||||
case fo_inverse:
|
||||
createPlan_c_1d(plan, in.size_s(), in.data(), out.data(), FFTW_BACKWARD, FFTW_MEASURE);
|
||||
case fo_inverse:
|
||||
p_in.resize(size);
|
||||
p_out.resize(size);
|
||||
p_createPlan_c2c_1d(plan, size, p_in.data(), p_out.data(), FFTW_BACKWARD, FFTW_MEASURE | FFTW_UNALIGNED);
|
||||
break;
|
||||
default:
|
||||
size = 0;
|
||||
break;
|
||||
}
|
||||
__pip_fft_plan_mutex.unlock();
|
||||
prepare = PlanParams(size, (FFT_Operation)op);
|
||||
}
|
||||
|
||||
inline void createPlan_c_1d(void * plan, int size, const void * in, void * out, int dir, int flags) {}
|
||||
inline void createPlan_r2c_1d(void * plan, int size, const void * in, void * out, int flags) {}
|
||||
inline void executePlan(void * plan) {}
|
||||
inline void destroyPlan(void * plan) {}
|
||||
inline void newPlan(void *& plan) {}
|
||||
inline void deletePlan(void *& plan) {}
|
||||
inline void p_createPlan_c2c_1d(void *& plan, int size, const void * in, void * out, int dir, int flags) {}
|
||||
inline void p_createPlan_r2c_1d(void *& plan, int size, const void * in, void * out, int flags) {}
|
||||
inline void p_executePlan_c2c(void * plan, const void * in, void * out) {}
|
||||
inline void p_executePlan_r2c(void * plan, const void * in, void * out) {}
|
||||
inline void p_destroyPlan(void *& plan) {}
|
||||
inline void p_makeThreadSafe() {}
|
||||
|
||||
PIVector<complex<T> > result;
|
||||
struct PlanParams {
|
||||
PlanParams() {size = 0; op = fo_complex;}
|
||||
PlanParams(int size_, FFT_Operation op_) {size = size_; op = op_;}
|
||||
bool isValid() {return size > 0;}
|
||||
bool operator ==(const PlanParams & v) const {return (v.size == size) && (v.op == op);}
|
||||
bool operator !=(const PlanParams & v) const {return !(*this == v);}
|
||||
int size;
|
||||
FFT_Operation op;
|
||||
};
|
||||
|
||||
PIVector<complex<T> > p_in;
|
||||
PIVector<T> p_inr;
|
||||
PIVector<complex<T> > p_out;
|
||||
void * plan;
|
||||
PlanParams prepare;
|
||||
};
|
||||
|
||||
|
||||
#ifdef PIP_FFTW
|
||||
template<> inline void PIFFTW_Private<float>::p_createPlan_c2c_1d(void *& plan, int size, const void * in, void * out, int dir, int flags) {
|
||||
plan = fftwf_plan_dft_1d(size, (fftwf_complex *)in, (fftwf_complex *)out, dir, flags);}
|
||||
template<> inline void PIFFTW_Private<float>::p_createPlan_r2c_1d(void *& plan, int size, const void * in, void * out, int flags) {
|
||||
plan = fftwf_plan_dft_r2c_1d(size, (float *)in, (fftwf_complex *)out, flags);}
|
||||
template<> inline void PIFFTW_Private<float>::p_executePlan_c2c(void * plan, const void * in, void * out) {fftwf_execute_dft((fftwf_plan)plan, (fftwf_complex *)in, (fftwf_complex *)out);}
|
||||
template<> inline void PIFFTW_Private<float>::p_executePlan_r2c(void * plan, const void * in, void * out) {fftwf_execute_dft_r2c((fftwf_plan)plan, (float *)in, (fftwf_complex *)out);}
|
||||
template<> inline void PIFFTW_Private<float>::p_destroyPlan(void *& plan) {if (plan) fftwf_destroy_plan((fftwf_plan)plan); plan = 0;}
|
||||
template<> inline void PIFFTW_Private<float>::p_makeThreadSafe() {fftwf_make_planner_thread_safe();}
|
||||
|
||||
template<> inline void PIFFTW_Private<float>::createPlan_c_1d(void * plan, int size, const void * in, void * out, int dir, int flags) {
|
||||
*(fftwf_plan*)plan = fftwf_plan_dft_1d(size, (fftwf_complex *)in, (fftwf_complex *)out, dir, flags);}
|
||||
template<> inline void PIFFTW_Private<float>::createPlan_r2c_1d(void * plan, int size, const void * in, void * out, int flags) {
|
||||
*(fftwf_plan*)plan = fftwf_plan_dft_r2c_1d(size, (float *)in, (fftwf_complex *)out, flags);}
|
||||
template<> inline void PIFFTW_Private<float>::executePlan(void * plan) {fftwf_execute(*(fftwf_plan*)plan);}
|
||||
template<> inline void PIFFTW_Private<float>::destroyPlan(void * plan) {fftwf_destroy_plan(*(fftwf_plan*)plan);}
|
||||
template<> inline void PIFFTW_Private<float>::newPlan(void *& plan) {plan = new fftwf_plan();}
|
||||
template<> inline void PIFFTW_Private<float>::deletePlan(void *& plan) {if (plan) delete (fftwf_plan*)plan; plan = 0;}
|
||||
template<> inline void PIFFTW_Private<double>::p_createPlan_c2c_1d(void *& plan, int size, const void * in, void * out, int dir, int flags) {
|
||||
plan = fftw_plan_dft_1d(size, (fftw_complex *)in, (fftw_complex *)out, dir, flags);}
|
||||
template<> inline void PIFFTW_Private<double>::p_createPlan_r2c_1d(void *& plan, int size, const void * in, void * out, int flags) {
|
||||
plan = fftw_plan_dft_r2c_1d(size, (double *)in, (fftw_complex *)out, flags);}
|
||||
template<> inline void PIFFTW_Private<double>::p_executePlan_c2c(void * plan, const void * in, void * out) {fftw_execute_dft((fftw_plan)plan, (fftw_complex *)in, (fftw_complex *)out);}
|
||||
template<> inline void PIFFTW_Private<double>::p_executePlan_r2c(void * plan, const void * in, void * out) {fftw_execute_dft_r2c((fftw_plan)plan, (double *)in, (fftw_complex *)out);}
|
||||
template<> inline void PIFFTW_Private<double>::p_destroyPlan(void *& plan) {if (plan) fftw_destroy_plan((fftw_plan)plan); plan = 0;}
|
||||
template<> inline void PIFFTW_Private<double>::p_makeThreadSafe() {fftw_make_planner_thread_safe();}
|
||||
|
||||
#ifdef WINDOWS
|
||||
template<> inline void PIFFTW_Private<ldouble>::p_createPlan_c2c_1d(void *& plan, int size, const void * in, void * out, int dir, int flags) {
|
||||
plan = fftwl_plan_dft_1d(size, (fftwl_complex *)in, (fftwl_complex *)out, dir, flags);}
|
||||
template<> inline void PIFFTW_Private<ldouble>::p_createPlan_r2c_1d(void *& plan, int size, const void * in, void * out, int flags) {
|
||||
plan = fftwl_plan_dft_r2c_1d(size, (ldouble *)in, (fftwl_complex *)out, flags);}
|
||||
template<> inline void PIFFTW_Private<ldouble>::p_executePlan_c2c(void * plan, const void * in, void * out) {fftwl_execute_dft((fftwl_plan)plan, (fftwl_complex *)in, (fftwl_complex *)out);}
|
||||
template<> inline void PIFFTW_Private<ldouble>::p_executePlan_r2c(void * plan, const void * in, void * out) {fftwl_execute_dft_r2c((fftwl_plan)plan, (ldouble *)in, (fftwl_complex *)out);}
|
||||
template<> inline void PIFFTW_Private<ldouble>::p_destroyPlan(void *& plan) {if (plan) fftwl_destroy_plan((fftwl_plan)plan); plan = 0;}
|
||||
template<> inline void PIFFTW_Private<ldouble>::p_makeThreadSafe() {fftwl_make_planner_thread_safe();}
|
||||
#endif // WINDOWS
|
||||
|
||||
template<> inline void PIFFTW_Private<double>::createPlan_c_1d(void * plan, int size, const void * in, void * out, int dir, int flags) {
|
||||
*(fftw_plan*)plan = fftw_plan_dft_1d(size, (fftw_complex *)in, (fftw_complex *)out, dir, flags);}
|
||||
template<> inline void PIFFTW_Private<double>::createPlan_r2c_1d(void * plan, int size, const void * in, void * out, int flags) {
|
||||
*(fftw_plan*)plan = fftw_plan_dft_r2c_1d(size, (double *)in, (fftw_complex *)out, flags);}
|
||||
template<> inline void PIFFTW_Private<double>::executePlan(void * plan) {fftw_execute(*(fftw_plan*)plan);}
|
||||
template<> inline void PIFFTW_Private<double>::destroyPlan(void * plan) {fftw_destroy_plan(*(fftw_plan*)plan);}
|
||||
template<> inline void PIFFTW_Private<double>::newPlan(void *& plan) {plan = new fftw_plan();}
|
||||
template<> inline void PIFFTW_Private<double>::deletePlan(void *& plan) {if (plan) delete (fftw_plan*)plan; plan = 0;}
|
||||
|
||||
|
||||
template<> inline void PIFFTW_Private<ldouble>::createPlan_c_1d(void * plan, int size, const void * in, void * out, int dir, int flags) {
|
||||
*(fftwl_plan*)plan = fftwl_plan_dft_1d(size, (fftwl_complex *)in, (fftwl_complex *)out, dir, flags);}
|
||||
template<> inline void PIFFTW_Private<ldouble>::createPlan_r2c_1d(void * plan, int size, const void * in, void * out, int flags) {
|
||||
*(fftwl_plan*)plan = fftwl_plan_dft_r2c_1d(size, (ldouble *)in, (fftwl_complex *)out, flags);}
|
||||
template<> inline void PIFFTW_Private<ldouble>::executePlan(void * plan) {fftwl_execute(*(fftwl_plan*)plan);}
|
||||
template<> inline void PIFFTW_Private<ldouble>::destroyPlan(void * plan) {fftwl_destroy_plan(*(fftwl_plan*)plan);}
|
||||
template<> inline void PIFFTW_Private<ldouble>::newPlan(void *& plan) {plan = new fftwl_plan();}
|
||||
template<> inline void PIFFTW_Private<ldouble>::deletePlan(void *& plan) {if (plan) delete (fftwl_plan*)plan; plan = 0;}
|
||||
|
||||
#endif // PIP_FFTW
|
||||
|
||||
|
||||
Reference in New Issue
Block a user