Capability Dispatch#
A space has an operation only if its class carries the capability that defines
it; test with isinstance(X, sc.StarSpace) and so on.
Capability |
Adds |
|---|---|
|
context, |
|
|
|
|
|
|
|
|
|
|
|
marker: Jordan structure compatible with the Euclidean inner product |
DenseCoordinateSpace: inner product, no star.DenseVectorSpaceadds star, no Jordan.ElementwiseJordanSpaceadds Jordan.ElementwiseJordanSpace(shape, ctx)returns anEuclideanElementwiseJordanSpacewhen the dtype is real and the geometry Euclidean; constructing the Euclidean class directly with any other geometry raisesTypeError.TreeSpaceandStackedSpacecarry exactly the capabilities shared by all their leaves (or their base), and re-select them afterconvert.A missing capability is a missing attribute (
AttributeError).
import numpy as np
import spacecore as sc
ctx = sc.Context(sc.NumpyOps(), dtype=np.float64)
V = sc.DenseVectorSpace((2,), ctx)
D = sc.DenseCoordinateSpace((2,), ctx)
assert isinstance(sc.TreeSpace.from_leaf_spaces((V, V)), sc.StarSpace)
assert not isinstance(sc.TreeSpace.from_leaf_spaces((V, D)), sc.StarSpace)
assert isinstance(sc.ElementwiseJordanSpace((2,), ctx),
sc.EuclideanElementwiseJordanSpace)
try:
sc.EuclideanElementwiseJordanSpace(
(2,), ctx, geometry=sc.WeightedInnerProduct(ctx.asarray([1.0, 2.0]))
)
except TypeError as exc:
print(exc) # EuclideanElementwiseJordanSpace requires EuclideanInnerProduct.
try:
D.star(ctx.asarray([1.0, 2.0]))
except AttributeError as exc:
print(exc) # 'DenseCoordinateSpace' object has no attribute 'star'