📄 spblastest.cpp
字号:
/* * spBlasTest.cpp * * Author: cyril Poulet */#include "spBlasTest.h"void spBlasTest::test_copy(){ spIdx<intg> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<int> sptest2(0, 4, 4); idx_copy(sptest, sptest2); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ CPPUNIT_ASSERT_EQUAL(sptest.get(i,j), (intg)sptest2.get(i, j)); }; }; spIdx<ubyte> sptest3(0, 4, 4); idx_copy(sptest, sptest3); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ CPPUNIT_ASSERT_EQUAL(sptest.get(i,j), (intg)sptest3.get(i, j)); }; }; spIdx<double> sptest4(0, 4, 4); idx_copy(sptest, sptest4); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ CPPUNIT_ASSERT_EQUAL(sptest.get(i,j), (intg)sptest4.get(i, j)); }; };}void spBlasTest::test_copy2(){ spIdx<intg> sptest(0, 4, 4, 4); sptest.set(1, 0, 1, 2); sptest.set(2, 1, 2, 3); sptest.set(3, 2, 3, 0); sptest.set(4, 3, 0, 1); Idx<int> test(4,4, 4); idx_copy(sptest, test); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ for(int k=0; k<4; k++){ CPPUNIT_ASSERT_EQUAL(sptest.get(i,j,k), (intg)test.get(i, j, k)); }; }; };}void spBlasTest::test_copy3(){ Idx<double> test(2,2); test.set(1.5, 0, 0); test.set(2.25, 0, 1); test.set(-1.5, 1, 0); test.set(-1, 1, 1); spIdx<int> sptest(0,2,2); idx_copy(test, sptest); for(int i = 0; i<2; i++){ for(int j = 0; j<2; j++){ CPPUNIT_ASSERT_EQUAL((int)test.get(i,j), sptest.get(i, j)); }; }; Idx<double> test2(2,2); test2.set(1.5, 0, 0); test2.set(-2.5, 1, 0); spIdx<ubyte> sptest2(0, 2, 2); idx_copy(test2, sptest2); for(int i = 0; i<2; i++){ for(int j = 0; j<2; j++){ CPPUNIT_ASSERT_EQUAL((ubyte)test2.get(i,j), sptest2.get(i, j)); }; };}void spBlasTest::test_clear(){ spIdx<intg> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); idx_clear(sptest); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ CPPUNIT_ASSERT_EQUAL((intg)BACKGROUND, sptest.get(i, j)); }; };}void spBlasTest::test_minus(){ spIdx<intg> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<intg> sptest2(0, 4, 4); sptest2.set(2, 1, 2); sptest2.set(3, 2, 3); sptest2.set(4, 3, 0); idx_minus(sptest, sptest2); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ CPPUNIT_ASSERT_EQUAL(-sptest.get(i,j), sptest2.get(i, j)); }; };}void spBlasTest::test_inv(){ spIdx<double> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<double> sptest2(0, 4, 4); sptest2.set(2, 1, 2); sptest2.set(3, 2, 3); sptest2.set(4, 3, 0); idx_inv(sptest, sptest2); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ double k = sptest.get(i,j); CPPUNIT_ASSERT_EQUAL((k == BACKGROUND)? BACKGROUND : 1/k, sptest2.get(i, j)); }; };}void spBlasTest::test_add(){ spIdx<double> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<double> sptest2(0, 4, 4); sptest2.set(2, 1, 2); sptest2.set(3, 1, 3); spIdx<double> sptest3(0,4,4); idx_add(sptest, sptest2, sptest3); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ CPPUNIT_ASSERT_EQUAL(sptest.get(i,j)+sptest2.get(i,j), sptest3.get(i, j)); }; };}void spBlasTest::test_sub(){ spIdx<double> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<double> sptest2(0, 4, 4); sptest2.set(2, 1, 2); sptest2.set(3, 1, 3); spIdx<double> sptest3(0,4,4); idx_sub(sptest, sptest2, sptest3); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ CPPUNIT_ASSERT_EQUAL(sptest.get(i,j)-sptest2.get(i,j), sptest3.get(i, j)); }; };}void spBlasTest::test_mul(){ spIdx<double> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<double> sptest2(0, 4, 4); sptest2.set(2, 1, 2); sptest2.set(3, 1, 3); spIdx<double> sptest3(0,4,4); idx_mul(sptest, sptest2, sptest3); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ CPPUNIT_ASSERT_EQUAL(sptest.get(i,j)*sptest2.get(i,j), sptest3.get(i, j)); }; };}void spBlasTest::test_addc(){ spIdx<double> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<double> sptest2(0, 4, 4); sptest2.set(2, 1, 2); sptest2.set(3, 1, 3); idx_addc(sptest, (double)-3, sptest2); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ double k = sptest.get(i,j); CPPUNIT_ASSERT_EQUAL((k==BACKGROUND)? BACKGROUND : k-3, sptest2.get(i, j)); }; };}void spBlasTest::test_addcacc(){ spIdx<double> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<double> sptest2(0, 4, 4); sptest2.set(2, 1, 2); sptest2.set(3, 1, 3); spIdx<double> sptest3(0,4,4); idx_copy(sptest2, sptest3); idx_addcacc(sptest, (double)-3, sptest2); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ double k = sptest.get(i,j); k = (k==BACKGROUND)? BACKGROUND : k-3; CPPUNIT_ASSERT_EQUAL(k + sptest3.get(i,j), sptest2.get(i, j)); }; };}void spBlasTest::test_dotc(){ spIdx<double> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<double> sptest2(0, 4, 4); sptest2.set(2, 1, 2); sptest2.set(3, 1, 3); idx_dotc(sptest, (double)-3, sptest2); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ double k = sptest.get(i,j); CPPUNIT_ASSERT_EQUAL((k==BACKGROUND)? BACKGROUND : k*(-3), sptest2.get(i, j)); }; }; idx_dotc(sptest, (double)0, sptest2); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ CPPUNIT_ASSERT_EQUAL( (double)BACKGROUND, sptest2.get(i, j)); }; };}void spBlasTest::test_dotcacc(){ spIdx<double> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<double> sptest2(0, 4, 4); sptest2.set(2, 1, 2); sptest2.set(3, 1, 3); spIdx<double> sptest3(0, 4, 4); idx_copy(sptest2, sptest3); idx_dotcacc(sptest, (double)-3, sptest2); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ double k = sptest.get(i,j); k = (k==BACKGROUND)? BACKGROUND : k*(-3); CPPUNIT_ASSERT_EQUAL(k + sptest3.get(i,j), sptest2.get(i, j)); }; };}void spBlasTest::test_subsquare(){ spIdx<double> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<double> sptest2(0, 4, 4); sptest2.set(2, 1, 2); sptest2.set(3, 1, 3); spIdx<double> sptest3(0, 4, 4); idx_subsquare(sptest, sptest2, sptest3); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ CPPUNIT_ASSERT_EQUAL((sptest.get(i,j) - sptest2.get(i,j))*(sptest.get(i,j) - sptest2.get(i,j)), sptest3.get(i, j)); }; };}void spBlasTest::test_lincomb(){ spIdx<double> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<double> sptest2(0, 4, 4); sptest2.set(2, 1, 2); sptest2.set(3, 1, 3); spIdx<double> sptest3(0, 4, 4); idx_lincomb(sptest, (double)-3, sptest2, (double)2, sptest3); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ CPPUNIT_ASSERT_EQUAL(-3 * sptest.get(i,j) + 2 * sptest2.get(i,j), sptest3.get(i, j)); }; }; spIdx<double> sptest4(0, 4, 4); idx_lincomb(sptest, (double)0, sptest2, (double)0, sptest4); CPPUNIT_ASSERT_EQUAL(true, sptest4.isempty());}void spBlasTest::test_abs(){ spIdx<int> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(-2, 1, 2); sptest.set(3, 2, 3); sptest.set(-4, 3, 0); spIdx<int> sptest2(0, 4, 4); idx_abs(sptest, sptest2); for(int i = 0; i<4; i++){ for(int j = 0; j<4; j++){ CPPUNIT_ASSERT_EQUAL(abs(sptest.get(i,j)), sptest2.get(i, j)); }; };}void spBlasTest::test_indexmax(){ spIdx<double> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(-2, 1, 2); sptest.set(3, 2, 3); sptest.set(-4, 3, 0); CPPUNIT_ASSERT_EQUAL((intg)2, idx_indexmax(sptest));}void spBlasTest::test_sqrdist(){ spIdx<double> sptest(0, 4, 4); sptest.set(1, 0, 1); sptest.set(2, 1, 2); sptest.set(3, 2, 3); sptest.set(4, 3, 0); spIdx<double> sptest2(0, 4, 4); sptest2.set(2, 1, 2); sptest2.set(3, 1, 3); CPPUNIT_ASSERT_EQUAL((double)35, idx_sqrdist(sptest, sptest2)); Idx<double> res; idx_sqrdist(sptest, sptest2, res); CPPUNIT_ASSERT_EQUAL(res.get(), idx_sqrdist(sptest, sptest2));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -