def filter_inplace(self, data, old_data, strict=False, allow_downcast=None): if strict or allow_downcast or isinstance(data, cuda.CudaNdarray): return cuda.filter(data, self.broadcastable, strict, old_data) else: # (not strict) and (not allow_downcast) # Check if data.dtype can be accurately cast to self.dtype if isinstance(data, numpy.ndarray): up_dtype = scal.upcast(self.dtype, data.dtype) if up_dtype == self.dtype: return cuda.filter(data, self.broadcastable, strict, old_data) else: raise TypeError( "%s, with dtype %s, cannot store a value of " "dtype %s without risking loss of precision." "If you do not mind, please cast your data to %s." % (self, self.dtype, data.dtype, self.dtype), data, ) else: converted_data = theano._asarray(data, self.dtype) if allow_downcast is None and type(data) is float and self.dtype == theano.config.floatX: return cuda.filter(converted_data, self.broadcastable, strict, old_data) elif numpy.all(data == converted_data): return cuda.filter(converted_data, self.broadcastable, strict, old_data) else: raise TypeError( "%s, with dtype %s, cannot store accurately value %s, " "it would be represented as %s. If you do not mind, " "you can cast your data to %s." % (self, self.dtype, data, converted_data, self.dtype), data, )
def filter_inplace(self, data, old_data, strict=False, allow_downcast=None): if strict or allow_downcast or isinstance(data, cuda.CudaNdarray): return cuda.filter(data, self.broadcastable, strict, old_data) else: # (not strict) and (not allow_downcast) # Check if data.dtype can be accurately cast to self.dtype if isinstance(data, numpy.ndarray): up_dtype = scal.upcast(self.dtype, data.dtype) if up_dtype == self.dtype: return cuda.filter(data, self.broadcastable, strict, old_data) else: raise TypeError( '%s, with dtype %s, cannot store a value of ' 'dtype %s without risking loss of precision.' 'If you do not mind, please cast your data to %s.' % (self, self.dtype, data.dtype, self.dtype), data) else: converted_data = theano._asarray(data, self.dtype) if (allow_downcast is None and type(data) is float and self.dtype == theano.config.floatX): return cuda.filter(converted_data, self.broadcastable, strict, old_data) elif numpy.all(data == converted_data): return cuda.filter(converted_data, self.broadcastable, strict, old_data) else: raise TypeError( '%s, with dtype %s, cannot store accurately value %s, ' 'it would be represented as %s. If you do not mind, ' 'you can cast your data to %s.' % (self, self.dtype, data, converted_data, self.dtype), data)