diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 45a3240091..94217fcc08 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -190,7 +190,6 @@ set(utils_files nupic/utils/Random.cpp nupic/utils/Random.hpp nupic/utils/SlidingWindow.hpp - nupic/utils/VectorHelpers.hpp nupic/utils/SdrMetrics.cpp nupic/utils/SdrMetrics.hpp nupic/utils/MurmurHash3.hpp diff --git a/src/nupic/algorithms/SpatialPooler.cpp b/src/nupic/algorithms/SpatialPooler.cpp index 2a914d7c2d..bd5df24f2b 100644 --- a/src/nupic/algorithms/SpatialPooler.cpp +++ b/src/nupic/algorithms/SpatialPooler.cpp @@ -31,7 +31,6 @@ #include #include -#include using namespace std; using namespace nupic; @@ -450,18 +449,17 @@ void SpatialPooler::initialize( inhibitionRadius_ = 0; connections_.initialize(numColumns_, synPermConnected_); - for (Size i = 0; i < numColumns_; ++i) { - connections_.createSegment( (CellIdx)i ); - - // Note: initMapPotential_ & initPermanence_ return dense arrays. - vector potential = initMapPotential_((UInt)i, wrapAround_); - vector perm = initPermanence_(potential, initConnectedPct_); - for(UInt presyn = 0; presyn < numInputs_; presyn++) { - if( potential[presyn] ) - connections_.createSynapse( (Segment)i, presyn, perm[presyn] ); + for (Size column = 0; column < numColumns_; column++) { + connections_.createSegment( static_cast(column) ); + + SDR potential({numInputs_}); + initMapPotential_(static_cast(column), wrapAround_, potential); + const vector perm = initPermanence_(potential, initConnectedPct_); + for(const auto presyn : potential.getSparse()) { + connections_.createSynapse( static_cast(column), presyn, perm[presyn] ); } - connections_.raisePermanencesToThreshold( (Segment)i, stimulusThreshold_ ); + connections_.raisePermanencesToThreshold( static_cast(column), stimulusThreshold_ ); } updateInhibitionRadius_(); @@ -505,6 +503,7 @@ void SpatialPooler::compute(const SDR &input, const bool learn, SDR &active) { void SpatialPooler::boostOverlaps_(const vector &overlaps, //TODO use Eigen sparse vector here vector &boosted) const { + NTA_ASSERT(overlaps.size() == numColumns_); for (UInt i = 0; i < numColumns_; i++) { boosted[i] = overlaps[i] * boostFactors_[i]; } @@ -530,8 +529,10 @@ UInt SpatialPooler::initMapColumn_(UInt column) const { } -vector SpatialPooler::initMapPotential_(UInt column, bool wrapAround) { - NTA_ASSERT(column < numColumns_); +void SpatialPooler::initMapPotential_(UInt column, bool wrapAround, SDR& potential) { + NTA_CHECK(potential.size == numInputs_); + NTA_CHECK(column < numColumns_); + const UInt centerInput = initMapColumn_(column); vector columnInputs; @@ -547,9 +548,9 @@ vector SpatialPooler::initMapPotential_(UInt column, bool wrapAround) { } const UInt numPotential = (UInt)round(columnInputs.size() * potentialPct_); - const auto selectedInputs = rng_.sample(columnInputs, numPotential); - const vector potential = VectorHelpers::sparseToBinary(selectedInputs, numInputs_); - return potential; + auto selectedInputs = rng_.sample(columnInputs, numPotential); + std::sort(selectedInputs.begin(), selectedInputs.end()); + potential.setSparse(selectedInputs); } @@ -563,14 +564,9 @@ Real SpatialPooler::initPermNonConnected_() { } -vector SpatialPooler::initPermanence_(const vector &potential, //TODO make potential sparse - Real connectedPct) { +const vector SpatialPooler::initPermanence_(const SDR &potential, const Real connectedPct) { vector perm(numInputs_, 0); - for (UInt i = 0; i < numInputs_; i++) { - if (potential[i] < 1) { - continue; - } - + for (const auto i : potential.getSparse()) { if (rng_.getReal64() <= connectedPct) { perm[i] = initPermConnected_(); } else { diff --git a/src/nupic/algorithms/SpatialPooler.hpp b/src/nupic/algorithms/SpatialPooler.hpp index 1131900aae..164a772771 100644 --- a/src/nupic/algorithms/SpatialPooler.hpp +++ b/src/nupic/algorithms/SpatialPooler.hpp @@ -839,8 +839,10 @@ class SpatialPooler : public Serializable @param wrapAround A boolean value indicating that boundaries should be ignored. + @param potential A SDR (sized as input), the return values are written to + this field */ - vector initMapPotential_(UInt column, bool wrapAround); + void initMapPotential_(UInt column, bool wrapAround, SDR& potential); /** Returns a randomly generated permanence value for a synapses that is @@ -880,7 +882,7 @@ class SpatialPooler : public Serializable @param connectedPct A real value between 0 or 1 specifying the percent of the input bits that will start off in a connected state. */ - vector initPermanence_(const vector &potential, Real connectedPct); + const vector initPermanence_(const SDR &potential, const Real connectedPct); void clip_(vector &perm) const; diff --git a/src/nupic/regions/TMRegion.cpp b/src/nupic/regions/TMRegion.cpp index 89d6a4334d..c1681d7763 100644 --- a/src/nupic/regions/TMRegion.cpp +++ b/src/nupic/regions/TMRegion.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #define VERSION 1 diff --git a/src/nupic/utils/VectorHelpers.hpp b/src/nupic/utils/VectorHelpers.hpp deleted file mode 100644 index 4966d8b9f7..0000000000 --- a/src/nupic/utils/VectorHelpers.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef NTA_UTILS_VECTORHELPERS -#define NTA_UTILS_VECTORHELPERS - -#include -#include -#include -#include -#include -#include - -#include -#include - - -namespace nupic { - -class VectorHelpers -{ -public: - - /** - * Convert sparse to binary representation. - */ - template - static std::vector sparseToBinary(const std::vector& sparseVector, UInt width) - { - std::vector binary(width); - for (auto sparseIdx: sparseVector) { - binary[sparseIdx] = (T)1; - } - return binary; - } -}; - -} // end namespace nupic -#endif // end NTA_UTILS_VECTORHELPERS diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 3b2e84094b..d78f88382c 100755 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -104,7 +104,6 @@ set(utils_tests unit/utils/GroupByTest.cpp unit/utils/MovingAverageTest.cpp unit/utils/RandomTest.cpp - unit/utils/VectorHelpersTest.cpp unit/utils/SdrMetricsTest.cpp ) diff --git a/src/test/unit/algorithms/SpatialPoolerTest.cpp b/src/test/unit/algorithms/SpatialPoolerTest.cpp index fd4fda76fa..ad603934db 100644 --- a/src/test/unit/algorithms/SpatialPoolerTest.cpp +++ b/src/test/unit/algorithms/SpatialPoolerTest.cpp @@ -60,7 +60,7 @@ bool almost_eq(Real a, Real b) { return (diff > -1e-5 && diff < 1e-5); } -bool check_vector_eq(UInt arr[], vector vec) { //TODO replace with ArrayBase, VectorHelpers or teplates +bool check_vector_eq(UInt arr[], vector vec) { //TODO replace with ArrayBase, or teplates for (UInt i = 0; i < vec.size(); i++) { if (arr[i] != vec[i]) { return false; @@ -127,6 +127,14 @@ bool check_vector_eq(vector vec1, vector vec2) { return true; } +bool check_vector_eq(UInt arr[], SDR &sdr) { + const auto vec = sdr.getSparse(); + for(UInt i = 0; i < vec.size(); i++) { + if(arr[i] != vec[i]) return false; + } + return true; +} + void check_spatial_eq(const SpatialPooler& sp1, const SpatialPooler& sp2) { UInt numColumns = sp1.getNumColumns(); UInt numInputs = sp2.getNumInputs(); @@ -1615,39 +1623,39 @@ TEST(SpatialPoolerTest, testinitMapPotential1D) { sp.initialize(inputDim, columnDim); sp.setPotentialRadius(potentialRadius); - vector mask; + SDR mask({sp.getNumInputs()}); // Test without wrapAround and potentialPct = 1 sp.setPotentialPct(1.0); UInt expectedMask1[12] = {1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}; - mask = sp.initMapPotential_(0, false); + sp.initMapPotential_(0, false, mask); ASSERT_TRUE(check_vector_eq(expectedMask1, mask)); UInt expectedMask2[12] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0}; - mask = sp.initMapPotential_(2, false); + sp.initMapPotential_(2, false, mask); ASSERT_TRUE(check_vector_eq(expectedMask2, mask)); // Test with wrapAround and potentialPct = 1 sp.setPotentialPct(1.0); UInt expectedMask3[12] = {1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1}; - mask = sp.initMapPotential_(0, true); + sp.initMapPotential_(0, true, mask); ASSERT_TRUE(check_vector_eq(expectedMask3, mask)); UInt expectedMask4[12] = {1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}; - mask = sp.initMapPotential_(3, true); + sp.initMapPotential_(3, true, mask); ASSERT_TRUE(check_vector_eq(expectedMask4, mask)); // Test with potentialPct < 1 sp.setPotentialPct(0.5); UInt supersetMask1[12] = {1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1}; - mask = sp.initMapPotential_(0, true); - ASSERT_TRUE(accumulate(mask.begin(), mask.end(), 0.0f) == 3u); + sp.initMapPotential_(0, true, mask); + ASSERT_TRUE(mask.getSum() == 3u); UInt unionMask1[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; for (UInt i = 0; i < 12; i++) { - unionMask1[i] = supersetMask1[i] | mask.at(i); + unionMask1[i] = supersetMask1[i] | mask.getDense().at(i); } ASSERT_TRUE(check_vector_eq(unionMask1, supersetMask1, 12)); @@ -1667,21 +1675,21 @@ TEST(SpatialPoolerTest, testinitMapPotential2D) { sp.setPotentialRadius(potentialRadius); sp.setPotentialPct(potentialPct); - vector mask; + SDR mask({sp.getNumInputs()}); // Test without wrapAround UInt expectedMask1[72] = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - mask = sp.initMapPotential_(0, false); + sp.initMapPotential_(0, false, mask); ASSERT_TRUE(check_vector_eq(expectedMask1, mask)); UInt expectedMask2[72] = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - mask = sp.initMapPotential_(2, false); + sp.initMapPotential_(2, false, mask); ASSERT_TRUE(check_vector_eq(expectedMask2, mask)); // Test with wrapAround @@ -1691,14 +1699,14 @@ TEST(SpatialPoolerTest, testinitMapPotential2D) { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1}; - mask = sp.initMapPotential_(0, true); + sp.initMapPotential_(0, true, mask); ASSERT_TRUE(check_vector_eq(expectedMask3, mask)); UInt expectedMask4[72] = { 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}; - mask = sp.initMapPotential_(3, true); + sp.initMapPotential_(3, true, mask); ASSERT_TRUE(check_vector_eq(expectedMask4, mask)); } diff --git a/src/test/unit/regions/TMRegionTest.cpp b/src/test/unit/regions/TMRegionTest.cpp index 78d3840b28..dc8dbb3a74 100644 --- a/src/test/unit/regions/TMRegionTest.cpp +++ b/src/test/unit/regions/TMRegionTest.cpp @@ -60,7 +60,6 @@ #include #include #include -#include #include // fabs/abs #include // exit @@ -75,6 +74,8 @@ #include "yaml-cpp/yaml.h" #include "gtest/gtest.h" +namespace testing { + #define VERBOSE if (verbose) std::cerr << "[ ] " static bool verbose = false; // turn this on to print extra stuff for debugging the test. @@ -84,7 +85,6 @@ static bool verbose = false; // turn this on to print extra stuff for debugging using namespace nupic; -namespace testing { // Verify that all parameters are working. // Assumes that the default value in the Spec is the same as the default when @@ -277,9 +277,9 @@ TEST(TMRegionTest, testLinking) { << r3InputArray.getCount(); EXPECT_TRUE(r3InputArray.getType() == NTA_BasicType_SDR); VERBOSE << " " << r3InputArray << "\n"; - std::vector expected3in = VectorHelpers::sparseToBinary( - { 1, 2, 3, 5, 6, 8, 11, 13, 17, 19 }, (UInt32)r3InputArray.getCount()); - EXPECT_TRUE(r3InputArray == expected3in); + SDR expectedR3Input({(UInt32)r3InputArray.getCount()}); + expectedR3Input.setSparse(SDR_sparse_t{ 1, 2, 3, 5, 6, 8, 11, 13, 17, 19 }); + EXPECT_EQ(r3InputArray.getSDR(), expectedR3Input); VERBOSE << " TMRegion output " << region3->getOutputDimensions("bottomUpOut") << "\n"; @@ -293,13 +293,13 @@ TEST(TMRegionTest, testLinking) { << r3InputArray.getCount(); EXPECT_TRUE(r3OutputArray.getType() == NTA_BasicType_SDR); VERBOSE << " " << r3OutputArray << "\n"; - std::vector expected3out = VectorHelpers::sparseToBinary( - { 5u, 6u, 7u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u, + SDR expectedR3Out({(UInt32)r3OutputArray.getCount()}); + expectedR3Out.setSparse( SDR_sparse_t{ 5u, 6u, 7u, 8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u, 16u, 17u, 18u, 19u, 25u, 26u, 27u, 28u, 29u, 30u, 31u, 32u, 33u, 34u, 40u, 41u, 42u, 43u, 44u, 55u, 56u, 57u, 58u, 59u, 65u, 66u, 67u, 68u, 69u, 85u, 86u, 87u, - 88u, 89u, 95u, 96u, 97u, 98u, 99u }, (UInt32)r3OutputArray.getCount()); - EXPECT_TRUE(r3OutputArray == expected3out); - EXPECT_EQ(r3OutputArray.getSDR().getSparse().size(), 50u); + 88u, 89u, 95u, 96u, 97u, 98u, 99u }); + EXPECT_EQ(r3OutputArray.getSDR(), expectedR3Out); + EXPECT_EQ(r3OutputArray.getSDR().getSum(), 50u); // execute TMRegion several more times and check that it has output. VERBOSE << "Execute 9 times." << std::endl; @@ -313,12 +313,12 @@ TEST(TMRegionTest, testLinking) { << r3OutputArray.getCount() << ", should be (" << numberOfCols << " * " << cellsPerColumn; VERBOSE << " " << r3OutputArray << ")\n"; - std::vector expected3outa = VectorHelpers::sparseToBinary( - {20u, 21u, 22u, 23u, 24u, 25u, 26u, 27u, 28u, 29u, 35u, 36u, 37u, 38u, + expectedR3Out.setSparse( + SDR_sparse_t{20u, 21u, 22u, 23u, 24u, 25u, 26u, 27u, 28u, 29u, 35u, 36u, 37u, 38u, 39u, 45u, 46u, 47u, 48u, 49u, 50u, 51u, 52u, 53u, 54u, 60u, 61u, 62u, 63u, 64u, 70u, 71u, 72u, 73u, 74u, 80u, 81u, 82u, 83u, 84u, 90u, 91u, - 92u, 93u, 94u, 95u, 96u, 97u, 98u, 99u}, (UInt32)r3OutputArray.getCount()); - EXPECT_TRUE(r3OutputArray == expected3outa); + 92u, 93u, 94u, 95u, 96u, 97u, 98u, 99u}); + EXPECT_EQ(r3OutputArray, expectedR3Out.getDense()); VERBOSE << " Input to VectorFileEffector " @@ -326,7 +326,7 @@ TEST(TMRegionTest, testLinking) { Array r4InputArray = region4->getInputData("dataIn"); EXPECT_TRUE(r4InputArray.getType() == NTA_BasicType_Real32); VERBOSE << " " << r4InputArray << "\n"; - EXPECT_TRUE(r4InputArray == expected3outa); + EXPECT_TRUE(r4InputArray == expectedR3Out.getDense()); // cleanup region3->executeCommand({"closeFile"}); diff --git a/src/test/unit/types/SdrTest.cpp b/src/test/unit/types/SdrTest.cpp index 8bb7ba04cc..3cd2ead530 100644 --- a/src/test/unit/types/SdrTest.cpp +++ b/src/test/unit/types/SdrTest.cpp @@ -43,9 +43,9 @@ TEST(SdrTest, TestConstructor) { ASSERT_EQ( b.dimensions, b_dims ); ASSERT_EQ( b.getCoordinates().size(), 1ul ); // zero initialized - ASSERT_EQ( b.getDense(), vector({0, 0, 0}) ); - ASSERT_EQ( b.getSparse(), vector(0) ); - ASSERT_EQ( b.getCoordinates(), vector>({{}}) ); + ASSERT_EQ( b.getDense(), SDR_dense_t({0, 0, 0}) ); + ASSERT_EQ( b.getSparse(), SDR_sparse_t(0) ); + ASSERT_EQ( b.getCoordinates(), SDR_coordinate_t({{}}) ); // Test 3-D vector c_dims = {11u, 15u, 3u}; @@ -69,15 +69,15 @@ TEST(SdrTest, TestConstructorCopy) { SDR a({5}); a.setDense( SDR_dense_t({0, 1, 0, 0, 0})); SDR b(a); - ASSERT_EQ( b.getSparse(), vector({1}) ); + ASSERT_EQ( b.getSparse(), SDR_sparse_t({1}) ); ASSERT_TRUE(a == b); } TEST(SdrTest, TestZero) { SDR a({4, 4}); - a.setDense( vector(16, 1) ); + a.setDense( SDR_dense_t(16, 1) ); a.zero(); - ASSERT_EQ( vector(16, 0), a.getDense() ); + ASSERT_EQ( SDR_dense_t(16, 0), a.getDense() ); ASSERT_EQ( a.getSparse().size(), 0ul); ASSERT_EQ( a.getCoordinates().size(), 2ul); ASSERT_EQ( a.getCoordinates().at(0).size(), 0ul); @@ -88,7 +88,7 @@ TEST(SdrTest, TestSDR_Examples) { // Make an SDR with 9 values, arranged in a (3 x 3) grid. // "SDR" is an alias/typedef for SparseDistributedRepresentation. SDR X( {3, 3} ); - vector data({ + SDR_dense_t data({ 0, 1, 0, 0, 1, 0, 0, 0, 1 }); @@ -115,11 +115,11 @@ TEST(SdrTest, TestSDR_Examples) { X.getDense(); // This line will resuse the result of the previous line X.zero(); - Byte *before = X.getDense().data(); + auto before = X.getDense().data(); SDR_dense_t newData({ 1, 0, 0, 1, 0, 0, 1, 0, 0 }); - Byte *data_ptr = newData.data(); + auto data_ptr = newData.data(); X.setDense( newData ); - Byte *after = X.getDense().data(); + auto after = X.getDense().data(); // X now points to newData, and newData points to X's old data. ASSERT_EQ( after, data_ptr ); ASSERT_EQ( newData.data(), before ); @@ -150,17 +150,19 @@ TEST(SdrTest, TestReshape) { } TEST(SdrTest, TestSetDenseVec) { + // Tests that sdr.setDense() swaps vector content when data types are correct. SDR a({11, 10, 4}); - Byte *before = a.getDense().data(); - SDR_dense_t vec = vector(440, 1); - Byte *data = vec.data(); + auto before = a.getDense().data(); + SDR_dense_t vec = SDR_dense_t(440, 1); + auto data = vec.data(); a.setDense( vec ); - Byte *after = a.getDense().data(); + auto after = a.getDense().data(); ASSERT_NE( before, after ); // not a copy. ASSERT_EQ( after, data ); // correct data buffer. } TEST(SdrTest, TestSetDenseByte) { + // Tests sdr.setDense will copy data correctly, when given a pointer. SDR a({11, 10, 4}); auto vec = vector(a.size, 1); a.zero(); @@ -171,29 +173,32 @@ TEST(SdrTest, TestSetDenseByte) { } TEST(SdrTest, TestSetDenseUInt) { + // Tests sdr.setDense will copy data correctly, when given input with the wrong data type. SDR a({11, 10, 4}); auto vec = vector(a.size, 1); - a.setDense( (UInt*) vec.data() ); - ASSERT_EQ( a.getDense(), vector(a.size, 1) ); + a.setDense(vec ); + ASSERT_EQ( a.getDense(), SDR_dense_t(a.size, 1) ); ASSERT_NE( a.getDense().data(), (const Byte*) vec.data()); // true copy not a reference } TEST(SdrTest, TestSetDenseInplace) { SDR a({10, 10}); auto& a_data = a.getDense(); - ASSERT_EQ( a_data, vector(100, 0) ); + ASSERT_EQ( a_data, SDR_dense_t(100, 0) ); a_data.assign( a.size, 1 ); a.setDense( a_data ); ASSERT_EQ( a.getDense().data(), a.getDense().data() ); ASSERT_EQ( a.getDense().data(), a_data.data() ); - ASSERT_EQ( a.getDense(), vector(a.size, 1) ); + ASSERT_EQ( a.getDense(), SDR_dense_t(a.size, 1) ); ASSERT_EQ( a.getDense(), a_data ); } TEST(SdrTest, TestSetSparseVec) { + // This tests that the SDR swaps vector contents instead of copying, when + // the given vector has the correct data type. SDR a({11, 10, 4}); UInt *before = a.getSparse().data(); - auto vec = vector(a.size, 1); + auto vec = SDR_sparse_t(a.size, 1); UInt *data = vec.data(); for(UInt i = 0; i < a.size; i++) vec[i] = i; @@ -204,8 +209,9 @@ TEST(SdrTest, TestSetSparseVec) { } TEST(SdrTest, TestSetSparsePtr) { + // Test sdr.setSparse copies data correctly when given a pointer. SDR a({11, 10, 4}); - auto vec = vector(a.size, 1); + auto vec = SDR_sparse_t(a.size, 1); for(UInt i = 0; i < a.size; i++) vec[i] = i; a.zero(); @@ -219,23 +225,23 @@ TEST(SdrTest, TestSetSparseInplace) { SDR a({10, 10}); a.zero(); auto& a_data = a.getSparse(); - ASSERT_EQ( a_data, vector(0) ); + ASSERT_EQ( a_data, SDR_sparse_t(0) ); a_data.push_back(0); a.setSparse( a_data ); ASSERT_EQ( a.getSparse().data(), a.getSparse().data() ); ASSERT_EQ( a.getSparse(), a.getSparse() ); ASSERT_EQ( a.getSparse().data(), a_data.data() ); ASSERT_EQ( a.getSparse(), a_data ); - ASSERT_EQ( a.getSparse(), vector(1) ); + ASSERT_EQ( a.getSparse(), SDR_sparse_t(1) ); a_data.clear(); a.setSparse( a_data ); - ASSERT_EQ( a.getDense(), vector(a.size, 0) ); + ASSERT_EQ( a.getDense(), SDR_dense_t(a.size, 0) ); } TEST(SdrTest, TestSetCoordinates) { SDR a({4, 1, 3}); void *before = a.getCoordinates().data(); - auto vec = vector>({ + auto vec = SDR_coordinate_t({ { 0, 1, 2, 0 }, { 0, 0, 0, 0 }, { 0, 1, 2, 1 } }); @@ -279,11 +285,11 @@ TEST(SdrTest, TestSetCoordinatesInplace) { ASSERT_EQ( a.getCoordinates(), a.getCoordinates() ); ASSERT_EQ( a.getCoordinates().data(), a_data.data() ); ASSERT_EQ( a.getCoordinates(), a_data ); - ASSERT_EQ( a.getSparse(), vector({0, 37, 71}) ); // Check data ok + ASSERT_EQ( a.getSparse(), SDR_sparse_t({0, 37, 71}) ); // Check data ok a_data[0].clear(); a_data[1].clear(); a.setCoordinates( a_data ); - ASSERT_EQ( a.getDense(), vector(a.size, 0) ); + ASSERT_EQ( a.getDense(), SDR_dense_t(a.size, 0) ); } TEST(SdrTest, TestSetSDR) { @@ -292,15 +298,15 @@ TEST(SdrTest, TestSetSDR) { // Test dense assignment works a.setDense(SDR_dense_t({1, 1, 1, 1, 1})); b.setSDR(a); - ASSERT_EQ( b.getSparse(), vector({0, 1, 2, 3, 4}) ); + ASSERT_EQ( b.getSparse(), SDR_sparse_t({0, 1, 2, 3, 4}) ); // Test sparse assignment works a.setSparse(SDR_sparse_t({0, 1, 2, 3, 4})); b.setSDR(a); - ASSERT_EQ( b.getDense(), vector({1, 1, 1, 1, 1}) ); + ASSERT_EQ( b.getDense(), SDR_dense_t({1, 1, 1, 1, 1}) ); // Test coordinate assignment works a.setCoordinates(SDR_coordinate_t({{0, 1, 2, 3, 4}})); b.setSDR(a); - ASSERT_EQ( b.getDense(), vector({1, 1, 1, 1, 1}) ); + ASSERT_EQ( b.getDense(), SDR_dense_t({1, 1, 1, 1, 1}) ); // Test equals override works a.zero(); b = a; @@ -312,18 +318,18 @@ TEST(SdrTest, TestGetDenseFromSparse) { // Test zeros SDR z({4, 4}); z.setSparse(SDR_sparse_t({})); - ASSERT_EQ( z.getDense(), vector(16, 0) ); + ASSERT_EQ( z.getDense(), SDR_dense_t(16, 0) ); // Test ones SDR nz({4, 4}); nz.setSparse(SDR_sparse_t( {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15})); - ASSERT_EQ( nz.getDense(), vector(16, 1) ); + ASSERT_EQ( nz.getDense(), SDR_dense_t(16, 1) ); // Test 1-D SDR d1({30}); d1.setSparse(SDR_sparse_t({1, 4, 5, 7, 29})); - vector ans(30, 0); + SDR_dense_t ans(30, 0); ans[1] = 1; ans[4] = 1; ans[5] = 1; @@ -334,7 +340,7 @@ TEST(SdrTest, TestGetDenseFromSparse) { // Test 3-D SDR d3({10, 10, 10}); d3.setSparse(SDR_sparse_t({0, 5, 50, 55, 500, 550, 555, 999})); - vector ans2(1000, 0); + SDR_dense_t ans2(1000, 0); ans2[0] = 1; ans2[5] = 1; ans2[50] = 1; @@ -350,7 +356,7 @@ TEST(SdrTest, TestGetDenseFromCoordinates) { // Test simple 2-D SDR a({3, 3}); a.setCoordinates(SDR_coordinate_t({{0, 1, 2}, {0, 2, 2}})); - vector ans(9, 0); + SDR_dense_t ans(9, 0); ans[0] = 1; ans[5] = 1; ans[8] = 1; @@ -359,7 +365,7 @@ TEST(SdrTest, TestGetDenseFromCoordinates) { // Test zeros SDR z({99, 1}); z.setCoordinates(SDR_coordinate_t({{}, {}})); - ASSERT_EQ( z.getDense(), vector(99, 0) ); + ASSERT_EQ( z.getDense(), SDR_dense_t(99, 0) ); } TEST(SdrTest, TestGetSparseFromDense) { @@ -373,7 +379,7 @@ TEST(SdrTest, TestGetSparseFromDense) { ASSERT_EQ(a.getSparse().at(1), 8ul); // Test zero'd SDR. - a.setDense( vector(a.size, 0) ); + a.setDense( SDR_dense_t(a.size, 0) ); ASSERT_EQ( a.getSparse().size(), 0ul ); } @@ -432,7 +438,7 @@ TEST(SdrTest, TestGetCoordinatesFromDense) { { 2, 2 }}) ); // Test zero'd SDR. - a.setDense( vector(a.size, 0) ); + a.setDense( SDR_dense_t(a.size, 0) ); ASSERT_EQ( a.getCoordinates()[0].size(), 0ul ); ASSERT_EQ( a.getCoordinates()[1].size(), 0ul ); }