/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */ /* Author(s): Anton Deguet Created on: 2004-11-17 (C) Copyright 2004-2026 Johns Hopkins University (JHU), All Rights Reserved. --- begin cisst license - do not edit --- This software is provided "as is" under an open source license, with no warranty. The complete license can be found in license.txt and http://www.cisst.org/cisst/license.txt. --- end cisst license --- */ #include "vctDynamicMatrixRefTest.h" #include "vctGenericContainerTest.h" #include "vctGenericMatrixTest.h" #include #include #include #include #include // this macro creates a matrix##number by reference and the // associatied storage based on SIZE and STRIDE##number #define CREATE_STORAGE_AND_REF(number) \ vctDynamicMatrix storage##number(6, 11); \ vctDynamicMatrixRef matrix##number; \ matrix##number.SetRef(3, 5, storage##number.row_stride() * 2, 2, storage##number.Pointer()) template void vctDynamicMatrixRefTest::TestAssignment(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); vctRandom(matrix1, value_type(-10), value_type(10)); vctGenericMatrixTest::TestAssignment(matrix1, matrix2); } void vctDynamicMatrixRefTest::TestAssignmentDouble(void) { TestAssignment(); } void vctDynamicMatrixRefTest::TestAssignmentFloat(void) { TestAssignment(); } void vctDynamicMatrixRefTest::TestAssignmentInt(void) { TestAssignment(); } template void vctDynamicMatrixRefTest::TestAccessMethods(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); vctRandom(matrix1, value_type(-10), value_type(10)); vctDynamicConstMatrixRef matrix2(matrix1.rows(), matrix1.cols(), matrix1.row_stride(), matrix1.col_stride(), matrix1.Pointer()); vctGenericMatrixTest::TestAccessMethods(matrix1, matrix2); } void vctDynamicMatrixRefTest::TestAccessMethodsDouble(void) { TestAccessMethods(); } void vctDynamicMatrixRefTest::TestAccessMethodsFloat(void) { TestAccessMethods(); } void vctDynamicMatrixRefTest::TestAccessMethodsInt(void) { TestAccessMethods(); } template void vctDynamicMatrixRefTest::TestSoMiOperations(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); vctRandom(matrix1, value_type(-10), value_type(10)); vctGenericContainerTest::TestSoCiOperations(matrix1, matrix2); } void vctDynamicMatrixRefTest::TestSoMiOperationsDouble(void) { TestSoMiOperations(); } void vctDynamicMatrixRefTest::TestSoMiOperationsFloat(void) { TestSoMiOperations(); } void vctDynamicMatrixRefTest::TestSoMiOperationsInt(void) { TestSoMiOperations(); } template void vctDynamicMatrixRefTest::TestSoMiMiOperations(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); CREATE_STORAGE_AND_REF(3); vctRandom(matrix1, value_type(-10), value_type(10)); vctRandom(matrix2, value_type(-10), value_type(10)); vctGenericContainerTest::TestSoCiCiOperations(matrix1, matrix2, matrix3); } void vctDynamicMatrixRefTest::TestSoMiMiOperationsDouble(void) { TestSoMiMiOperations(); } void vctDynamicMatrixRefTest::TestSoMiMiOperationsFloat(void) { TestSoMiMiOperations(); } void vctDynamicMatrixRefTest::TestSoMiMiOperationsInt(void) { TestSoMiMiOperations(); } template void vctDynamicMatrixRefTest::TestMioMiOperations(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); CREATE_STORAGE_AND_REF(3); vctRandom(matrix1, value_type(-10), value_type(10)); vctRandom(matrix2, value_type(-10), value_type(10)); RemoveQuasiZero(matrix2); vctGenericContainerTest::TestCioCiOperations(matrix1, matrix2, matrix3); } void vctDynamicMatrixRefTest::TestMioMiOperationsDouble(void) { TestMioMiOperations(); } void vctDynamicMatrixRefTest::TestMioMiOperationsFloat(void) { TestMioMiOperations(); } void vctDynamicMatrixRefTest::TestMioMiOperationsInt(void) { TestMioMiOperations(); } template void vctDynamicMatrixRefTest::TestMioSiMiOperations(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); CREATE_STORAGE_AND_REF(3); vctRandom(matrix1, value_type(-10), value_type(10)); vctRandom(matrix2, value_type(-10), value_type(10)); RemoveQuasiZero(matrix2); value_type scalar; vctRandom(matrix1, value_type(-10), value_type(10)); cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-10), value_type(10), scalar); vctGenericContainerTest::TestCioSiCiOperations(matrix1, scalar, matrix2, matrix3); } void vctDynamicMatrixRefTest::TestMioSiMiOperationsDouble(void) { TestMioSiMiOperations(); } void vctDynamicMatrixRefTest::TestMioSiMiOperationsFloat(void) { TestMioSiMiOperations(); } void vctDynamicMatrixRefTest::TestMioSiMiOperationsInt(void) { TestMioSiMiOperations(); } template void vctDynamicMatrixRefTest::TestMioMiMiOperations(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); CREATE_STORAGE_AND_REF(3); CREATE_STORAGE_AND_REF(4); vctRandom(matrix1, value_type(-10), value_type(10)); vctRandom(matrix2, value_type(-10), value_type(10)); vctRandom(matrix3, value_type(-10), value_type(10)); RemoveQuasiZero(matrix3); vctGenericContainerTest::TestCioCiCiOperations(matrix1, matrix2, matrix3, matrix4); } void vctDynamicMatrixRefTest::TestMioMiMiOperationsDouble(void) { TestMioMiMiOperations(); } void vctDynamicMatrixRefTest::TestMioMiMiOperationsFloat(void) { TestMioMiMiOperations(); } void vctDynamicMatrixRefTest::TestMioMiMiOperationsInt(void) { TestMioMiMiOperations(); } template void vctDynamicMatrixRefTest::TestMoMiMiOperations(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); CREATE_STORAGE_AND_REF(3); vctRandom(matrix1, value_type(-10), value_type(10)); vctRandom(matrix2, value_type(-10), value_type(10)); RemoveQuasiZero(matrix2); vctGenericContainerTest::TestCoCiCiOperations(matrix1, matrix2, matrix3); } void vctDynamicMatrixRefTest::TestMoMiMiOperationsDouble(void) { TestMoMiMiOperations(); } void vctDynamicMatrixRefTest::TestMoMiMiOperationsFloat(void) { TestMoMiMiOperations(); } void vctDynamicMatrixRefTest::TestMoMiMiOperationsInt(void) { TestMoMiMiOperations(); } template void vctDynamicMatrixRefTest::TestProductOperations(void) { // result size enum {ROWS = 4, COLS = 5, COMSIZE = 7}; typedef _elementType value_type; vctDynamicMatrix matrix1(ROWS, COMSIZE); vctDynamicMatrix matrix2(COMSIZE, COLS); vctDynamicMatrix matrix3(ROWS, COLS); vctDynamicVector vector1(COMSIZE); vctDynamicVector vector2(ROWS); vctRandom(matrix1, value_type(-10), value_type(10)); vctRandom(matrix2, value_type(-10), value_type(10)); vctRandom(vector1, value_type(-10), value_type(10)); vctGenericMatrixTest::TestMatrixMatrixProductOperations(matrix1, matrix2, matrix3); vctGenericMatrixTest::TestMatrixVectorProductOperations(matrix1, vector1, vector2); vctRandom(vector2, value_type(-10), value_type(10)); vctGenericMatrixTest::TestVectorMatrixProductOperations(matrix1, vector2, vector1); } void vctDynamicMatrixRefTest::TestProductOperationsDouble(void) { TestProductOperations(); } void vctDynamicMatrixRefTest::TestProductOperationsFloat(void) { TestProductOperations(); } void vctDynamicMatrixRefTest::TestProductOperationsInt(void) { TestProductOperations(); } template void vctDynamicMatrixRefTest::TestMoMiOperations(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); vctRandom(matrix1, value_type(-10), value_type(10)); vctGenericContainerTest::TestCoCiOperations(matrix1, matrix2); } void vctDynamicMatrixRefTest::TestMoMiOperationsDouble(void) { TestMoMiOperations(); } void vctDynamicMatrixRefTest::TestMoMiOperationsFloat(void) { TestMoMiOperations(); } void vctDynamicMatrixRefTest::TestMoMiOperationsInt(void) { TestMoMiOperations(); } template void vctDynamicMatrixRefTest::TestMoMiSiOperations(void) { typedef _elementType value_type; value_type scalar; cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-5), value_type(5), scalar); CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); if ((scalar < value_type(1)) && (scalar > -value_type(1))) { scalar = value_type(3); } vctRandom(matrix1, value_type(-10), value_type(10)); vctGenericContainerTest::TestCoCiSiOperations(matrix1, scalar, matrix2); } void vctDynamicMatrixRefTest::TestMoMiSiOperationsDouble(void) { TestMoMiSiOperations(); } void vctDynamicMatrixRefTest::TestMoMiSiOperationsFloat(void) { TestMoMiSiOperations(); } void vctDynamicMatrixRefTest::TestMoMiSiOperationsInt(void) { TestMoMiSiOperations(); } template void vctDynamicMatrixRefTest::TestMoSiMiOperations(void) { typedef _elementType value_type; value_type scalar; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-5), value_type(5), scalar); vctRandom(matrix1, value_type(-10), value_type(10)); RemoveQuasiZero(matrix1); vctGenericContainerTest::TestCoSiCiOperations(scalar, matrix1, matrix2); } void vctDynamicMatrixRefTest::TestMoSiMiOperationsDouble(void) { TestMoSiMiOperations(); } void vctDynamicMatrixRefTest::TestMoSiMiOperationsFloat(void) { TestMoSiMiOperations(); } void vctDynamicMatrixRefTest::TestMoSiMiOperationsInt(void) { TestMoSiMiOperations(); } template void vctDynamicMatrixRefTest::TestMioSiOperations(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); value_type scalar; cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-5), value_type(5), scalar); if ((scalar < value_type(1)) && (scalar > -value_type(1))) { scalar = value_type(3); } vctRandom(matrix1, value_type(-10), value_type(10)); vctGenericContainerTest::TestCioSiOperations(matrix1, scalar, matrix2); } void vctDynamicMatrixRefTest::TestMioSiOperationsDouble(void) { TestMioSiOperations(); } void vctDynamicMatrixRefTest::TestMioSiOperationsFloat(void) { TestMioSiOperations(); } void vctDynamicMatrixRefTest::TestMioSiOperationsInt(void) { TestMioSiOperations(); } template void vctDynamicMatrixRefTest::TestMioOperations(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); vctRandom(matrix1, value_type(-10), value_type(10)); vctGenericContainerTest::TestCioOperations(matrix1, matrix2); } void vctDynamicMatrixRefTest::TestMioOperationsDouble(void) { TestMioOperations(); } void vctDynamicMatrixRefTest::TestMioOperationsFloat(void) { TestMioOperations(); } void vctDynamicMatrixRefTest::TestMioOperationsInt(void) { TestMioOperations(); } template void vctDynamicMatrixRefTest::TestSoMiSiOperations(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); value_type scalar; cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-5), value_type(5), scalar); vctRandom(matrix1, value_type(-10), value_type(10)); vctGenericContainerTest::TestSoCiSiOperations(matrix1, scalar, matrix2); } void vctDynamicMatrixRefTest::TestSoMiSiOperationsDouble(void) { TestSoMiSiOperations(); } void vctDynamicMatrixRefTest::TestSoMiSiOperationsFloat(void) { TestSoMiSiOperations(); } void vctDynamicMatrixRefTest::TestSoMiSiOperationsInt(void) { TestSoMiSiOperations(); } template void vctDynamicMatrixRefTest::TestMinAndMax(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); vctRandom(matrix1, value_type(-50), value_type(50)); vctGenericContainerTest::TestMinAndMax(matrix1); } void vctDynamicMatrixRefTest::TestMinAndMaxDouble(void) { TestMinAndMax(); } void vctDynamicMatrixRefTest::TestMinAndMaxFloat(void) { TestMinAndMax(); } void vctDynamicMatrixRefTest::TestMinAndMaxInt(void) { TestMinAndMax(); } template void vctDynamicMatrixRefTest::TestIterators(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); vctRandom(matrix1, value_type(-10), value_type(10)); vctGenericContainerTest::TestIterators(matrix1); } void vctDynamicMatrixRefTest::TestIteratorsDouble(void) { TestIterators(); } void vctDynamicMatrixRefTest::TestIteratorsFloat(void) { TestIterators(); } void vctDynamicMatrixRefTest::TestIteratorsInt(void) { TestIterators(); } template void vctDynamicMatrixRefTest::TestSTLFunctions(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); vctRandom(matrix1, value_type(-10), value_type(10)); vctGenericContainerTest::TestSTLFunctions(matrix1, matrix2); } void vctDynamicMatrixRefTest::TestSTLFunctionsDouble(void) { TestSTLFunctions(); } void vctDynamicMatrixRefTest::TestSTLFunctionsFloat(void) { TestSTLFunctions(); } void vctDynamicMatrixRefTest::TestSTLFunctionsInt(void) { TestSTLFunctions(); } template void vctDynamicMatrixRefTest::TestRandomTemporaryRef(void) { typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); matrix1.SetAll(value_type(100)); vctRandom(vctDynamicMatrixRef(matrix1.rows(), matrix1.cols(), matrix1.row_stride(), matrix1.col_stride(), matrix1.Pointer()), value_type(-10), value_type(10)); vctGenericContainerTest::TestElementsInRange(matrix1, value_type(-10), value_type(10)); } void vctDynamicMatrixRefTest::TestRandomTemporaryRefDouble(void) { TestRandomTemporaryRef(); } void vctDynamicMatrixRefTest::TestRandomTemporaryRefFloat(void) { TestRandomTemporaryRef(); } void vctDynamicMatrixRefTest::TestRandomTemporaryRefInt(void) { TestRandomTemporaryRef(); } CPPUNIT_TEST_SUITE_REGISTRATION(vctDynamicMatrixRefTest);