Пример #1
0
 def testExampleUsage(self):
     A = SDR(10)
     B = SDR(10)
     C = SDR(20)
     A.sparse = [0, 1, 2]
     B.sparse = [0, 1, 2]
     C.concatenate(A, B)
     assert (set(C.sparse) == set([0, 1, 2, 10, 11, 12]))
Пример #2
0
 def testVersusNumpy(self):
     # Each testcase is a pair of lists of SDR dimensions and axis
     # dimensions.
     test_cases = [
         ([(9, 30, 40), (2, 30, 40)], 0),
         ([(2, 30, 40), (2, 99, 40)], 1),
         ([(2, 30, 40), (2, 30, 99)], 2),
         ([(100, ), (10), (30)], 0),
         ([(100, 2), (10, 2), (30, 2)], 0),
         ([(1, 77), (1, 99), (1, 88)], 1),
         ([(1, 77, 2), (1, 99, 2), (1, 88, 2)], 1),
     ]
     for sdr_dims, axis in test_cases:
         sdrs = [SDR(dims) for dims in sdr_dims]
         [sdr.randomize(.50) for sdr in sdrs]
         cat_dims = sdrs[0].dimensions
         cat_dims[axis] = sum(sdr.dimensions[axis] for sdr in sdrs)
         cat = SDR(cat_dims)
         cat.concatenate(sdrs, axis)
         np_cat = np.concatenate([sdr.dense for sdr in sdrs], axis=axis)
         assert ((cat.dense == np_cat).all())
Пример #3
0
 def testMirroring(self):
     A = SDR(100)
     A.randomize(.05)
     Ax10 = SDR(100 * 10)
     Ax10.concatenate([A] * 10)
     assert (Ax10.getSum() == 100 * 10 * .05)
Пример #4
0
    def testConstructorErrors(self):
        A = SDR(100)
        B = SDR((100, 2))
        AB = SDR(300)
        C = SDR([3, 3])
        D = SDR([3, 4])
        CD = SDR([3, 7])
        # Test bad argument dimensions
        with pytest.raises(TypeError):
            AB.concatenate(A)  # Not enough inputs!
        with pytest.raises(RuntimeError):
            AB.concatenate(A, B)  # Different numbers of dimensions!
        with pytest.raises(RuntimeError):
            AB.concatenate(B, C)  # All dims except axis must match!
        with pytest.raises(RuntimeError):
            CD.concatenate(C, D)  # All dims except axis must match!
        with pytest.raises(RuntimeError):
            CD.concatenate(C, D, axis=2)  # Invalid axis!
        with pytest.raises(TypeError):
            CD.concatenate(C, D, axis=-1)  # Invalid axis!

        # Test KeyWord Arguments.  These should all work.
        CD.concatenate(C, D, 1)
        CD.concatenate(C, D, axis=1)
        CD.concatenate([C, D], axis=1)
        CD.concatenate(inputs=[C, D], axis=1)