예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
0
def test_unary_op_array_using_constants(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, rtol=0.001)
예제 #6
0
def test_gather_using_constants():
    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_numeric_data(input_data, ng.gather, input_indices,
                                 input_axes)
    assert np.allclose(result, expected)
예제 #7
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)
예제 #8
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)
예제 #9
0
def test_logical_not_using_constants(input_data):
    expected = np.logical_not(input_data)

    result = run_op_numeric_data(input_data, ng.logical_not)
    assert np.allclose(result, expected)
예제 #10
0
def test_unary_op_scalar_using_constants(ng_api_fn, numpy_fn, input_data):
    expected = numpy_fn(input_data)

    result = run_op_numeric_data(input_data, ng_api_fn)
    assert np.allclose(result, expected)