示例#1
0
def test_unary_op_array_err(ng_api_fn, numpy_fn, range_start, range_end):
    np.random.seed(133391)
    input_data = range_start + np.random.rand(2, 3, 4) * (range_end - range_start)
    expected = numpy_fn(input_data)

    result = run_op_numeric_data(input_data, ng_api_fn)
    assert np.allclose(result, expected)
示例#2
0
def test_logical_not(input_data):
    expected = np.logical_not(input_data)

    result = run_op_node([input_data], ng.logical_not)

    assert np.allclose(result, expected)
    result = run_op_numeric_data(input_data, ng.logical_not)
    assert np.allclose(result, expected)
示例#3
0
def test_unary_op_scalar(ng_api_fn, numpy_fn, input_data):
    expected = numpy_fn(input_data)

    result = run_op_node([input_data], ng_api_fn)
    assert np.allclose(result, expected)

    result = run_op_numeric_data(input_data, ng_api_fn)
    assert np.allclose(result, expected)
示例#4
0
def test_constant_from_integer_array(val_type, range_start, range_end):
    np.random.seed(133391)
    input_data = np.array(np.random.randint(range_start,
                                            range_end,
                                            size=(2, 2)),
                          dtype=val_type)
    result = run_op_numeric_data(input_data, ng.constant, val_type)
    assert np.allclose(result, input_data)
示例#5
0
def test_unary_op_scalar(ng_api_fn, numpy_fn, input_data):
    expected = numpy_fn(input_data)

    result = run_op_node([input_data], ng_api_fn)
    assert np.allclose(result, expected)

    result = run_op_numeric_data(input_data, ng_api_fn)
    assert np.allclose(result, expected)
示例#6
0
def test_logical_not(input_data):
    expected = np.logical_not(input_data)

    result = run_op_node([input_data], ng.logical_not)[0]

    assert np.array_equal(result, expected)
    result = run_op_numeric_data(input_data, ng.logical_not)[0]
    assert np.array_equal(result, expected)
示例#7
0
def test_unary_op_array_err(ng_api_fn, numpy_fn, range_start, range_end):
    np.random.seed(133391)
    input_data = range_start + np.random.rand(2, 3,
                                              4) * (range_end - range_start)
    expected = numpy_fn(input_data)

    result = run_op_numeric_data(input_data, ng_api_fn)
    assert np.allclose(result, expected)
示例#8
0
def test_erf():
    input_tensor = np.array([-1.0, 0.0, 1.0, 2.5, 3.14, 4.0], dtype=np.float32)
    expected = [-0.842701, 0.0, 0.842701, 0.999593, 0.999991, 1.0]

    result = run_op_node([input_tensor], ng.erf)
    assert np.allclose(result, expected)

    result = run_op_numeric_data(input_tensor, ng.erf)
    assert np.allclose(result, expected)
示例#9
0
def test_unary_op_array(ng_api_fn, numpy_fn, range_start, range_end):
    np.random.seed(133391)
    input_data = range_start + np.random.rand(2, 3, 4) * (range_end - range_start)
    expected = numpy_fn(input_data)

    result = run_op_node([input_data], ng_api_fn)[0]
    np.testing.assert_allclose(result, expected, rtol=0.001)

    result = run_op_numeric_data(input_data, ng_api_fn)[0]
    np.testing.assert_allclose(result, expected, rtol=0.001)
示例#10
0
def test_gather():
    input_data = np.array([1.0, 1.1, 1.2, 2.0, 2.1, 2.2, 3.0, 3.1, 3.2], np.float32).reshape((3, 3))
    input_indices = np.array([0, 2], np.int64).reshape(1, 2)
    input_axes = np.array([1], np.int64)

    expected = np.array([1.0, 1.2, 2.0, 2.2, 3.0, 3.2], dtype=np.float32).reshape((3, 1, 2))

    result = run_op_node([input_data, input_indices, input_axes], ng.gather)
    assert np.allclose(result, expected)

    result = run_op_numeric_data(input_data, ng.gather, input_indices, input_axes)
    assert np.allclose(result, expected)
示例#11
0
def test_constant_from_float_array(val_type):
    np.random.seed(133391)
    input_data = np.array(-1 + np.random.rand(2, 3, 4) * 2, dtype=val_type)
    result = run_op_numeric_data(input_data, ng.constant, val_type)
    assert np.allclose(result, input_data)
示例#12
0
def test_constant_from_scalar(val_type, value):
    expected = np.array(value, dtype=val_type)
    result = run_op_numeric_data(value, ng.constant, val_type)
    assert np.allclose(result, expected)
示例#13
0
def test_constant_from_integer_array(val_type, range_start, range_end):
    np.random.seed(133391)
    input_data = np.array(np.random.randint(range_start, range_end, size=(2, 2)), dtype=val_type)
    result = run_op_numeric_data(input_data, ng.constant, val_type)
    assert np.allclose(result, input_data)
示例#14
0
def test_constant_from_float_array(val_type):
    np.random.seed(133391)
    input_data = np.array(-1 + np.random.rand(2, 3, 4) * 2, dtype=val_type)
    result = run_op_numeric_data(input_data, ng.constant, val_type)
    assert np.allclose(result, input_data)
示例#15
0
def test_constant_from_scalar(val_type, value):
    expected = np.array(value, dtype=val_type)
    result = run_op_numeric_data(value, ng.constant, val_type)
    assert np.allclose(result, expected)