def values_eq_approx(a, b, allow_remove_inf=False, allow_remove_nan=False, rtol=None, atol=None): if a.shape != b.shape or a.dtype != b.dtype: return False if 'int' in str(a.dtype): return GpuArrayType.values_eq(a, b) else: if allow_remove_inf or allow_remove_nan: raise NotImplementedError( "GpuArrayType.values_eq_approx() don't implemented the" " allow_remove_inf and allow_remove_nan parameter") atol_, rtol_ = theano.tensor.basic._get_atol_rtol(a, b) if rtol is not None: rtol_ = rtol if atol is not None: atol_ = atol res = elemwise2(a, '', b, a, odtype=numpy.dtype('bool'), op_tmpl="res = (fabs(a - b) <" "(%(atol_)s + %(rtol_)s * fabs(b)))" % locals()) ret = numpy.asarray(res).all() if ret: return True # maybe the trouble is that there are NaNs an = numpy.asarray(a) bn = numpy.asarray(b) return tensor.TensorType.values_eq_approx( an, bn, allow_remove_inf=allow_remove_inf, allow_remove_nan=allow_remove_nan, rtol=rtol, atol=atol)
def values_eq_approx(a, b, allow_remove_inf=False, allow_remove_nan=False, rtol=None, atol=None): if a.shape != b.shape or a.dtype != b.dtype: return False if 'int' in str(a.dtype): return GpuArrayType.values_eq(a, b) else: if allow_remove_inf or allow_remove_nan: raise NotImplementedError( "GpuArrayType.values_eq_approx() don't implemented the" " allow_remove_inf and allow_remove_nan parameter") narrow = 'float32', 'complex64' if (str(a.dtype) in narrow) or (str(b.dtype) in narrow): atol_ = theano.tensor.basic.float32_atol rtol_ = theano.tensor.basic.float32_rtol else: atol_ = theano.tensor.basic.float64_atol rtol_ = theano.tensor.basic.float64_rtol if rtol is not None: rtol_ = rtol if atol is not None: atol_ = atol res = elemwise2(a, '', b, a, odtype=numpy.dtype('bool'), op_tmpl="res[i] = (fabs(%%(a)s - %%(b)s) <" "(%(atol_)s + %(rtol_)s * fabs(%%(b)s)))" % locals()) return numpy.asarray(res).all()
def values_eq_approx(a, b, allow_remove_inf=False, allow_remove_nan=False, rtol=None, atol=None): if a.shape != b.shape or a.dtype != b.dtype: return False if str(a.dtype) in theano.tensor.discrete_dtypes: return GpuArrayType.values_eq(a, b) else: if not (allow_remove_inf or allow_remove_nan): atol_, rtol_ = theano.tensor.basic._get_atol_rtol(a, b) if rtol is not None: rtol_ = rtol if atol is not None: atol_ = atol res = elemwise2(a, '', b, a, odtype=np.dtype('bool'), op_tmpl="res = (fabs(a - b) <" "(%(atol_)s + %(rtol_)s * fabs(b)))" % locals()) ret = np.asarray(res).all() if ret: return True an = np.asarray(a) bn = np.asarray(b) return tensor.TensorType.values_eq_approx( an, bn, allow_remove_inf=allow_remove_inf, allow_remove_nan=allow_remove_nan, rtol=rtol, atol=atol)
def values_eq_approx(a, b): if a.shape != b.shape or a.dtype != b.dtype: return False if 'int' in str(a.dtype): return GpuArrayType.values_eq(a, b) else: res = elemwise2(a, '', b, a, odtype=numpy.dtype('bool'), op_tmpl="res[i] = ((%(a)s - %(b)s) <" "(1e-8 + 1e-5 * fabs(%(b)s)))") return numpy.asarray(res).all()
def values_eq_approx(a, b, allow_remove_inf=False, allow_remove_nan=False, rtol=None, atol=None): if a.shape != b.shape or a.dtype != b.dtype: return False if str(a.dtype) in theano.tensor.discrete_dtypes: return GpuArrayType.values_eq(a, b) else: if not (allow_remove_inf or allow_remove_nan): atol_, rtol_ = theano.tensor.basic._get_atol_rtol(a, b) if rtol is not None: rtol_ = rtol if atol is not None: atol_ = atol res = elemwise2( a, "", b, a, odtype=np.dtype("bool"), op_tmpl="res = (fabs(a - b) <" "(%(atol_)s + %(rtol_)s * fabs(b)))" % locals(), ) ret = np.asarray(res).all() if ret: return True an = np.asarray(a) bn = np.asarray(b) return tensor.TensorType.values_eq_approx( an, bn, allow_remove_inf=allow_remove_inf, allow_remove_nan=allow_remove_nan, rtol=rtol, atol=atol, )