Skip to content

Class swarmauri_core.matrices.IMatrix.IMatrix

swarmauri_core.matrices.IMatrix.IMatrix

Bases: ABC

Interface abstraction for matrix operations.

This interface defines the standard operations and properties that all matrix implementations must support, providing a common API for linear operators and 2D structures.

shape abstractmethod property

shape

Get the shape of the matrix.

Returns

Tuple[int, int] The dimensions of the matrix as (rows, columns)

dtype abstractmethod property

dtype

Get the data type of the matrix elements.

Returns

type The data type of the elements

reshape abstractmethod

reshape(shape)

Reshape the matrix to the specified dimensions.

Parameters

shape : Tuple[int, int] The new dimensions as (rows, columns)

Returns

IMatrix A reshaped matrix

Raises

ValueError If the new shape is incompatible with the total number of elements

Source code in swarmauri_core/matrices/IMatrix.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@abstractmethod
def reshape(self, shape: Tuple[int, int]) -> "IMatrix":
    """
    Reshape the matrix to the specified dimensions.

    Parameters
    ----------
    shape : Tuple[int, int]
        The new dimensions as (rows, columns)

    Returns
    -------
    IMatrix
        A reshaped matrix

    Raises
    ------
    ValueError
        If the new shape is incompatible with the total number of elements
    """
    pass

tolist abstractmethod

tolist()

Convert the matrix to a nested list.

Returns

List[List[T]] A list of lists representing the matrix

Source code in swarmauri_core/matrices/IMatrix.py
130
131
132
133
134
135
136
137
138
139
140
@abstractmethod
def tolist(self) -> List[List[T]]:
    """
    Convert the matrix to a nested list.

    Returns
    -------
    List[List[T]]
        A list of lists representing the matrix
    """
    pass

row abstractmethod

row(index)

Get a specific row of the matrix.

Parameters

index : int The row index

Returns

IVector The specified row as a vector

Raises

IndexError If the index is out of bounds

Source code in swarmauri_core/matrices/IMatrix.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
@abstractmethod
def row(self, index: int) -> IVector:
    """
    Get a specific row of the matrix.

    Parameters
    ----------
    index : int
        The row index

    Returns
    -------
    IVector
        The specified row as a vector

    Raises
    ------
    IndexError
        If the index is out of bounds
    """
    pass

column abstractmethod

column(index)

Get a specific column of the matrix.

Parameters

index : int The column index

Returns

IVector The specified column as a vector

Raises

IndexError If the index is out of bounds

Source code in swarmauri_core/matrices/IMatrix.py
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
@abstractmethod
def column(self, index: int) -> IVector:
    """
    Get a specific column of the matrix.

    Parameters
    ----------
    index : int
        The column index

    Returns
    -------
    IVector
        The specified column as a vector

    Raises
    ------
    IndexError
        If the index is out of bounds
    """
    pass

transpose abstractmethod

transpose()

Transpose the matrix.

Returns

IMatrix The transposed matrix

Source code in swarmauri_core/matrices/IMatrix.py
339
340
341
342
343
344
345
346
347
348
349
@abstractmethod
def transpose(self) -> "IMatrix":
    """
    Transpose the matrix.

    Returns
    -------
    IMatrix
        The transposed matrix
    """
    pass