Skip to content

braedynl/matrixlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MatrixLib

General-purpose matrices for the layman.

Implements a family of general-purpose matrix types, with comprehensive type-checking capabilities, and seamless integration with core Python services.

>>> from collections.abc import Iterable
>>> from math import fsum, sqrt, isclose
>>> from typing import Literal as L
>>>
>>> from matrixlib import ROW, RealMatrix, IntegerMatrix
>>>
>>> def norm(a: Iterable[float]) -> float:
...     return sqrt(fsum(map(lambda x: x * x, a)))
...
>>> a = IntegerMatrix[L[3], L[3], int](
...     (
...         1, 2, 3,
...         4, 5, 6,
...         7, 8, 9,
...     ),
...     shape=(3, 3),
... )
>>>
>>> b = RealMatrix[L[3], L[3], float](
...     (
...         val
...         for row in a.slices(by=ROW)
...         for val in row / norm(row)
...     ),
...     shape=a.shape,
... )
>>>
>>> print(b)
| 0.267260.534520.80178|
| 0.455840.569800.68376|
| 0.502570.574360.64616|
(3 × 3)
>>>
>>> assert all(isclose(norm(row), 1) for row in b.slices(by=ROW))

Getting Started

This project is available through pip (requires Python 3.9 or later, 3.11 recommended):

pip install matrixlib

Warning: MatrixLib is currently in its infancy, and may see future changes that are not always backwards compatible.

The current iteration of this library is in beta. Further testing is being conducted at the moment.

Contributing

This project is currently maintained by Braedyn L. Feel free to report bugs or make a pull request through this repository.

License

Distributed under the MIT license. See the LICENSE file for more details.