dipas.backends module

class dipas.backends.Backend(*args, **kwds)

Bases: Generic[dipas.backends._TensorType, dipas.backends._ParameterType]

ModuleType: ClassVar[Type]
ParameterType: ClassVar[Type]
TensorType: ClassVar[Type]
as_float64(x: _TensorType) → _TensorType

Convert the given tensor’s data representation to float64.

as_parameter(x: _TensorType) → _ParameterType

Transform the given tensor to a parameter.

concatenate(xs: Union[List[_TensorType], Tuple[_TensorType, ]], *, dim: int = 0) → _TensorType

Concatenate multiple tensors along one of their dimensions.

from_numbers(value: Union[float, Sequence[Union[float, Sequence[Union[float, Sequence[float]]]]]]) → _TensorType

Create a new tensor from the given number(s).

from_numpy(array: <MagicMock name='mock.ndarray' id='140523363864656'>) → _TensorType

Create a new tensor from the given numpy array.

functions: dipas.backends._Functions[_TensorType]
ignore_gradient: Callable[], AbstractContextManager]
linalg: dipas.backends._Linalg[_TensorType]
make_id_matrix(n: int) → _TensorType

Create a new tensor representing the nxn identity matrix.

make_zeros(*shape: int) → _TensorType

Create a new tensor of the given shape, filled with zeros.

random: dipas.backends._Random[_TensorType]
requires_grad(x: _TensorType) → bool

Check whether the given tensor requires gradient tracking.

stack(xs: Union[List[_TensorType], Tuple[_TensorType, ]], *, dim: int = 0) → _TensorType

Stack multiple tensors along a new dimension.

to_number(x: _TensorType) → float

Convert the given 0-dim tensor to a float object.

to_numpy(x: _TensorType) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Convert the given tensor to a numpy array.

transpose(x: _TensorType) → _TensorType

Transpose the given tensor by swapping the (0,1) dimensions.

update_tensor_data(x: _TensorType, new_value: _TensorType) → None

Update the underlying tensor data while ignoring any gradient tracking.

zeros_like(x: _TensorType) → _TensorType

Create a new tensor of same shape as the given tensor, filled will zeros.

class dipas.backends.Numpy

Bases: dipas.backends.Backend[unittest.mock., unittest.mock.]

ModuleType

alias of dipas.backends.ModuleProxy

ParameterType: ClassVar[Type] = <MagicMock name='mock.ndarray' id='140523363864656'>
TensorType: ClassVar[Type] = <MagicMock name='mock.ndarray' id='140523363864656'>
as_float64(x: <MagicMock name='mock.ndarray' id='140523363864656'>) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Convert the given tensor’s data representation to float64.

as_parameter(x: <MagicMock name='mock.ndarray' id='140523363864656'>) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Transform the given tensor to a parameter.

concatenate(xs: Union[List[<MagicMock name='mock.ndarray' id='140523363864656'>], Tuple[<MagicMock name='mock.ndarray' id='140523363864656'>, ...]], *, dim: int = 0) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Concatenate multiple tensors along one of their dimensions.

from_numbers(value: Union[float, Sequence[Union[float, Sequence[Union[float, Sequence[float]]]]]]) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Create a new tensor from the given number(s).

from_numpy(array: <MagicMock name='mock.ndarray' id='140523363864656'>) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Create a new tensor from the given numpy array.

functions: dipas.backends._Functions[_TensorType]
ignore_gradient: Callable[], AbstractContextManager]
linalg: dipas.backends._Linalg[_TensorType]
make_id_matrix(n: int) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Create a new tensor representing the nxn identity matrix.

make_zeros(*shape: int) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Create a new tensor of the given shape, filled with zeros.

random: dipas.backends._Random[_TensorType]
requires_grad(x: <MagicMock name='mock.ndarray' id='140523363864656'>) → bool

Check whether the given tensor requires gradient tracking.

stack(xs: Union[List[<MagicMock name='mock.ndarray' id='140523363864656'>], Tuple[<MagicMock name='mock.ndarray' id='140523363864656'>, ...]], *, dim: int = 0) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Stack multiple tensors along a new dimension.

to_number(x: <MagicMock name='mock.ndarray' id='140523363864656'>) → float

Convert the given 0-dim tensor to a float object.

to_numpy(x: <MagicMock name='mock.ndarray' id='140523363864656'>) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Convert the given tensor to a numpy array.

transpose(x: <MagicMock name='mock.ndarray' id='140523363864656'>) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Transpose the given tensor by swapping the (0,1) dimensions.

update_tensor_data(x: <MagicMock name='mock.ndarray' id='140523363864656'>, new_value: <MagicMock name='mock.ndarray' id='140523363864656'>) → None

Update the underlying tensor data while ignoring any gradient tracking.

zeros_like(x: <MagicMock name='mock.ndarray' id='140523363864656'>) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Create a new tensor of same shape as the given tensor, filled will zeros.

class dipas.backends.PyTorch

Bases: dipas.backends.Backend[unittest.mock., unittest.mock.]

ModuleType

alias of object

ParameterType: ClassVar[Type] = <MagicMock name='mock.nn.Parameter' id='140523363386640'>
TensorType: ClassVar[Type] = <MagicMock name='mock.Tensor' id='140523370412496'>
as_float64(x: <MagicMock name='mock.Tensor' id='140523370412496'>) → <MagicMock name=’mock.Tensor’ id=’140523370412496’>

Convert the given tensor’s data representation to float64.

as_parameter(x: <MagicMock name='mock.Tensor' id='140523370412496'>) → <MagicMock name=’mock.nn.Parameter’ id=’140523363386640’>

Transform the given tensor to a parameter.

concatenate(xs: Union[List[<MagicMock name='mock.Tensor' id='140523370412496'>], Tuple[<MagicMock name='mock.Tensor' id='140523370412496'>, ...]], *, dim: int = 0) → <MagicMock name=’mock.Tensor’ id=’140523370412496’>

Concatenate multiple tensors along one of their dimensions.

from_numbers(value: Union[float, Sequence[Union[float, Sequence[Union[float, Sequence[float]]]]]]) → <MagicMock name=’mock.Tensor’ id=’140523370412496’>

Create a new tensor from the given number(s).

from_numpy(array: <MagicMock name='mock.ndarray' id='140523363864656'>) → <MagicMock name=’mock.Tensor’ id=’140523370412496’>

Create a new tensor from the given numpy array.

functions: dipas.backends._Functions[_TensorType]
ignore_gradient: Callable[], AbstractContextManager]
linalg: dipas.backends._Linalg[_TensorType]
make_id_matrix(n: int) → <MagicMock name=’mock.Tensor’ id=’140523370412496’>

Create a new tensor representing the nxn identity matrix.

make_zeros(*shape: int) → <MagicMock name=’mock.Tensor’ id=’140523370412496’>

Create a new tensor of the given shape, filled with zeros.

random: dipas.backends._Random[_TensorType]
requires_grad(x: <MagicMock name='mock.Tensor' id='140523370412496'>) → bool

Check whether the given tensor requires gradient tracking.

stack(xs: Union[List[<MagicMock name='mock.Tensor' id='140523370412496'>], Tuple[<MagicMock name='mock.Tensor' id='140523370412496'>, ...]], *, dim: int = 0) → <MagicMock name=’mock.Tensor’ id=’140523370412496’>

Stack multiple tensors along a new dimension.

to_number(x: <MagicMock name='mock.Tensor' id='140523370412496'>) → float

Convert the given 0-dim tensor to a float object.

to_numpy(x: <MagicMock name='mock.Tensor' id='140523370412496'>) → <MagicMock name=’mock.ndarray’ id=’140523363864656’>

Convert the given tensor to a numpy array.

transpose(x: <MagicMock name='mock.Tensor' id='140523370412496'>) → <MagicMock name=’mock.Tensor’ id=’140523370412496’>

Transpose the given tensor by swapping the (0,1) dimensions.

update_tensor_data(x: <MagicMock name='mock.Tensor' id='140523370412496'>, new_value: <MagicMock name='mock.Tensor' id='140523370412496'>) → None

Update the underlying tensor data while ignoring any gradient tracking.

zeros_like(x: <MagicMock name='mock.Tensor' id='140523370412496'>) → <MagicMock name=’mock.Tensor’ id=’140523370412496’>

Create a new tensor of same shape as the given tensor, filled will zeros.