Skip to content

Commit eb3866a

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 3d17abe commit eb3866a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

linear_algebra/matrix_trace.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def trace_properties_demo(matrix: NDArray[float64]) -> dict:
8585
"scalar_factor": scalar,
8686
"identity_trace": tr_identity,
8787
"trace_equals_transpose": abs(tr - tr_transpose) < 1e-10,
88-
"scalar_property_check": abs(tr_scalar - scalar * tr) < 1e-10
88+
"scalar_property_check": abs(tr_scalar - scalar * tr) < 1e-10,
8989
}
9090

9191

@@ -101,28 +101,28 @@ def test_trace() -> None:
101101
assert abs(tr_2x2 - 5.0) < 1e-10, "2x2 trace calculation failed"
102102

103103
# Test 2: 3x3 matrix
104-
matrix_3x3 = np.array([[2.0, -1.0, 3.0],
105-
[4.0, 5.0, -2.0],
106-
[1.0, 0.0, 7.0]], dtype=float)
104+
matrix_3x3 = np.array(
105+
[[2.0, -1.0, 3.0], [4.0, 5.0, -2.0], [1.0, 0.0, 7.0]], dtype=float
106+
)
107107
tr_3x3 = trace(matrix_3x3)
108108
assert abs(tr_3x3 - 14.0) < 1e-10, "3x3 trace calculation failed"
109109

110110
# Test 3: Identity matrix
111111
identity_4x4 = np.eye(4, dtype=float)
112112
tr_identity = trace(identity_4x4)
113-
assert (
114-
abs(tr_identity - 4.0) < 1e-10
115-
), "Identity matrix trace should equal dimension"
113+
assert abs(tr_identity - 4.0) < 1e-10, (
114+
"Identity matrix trace should equal dimension"
115+
)
116116

117117
# Test 4: Zero matrix
118118
zero_matrix = np.zeros((3, 3), dtype=float)
119119
tr_zero = trace(zero_matrix)
120120
assert abs(tr_zero) < 1e-10, "Zero matrix should have zero trace"
121121

122122
# Test 5: Trace properties
123-
test_matrix = np.array([[1.0, 2.0, 3.0],
124-
[4.0, 5.0, 6.0],
125-
[7.0, 8.0, 9.0]], dtype=float)
123+
test_matrix = np.array(
124+
[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]], dtype=float
125+
)
126126
properties = trace_properties_demo(test_matrix)
127127
assert properties["trace_equals_transpose"], "Trace should equal transpose trace"
128128
assert properties["scalar_property_check"], "Scalar multiplication property failed"
@@ -131,9 +131,9 @@ def test_trace() -> None:
131131
diagonal_matrix = np.diag([1.0, 2.0, 3.0, 4.0])
132132
tr_diagonal = trace(diagonal_matrix)
133133
expected = 1.0 + 2.0 + 3.0 + 4.0
134-
assert (
135-
abs(tr_diagonal - expected) < 1e-10
136-
), "Diagonal matrix trace should equal sum of diagonal elements"
134+
assert abs(tr_diagonal - expected) < 1e-10, (
135+
"Diagonal matrix trace should equal sum of diagonal elements"
136+
)
137137

138138

139139
if __name__ == "__main__":

0 commit comments

Comments
 (0)