is_compatible_space

odl.operator.tensor_ops.is_compatible_space(space, base_space)[source]

Check compatibility of a (power) space with a base space.

Compatibility here means that the spaces are equal or space is a non-empty power space of base_space up to different data types.

Parameters
space, base_spaceLinearSpace

Spaces to check for compatibility. base_space cannot be a ProductSpace.

Returns
is_compatiblebool

True if

  • space == base_space or

  • space.astype(base_space.dtype) == base_space, provided that these properties exist, or

  • space is a power space of nonzero length and one of the three situations applies to space[0] (recursively).

Otherwise False.

Examples

Scalar spaces:

>>> base = odl.rn(2)
>>> is_compatible_space(odl.rn(2), base)
True
>>> is_compatible_space(odl.rn(3), base)
False
>>> is_compatible_space(odl.rn(2, dtype='float32'), base)
True

Power spaces:

>>> is_compatible_space(odl.rn(2) ** 2, base)
True
>>> is_compatible_space(odl.rn(2) * odl.rn(3), base)  # no power space
False
>>> is_compatible_space(odl.rn(2, dtype='float32') ** 2, base)
True