Class swarmauri_core.tensors.ITensor.ITensor
swarmauri_core.tensors.ITensor.ITensor
Bases: ABC
Core interface for tensorial algebra components.
This interface specifies required tensor operations and structural properties that all tensor implementations must support, providing a common API for n-dimensional arrays and mathematical operations.
shape
abstractmethod
property
shape
Get the shape of the tensor.
Returns
Shape The dimensions of the tensor
dtype
abstractmethod
property
dtype
Get the data type of the tensor elements.
Returns
type The data type of the elements
reshape
abstractmethod
reshape(shape)
Reshape the tensor to the specified dimensions.
Parameters
shape : Shape The new dimensions
Returns
ITensor A reshaped tensor
Raises
ValueError If the new shape is incompatible with the total number of elements
Source code in swarmauri_core/tensors/ITensor.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
tolist
abstractmethod
tolist()
Convert the tensor to a nested list.
Returns
List A nested list representing the tensor
Source code in swarmauri_core/tensors/ITensor.py
130 131 132 133 134 135 136 137 138 139 140 |
|
transpose
abstractmethod
transpose(axes=None)
Transpose (permute) the tensor's axes.
Parameters
axes : Union[None, Tuple[int, ...]], optional The new order of dimensions. If None, reverse the dimensions.
Returns
ITensor The transposed tensor
Raises
ValueError If the axes specification is invalid
Source code in swarmauri_core/tensors/ITensor.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
broadcast
abstractmethod
broadcast(shape)
Broadcast the tensor to a new shape.
Parameters
shape : Shape The shape to broadcast to
Returns
ITensor The broadcasted tensor
Raises
ValueError If the tensor cannot be broadcast to the given shape
Source code in swarmauri_core/tensors/ITensor.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
astype
abstractmethod
astype(dtype)
Cast the tensor to a specified data type.
Parameters
dtype : type The target data type
Returns
ITensor A new tensor with the specified data type
Source code in swarmauri_core/tensors/ITensor.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
to_matrix
abstractmethod
to_matrix()
Convert the tensor to a matrix if possible.
Returns
IMatrix The tensor as a matrix
Raises
ValueError If the tensor cannot be converted to a matrix
Source code in swarmauri_core/tensors/ITensor.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
|
to_vector
abstractmethod
to_vector()
Convert the tensor to a vector if possible.
Returns
IVector The tensor as a vector
Raises
ValueError If the tensor cannot be converted to a vector
Source code in swarmauri_core/tensors/ITensor.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|