📄 mmat_05.cc
字号:
// file: $isip/class/math/matrix/MMatrix/mmat_05.cc// version: $Id: mmat_05.cc,v 1.30 2002/03/15 23:29:56 zheng Exp $//// isip include files//#include "MMatrixMethods.h"#include "MMatrix.h"template<class TScalar, class TIntegral>////template<class TScalar, class TIntegral, class TAIntegral>boolean MMatrixMethods::assignComplexDiagnose( MMatrix<TScalar, TIntegral>& this_a, long nrows_a, long ncols_a, const double* mdata_a, Integral::MTYPE type_a) { // create a vector from the input data // MVector<TScalar, TIntegral> vec; if (!vec.assign(this_a.vecLength(nrows_a, ncols_a, type_a), mdata_a)) { this_a.debug(L"this_a"); return Error::handle(name(), L"assign", Error::ARG, __FILE__, __LINE__); } MVector<TScalar, TIntegral> vec_imag; if (!vec_imag.assign(this_a.vecLength(nrows_a, ncols_a, type_a), this_a.vecLength(nrows_a, ncols_a, type_a) + mdata_a)) { this_a.debug(L"this_a"); return Error::handle(name(), L"assign", Error::ARG, __FILE__, __LINE__); } #ifdef ISIP_TEMPLATE_complex vec_imag.mult(TIntegral(0, 1)); vec.add(vec_imag);#endif // call the assign stream method to actually do the matrix assign // return this_a.assignStream(nrows_a, ncols_a, vec, (Integral::MTYPE)type_a);}// explicit instantiations//template booleanMMatrixMethods::assignComplexDiagnose<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const double*, Integral::MTYPE);// method: assignStream//// arguments:// MMatrix<TScalar, TIntegral>& this: (output) class operand// long nrows: (input) number of rows// long ncols: (input) number of columns// const MVector<TScalar, TIntegral>& vec: (input) vector containing the data// Integral::MTYPE type: (input) type of matrix//// return: a boolean value indicating status//// this method assigns the matrix from a stream of data stored in a vector.//template<class TScalar, class TIntegral>boolean MMatrixMethods::assignStream(MMatrix<TScalar, TIntegral>& this_a, long nrows_a, long ncols_a, const MVector<TScalar, TIntegral>& vec_a, Integral::MTYPE type_a) { // set the dimensions of the current matrix to create space // if (!this_a.setDimensions(nrows_a, ncols_a, false, type_a)) { return false; } // type: FULL, DIAGONAL, SYMMETRIC, or LOWER_TRIANGULAR // just assign the vector directly // if ((this_a.type_d == Integral::DIAGONAL) || (this_a.type_d == Integral::FULL) || (this_a.type_d == Integral::SYMMETRIC) || (this_a.type_d == Integral::LOWER_TRIANGULAR)) { this_a.m_d.assign(vec_a); } // type: UPPER_TRIANGULAR // we input the elements of upper triangular matrix in row order, but we // store them in column order. // else if (this_a.type_d == Integral::UPPER_TRIANGULAR) { for (long row = 0, index = 0; row < nrows_a; row++) { for (long col = row; col < ncols_a; col++) { this_a.m_d(this_a.index(row, col)) = vec_a(index++); } } } // type: SPARSE // assign only non-zero elements to the vector // else if (this_a.type_d == Integral::SPARSE) { // get the number of non-zero elements in the input vector // long len = vec_a.length(); long count = vec_a.numNotEqual(0); // create space to hold the values // this_a.m_d.setLength(count); this_a.row_index_d.setLength(count); this_a.col_index_d.setLength(count); // loop over length of sparse vectors and assign non-zero values // and corresponding row and column indices // for (long i = 0, index = 0; i < len; i++) { if ((TIntegral)vec_a(i) != 0) { this_a.m_d(index) = vec_a(i); this_a.row_index_d(index) = i / ncols_a; this_a.col_index_d(index) = i % ncols_a; index++; } } } // exit gracefully // return true;}// explicit instantiations//template booleanMMatrixMethods::assignStream<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const MVector<ISIP_TEMPLATE_TARGET>&, Integral::MTYPE);// method: assign//// arguments:// MMatrix<TScalar, TIntegral>& this: (output) class operand// const MMatrix<TAScalar, TAIntegral>& arg: (input) matrix to copy//// return: a boolean value indicating status//// this method assigns all the elements of the source matrix to the// current matrix, including type of matrix.//template <class TScalar, class TIntegral, class TAScalar, class TAIntegral>boolean MMatrixMethods::assign(MMatrix<TScalar, TIntegral>& this_a, const MMatrix<TAScalar, TAIntegral>& arg_a) { // if the matrices are the same object, we are done. note that the // comparison uses void* to get around the issue of comparing a // MatrixFloat to a MatrixDouble, assuming that if the *this pointer // is the same for the objects then the actual objects are the same. // if ((void*)&this_a == (void*)&arg_a) { return true; } // set the type of the current matrix to be same as that of the input matrix // this_a.type_d = arg_a.type_d; // assign each data element // return (this_a.m_d.assign(arg_a.m_d) && this_a.nrows_d.assign(arg_a.nrows_d) && this_a.ncols_d.assign(arg_a.ncols_d) && this_a.row_index_d.assign(arg_a.row_index_d) && this_a.col_index_d.assign(arg_a.col_index_d));}// explicit instantiations//template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET, Byte, byte>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Byte, byte>&);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET, Ushort, ushort>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Ushort, ushort>&);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET, Ulong, ulong>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Ulong, ulong>&);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET, Ullong, ullong>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Ullong, ullong>&);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET, Short, short>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Short, short>&);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET, Long, long>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Long, long>&);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET, Llong, llong>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Llong, llong>&);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET, Float, float>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Float, float>&);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET, Double, double>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Double, double>&);#ifdef ISIP_TEMPLATE_complextemplate booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET, ComplexDouble, complexdouble>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ComplexDouble, complexdouble>&);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET, ComplexFloat, complexfloat>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ComplexFloat, complexfloat>&);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET, ComplexLong, complexlong>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ComplexLong, complexlong>&);#endif// method: assign//// arguments:// MMatrix<TScalar, TIntegral>& this: (output) class operand// long nrows: (input) number of rows// long ncols: (input) number of columns// const TAIntegral* mdata: (input) matrix data// Integral::MTYPE type: (input) matrix type//// return: a boolean value indicating status//// this method assigns the matrix from a TAIntegral array//template<class TScalar, class TIntegral, class TAIntegral>boolean MMatrixMethods::assign(MMatrix<TScalar, TIntegral>& this_a, long nrows_a, long ncols_a, const TAIntegral* mdata_a, Integral::MTYPE type_a) { // create a vector from the input data // MVector<TScalar, TIntegral> vec; if (!vec.assign(this_a.vecLength(nrows_a, ncols_a, type_a), mdata_a)) { this_a.debug(L"this_a"); return Error::handle(name(), L"assign", Error::ARG, __FILE__, __LINE__); } // call the assign stream method to actually do the matrix assign // return this_a.assignStream(nrows_a, ncols_a, vec, (Integral::MTYPE)type_a);}// explicit instantiations//template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const byte*, Integral::MTYPE);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const ushort*, Integral::MTYPE);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const ulong*, Integral::MTYPE);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const ullong*, Integral::MTYPE);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const short*, Integral::MTYPE);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const long*, Integral::MTYPE);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const llong*, Integral::MTYPE);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const float*, Integral::MTYPE);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const double*, Integral::MTYPE);#ifdef ISIP_TEMPLATE_complextemplate booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const complexlong*, Integral::MTYPE);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const complexfloat*, Integral::MTYPE);template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const complexdouble*, Integral::MTYPE);#endif// method: assign//// arguments:// MMatrix<TScalar, TIntegral>& this: (output) class operand// long nrows: (input) number of rows// long ncols: (input) number of columns// const String* mdata: (input) matrix data// Integral::MTYPE type: (input) matrix type//// return: a boolean value indicating status//// this method assigns the matrix from an array of String objects.//template<class TScalar, class TIntegral>boolean MMatrixMethods::assign(MMatrix<TScalar, TIntegral>& this_a, long nrows_a, long ncols_a, const String* mdata_a, Integral::MTYPE type_a) { // create a temporary copy of the input // MVector<TScalar, TIntegral> vec; if (!vec.assign(this_a.vecLength(nrows_a, ncols_a, type_a), mdata_a)) { this_a.debug(L"this_a"); return Error::handle(name(), L"assign", Error::ARG, __FILE__, __LINE__); } // call the assign stream method to actually do the matrix assign // return this_a.assignStream(nrows_a, ncols_a, vec, (Integral::MTYPE)type_a);}// explicit instantiations//template booleanMMatrixMethods::assign<ISIP_TEMPLATE_TARGET>(MMatrix<ISIP_TEMPLATE_TARGET>&, long, long, const String*, Integral::MTYPE);// method: assign//// arguments:// MMatrix<TScalar, TIntegral>& this: (output) class operand// long nrows: (input) number of rows// long ncols: (input) number of columns// const String& str: (input) string of data// Integral::MTYPE type: (input) matrix type// const Char delim: (input) delimiter character//// return: a boolean value indicating status//// this method creates a matrix from a String object.//template<class TScalar, class TIntegral>boolean MMatrixMethods::assign(MMatrix<TScalar, TIntegral>& this_a, long nrows_a, long ncols_a, const String& str_a, Integral::MTYPE type_a, const Char delim_a) { // get the number of elements in the matrix and length of string
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -