def test_backward_dot_muti_array(seed, shape_a, shape_b): rng = np.random.RandomState(seed) a = rng.randn(*shape_a).astype(np.float32) b = rng.randn(*shape_b).astype(np.float32) inputs = [ a, b, ] function_network_tester(rng, F.dot, inputs)
def test_backward_dot_muti_array_out(seed, shape_a, shape_b): rng = np.random.RandomState(seed) a = rng.randn(*shape_a).astype(np.float32) b = rng.randn(*shape_b).astype(np.float32) inputs = [ a, b, ] v_a = nn.Variable.from_numpy_array(a) v_b = nn.Variable.from_numpy_array(b) ans = F.dot(v_a, v_b) out = nn.Variable(ans.shape) out.data.cast(np.float32) function_network_tester(rng, F.dot, inputs, func_args=[out], args_out=True)
def test_backward_dot_have_scalar_out(seed, shape_a, shape_b): rng = np.random.RandomState(seed) inputs = [] func_args = [] if not shape_a: a = rng.randn() func_args += [a] v_a = nn.Variable() v_a.data.cast(np.float32)[...] = a else: a = rng.randn(*shape_a).astype(np.float32) inputs += [a] v_a = nn.Variable.from_numpy_array(a) if not shape_b: b = rng.randn() func_args += [b] v_b = nn.Variable() v_b.data.cast(np.float32)[...] = b else: b = rng.randn(*shape_b).astype(np.float32) inputs += [b] v_b = nn.Variable.from_numpy_array(b) ans = F.dot(v_a, v_b) out = nn.Variable(ans.shape) out.data.cast(np.float32) func_args += [out] function_network_tester(rng, F.dot, inputs, func_args=func_args, have_scalar=True, args_out=True)
def test_backward_dot_have_scalar(seed, shape_a, shape_b): rng = np.random.RandomState(seed) inputs = [] func_args = [] if not shape_a: a = rng.randn() func_args += [a] else: a = rng.randn(*shape_a).astype(np.float32) inputs += [a] if not shape_b: b = rng.randn() func_args += [b] else: b = rng.randn(*shape_b).astype(np.float32) inputs += [b] function_network_tester(rng, F.dot, inputs, func_args=func_args, have_scalar=True)