Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def arctan2(self, other):
den = self.value*self.value+other.value*other.value
s = self.value/den
o = other.value/den
return DerivVar(numpy.arctan2(self.value, other.value),
_mapderiv(lambda a,b: a-b,
list(map(lambda x,f=o: f*x, self.deriv)),
list(map(lambda x,f=s: f*x, other.deriv))))
def __mul__(self, other):
return DerivVar(self.value*other.value,
_mapderiv(lambda a,b: a+b,
list(map(lambda x,f=other.value:f*x, self.deriv)),
list(map(lambda x,f=self.value:f*x, other.deriv))))
def __add__(self, other):
return DerivVar(self.value + other.value,
_mapderiv(lambda a,b: a+b, self.deriv, other.deriv))
def sign(self):
if self.value == 0:
raise ValueError("can't differentiate sign() at zero")
return DerivVar(numpy.sign(self.value), 0)
def arctan(self):
v = numpy.arctan(self.value)
d = 1./(1.+pow(self.value,2))
return DerivVar(v, list(map(lambda x,f=d: f*x, self.deriv)))
def log10(self):
v = numpy.log10(self.value)
d = 1./(self.value * numpy.log(10))
return DerivVar(v, list(map(lambda x,f=d: f*x, self.deriv)))
def arccos(self):
v = numpy.arccos(self.value)
d = -1./numpy.sqrt(1.-pow(self.value,2))
return DerivVar(v, list(map(lambda x,f=d: f*x, self.deriv)))
def __rsub__(self, other):
return DerivVar(other.value - self.value,
_mapderiv(lambda a,b: a-b, other.deriv, self.deriv))
def cosh(self):
v = numpy.cosh(self.value)
d = numpy.sinh(self.value)
return DerivVar(v, list(map(lambda x,f=d: f*x, self.deriv)))
def __div__(self, other):
if not other.value:
raise ZeroDivisionError('DerivVar division')
inv = 1./other.value
return DerivVar(self.value*inv,
_mapderiv(lambda a,b: a-b,
list(map(lambda x,f=inv: f*x, self.deriv)),
list(map(lambda x,f=self.value*inv*inv: f*x,
other.deriv))))