Skip to content

Commit

Permalink
improved docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Leao authored and Eduardo Leao committed Jan 15, 2024
1 parent f3a6920 commit 2c14653
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions neuralforge/tensor_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@

# Tensor class, with __init__, backward, magic methods, and utils:
class Tensor:
''' Tensor class, with __init__, backward, magic methods, and utils '''
def __init__(self, data, requires_grad = False, operation = None) -> None:
'''
Creates new instance of the Tensor class.
@param data (Array-like): Iterable containing the data to be stored in the Tensor.
@param requires_grad (Bool): Whether to keep track of the Tensor's gradients.
@param operation (Operation Object): When a tensor is created from other tensors, this stores
the operation that generated the new tensor (e.g. "Add", "Exp", "MatMul").
'''
self._data = array(data)
self.requires_grad = requires_grad
self.operation = operation
Expand All @@ -16,9 +25,14 @@ def __repr__(self):
return f"""({self._data}, requires_grad = {self.requires_grad})"""

def data(self):
''' Returns the data stored in the tensor as a Numpy Array. '''
return self._data

def backward(self, grad = None, z = None):
'''
Performs the backpropagation with gradient descent from current tensor.
Will fill every tensor's "grad" attribute with gradients relative to "self" (current Tensor).
'''
if not self.requires_grad:
return "this tensor has requires_grad set to False"

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def read_readme(path):

setup(
name = 'neuralforge',
version = '0.0.6',
version = '0.0.7',
author = 'Eduardo Leitao da Cunha Opice Leao',
author_email = '[email protected]',
maintainer = 'Eduardo Leitao da Cunha Opice Leao',
Expand Down

0 comments on commit 2c14653

Please sign in to comment.