def run_case(self, testname, inputs): inputs_ref = [theano.shared(inp) for inp in inputs] inputs_tst = [theano.shared(inp) for inp in inputs] try: node_ref = safe_make_node(self.op, *inputs_ref) node_tst = safe_make_node(self.op, *inputs_tst) except Exception, exc: err_msg = ("Test %s::%s: Error occured while making " "a node with inputs %s") % (self.gpu_op, testname, inputs) exc.args += (err_msg, ) raise
def run_case(self, testname, inputs): inputs_ref = [theano.shared(inp) for inp in inputs] inputs_tst = [theano.shared(inp) for inp in inputs] try: node_ref = safe_make_node(self.op, *inputs_ref) node_tst = safe_make_node(self.op, *inputs_tst) except Exception, exc: err_msg = ("Test %s::%s: Error occured while making " "a node with inputs %s") % (self.gpu_op, testname, inputs) exc.args += (err_msg,) raise
def test_good(self): if skip: raise SkipTest(skip) for testname, inputs in good.items(): inputs = [copy(input) for input in inputs] inputrs = [fake_shared(input) for input in inputs] try: node = safe_make_node(self.op, *inputrs) except Exception, exc: err_msg = ("Test %s::%s: Error occured while making " "a node with inputs %s") % (self.op, testname, inputs) exc.args += (err_msg,) raise try: f = inplace_func([], node.outputs, mode=mode, name='test_good') except Exception, exc: err_msg = ("Test %s::%s: Error occured while trying to " "make a Function") % (self.op, testname) exc.args += (err_msg,) raise
def run_case(self, testname, inputs): inputs_ref = [theano.shared(inp) for inp in inputs] inputs_tst = [theano.shared(inp) for inp in inputs] try: node_ref = safe_make_node(self.op, *inputs_ref) node_tst = safe_make_node(self.op, *inputs_tst) except Exception as exc: err_msg = ("Test %s::%s: Error occured while making " "a node with inputs %s") % (self.gpu_op, testname, inputs) exc.args += (err_msg, ) raise try: f_ref = inplace_func([], node_ref.outputs, mode=mode_nogpu) f_tst = inplace_func([], node_tst.outputs, mode=mode_gpu) except Exception as exc: err_msg = ("Test %s::%s: Error occured while trying to " "make a Function") % (self.gpu_op, testname) exc.args += (err_msg, ) raise self.assertFunctionContains1(f_tst, self.gpu_op) ref_e = None try: expecteds = f_ref() except Exception as exc: ref_e = exc try: variables = f_tst() except Exception as exc: if ref_e is None: err_msg = ("Test %s::%s: exception when calling the " "Function") % (self.gpu_op, testname) exc.args += (err_msg, ) raise else: # if we raised an exception of the same type we're good. if isinstance(exc, type(ref_e)): return else: err_msg = ( "Test %s::%s: exception raised during test " "call was not the same as the reference " "call (got: %s, expected %s)" % (self.gpu_op, testname, type(exc), type(ref_e))) exc.args += (err_msg, ) raise for i, (variable, expected) in \ enumerate(izip(variables, expecteds)): if variable.dtype != expected.dtype or \ variable.shape != expected.shape or \ not TensorType.values_eq_approx(variable, expected): self.fail(("Test %s::%s: Output %s gave the wrong " "value. With inputs %s, expected %s " "(dtype %s), got %s (dtype %s)." % (self.op, testname, i, inputs, expected, expected.dtype, variable, variable.dtype))) for description, check in iteritems(self.checks): if not check(inputs, variables): self.fail( ("Test %s::%s: Failed check: %s " "(inputs were %s, ouputs were %s)") % (self.op, testname, description, inputs, variables))
def run_case(self, testname, inputs): inputs_ref = [theano.shared(inp) for inp in inputs] inputs_tst = [theano.shared(inp) for inp in inputs] try: node_ref = safe_make_node(self.op, *inputs_ref) node_tst = safe_make_node(self.op, *inputs_tst) except Exception as exc: err_msg = ("Test %s::%s: Error occured while making " "a node with inputs %s") % (self.gpu_op, testname, inputs) exc.args += (err_msg,) raise try: f_ref = inplace_func([], node_ref.outputs, mode=mode_nogpu) f_tst = inplace_func([], node_tst.outputs, mode=mode_gpu) except Exception as exc: err_msg = ("Test %s::%s: Error occured while trying to " "make a Function") % (self.gpu_op, testname) exc.args += (err_msg,) raise self.assertFunctionContains1(f_tst, self.gpu_op) ref_e = None try: expecteds = f_ref() except Exception as exc: ref_e = exc try: variables = f_tst() except Exception as exc: if ref_e is None: err_msg = ("Test %s::%s: exception when calling the " "Function") % (self.gpu_op, testname) exc.args += (err_msg,) raise else: # if we raised an exception of the same type we're good. if isinstance(exc, type(ref_e)): return else: err_msg = ("Test %s::%s: exception raised during test " "call was not the same as the reference " "call (got: %s, expected %s)") % \ (self.gpu_op, testname, type(exc), type(ref_e)) exc.args += (err_msg,) raise for i, (variable, expected) in \ enumerate(izip(variables, expecteds)): if variable.dtype != expected.dtype or \ variable.shape != expected.shape or \ not TensorType.values_eq_approx(variable, expected): self.fail(("Test %s::%s: Output %s gave the wrong " "value. With inputs %s, expected %s " "(dtype %s), got %s (dtype %s).") % ( self.op, testname, i, inputs, expected, expected.dtype, variable, variable.dtype)) for description, check in self.checks.items(): if not check(inputs, variables): self.fail(("Test %s::%s: Failed check: %s " "(inputs were %s, ouputs were %s)") % (self.op, testname, description, inputs, variables))