예제 #1
0
파일: test_cc2.py 프로젝트: zz119/neon
 def test_less_equal(self):
     left = self.be.array([[-1, 0], [1, 92]])
     right = self.be.ones([2, 2])
     out = self.be.empty([2, 2])
     self.be.less_equal(left, right, out)
     assert out.shape == (2, 2)
     assert_tensor_equal(out, self.gpt([[1, 1], [1, 0]]))
예제 #2
0
파일: test_cc2.py 프로젝트: AI-Cdrone/neon
 def test_some_not_equal(self):
     left = self.be.ones([2, 2])
     right = self.be.array([[0, 1], [0, 1]])
     out = self.be.empty([2, 2])
     self.be.not_equal(left, right, out)
     assert out.shape == (2, 2)
     assert_tensor_equal(out, self.gpt([[1, 0], [1, 0]]))
예제 #3
0
파일: test_cc2.py 프로젝트: zz119/neon
 def test_greater(self):
     left = self.be.array([[-1, 0], [1, 92]])
     right = self.be.ones([2, 2])
     out = self.be.empty([2, 2])
     self.be.greater(left, right, out)
     assert out.shape == (2, 2)
     assert_tensor_equal(out, self.gpt([[0, 0], [0, 1]]))
예제 #4
0
파일: test_cc2.py 프로젝트: zz119/neon
 def test_some_equal(self):
     left = self.be.ones([2, 2])
     right = self.be.array([[0, 1], [0, 1]])
     out = self.be.empty([2, 2])
     self.be.equal(left, right, out)
     assert out.shape == (2, 2)
     assert_tensor_equal(out, self.gpt([[0, 1], [0, 1]]))
예제 #5
0
파일: test_cc2.py 프로젝트: AI-Cdrone/neon
 def test_less_equal(self):
     left = self.be.array([[-1, 0], [1, 92]])
     right = self.be.ones([2, 2])
     out = self.be.empty([2, 2])
     self.be.less_equal(left, right, out)
     assert out.shape == (2, 2)
     assert_tensor_equal(out, self.gpt([[1, 1], [1, 0]]))
예제 #6
0
파일: test_cpu.py 프로젝트: AI-Cdrone/neon
 def test_some_equal(self):
     left = self.be.ones([2, 2])
     right = self.be.array([[0, 1], [0, 1]])
     out = self.be.empty([2, 2])
     self.be.equal(left, right, out)
     assert out.shape == (2, 2)
     assert_tensor_equal(out, CPUTensor([[0, 1], [0, 1]]))
예제 #7
0
 def test_all_not_equal(self):
     left = self.be.ones([2, 2])
     right = self.be.zeros([2, 2])
     out = self.be.empty([2, 2])
     self.be.not_equal(left, right, out)
     assert out.shape == (2, 2)
     assert_tensor_equal(out, CPUTensor([[1, 1], [1, 1]]))
예제 #8
0
 def test_some_not_equal(self):
     left = self.be.ones([2, 2])
     right = self.be.array([[0, 1], [0, 1]])
     out = self.be.empty([2, 2])
     self.be.not_equal(left, right, out)
     assert out.shape == (2, 2)
     assert_tensor_equal(out, CPUTensor([[1, 0], [1, 0]]))
예제 #9
0
파일: test_cpu.py 프로젝트: AI-Cdrone/neon
 def test_none_not_equal(self):
     left = self.be.ones([2, 2])
     right = self.be.ones([2, 2])
     out = self.be.empty([2, 2])
     self.be.not_equal(left, right, out)
     assert out.shape == (2, 2)
     assert_tensor_equal(out, CPUTensor([[0, 0], [0, 0]]))
예제 #10
0
파일: test_cpu.py 프로젝트: AI-Cdrone/neon
 def test_greater(self):
     left = self.be.array([[-1, 0], [1, 92]])
     right = self.be.ones([2, 2])
     out = self.be.empty([2, 2])
     self.be.greater(left, right, out)
     assert out.shape == (2, 2)
     assert_tensor_equal(out, CPUTensor([[0, 0], [0, 1]]))
예제 #11
0
파일: test_cc2.py 프로젝트: AI-Cdrone/neon
 def test_all_not_equal(self):
     left = self.be.ones([2, 2])
     right = self.be.zeros([2, 2])
     out = self.be.empty([2, 2])
     self.be.not_equal(left, right, out)
     assert out.shape == (2, 2)
     assert_tensor_equal(out, self.gpt([[1, 1], [1, 1]]))
