📄 mmat_06.cc
字号:
// file: $isip/class/math/matrix/MMatrix/mmat_06.cc// version: $Id: mmat_06.cc,v 1.31 2002/02/27 20:54:25 alphonso Exp $//// isip include files//#include "MMatrixMethods.h"#include "MMatrix.h"// method: gt//// arguments:// const MMatrix<TScalar, TIntegral>& this: (output) class operand// TIntegral value: (input) operand//// return: a boolean value of true if all elements in the matrix are// greater than value//// this method checks if all the elements in the current matrix are// greater than the input value//template<class TScalar, class TIntegral>boolean MMatrixMethods::gt(const MMatrix<TScalar, TIntegral>& this_a, TIntegral value_a) { // type: FULL, SYMMETRIC // call the vector gt method for all the elements // if ((this_a.type_d == Integral::FULL) || (this_a.type_d == Integral::SYMMETRIC)) { return this_a.m_d.gt(value_a); } // type: DIAGONAL, LOWER_TRIANGULAR, UPPER_TRIANGULAR // check if the value being compared is less than 0 and if the non-zero // elements in the matrix are greater than the input value // else if ((this_a.type_d == Integral::DIAGONAL) || (this_a.type_d == Integral::LOWER_TRIANGULAR) || (this_a.type_d == Integral::UPPER_TRIANGULAR)) { // if the dimensions of one matrix are greater than 1, there must // be zero elements in this matrix because its type is diagonal or // triangular. the zero element(s) is obviously less than the input // value if the input value is greater than zero. Thus, // gt method should always return false in this situation // // note that the cast to double prevents a compiler warning. // if ((long)(this_a.nrows_d) > 1) {#ifndef ISIP_TEMPLATE_unsigned if ((TIntegral)0 <= value_a) {#endif return false;#ifndef ISIP_TEMPLATE_unsigned }#endif } // call the vector gt method for all the valid (diagonal, for diagonal // matrix, or triangular, for triangular matrix) elements in the matrix // return this_a.m_d.gt(value_a); } // type: SPARSE // check if the value being compared is less than 0 and if the non-zero // elements in the matrix are greater than the input value // else { // see if we have any zero elements // if (this_a.numEqual(0) > 0) { #ifndef ISIP_TEMPLATE_unsigned if ((TIntegral)0 <= value_a) {#endif return false;#ifndef ISIP_TEMPLATE_unsigned }#endif } // make sure all of the non-zero elements pass // return this_a.m_d.gt(value_a); }}// explicit instantiations//template booleanMMatrixMethods::gt<ISIP_TEMPLATE_TARGET>(const MMatrix<ISIP_TEMPLATE_TARGET>&, ISIP_TEMPLATE_T1);// method: lt//// arguments:// const MMatrix<TScalar, TIntegral>& this: (output) class operand// TIntegral value: (input) operand//// return: a boolean value of true if all elements in the matrix are// less than value//// this method checks if all the elements in the current matrix are// less than the input value//template<class TScalar, class TIntegral>boolean MMatrixMethods::lt(const MMatrix<TScalar, TIntegral>& this_a, TIntegral value_a) { // type: FULL, SYMMETRIC // call the vector gt method for all the elements // if ((this_a.type_d == Integral::FULL) || (this_a.type_d == Integral::SYMMETRIC)) { return this_a.m_d.lt(value_a); } // type: DIAGONAL, LOWER_TRIANGULAR, UPPER_TRIANGULAR // check if the value being compared is greater than 0 and if the non-zero // elements are less than the input value // else if ((this_a.type_d == Integral::DIAGONAL) || (this_a.type_d == Integral::LOWER_TRIANGULAR) || (this_a.type_d == Integral::UPPER_TRIANGULAR)) { // if the dimensions of one matrix are greater than 1, there must // be zero elements in this matrix because its type is diagonal or // triangular. the zero element(s) is obviously greater than or equal // to the input value if the input value is less than or equal to zero. // Thus, lt method should always return false in this situation // if ((TIntegral)(this_a.nrows_d) > 1) { if ((TIntegral)0 >= (TIntegral)value_a) { return false; } } // call the vector lt method for all the valid (diagonal, for diagonal // matrix, or triangular, for triangular matrix) elements in the matrix // return this_a.m_d.lt(value_a); } // type: SPARSE // for sparse matrix check if the value being compared is greater than 0 // and if the non-zero elements in the matrix are less than the input value // else { // see if we have any zero elements // if (this_a.numEqual(0) > 0) { if ((TIntegral)0 >= (TIntegral)value_a) { return false; } } // only check for non-zero elements // return this_a.m_d.lt(value_a); }}// explicit instantiations//template booleanMMatrixMethods::lt<ISIP_TEMPLATE_TARGET>(const MMatrix<ISIP_TEMPLATE_TARGET>&, ISIP_TEMPLATE_T1);// method: ge//// arguments:// const MMatrix<TScalar, TIntegral>& this: (output) class operand// TIntegral value: (input) operand//// return: a boolean value of true if all elements in the matrix are// greater than or equal to value//// this method checks if all the elements in the current matrix are// greater or equal in value to the input value//template<class TScalar, class TIntegral>boolean MMatrixMethods::ge(const MMatrix<TScalar, TIntegral>& this_a, TIntegral value_a) { // type: FULL, SYMMETRIC // call the vector ge method for all the elements // if ((this_a.type_d == Integral::FULL) || (this_a.type_d == Integral::SYMMETRIC)) { return this_a.m_d.ge(value_a); } // type: DIAGONAL, LOWER_TRIANGULAR, UPPER_TRIANGULAR // check if the value being compared is greater than 0 and if the non-zero // elements are greater than the input value // else if ((this_a.type_d == Integral::DIAGONAL) || (this_a.type_d == Integral::LOWER_TRIANGULAR) || (this_a.type_d == Integral::UPPER_TRIANGULAR)) { // if the dimensions of one matrix are greater than 1, there must // be zero elements in this matrix because its type is diagonal or // triangular. the zero element(s) is obviously less than the input // value if the input value is greater than zero. Thus, ge method // should always return false in this situation // if ((TIntegral)(this_a.nrows_d) > 1) { if ((TIntegral)0 < (TIntegral)value_a) { return false; } } // call the vector ge method for all the valid (diagonal, for diagonal // matrix, or triangular, for triangular matrix) elements in the matrix // return this_a.m_d.ge(value_a); } // type: SPARSE // for sparse matrix, check the non-zero values only // else { // see if we have any zero elements // if (this_a.numEqual(0) > 0) { if ((TIntegral)0 < (TIntegral)value_a) { return false; } } // make sure all of the non-zero elements pass // return this_a.m_d.ge(value_a); }}// explicit instantiations//template booleanMMatrixMethods::ge<ISIP_TEMPLATE_TARGET>(const MMatrix<ISIP_TEMPLATE_TARGET>&, ISIP_TEMPLATE_T1);// method: le//// arguments:// const MMatrix<TScalar, TIntegral>& this: (output) class operand// TIntegral value: (input) operand//// return: a boolean value of true if all elements in the matrix are// less than or equal to value//// this method checks if all elements in the current matrix are less than// or equal to the input value//template<class TScalar, class TIntegral>boolean MMatrixMethods::le(const MMatrix<TScalar, TIntegral>& this_a, TIntegral value_a) { // type: FULL, SYMMETRIC // call the vector le method for all the elements // if ((this_a.type_d == Integral::FULL) || (this_a.type_d == Integral::SYMMETRIC)) { return this_a.m_d.le(value_a); } // type: DIAGONAL, LOWER_TRIANGULAR, UPPER_TRIANGULAR // check if the value is less than 0 and if the non-zero elements are // less than the input value // else if ((this_a.type_d == Integral::DIAGONAL) || (this_a.type_d == Integral::LOWER_TRIANGULAR) || (this_a.type_d == Integral::UPPER_TRIANGULAR)) { // if the dimensions of one matrix are greater than 1, there must // be zero elements in this matrix because its type is diagonal or // triangular. the zero element(s) is obviously greater than the input // value if the input value is less than zero. Thus, le method // should always return false in this situation //#ifndef ISIP_TEMPLATE_unsigned if ((TIntegral)(this_a.nrows_d) > 1) { if ((TIntegral)0 > value_a) { return false; } }#endif // call the vector le method for all the valid (diagonal, for diagonal // matrix, or triangular, for triangular matrix) elements in the matrix // return this_a.m_d.le(value_a); } // type: SPARSE // for sparse matrix only check the non-zero values // else { // see if we have any zero elements //#ifndef ISIP_TEMPLATE_unsigned if (this_a.numEqual(0) > 0) { if ((TIntegral)0 > value_a) { return false; } }#endif // make sure all of the non-zero elements pass // return this_a.m_d.le(value_a); }}// explicit instantiations//template booleanMMatrixMethods::le<ISIP_TEMPLATE_TARGET>(const MMatrix<ISIP_TEMPLATE_TARGET>&, ISIP_TEMPLATE_T1);// method: eq//// arguments:// const MMatrix<TScalar, TIntegral>& this: (output) class operand// TIntegral value: (input) operand//// return: a boolean value of true if all elements in the matrix are// equal to value//// this method checks if all elements in the current matrix are equal to// the input value//template<class TScalar, class TIntegral>boolean MMatrixMethods::eq(const MMatrix<TScalar, TIntegral>& this_a, TIntegral value_a) { // type: FULL, SYMMETRIC // call the vector eq method for all the elements // if ((this_a.type_d == Integral::FULL) || (this_a.type_d == Integral::SYMMETRIC)) { return this_a.m_d.eq(value_a); } // type: DIAGONAL, LOWER_TRIANGULAR, UPPER_TRIANGULAR // test for diagonal, lower and upper triangular matrix // else if ((this_a.type_d == Integral::DIAGONAL) || (this_a.type_d == Integral::LOWER_TRIANGULAR) || (this_a.type_d == Integral::UPPER_TRIANGULAR)) { // if the dimensions of one matrix are greater than 1, there must // be zero elements in this matrix because its type is diagonal or // triangular. the zero element(s) is obviously not equal to the input // value if the input value is not zero. Thus, eq method should // always return false in this situation // if ((TIntegral)(this_a.nrows_d) > 1) { if ((TIntegral)0 != value_a) { return false; } } // call the vector eq method for all the valid (diagonal, for diagonal // matrix, or triangular, for triangular matrix) elements in the matrix // return this_a.m_d.eq(value_a); } // type: SPARSE // for sparse matrix only check the non-zero values // else { // if we have any zero elements, then the value_a must be 0 // if (this_a.numEqual(0) > 0) { if ((TIntegral)0 != value_a) { return false; } } // make sure all of the non-zero elements pass // return this_a.m_d.eq(value_a); }}// explicit instantiations//template booleanMMatrixMethods::eq<ISIP_TEMPLATE_TARGET>(const MMatrix<ISIP_TEMPLATE_TARGET>&, ISIP_TEMPLATE_T1);// method: numEqual//// arguments:// const MMatrix<TScalar, TIntegral>& this: (output) class operand// TIntegral value: (input) value to be tested//// return: a long value containing the number of elements equal to the// input element//// this method counts the number of elements in the current matrix// which are equal to the input value//template<class TScalar, class TIntegral>long MMatrixMethods::numEqual(const MMatrix<TScalar, TIntegral>& this_a, TIntegral value_a) { // type: FULL // count the number of elements equal to value_a // if (this_a.type_d == Integral::FULL) { return this_a.m_d.numEqual(value_a); } // type: DIAGONAL // else if (this_a.type_d == Integral::DIAGONAL) { // count the number of elements equal to value_a in the diagonal vector // long num_eq = this_a.m_d.numEqual(value_a); // if given value is 0, adding the number of 0 elements not in diagonal // if (value_a == 0) { num_eq += (long)( this_a.nrows_d) * ((long)(this_a.nrows_d) - 1); } // exit gracefully // return num_eq; } // type: SYMMETRIC // else if (this_a.type_d == Integral::SYMMETRIC) { // count the number of elements equal to value_a in the lower triangle // long num_eq = this_a.m_d.numEqual(value_a); num_eq += num_eq; // subtract the number of diagonal elements which is equal to value_a // from num_eq // for (long index = 0; index < this_a.nrows_d; index++) { if (this_a.m_d(this_a.index(index, index)) == value_a) { num_eq--; } } // exit gracefully // return num_eq; } // type: LOWER_TRIANGULAR, UPPER_TRIANGULAR // else if ((this_a.type_d == Integral::LOWER_TRIANGULAR) || (this_a.type_d == Integral::UPPER_TRIANGULAR)) { // count the number of elements equal to value_a in the vector // long num_eq = this_a.m_d.numEqual(value_a); // if value_a = 0, add the number of zero elements implied by the // other half of the matrix. this happens to be the length of // the data vector, m_d, minus the number of rows. // if (value_a == 0) { num_eq += this_a.m_d.length() - this_a.nrows_d; } // exit gracefully // return num_eq; } // type: SPARSE // else { // for non-zero value call the numEqual for value vector // if (value_a != 0) { return this_a.m_d.numEqual(value_a); } // else return the number of zeros in the matrix // long number = (this_a.nrows_d * this_a.ncols_d) - this_a.m_d.length(); // exit gracefully // return number; }}// explicit instantiations//template longMMatrixMethods::numEqual<ISIP_TEMPLATE_TARGET>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -