Source code for spacecore.space.base._vector
from __future__ import annotations
from abc import abstractmethod
from typing import Any
from ._space import Space
[docs]
class VectorSpace(Space):
"""
Abstract vector-space capability: linear operations only.
Parameters
----------
ctx : Context, str, or None, optional
Context specification used for elements and validation checks.
"""
[docs]
@abstractmethod
def zeros(self) -> Any:
"""Return the additive identity."""
[docs]
@abstractmethod
def add(self, x: Any, y: Any) -> Any:
"""Return x + y."""
[docs]
@abstractmethod
def scale(self, a: Any, x: Any) -> Any:
"""Return a * x."""
[docs]
def axpy(self, a: Any, x: Any, y: Any) -> Any:
"""Return a*x + y."""
return self.add(self.scale(a, x), y)