예제 #12
0
파일: test_cc2.py 프로젝트: zz119/neon
 def test_none_not_equal(self):
     left = self.be.ones([2, 2])
     right = self.be.ones([2, 2])
     out = self.be.empty([2, 2])
     self.be.not_equal(left, right, out)
     assert out.shape == (2, 2)
     assert_tensor_equal(out, self.gpt([[0, 0], [0, 0]]))
예제 #13
0
 def test_0norm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     # -> sum(tsr != 0, axis=0) -> [2, 1]
     assert_tensor_equal(self.be.norm(tsr, order=0, axis=0),
                         CPUTensor([[2, 1]]))
     # -> sum(tsr != 0, axis=1) -> [1, 2]
     assert_tensor_equal(self.be.norm(tsr, order=0, axis=1),
                         CPUTensor([1, 2]))
예제 #14
0
def test_rectleaky_slope_zero_rectlin_equiv():
    be = CPU()
    inputs = be.uniform(low=-5.0, high=10.0, size=(10, 10))
    lin_buf = be.empty(inputs.shape)
    leaky_buf = be.empty(inputs.shape)
    be.rectlin(inputs, out=lin_buf)
    be.rectleaky(inputs, slope=0.0, out=leaky_buf)
    assert_tensor_equal(lin_buf, leaky_buf)
예제 #15
0
 def test_1norm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     # -> sum([[1, 0], [1, 3]], axis=0)**1 -> [2, 3]
     assert_tensor_equal(self.be.norm(tsr, order=1, axis=0),
                         CPUTensor([[2, 3]]))
     # -> sum([[1, 0], [1, 3]], axis=1)**1 -> [1, 4]
     assert_tensor_equal(self.be.norm(tsr, order=1, axis=1),
                         CPUTensor([1, 4]))
예제 #16
0
파일: test_cpu.py 프로젝트: AI-Cdrone/neon
 def test_1norm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     # -> sum([[1, 0], [1, 3]], axis=0)**1 -> [2, 3]
     assert_tensor_equal(self.be.norm(tsr, order=1, axis=0),
                         CPUTensor([[2, 3]]))
     # -> sum([[1, 0], [1, 3]], axis=1)**1 -> [1, 4]
     assert_tensor_equal(self.be.norm(tsr, order=1, axis=1),
                         CPUTensor([1, 4]))
예제 #17
0
파일: test_cpu.py 프로젝트: AI-Cdrone/neon
 def test_infnorm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     # -> max(abs(tsr), axis=0) -> [1, 3]
     assert_tensor_equal(self.be.norm(tsr, order=float('inf'), axis=0),
                         CPUTensor([[1, 3]]))
     # -> max(abs(tsr), axis=1) -> [1, 3]
     assert_tensor_equal(self.be.norm(tsr, order=float('inf'), axis=1),
                         CPUTensor([1, 3]))
예제 #18
0
파일: test_cc2.py 프로젝트: zz119/neon
 def test_neginfnorm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     # -> min(abs(tsr), axis=0) -> [1, 0]
     assert_tensor_equal(self.be.norm(tsr, order=float('-inf'), axis=0),
                         self.gpt([[1, 0]]))
     # -> min(abs(tsr), axis=1) -> [0, 1]
     assert_tensor_equal(self.be.norm(tsr, order=float('-inf'), axis=1),
                         self.gpt([0, 1]))
예제 #19
0
파일: test_cpu.py 프로젝트: AI-Cdrone/neon
 def test_neginfnorm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     # -> min(abs(tsr), axis=0) -> [1, 0]
     assert_tensor_equal(self.be.norm(tsr, order=float('-inf'), axis=0),
                         CPUTensor([[1, 0]]))
     # -> min(abs(tsr), axis=1) -> [0, 1]
     assert_tensor_equal(self.be.norm(tsr, order=float('-inf'), axis=1),
                         CPUTensor([0, 1]))
예제 #20
0
 def test_range_slicing(self):
     tns = CPUTensor([[1, 2], [3, 4]])
     res = tns[0:2, 0]
     expected_shape = (2, )
     while len(expected_shape) < res._min_dims:
         expected_shape += (1, )
     assert res.shape == expected_shape
     assert_tensor_equal(res, CPUTensor([1, 3]))
예제 #21
0
파일: test_cc2.py 프로젝트: zz119/neon
 def test_infnorm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     # -> max(abs(tsr), axis=0) -> [1, 3]
     assert_tensor_equal(self.be.norm(tsr, order=float('inf'), axis=0),
                         self.gpt([[1, 3]]))
     # -> max(abs(tsr), axis=1) -> [1, 3]
     assert_tensor_equal(self.be.norm(tsr, order=float('inf'), axis=1),
                         self.gpt([1, 3]))
예제 #22
0
파일: test_cpu.py 프로젝트: AI-Cdrone/neon
 def test_0norm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     # -> sum(tsr != 0, axis=0) -> [2, 1]
     assert_tensor_equal(self.be.norm(tsr, order=0, axis=0),
                         CPUTensor([[2, 1]]))
     # -> sum(tsr != 0, axis=1) -> [1, 2]
     assert_tensor_equal(self.be.norm(tsr, order=0, axis=1),
                         CPUTensor([1, 2]))
예제 #23
0
파일: test_cpu.py 프로젝트: AI-Cdrone/neon
 def test_2norm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     rpow = 1. / 2
     # -> sum([[1, 0], [1, 9]], axis=0)**.5 -> sqrt([2, 9])
     assert_tensor_equal(self.be.norm(tsr, order=2, axis=0),
                         CPUTensor([[2**rpow, 9**rpow]]))
     # -> sum([[1, 0], [1, 9]], axis=1)**.5 -> sqrt([1, 10])
     assert_tensor_equal(self.be.norm(tsr, order=2, axis=1),
                         CPUTensor([1**rpow, 10**rpow]))
예제 #24
0
def test_cc2_rectleaky_derivative_slope_zero_rectlin_equiv():
    from neon.backends.cc2 import GPU
    be = GPU()
    inputs = be.uniform(low=-5.0, high=10.0, size=(10, 10))
    lin_buf = be.empty(inputs.shape)
    leaky_buf = be.empty(inputs.shape)
    be.rectlin_derivative(inputs, out=lin_buf)
    be.rectleaky_derivative(inputs, slope=0.0, out=leaky_buf)
    assert_tensor_equal(lin_buf, leaky_buf)
예제 #25
0
 def test_2norm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     rpow = 1. / 2
     # -> sum([[1, 0], [1, 9]], axis=0)**.5 -> sqrt([2, 9])
     assert_tensor_equal(self.be.norm(tsr, order=2, axis=0),
                         CPUTensor([[2**rpow, 9**rpow]]))
     # -> sum([[1, 0], [1, 9]], axis=1)**.5 -> sqrt([1, 10])
     assert_tensor_equal(self.be.norm(tsr, order=2, axis=1),
                         CPUTensor([1**rpow, 10**rpow]))
예제 #26
0
파일: test_cc2.py 프로젝트: AI-Cdrone/neon
 def test_1norm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     # -> sum([[1, 0], [1, 3]], axis=0)**1 -> [2, 3]
     out = self.be.empty((1, 2))
     assert_tensor_equal(self.be.norm(tsr, order=1, axis=0, out=out),
                         self.gpt([[2, 3]]))
     # -> sum([[1, 0], [1, 3]], axis=1)**1 -> [1, 4]
     out = self.be.empty((2, 1))
     assert_tensor_equal(self.be.norm(tsr, order=1, axis=1, out=out),
                         self.gpt([1, 4]))
예제 #27
0
파일: test_cc2.py 프로젝트: AI-Cdrone/neon
 def test_0norm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     # -> sum(tsr != 0, axis=0) -> [2, 1]
     out = self.be.empty((1, 2))
     assert_tensor_equal(self.be.norm(tsr, order=0, axis=0, out=out),
                         self.gpt([[2, 1]]))
     # -> sum(tsr != 0, axis=1) -> [1, 2]
     out = self.be.empty((2, 1))
     assert_tensor_equal(self.be.norm(tsr, order=0, axis=1, out=out),
                         self.gpt([1, 2]))
예제 #28
0
파일: test_cc2.py 프로젝트: zz119/neon
 def test_0norm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     # -> sum(tsr != 0, axis=0) -> [2, 1]
     out = self.be.empty((1, 2))
     assert_tensor_equal(self.be.norm(tsr, order=0, axis=0, out=out),
                         self.gpt([[2, 1]]))
     # -> sum(tsr != 0, axis=1) -> [1, 2]
     out = self.be.empty((2, 1))
     assert_tensor_equal(self.be.norm(tsr, order=0, axis=1, out=out),
                         self.gpt([1, 2]))
예제 #29
0
파일: test_cc2.py 프로젝트: zz119/neon
 def test_1norm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     # -> sum([[1, 0], [1, 3]], axis=0)**1 -> [2, 3]
     out = self.be.empty((1, 2))
     assert_tensor_equal(self.be.norm(tsr, order=1, axis=0, out=out),
                         self.gpt([[2, 3]]))
     # -> sum([[1, 0], [1, 3]], axis=1)**1 -> [1, 4]
     out = self.be.empty((2, 1))
     assert_tensor_equal(self.be.norm(tsr, order=1, axis=1, out=out),
                         self.gpt([1, 4]))
예제 #30
0
파일: test_cpu.py 프로젝트: AI-Cdrone/neon
 def test_lrgnorm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     rpow = 1. / 5
     # -> sum([[1, 0], [1, 243]], axis=0)**rpow -> rpow([2, 243])
     assert_tensor_equal(self.be.norm(tsr, order=5, axis=0),
                         CPUTensor([[2**rpow, 243**rpow]]))
     # -> sum([[1, 0], [1, 243]], axis=1)**rpow -> rpow([1, 244])
     # 244**.2 == ~3.002465 hence the near_equal test
     assert_tensor_near_equal(self.be.norm(tsr, order=5, axis=1),
                              CPUTensor([1**rpow, 244**rpow]), 1e-6)
예제 #31
0
def compare_cpu_tensors(inputs, outputs, deriv=False):
    rlin = RectLeaky()
    be = CPU()
    temp = be.zeros(inputs.shape)
    if deriv is True:
        rlin.apply_derivative(be, CPUTensor(inputs), temp)
    else:
        rlin.apply_function(be, CPUTensor(inputs), temp)
    be.subtract(temp, CPUTensor(outputs), temp)
    assert_tensor_equal(temp, be.zeros(inputs.shape))
예제 #32
0
 def test_lrgnorm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     rpow = 1. / 5
     # -> sum([[1, 0], [1, 243]], axis=0)**rpow -> rpow([2, 243])
     assert_tensor_equal(self.be.norm(tsr, order=5, axis=0),
                         CPUTensor([[2**rpow, 243**rpow]]))
     # -> sum([[1, 0], [1, 243]], axis=1)**rpow -> rpow([1, 244])
     # 244**.2 == ~3.002465 hence the near_equal test
     assert_tensor_near_equal(self.be.norm(tsr, order=5, axis=1),
                              CPUTensor([1**rpow, 244**rpow]), 1e-6)
예제 #33
0
파일: test_cc2.py 프로젝트: zz119/neon
 def test_2norm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     rpow = 1. / 2
     # -> sum([[1, 0], [1, 9]], axis=0)**.5 -> sqrt([2, 9])
     out = self.be.empty((1, 2))
     assert_tensor_equal(self.be.norm(tsr, order=2, axis=0, out=out),
                         self.gpt([[2**rpow, 9**rpow]]))
     # -> sum([[1, 0], [1, 9]], axis=1)**.5 -> sqrt([1, 10])
     out = self.be.empty((2, 1))
     assert_tensor_equal(self.be.norm(tsr, order=2, axis=1, out=out),
                         self.gpt([1**rpow, 10**rpow]))
예제 #34
0
 def test_negnorm(self):
     tsr = self.be.array([[-1, -2], [1, 3]])
     rpow = -1. / 3
     # -> sum([[1, .125], [1, .037037]], axis=0)**rpow -> rpow([2, .162037])
     assert_tensor_equal(self.be.norm(tsr, order=-3, axis=0),
                         CPUTensor([[2**rpow, .162037037037**rpow]]))
     # -> sum([[1, .125], [1, .037037]], axis=1)**rpow ->
     # rpow([1.125, 1.037037])
     assert_tensor_near_equal(self.be.norm(tsr, order=-3, axis=1),
                              CPUTensor([1.125**rpow, 1.037037**rpow]),
                              1e-6)
