From 1946b7b48be2c45016a5abe4e4c325fb4c984d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Mon, 17 Apr 2017 14:31:13 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@395 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src/containers/pipair.h | 2 + src/core/pistring_std.h | 6 +-- src/math/pievaluator.h | 2 +- src/math/pifft.h | 2 +- src/math/pimathbase.h | 62 ++--------------------------- src/math/pimathcomplex.h | 73 +++++++++++++++++++++++++++++++++++ src/math/pimathmatrix.h | 6 +++ src/math/pimathvector.h | 5 ++- src/thread/pipipelinethread.h | 1 + 9 files changed, 94 insertions(+), 65 deletions(-) create mode 100644 src/math/pimathcomplex.h diff --git a/src/containers/pipair.h b/src/containers/pipair.h index 64ecc64e..8dc04a45 100644 --- a/src/containers/pipair.h +++ b/src/containers/pipair.h @@ -19,8 +19,10 @@ inline bool operator ==(const PIPair & value0, const PIPair inline bool operator !=(const PIPair & value0, const PIPair & value1) {return (value0.first != value1.first) || (value0.second != value1.second);} +#ifdef PIP_STD_IOSTREAM template inline std::ostream & operator <<(std::ostream & s, const PIPair & v) {s << "(" << v.first << ", " << v.second << ")"; return s;} +#endif template inline PICout operator <<(PICout s, const PIPair & v) {s.space(); s.setControl(0, true); s << "(" << v.first << ", " << v.second << ")"; s.restoreControl(); return s;} diff --git a/src/core/pistring_std.h b/src/core/pistring_std.h index e866bc41..f6c21b80 100644 --- a/src/core/pistring_std.h +++ b/src/core/pistring_std.h @@ -1,5 +1,5 @@ -#ifndef PISTRING2STD_H -#define PISTRING2STD_H +#ifndef PISTRING_STD_H +#define PISTRING_STD_H #include #ifdef QNX typedef std::basic_string wstring; @@ -78,4 +78,4 @@ inline std::ostream & operator <<(std::ostream & s, const PIStringList & v) { return s; } -#endif // PISTRING2STD_H +#endif // PISTRING_STD_H diff --git a/src/math/pievaluator.h b/src/math/pievaluator.h index 2819ce52..85523200 100755 --- a/src/math/pievaluator.h +++ b/src/math/pievaluator.h @@ -24,7 +24,7 @@ #define PIEVALUATOR_H #include "pistring.h" -#include "pimathbase.h" +#include "pimathcomplex.h" typedef complexd (*FuncFunc)(void * , int, complexd * ); diff --git a/src/math/pifft.h b/src/math/pifft.h index 80dcc1dc..87b3a420 100644 --- a/src/math/pifft.h +++ b/src/math/pifft.h @@ -23,7 +23,7 @@ #ifndef PIFFT_H #define PIFFT_H -#include "pimathbase.h" +#include "pimathcomplex.h" class PIP_EXPORT PIFFT_double { diff --git a/src/math/pimathbase.h b/src/math/pimathbase.h index 1ba05368..c627e490 100644 --- a/src/math/pimathbase.h +++ b/src/math/pimathbase.h @@ -24,8 +24,8 @@ #define PIMATHBASE_H #include "piinit.h" -#include "pibytearray.h" -#include +#include "pivector.h" +#include "pipair.h" #ifdef QNX # undef PIP_MATH_J0 # undef PIP_MATH_J1 @@ -90,50 +90,19 @@ # define M_GRAVITY_CONST 398600.4418e9; #endif -using std::complex; -typedef complex complexi; -typedef complex complexf; -typedef complex complexd; -typedef complex complexld; - -const complexld complexld_i(0., 1.); -const complexld complexld_0(0.); -const complexld complexld_1(1.); -const complexd complexd_i(0., 1.); -const complexd complexd_0(0.); -const complexd complexd_1(1.); - -__PICONTAINERS_SIMPLE_TYPE__(complexi) -__PICONTAINERS_SIMPLE_TYPE__(complexf) -__PICONTAINERS_SIMPLE_TYPE__(complexd) -__PICONTAINERS_SIMPLE_TYPE__(complexld) const double deg2rad = M_PI_180; const double rad2deg = M_180_PI; inline int sign(const float & x) {return (x < 0.) ? -1 : (x > 0. ? 1 : 0);} inline int sign(const double & x) {return (x < 0.) ? -1 : (x > 0. ? 1 : 0);} -inline complexd sign(const complexd & x) {return complexd(sign(x.real()), sign(x.imag()));} inline int pow2(const int p) {return 1 << p;} inline int sqr(const int v) {return v * v;} inline float sqr(const float & v) {return v * v;} inline double sqr(const double & v) {return v * v;} inline double sinc(const double & v) {if (v == 0.) return 1.; double t = M_PI * v; return sin(t) / t;} -inline complexd round(const complexd & c) {return complexd(piRound(c.real()), piRound(c.imag()));} -inline complexd floor(const complexd & c) {return complexd(floor(c.real()), floor(c.imag()));} -inline complexd ceil(const complexd & c) {return complexd(ceil(c.real()), ceil(c.imag()));} -inline complexd atanc(const complexd & c) {return -complexd(-0.5, 1.) * log((complexd_1 + complexd_i * c) / (complexd_1 - complexd_i * c));} -inline complexd asinc(const complexd & c) {return -complexd_i * log(complexd_i * c + sqrt(complexd_1 - c * c));} -inline complexd acosc(const complexd & c) {return -complexd_i * log(c + complexd_i * sqrt(complexd_1 - c * c));} -#ifdef CC_GCC -# if CC_GCC_VERSION <= 0x025F -inline complexd tan(const complexd & c) {return sin(c) / cos(c);} -inline complexd tanh(const complexd & c) {return sinh(c) / cosh(c);} -inline complexd log2(const complexd & c) {return log(c) / M_LN2;} -inline complexd log10(const complexd & c) {return log(c) / M_LN10;} -# endif -#endif + double piJ0(const double & v); double piJ1(const double & v); double piJn(int n, const double & v); @@ -145,35 +114,12 @@ inline double fromDb(double val) {return pow(10., val / 10.);} inline double toRad(double deg) {return deg * M_PI_180;} inline double toDeg(double rad) {return rad * M_180_PI;} -template -inline PICout operator <<(PICout s, const complex & v) {s.space(); s.setControl(0, true); s << "(" << v.real() << "; " << v.imag() << ")"; s.restoreControl(); return s;} - -//! \relatesalso PIByteArray \brief Store operator -inline PIByteArray & operator <<(PIByteArray & s, complexf v) {float t; t = v.real(); s << t; t = v.imag(); s << t; return s;} -//! \relatesalso PIByteArray \brief Store operator -inline PIByteArray & operator <<(PIByteArray & s, complexd v) {double t; t = v.real(); s << t; t = v.imag(); s << t; return s;} -//! \relatesalso PIByteArray \brief Store operator -inline PIByteArray & operator <<(PIByteArray & s, complexld v) {ldouble t; t = v.real(); s << t; t = v.imag(); s << t; return s;} - -//! \relatesalso PIByteArray \brief Restore operator -inline PIByteArray & operator >>(PIByteArray & s, complexf & v) {float t0, t1; s >> t0; s >> t1; v = complexf(t0, t1); return s;} -//! \relatesalso PIByteArray \brief Restore operator -inline PIByteArray & operator >>(PIByteArray & s, complexd & v) {double t0, t1; s >> t0; s >> t1; v = complexd(t0, t1); return s;} -//! \relatesalso PIByteArray \brief Restore operator -inline PIByteArray & operator >>(PIByteArray & s, complexld & v) {ldouble t0, t1; s >> t0; s >> t1; v = complexld(t0, t1); return s;} - // [-1 ; 1] double randomd(); // [-1 ; 1] normal double randomn(double dv = 0., double sv = 1.); -inline PIVector abs(const PIVector & v) { - PIVector result; - result.resize(v.size()); - for (uint i = 0; i < v.size(); i++) - result[i] = abs(v[i]); - return result; -} + inline PIVector abs(const PIVector & v) { PIVector result; result.resize(v.size()); diff --git a/src/math/pimathcomplex.h b/src/math/pimathcomplex.h new file mode 100644 index 00000000..085d47c6 --- /dev/null +++ b/src/math/pimathcomplex.h @@ -0,0 +1,73 @@ +#ifndef PIMATHCOMPLEX_H +#define PIMATHCOMPLEX_H + +#include +#include "pimathbase.h" +#include "pibytearray.h" + +#define PIP_MATH_COMPLEX + +using std::complex; + +typedef complex complexi; +typedef complex complexf; +typedef complex complexd; +typedef complex complexld; + +const complexld complexld_i(0., 1.); +const complexld complexld_0(0.); +const complexld complexld_1(1.); +const complexd complexd_i(0., 1.); +const complexd complexd_0(0.); +const complexd complexd_1(1.); + +__PICONTAINERS_SIMPLE_TYPE__(complexi) +__PICONTAINERS_SIMPLE_TYPE__(complexf) +__PICONTAINERS_SIMPLE_TYPE__(complexd) +__PICONTAINERS_SIMPLE_TYPE__(complexld) + +inline complexd sign(const complexd & x) {return complexd(sign(x.real()), sign(x.imag()));} + +inline complexd round(const complexd & c) {return complexd(piRound(c.real()), piRound(c.imag()));} +inline complexd floor(const complexd & c) {return complexd(floor(c.real()), floor(c.imag()));} +inline complexd ceil(const complexd & c) {return complexd(ceil(c.real()), ceil(c.imag()));} +inline complexd atanc(const complexd & c) {return -complexd(-0.5, 1.) * log((complexd_1 + complexd_i * c) / (complexd_1 - complexd_i * c));} +inline complexd asinc(const complexd & c) {return -complexd_i * log(complexd_i * c + sqrt(complexd_1 - c * c));} +inline complexd acosc(const complexd & c) {return -complexd_i * log(c + complexd_i * sqrt(complexd_1 - c * c));} + +#ifdef CC_GCC +# if CC_GCC_VERSION <= 0x025F +inline complexd tan(const complexd & c) {return sin(c) / cos(c);} +inline complexd tanh(const complexd & c) {return sinh(c) / cosh(c);} +inline complexd log2(const complexd & c) {return log(c) / M_LN2;} +inline complexd log10(const complexd & c) {return log(c) / M_LN10;} +# endif +#endif + +template +inline PICout operator <<(PICout s, const complex & v) {s.space(); s.setControl(0, true); s << "(" << v.real() << "; " << v.imag() << ")"; s.restoreControl(); return s;} + +//! \relatesalso PIByteArray \brief Store operator +inline PIByteArray & operator <<(PIByteArray & s, complexf v) {float t; t = v.real(); s << t; t = v.imag(); s << t; return s;} +//! \relatesalso PIByteArray \brief Store operator +inline PIByteArray & operator <<(PIByteArray & s, complexd v) {double t; t = v.real(); s << t; t = v.imag(); s << t; return s;} +//! \relatesalso PIByteArray \brief Store operator +inline PIByteArray & operator <<(PIByteArray & s, complexld v) {ldouble t; t = v.real(); s << t; t = v.imag(); s << t; return s;} + +//! \relatesalso PIByteArray \brief Restore operator +inline PIByteArray & operator >>(PIByteArray & s, complexf & v) {float t0, t1; s >> t0; s >> t1; v = complexf(t0, t1); return s;} +//! \relatesalso PIByteArray \brief Restore operator +inline PIByteArray & operator >>(PIByteArray & s, complexd & v) {double t0, t1; s >> t0; s >> t1; v = complexd(t0, t1); return s;} +//! \relatesalso PIByteArray \brief Restore operator +inline PIByteArray & operator >>(PIByteArray & s, complexld & v) {ldouble t0, t1; s >> t0; s >> t1; v = complexld(t0, t1); return s;} + + +inline PIVector abs(const PIVector & v) { + PIVector result; + result.resize(v.size()); + for (uint i = 0; i < v.size(); i++) + result[i] = abs(v[i]); + return result; +} + +#endif // PIMATHCOMPLEX_H diff --git a/src/math/pimathmatrix.h b/src/math/pimathmatrix.h index 386f9224..cb467955 100644 --- a/src/math/pimathmatrix.h +++ b/src/math/pimathmatrix.h @@ -225,8 +225,11 @@ template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleX(double fac template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleY(double factor) {PIMathMatrixT<3u, 3u> tm; tm[0][0] = tm[2][2] = 1.; tm[1][1] = factor; return tm;} template<> inline PIMathMatrixT<3u, 3u> PIMathMatrixT<3u, 3u>::scaleZ(double factor) {PIMathMatrixT<3u, 3u> tm; tm[0][0] = tm[1][1] = 1.; tm[2][2] = factor; return tm;} +#ifdef PIP_STD_IOSTREAM template inline std::ostream & operator <<(std::ostream & s, const PIMathMatrixT & m) {s << '{'; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << std::endl << ' ';} s << '}'; return s;} +#endif + template inline PICout operator <<(PICout s, const PIMathMatrixT & m) {s << '{'; PIMM_FOR_I(r, c) s << m[r][c]; if (c < Cols - 1 || r < Rows - 1) s << ", ";} if (r < Rows - 1) s << PICoutManipulators::NewLine << ' ';} s << '}'; return s;} @@ -472,8 +475,11 @@ private: }; +#ifdef PIP_STD_IOSTREAM template inline std::ostream & operator <<(std::ostream & s, const PIMathMatrix & m) {s << '{'; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m[c][r]; if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << std::endl << ' ';} s << '}'; return s;} +#endif + template inline PICout operator <<(PICout s, const PIMathMatrix & m) {s << '{'; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m[c][r]; if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << PICoutManipulators::NewLine << ' ';} s << '}'; return s;} diff --git a/src/math/pimathvector.h b/src/math/pimathvector.h index 37270471..4536051d 100644 --- a/src/math/pimathvector.h +++ b/src/math/pimathvector.h @@ -128,8 +128,6 @@ inline PIMathVectorT operator *(const Type & x, const PIMathVectorT< return v * x; } -template -inline std::ostream & operator <<(std::ostream & s, const PIMathVectorT & v) {s << '{'; PIMV_FOR(i, 0) {s << v[i]; if (i < Size - 1) s << ", ";} s << '}'; return s;} template inline PICout operator <<(PICout s, const PIMathVectorT & v) {s << '{'; PIMV_FOR(i, 0) {s << v[i]; if (i < Size - 1) s << ", ";} s << '}'; return s;} template @@ -230,8 +228,11 @@ private: #undef PIMV_FOR +#ifdef PIP_STD_IOSTREAM template inline std::ostream & operator <<(std::ostream & s, const PIMathVector & v) {s << '{'; for (uint i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << '}'; return s;} +#endif + template inline PICout operator <<(PICout s, const PIMathVector & v) {s << '{'; for (uint i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << '}'; return s;} diff --git a/src/thread/pipipelinethread.h b/src/thread/pipipelinethread.h index 648a7671..5e4d6a41 100644 --- a/src/thread/pipipelinethread.h +++ b/src/thread/pipipelinethread.h @@ -24,6 +24,7 @@ #define PIPIPELINETHREAD_H #include "pithread.h" +#include "piqueue.h" template class PIPipelineThread : public PIThread