コード例 #1
0
def test_float_exp_():
    data = np.array([0., 1., 2., 5.])
    expected = np.array([1., 2.71828183, 7.3890561, 148.4131591])
    a = FloatTensor(data)
    a.exp_()

    # a does change when inlined
    np.testing.assert_almost_equal(expected, a.to_numpy(), decimal=4)
コード例 #2
0
def test_float_log1p_():
    data = np.array([1.2, -0.9, 9.9, 0.1, -0.455])
    expected = np.array([0.78845736, -2.30258509,  2.38876279,  0.09531018, -0.60696948])
    a = FloatTensor(data)
    a.log1p_()

    # a does change when inlined
    np.testing.assert_almost_equal(expected, a.to_numpy(), decimal=5)
コード例 #3
0
def test_float_reciprocal_():
    data = np.array([1., 2., 3., 4.])
    expected = np.array([1., 0.5, 0.33333333, 0.25])
    a = FloatTensor(data)
    a.reciprocal_()

    # a does change when inlined
    np.testing.assert_almost_equal(expected, a.to_numpy(), decimal=4)
コード例 #4
0
def test_float_round_():
    data = np.array([12.7292, -3.11, 9.00, 20.4999, 20.5001])
    expected = np.array([13, -3, 9, 20, 21])
    a = FloatTensor(data)
    a.round_()

    # a does change when inlined
    np.testing.assert_array_equal(expected, a.to_numpy())
コード例 #5
0
def test_float_rsqrt_():
    data = np.array([1., 2., 3., 4.])
    expected = np.array([1., 0.7071068, 0.5773503, 0.5])
    a = FloatTensor(data)
    a.rsqrt_()

    # a does change when inlined
    np.testing.assert_almost_equal(expected, a.to_numpy(), decimal=4)
コード例 #6
0
def test_float_sqrt_():
    data = np.array([1., 2., 3., 4.])
    expected = np.array([1., 1.41421356, 1.73205081, 2.])
    a = FloatTensor(data)
    a.sqrt_()

    # a does change when inlined
    np.testing.assert_almost_equal(expected, a.to_numpy(), decimal=4)
コード例 #7
0
def test_float_exp_():
    data = np.array([0, np.log(2)])
    expected = np.array([1., 2.])
    a = FloatTensor(data)
    a.exp_()

    # a does change when inlined
    np.testing.assert_almost_equal(a.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #8
0
def test_float_erfinv_():
    data = np.array([0, 0.5, -1.])
    expected = np.array([0., 0.47693628, -np.inf])
    a = FloatTensor(data)
    a.erfinv_()

    # a does change when inlined
    np.testing.assert_almost_equal(a.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #9
0
def test_float_erf_():
    data = np.array([0, -1., 10.])
    expected = np.array([0., -0.84270078, 1.])
    a = FloatTensor(data)
    a.erf_()

    # a does change when inlined
    np.testing.assert_almost_equal(a.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #10
0
def test_float_cosh_():
    data = np.array([-0.6366, 0.2718, 0.4469, 1.3122])
    expected = np.array([1.209566, 1.03716552, 1.10153294, 1.99178159])
    a = FloatTensor(data)
    a.cosh_()

    # a does change when inlined
    np.testing.assert_almost_equal(a.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #11
0
def test_float_cos_():
    data = np.array([-0.6366, 0.2718, 0.4469, 1.3122])
    expected = np.array([0.80412155, 0.9632892, 0.90179116, 0.25572386])
    a = FloatTensor(data)
    a.cos_()

    # a does change when inlined
    np.testing.assert_almost_equal(a.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #12
0
def test_float_atan_():
    data = np.array([-0.6366, 0.2718, 0.4469, 1.3122])
    expected = np.array([-0.56689745, 0.26538879, 0.42027298, 0.91960937])
    a = FloatTensor(data)
    a.atan_()

    # a does change when inlined
    np.testing.assert_almost_equal(a.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #13
0
def test_float_asin_():
    data = np.array([-0.6366, 0.2718, 0.4469, 1.3122])
    expected = np.array([-0.69008148, 0.27526295, 0.46329704, np.nan])
    a = FloatTensor(data)
    a.asin_()

    # a does change when inlined
    np.testing.assert_almost_equal(a.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #14
0
def test_float_floor_():
    data = np.array([1.3869, 0.3912, -0.8634, -0.5468])
    expected = np.array([1., 0., -1., -1.])
    a = FloatTensor(data)
    a.floor_()

    # a does change when inlined
    np.testing.assert_almost_equal(a.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #15
0
def test_float_sqrt():
    data = np.array([1., 2., 3., 4.])
    expected = np.array([1., 1.41421356, 1.73205081, 2.])
    a = FloatTensor(data)
    b = a.sqrt()

    np.testing.assert_almost_equal(expected, b.to_numpy(), decimal=4)
    # a doesn't change
    np.testing.assert_array_equal(data, a.to_numpy())
コード例 #16
0
def test_float_acos_():
    data = np.array([-1., -2., 3., 4., 5., -6.])
    expected = np.array([1., 2., 3., 4., 5., 6.])
    a = FloatTensor(data)
    a.abs_()

    # a does change when inlined
    np.testing.assert_almost_equal(a.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #17
0
def test_float_rsqrt():
    data = np.array([1., 2., 3., 4.])
    expected = np.array([1., 0.7071068, 0.5773503, 0.5])
    a = FloatTensor(data)
    b = a.rsqrt()

    np.testing.assert_almost_equal(expected, b.to_numpy(), decimal=4)
    # a doesn't change
    np.testing.assert_array_equal(data, a.to_numpy())
コード例 #18
0
def test_float_round():
    data = np.array([12.7292, -3.11, 9.00, 20.4999, 20.5001])
    expected = np.array([13, -3, 9, 20, 21])
    a = FloatTensor(data)
    b = a.round()

    np.testing.assert_array_equal(expected, b.to_numpy())
    # a doesn't change
    np.testing.assert_array_equal(data, a.to_numpy())
コード例 #19
0
def test_float_reciprocal():
    data = np.array([1., 2., 3., 4.])
    expected = np.array([1., 0.5, 0.33333333, 0.25])
    a = FloatTensor(data)
    b = a.reciprocal()

    np.testing.assert_almost_equal(expected, b.to_numpy(), decimal=4)
    # a doesn't change
    np.testing.assert_array_equal(data, a.to_numpy())
コード例 #20
0
def test_float_exp():
    data = np.array([0., 1., 2., 5.])
    expected = np.array([1., 2.71828183, 7.3890561, 148.4131591])
    a = FloatTensor(data)
    b = a.exp()

    np.testing.assert_almost_equal(expected, b.to_numpy(), decimal=4)
    # a doesn't change
    np.testing.assert_array_equal(data, a.to_numpy())
コード例 #21
0
def test_float_fmod_():
    data = np.array([-3, -2, -1, 1, 2, 3])
    expected = np.array([-1., -0., -1., 1., 0., 1.])
    a = FloatTensor(data)
    a.fmod_(2)

    # a does change when inlined
    np.testing.assert_almost_equal(a.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #22
0
def test_float_fmod():
    data = np.array([-3, -2, -1, 1, 2, 3])
    expected = np.array([-1., -0., -1., 1., 0., 1.])
    a = FloatTensor(data)
    b = a.fmod(2)

    np.testing.assert_almost_equal(b.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
    # a doesn't change
    np.testing.assert_almost_equal(a.to_numpy(), data,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #23
0
def test_float_ceil():
    data = np.array([1.3869, 0.3912, -0.8634, -0.5468])
    expected = np.array([2., 1., -0., -0.])
    a = FloatTensor(data)
    b = a.ceil()

    np.testing.assert_almost_equal(b.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
    # a doesn't change
    np.testing.assert_almost_equal(a.to_numpy(), data,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #24
0
def test_float_erf():
    data = np.array([0, -1., 10.])
    expected = np.array([0., -0.84270078, 1.])
    a = FloatTensor(data)
    b = a.erf()

    np.testing.assert_almost_equal(b.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
    # a doesn't change
    np.testing.assert_almost_equal(a.to_numpy(), data,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #25
0
def test_float_erfinv():
    data = np.array([0, 0.5, -1.])
    expected = np.array([0., 0.47693628, -np.inf])
    a = FloatTensor(data)
    b = a.erfinv()

    np.testing.assert_almost_equal(b.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
    # a doesn't change
    np.testing.assert_almost_equal(a.to_numpy(), data,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #26
0
def test_float_exp():
    data = np.array([0, np.log(2)])
    expected = np.array([1., 2.])
    a = FloatTensor(data)
    b = a.exp()

    np.testing.assert_almost_equal(b.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
    # a doesn't change
    np.testing.assert_almost_equal(a.to_numpy(), data,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #27
0
def test_float_acos():
    data = np.array([-0.6366, 0.2718, 0.4469, 1.3122])
    expected = np.array([2.26087785, 1.2955333, 1.10749924, np.nan])
    a = FloatTensor(data)
    b = a.acos()

    np.testing.assert_almost_equal(b.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
    # a doesn't change
    np.testing.assert_almost_equal(a.to_numpy(), data,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #28
0
def test_float_abs():
    data = np.array([-1., -2., 3., 4., 5., -6.])
    expected = np.array([1., 2., 3., 4., 5., 6.])
    a = FloatTensor(data)
    b = a.abs()

    np.testing.assert_almost_equal(b.to_numpy(), expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
    # a doesn't change
    np.testing.assert_almost_equal(a.to_numpy(), data,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #29
0
def test_float_trace():
    data = np.random.randn(17, 17).astype('float')
    expected = data.trace()

    a = FloatTensor(data)
    actual = a.trace()
    np.testing.assert_almost_equal(actual, expected,
                                   decimal=decimal_accuracy, verbose=verbosity)

    a = a.gpu()
    actual = a.trace()
    np.testing.assert_almost_equal(actual, expected,
                                   decimal=decimal_accuracy, verbose=verbosity)
コード例 #30
0
ファイル: sequential.py プロジェクト: ygambhir/PySyft
	def predict(self,x):

		if(type(x) == list):
			x = np.array(x).astype('float')
		if(type(x) == np.array or type(x) == np.ndarray):
			x = FloatTensor(x,autograd=True, delete_after_use=False)

		return self.syft.forward(input=x).to_numpy()