Skip to content

Commit

Permalink
fix: rename SumDimensionMismatch to SumDimensionMismatchError
Browse files Browse the repository at this point in the history
  • Loading branch information
CallumJHays committed Oct 26, 2022
1 parent 041867b commit 43b6b4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions mathpad/val.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __eq__(self, other: "Q[Self]") -> "Equation":

def __eq__(self, other: "Q[Val]") -> "Equation":
if isinstance(other, Val):
SumDimensionsMismatch.check(self, "==", other)
SumDimensionsMismatchError.check(self, "==", other)
return Equation(self, other)

def __req__(self, other: Num) -> "Equation":
Expand Down Expand Up @@ -173,7 +173,7 @@ def in_units(self, units: Union[Literal["SI"], "Val"]) -> Self:
new_units = UnitSystem.get_unit_system(units)._base_units

else:
SumDimensionsMismatch.check(self, ".in_units", units)
SumDimensionsMismatchError.check(self, ".in_units", units)
new_units = units.units

units_factor, new_units = _split_coeff_and_units(
Expand Down Expand Up @@ -300,7 +300,7 @@ def _sum_op(
)

if isinstance(other, Val):
SumDimensionsMismatch.check(
SumDimensionsMismatchError.check(
other if reverse else self, op_str, self if reverse else other
)

Expand Down Expand Up @@ -405,7 +405,7 @@ def check(cls, exponent: Val):
raise cls(f"Exponent must be dimensionless: {exponent.dimension}")


class SumDimensionsMismatch(DimensionError):
class SumDimensionsMismatchError(DimensionError):
def __init__(
self,
left: Val,
Expand Down
10 changes: 5 additions & 5 deletions mathpad/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sympy.vector import Dot, Vector
from sympy import MatrixSymbol, Matrix, MatrixExpr, Expr, Derivative, Function

from mathpad.val import DimensionError, SumDimensionsMismatch, Val, Q
from mathpad.val import DimensionError, SumDimensionsMismatchError, Val, Q
from mathpad.vector_space import VectorSpaceT
from mathpad.equation import Equation

Expand Down Expand Up @@ -68,7 +68,7 @@ def re(self, space: VectorSpaceT) -> 'Vector[VectorSpaceT]':
def __eq__(self, other: 'Vector') -> "Equation":

for a, b in zip(self.space.base_units, other.space.base_units):
SumDimensionsMismatch.check(a, "==", b) # type: ignore
SumDimensionsMismatchError.check(a, "==", b) # type: ignore

return Equation(self, other)

Expand All @@ -82,7 +82,7 @@ def __add__(self, other: Self) -> Self:
f"Cannot add {type(other)} to {type(self)}"

for a, b in zip(self.space.base_units, other.space.base_units):
SumDimensionsMismatch.check(a, "==", b) # type: ignore
SumDimensionsMismatchError.check(a, "==", b) # type: ignore

assert self.space is other.space, \
f"Cannot add vectors of different VectorSpaces: {self.space} + {other.space}"
Expand All @@ -99,7 +99,7 @@ def __sub__(self, other: Self) -> Self:
"self - other"

for a, b in zip(self.space.base_units, other.space.base_units):
SumDimensionsMismatch.check(a, "==", b)
SumDimensionsMismatchError.check(a, "==", b)

assert self.space is other.space, \
f"Cannot subtract vectors of different VectorSpaces: {self.space} - {other.space}"
Expand Down Expand Up @@ -171,7 +171,7 @@ def norm(self) -> Val:

try:
norm_squared = sum(val ** 2 for val in self)
except SumDimensionsMismatch:
except SumDimensionsMismatchError:
raise ValueError("Cannot take the norm of a vector with non-uniform units")

return sqrt(norm_squared) # type: ignore
Expand Down

0 comments on commit 43b6b4e

Please sign in to comment.