qewton.backends package

Module contents

qewton.backends.resolve_backend(tensor) → type[ComputingBackend][source]

Finds the ComputingBackend subclass whose default_dtype matches the given tensor’s type.

Raises if no backend matches, or if more than one does. The latter can in principle happen if two backends wrap the same underlying tensor type (e.g. a hypothetical SciPy backend also using plain np.ndarray, same as NumPyBackend) - the tensor’s type alone can’t disambiguate that, so this fails loudly with both candidates named rather than silently guessing. Callers that already know their backend (e.g. via a Node/Geometry) should use it directly instead of inferring it from a tensor.

Submodules

qewton.backends.base module

class qewton.backends.base.ArrayLike(*args, **kwargs)[source]

Bases: Protocol

reshape(*new_shape) → TensorType[source]
property shape: tuple[int, ...]
property size: int
class qewton.backends.base.Backend(*args, **kwargs)[source]

Bases: Serializable, Generic[TensorType]

A Container that allows the connection of Qewton to any other library, which then might perform computations. Pre-defined subclasses require the implementation of certain methods.

All backends are expected to be stateless, and only contain class methods.

default_dtype: ClassVar[type[TensorType]]
classmethod save(serializer: Serializer) → None[source]

The save method is responsible for serializing the object’s state. It collects the object’s attributes and adds them to the serializer.

Parameters:

serializer (Serializer) – The serializer instance that manages the serialization process.

classmethod construct_new_object(serializer: Deserializer, data_config: dict) → Any[source]

Generates a new instance of the class without calling its __init__ method.

Parameters:
  • serializer (Deserializer) – The deserializer instance that manages the loading process.

  • data_config (dict) – A dictionary containing the serialized data for the object.

Returns:

A new instance of the class, without calling its __init__ method.

The attributes will be set later.

Return type:

Any

class qewton.backends.base.ComputingBackend(*args, **kwargs)[source]

Bases: Backend[TensorType]

math: ClassVar[type[MathBackend]]
random: ClassVar[type[RandomBackend]]
linalg: ClassVar[type[LinAlgBackend]]
dtypes: ClassVar[dict]
classmethod build_tensor(data, dtype: Any = <class 'qewton.config.dtypes.Float32'>, device: Device | str = CPU()) → TensorType[source]

Builds a tensor from the given data.

Parameters:

data – The data to build the tensor from.

Returns:

The built tensor.

Return type:

TensorType

classmethod to(data, device)[source]

Moves the data to the given device.

Parameters:
  • data (TensorType) – The data to move.

  • device (str) – The device to move the data to.

Returns:

The moved data.

Return type:

TensorType

classmethod move_to_same_device(data, reference) → TensorType[source]

Moves the data to the same device as the reference.

Parameters:
  • data (TensorType) – The data to move.

  • reference (TensorType) – The reference data.

Returns:

The moved data.

Return type:

TensorType

classmethod cast_dtype(data, dtype)[source]

Changes the data type of the given data.

Parameters:
  • data (TensorType) – The data to change the type of.

  • dtype (qt_dtypes) – The new type of the data.

Returns:

The data with the new type.

Return type:

TensorType

classmethod to_numpy(data)[source]

Converts this backend’s tensor type to a plain numpy array.

Parameters:

data (TensorType) – The data to convert.

Returns:

The converted data.

Return type:

np.ndarray

classmethod save_data(data, path: str | Path)[source]

Saves the given data to the given path.

Parameters:
  • data (TensorType) – The data to save.

  • path (str | Path) – The path to save the data to.

classmethod load_data(path: str | Path) → TensorType[source]

Loads the data from the given path.

Parameters:

path (str | Path) – The path to load the data from.

Returns:

The loaded data.

Return type:

TensorType

classmethod memory_consumption(data) → int[source]

Returns the memory consumption of the given data in bytes.

Parameters:

data (TensorType) – The data to calculate the memory consumption of.

class qewton.backends.base.DeepLearningBackend(*args, **kwargs)[source]

Bases: ComputingBackend[TensorType]

A Backend that implements all the necessary methods for deep learning.

Note that this structure is similar to Keras’ backends.

