syna.core module¶
Core — Tensor and autograd primitives.
Core Tensor, Parameter, Config and autograd Function primitives used across the syna library. This module contains the lightweight Tensor container and the Function base class which implement forward/backward for automatic differentiation.
- class syna.core.Config[source]¶
Bases:
object
Global config flags affecting backprop and training behavior.
- enable_backprop = True¶
- train = True¶
- class syna.core.Function[source]¶
Bases:
object
Base Function for forward/backward ops used in autograd.
Subclasses should implement forward (numpy arrays -> numpy arrays) and backward (Tensor grads -> Tensor grads).
- class syna.core.Parameter(data, name: str | None = None)[source]¶
Bases:
Tensor
A thin wrapper for trainable parameters (keeps API separate).
- class syna.core.Tensor(data, name: str | None = None)[source]¶
Bases:
object
Simple Tensor container holding data, gradient and creator Function.
Most operator behavior delegates to syna.functions.* helpers so this class focuses on bookkeeping for autograd.
- property T¶
- backward(retain_grad=False, create_graph=False) None [source]¶
Run backpropagation to compute gradients of inputs.
- Args:
retain_grad: if False, intermediate gradients are cleared to save memory. create_graph: if True, create graph for higher-order gradients.
- property dtype¶
- property ndim¶
- set_creator(func: Function) None [source]¶
Mark this tensor as created by func (used for backprop ordering).
- property shape¶
- property size¶
- syna.core.arange(start, stop=None, step=1, dtype=None, requires_grad: bool = False, name: str | None = None) Tensor [source]¶
Return a 1-D tensor with values from start to stop (exclusive).
- syna.core.as_tensor(obj) Tensor [source]¶
Ensure obj is a Tensor; convert scalars/arrays to Tensor if needed.
Delegates to tensor(…), which follows PyTorch-style semantics.
- syna.core.eye(n, m=None, dtype=None, requires_grad: bool = False, name: str | None = None) Tensor [source]¶
Return a 2-D identity matrix (or rectangular identity if m is given).
- syna.core.full(shape, fill_value, dtype=None, requires_grad: bool = False, name: str | None = None) Tensor [source]¶
Return a tensor of shape shape filled with fill_value.
shape may be an int or a tuple/list of ints (matches numpy/torch style).
- syna.core.full_like(x, fill_value, dtype=None, requires_grad: bool = False, name: str | None = None) Tensor [source]¶
Return a tensor with the same shape as x filled with fill_value.
x may be a Tensor or array-like.
- syna.core.ones(*shape, dtype=None, requires_grad: bool = False, name: str | None = None) Tensor [source]¶
Return a tensor filled with ones.
- syna.core.ones_like(x, dtype=None, requires_grad: bool = False, name: str | None = None) Tensor [source]¶
Return a tensor of ones with the same shape as x (Tensor or array-like).
- syna.core.rand(*shape, dtype=None, requires_grad: bool = False, name: str | None = None) Tensor [source]¶
Return a tensor with uniform random values in [0, 1).
- syna.core.randint(low, high=None, size=None, dtype=None, requires_grad: bool = False, name: str | None = None) Tensor [source]¶
Return random integers from low (inclusive) to high (exclusive).
- syna.core.randn(*shape, dtype=None, requires_grad: bool = False, name: str | None = None) Tensor [source]¶
Return a tensor with samples from the standard normal distribution.
- syna.core.range(start, stop=None, step=1, dtype=None, requires_grad: bool = False, name: str | None = None) Tensor [source]¶
Alias for arange to match torch.range-like convenience (behaves like arange).
- syna.core.tensor(data, dtype=None, requires_grad: bool = False, name: str | None = None) Tensor [source]¶
Tensor factory.
- Args:
data: array-like or scalar. dtype: numpy dtype (optional). requires_grad: if True, the returned Tensor is a leaf that will accumulate gradients. name: optional name for the Tensor.
- syna.core.using_config(name: str, value: bool)[source]¶
Temporarily set a Config attribute inside a context.