syna package¶
Subpackages¶
Submodules¶
Module contents¶
- class syna.Config[source]¶
Bases:
object
Global config flags affecting backprop and training behavior.
- enable_backprop = True¶
- train = True¶
- class syna.DataLoader(dataset: Iterable[Tuple[Any, Any]], batch_size: int, shuffle: bool = True)[source]¶
Bases:
object
Simple iterable data loader.
- Args:
dataset: Sequence of (input, target) pairs. batch_size: Number of samples per batch. shuffle: If True, shuffle dataset order at the start of each epoch.
- Behavior:
Iterates over dataset in batches. The last batch may be smaller.
Iteration raises StopIteration at epoch end and automatically resets for the next epoch.
- class syna.Dataset(train: bool = True, transform: Callable[[Any], Any] | None = None, target_transform: Callable[[Any], Any] | None = None)[source]¶
Bases:
object
Minimal base dataset.
Subclasses should override prepare() to populate self.data (and optionally self.label).
- Args:
train (bool): Whether this is a training split. transform (callable, optional): Function applied to each data item. target_transform (callable, optional): Function applied to each label.
- Attributes:
data: Sequence of data items (must support indexing and len()). label: Sequence of labels or None.
- class syna.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.Layer[source]¶
Bases:
object
Base layer class that tracks Parameters and sub-Layers.
Subclasses must implement forward(). Layers register any attribute that is a Parameter or Layer automatically.
- class syna.Model[source]¶
Bases:
Layer
Base model class (also a Layer) with a convenience plot method.
The plot method runs forward on the provided inputs and writes a DOT graph of the computation to the given file.
- class syna.Parameter(data, name: str | None = None)[source]¶
Bases:
Tensor
A thin wrapper for trainable parameters (keeps API separate).
- class syna.SeqDataLoader(dataset: Iterable[Tuple[Any, Any]], batch_size: int)[source]¶
Bases:
DataLoader
Sequence-aware loader that yields batch_size sequences in parallel.
The loader divides the dataset into batch_size streams by computing a ‘jump’ = data_size // batch_size and, for each iteration step k, takes the elements at positions (i*jump + k) % data_size for i in range(batch_size).
- Args:
dataset: Sequence of (input, target) pairs. batch_size: Number of parallel sequences (streams) per batch.
- Behavior:
shuffle is always disabled for sequence loader.
Iteration yields exactly data_size // jump steps (i.e., max_iter inherited).
- class syna.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.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.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.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.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.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.ones(*shape, dtype=None, requires_grad: bool = False, name: str | None = None) Tensor [source]¶
Return a tensor filled with ones.
- syna.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.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.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.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.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.