예제 #35
0
파일: test_cc2.py 프로젝트: AI-Cdrone/neon
 def test_2norm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     rpow = 1. / 2
     # -> sum([[1, 0], [1, 9]], axis=0)**.5 -> sqrt([2, 9])
     out = self.be.empty((1, 2))
     assert_tensor_equal(self.be.norm(tsr, order=2, axis=0, out=out),
                         self.gpt([[2**rpow, 9**rpow]]))
     # -> sum([[1, 0], [1, 9]], axis=1)**.5 -> sqrt([1, 10])
     out = self.be.empty((2, 1))
     assert_tensor_equal(self.be.norm(tsr, order=2, axis=1, out=out),
                         self.gpt([1**rpow, 10**rpow]))
예제 #36
0
파일: test_cpu.py 프로젝트: AI-Cdrone/neon
 def test_negnorm(self):
     tsr = self.be.array([[-1, -2], [1, 3]])
     rpow = -1. / 3
     # -> sum([[1, .125], [1, .037037]], axis=0)**rpow -> rpow([2, .162037])
     assert_tensor_equal(self.be.norm(tsr, order=-3, axis=0),
                         CPUTensor([[2**rpow, .162037037037**rpow]]))
     # -> sum([[1, .125], [1, .037037]], axis=1)**rpow ->
     # rpow([1.125, 1.037037])
     assert_tensor_near_equal(self.be.norm(tsr, order=-3, axis=1),
                              CPUTensor([1.125**rpow, 1.037037**rpow]),
                              1e-6)
예제 #37
0
def compare_cc2_tensors(inputs, outputs, deriv=False):
    from neon.backends.cc2 import GPU, GPUTensor
    rlin = RectLeaky()
    be = GPU()
    temp = be.zeros(inputs.shape)
    if deriv is True:
        rlin.apply_derivative(be, GPUTensor(inputs), temp)
    else:
        rlin.apply_function(be, GPUTensor(inputs), temp)
    be.subtract(temp, GPUTensor(outputs), temp)
    assert_tensor_equal(temp, be.zeros(inputs.shape))
예제 #38
0
파일: test_cc2.py 프로젝트: AI-Cdrone/neon
 def test_lrgnorm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     rpow = 1. / 5
     # -> sum([[1, 0], [1, 243]], axis=0)**rpow -> rpow([2, 243])
     out = self.be.empty((1, 2))
     assert_tensor_equal(self.be.norm(tsr, order=5, axis=0, out=out),
                         self.gpt([[2**rpow, 243**rpow]]))
     # -> sum([[1, 0], [1, 243]], axis=1)**rpow -> rpow([1, 244])
     # 244**.2 == ~3.002465 hence the near_equal test
     out = self.be.empty((2, 1))
     assert_tensor_near_equal(self.be.norm(tsr, order=5, axis=1, out=out),
                              self.gpt([1**rpow, 244**rpow]), 1e-6)
예제 #39
0
파일: test_cc2.py 프로젝트: zz119/neon
 def test_lrgnorm(self):
     tsr = self.be.array([[-1, 0], [1, 3]])
     rpow = 1. / 5
     # -> sum([[1, 0], [1, 243]], axis=0)**rpow -> rpow([2, 243])
     out = self.be.empty((1, 2))
     assert_tensor_equal(self.be.norm(tsr, order=5, axis=0, out=out),
                         self.gpt([[2**rpow, 243**rpow]]))
     # -> sum([[1, 0], [1, 243]], axis=1)**rpow -> rpow([1, 244])
     # 244**.2 == ~3.002465 hence the near_equal test
     out = self.be.empty((2, 1))
     assert_tensor_near_equal(self.be.norm(tsr, order=5, axis=1, out=out),
                              self.gpt([1**rpow, 244**rpow]), 1e-6)
예제 #40
0
파일: test_cc2.py 프로젝트: zz119/neon
 def test_negnorm(self):
     tsr = self.be.array([[-1, -2], [1, 3]])
     rpow = -1. / 3
     # -> sum([[1, .125], [1, .037037]], axis=0)**rpow -> rpow([2, .162037])
     out = self.be.empty((1, 2))
     assert_tensor_equal(self.be.norm(tsr, order=-3, axis=0, out=out),
                         self.gpt([[2**rpow, .162037037037**rpow]]))
     # -> sum([[1, .125], [1, .037037]], axis=1)**rpow ->
     # rpow([1.125, 1.037037])
     out = self.be.empty((2, 1))
     assert_tensor_near_equal(self.be.norm(tsr, order=-3, axis=1, out=out),
                              self.gpt([1.125**rpow, 1.037037**rpow]), 1e-6)
