Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion matops/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Matrix Operations"""

__version__ = "0.1.2"
__version__ = "0.1.3"

from .matrix import Matrix
7 changes: 7 additions & 0 deletions matops/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ def __init__(self, rows: List[List[Number]]) -> None:
def __str__(self) -> str:
return str(self.rows)

def __round__(self, ndigits: int = None) -> "Matrix":
temp = self._get_zero_matrix()
for i in range(self.num_rows):
for j in range(self.num_cols):
temp[i][j] = round(self.rows[i][j], ndigits)
return Matrix(temp)

def __add__(self, other: "Matrix") -> "Matrix":
temp = self._get_zero_matrix()
for i in range(self.num_rows):
Expand Down
20 changes: 20 additions & 0 deletions tests/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,23 @@ def test_proof_1():
)

assert (m1 * m2).transpose() == m2.transpose() * m1.transpose()


def test_round_1():
m1 = Matrix(
[
[1.1123, -2.982143],
[3.21043, 4.4253],
]
)
assert round(m1) == Matrix([[1, -3], [3, 4]])


def test_round_2():
m1 = Matrix(
[
[1.1123, -2.982143],
[3.21043, 4.4253],
]
)
assert round(m1, 2) == Matrix([[1.11, -2.98], [3.21, 4.43]])