TensorSpace¶
- class odl.space.base_tensors.TensorSpace(shape, dtype)[source]¶
Bases:
LinearSpaceBase 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_dtypeThe complex dtype corresponding to this space's
dtype.complex_spaceThe space corresponding to this space's
complex_dtype.default_orderDefault storage order for new elements in this space.
dtypeScalar data type of each entry in an element of this space.
element_typeType of elements in this space:
Tensor.examplesReturn example random vectors.
fieldScalar field of numbers for this vector space.
implName of the implementation back-end of this tensor set.
is_complexTrue if this is a space of complex tensors.
is_realTrue if this is a space of real tensors.
itemsizeSize in bytes of one entry in an element of this space.
nbytesTotal number of bytes in memory used by an element of this space.
ndimNumber of axes (=dimensions) of this space, also called "rank".
real_dtypeThe real dtype corresponding to this space's
dtype.real_spaceThe space corresponding to this space's
real_dtype.shapeNumber of scalar elements per axis.
sizeTotal number of entries in an element of this space.
Methods
astype(dtype)Return a copy of this space with new
dtype.Return the set of data types available in this implementation.
contains_all(other)Test if all elements in
otherare contained in this set.contains_set(other)Test if
otheris a subset of this set.default_dtype([field])Return the default data type for a given field.
dist(x1, x2)Return the distance between
x1andx2.divide(x1, x2[, out])Return the pointwise quotient of
x1andx2element([inp])Create a
LinearSpaceElementfrominpor from scratch.inner(x1, x2)Return the inner product of
x1andx2.lincomb(a, x1[, b, x2, out])Implement
out[:] = a * x1 + b * x2.multiply(x1, x2[, out])Return the pointwise product of
x1andx2.norm(x)Return the norm of
x.one()Return a tensor of all ones.
zero()Return a tensor of all zeros.
- __init__(shape, dtype)[source]¶
Initialize a new instance.
- Parameters:
- shapenonnegative int or sequence of nonnegative ints
Number of entries of type
dtypeper 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.dtypeconstructor 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.