Skip to content

Class swarmauri_base.norms.UseInnerProductMixin.UseInnerProductMixin

swarmauri_base.norms.UseInnerProductMixin.UseInnerProductMixin

UseInnerProductMixin(inner_product, *args, **kwargs)

Bases: IUseInnerProduct

Base mixin class for structures dependent on inner products.

This mixin provides functionality for components that require an inner product structure for their operations. It maintains a reference to an inner product object and implements the IUseInnerProduct interface.

Attributes

_inner_product : IInnerProduct Reference to the inner product implementation used by this component

Initialize the mixin with an inner product.

Parameters

inner_product : IInnerProduct The inner product implementation to use args : Any Additional positional arguments for parent classes *kwargs : Any Additional keyword arguments for parent classes

Source code in swarmauri_base/norms/UseInnerProductMixin.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def __init__(self, inner_product: IInnerProduct, *args: Any, **kwargs: Any):
    """
    Initialize the mixin with an inner product.

    Parameters
    ----------
    inner_product : IInnerProduct
        The inner product implementation to use
    *args : Any
        Additional positional arguments for parent classes
    **kwargs : Any
        Additional keyword arguments for parent classes
    """
    self._inner_product = inner_product
    super().__init__(*args, **kwargs)
    logger.debug(
        f"Initialized {self.__class__.__name__} with inner product {inner_product}"
    )

get_inner_product

get_inner_product()

Get the inner product implementation used by this component.

Returns

IInnerProduct The inner product implementation

Source code in swarmauri_base/norms/UseInnerProductMixin.py
46
47
48
49
50
51
52
53
54
55
def get_inner_product(self) -> Literal[IInnerProduct]:
    """
    Get the inner product implementation used by this component.

    Returns
    -------
    IInnerProduct
        The inner product implementation
    """
    return self._inner_product

check_angle_between_vectors

check_angle_between_vectors(v1, v2)

Calculate the angle between two vectors using the inner product.

Parameters

v1 : Vector First vector v2 : Vector Second vector

Returns

float Angle between vectors in radians

Raises

NotImplementedError This is a base implementation that needs to be overridden

Source code in swarmauri_base/norms/UseInnerProductMixin.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def check_angle_between_vectors(self, v1: Vector, v2: Vector) -> float:
    """
    Calculate the angle between two vectors using the inner product.

    Parameters
    ----------
    v1 : Vector
        First vector
    v2 : Vector
        Second vector

    Returns
    -------
    float
        Angle between vectors in radians

    Raises
    ------
    NotImplementedError
        This is a base implementation that needs to be overridden
    """
    raise NotImplementedError(
        "check_angle_between_vectors must be implemented by subclasses"
    )

check_orthogonality

check_orthogonality(v1, v2, tolerance=1e-10)

Verify if two vectors are orthogonal to each other.

Parameters

v1 : Vector First vector v2 : Vector Second vector tolerance : float, optional Numerical tolerance for zero comparison, by default 1e-10

Returns

bool True if vectors are orthogonal, False otherwise

Raises

NotImplementedError This is a base implementation that needs to be overridden

Source code in swarmauri_base/norms/UseInnerProductMixin.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def check_orthogonality(
    self, v1: Vector, v2: Vector, tolerance: float = 1e-10
) -> bool:
    """
    Verify if two vectors are orthogonal to each other.

    Parameters
    ----------
    v1 : Vector
        First vector
    v2 : Vector
        Second vector
    tolerance : float, optional
        Numerical tolerance for zero comparison, by default 1e-10

    Returns
    -------
    bool
        True if vectors are orthogonal, False otherwise

    Raises
    ------
    NotImplementedError
        This is a base implementation that needs to be overridden
    """
    raise NotImplementedError(
        "check_orthogonality must be implemented by subclasses"
    )

check_xy_projection

check_xy_projection(v, basis_x, basis_y)

Project a vector onto the plane defined by two basis vectors.

Parameters

v : Vector Vector to project basis_x : Vector First basis vector (x-axis) basis_y : Vector Second basis vector (y-axis)

Returns

tuple[float, float] The (x, y) coordinates of the projection

Raises

NotImplementedError This is a base implementation that needs to be overridden

Source code in swarmauri_base/norms/UseInnerProductMixin.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def check_xy_projection(
    self, v: Vector, basis_x: Vector, basis_y: Vector
) -> tuple[float, float]:
    """
    Project a vector onto the plane defined by two basis vectors.

    Parameters
    ----------
    v : Vector
        Vector to project
    basis_x : Vector
        First basis vector (x-axis)
    basis_y : Vector
        Second basis vector (y-axis)

    Returns
    -------
    tuple[float, float]
        The (x, y) coordinates of the projection

    Raises
    ------
    NotImplementedError
        This is a base implementation that needs to be overridden
    """
    raise NotImplementedError(
        "check_xy_projection must be implemented by subclasses"
    )

check_parallelogram_law

check_parallelogram_law(v1, v2, tolerance=1e-10)

Verify if the parallelogram law holds for two vectors: ||v1 + v2||² + ||v1 - v2||² = 2(||v1||² + ||v2||²)

Parameters

v1 : Vector First vector v2 : Vector Second vector tolerance : float, optional Numerical tolerance for comparison, by default 1e-10

Returns

bool True if the parallelogram law holds, False otherwise

Raises

NotImplementedError This is a base implementation that needs to be overridden

Source code in swarmauri_base/norms/UseInnerProductMixin.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
def check_parallelogram_law(
    self, v1: Vector, v2: Vector, tolerance: float = 1e-10
) -> bool:
    """
    Verify if the parallelogram law holds for two vectors:
    ||v1 + v2||² + ||v1 - v2||² = 2(||v1||² + ||v2||²)

    Parameters
    ----------
    v1 : Vector
        First vector
    v2 : Vector
        Second vector
    tolerance : float, optional
        Numerical tolerance for comparison, by default 1e-10

    Returns
    -------
    bool
        True if the parallelogram law holds, False otherwise

    Raises
    ------
    NotImplementedError
        This is a base implementation that needs to be overridden
    """
    raise NotImplementedError(
        "check_parallelogram_law must be implemented by subclasses"
    )