Merge pull request #43 from lucasdelimanogueira/tmp
add example training
This commit is contained in:
commit
4e5173597c
6 changed files with 184 additions and 1 deletions
177
examples/train.ipynb
Normal file
177
examples/train.ipynb
Normal file
File diff suppressed because one or more lines are too long
2
install.sh
Executable file
2
install.sh
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
cd build
|
||||
make
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -27,7 +27,9 @@ class ElementwiseMulBackward:
|
|||
self.input = [x, y]
|
||||
|
||||
def backward(self, gradient):
|
||||
return [gradient * self.input[1], gradient * self.input[0]]
|
||||
x = self.input[0]
|
||||
y = self.input[1]
|
||||
return [y * gradient, x * gradient]
|
||||
|
||||
class MatmulBackward:
|
||||
def __init__(self, x, y):
|
||||
|
|
|
|||
|
|
@ -179,6 +179,8 @@ class Tensor:
|
|||
self.grad_fn = None
|
||||
|
||||
def __getitem__(self, indices):
|
||||
if isinstance(indices, int):
|
||||
indices = [indices]
|
||||
if len(indices) != self.ndim:
|
||||
raise ValueError("Number of indices must match the number of dimensions")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue