Factory Functions
simplegrad.core.factory.zeros(shape: tuple[int, ...], dtype: str = 'float32', comp_grad: bool | None = None, label: bool | None = None) -> Tensor
Create a tensor filled with zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
Output shape. |
required |
dtype
|
str
|
Data type string. Defaults to |
'float32'
|
comp_grad
|
bool | None
|
Enable gradient tracking. Defaults to the global flag. |
None
|
label
|
bool | None
|
Optional name for visualization. |
None
|
Source code in simplegrad/core/factory.py
simplegrad.core.factory.ones(shape: tuple[int, ...], dtype: str = 'float32', comp_grad: bool | None = None, label: bool | None = None) -> Tensor
Create a tensor filled with ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
Output shape. |
required |
dtype
|
str
|
Data type string. Defaults to |
'float32'
|
comp_grad
|
bool | None
|
Enable gradient tracking. Defaults to the global flag. |
None
|
label
|
bool | None
|
Optional name for visualization. |
None
|
Source code in simplegrad/core/factory.py
simplegrad.core.factory.normal(shape: tuple[int, ...], dtype: str = 'float32', comp_grad: bool | None = None, label: bool | None = None, mu: int | float = 0, sigma: int | float = 1) -> Tensor
Create a tensor sampled from a normal distribution N(mu, sigma).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
Output shape. |
required |
dtype
|
str
|
Data type string. Defaults to |
'float32'
|
comp_grad
|
bool | None
|
Enable gradient tracking. Defaults to the global flag. |
None
|
label
|
bool | None
|
Optional name for visualization. |
None
|
mu
|
int | float
|
Distribution mean. |
0
|
sigma
|
int | float
|
Distribution standard deviation. |
1
|
Source code in simplegrad/core/factory.py
simplegrad.core.factory.uniform(shape: tuple[int, ...], dtype: str = 'float32', comp_grad: bool | None = None, label: bool | None = None, low: int | float = 0, high: int | float = 1) -> Tensor
Create a tensor sampled from a uniform distribution U(low, high).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
Output shape. |
required |
dtype
|
str
|
Data type string. Defaults to |
'float32'
|
comp_grad
|
bool | None
|
Enable gradient tracking. Defaults to the global flag. |
None
|
label
|
bool | None
|
Optional name for visualization. |
None
|
low
|
int | float
|
Lower bound of the distribution. |
0
|
high
|
int | float
|
Upper bound of the distribution. |
1
|
Source code in simplegrad/core/factory.py
simplegrad.core.factory.full(shape: tuple[int, ...], fill_value: float, dtype: str = 'float32', comp_grad: bool | None = None, label: bool | None = None) -> Tensor
Create a tensor filled with a constant value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
Output shape. |
required |
fill_value
|
float
|
Value to fill the tensor with. |
required |
dtype
|
str
|
Data type string. Defaults to |
'float32'
|
comp_grad
|
bool | None
|
Enable gradient tracking. Defaults to the global flag. |
None
|
label
|
bool | None
|
Optional name for visualization. |
None
|