Exemplo n.º 1
0
        public void TestUtilSparseMatrix_Vecsum()
        {
            SparseBinaryMatrix matrix1 = new SparseBinaryMatrix(new[] { 1024, 1024 });

            // fill half the matrix
            for (int i = 0; i < 1024; i++)
            {
                for (int j = 0; j < 512; j += 2)
                {
                    matrix1.Set(1, i, j);
                }
            }

            int[] inputVec = new int[1024]; // all zero
            int[] results  = new int[1024];
            matrix1.RightVecSumAtNZ(inputVec, results, 0);

            inputVec = new int[1024]; // some zero
            for (int j = 0; j < 512; j += 2)
            {
                inputVec[j] = 1;
            }
            results = new int[1024];
            matrix1.RightVecSumAtNZ(inputVec, results, 0);
        }
Exemplo n.º 2
0
        public void TestAll()
        {
            SparseBinaryMatrix sm = CreateDefaultMatrix();

            int[] all = { 0, 5, 11, 16, 22, 27, 33, 38, 44, 49 };
            Assert.IsTrue(sm.All(all));
        }
Exemplo n.º 3
0
        public void TestOr()
        {
            SparseBinaryMatrix sm = CreateDefaultMatrix();

            int[]  orBits   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            byte[] expected = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
            sm.Or(orBits);
            Assert.IsTrue(Arrays.AreEqual(expected, ((SparseByteArray)sm.GetSlice(0)).AsDense()), "Arrays are not equal");
        }
Exemplo n.º 4
0
        public void CreateDistributedArrayTest()
        {
            int[] dims;

            var arr = new InMemoryArray(1, typeof(int), dims = new int[] { 100, 100 });

            SparseBinaryMatrix m = new SparseBinaryMatrix(dims, true, arr);

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    m.set(7, i, j);
                }
            }
        }
Exemplo n.º 5
0
        public void TestSliceIndexes()
        {
            SparseBinaryMatrix sm = new SparseBinaryMatrix(this.dimensions);

            int[][] expected =
            {
                new int[]    {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9 },
                new int[]    { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 },
                new int[]    { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 },
                new int[]    { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 },
                new int[]    { 40, 41, 42, 43, 44, 45, 46, 47, 48, 49 }
            };

            for (int i = 0; i < this.dimensions[0]; i++)
            {
                Assert.IsTrue(Arrays.AreEqual(expected[i], sm.GetSliceIndexes(new[] { i })));
            }
        }
Exemplo n.º 6
0
        private SparseBinaryMatrix CreateDefaultMatrix()
        {
            SparseBinaryMatrix sm = new SparseBinaryMatrix(this.dimensions);

            int[][] values =
            {
                new int[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
                new int[] { 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
                new int[] { 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 },
                new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 },
                new int[] { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }
            };

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    sm.Set(values[i][j], new int[] { i, j });
                }
            }

            return(sm);
        }
Exemplo n.º 7
0
        private void DoTestRightVecSumAtNzFast(AbstractSparseBinaryMatrix sm)
        {
            int[]   dimensions        = new int[] { 5, 10 };
            int[][] connectedSynapses = new int[][]
            {
                new int[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
                new int[] { 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
                new int[] { 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 },
                new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 },
                new int[] { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }
            };

            for (int i = 0; i < sm.GetDimensions()[0]; i++)
            {
                for (int j = 0; j < sm.GetDimensions()[1]; j++)
                {
                    sm.Set(connectedSynapses[i][j], i, j);
                }
            }

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Assert.AreEqual(connectedSynapses[i][j], sm.GetIntValue(i, j));
                }
            }

            int[] inputVector = new int[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 };
            int[] results     = new int[5];
            int[] trueResults = new int[] { 1, 1, 1, 1, 1 };
            sm.RightVecSumAtNZ(inputVector, results);

            for (int i = 0; i < results.Length; i++)
            {
                Assert.AreEqual(trueResults[i], results[i]);
            }

            ///////////////////////

            connectedSynapses = new int[][]
            {
                new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                new int[] { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 },
                new int[] { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 },
                new int[] { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 },
                new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }
            };
            sm = new SparseBinaryMatrix(dimensions);
            for (int i = 0; i < sm.GetDimensions()[0]; i++)
            {
                for (int j = 0; j < sm.GetDimensions()[1]; j++)
                {
                    sm.Set(connectedSynapses[i][j], i, j);
                }
            }

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Assert.AreEqual(connectedSynapses[i][j], sm.GetIntValue(i, j));
                }
            }

            inputVector = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
            results     = new int[5];
            trueResults = new int[] { 10, 8, 6, 4, 2 };
            sm.RightVecSumAtNZ(inputVector, results);

            for (int i = 0; i < results.Length; i++)
            {
                Assert.AreEqual(trueResults[i], results[i]);
            }
        }