def __call__(self, x): # the units of x is not checked y = array(x) - self.xmin ind = array(y * self.invdx, dtype=int) try: if is_dimensionless(x): # could be a problem if it is a Quantity with units=1 return self.f[ind] + self.df[ind] * (y - array(ind) * self.dx) else: return array(self.f[ind] + self.df[ind] * (y - array(ind) * self.dx)) * self.unit except IndexError: # out of bounds return NaN * self.unit
def __call__(self, x): # the units of x is not checked y = array(x) - self.xmin ind = array(y * self.invdx, dtype=int) try: if is_dimensionless( x): # could be a problem if it is a Quantity with units=1 return self.f[ind] + self.df[ind] * (y - array(ind) * self.dx) else: return array(self.f[ind] + self.df[ind] * (y - array(ind) * self.dx)) * self.unit except IndexError: # out of bounds return NaN * self.unit
def __init__(self, f, xmin, xmax, n): self.xmin = xmin self.xmax = xmax self.dx = (xmax - xmin) / float(n - 1) self.invdx = 1 / self.dx # Not at midpoints here x = xmin + arange(n) * self.dx self.unit = get_unit(f(xmin)) try: self.f = f(x) except: # If it fails we try passing the values one by one self.f = zeros(n) * f(xmin) # for the unit for i in xrange(n): self.f[i] = f(x[i]) self.f = array(self.f) self.df = (self.f[range(1, n)] - self.f[range(n - 1)]) * float(self.invdx)
def __init__(self, f, xmin, xmax, n): self.xmin = xmin self.xmax = xmax self.dx = (xmax - xmin) / float(n - 1) self.invdx = 1 / self.dx # Not at midpoints here x = xmin + arange(n) * self.dx self.unit = get_unit(f(xmin)) try: self.f = f(x) except: # If it fails we try passing the values one by one self.f = zeros(n) * f(xmin) # for the unit for i in xrange(n): self.f[i] = f(x[i]) self.f = array(self.f) self.df = (self.f[range(1, n)] - self.f[range(n - 1)]) * float( self.invdx)
def __call__(self, x): try: # possible problem if x is an array and an array is wanted return self.f[array((array(x) - self.xmin) * self.invdx, dtype=int)] except IndexError: # out of bounds return NaN * self.unit