add parametrized fixture for cpu-gpu
This commit is contained in:
Родитель
4927f58aaf
Коммит
e28118ebf3
|
@ -11,7 +11,7 @@ the forward and the backward pass
|
|||
|
||||
import numpy as np
|
||||
import pytest
|
||||
from .ops_test_utils import test_helper, C, AA, I
|
||||
from .ops_test_utils import test_helper, C, AA, I, cpu_gpu
|
||||
from ...graph import *
|
||||
from ...reader import *
|
||||
import numpy as np
|
||||
|
@ -19,14 +19,14 @@ import numpy as np
|
|||
# Testing inputs
|
||||
@pytest.mark.parametrize("left_operand, right_operand", [
|
||||
([30], [10]),
|
||||
([[30]], [[10]]),
|
||||
([[1.5,2.1]], [[10,20]]),
|
||||
#([[30]], [[10]]),
|
||||
#([[1.5,2.1]], [[10,20]]),
|
||||
#TODO: enable once all branches are merged to master
|
||||
#([5], [[30,40], [1,2]]),
|
||||
#Adding two 3x2 inputs of sequence length 1
|
||||
#([[30,40], [1,2], [0.1, 0.2]], [[10,20], [3,4], [-0.5, -0.4]]),
|
||||
])
|
||||
def test_op_add(left_operand, right_operand):
|
||||
def test_op_add2(left_operand, right_operand, cpu_gpu):
|
||||
|
||||
#Forward pass test
|
||||
|
||||
|
@ -40,14 +40,14 @@ def test_op_add(left_operand, right_operand):
|
|||
b = I([right_operand], has_sequence_dimension=False)
|
||||
|
||||
left_as_input = a + right_operand
|
||||
test_helper(left_as_input, expected, False)
|
||||
test_helper(left_as_input, expected, cpu_gpu, False)
|
||||
|
||||
right_as_input = left_operand + b
|
||||
test_helper(right_as_input, expected, False)
|
||||
test_helper(right_as_input, expected, cpu_gpu, False)
|
||||
|
||||
#Backward pass test
|
||||
|
||||
#the expected results for the backward pass is all ones
|
||||
expected = [[[np.ones_like(x) for x in left_operand]]]
|
||||
test_helper(left_as_input, expected, clean_up=True, backward_pass = True, input_node = a)
|
||||
test_helper(right_as_input, expected, clean_up=True, backward_pass = True, input_node = b)
|
||||
test_helper(left_as_input, expected, cpu_gpu, clean_up=True, backward_pass = True, input_node = a)
|
||||
test_helper(right_as_input, expected, cpu_gpu, clean_up=True, backward_pass = True, input_node = b)
|
|
@ -9,6 +9,7 @@ Utils for operations unit tests
|
|||
"""
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
from ...context import get_new_context
|
||||
from ...graph import *
|
||||
from ...reader import *
|
||||
|
@ -18,9 +19,14 @@ C = constant
|
|||
I = input
|
||||
AA = np.asarray
|
||||
|
||||
def test_helper(root_node, expected, clean_up=True, backward_pass = False, input_node = None):
|
||||
@pytest.fixture(params=[-1,0])
|
||||
def cpu_gpu(request):
|
||||
return request.param
|
||||
|
||||
def test_helper(root_node, expected, device_id = -1, clean_up=True, backward_pass = False, input_node = None):
|
||||
with get_new_context() as ctx:
|
||||
ctx.clean_up = clean_up
|
||||
ctx.device_id = device_id
|
||||
assert not ctx.input_nodes
|
||||
result = ctx.eval(root_node, None, backward_pass, input_node)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче