implementing tests for elementdivide (currently fail)

This commit is contained in:
William Darling 2016-04-08 15:39:02 +02:00 коммит произвёл jeanfad
Родитель 8322e421e6
Коммит 4630e4bfca
2 изменённых файлов: 42 добавлений и 4 удалений

Просмотреть файл

@ -93,16 +93,18 @@ class ComputationNode(object):
# NOTE supported in Python 3.5
return Times(other, self)
def __div__(self, other):
def __truediv__(self, other):
if not isinstance(other, ComputationNode):
# TODO: in case of non-scalars we have to pull in a reader
other = constant(other)
self.__div__ = self.__truediv__
return ElementDivide(self, other)
def __rdiv__(self, other):
def __rtruediv__(self, other):
if not isinstance(other, ComputationNode):
# TODO: in case of non-scalars we have to pull in a reader
other = constant(other)
self.__rdiv__ = self.__rtruediv__
return ElementDivide(other, self)
def __abs__(self):

Просмотреть файл

@ -31,7 +31,7 @@ def test_op_plus(left_operand, right_operand, device_id, precision):
#Forward pass test
#==================
#we compute the expected output for the forward pass
# we compute the expected output for the forward pass
# we need two surrounding brackets
# the first for sequences (length=1, since we have has_sequence_dimension=False)
# the second for batch of one sample
@ -56,4 +56,40 @@ def test_op_plus(left_operand, right_operand, device_id, precision):
precision=precision, clean_up=True, backward_pass=True, input_node=a)
unittest_helper(right_as_input, expected, device_id=device_id,
precision=precision, clean_up=True, backward_pass=True, input_node=b)
# -- element divide tests --
# Testing inputs
@pytest.mark.parametrize("left_operand, right_operand", [
([30], [10]),
([[30]], [[10]]),
([[1.5,2.1]], [[10,20]]),
])
def test_op_element_divide(left_operand, right_operand, device_id, precision):
#Forward pass test
#==================
# we compute the expected output for the forward pass
# we need two surrounding brackets
# the first for sequences (length=1, since we have has_sequence_dimension=False)
# the second for batch of one sample
expected = [[AA(left_operand) / AA(right_operand)]]
a = I([left_operand], has_sequence_dimension=False)
b = I([right_operand], has_sequence_dimension=False)
left_as_input = a / right_operand
unittest_helper(left_as_input, expected, device_id=device_id,
precision=precision, clean_up=False, backward_pass=False)
right_as_input = left_operand / b
unittest_helper(right_as_input, expected, device_id=device_id,
precision=precision, clean_up=True, backward_pass=False)
#Backward pass test
#==================
# the expected results for the backward pass is all ones
#expected = [[[np.ones_like(x) for x in left_operand]]]
#unittest_helper(left_as_input, expected, device_id=device_id,
# precision=precision, clean_up=True, backward_pass=True, input_node=a)
#unittest_helper(right_as_input, expected, device_id=device_id,
# precision=precision, clean_up=True, backward_pass=True, input_node=b)