def test_op_plus_var_sequences_input_input(left_batch, right_batch, device_id, precision): from .. import plus, sequence assert len(left_batch) == len(right_batch) expected_forward = [ AA(left_batch[i]) + AA(right_batch[i]) for i in range(len(left_batch)) ] expected_backward = { 'left': _ones_like(left_batch, PRECISION_TO_TYPE[precision]), 'right': _ones_like(right_batch, PRECISION_TO_TYPE[precision]) } left_value = [ AA(sample, dtype=PRECISION_TO_TYPE[precision]) for sample in left_batch ] left_shape = left_value[0][0].shape right_value = [ AA(sample, dtype=PRECISION_TO_TYPE[precision]) for sample in right_batch ] right_shape = right_value[0][0].shape a = sequence.input_variable(shape=left_shape, dtype=sanitize_dtype_cntk( PRECISION_TO_TYPE[precision]), needs_gradient=True, name='a') b = sequence.input_variable(shape=right_shape, dtype=sanitize_dtype_cntk( PRECISION_TO_TYPE[precision]), needs_gradient=True, name='b') input_op_input = plus(a, b) forward_input = {a: left_value, b: right_value} backward_input = {a: None, b: None} expected_backward = { a: expected_backward['left'], b: expected_backward['right'], } unittest_helper(input_op_input, forward_input, expected_forward, expected_backward, device_id, precision)
def test_op_plus_var_sequences_input_input(left_batch, right_batch, device_id, precision): from .. import plus, sequence assert len(left_batch) == len(right_batch) expected_forward = [AA(left_batch[i]) + AA(right_batch[i]) for i in range(len(left_batch))] expected_backward = { 'left': _ones_like(left_batch, PRECISION_TO_TYPE[precision]), 'right': _ones_like(right_batch, PRECISION_TO_TYPE[precision]) } left_value = [AA(sample, dtype=PRECISION_TO_TYPE[precision]) for sample in left_batch] left_shape = left_value[0][0].shape right_value = [AA(sample, dtype=PRECISION_TO_TYPE[precision]) for sample in right_batch] right_shape = right_value[0][0].shape a = sequence.input_variable(shape=left_shape, dtype=sanitize_dtype_cntk(PRECISION_TO_TYPE[precision]), needs_gradient=True, name='a') b = sequence.input_variable(shape=right_shape, dtype=sanitize_dtype_cntk(PRECISION_TO_TYPE[precision]), needs_gradient=True, name='b') input_op_input = plus(a, b) forward_input = {a: left_value, b: right_value} backward_input = {a: None, b: None} expected_backward = { a: expected_backward['left'], b: expected_backward['right'], } unittest_helper(input_op_input, forward_input, expected_forward, expected_backward, device_id, precision)