Пример #1
0
        private void DoTestBackingStoreAndSliceAccess(AbstractSparseBinaryMatrix sm)
        {
            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));
                }
            }

            for (int i = 0; i < connectedSynapses.Length; i++)
            {
                for (int j = 0; j < connectedSynapses[i].Length; j++)
                {
                    Assert.AreEqual(connectedSynapses[i][j], ((SparseByteArray)sm.GetSlice(i))[j], 0);
                }
            }

            //Make sure warning is proper for exact access
            try
            {
                sm.GetSlice(0, 4);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("This method only returns the array holding the specified index: " +
                                Arrays.ToString(new int[] { 0, 4 }), e.Message);
            }
        }
Пример #2
0
        private void DoTestBackingStoreAndSliceAccessManyDimensions(AbstractSparseBinaryMatrix sm)
        {
            /*set diagonal element to true*/
            sm.Set(1, 0, 0, 0);
            sm.Set(1, 1, 1, 1);
            sm.Set(1, 2, 2, 2);
            sm.Set(1, 3, 3, 3);
            sm.Set(1, 4, 4, 4);
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    for (int k = 0; k < 5; k++)
                    {
                        if (k == j & j == i)
                        {
                            Assert.AreEqual(1, sm.GetIntValue(i, j, k));
                        }
                    }
                }
            }
            SparseByteArray slice = (SparseByteArray)sm.GetSlice(4, 4);

            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(1, sm.GetTrueCount(i));
            }
            Console.WriteLine("slice:" + ArrayUtils.IntArrayToString(slice));
            Assert.AreEqual(1, slice[4]);
            /*update first row to true, other to false*/
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    for (int k = 0; k < 5; k++)
                    {
                        if (0 == i)
                        {
                            sm.Set(1, i, j, k);
                        }
                        else
                        {
                            sm.Set(0, i, j, k);
                        }
                    }
                }
            }
            Assert.AreEqual(25, sm.GetTrueCounts()[0]);
            Assert.AreEqual(0, sm.GetTrueCounts()[1]);
        }