inline PIBinaryStream & operator <<(PIBinaryStream
& s, const PIMathMatrix & v) {
s << (const PIVector2D &) v;
return s;
}
//! \~english
//! \brief Inline operator to deserialize matrix from \a PIByteArray.
//! \param s \a PIBinaryStream type.
//! \param v \a PIMathMatrix type.
//! \~russian
//! \brief Inline-оператор для сериализации матрицы в \a PIByteArray.
//! \param s типа \a PIBinaryStream.
//! \param v типа \a PIMathMatrix.
template
inline PIBinaryStream & operator >>(PIBinaryStream
& s, PIMathMatrix & v) {
s >> (PIVector2D &) v;
return s;
}
//! \~english
//! \brief Multiplying matrices by each other.
//! \details If you enter an index out of the border of the matrix there will be "undefined behavior".
//! \param fm first matrix multiplier.
//! \param sm second matrix multiplier.
//! \return matrix that is the result of multiplication.
//! \~russian
//! \brief Умножение матриц друг на друга.
//! \details Если вы введете индекс вне границ матрицы, то поведение не определено ("undefined behavior").
//! \param fm первый множитель-матрица.
//! \param sm вторая множитель-матрица.
//! \return матрица, являющаяся результатом умножения.
template
inline PIMathMatrix operator*(const PIMathMatrix &fm,
const PIMathMatrix &sm) {
assert(fm.cols() == sm.rows());
PIMathMatrix tm(sm.cols(), fm.rows());
Type t;
for (uint j = 0; j < fm.rows(); ++j) {
for (uint i = 0; i < sm.cols(); ++i) {
t = Type(0);
for (uint k = 0; k < fm.cols(); ++k)
t += fm.element(j, k) * sm.element(k, i);
tm.element(j, i) = t;
}
}
return tm;
}
//! \~english
//! \brief Multiplying a matrix by a vector.
//! \details If you enter an index out of the border of the matrix there will be "undefined behavior".
//! \param fm first matrix multiplier
//! \param sv second vector multiplier
//! \return vector that is the result of multiplication
//! \~russian
//! \brief Умножения матрицы на вектор.
//! \details Если вы введете индекс вне границ матрицы, то поведение не определено ("undefined behavior").
//! \param fm первый множитель-матрица.
//! \param sv второй множитель-вектор.
//! \return вектор, являющийся результатом умножения.
template
inline PIMathVector operator*(const PIMathMatrix &fm,
const PIMathVector &sv) {
assert(fm.cols() == sv.size());
PIMathVector tv(fm.rows());
Type t;
for (uint j = 0; j < fm.rows(); ++j) {
t = Type(0);
for (uint i = 0; i < fm.cols(); ++i)
t += fm.element(j, i) * sv[i];
tv[j] = t;
}
return tv;
}
//! \~english
//! \brief Multiplying a vector by a matrix.
//! \details If you enter an index out of the border of the matrix there will be "undefined behavior".
//! \param sv first vector multiplier
//! \param fm second matrix multiplier
//! \return vector that is the result of multiplication
//! \~russian
//! \brief Умножения вектора на матрицу.
//! \details Если вы введете индекс вне границ матрицы, то поведение не определено ("undefined behavior").
//! \param sv второй множитель-вектор.
//! \param fm первый множитель-матрица.
//! \return вектор, являющийся результатом умножения.
template
inline PIMathVector operator*(const PIMathVector &sv,
const PIMathMatrix &fm) {
PIMathVector tv(fm.cols());
assert(fm.rows() == sv.size());
Type t;
for (uint j = 0; j < fm.cols(); ++j) {
t = Type(0);
for (uint i = 0; i < fm.rows(); ++i)
t += fm.element(i, j) * sv[i];
tv[j] = t;
}
return tv;
}
//! \~english
//! \brief Multiplying a value of type `Type` by a matrix.
//! \param x first multiplier of type `Type`.
//! \param v second matrix multiplier.
//! \return matrix that is the result of multiplication.
//! \~russian
//! \brief Умножение значения тип `Type` на матрицу.
//! \param x первый множитель типа `Type`.
//! \param v второй множитель-матрица.
//! \return матрица, являющаяся результатом умножения.
template
inline PIMathMatrix operator*(const Type &x, const PIMathMatrix &v) {
return v * x;
}
typedef PIMathMatrix PIMathMatrixi;
typedef PIMathMatrix PIMathMatrixd;
//! \~english
//! \brief Searching hermitian matrix.
//! \param m conjugate transpose matrix.
//! \return result of the hermitian.
//! \~russian
//! \brief Поиск эрмитовой матрицы.
//! \param m сопряженная транспонированная матрица.
//! \return результат преобразования.
template
PIMathMatrix > hermitian(const PIMathMatrix > &m) {
PIMathMatrix > ret(m);
for (uint r = 0; r < ret.rows(); ++r)
for (uint c = 0; c < ret.cols(); ++c)
ret.element(r, c).imag(-(ret.element(r, c).imag()));
return ret.transposed();
}
#undef PIMM_FOR
#undef PIMM_FOR_A
#undef PIMM_FOR_C
#undef PIMM_FOR_R
#endif // PIMATHMATRIX_H