MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / __mul__

Method __mul__

maths/dual_number_automatic_differentiation.py:48–62  ·  view source on GitHub ↗
(self, other)

Source from the content-addressed store, hash-verified

46 return self + other * -1
47
48 def __mul__(self, other):
49 if not isinstance(other, Dual):
50 new_duals = []
51 for i in self.duals:
52 new_duals.append(i * other)
53 return Dual(self.real * other, new_duals)
54 new_duals = [0] * (len(self.duals) + len(other.duals) + 1)
55 for i, item in enumerate(self.duals):
56 for j, jtem in enumerate(other.duals):
57 new_duals[i + j + 1] += item * jtem
58 for k in range(len(self.duals)):
59 new_duals[k] += self.duals[k] * other.real
60 for index in range(len(other.duals)):
61 new_duals[index] += other.duals[index] * self.real
62 return Dual(self.real * other.real, new_duals)
63
64 __rmul__ = __mul__
65

Callers

nothing calls this directly

Calls 2

DualClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected