Compare commits
No commits in common. "d31a72374dadc273a0d2c59af18fe1096a5f9391" and "de084e8ce3302272474085d5f87eae1536cc43e6" have entirely different histories.
d31a72374d
...
de084e8ce3
|
@ -7,8 +7,6 @@ class Tensor:
|
||||||
# TODO Implement 'requires_grad' functionality.
|
# TODO Implement 'requires_grad' functionality.
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
# TODO Add support for scalar values.
|
# TODO Add support for scalar values.
|
||||||
if isinstance(value, list):
|
|
||||||
value = np.array(value)
|
|
||||||
if not isinstance(value, np.ndarray):
|
if not isinstance(value, np.ndarray):
|
||||||
print(f"{type(value)} is not compatible with {np.ndarray}")
|
print(f"{type(value)} is not compatible with {np.ndarray}")
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
@ -38,16 +36,6 @@ class Tensor:
|
||||||
tensor._back = back
|
tensor._back = back
|
||||||
return tensor
|
return tensor
|
||||||
|
|
||||||
def sub(self, other):
|
|
||||||
tensor = Tensor(np.add(self.value, other.value))
|
|
||||||
tensor._save(self, other)
|
|
||||||
|
|
||||||
def back(upstream):
|
|
||||||
return np.dot(np.ones_like(self.value).T, upstream), -np.dot(np.ones_like(self.value).T, upstream)
|
|
||||||
|
|
||||||
tensor._back = back
|
|
||||||
return tensor
|
|
||||||
|
|
||||||
def mul(self, other):
|
def mul(self, other):
|
||||||
tensor = Tensor(np.dot(self.value, other.value))
|
tensor = Tensor(np.dot(self.value, other.value))
|
||||||
tensor._save(self, other)
|
tensor._save(self, other)
|
||||||
|
@ -70,16 +58,6 @@ class Tensor:
|
||||||
tensor._back = back
|
tensor._back = back
|
||||||
return tensor
|
return tensor
|
||||||
|
|
||||||
def neg(self):
|
|
||||||
tensor = Tensor(-self.value)
|
|
||||||
tensor._save(self)
|
|
||||||
|
|
||||||
def back(upstream):
|
|
||||||
return [np.dot(-np.ones_like(self.value), upstream)]
|
|
||||||
|
|
||||||
tensor._back = back
|
|
||||||
return tensor
|
|
||||||
|
|
||||||
def expt(self, exponent):
|
def expt(self, exponent):
|
||||||
tensor = Tensor(self.value ** exponent)
|
tensor = Tensor(self.value ** exponent)
|
||||||
tensor._save(self)
|
tensor._save(self)
|
||||||
|
@ -113,17 +91,6 @@ class Tensor:
|
||||||
tensor._back = back
|
tensor._back = back
|
||||||
return tensor
|
return tensor
|
||||||
|
|
||||||
def log(self):
|
|
||||||
tensor = Tensor(np.log(self.value))
|
|
||||||
tensor._save(self)
|
|
||||||
|
|
||||||
def back(upstream):
|
|
||||||
a, = tensor._parents
|
|
||||||
return [np.dot(1 / a.value, upstream)]
|
|
||||||
|
|
||||||
tensor._back = back
|
|
||||||
return tensor
|
|
||||||
|
|
||||||
def tanh(self):
|
def tanh(self):
|
||||||
tensor = Tensor(np.tanh(self.value))
|
tensor = Tensor(np.tanh(self.value))
|
||||||
tensor._save(self)
|
tensor._save(self)
|
||||||
|
|
Loading…
Reference in a new issue