예제 #41
0
파일: test_cc2.py 프로젝트: AI-Cdrone/neon
 def test_negnorm(self):
     tsr = self.be.array([[-1, -2], [1, 3]])
     rpow = -1. / 3
     # -> sum([[1, .125], [1, .037037]], axis=0)**rpow -> rpow([2, .162037])
     out = self.be.empty((1, 2))
     assert_tensor_equal(self.be.norm(tsr, order=-3, axis=0, out=out),
                         self.gpt([[2**rpow, .162037037037**rpow]]))
     # -> sum([[1, .125], [1, .037037]], axis=1)**rpow ->
     # rpow([1.125, 1.037037])
     out = self.be.empty((2, 1))
     assert_tensor_near_equal(self.be.norm(tsr, order=-3, axis=1, out=out),
                              self.gpt([1.125**rpow, 1.037037**rpow]),
                              1e-6)
예제 #42
0
def check_bprop(layer, backend):
    errors = backend.ones((nout, batch_size))
    deltas = backend.zeros((nin, batch_size))
    deltas[:2] = backend.ones((nout, batch_size))

    # initialize deltas since they are not set
    # by the layer initialize method.
    layer.deltas = backend.ones((nin, batch_size))

    # layers should be refactored to remove references
    # to external layers. inputs can be cached during
    # fprop.
    class PreviousLayer(object):
        def __init__(self):
            self.is_data = True
            self.output = backend.ones((nin, batch_size))

    layer.prev_layer = PreviousLayer()
    layer.bprop(errors)
    assert_tensor_equal(layer.deltas, deltas)
예제 #43
0
def check_bprop(layer, backend):
        errors = backend.ones((nout, batch_size))
        deltas = backend.zeros((nin, batch_size))
        deltas[:2] = backend.ones((nout, batch_size))

        # initialize deltas since they are not set
        # by the layer initialize method.
        layer.deltas = backend.ones((nin, batch_size))

        # layers should be refactored to remove references
        # to external layers. inputs can be cached during
        # fprop.
        class PreviousLayer(object):

            def __init__(self):
                self.is_data = True
                self.output = backend.ones((nin, batch_size))

        layer.prev_layer = PreviousLayer()
        layer.bprop(errors)
        assert_tensor_equal(layer.deltas, deltas)
예제 #44
0
def m_assert_tensor_equal(t1, t2):
    for _t1, _t2, ctx in zip(t1._tensorlist, t2._tensorlist, t1._ctxs):
        ctx.push()
        assert_tensor_equal(_t1, _t2)
        ctx.pop()
예제 #45
0
 def test_fill(self):
     tns = self.gpt([[1, 2], [3, 4]])
     tns.fill(-9.5)
     assert_tensor_equal(tns, self.gpt([[-9.5, -9.5], [-9.5, -9.5]]))
예제 #46
0
 def test_fill(self):
     tns = CPUTensor([[1, 2], [3, 4]])
     tns.fill(-9.5)
     assert_tensor_equal(tns, CPUTensor([[-9.5, -9.5], [-9.5, -9.5]]))
예제 #47
0
 def test_transpose(self):
     tns = CPUTensor([[1, 2], [3, 4]])
     res = tns.transpose()
     assert_tensor_equal(res, CPUTensor([[1, 3], [2, 4]]))
예제 #48
0
 def test_asnumpyarray(self):
     tns = CPUTensor([[1, 2], [3, 4]])
     res = tns.asnumpyarray()
     assert isinstance(res, np.ndarray)
     assert_tensor_equal(res, np.array([[1, 2], [3, 4]]))
예제 #49
0
 def test_scalar_slice_assignment(self):
     tns = CPUTensor([[1, 2], [3, 4]])
     tns[1, 0] = 9
     assert_tensor_equal(tns, CPUTensor([[1, 2], [9, 4]]))
예제 #50
0
def check_fprop(layer, backend):
    inputs = backend.ones((nin, batch_size))
    output = backend.ones((nout, batch_size))
    layer.fprop(inputs)
    assert_tensor_equal(layer.output, output)