TensorSpace¶
-
class
odl.space.base_tensors.
TensorSpace
(shape, dtype)[source]¶ Bases:
odl.set.space.LinearSpace
Base class for sets of tensors of arbitrary data type.
A tensor is, in the most general sense, a multi-dimensional array that allows operations per entry (keep the rank constant), reductions / contractions (reduce the rank) and broadcasting (raises the rank). For non-numeric data type like
object
, the range of valid operations is rather limited since such a set of tensors does not define a vector space. Any numeric data type, on the other hand, is considered valid for a tensor space, although certain operations - like division with integer dtype - are not guaranteed to yield reasonable results.Under these restrictions, all basic vector space operations are supported by this class, along with reductions based on arithmetic or comparison, and element-wise mathematical functions (“ufuncs”).
See the Wikipedia article on tensors for further details. See also [Hac2012] “Part I Algebraic Tensors” for a rigorous treatment of tensors with a definition close to this one.
Note also that this notion of tensors is the same as in popular Deep Learning frameworks.
References
[Hac2012] Hackbusch, W. Tensor Spaces and Numerical Tensor Calculus. Springer, 2012.
- Attributes
complex_dtype
The complex dtype corresponding to this space’s
dtype
.complex_space
The space corresponding to this space’s
complex_dtype
.default_order
Default storage order for new elements in this space.
dtype
Scalar data type of each entry in an element of this space.
element_type
Type of elements in this space:
Tensor
.examples
Return example random vectors.
field
Scalar field of numbers for this vector space.
impl
Name of the implementation back-end of this tensor set.
is_complex
True if this is a space of complex tensors.
is_real
True if this is a space of real tensors.
itemsize
Size in bytes of one entry in an element of this space.
nbytes
Total number of bytes in memory used by an element of this space.
ndim
Number of axes (=dimensions) of this space, also called “rank”.
real_dtype
The real dtype corresponding to this space’s
dtype
.real_space
The space corresponding to this space’s
real_dtype
.shape
Number of scalar elements per axis.
size
Total number of entries in an element of this space.
Methods
_dist
(self, x1, x2)Return the distance between
x1
andx2
._divide
(self, x1, x2, out)The entry-wise quotient of two tensors, assigned to
out
._inner
(self, x1, x2)Return the inner product of
x1
andx2
._lincomb
(self, a, x1, b, x2, out)Implement
out[:] = a * x1 + b * x2
._multiply
(self, x1, x2, out)The entry-wise product of two tensors, assigned to
out
._norm
(self, x)Return the norm of
x
.astype
(self, dtype)Return a copy of this space with new
dtype
.Return the set of data types available in this implementation.
contains_all
(self, other)Test if all elements in
other
are contained in this set.contains_set
(self, other)Test if
other
is a subset of this set.default_dtype
([field])Return the default data type for a given field.
dist
(self, x1, x2)Return the distance between
x1
andx2
.divide
(self, x1, x2[, out])Return the pointwise quotient of
x1
andx2
element
(self[, inp])Create a
LinearSpaceElement
frominp
or from scratch.inner
(self, x1, x2)Return the inner product of
x1
andx2
.lincomb
(self, a, x1[, b, x2, out])Implement
out[:] = a * x1 + b * x2
.multiply
(self, x1, x2[, out])Return the pointwise product of
x1
andx2
.norm
(self, x)Return the norm of
x
.one
(self)Return a tensor of all ones.
zero
(self)Return a tensor of all zeros.
-
__init__
(self, shape, dtype)[source]¶ Initialize a new instance.
- Parameters
- shapenonnegative int or sequence of nonnegative ints
Number of entries of type
dtype
per axis in this space. A single integer results in a space with rank 1, i.e., 1 axis.- dtype :
Data type of elements in this space. Can be provided in any way the
numpy.dtype
constructor understands, e.g. as built-in type or as a string. For a data type with adtype.shape
, these extra dimensions are added to the left ofshape
.