git-svn-id: svn://db.shs.com.ru/pip@660 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
80
main.cpp
80
main.cpp
@@ -1,10 +1,44 @@
|
|||||||
#include "pip.h"
|
#include "picout.h"
|
||||||
|
#include "pivector2d.h"
|
||||||
|
#include "Eigen/Dense"
|
||||||
|
|
||||||
|
typedef Eigen::MatrixXd PIMathMatrixd;
|
||||||
|
typedef Eigen::MatrixXf PIMathMatrixf;
|
||||||
|
typedef Eigen::MatrixXcf PIMathMatrixcf;
|
||||||
|
typedef Eigen::MatrixXcd PIMathMatrixcd;
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
inline PICout operator <<(PICout s, const Eigen::DenseCoeffsBase<Type, Eigen::ReadOnlyAccessors> & m) {s << '{'; for (uint r = 0; r < m.rows(); ++r) { for (uint c = 0; c < m.cols(); ++c) { s << m(r, c); if (c < m.cols() - 1 || r < m.rows() - 1) s << ", ";} if (r < m.rows() - 1) s << PICoutManipulators::NewLine << ' ';} s << '}'; return s;}
|
||||||
|
template<typename Type>
|
||||||
|
inline PIVector<PIVector<typename Type::Scalar> > toVectors(const Eigen::DenseCoeffsBase<Type, Eigen::ReadOnlyAccessors> & m) {
|
||||||
|
PIVector<PIVector<typename Type::Scalar> > ret;
|
||||||
|
for(int i = 0; i < m.cols(); ++i)
|
||||||
|
ret << PIVector<typename Type::Scalar>(&(m(i*m.rows())), m.rows());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
inline Eigen::Matrix<Type, Eigen::Dynamic, Eigen::Dynamic> fromVectors(const PIVector<PIVector<Type> > & m) {
|
||||||
|
if (m.isEmpty()) return Eigen::Matrix<Type, Eigen::Dynamic, Eigen::Dynamic>(0, 0);
|
||||||
|
if (m[0].isEmpty()) return Eigen::Matrix<Type, Eigen::Dynamic, Eigen::Dynamic>(1, 0);
|
||||||
|
Eigen::Matrix<Type, Eigen::Dynamic, Eigen::Dynamic> ret(m[0].size(), m.size());
|
||||||
|
for(int i = 0; i < m.size_s(); ++i)
|
||||||
|
for(int j = 0; j < m[i].size_s(); ++j)
|
||||||
|
ret(j,i) = m[i][j];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
template<typename Type>
|
||||||
|
inline PIVector<typename Type::Scalar> toPlainVector(const Eigen::DenseCoeffsBase<Type, Eigen::ReadOnlyAccessors> & m) {
|
||||||
|
return PIVector<typename Type::Scalar>(&(m(0)), m.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
// Eigen::MatrixXd;
|
||||||
// PIMathMatrix<complexd> m1(2,2, PIVector<complexd>() << complexd(1.) << complexd(1.) << complexd(0.) << complexd(1.));
|
// PIMathMatrix<complexd> m1(2,2, PIVector<complexd>() << complexd(1.) << complexd(1.) << complexd(0.) << complexd(1.));
|
||||||
// PIMathMatrix<complexd> m2(2,3, PIVector<complexd>() << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.));
|
// PIMathMatrix<complexd> m2(2,3, PIVector<complexd>() << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.));
|
||||||
PIMathMatrix<double> m1(3,3, PIVector<double>() << 1. << 2. << 3. << 4. << 6. << 5. << 9. << 8. << 7.);
|
PIMathMatrixd m1(3,3);
|
||||||
|
m1 << 1,2,3,4,6,5,9,8,7;
|
||||||
// PIMathMatrix<double> m2(2,3, PIVector<double>() << 1. << 2. << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.));
|
// PIMathMatrix<double> m2(2,3, PIVector<double>() << 1. << 2. << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.) << complexd(2., 3.));
|
||||||
// PIMathMatrix<double> m3(vv);
|
// PIMathMatrix<double> m3(vv);
|
||||||
// piCout << m2 << PICoutManipulators::NewLine;
|
// piCout << m2 << PICoutManipulators::NewLine;
|
||||||
@@ -18,6 +52,7 @@ int main() {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
piCout << m1 << PICoutManipulators::NewLine;
|
piCout << m1 << PICoutManipulators::NewLine;
|
||||||
|
piCout << toPlainVector(m1);
|
||||||
// piCout << m2 << PICoutManipulators::NewLine;
|
// piCout << m2 << PICoutManipulators::NewLine;
|
||||||
// piCout << (PIVector2D<complexd>)m2 << PICoutManipulators::NewLine;
|
// piCout << (PIVector2D<complexd>)m2 << PICoutManipulators::NewLine;
|
||||||
// piCout << m2.transposed() << PICoutManipulators::NewLine;
|
// piCout << m2.transposed() << PICoutManipulators::NewLine;
|
||||||
@@ -27,17 +62,17 @@ int main() {
|
|||||||
// piCout << (m1*PIMathMatrix<complexd>::matrixCol(v));```
|
// piCout << (m1*PIMathMatrix<complexd>::matrixCol(v));```
|
||||||
// piCout << m2;
|
// piCout << m2;
|
||||||
// piCout << m3;
|
// piCout << m3;
|
||||||
bool ok;
|
// bool ok;
|
||||||
PIMathMatrix<double> mi = m1.inverted(&ok);
|
PIMathMatrixd mi = m1.inverse();
|
||||||
piCout << mi << ok;
|
piCout << mi;
|
||||||
piCout << (mi * m1);
|
piCout << PIMathMatrixd(mi * m1);
|
||||||
piCout << m1.row(0).toVector();
|
piCout << m1.row(0);
|
||||||
piCout << m1.row(1).toVector();
|
piCout << m1.row(1);
|
||||||
piCout << m1.row(2).toVector();
|
piCout << m1.row(2);
|
||||||
piCout << "";
|
piCout << "";
|
||||||
piCout << m1.col(0).toVector();
|
piCout << m1.col(0);
|
||||||
piCout << m1.col(1).toVector();
|
piCout << m1.col(1);
|
||||||
piCout << m1.col(2).toVector();
|
piCout << m1.col(2);
|
||||||
//m2 = m2.transposed();
|
//m2 = m2.transposed();
|
||||||
// piCout << m2 << PICoutManipulators::NewLine << hermitian(m2);
|
// piCout << m2 << PICoutManipulators::NewLine << hermitian(m2);
|
||||||
// piCout << PICoutManipulators::NewLine << hermitian(m2) * mi;
|
// piCout << PICoutManipulators::NewLine << hermitian(m2) * mi;
|
||||||
@@ -57,12 +92,21 @@ int main() {
|
|||||||
// v[r][c] = -v[r][c];
|
// v[r][c] = -v[r][c];
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
PIMathMatrix<double> v = PIMathMatrix<double>(3,2, m1.toPlainVector().resize(6));
|
piCout << "-------" << PICoutManipulators::NewLine;
|
||||||
PIMathMatrix<double> v2 = PIMathMatrix<double>(2,3, m1.toPlainVector().resize(6));
|
PIMathMatrixd v = m1.block(0,0, 3,2);
|
||||||
piCout << v << PICoutManipulators::NewLine;
|
m1 = v;
|
||||||
piCout << v.toVectors() << PICoutManipulators::NewLine;
|
// PIMathMatrixd v2 = m1.block(0,0, 2,3);
|
||||||
|
// PIMathMatrixd v2(2,3, m1.toPlainVector().resize(6));
|
||||||
|
// piCout << v << PICoutManipulators::NewLine;
|
||||||
|
piCout << m1 << PICoutManipulators::NewLine;
|
||||||
|
PIVector<PIVector<double> > vv = toVectors(m1);
|
||||||
|
piCout << vv << PICoutManipulators::NewLine;
|
||||||
|
piCout << fromVectors(vv) << PICoutManipulators::NewLine;
|
||||||
|
// piCout << toVectors(PIMathMatrixd(m1.transpose())) << PICoutManipulators::NewLine;
|
||||||
// PIMathMatrix<double> v2 = PIMathMatrix<double>(v.toVectors());
|
// PIMathMatrix<double> v2 = PIMathMatrix<double>(v.toVectors());
|
||||||
piCout << v2 << PICoutManipulators::NewLine;
|
// piCout << v2 << PICoutManipulators::NewLine;
|
||||||
piCout << v*v2 << PICoutManipulators::NewLine;
|
// piCout << v*v2 << PICoutManipulators::NewLine;
|
||||||
|
// piCout << v2*v << PICoutManipulators::NewLine;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,13 +148,14 @@ public:
|
|||||||
private:
|
private:
|
||||||
class Pool: public PIThread {
|
class Pool: public PIThread {
|
||||||
public:
|
public:
|
||||||
Pool();
|
|
||||||
~Pool();
|
|
||||||
static Pool * instance();
|
static Pool * instance();
|
||||||
void add(_PITimerImp_Pool * t);
|
void add(_PITimerImp_Pool * t);
|
||||||
void remove(_PITimerImp_Pool * t);
|
void remove(_PITimerImp_Pool * t);
|
||||||
void run();
|
void run();
|
||||||
PIVector<_PITimerImp_Pool * > timers, to_remove;
|
PIVector<_PITimerImp_Pool * > timers, to_remove;
|
||||||
|
private:
|
||||||
|
explicit Pool();
|
||||||
|
virtual ~Pool();
|
||||||
};
|
};
|
||||||
virtual bool startTimer(double interval_ms);
|
virtual bool startTimer(double interval_ms);
|
||||||
virtual bool stopTimer(bool wait);
|
virtual bool stopTimer(bool wait);
|
||||||
@@ -390,7 +391,7 @@ _PITimerImp_Pool::Pool * _PITimerImp_Pool::Pool::instance() {
|
|||||||
void _PITimerImp_Pool::Pool::add(_PITimerImp_Pool * t) {
|
void _PITimerImp_Pool::Pool::add(_PITimerImp_Pool * t) {
|
||||||
//piCout << "add ...";
|
//piCout << "add ...";
|
||||||
lock();
|
lock();
|
||||||
to_remove.removeOne(t);
|
to_remove.removeAll(t);
|
||||||
if (!timers.contains(t))
|
if (!timers.contains(t))
|
||||||
timers << t;
|
timers << t;
|
||||||
unlock();
|
unlock();
|
||||||
@@ -408,14 +409,13 @@ void _PITimerImp_Pool::Pool::remove(_PITimerImp_Pool * t) {
|
|||||||
|
|
||||||
|
|
||||||
void _PITimerImp_Pool::Pool::run() {
|
void _PITimerImp_Pool::Pool::run() {
|
||||||
piForeach (_PITimerImp_Pool * t, timers)
|
|
||||||
t->threadFunc();
|
|
||||||
if (!to_remove.isEmpty()) {
|
if (!to_remove.isEmpty()) {
|
||||||
piForeach (_PITimerImp_Pool * t, to_remove)
|
piForeach (_PITimerImp_Pool * t, to_remove)
|
||||||
timers.removeOne(t);
|
timers.removeAll(t);
|
||||||
to_remove.clear();
|
to_remove.clear();
|
||||||
}
|
}
|
||||||
//while (t->threadFunc());
|
piForeach (_PITimerImp_Pool * t, timers)
|
||||||
|
t->threadFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -428,6 +428,9 @@ bool _PITimerImp_Pool::startTimer(double interval_ms) {
|
|||||||
|
|
||||||
bool _PITimerImp_Pool::stopTimer(bool wait) {
|
bool _PITimerImp_Pool::stopTimer(bool wait) {
|
||||||
Pool::instance()->remove(this);
|
Pool::instance()->remove(this);
|
||||||
|
// if (wait) {
|
||||||
|
// Pool::instance()->waitForDelete(this);
|
||||||
|
// }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user