680 lines
29 KiB
C++
680 lines
29 KiB
C++
/*
|
|
AUTOMATICALLY GENERATED FILE - DO NOT EDIT!
|
|
Please change MatrixNxN.py and re-run it
|
|
*/
|
|
/* Generated with ./MatrixNxN.py n = 2, TYPE = double */
|
|
|
|
#include "ZUnitTest.hpp"
|
|
#include <float.h>
|
|
#include <math.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <SST/SST_Mat22.h>
|
|
#include <SST/SST_Vec2.h>
|
|
|
|
|
|
|
|
|
|
static const char* testSST_Math_Mat22dAdd();
|
|
static const char* testSST_Math_Mat22dAddLocal();
|
|
static const char* testSST_Math_Mat22dSubtract();
|
|
static const char* testSST_Math_Mat22dSubtractLocal();
|
|
static const char* testSST_Math_Mat22dMultiplyElementwise();
|
|
static const char* testSST_Math_Mat22dMultiplyElementwiseLocal();
|
|
static const char* testSST_Math_Mat22dMultiplyScalar();
|
|
static const char* testSST_Math_Mat22dMultiplyScalarLocal();
|
|
static const char* testSST_Math_Mat22dMultiplyMatrix();
|
|
static const char* testSST_Math_Mat22dMultiplyMatrixLocal();
|
|
static const char* testSST_Math_Mat22dMultiplyVector();
|
|
static const char* testSST_Math_Mat22dMultiplyVectorLocal();
|
|
static const char* testSST_Math_Mat22dTranspose();
|
|
static const char* testSST_Math_Mat22dTransposeLocal();
|
|
static const char* testSST_Math_Mat22dDeterminant();
|
|
static const char* testSST_Math_Mat22dCheckOrthonormal();
|
|
static const char* testSST_Math_Mat22dInvert();
|
|
static const char* testSST_Math_Mat22dInvertLocal();
|
|
static const char* testSST_Math_Mat22dCreateLU();
|
|
static const char* testSST_Math_Mat22dCreateLULocal();
|
|
static const char* testSST_Math_Mat22dApplyLUMat();
|
|
static const char* testSST_Math_Mat22dApplyLUMatLocal();
|
|
static const char* testSST_Math_Mat22dApplyLUVec();
|
|
static const char* testSST_Math_Mat22dApplyLUVecLocal();
|
|
// List of unit tests
|
|
ZUnitTest SST_Math_Mat22dUnitTests[] =
|
|
{
|
|
{ "testSST_Math_Mat22dAdd " , testSST_Math_Mat22dAdd },
|
|
{ "testSST_Math_Mat22dAddLocal " , testSST_Math_Mat22dAddLocal },
|
|
{ "testSST_Math_Mat22dSubtract " , testSST_Math_Mat22dSubtract },
|
|
{ "testSST_Math_Mat22dSubtractLocal " , testSST_Math_Mat22dSubtractLocal },
|
|
{ "testSST_Math_Mat22dMultiplyElementwise " , testSST_Math_Mat22dMultiplyElementwise },
|
|
{ "testSST_Math_Mat22dMultiplyElementwiseLocal " , testSST_Math_Mat22dMultiplyElementwiseLocal },
|
|
{ "testSST_Math_Mat22dMultiplyScalar " , testSST_Math_Mat22dMultiplyScalar },
|
|
{ "testSST_Math_Mat22dMultiplyScalarLocal " , testSST_Math_Mat22dMultiplyScalarLocal },
|
|
{ "testSST_Math_Mat22dMultiplyMatrix " , testSST_Math_Mat22dMultiplyMatrix },
|
|
{ "testSST_Math_Mat22dMultiplyMatrixLocal " , testSST_Math_Mat22dMultiplyMatrixLocal },
|
|
{ "testSST_Math_Mat22dMultiplyVector " , testSST_Math_Mat22dMultiplyVector },
|
|
{ "testSST_Math_Mat22dMultiplyVectorLocal " , testSST_Math_Mat22dMultiplyVectorLocal },
|
|
{ "testSST_Math_Mat22dDeterminant " , testSST_Math_Mat22dDeterminant },
|
|
{ "testSST_Math_Mat22dCheckOrthonormal " , testSST_Math_Mat22dCheckOrthonormal },
|
|
{ "testSST_Math_Mat22dInvert " , testSST_Math_Mat22dInvert },
|
|
{ "testSST_Math_Mat22dInvertLocal " , testSST_Math_Mat22dInvertLocal },
|
|
{ "testSST_Math_Mat22dCreateLU " , testSST_Math_Mat22dCreateLU },
|
|
{ "testSST_Math_Mat22dCreateLULocal " , testSST_Math_Mat22dCreateLULocal },
|
|
{ "testSST_Math_Mat22dApplyLUMat " , testSST_Math_Mat22dApplyLUMat },
|
|
{ "testSST_Math_Mat22dApplyLUMatLocal " , testSST_Math_Mat22dApplyLUMatLocal },
|
|
{ "testSST_Math_Mat22dApplyLUVec " , testSST_Math_Mat22dApplyLUVec },
|
|
{ "testSST_Math_Mat22dApplyLUVecLocal " , testSST_Math_Mat22dApplyLUVecLocal },
|
|
{ "testSST_Math_Mat22dTranspose " , testSST_Math_Mat22dTranspose },
|
|
{ "testSST_Math_Mat22dTransposeLocal " , testSST_Math_Mat22dTransposeLocal }
|
|
};
|
|
DECLARE_ZTESTBLOCK(SST_Math_Mat22d)
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dAdd(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d Y; /* 2 x 2 matrix */
|
|
SST_Mat22d A; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = -13.000000000000000;
|
|
X.v[1] = 3.000000000000000;
|
|
X.v[2] = 3.000000000000000;
|
|
X.v[3] = 11.000000000000000;
|
|
Y.v[0] = -20.000000000000000;
|
|
Y.v[1] = 12.000000000000000;
|
|
Y.v[2] = 2.000000000000000;
|
|
Y.v[3] = -6.000000000000000;
|
|
/*
|
|
[[-13. 3.]
|
|
[ 3. 11.]]
|
|
[[-20. 2.]
|
|
[ 12. -6.]]
|
|
[[-33. 5.]
|
|
[ 15. 5.]]
|
|
*/
|
|
SST_Math_Mat22dAdd(&X,&Y,&A);
|
|
TASSERT(fabs((A.v[0])-( -33.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((A.v[2])-( 5.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((A.v[1])-( 15.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((A.v[3])-( 5.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dAddLocal(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d Y; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = 6.000000000000000;
|
|
X.v[1] = -18.000000000000000;
|
|
X.v[2] = 11.000000000000000;
|
|
X.v[3] = -16.000000000000000;
|
|
Y.v[0] = -1.000000000000000;
|
|
Y.v[1] = 12.000000000000000;
|
|
Y.v[2] = 14.000000000000000;
|
|
Y.v[3] = -5.000000000000000;
|
|
/*
|
|
[[ 6. 11.]
|
|
[-18. -16.]]
|
|
[[ -1. 14.]
|
|
[ 12. -5.]]
|
|
[[ 5. 25.]
|
|
[ -6. -21.]]
|
|
*/
|
|
SST_Math_Mat22dAddLocal(&X,&Y); /* for accuracy */
|
|
TASSERT(fabs((X.v[0])-( 5.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((X.v[2])-( 25.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((X.v[1])-( -6.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((X.v[3])-( -21.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dSubtract(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d Y; /* 2 x 2 matrix */
|
|
SST_Mat22d A; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = -5.000000000000000;
|
|
X.v[1] = -10.000000000000000;
|
|
X.v[2] = 6.000000000000000;
|
|
X.v[3] = 10.000000000000000;
|
|
Y.v[0] = -16.000000000000000;
|
|
Y.v[1] = 0.000000000000000;
|
|
Y.v[2] = -4.000000000000000;
|
|
Y.v[3] = -5.000000000000000;
|
|
/*
|
|
[[ -5. 6.]
|
|
[-10. 10.]]
|
|
[[-16. -4.]
|
|
[ 0. -5.]]
|
|
[[ 11. 10.]
|
|
[-10. 15.]]
|
|
*/
|
|
SST_Math_Mat22dSubtract(&X,&Y,&A);
|
|
TASSERT(fabs((A.v[0])-( 11.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((A.v[2])-( 10.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((A.v[1])-( -10.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((A.v[3])-( 15.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dSubtractLocal(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d Y; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = -7.000000000000000;
|
|
X.v[1] = 3.000000000000000;
|
|
X.v[2] = 4.000000000000000;
|
|
X.v[3] = -16.000000000000000;
|
|
Y.v[0] = 6.000000000000000;
|
|
Y.v[1] = 5.000000000000000;
|
|
Y.v[2] = -12.000000000000000;
|
|
Y.v[3] = -20.000000000000000;
|
|
/*
|
|
[[ -7. 4.]
|
|
[ 3. -16.]]
|
|
[[ 6. -12.]
|
|
[ 5. -20.]]
|
|
[[-13. 16.]
|
|
[ -2. 4.]]
|
|
*/
|
|
SST_Math_Mat22dSubtractLocal(&X,&Y); /* for accuracy */
|
|
TASSERT(fabs((X.v[0])-( -13.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((X.v[2])-( 16.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((X.v[1])-( -2.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((X.v[3])-( 4.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dMultiplyElementwise(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d Y; /* 2 x 2 matrix */
|
|
SST_Mat22d A; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = -12.000000000000000;
|
|
X.v[1] = 7.000000000000000;
|
|
X.v[2] = 6.000000000000000;
|
|
X.v[3] = -2.000000000000000;
|
|
Y.v[0] = -14.000000000000000;
|
|
Y.v[1] = 2.000000000000000;
|
|
Y.v[2] = -12.000000000000000;
|
|
Y.v[3] = -3.000000000000000;
|
|
/*
|
|
[[-12. 6.]
|
|
[ 7. -2.]]
|
|
[[-14. -12.]
|
|
[ 2. -3.]]
|
|
[[ 168. -72.]
|
|
[ 14. 6.]]
|
|
*/
|
|
SST_Math_Mat22dMultiplyElementwise(&X, &Y, &A);
|
|
TASSERT(fabs((A.v[0])-( 168.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((A.v[2])-( -72.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((A.v[1])-( 14.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((A.v[3])-( 6.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dMultiplyElementwiseLocal(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d Y; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = -11.000000000000000;
|
|
X.v[1] = 4.000000000000000;
|
|
X.v[2] = 17.000000000000000;
|
|
X.v[3] = -6.000000000000000;
|
|
Y.v[0] = 9.000000000000000;
|
|
Y.v[1] = -19.000000000000000;
|
|
Y.v[2] = -7.000000000000000;
|
|
Y.v[3] = 9.000000000000000;
|
|
/*
|
|
[[-11. 17.]
|
|
[ 4. -6.]]
|
|
[[ 9. -7.]
|
|
[-19. 9.]]
|
|
[[ -99. -119.]
|
|
[ -76. -54.]]
|
|
*/
|
|
SST_Math_Mat22dMultiplyElementwiseLocal(&X,&Y);
|
|
TASSERT(fabs((X.v[0])-( -99.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((X.v[2])-( -119.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((X.v[1])-( -76.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((X.v[3])-( -54.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dMultiplyScalar(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d A; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = 0.000000000000000;
|
|
X.v[1] = 7.000000000000000;
|
|
X.v[2] = 10.000000000000000;
|
|
X.v[3] = -15.000000000000000;
|
|
/*
|
|
[[ 0. 10.]
|
|
[ 7. -15.]]
|
|
[[ 0. 20.]
|
|
[ 14. -30.]]
|
|
*/
|
|
SST_Math_Mat22dMultiplyScalar(&X, 2.000000000000000,&A);
|
|
TASSERT(fabs((A.v[0])-( 0.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((A.v[2])-( 20.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((A.v[1])-( 14.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((A.v[3])-( -30.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dMultiplyScalarLocal(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = -16.000000000000000;
|
|
X.v[1] = -7.000000000000000;
|
|
X.v[2] = -14.000000000000000;
|
|
X.v[3] = 14.000000000000000;
|
|
/*
|
|
[[-16. -14.]
|
|
[ -7. 14.]]
|
|
[[-32. -28.]
|
|
[-14. 28.]]
|
|
*/
|
|
SST_Math_Mat22dMultiplyScalarLocal(&X, 2.000000000000000);
|
|
TASSERT(fabs((X.v[0])-( -32.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((X.v[2])-( -28.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((X.v[1])-( -14.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((X.v[3])-( 28.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dMultiplyMatrix(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d Y; /* 2 x 2 matrix */
|
|
SST_Mat22d A; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = 19.000000000000000;
|
|
X.v[1] = -14.000000000000000;
|
|
X.v[2] = -18.000000000000000;
|
|
X.v[3] = -16.000000000000000;
|
|
Y.v[0] = -11.000000000000000;
|
|
Y.v[1] = 11.000000000000000;
|
|
Y.v[2] = 19.000000000000000;
|
|
Y.v[3] = -19.000000000000000;
|
|
/*
|
|
X
|
|
[[ 19. -18.]
|
|
[-14. -16.]]
|
|
Y
|
|
[[-11. 19.]
|
|
[ 11. -19.]]
|
|
[[-407. 703.]
|
|
[ -22. 38.]]
|
|
*/
|
|
SST_Math_Mat22dMultiplyMatrix(&X,&Y,&A);
|
|
TASSERT(fabs((A.v[0])-( -407.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((A.v[2])-( 703.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((A.v[1])-( -22.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((A.v[3])-( 38.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dMultiplyMatrixLocal(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d Y; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = 4.000000000000000;
|
|
X.v[1] = -12.000000000000000;
|
|
X.v[2] = 6.000000000000000;
|
|
X.v[3] = 16.000000000000000;
|
|
Y.v[0] = -6.000000000000000;
|
|
Y.v[1] = -11.000000000000000;
|
|
Y.v[2] = -19.000000000000000;
|
|
Y.v[3] = -6.000000000000000;
|
|
/*
|
|
X
|
|
[[ 4. 6.]
|
|
[-12. 16.]]
|
|
Y
|
|
[[ -6. -19.]
|
|
[-11. -6.]]
|
|
X
|
|
[[ -90. -112.]
|
|
[-104. 132.]]
|
|
*/
|
|
SST_Math_Mat22dMultiplyMatrixLocal(&X,&Y);
|
|
TASSERT(fabs((X.v[0])-( -90.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((X.v[2])-( -112.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((X.v[1])-( -104.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((X.v[3])-( 132.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dMultiplyVector(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Vec2d v; /* 2 vector */
|
|
SST_Vec2d w; /* 2 vector */
|
|
/* Resetting test vectors / mats */
|
|
v.v[0] = 9.000000000000000;
|
|
v.v[1] = -10.000000000000000;
|
|
X.v[0] = 4.000000000000000;
|
|
X.v[1] = 5.000000000000000;
|
|
X.v[2] = -2.000000000000000;
|
|
X.v[3] = -8.000000000000000;
|
|
/*
|
|
X
|
|
[[ 4. -2.]
|
|
[ 5. -8.]]
|
|
v
|
|
[ 9. -10.]
|
|
w
|
|
[ 56. 125.]
|
|
*/
|
|
SST_Math_Mat22dMultiplyVector(&X,&v,&w);
|
|
TASSERT(fabs((w.v[0])-( 56.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry .v[0] failed!");
|
|
TASSERT(fabs((w.v[1])-( 125.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry .v[1] failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dMultiplyVectorLocal(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Vec2d v; /* 2 vector */
|
|
/* Resetting test vectors / mats */
|
|
v.v[0] = -5.000000000000000;
|
|
v.v[1] = -14.000000000000000;
|
|
X.v[0] = -13.000000000000000;
|
|
X.v[1] = -18.000000000000000;
|
|
X.v[2] = 18.000000000000000;
|
|
X.v[3] = 18.000000000000000;
|
|
/*
|
|
X
|
|
[[-13. 18.]
|
|
[-18. 18.]]
|
|
v
|
|
[ -5. -14.]
|
|
v
|
|
[-187. -162.]
|
|
*/
|
|
SST_Math_Mat22dMultiplyVectorLocal(&X,&v);
|
|
TASSERT(fabs((v.v[0])-( -187.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry .v[0] failed!");
|
|
TASSERT(fabs((v.v[1])-( -162.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry .v[1] failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dTranspose(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d A; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = 5.000000000000000;
|
|
X.v[1] = 10.000000000000000;
|
|
X.v[2] = -2.000000000000000;
|
|
X.v[3] = 17.000000000000000;
|
|
SST_Math_Mat22dTranspose(&X,&A);
|
|
TASSERT(fabs((A.v[0])-( 5.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((A.v[2])-( 10.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((A.v[1])-( -2.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((A.v[3])-( 17.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dTransposeLocal(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = 7.000000000000000;
|
|
X.v[1] = 13.000000000000000;
|
|
X.v[2] = -16.000000000000000;
|
|
X.v[3] = 1.000000000000000;
|
|
SST_Math_Mat22dTransposeLocal(&X);
|
|
TASSERT(fabs((X.v[0])-( 7.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((X.v[2])-( 13.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((X.v[1])-( -16.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((X.v[3])-( 1.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dCheckOrthonormal(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d Y; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = -17.000000000000000;
|
|
X.v[1] = -20.000000000000000;
|
|
X.v[2] = -3.000000000000000;
|
|
X.v[3] = -2.000000000000000;
|
|
Y.v[0] = 6.000000000000000;
|
|
Y.v[1] = 16.000000000000000;
|
|
Y.v[2] = 12.000000000000000;
|
|
Y.v[3] = 17.000000000000000;
|
|
/*
|
|
[[-0.64764842 -0.76193932]
|
|
[-0.76193932 0.64764842]]
|
|
[[ 1.00000000e+00 1.66533454e-16]
|
|
[ 1.66533454e-16 1.00000000e+00]]
|
|
*/
|
|
/* Set X to orthogonal matrix Q */
|
|
X.v[0] = (double) -0.647648420095541;
|
|
X.v[1] = (double) -0.761939317759459;
|
|
X.v[2] = (double) -0.761939317759459;
|
|
X.v[3] = (double) 0.647648420095540;
|
|
/* Check Positive Test */
|
|
TASSERT(SST_Math_Mat22dCheckOrthonormal(&X),"CheckOrthonormal failed when it should have passed");
|
|
/* Check Negative Test */
|
|
TASSERT(!SST_Math_Mat22dCheckOrthonormal(&Y),"CheckOrthonormal succeeded when it should have failed");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dDeterminant(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = -14.000000000000000;
|
|
X.v[1] = 0.000000000000000;
|
|
X.v[2] = -17.000000000000000;
|
|
X.v[3] = 9.000000000000000;
|
|
/* det(X) =
|
|
-126.0
|
|
*/
|
|
double result = SST_Math_Mat22dDeterminant(&X);
|
|
TASSERT(fabs( (result)/( -126.000000000000000) - 1.000000000000000 ) <= 100*DBL_EPSILON,"Determinant failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dInvert(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d B; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = -9.000000000000000;
|
|
X.v[1] = -16.000000000000000;
|
|
X.v[2] = 9.000000000000000;
|
|
X.v[3] = -15.000000000000000;
|
|
/*
|
|
[[-0.05376344 -0.03225806]
|
|
[ 0.05734767 -0.03225806]]
|
|
*/
|
|
SST_Math_Mat22dInvert(&X,&B);
|
|
TASSERT(fabs((B.v[0])-( -0.053763440860215)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((B.v[1])-( 0.057347670250896)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((B.v[2])-( -0.032258064516129)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((B.v[3])-( -0.032258064516129)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dInvertLocal(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
/* Resetting test vectors / mats */
|
|
X.v[0] = -10.000000000000000;
|
|
X.v[1] = 15.000000000000000;
|
|
X.v[2] = -5.000000000000000;
|
|
X.v[3] = -8.000000000000000;
|
|
/*
|
|
()
|
|
[[-0.0516129 0.03225806]
|
|
[-0.09677419 -0.06451613]]
|
|
*/
|
|
SST_Math_Mat22dInvertLocal(&X);
|
|
TASSERT(fabs((X.v[0])-( -0.051612903225806)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a11 failed!");
|
|
TASSERT(fabs((X.v[1])-( -0.096774193548387)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a21 failed!");
|
|
TASSERT(fabs((X.v[2])-( 0.032258064516129)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a12 failed!");
|
|
TASSERT(fabs((X.v[3])-( -0.064516129032258)) <=100*DBL_EPSILON /* yes this is bad */,"Entry _a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static const char* testSST_Math_Mat22dCreateLU(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d LU; /* 2 x 2 matrix */
|
|
X.v[0] = 2.000000000000000;
|
|
X.v[1] = -3.000000000000000;
|
|
X.v[2] = -1.000000000000000;
|
|
X.v[3] = 1.000000000000000;
|
|
SST_Math_Mat22dCreateLU(&X,&LU);
|
|
/*
|
|
[[ 2 -1]
|
|
[-3 1]]
|
|
*/
|
|
/*
|
|
[[ 2. 0. ]
|
|
[-3. -0.5]]
|
|
*/
|
|
/*
|
|
[[ 1. -0.5]
|
|
[ 0. 1. ]]
|
|
*/
|
|
TASSERT(fabs((LU.v[0])-( 2.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"L:Entry A_a11 failed!");
|
|
TASSERT(fabs((LU.v[2])-( -0.500000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"U:Entry B_a12 failed!");
|
|
TASSERT(fabs((LU.v[1])-( -3.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"L:Entry A_a21 failed!");
|
|
TASSERT(fabs((LU.v[3])-( -0.500000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"L:Entry A_a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
static const char* testSST_Math_Mat22dCreateLULocal(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
X.v[0] = 2.000000000000000;
|
|
X.v[1] = -3.000000000000000;
|
|
X.v[2] = -1.000000000000000;
|
|
X.v[3] = 1.000000000000000;
|
|
SST_Math_Mat22dCreateLULocal(&X);
|
|
TASSERT(fabs((X.v[0])-( 2.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"L:Entry A_a11 failed!");
|
|
TASSERT(fabs((X.v[2])-( -0.500000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"U:Entry B_a12 failed!");
|
|
TASSERT(fabs((X.v[1])-( -3.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"L:Entry A_a21 failed!");
|
|
TASSERT(fabs((X.v[3])-( -0.500000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"L:Entry A_a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
static const char* testSST_Math_Mat22dApplyLUMat(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d LU; /* 2 x 2 matrix */
|
|
SST_Mat22d I; /* 2 x 2 matrix */
|
|
X.v[0] = 2.000000000000000;
|
|
X.v[1] = -3.000000000000000;
|
|
X.v[2] = -1.000000000000000;
|
|
X.v[3] = 1.000000000000000;
|
|
SST_Math_Mat22dCreateLU(&X,&LU);
|
|
/*
|
|
[[ 2 -1]
|
|
[-3 1]]
|
|
*/
|
|
/*
|
|
[[ 2. 0. ]
|
|
[-3. -0.5]]
|
|
*/
|
|
/*
|
|
[[ 1. -0.5]
|
|
[ 0. 1. ]]
|
|
*/
|
|
TASSERT(fabs((LU.v[0])-( 2.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"L:Entry A_a11 failed!");
|
|
TASSERT(fabs((LU.v[2])-( -0.500000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"U:Entry B_a12 failed!");
|
|
TASSERT(fabs((LU.v[1])-( -3.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"L:Entry A_a21 failed!");
|
|
TASSERT(fabs((LU.v[3])-( -0.500000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"L:Entry A_a22 failed!");
|
|
SST_Math_Mat22dApplyLUMat(&LU,&X,&I);
|
|
TASSERT(fabs((I.v[0])-( 1.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"I:Entry I_a11 failed!");
|
|
TASSERT(fabs((I.v[1])-( 0.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"I:Entry I_a21 failed!");
|
|
TASSERT(fabs((I.v[2])-( 0.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"I:Entry I_a12 failed!");
|
|
TASSERT(fabs((I.v[3])-( 1.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"I:Entry I_a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
static const char* testSST_Math_Mat22dApplyLUMatLocal(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d Xinv; /* 2 x 2 matrix */
|
|
X.v[0] = 2.000000000000000;
|
|
X.v[1] = -3.000000000000000;
|
|
X.v[2] = -1.000000000000000;
|
|
X.v[3] = 1.000000000000000;
|
|
Xinv.v[0] = 2.000000000000000;
|
|
Xinv.v[1] = -3.000000000000000;
|
|
Xinv.v[2] = -1.000000000000000;
|
|
Xinv.v[3] = 1.000000000000000;
|
|
SST_Math_Mat22dCreateLULocal(&X);
|
|
TASSERT(fabs((X.v[0])-( 2.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"L:Entry A_a11 failed!");
|
|
TASSERT(fabs((X.v[2])-( -0.500000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"U:Entry B_a12 failed!");
|
|
TASSERT(fabs((X.v[1])-( -3.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"L:Entry A_a21 failed!");
|
|
TASSERT(fabs((X.v[3])-( -0.500000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"L:Entry A_a22 failed!");
|
|
SST_Math_Mat22dApplyLUMatLocal(&X,&Xinv);
|
|
TASSERT(fabs((Xinv.v[0])-( 1.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Xinv:Entry Xinv_a11 failed!");
|
|
TASSERT(fabs((Xinv.v[1])-( 0.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Xinv:Entry Xinv_a21 failed!");
|
|
TASSERT(fabs((Xinv.v[2])-( 0.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Xinv:Entry Xinv_a12 failed!");
|
|
TASSERT(fabs((Xinv.v[3])-( 1.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"Xinv:Entry Xinv_a22 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
static const char* testSST_Math_Mat22dApplyLUVec(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d LU; /* 2 x 2 matrix */
|
|
SST_Vec2d b; /* 2 x 2 vector */
|
|
SST_Vec2d x; /* 2 x 2 vector */
|
|
X.v[0] = 2.000000000000000;
|
|
X.v[1] = -3.000000000000000;
|
|
X.v[2] = -1.000000000000000;
|
|
X.v[3] = 1.000000000000000;
|
|
b.v[0] = 2.000000000000000;
|
|
b.v[1] = -1.000000000000000;
|
|
SST_Math_Mat22dCreateLU(&X,&LU);
|
|
SST_Math_Mat22dApplyLUVec(&LU,&b,&x);
|
|
TASSERT(fabs((x.v[0])-( -1.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"x:Entry x_a1 failed!");
|
|
TASSERT(fabs((x.v[1])-( -3.999999999999999)) <=100*DBL_EPSILON /* yes this is bad */,"x:Entry x_a2 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|
|
static const char* testSST_Math_Mat22dApplyLUVecLocal(){
|
|
SST_Mat22d X; /* 2 x 2 matrix */
|
|
SST_Mat22d LU; /* 2 x 2 matrix */
|
|
SST_Vec2d b; /* 2 x 2 vector */
|
|
X.v[0] = 2.000000000000000;
|
|
X.v[1] = -3.000000000000000;
|
|
X.v[2] = -1.000000000000000;
|
|
X.v[3] = 1.000000000000000;
|
|
b.v[0] = 2.000000000000000;
|
|
b.v[1] = -1.000000000000000;
|
|
SST_Math_Mat22dCreateLU(&X,&LU);
|
|
SST_Math_Mat22dApplyLUVecLocal(&LU,&b);
|
|
TASSERT(fabs((b.v[0])-( -1.000000000000000)) <=100*DBL_EPSILON /* yes this is bad */,"x:Entry x_a1 failed!");
|
|
TASSERT(fabs((b.v[1])-( -3.999999999999999)) <=100*DBL_EPSILON /* yes this is bad */,"x:Entry x_a2 failed!");
|
|
return ZTEST_SUCCESS;
|
|
}
|