def test_div(self): a1, n1 = self.prepare((2, 3)) a2 = A([[3, 2, 2], [4, 5, 4]], dtype=float) n2 = Nplike(a2) res = A([[0, 1.0 / 2.0, 1.0], [0.75, 0.8, 1.25]]) array_almost_equal((n1 / n2).eval(), res) array_almost_equal((n1 / a2).eval(), res)
def test_amax(self): a, n = self.prepare((2, 3)) m = n.amax(axis=0, keepdims=True) m2 = n.amax(axis=1, keepdims=True) b1 = m.eval() b2 = m2.eval() array_almost_equal(b1, A([[3, 4, 5]])) array_almost_equal(b2, A([[2], [5]]))
def test_square(self): a, n = self.prepare((2, 3)) array_almost_equal(a * a, n.square().eval())
def test_exp(self): a = (np.arange(6) + 0.0).reshape((2, 3)) n = Nplike(a) array_almost_equal(np.exp(a), n.exp().eval())
def test_neg(self): a, n = self.prepare((2, 3)) array_almost_equal(-a, n.neg().eval())
def test_reciprocal(self): a = (np.arange(6) + 1.0).reshape((2, 3)) n = Nplike(a) array_almost_equal(n.reciprocal().eval(), 1.0 / a)
def test_rdiv(self): a = A([[3, 2, 2], [4, 5, 4]], dtype=float) n = Nplike(a) res = A([[1.0 / 3.0, 0.5, 0.5], [0.25, 0.2, 0.25]]) array_almost_equal((1.0 / n).eval(), res)
def test_from_shape1(self): n = Nplike.from_shape((2, 3), neutral=True) array_almost_equal(n.eval(), np.zeros((2, 3)))
def test_from_shape2(self): n = Nplike.from_shape((2, 3), neutral=False) array_almost_equal(n.eval(), np.ones((2, 3)))
def test_abs(self): a, n = self.prepare((2, 3)) n -= 3 s = n.abs() array_almost_equal(s.eval(), A([[3, 2, 1], [0, 1, 2]]))
def test_T(self): a, n = self.prepare((2, 3)) m = n.T array_almost_equal(m.eval(), A([[0, 3], [1, 4], [2, 5]]))
def test_sum(self): a, n = self.prepare((2, 3)) s = n.sum() array_almost_equal(s.eval(), A([15]))
def test_flatten(self): a, n = self.prepare((2, 3)) m = n.flatten() array_almost_equal(m.eval(), A([0, 1, 2, 3, 4, 5]))
def test_reshape(self): a, n = self.prepare((2, 3)) m = n.reshape((6, 1)) array_almost_equal(m.eval(), A([[0], [1], [2], [3], [4], [5]]))
def test_power(self): a, n = self.prepare((2, 3)) e = 3.1415 array_almost_equal(np.power(a, e), n.power(e).eval())
def test_eval(self): a, n = self.prepare((2, 3)) array_almost_equal(n.eval(), a)
def test_dot(self): a, n = self.prepare((2, 3)) b, m = self.prepare((3, 4)) p = n.dot(b).eval() array_almost_equal(p, A([[20, 23, 26, 29], [56, 68, 80, 92]]))
def test_max(self): a, n = self.prepare((2, 3)) b = A([[3, 0, 3], [0, 3, -123]]) array_almost_equal(n.max(b).eval(), A([[3, 1, 3], [3, 4, 5]]))