grad: ClassVar[type[GradBackend]]
optim: ClassVar[type[OptimBackend]]
nn: ClassVar[type[NNBackend]]
param: ClassVar[type[ParameterBackend]]
dtypes = {<class 'qewton.config.dtypes.BFloat16'>: None, <class 'qewton.config.dtypes.Bool'>: None, <class 'qewton.config.dtypes.Complex128'>: None, <class 'qewton.config.dtypes.Complex32'>: None, <class 'qewton.config.dtypes.Complex64'>: None, <class 'qewton.config.dtypes.Float16'>: None, <class 'qewton.config.dtypes.Float32'>: None, <class 'qewton.config.dtypes.Float64'>: None, <class 'qewton.config.dtypes.Int16'>: None, <class 'qewton.config.dtypes.Int32'>: None, <class 'qewton.config.dtypes.Int64'>: None, <class 'qewton.config.dtypes.Int8'>: None, <class 'qewton.config.dtypes.Number'>: None, <class 'qewton.config.dtypes.UInt16'>: None, <class 'qewton.config.dtypes.UInt32'>: None, <class 'qewton.config.dtypes.UInt64'>: None, <class 'qewton.config.dtypes.UInt8'>: None}
classmethod from_numpy(data, dtype=<class 'qewton.config.dtypes.Float32'>)[source]

Converts a numpy array to the standard datatype of this backend.

Parameters:

data (np.ndarray) – The numpy array to convert.

Returns:

The converted data.

Return type:

TensorType

classmethod get_device(device: Device)[source]

qewton.backends.grad module

class qewton.backends.grad.GradBackend(*args, **kwargs)[source]

Bases: Backend[TensorType]

A Backend that implements all differential operators.

abstractmethod static gradient_tracking(inp: Any) → TensorType[source]
abstractmethod static gradient(u: Any, x: Any) → TensorType[source]
abstractmethod static laplacian(u: Any, x: Any) → TensorType[source]
abstractmethod static normal_derivative(u: Any, normals: Any, x: Any) → TensorType[source]
abstractmethod static divergence(u: Any, x: Any) → TensorType[source]
abstractmethod static jacobian(u: Any, x: Any) → TensorType[source]
abstractmethod static partial(u: Any, x: Any) → TensorType[source]
abstractmethod static hessian(u: Any, x: Any) → TensorType[source]
abstractmethod static matrix_divergence(u: Any, x: Any) → TensorType[source]
abstractmethod static rotation(u: Any, x: Any) → TensorType[source]
abstractmethod static symmetric_gradient(u: Any, x: Any) → TensorType[source]

qewton.backends.linalg module

class qewton.backends.linalg.LinAlgBackend(*args, **kwargs)[source]

Bases: Backend[TensorType]

A Backend that implements linear algebra stuff such as matrix system solving, eigendecomposition, etc.

abstractmethod static svd(x: TensorType) → tuple[TensorType, TensorType, TensorType][source]
abstractmethod static pca(x: TensorType, q=None) → tuple[TensorType, TensorType, TensorType][source]
abstractmethod static norm(x: TensorType, order: str | int = 'fro', axis=None, keepdims=False) → TensorType[source]
abstractmethod static det(x: TensorType) → TensorType[source]
abstractmethod static inv(x: TensorType) → TensorType[source]

qewton.backends.math module

class qewton.backends.math.MathBackend(*args, **kwargs)[source]

Bases: Backend[TensorType]

A Backend that implements all basic mathematical methods, method selection inspired by numpy.

The overall idea is that every math backend implements the numpy methods, and mimics numpy’s behavior to unify the usage among all backends.

