⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmat_08.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 4 页
字号:
        }        for (long col = row; col < ncols; col++) {          this_a.m_d(this_a.index(row, col)) =	    (TScalar)((TIntegral)(m2_a.m_d(col)) *		      (TIntegral)(m1_a.m_d(m1_a.index(col, row))));        }      }    }    // type2: FULL, SYMMETRIC, LOWER_TRIANGULAR, UPPER_TRIANGULAR    //  set the type of output matrix as full, and multiply elements in the    //  given row of the first matrix with the elements in the given column    //  of the second matrix.    //    else if ((type2 == Integral::FULL) ||	     (type2 == Integral::SYMMETRIC) ||	     (type2 == Integral::LOWER_TRIANGULAR) ||	     (type2 == Integral::UPPER_TRIANGULAR)) {      // create space in the output matrix      //      this_a.setDimensions(nrows, ncols, false, Integral::FULL);            // loop through over elements      //            for (long row = 0; row < nrows; row++) {        for (long col = 0; col < ncols; col++) {            this_a.m_d(this_a.index(row, col)) =             this_a.multiplyRowByRow(m1_a, m2_a, row, col);        }      }          }    // type2: SPARSE    //  set the type of output matrix as full.     //    else if (type2 == Integral::SPARSE) {      // create space in the output matrix      //      this_a.setDimensions(nrows, ncols, false, Integral::FULL);      this_a.clear(Integral::RETAIN);             // declare local variables      //      long b_row;      long b_col;      TAIntegral b_val;      TIntegral c_val = 0;      TIntegral sub_val = 0;      long length = m2_a.m_d.length();      // loop over the values of the sparse matrix and multiply      //      for (long b_index = 0; b_index < length; b_index++) {        b_row = m2_a.row_index_d(b_index);        b_col = m2_a.col_index_d(b_index);        b_val = m2_a.m_d(b_index);        long a_rows = m1_a.getNumRows();        for (long a_index = 0; a_index < a_rows; a_index++) {          c_val = this_a.getValue(a_index, b_row);          sub_val = (TIntegral)((TAIntegral)b_val *				m1_a.getValue(a_index, b_col));          this_a.setValue(a_index, b_row, c_val + sub_val);        }      }    }  }  // type1: LOWER_TRIANGULAR  //  else if (type1 == Integral::LOWER_TRIANGULAR) {    // type2: DIAGONAL    //  set the type of output matrix as full.    //    if (type2 ==  Integral::DIAGONAL) {      // create space in the output matrix      //      this_a.setDimensions(m1_a, false, Integral::LOWER_TRIANGULAR);            // loop over each element      //      for (long row = 0; row < nrows; row++) {        for (long col = 0; col <= row; col++) {          this_a.m_d(this_a.index(row, col)) =	    (TScalar)((TIntegral)((TIntegral)m2_a.m_d(col) *		      (TIntegral)(m1_a.m_d(m1_a.index(row, col)))));        }      }    }          // type2: FULL, SYMMETRIC, LOWER_TRIANGULAR, UPPER_TRIANGULAR    //  set the type of output matrix as full, and multiply elements in the    //  given row of the first matrix with the elements in the given column    //  of the second matrix.    //    else if ((type2 == Integral::FULL) ||	     (type2 == Integral::SYMMETRIC) ||	     (type2 == Integral::LOWER_TRIANGULAR) ||      	     (type2 == Integral::UPPER_TRIANGULAR)) {      // create space in the output matrix      //      this_a.setDimensions(nrows, ncols, false, Integral::FULL);            // loop over all elements      //      for (long row = 0; row < nrows; row++) {        for (long col = 0; col < ncols; col++) {            this_a.m_d(this_a.index(row, col)) =             this_a.multiplyRowByRow(m1_a, m2_a, row, col);        }      }          }    // type2: SPARSE    //  set the type of output matrix as full.    //    else if (type2 == Integral::SPARSE) {      // create space in the output matrix      //            this_a.setDimensions(nrows, ncols, false, Integral::FULL);      this_a.clear(Integral::RETAIN);             // declare local variables      //      long b_row;      long b_col;      TAIntegral b_val;      TIntegral c_val = 0;      TIntegral sub_val = 0;      long length = m2_a.m_d.length();      // loop over the elements of sparse matrix, get the row index,      // column index and value of the element, then multiply it with      // corresponding element in the first matrix      //      for (long b_index = 0; b_index < length; b_index++) {        b_row = m2_a.row_index_d(b_index);        b_col = m2_a.col_index_d(b_index);        b_val = m2_a.m_d(b_index);        long a_rows = m1_a.getNumRows();        for (long a_index = 0; a_index < a_rows; a_index++) {          c_val = this_a.getValue(a_index, b_row);          sub_val = (TIntegral)((TAIntegral)b_val *				m1_a.getValue(a_index, b_col));          this_a.setValue(a_index, b_row, c_val + sub_val);        }      }    }      }  // type1: UPPER_TRIANGULAR  //  else if (type1 == Integral::UPPER_TRIANGULAR) {    // type2: DIAGONAL    //  set the type of output matrix as lower triangular.    //    if (type2 == Integral::DIAGONAL) {      // create space in the output matrix      //      this_a.setDimensions(nrows, ncols, false, Integral::UPPER_TRIANGULAR);      // loop over each element      //      for (long row = 0; row < nrows; row++) {        for (long col = row; col < ncols; col++) {          this_a.m_d(this_a.index(row, col)) =	    (TScalar)((TIntegral)m2_a.m_d(col) *		      (TIntegral)(m1_a.m_d(m1_a.index(row, col))));        }      }    }    // type2: FULL, SYMMETRIC, LOWER_TRIANGULAR, UPPER_TRIANGULAR    //  set the type of output matrix as full.    //    else if ((type2 == Integral::FULL) ||	     (type2 == Integral::SYMMETRIC) ||	     (type2 == Integral::LOWER_TRIANGULAR) ||      	     (type2 == Integral::UPPER_TRIANGULAR)) {      // create space in the output matrix      //      this_a.setDimensions(nrows, ncols, false, Integral::FULL);            // multiply elements in the given row of the first matrix with the      // elements in the given column of the second matrix      //      for (long row = 0; row < nrows; row++) {        for (long col = 0; col < ncols; col++) {            this_a.m_d(this_a.index(row, col)) =             this_a.multiplyRowByRow(m1_a, m2_a, row, col);        }      }          }    // type2: SPARSE    //  set the type of output matrix as full.    //    else if (type2 == Integral::SPARSE) {      // create space in the output matrix      //            this_a.setDimensions(nrows, ncols, false, Integral::FULL);      this_a.clear(Integral::RETAIN);             // declare local variables      //      long b_row;      long b_col;      TAIntegral b_val;      TIntegral c_val = 0;      TIntegral sub_val = 0;      long length = m2_a.m_d.length();      // loop over the elements of sparse matrix, get the row index,      // column index and value of the element, then multiply it with      // corresponding element in the first matrix      //      for (long b_index = 0; b_index < length; b_index++) {        b_row = m2_a.row_index_d(b_index);        b_col = m2_a.col_index_d(b_index);        b_val = m2_a.m_d(b_index);        long a_rows = m1_a.getNumRows();        for (long a_index = 0; a_index < a_rows; a_index++) {          c_val = this_a.getValue(a_index, b_row);          sub_val = (TIntegral)((TAIntegral)b_val *				m1_a.getValue(a_index, b_col));          this_a.setValue(a_index, b_row, c_val + sub_val);        }      }    }      }  // type1: SPARSE  //  else if (type1 == Integral::SPARSE) {    // type2: DIAGONAL    //  set the type of output matrix as sparse    //    if (type2 == Integral::DIAGONAL) {      // create space in the output matrix      //            this_a.setDimensions(nrows, ncols, false, Integral::FULL);      this_a.clear(Integral::RETAIN);      // declare local variables      //      long row1 = 0;      long col1 = 0;      TAIntegral val2 = 0;      TIntegral val1 = 0;            // get the number of rows of the second matrix and the length of      // vector of sparse matrix      //      long len2 = m2_a.getNumColumns();      long len1 = m1_a.m_d.length();      // loop over the number of rows of second matrix      //      for (long col2 = 0; col2 < len2; col2++) {        val2 = m2_a.m_d(col2);        for (long index = 0; index < len1; index++) {          row1 = m1_a.row_index_d(index);          col1 = m1_a.col_index_d(index);          val1 = m1_a.m_d(index);          // if the row index matches with position of diag vector          // elements, multiply them          //          if (col2 == col1) {            this_a.setValue(row1, col2, (TIntegral)(val1 * val2));          }        }      }      // result should be sparse matrix      //      this_a.changeType(Integral::SPARSE);    }    // type2: FULL, SYMMETRIC, LOWER_TRIANGULAR, UPPER_TRIANGULAR    //  set the type of output matrix as full    //    else if ((type2 == Integral::FULL) ||	     (type2 == Integral::SYMMETRIC) ||	     (type2 == Integral::LOWER_TRIANGULAR) ||      	     (type2 == Integral::UPPER_TRIANGULAR)) {      // create space in the output matrix      //      this_a.setDimensions(nrows, ncols, false, Integral::FULL);      this_a.clear(Integral::RETAIN);             // declare local variables      //      long a_row;      long a_col;      TIntegral a_val;      TIntegral c_val = 0;      TIntegral sub_val = 0;      long length = m1_a.m_d.length();      // loop over the values of the sparse matrix      //      for (long a_index = 0; a_index < length; a_index++) {	// get the row index, column index and value	//        a_row = m1_a.row_index_d(a_index);        a_col = m1_a.col_index_d(a_index);        a_val = m1_a.m_d(a_index);	// row of first matrix should be the same as the row in	// the second matrix	//        long b_rows = m2_a.getNumRows();        // loop over the columns of the second matrix	//        for (long b_index = 0; b_index < b_rows; b_index++) {          c_val = this_a.getValue(a_row, b_index);          sub_val = (TIntegral)((TIntegral)a_val *				(TAIntegral)m2_a.getValue(b_index, a_col));          this_a.setValue(a_row, b_index, c_val + sub_val);        }      }    }    // type2: SPARSE    //  set the type of output matrix as sparse    //    else if (type2 == Integral::SPARSE) {      // temporary matrix is required      //      MMatrix<TScalar, TIntegral> temp(nrows, ncols);      temp.clear(Integral::RETAIN);      // temporary variables      //      long row1;      long row2;      long col1;      long col2;      TIntegral value;            // loop over elements of the first matrix      //      for (long i = 0; i < m1_a.m_d.length(); i++) {                // loop over elements of second matrix        //        for (long j = 0; j < m2_a.m_d.length(); j++) {                    // compare the respective column and row indices          //	  row1 = m1_a.row_index_d(i);	  row2 = m2_a.row_index_d(j);	  col1 = m1_a.col_index_d(i);	  col2 = m2_a.col_index_d(j);          if (col1 == col2) {                        // multiply the elements and store them in a temporary matrix            //            value = temp.getValue(row1, row2) +              (TIntegral)((TIntegral)m1_a.m_d(i) * (TAIntegral)m2_a.m_d(j));            temp.setValue(row1, row2, value);          }        }      }      // copy the result to the current matrix      //      this_a.assign(temp, Integral::SPARSE);    }  }  // restore the type if possible  //  if (this_a.isTypePossible(old_type)) {    return this_a.changeType(old_type);  }  else {    return this_a.changeType(Integral::FULL);  }}// explicit instantiations//#ifndef ISIP_TEMPLATE_complextemplate booleanMMatrixMethods::outerProduct<ISIP_TEMPLATE_TARGET, Byte, byte>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Byte, byte>&);template booleanMMatrixMethods::outerProduct<ISIP_TEMPLATE_TARGET, Ushort, ushort>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Ushort, ushort>&);template booleanMMatrixMethods::outerProduct<ISIP_TEMPLATE_TARGET, Ulong, ulong>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Ulong, ulong>&);template booleanMMatrixMethods::outerProduct<ISIP_TEMPLATE_TARGET, Ullong, ullong>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Ullong, ullong>&);template booleanMMatrixMethods::outerProduct<ISIP_TEMPLATE_TARGET, Short, short>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Short, short>&);template booleanMMatrixMethods::outerProduct<ISIP_TEMPLATE_TARGET, Long, long>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Long, long>&);template booleanMMatrixMethods::outerProduct<ISIP_TEMPLATE_TARGET, Llong, llong>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Llong, llong>&);template booleanMMatrixMethods::outerProduct<ISIP_TEMPLATE_TARGET, Float, float>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Float, float>&);template booleanMMatrixMethods::outerProduct<ISIP_TEMPLATE_TARGET, Double, double>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<Double, double>&);#endif#ifdef ISIP_TEMPLATE_complextemplate booleanMMatrixMethods::outerProduct<ISIP_TEMPLATE_TARGET, ComplexLong, complexlong>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ComplexLong, complexlong>&);template booleanMMatrixMethods::outerProduct<ISIP_TEMPLATE_TARGET, ComplexFloat, complexfloat>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ComplexFloat, complexfloat>&); template booleanMMatrixMethods::outerProduct<ISIP_TEMPLATE_TARGET, ComplexDouble, complexdouble>(MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ISIP_TEMPLATE_TARGET>&, const MMatrix<ComplexDouble, complexdouble>&);#endif// method: outerProduct//// arguments://  MMatrix<TScalar, TIntegral>& this: (output) class operand//  const MVector<TScalar, TIntegral>& v1: (input) operand 1//  const MVector<TAScalar, TAIntegral>& v2: (input) operand 2//// return: a boolean value indicating status//// this method computes the outer product of two column vectors. because the// outer product produces a full matrix, the output matrix type is// normally set to FULL. if the matrix is input as a SPARSE matrix, its// type is maintained however.//// example://                                                  [ 4  5  6  7]//  m1 = [1] m2 = [4]  m_out = m1 * transpose(m2) = [ 8 10 12 14]//       [2]      [5]                               [12 15 18 21]//       [3]      [6]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -