Linear spaces¶
The LinearSpace
class represent abstract mathematical concepts
of vector spaces. It cannot be used directly but are rather intended
to be subclassed by concrete space implementations. The space
provides default implementations of the most important vector space
operations. See the documentation of the respective classes for more
details.
The concept of linear vector spaces in ODL is largely inspired by the Rice Vector Library (RVL).
The abstract LinearSpace
class is intended for quick prototyping.
It has a number of abstract methods which must be overridden by a
subclass. On the other hand, it provides automatic error checking
and numerous attributes and methods for convenience.
Abstract methods¶
In the following, the abstract methods are explained in detail.
Element creation¶
element(inp=None)
This public method is the factory for the inner
LinearSpaceElement
class. It creates a new element of the space,
either from scratch or from an existing data container. In the
simplest possible case, it just delegates the construction to the
LinearSpaceElement
class.
If no data is provided, the new element is merely allocated, not initialized, thus it can contain any value.
- Parameters:
- inp
object
, optional A container for values for the element initialization.
- inp
- Returns:
- element
LinearSpaceElement
The new element.
- element
Linear combination¶
_lincomb(a, x1, b, x2, out)
This private method is the raw implementation (i.e. without error
checking) of the linear combination out = a * x1 + b * x2
.
LinearSpace._lincomb
and its public counterpart
LinearSpace.lincomb
are used to cover a range of convenience
functions, see below.
- Parameters:
- a, bscalars, must be members of the space's
field
Multiplicative scalar factors for input element
x1
orx2
, respectively.- x1, x2
LinearSpaceElement
Input elements.
- out
LinearSpaceElement
Element to which the result of the computation is written.
- a, bscalars, must be members of the space's
Returns: None
- Requirements:
Aliasing of
x1
,x2
andout
must be allowed.The input elements
x1
andx2
must not be modified.The initial state of the output element
out
must not influence the result.
Underlying scalar field¶
field
The public attribute determining the type of scalars which
underlie the space. Can be instances of either RealNumbers
or
ComplexNumbers
(see Field
).
Should be implemented as a @property
to make it immutable.
Equality check¶
__eq__(other)
LinearSpace
inherits this abstract method from Set
. Its
purpose is to check two LinearSpace
instances for equality.
- Parameters:
- other
object
The object to compare to.
- other
- Returns:
- equals
bool
True
ifother
is the sameLinearSpace
,False
otherwise.
- equals
Distance (optional)¶
_dist(x1, x2)
A raw (not type-checking) private method measuring the distance
between two elements x1
and x2
.
A space with a distance is called a metric space.
- Parameters:
- x1,x2
LinearSpaceElement
Elements whose mutual distance to calculate.
- x1,x2
- Returns:
- distance
float
The distance between
x1
andx2
, measured in the space's metric
- distance
- Requirements:
_dist(x, y) == _dist(y, x)
_dist(x, y) <= _dist(x, z) + _dist(z, y)
_dist(x, y) >= 0
_dist(x, y) == 0
(approx.) if and only ifx == y
(approx.)
Norm (optional)¶
_norm(x)
A raw (not type-checking) private method measuring the length of a
space element x
.
A space with a norm is called a normed space.
- Parameters:
- x
LinearSpaceElement
The element to measure.
- x
- Returns:
- norm
float
The length of
x
as measured in the space's norm.
- norm
- Requirements:
_norm(s * x) = |s| * _norm(x)
for any scalars
_norm(x + y) <= _norm(x) + _norm(y)
_norm(x) >= 0
_norm(x) == 0
(approx.) if and only ifx == 0
(approx.)
Inner product (optional)¶
_inner(x, y)
A raw (not type-checking) private method calculating the inner
product of two space elements x
and y
.
- Parameters:
- x,y
LinearSpaceElement
Elements whose inner product to calculate.
- x,y
- Returns:
- inner
float
orcomplex
The inner product of
x
andy
. IfLinearSpace.field
is the set of real numbers,inner
is afloat
, otherwisecomplex
.
- inner
- Requirements:
_inner(x, y) == _inner(y, x)^*
with '*' = complex conjugation_inner(s * x, y) == s * _inner(x, y)
fors
scalar_inner(x + z, y) == _inner(x, y) + _inner(z, y)
_inner(x, x) == 0
(approx.) if and only ifx == 0
(approx.)
Pointwise multiplication (optional)¶
_multiply(x1, x2, out)
A raw (not type-checking) private method multiplying two elements
x1
and x2
point-wise and storing the result in out
.
- Parameters:
- x1, x2
LinearSpaceElement
Elements whose point-wise product to calculate.
- out
LinearSpaceElement
Element to store the result.
- x1, x2
Returns: None
- Requirements:
_multiply(x, y, out) <==> _multiply(y, x, out)
_multiply(s * x, y, out) <==> _multiply(x, y, out); out *= s <==>
_multiply(x, s * y, out)
for any scalars
There is a space element
one
without
after_multiply(one, x, out)
or_multiply(x, one, out)
equalsx
.
Notes¶
A normed space is automatically a metric space with the distance function
_dist(x, y) = _norm(x - y)
.A Hilbert space (inner product space) is automatically a normed space with the norm function
_norm(x) = sqrt(_inner(x, x))
.The conditions on the pointwise multiplication constitute a unital commutative algebra in the mathematical sense.
References¶
See Wikipedia's mathematical overview articles Vector space, Algebra.