📄 mmat_00.cc
字号:
// type: UNKNOWN // this->debug(L"this"); return Error::handle(name(), L"stopRow", Error::ARG, __FILE__, __LINE__);}// method: startColumn//// arguments:// long row: (input) row index// Integral::MTYPE type_1: (input) matrix type// Integral::MTYPE type_2: (input) matrix type//// return: a long value containing the column index of the first// available element in a row// // this method is typically used when copying data from one matrix to// the other. it determines the first non-zero value is a given// row that needs to be copied into the destination matrix.// the rules implemented below can be summarized with the following table://// the rules implemented below can be summarized with the following table://// TYPE1 TYPE2// full diag symm ltri utri sprs// full 0 row 0 0 row 0// diag row row row row row row// symm 0 row 0 0 row 0// ltri 0 row 0 0 row 0// utri row row row row row row// sprs 0 row 0 0 row 0 //// this matrix should always be symmetric.//template<class TScalar, class TIntegral>long MMatrix<TScalar, TIntegral>::startColumn(long row_a, Integral::MTYPE type_1_a, Integral::MTYPE type_2_a) const { // check the arguments // if (type_2_a == Integral::UNCHANGED) { type_2_a = type_1_a; } // type1: FULL // if (type_1_a == Integral::FULL) { if (type_2_a == Integral::FULL) { return 0; } else if (type_2_a == Integral::DIAGONAL) { return row_a; } else if (type_2_a == Integral::SYMMETRIC) { return 0; } else if (type_2_a == Integral::LOWER_TRIANGULAR) { return 0; } else if (type_2_a == Integral::UPPER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::SPARSE) { return 0; } } // type_1: DIAGONAL // else if (type_1_a == Integral::DIAGONAL) { if (type_2_a == Integral::FULL) { return row_a; } else if (type_2_a == Integral::DIAGONAL) { return row_a; } else if (type_2_a == Integral::SYMMETRIC) { return row_a; } else if (type_2_a == Integral::LOWER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::UPPER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::SPARSE) { return row_a; } } // type_1: SYMMETRIC // else if (type_1_a == Integral::SYMMETRIC) { if (type_2_a == Integral::FULL) { return 0; } else if (type_2_a == Integral::DIAGONAL) { return row_a; } else if (type_2_a == Integral::SYMMETRIC) { return 0; } else if (type_2_a == Integral::LOWER_TRIANGULAR) { return 0; } else if (type_2_a == Integral::UPPER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::SPARSE) { return 0; } } // type_1: LOWER_TRIANGULAR // else if (type_1_a == Integral::LOWER_TRIANGULAR) { if (type_2_a == Integral::FULL) { return 0; } else if (type_2_a == Integral::DIAGONAL) { return row_a; } else if (type_2_a == Integral::SYMMETRIC) { return 0; } else if (type_2_a == Integral::LOWER_TRIANGULAR) { return 0; } else if (type_2_a == Integral::UPPER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::SPARSE) { return 0; } } // type_1: UPPER_TRIANGULAR // else if (type_1_a == Integral::UPPER_TRIANGULAR) { if (type_2_a == Integral::FULL) { return row_a; } else if (type_2_a == Integral::DIAGONAL) { return row_a; } else if (type_2_a == Integral::SYMMETRIC) { return row_a; } else if (type_2_a == Integral::LOWER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::UPPER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::SPARSE) { return row_a; } } // type_1: SPARSE // else if (type_1_a == Integral::SPARSE) { if (type_2_a == Integral::FULL) { return 0; } else if (type_2_a == Integral::DIAGONAL) { return row_a; } else if (type_2_a == Integral::SYMMETRIC) { return 0; } else if (type_2_a == Integral::LOWER_TRIANGULAR) { return 0; } else if (type_2_a == Integral::UPPER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::SPARSE) { return 0; } } // type: UNKNOWN // this->debug(L"this"); return Error::handle(name(), L"startColumn", Error::ARG, __FILE__, __LINE__);}// method: stopColumn//// arguments:// long row: (input) row index// Integral::MTYPE type_1: (input) matrix type// Integral::MTYPE type_2: (input) matrix type//// return: a long value containing the column index of the first// available element in a row// // this method is typically used when copying data from one matrix to// the other. it determines the last non-zero value is a given// column that needs to be copied into the destination matrix.// the rules implemented below can be summarized with the following table://// see startColumn for a general explanation of what this method does.// the rules implemented below can be summarized with the following table://// TYPE1 TYPE2// full diag symm ltri utri sprs// full ncols row ncols row ncols ncols// diag row row row row row row// symm ncols row row row nols ncols// ltri row row row row row row// utri ncols row ncols row ncols ncols// sprs ncols row ncols row ncols ncols //// this matrix should always be symmetric.//template<class TScalar, class TIntegral>long MMatrix<TScalar, TIntegral>::stopColumn(long row_a, Integral::MTYPE type_1_a, Integral::MTYPE type_2_a) const { // check the arguments // if (type_2_a == Integral::UNCHANGED) { type_2_a = type_1_a; } // type1: FULL // if (type_1_a == Integral::FULL) { if (type_2_a == Integral::FULL) { return (long)ncols_d - 1; } else if (type_2_a == Integral::DIAGONAL) { return row_a; } else if (type_2_a == Integral::SYMMETRIC) { return (long)ncols_d - 1; } else if (type_2_a == Integral::LOWER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::UPPER_TRIANGULAR) { return (long)ncols_d - 1; } else if (type_2_a == Integral::SPARSE) { return (long)ncols_d - 1; } } // type_1: DIAGONAL // else if (type_1_a == Integral::DIAGONAL) { if (type_2_a == Integral::FULL) { return row_a; } else if (type_2_a == Integral::DIAGONAL) { return row_a; } else if (type_2_a == Integral::SYMMETRIC) { return row_a; } else if (type_2_a == Integral::LOWER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::UPPER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::SPARSE) { return row_a; } } // type_1: SYMMETRIC // else if (type_1_a == Integral::SYMMETRIC) { if (type_2_a == Integral::FULL) { return (long)ncols_d - 1; } else if (type_2_a == Integral::DIAGONAL) { return row_a; } else if (type_2_a == Integral::SYMMETRIC) { return row_a; } else if (type_2_a == Integral::LOWER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::UPPER_TRIANGULAR) { return (long)ncols_d - 1; } else if (type_2_a == Integral::SPARSE) { return (long)ncols_d - 1; } } // type_1: LOWER_TRIANGULAR // else if (type_1_a == Integral::LOWER_TRIANGULAR) { if (type_2_a == Integral::FULL) { return row_a; } else if (type_2_a == Integral::DIAGONAL) { return row_a; } else if (type_2_a == Integral::SYMMETRIC) { return row_a; } else if (type_2_a == Integral::LOWER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::UPPER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::SPARSE) { return row_a; } } // type_1: UPPER_TRIANGULAR // else if (type_1_a == Integral::UPPER_TRIANGULAR) { if (type_2_a == Integral::FULL) { return (long)ncols_d - 1; } else if (type_2_a == Integral::DIAGONAL) { return row_a; } else if (type_2_a == Integral::SYMMETRIC) { return (long)ncols_d - 1; } else if (type_2_a == Integral::LOWER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::UPPER_TRIANGULAR) { return (long)ncols_d - 1; } else if (type_2_a == Integral::SPARSE) { return (long)ncols_d - 1; } } // type_1: SPARSE // else if (type_1_a == Integral::SPARSE) { if (type_2_a == Integral::FULL) { return (long)ncols_d - 1; } else if (type_2_a == Integral::DIAGONAL) { return row_a; } else if (type_2_a == Integral::SYMMETRIC) { return (long)ncols_d - 1; } else if (type_2_a == Integral::LOWER_TRIANGULAR) { return row_a; } else if (type_2_a == Integral::UPPER_TRIANGULAR) { return (long)ncols_d - 1; } else if (type_2_a == Integral::SPARSE) { return (long)ncols_d - 1; } } // type: UNKNOWN // this->debug(L"this"); return Error::handle(name(), L"stopColumn", Error::ARG, __FILE__, __LINE__);}// method: vecLength//// arguments:// long nrows: (input) number of rows// long ncols: (input) number of columns// Integral::MTYPE type: (input) type of the matrix//// return: a long value containing the length of the vector for a// matrix of a particular type//template<class TScalar, class TIntegral>long MMatrix<TScalar, TIntegral>::vecLength(long nrows_a, long ncols_a, Integral::MTYPE type_a) const { // type: UNCHANGED // if (type_a == Integral::UNCHANGED) { return vecLength(nrows_a, ncols_a, type_d); } // type: FULL // we store all elements // else if (type_a == Integral::FULL) { return nrows_a * ncols_a; } // type: DIAGONAL // we store only the diagonal elements // else if (type_a == Integral::DIAGONAL) { if (nrows_a == ncols_a) { return nrows_a; } } // type: SYMMETRIC, LOWER_TRIANGULAR, UPPER_TRIANGULAR // symmetric storage mode - matrices must be square // else if ((type_a == Integral::SYMMETRIC) || (type_a == Integral::LOWER_TRIANGULAR) || (type_a == Integral::UPPER_TRIANGULAR)) { if (nrows_a == ncols_a) { return (nrows_a * (nrows_a + 1) / 2); } } // type: SPARSE // else if (type_a == Integral::SPARSE) { return nrows_a * ncols_a; } // exit gracefully: // if we got this far, there was an error // this->debug(L"this"); Error::handle(name(), L"vecLength", Error::ARG, __FILE__, __LINE__); return -1;}// method: vecCreateLength//// arguments:// long nrows: (input) number of rows// long ncols: (input) number of columns// Integral::MTYPE type: (input) desired type//// return: a boolean value containing the status// // this method is a very specific method used to facilitate setDimensions.// it sets the length according to the type. it is typically used// when the type is changed, and old data needs to be destroyed.// old data is, by definition, destroyed.//template<class TScalar, class TIntegral>booleanMMatrix<TScalar, TIntegral>::vecCreateLength(long nrows_a, long ncols_a, Integral::MTYPE type_a) { // note that note that we only need to check for // a crossconnect between SPARSE and all other types, because // SPARSE uses a unique storage format. setLength will take care // of the rest. // // condition: new matrix is not SPARSE // action: delete space used by the SPARSE representation // if (type_a != Integral::SPARSE) { // free space // row_index_d.clear(Integral::RELEASE); col_index_d.clear(Integral::RELEASE); // allocate space // m_d.setLength(vecLength(nrows_a, ncols_a, type_a), false); } // condition: new matrix is SPARSE // action: delete space used by the non-SPARSE representation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -