//----------------------------------------------------------------------------- // TestMatrixCopyConstructor //----------------------------------------------------------------------------- bool TestMatrixCopyConstructor() { Matrix A("1,2,3;4,5,6"); Matrix B( A ); return ApproxEqual(A,B,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixConstructorWithScalarFill //----------------------------------------------------------------------------- bool TestMatrixConstructorWithScalarFill() { Matrix A(2,3, 1.2); Matrix B("1.2,1.2,1.2;1.2,1.2,1.2"); return ApproxEqual(A,B,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixDimensionedConstructor //----------------------------------------------------------------------------- bool TestMatrixDimensionedConstructor() { Matrix A(2,3); Matrix B("0,0,0;0,0,0"); return ApproxEqual(A,B,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixConstructorWithStringFill //----------------------------------------------------------------------------- bool TestMatrixConstructorWithStringFill() { Matrix A("1,,;4,5,"); Matrix B("1,0,0;4,5,0"); return ApproxEqual(A,B,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixIdentity //----------------------------------------------------------------------------- bool TestMatrixIdentity() { Matrix A(3,2,1.0); Identity( A, 4 ); Matrix I("1,0,0,0; 0,1,0,0; 0,0,1,0; 0,0,0,1"); return ApproxEqual(A,I,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixScalarAssignment //----------------------------------------------------------------------------- bool TestMatrixScalarAssignment() { Matrix A("1,2,3;4,5,6"); A = 0.0; Matrix B("0,0,0;0,0,0"); return ApproxEqual(A,B,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixAssignmentOperator //----------------------------------------------------------------------------- bool TestMatrixAssignmentOperator() { Matrix A("1,2,3;4,5,6"); Matrix B("0,1,1,0"); B = A; return ApproxEqual(A,B,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixDestructiveResize //----------------------------------------------------------------------------- bool TestMatrixDestructiveResize() { Matrix A("1,2,3;4,5,6"); A.Resize(2,2); Matrix B("0,0;0,0"); return ApproxEqual(A,B,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixConstructorWithArrayFill //----------------------------------------------------------------------------- bool TestMatrixConstructorWithArrayFill() { double A_data[] = {1.0,2.0,3.0,4.0,5.0,6.0}; Matrix A(2,3, A_data); Matrix B("1,2,3;4,5,6"); return ApproxEqual(A,B,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixRowSum //----------------------------------------------------------------------------- bool TestMatrixRowSum() { Matrix A("1,2,3;4,5,6;7,8,9"); Matrix x; RowSum( A, x ); Matrix row_sum("6;15;24"); return ApproxEqual(x,row_sum,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixColumnSum //----------------------------------------------------------------------------- bool TestMatrixColumnSum() { Matrix A("1,2,3;4,5,6;7,8,9"); Matrix x; ColumnSum( A, x ); Matrix col_sum("12,15,18"); return ApproxEqual(x,col_sum,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixTranspose //----------------------------------------------------------------------------- bool TestMatrixTranspose() { Matrix A("1,2,3;4,5,6;7,8,9"); Matrix C; Transpose( A, C ); Matrix At("1,4,7; 2,5,8; 3,6,9"); return ApproxEqual(C,At,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixAdd_aM //----------------------------------------------------------------------------- bool TestMatrixAdd_aM() { Matrix A("1,2,3;4,5,6"); Matrix B; Add_aM(2,A,B); Matrix Ap2("3,4,5;6,7,8"); return ApproxEqual(B,Ap2,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixMultiply_aM //----------------------------------------------------------------------------- bool TestMatrixMultiply_aM() { Matrix A("1,2,3;4,5,6"); Matrix B; Multiply_aM(2,A,B); Matrix Ax2("2,4,6;8,10,12"); return ApproxEqual(B,Ax2,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixNegative //----------------------------------------------------------------------------- bool TestMatrixNegative() { Matrix A("1,2,3;4,5,6;7,8,9"); Matrix C; Negative( A, C ); Matrix B("-1,-2,-3;-4,-5,-6;-7,-8,-9"); return ApproxEqual(B,C,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixMultiply_MtMt //----------------------------------------------------------------------------- bool TestMatrixMultiply_MtMt() { Matrix A("1,4;2,5;3,6"); Matrix B("1,3,5;2,4,6"); Matrix C; Multiply_MtMt(A,B,C); Matrix AtxBt("22,28; 49,64"); return ApproxEqual(C,AtxBt,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixMultiply_MMt //----------------------------------------------------------------------------- bool TestMatrixMultiply_MMt() { Matrix A("1,2,3;4,5,6"); Matrix B("1,3,5;2,4,6"); Matrix C; Multiply_MMt(A,B,C); Matrix AxBt("22,28; 49,64"); return ApproxEqual(C,AxBt,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixMultiply_MtM //----------------------------------------------------------------------------- bool TestMatrixMultiply_MtM() { Matrix A("1,4;2,5;3,6"); Matrix B("1,2;3,4;5,6"); Matrix C; Multiply_MtM(A,B,C); Matrix AtxB("22,28; 49,64"); return ApproxEqual(C,AtxB,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixAdd_MM //----------------------------------------------------------------------------- bool TestMatrixAdd_MM() { Matrix A("1,2,3;4,5,6"); Matrix B("1,0,1;0,0,1"); Matrix C; Add_MM(A,B,C); Matrix ApB("2,2,4;4,5,7"); return ApproxEqual(C,ApB,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixQuadraticForm_MMM //----------------------------------------------------------------------------- bool TestMatrixQuadraticForm_MMM() { Matrix a("1,2,3"); Matrix B("1,2,3;4,5,6;7,8,9"); Matrix c("4;5;6"); double q = QuadraticForm_MMM(a,B,c); return ApproxEqual(q,552.0,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixSubtract_MM //----------------------------------------------------------------------------- bool TestMatrixSubtract_MM() { Matrix A("1,2,3;4,5,6"); Matrix B("1,0,1;0,0,1"); Matrix C; Subtract_MM(A,B,C); Matrix AmB("0,2,2;4,5,5"); return ApproxEqual(C,AmB,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixAccessToRawStorageWithOffset //----------------------------------------------------------------------------- bool TestMatrixAccessToRawStorageWithOffset() { Matrix A("1,2,3;4,5,6"); Matrix B(2,3); for (int i=0; i<2; ++i) for (int j=0; j<3; ++j) *B.Base(i,j) = *A.Base(i,j); return ApproxEqual(A,B,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixAccess //----------------------------------------------------------------------------- bool TestMatrixAccess() { Matrix A(2,3); Matrix B("1,2,3;4,5,6"); for (int i=0; i<2; ++i) for (int j=0; j<3; ++j) A(i,j) = B(i,j); return ApproxEqual(A,B,TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixAccessToRawStorage //----------------------------------------------------------------------------- bool TestMatrixAccessToRawStorage() { Matrix A("1,2,3;4,5,6"); Matrix B(2,3); const double* pA = A.Base(); double* pB = B.Base(); for (int i=0; i<6; ++i) *pB++ = *pA++; return ApproxEqual(A,B,TOLERANCE); }
void OnePole::ProcessHighpass(BufferOrVal& buf /*inout*/, sample_t approxEqualThresh) { if (buf.IsVal()) { sample_t val = buf.GetVal(); // If filter output memory (z1) is very close to input value, then don't need to process bool bSkipProcessing = ApproxEqual(val, sample_t(z1), approxEqualThresh); if (bSkipProcessing) { z1 = double(val); return; } buf.ConvertValToBuf(); } ProcessBufHighpass_(buf.GetBuf(), buf.GetBuf()); }
//----------------------------------------------------------------------------- // TestMatrixLInfNorm //----------------------------------------------------------------------------- bool TestMatrixLInfNorm() { Matrix A("1,2,3;4,5,6;7,8,9"); return ApproxEqual( LInfNorm(A), 24.0, TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixTrace //----------------------------------------------------------------------------- bool TestMatrixTrace() { Matrix A("1,2,3;4,5,6;7,8,9"); return ApproxEqual( Trace(A), 15.0, TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixMaxAbs //----------------------------------------------------------------------------- bool TestMatrixMaxAbs() { Matrix A("-1,2,-3;4,-5,6;-7,8,-9"); return ApproxEqual( MaxAbs(A), 9.0, TOLERANCE); }
//----------------------------------------------------------------------------- // TestMatrixFNorm //----------------------------------------------------------------------------- bool TestMatrixFNorm() { Matrix A("1,2,3;4,5,6;7,8,9"); return ApproxEqual( FNorm(A), 16.8819430161341, TOLERANCE); }