Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test basic ops for NdArray with size 0. #478

Merged
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Test basic ops for NdArray with size 0.

  • Loading branch information...
TE-StephenTiedemann committed Jun 12, 2019
commit 93d7c4a9f833440ddcf2b2dcd89be2e41336c9e8
@@ -23,12 +23,12 @@
@pytest.mark.parametrize("seed", [313])
@pytest.mark.parametrize("op", ["+", "-", "*", "/", "**"])
@pytest.mark.parametrize("x_var, y_var", [(False, False), (False, True), (True, False)])
def test_ndarray_arithmetic_ops2(seed, op, x_var, y_var):
@pytest.mark.parametrize("shape", [(2, 3, 4), (0,)])
def test_ndarray_arithmetic_ops2(seed, op, x_var, y_var, shape):
rng = np.random.RandomState(seed)
shape = [2, 3, 4]
vx_data = rng.randn(*shape).astype(np.float32)
vy_data = rng.randn(*shape).astype(np.float32)
if op == "**":
if op == "**" and vx_data.size > 0:
vx_data += - vx_data.min() + 1.0
if x_var:
vx = nn.Variable.from_numpy_array(vx_data)
@@ -54,11 +54,12 @@ def test_ndarray_arithmetic_ops2(seed, op, x_var, y_var):

@pytest.mark.parametrize("seed", [313, 314])
@pytest.mark.parametrize("op", ["+", "-", "*", "/", "**"])
def test_ndarray_arithmetic_scalar_ops(seed, op):
@pytest.mark.parametrize("shape", [(2, 3, 4), (0,)])
def test_ndarray_arithmetic_scalar_ops(seed, op, shape):
rng = np.random.RandomState(seed)
vx = nn.NdArray.from_numpy_array(rng.randn(2, 3, 4).astype(np.float32))
vx = nn.NdArray.from_numpy_array(rng.randn(*shape).astype(np.float32))
a = rng.randn()
if op == "**":
if op == "**" and vx.size > 0:
vx.data += - vx.data.min() + 1.0
vz = eval("vx {0} a".format(op))
ref_z = eval("vx.data {0} a".format(op))
@@ -73,9 +74,10 @@ def test_ndarray_arithmetic_scalar_ops(seed, op):

@pytest.mark.parametrize("seed", [313, 314])
@pytest.mark.parametrize("op", ["+", "-", "*", "/", "**"])
def test_ndarray_arithmetic_scalar_rops(seed, op):
@pytest.mark.parametrize("shape", [(2, 3, 4), (0,)])
def test_ndarray_arithmetic_scalar_rops(seed, op, shape):
rng = np.random.RandomState(seed)
vx = nn.NdArray.from_numpy_array(rng.randn(2, 3, 4).astype(np.float32))
vx = nn.NdArray.from_numpy_array(rng.randn(*shape).astype(np.float32))
a = rng.randn()
if op == "**":
a = np.abs(a)
@@ -86,9 +88,10 @@ def test_ndarray_arithmetic_scalar_rops(seed, op):

@pytest.mark.parametrize("seed", [313, 314])
@pytest.mark.parametrize("op", ["+", "-"])
def test_ndarray_arithmetic_unary_ops(seed, op):
@pytest.mark.parametrize("shape", [(2, 3, 4), (0,)])
def test_ndarray_arithmetic_unary_ops(seed, op, shape):
rng = np.random.RandomState(seed)
vx = nn.NdArray.from_numpy_array(rng.randn(2, 3, 4).astype(np.float32))
vx = nn.NdArray.from_numpy_array(rng.randn(*shape).astype(np.float32))
vz = eval("{0} vx".format(op))
ref_z = eval("{0} vx.data".format(op))
assert np.allclose(ref_z, vz.data)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.