abstractmethod static add(x1: Any, x2: Any, /) → TensorType[source]
abstractmethod static multiply(x1: Any, x2: Any, /) → TensorType[source]
abstractmethod static rot90(array: Any, k: int = 1, axes: tuple[int, int] = (0, 1)) → TensorType[source]
abstractmethod static einsum(subscripts: str, *operands: Any, **kwargs: Any) → TensorType[source]
abstractmethod static subtract(x1: Any, x2: Any, /) → TensorType[source]
abstractmethod static matmul(x1: Any, x2: Any, /) → TensorType[source]
abstractmethod static mean(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static max(x: Any, axis: Any = None, keepdims: bool = False, initial: Any = None) → TensorType[source]
abstractmethod static ones(shape: Any, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]
abstractmethod static ones_like(x: Any, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]
abstractmethod static zeros(shape: Any, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]
abstractmethod static zeros_like(x: Any, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]
abstractmethod static empty(shape: Any, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]
abstractmethod static empty_like(x: Any, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]
abstractmethod static eye(N: int, M: int | None = None, k: int = 0, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]
abstractmethod static linspace(start: Any, stop: Any, num: int = 50, endpoint: bool = True, retstep: bool = False, dtype: Any = None, axis: int = 0, device: Device | str = CPU()) → TensorType[source]
abstractmethod static logspace(start: Any, stop: Any, num: int = 50, endpoint: bool = True, base: float = 10.0, dtype: Any = None, axis: int = 0, device: Device | str = CPU()) → TensorType[source]
abstractmethod static absolute(x: Any) → TensorType[source]
abstractmethod static abs(x: Any) → TensorType[source]
abstractmethod static fabs(x: Any) → TensorType[source]
abstractmethod static all(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static angle(x: Any) → TensorType[source]
abstractmethod static any(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static amax(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static amin(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static append(x1: Any, x2: Any, axis: Any = None) → TensorType[source]
abstractmethod static arange(start: Any, stop: Any = None, step: Any = None, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]
abstractmethod static arccos(x: Any) → TensorType[source]
abstractmethod static arccosh(x: Any) → TensorType[source]
abstractmethod static arcsin(x: Any) → TensorType[source]
abstractmethod static arcsinh(x: Any) → TensorType[source]
abstractmethod static arctan(x: Any) → TensorType[source]
abstractmethod static arctan2(x1: Any, x2: Any) → TensorType[source]
abstractmethod static arctanh(x: Any) → TensorType[source]
abstractmethod static argmax(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static argmin(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static argsort(x: Any, axis: int = -1) → TensorType[source]
abstractmethod static view(x: Any, dtype: Any = None) → TensorType[source]
abstractmethod static average(x: Any, axis: Any = None, weights: Any = None) → TensorType[source]
abstractmethod static bartlett(x: Any) → TensorType[source]
abstractmethod static hamming(x: Any) → TensorType[source]
abstractmethod static hanning(x: Any) → TensorType[source]
abstractmethod static heaviside(x1: Any, x2: Any) → TensorType[source]
abstractmethod static kaiser(x: Any, beta: float) → TensorType[source]
abstractmethod static bincount(x: Any, weights: Any = None, minlength: int = 0, sparse: bool = False) → TensorType[source]
abstractmethod static bitwise_and(x: Any, y: Any) → TensorType[source]
abstractmethod static bitwise_invert(x: Any) → TensorType[source]
abstractmethod static bitwise_not(x: Any) → TensorType[source]
abstractmethod static bitwise_or(x: Any, y: Any) → TensorType[source]
abstractmethod static bitwise_xor(x: Any, y: Any) → TensorType[source]
abstractmethod static bitwise_left_shift(x: Any, y: Any) → TensorType[source]
abstractmethod static left_shift(x: Any, y: Any) → TensorType[source]
abstractmethod static bitwise_right_shift(x: Any, y: Any) → TensorType[source]
abstractmethod static right_shift(x: Any, y: Any) → TensorType[source]
abstractmethod static blackman(x: Any) → TensorType[source]
abstractmethod static broadcast_to(x: Any, shape: Any) → TensorType[source]
abstractmethod static cbrt(x: Any) → TensorType[source]
abstractmethod static delete(x: Any, obj: Any, axis: int | None = None)[source]
abstractmethod static ceil(x: Any) → TensorType[source]
abstractmethod static clip(x: Any, x_min: Any, x_max: Any) → TensorType[source]
abstractmethod static concatenate(xs: Any, axis: int = 0) → TensorType[source]
abstractmethod static conjugate(x: Any) → TensorType[source]
abstractmethod static conj(x: Any) → TensorType[source]
abstractmethod static copy(x: Any) → TensorType[source]
abstractmethod static cos(x: Any) → TensorType[source]
abstractmethod static cosh(x: Any) → TensorType[source]
abstractmethod static count_nonzero(x: Any, axis: Any = None) → TensorType[source]
abstractmethod static cross(x1: Any, x2: Any, axisa: int = -1, axisb: int = -1, axisc: int = -1, axis: Any = None) → TensorType[source]
abstractmethod static cumprod(x: Any, axis: Any = None, dtype: Any = None) → TensorType[source]
abstractmethod static cumsum(x: Any, axis: Any = None, dtype: Any = None) → TensorType[source]
abstractmethod static deg2rad(x: Any) → TensorType[source]
abstractmethod static rad2deg(x: Any) → TensorType[source]
abstractmethod static diag(x: Any, k: int = 0) → TensorType[source]
abstractmethod static diagflat(x: Any, k: int = 0) → TensorType[source]
abstractmethod static diagonal(x: Any, offset: int = 0, axis1: int = 0, axis2: int = 1) → TensorType[source]
abstractmethod static diff(a: Any, n: int = 1, axis: int = -1) → TensorType[source]
abstractmethod static digitize(x: Any, bins: Any) → TensorType[source]
abstractmethod static dot(x1: Any, x2: Any) → TensorType[source]
abstractmethod static dstack(xs: Any) → TensorType[source]
abstractmethod static equal(x1: Any, x2: Any) → TensorType[source]
abstractmethod static exp(x: Any) → TensorType[source]
abstractmethod static exp2(x: Any) → TensorType[source]
abstractmethod static expand_dims(x: Any, axis: Any) → TensorType[source]
abstractmethod static slice(x: Any, slice_config: Any) → TensorType[source]
abstractmethod static expm1(x: Any) → TensorType[source]
abstractmethod static flip(x: Any, axis: Any = None) → TensorType[source]
abstractmethod static fliplr(x: Any) → TensorType[source]
abstractmethod static flipud(x: Any) → TensorType[source]
abstractmethod static floor(x: Any) → TensorType[source]
abstractmethod static full(shape: Any, fill_value: Any, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]
abstractmethod static full_like(x: Any, fill_value: Any, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]
abstractmethod static gcd(x1: Any, x2: Any) → TensorType[source]
abstractmethod static geomspace(start: Any, stop: Any, num: int = 50, endpoint: bool = True, dtype: Any = None, axis: int = 0) → TensorType[source]
abstractmethod static greater(x1: Any, x2: Any) → TensorType[source]
abstractmethod static greater_equal(x1: Any, x2: Any) → TensorType[source]
abstractmethod static hstack(xs: Any) → TensorType[source]
abstractmethod static hsplit(x: Any, indices_or_sections: Any) → list[TensorType][source]
abstractmethod static hypot(x1: Any, x2: Any) → TensorType[source]
abstractmethod static identity(n: int, dtype: Any = None) → TensorType[source]
abstractmethod static imag(x: Any) → TensorType[source]
abstractmethod static i0(x: Any) → TensorType[source]
abstractmethod static isclose(x1: Any, x2: Any, rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False) → TensorType[source]
abstractmethod static allclose(x1: Any, x2: Any, rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False) → TensorType[source]
abstractmethod static isfinite(x: Any) → TensorType[source]
abstractmethod static isin(x1: Any, x2: Any, assume_unique: bool = False, invert: bool = False) → TensorType[source]
abstractmethod static isinf(x: Any) → TensorType[source]
abstractmethod static isnan(x: Any) → TensorType[source]
abstractmethod static isneginf(x: Any) → TensorType[source]
abstractmethod static isposinf(x: Any) → TensorType[source]
abstractmethod static isreal(x: Any) → TensorType[source]
abstractmethod static kron(x1: Any, x2: Any) → TensorType[source]
abstractmethod static lcm(x1: Any, x2: Any) → TensorType[source]
abstractmethod static ldexp(x1: Any, x2: Any) → TensorType[source]
abstractmethod static less(x1: Any, x2: Any) → TensorType[source]
abstractmethod static less_equal(x1: Any, x2: Any) → TensorType[source]
abstractmethod static log(x: Any) → TensorType[source]
abstractmethod static log10(x: Any) → TensorType[source]
abstractmethod static log1p(x: Any) → TensorType[source]
abstractmethod static log2(x: Any) → TensorType[source]
abstractmethod static logaddexp(x1: Any, x2: Any) → TensorType[source]
abstractmethod static logaddexp2(x1: Any, x2: Any) → TensorType[source]
abstractmethod static logical_and(x1: Any, x2: Any) → TensorType[source]
abstractmethod static logical_not(x: Any) → TensorType[source]
abstractmethod static logical_or(x1: Any, x2: Any) → TensorType[source]
abstractmethod static maximum(x1: Any, x2: Any) → TensorType[source]
abstractmethod static fmax(x1: Any, x2: Any) → TensorType[source]
abstractmethod static median(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static meshgrid(*x: Any, indexing: str = 'xy') → list[TensorType][source]
abstractmethod static min(x: Any, axis: Any = None, keepdims: bool = False, initial: Any = None) → TensorType[source]
abstractmethod static minimum(x1: Any, x2: Any) → TensorType[source]
abstractmethod static fmin(x1: Any, x2: Any) → TensorType[source]
abstractmethod static mod(x1: Any, x2: Any) → TensorType[source]
abstractmethod static fmod(x1: Any, x2: Any) → TensorType[source]
abstractmethod static moveaxis(x: Any, source: Any, destination: Any) → TensorType[source]
abstractmethod static nanargmax(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static nanargmin(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static nancumsum(x: Any, axis: Any = None, dtype: Any = None) → TensorType[source]
abstractmethod static nancumprod(x: Any, axis: Any = None, dtype: Any = None) → TensorType[source]
abstractmethod static nanmax(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static nanmean(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static nanmedian(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
static nanmin(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static nanpercentile(x: Any, q: Any, axis: Any = None, method: str = 'linear', keepdims: bool = False) → TensorType[source]
abstractmethod static nanprod(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static nanquantile(x: Any, q: Any, axis: Any = None, method: str = 'linear', keepdims: bool = False) → TensorType[source]
abstractmethod static nanstd(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static nansum(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static nanvar(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static nan_to_num(x: Any, nan: float = 0.0, posinf: Any = None, neginf: Any = None) → TensorType[source]
abstractmethod static ndim(x: Any) → int[source]
abstractmethod static nonzero(x: Any) → TensorType[source]
abstractmethod static not_equal(x1: Any, x2: Any) → TensorType[source]
abstractmethod static outer(x1: Any, x2: Any) → TensorType[source]
abstractmethod static pad(x: Any, pad_width: Any, mode: str = 'constant', constant_values: Any = None) → TensorType[source]
abstractmethod static shape(x: TensorType) → tuple[source]
abstractmethod static percentile(x: Any, q: Any, axis: Any = None, method: str = 'linear', keepdims: bool = False) → TensorType[source]
abstractmethod static prod(x: Any, axis: Any = None, keepdims: bool = False, dtype: Any = None) → TensorType[source]
abstractmethod static ptp(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static quantile(x: Any, q: Any, axis: Any = None, method: str = 'linear', keepdims: bool = False) → TensorType[source]
abstractmethod static ravel(x: Any) → TensorType[source]
abstractmethod static unravel_index(indices: Any, shape: Any) → tuple[TensorType, ...][source]
abstractmethod static real(x: Any) → TensorType[source]
abstractmethod static reciprocal(x: Any) → TensorType[source]
abstractmethod static repeat(x: Any, repeats: Any, axis: Any = None) → TensorType[source]
abstractmethod static reshape(x: Any, shape: Any) → TensorType[source]
abstractmethod static roll(x: Any, shift: Any, axis: Any = None) → TensorType[source]
abstractmethod static searchsorted(sorted_sequence: Any, values: Any, side: str = 'left') → TensorType[source]
abstractmethod static sign(x: Any) → TensorType[source]
abstractmethod static signbit(x: Any) → TensorType[source]
abstractmethod static sin(x: Any) → TensorType[source]
abstractmethod static sinc(x: Any) → TensorType[source]
abstractmethod static sinh(x: Any) → TensorType[source]
abstractmethod static size(x: Any) → int[source]
abstractmethod static sort(x: Any, axis: int = -1) → TensorType[source]
abstractmethod static split(x: Any, indices_or_sections: Any, axis: int = 0) → list[TensorType][source]
abstractmethod static array_split(x: Any, indices_or_sections: Any, axis: int = 0) → list[TensorType][source]
abstractmethod static stack(x: list[Any], axis: int = 0) → TensorType[source]
abstractmethod static std(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static swapaxes(x: Any, axis1: int, axis2: int) → TensorType[source]
abstractmethod static take(x: Any, indices: Any, axis: Any = None) → TensorType[source]
abstractmethod static take_along_axis(x: Any, indices: Any, axis: Any = None) → TensorType[source]
abstractmethod static tan(x: Any) → TensorType[source]
abstractmethod static tanh(x: Any) → TensorType[source]
abstractmethod static tensordot(x1: Any, x2: Any, axes: Any = 2) → TensorType[source]
abstractmethod static round(x: Any, decimals: int = 0) → TensorType[source]
abstractmethod static tile(x: Any, repeats: Any) → TensorType[source]
abstractmethod static trace(x: Any, offset: int = 0, axis1: int = 0, axis2: int = 1) → TensorType[source]
abstractmethod static tri(N: int, M: int | None = None, k: int = 0, dtype: Any = None) → TensorType[source]
abstractmethod static tril(x: Any, k: int = 0) → TensorType[source]
abstractmethod static triu(x: Any, k: int = 0) → TensorType[source]
abstractmethod static trunc(x: Any) → TensorType[source]
abstractmethod static vdot(x1: Any, x2: Any) → TensorType[source]
abstractmethod static inner(x1: Any, x2: Any) → TensorType[source]
abstractmethod static vstack(xs: list[Any]) → TensorType[source]
abstractmethod static vsplit(x: Any, indices_or_sections: Any) → list[TensorType][source]
abstractmethod static vectorize(pyfunc: Any, *, excluded: Any = None, signature: Any = None) → Any[source]
abstractmethod static where(condition: Any, x1: Any = None, x2: Any = None) → TensorType[source]
abstractmethod static divide(x1: Any, x2: Any) → TensorType[source]
abstractmethod static divide_no_nan(x1: Any, x2: Any) → TensorType[source]
abstractmethod static true_divide(x1: Any, x2: Any) → TensorType[source]
abstractmethod static power(x1: Any, x2: Any) → TensorType[source]
abstractmethod static negative(x: Any) → TensorType[source]
abstractmethod static nextafter(x1: Any, x2: Any) → TensorType[source]
abstractmethod static square(x: Any) → TensorType[source]
abstractmethod static sqrt(x: Any) → TensorType[source]
abstractmethod static squeeze(x: Any, axis: Any = None) → TensorType[source]
abstractmethod static unsqueeze(x: Any, axis: Any = None) → TensorType[source]
abstractmethod static transpose(x: Any, axes: Any = None) → TensorType[source]
abstractmethod static trapezoid(y: Any, x: Any = None, dx: float = 1.0, axis: int = -1) → TensorType[source]
abstractmethod static vander(x: Any, N: int | None = None, increasing: bool = False) → TensorType[source]
abstractmethod static var(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static sum(x: Any, axis: Any = None, keepdims: bool = False) → TensorType[source]
abstractmethod static floor_divide(x1: Any, x2: Any) → TensorType[source]
abstractmethod static logical_xor(x1: Any, x2: Any) → TensorType[source]
abstractmethod static corrcoef(x: Any) → TensorType[source]
abstractmethod static correlate(x1: Any, x2: Any, mode: str = 'valid') → TensorType[source]
abstractmethod static select(condlist: list[Any], choicelist: list[Any], default: Any = 0) → TensorType[source]
abstractmethod static slogdet(x: Any) → tuple[TensorType, TensorType][source]
abstractmethod static argpartition(x: Any, kth: int, axis: int = -1) → TensorType[source]
abstractmethod static histogram(x: Any, bins: int = 10, range: Any = None) → tuple[TensorType, TensorType][source]
abstractmethod static unique(x: Any, sorted: bool = True, return_index: bool = False, return_inverse: bool = False, return_counts: bool = False, axis: int | None = None) → Any[source]
abstractmethod static dsplit(x: Any, indices_or_sections: Any) → list[TensorType][source]
abstractmethod static flatten(x: Any, start_dim: int = 0, end_dim: int = -1) → TensorType[source]
abstractmethod static unflatten(x: Any, axis: int, sizes: tuple[int, ...]) → TensorType[source]
abstractmethod static narrow(x: Any, dim: int, start: int, length: int) → TensorType[source]
abstractmethod static rfftn(x: Any, s: tuple[int, ...] | None = None, dim: tuple[int, ...] | None = None, norm: Literal['forward', 'backward', 'ortho'] | None = None) → TensorType[source]
abstractmethod static irfftn(x: Any, s: tuple[int, ...] | None = None, dim: tuple[int, ...] | None = None, norm: Literal['forward', 'backward', 'ortho'] | None = None) → TensorType[source]
abstractmethod static fftshift(x: Any, dim: int | tuple[int, ...] | None = None) → TensorType[source]
abstractmethod static ifftshift(x: Any, dim: int | tuple[int, ...] | None = None) → TensorType[source]

qewton.backends.nn module

class qewton.backends.nn.NNBackend(*args, **kwargs)[source]

Bases: Backend[TensorType]

A Backend that implements all neural network related operations, such as activations, layers, etc.

abstractmethod static relu(x: Any, /) → TensorType[source]
abstractmethod static sigmoid(x: Any, /) → TensorType[source]
abstractmethod static tanh(x: Any, /) → TensorType[source]
abstractmethod static gelu(x: Any, /) → TensorType[source]
abstractmethod static softmax(x: Any, /, dim: int = -1) → TensorType[source]
abstractmethod static softplus(x: Any, /) → TensorType[source]
abstractmethod static conv1d(x: Any, /, weight: Any, bias: Any | None = None, stride: int | tuple[int] = 1, padding: int | tuple[int] = 0, dilation: int | tuple[int] = 1, groups: int = 1) → TensorType[source]
abstractmethod static conv2d(x: Any, /, weight: Any, bias: Any | None = None, stride: int | tuple[int, int] = 1, padding: int | tuple[int, int] = 0, dilation: int | tuple[int, int] = 1, groups: int = 1) → TensorType[source]
abstractmethod static conv3d(x: Any, /, weight: Any, bias: Any | None = None, stride: int | tuple[int, int, int] = 1, padding: int | tuple[int, int, int] = 0, dilation: int | tuple[int, int, int] = 1, groups: int = 1) → TensorType[source]
abstractmethod static max_pool1d(x: Any, /, kernel_size: int | tuple[int], stride: int | tuple[int] | None = None, padding: int | tuple[int] = 0, dilation: int | tuple[int] = 1, ceil_mode: bool = False) → TensorType[source]
abstractmethod static max_pool2d(x: Any, /, kernel_size: int | tuple[int, int], stride: int | tuple[int, int] | None = None, padding: int | tuple[int, int] = 0, dilation: int | tuple[int, int] = 1, ceil_mode: bool = False) → TensorType[source]
abstractmethod static max_pool3d(x: Any, /, kernel_size: int | tuple[int, int, int], stride: int | tuple[int, int, int] | None = None, padding: int | tuple[int, int, int] = 0, dilation: int | tuple[int, int, int] = 1, ceil_mode: bool = False) → TensorType[source]
abstractmethod static avg_pool1d(x: Any, /, kernel_size: int, stride: int = 0, padding: int = 0, ceil_mode: bool = False, count_include_pad: bool = True) → TensorType[source]
abstractmethod static avg_pool2d(x: Any, /, kernel_size: int | tuple[int, int], stride: int | tuple[int, int] | None = None, padding: int | tuple[int, int] = 0, ceil_mode: bool = False, count_include_pad: bool = True) → TensorType[source]
abstractmethod static avg_pool3d(x: Any, /, kernel_size: int | tuple[int, int, int], stride: int | tuple[int, int, int] | None = None, padding: int | tuple[int, int, int] = 0, ceil_mode: bool = False, count_include_pad: bool = True) → TensorType[source]
abstractmethod static batch_norm1d(x: Any, running_mean: Any | None, running_var: Any | None, weight: Any | None = None, bias: Any | None = None, training: bool = False, momentum: float = 0.1, eps: float = 1e-05) → TensorType[source]
abstractmethod static batch_norm2d(x: Any, running_mean: Any | None, running_var: Any | None, weight: Any | None = None, bias: Any | None = None, training: bool = False, momentum: float = 0.1, eps: float = 1e-05) → TensorType[source]
abstractmethod static batch_norm3d(x: Any, running_mean: Any | None, running_var: Any | None, weight: Any | None = None, bias: Any | None = None, training: bool = False, momentum: float = 0.1, eps: float = 1e-05) → TensorType[source]
abstractmethod static interpolate(x: Any, size: int | tuple[int] | tuple[int, int] | tuple[int, int, int] | None = None, scale_factor: float | tuple[float] | None = None, mode: Literal['nearest', 'linear', 'bilinear', 'bicubic', 'trilinear'] = 'nearest', align_corners: bool | None = False) → TensorType[source]

qewton.backends.optim module

class qewton.backends.optim.OptimBackend(*args, **kwargs)[source]

Bases: Backend[TensorType]

static setup_optimizer()[source]
static do_optimization_step()[source]
static adam(*args, **kwargs)[source]
static sgd(*args, **kwargs)[source]
static lbfgs(*args, **kwargs)[source]
static step_lr(*args, **kwargs)[source]
static exponential_lr(*args, **kwargs)[source]
static cosine_annealing_lr(*args, **kwargs)[source]

qewton.backends.param module

class qewton.backends.param.ParameterBackend(*args, **kwargs)[source]

Bases: Backend[TensorType]

abstractmethod static initialize(shape=None, tensor=None) → TensorType[source]
abstractmethod static to(data, device) → TensorType[source]
abstractmethod static requires_grad(data, requires_grad: bool) → TensorType[source]

qewton.backends.random module

class qewton.backends.random.RandomBackend(*args, **kwargs)[source]

Bases: Backend[TensorType]

A Backend that implements random number generation. Method selection and behavior inspired by numpy.random to unify usage across different backends.

static set_seed(seed: int)[source]

Sets the seed for the random number generator.

static normal(shape: Any, mean: float = 0.0, std: float = 1.0, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]

Samples from a normal (Gaussian) distribution.

static standard_normal(shape: Any, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]

Samples from a standard normal distribution (mean=0, std=1).

static uniform(shape: Any, low: float = 0.0, high: float = 1.0, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]

Samples from a uniform distribution over [low, high).

static randint(low: int, high: int | None = None, shape: Any = None, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]

Samples from a discrete uniform distribution over [low, high).

static choice(a: Any, shape: Any = None, replace: bool = True, p: Any = None, device: Device | str = CPU()) → TensorType[source]

Generates a random sample from a given 1-D array or integer.

static permutation(x: Any, device: Device | str = CPU()) → TensorType[source]

Randomly permute a sequence, or return a permuted range.

static exponential(shape: Any, scale: float = 1.0, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]

Samples from an exponential distribution.

static multivariate_normal(mean: Any, cov: Any, shape: Any = None, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]

Samples from a multivariate normal distribution.

static shuffle(x: Any, axis: int = 0) → None[source]

Modify a sequence in-place by shuffling its contents.

static binomial(n: int | Any, p: float | Any, shape: Any = None, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]

Samples from a binomial distribution.

static poisson(lam: float | Any, shape: Any = None, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]

Samples from a Poisson distribution.

static gamma(shape_param: float | Any, scale: float | Any = 1.0, shape: Any = None, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]

Samples from a Gamma distribution.

static beta(a: float | Any, b: float | Any, shape: Any = None, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]

Samples from a Beta distribution.

static lognormal(mean: float = 0.0, sigma: float = 1.0, shape: Any = None, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]

Samples from a log-normal distribution.

static gumbel(loc: float = 0.0, scale: float = 1.0, shape: Any = None, dtype: Any = None, device: Device | str = CPU()) → TensorType[source]

Samples from a Gumbel distribution.