Verified Commit 6a300bc8 authored by Julien Jerphanion's avatar Julien Jerphanion
Browse files

Use private class attributes for error messages

parent df1a0aa0
Pipeline #140510 failed with stage
in 13 minutes and 29 seconds
......@@ -7,7 +7,7 @@ import abc
class Basis(abc.ABC):
unimplementedMessage = "This method is not implemented."
_unimplemented_message = "This method is not implemented."
def __init__(self, multigenerator, support):
self.multigenerator = multigenerator
......@@ -15,27 +15,27 @@ class Basis(abc.ABC):
@abc.abstractmethod
def value(self, x):
raise NotImplementedError(Basis.unimplementedMessage)
raise NotImplementedError(Basis._unimplemented_message)
@abc.abstractmethod
def firstDerivativeValue(self, x):
raise NotImplementedError(Basis.unimplementedMessage)
raise NotImplementedError(Basis._unimplemented_message)
@abc.abstractmethod
def secondDerivativeValue(self, x):
raise NotImplementedError(Basis.unimplementedMessage)
raise NotImplementedError(Basis._unimplemented_message)
@abc.abstractmethod
def filterSymmetric(self, s):
raise NotImplementedError(Basis.unimplementedMessage)
raise NotImplementedError(Basis._unimplemented_message)
@abc.abstractmethod
def filterPeriodic(self, s):
raise NotImplementedError(Basis.unimplementedMessage)
raise NotImplementedError(Basis._unimplemented_message)
@abc.abstractmethod
def refinementMask(self):
raise NotImplementedError(Basis.unimplementedMessage)
raise NotImplementedError(Basis._unimplemented_message)
@property
def support(self):
......@@ -591,13 +591,13 @@ class H3(Basis):
return val
def filterPeriodic(self, s):
raise NotImplementedError(SplineGenerator.unimplementedMessage)
raise NotImplementedError(Basis._unimplemented_message)
def refinementMask(self):
raise NotImplementedError(SplineGenerator.unimplementedMessage)
raise NotImplementedError(Basis._unimplemented_message)
def filterSymmetric(self, s):
raise NotImplementedError(SplineGenerator.unimplementedMessage)
raise NotImplementedError(Basis._unimplemented_message)
class HE3(Basis):
......@@ -734,13 +734,13 @@ class HE3(Basis):
raise RuntimeError("HE3 isn't twice differentiable.")
def filterPeriodic(self, s):
raise NotImplementedError(Basis.unimplementedMessage)
raise NotImplementedError(Basis._unimplemented_message)
def refinementMask(self):
raise NotImplementedError(Basis.unimplementedMessage)
raise NotImplementedError(Basis._unimplemented_message)
def filterSymmetric(self, s):
raise NotImplementedError(Basis.unimplementedMessage)
raise NotImplementedError(Basis._unimplemented_message)
def multinomial(
......
......@@ -8,13 +8,13 @@ from scipy import integrate
class SplineCurve:
wrongDimensionMessage = "It looks like coefs is a 2D array with second " \
_wrong_dimension_message = "It looks like coefs is a 2D array with second " \
"dimension different than two. I don't know how " \
"to handle this yet."
wrongArraySizeMessage = "It looks like coefs is neither a 1 nor a 2D " \
_wrong_array_size_message = "It looks like coefs is neither a 1 nor a 2D " \
"array. I don't know how to handle this yet."
noCoefsMessage = "This model doesn't have any coefficients."
unimplementedMessage = "This function is not implemented."
_no_coefs_message = "This model doesn't have any coefficients."
_unimplemented_message = "This function is not implemented."
# A cache from pair (M, sampling_rate) to phi matrices
......@@ -216,7 +216,7 @@ class SplineCurve:
def draw(self, dimensions):
if self.coefs is None:
raise RuntimeError(self.noCoefsMessage)
raise RuntimeError(self._no_coefs_message)
if len(self.coefs.shape) != 2 or self.coefs.shape[1] != 2:
raise RuntimeError("draw() can only be used with 2D curves.")
......@@ -276,12 +276,12 @@ class SplineCurve:
filter = self.basis.filterSymmetric
if len(knots.shape) > 2:
raise RuntimeError(self.wrongArraySizeMessage)
raise RuntimeError(self._wrong_array_size_message)
elif len(knots.shape) == 1:
self._coefs = filter(knots)
elif len(knots.shape) == 2:
if knots.shape[1] != 2:
raise RuntimeError(self.wrongDimensionMessage)
raise RuntimeError(self._wrong_dimension_message)
else:
coefsX = filter(knots[:, 0])
coefsY = filter(knots[:, 1])
......@@ -420,7 +420,7 @@ class SplineCurve:
f"even=true", DeprecationWarning)
if self.coefs is None:
raise RuntimeError(self.noCoefsMessage)
raise RuntimeError(self._no_coefs_message)
if len(self.coefs.shape) == 1 or (
len(self.coefs.shape) == 2 and self.coefs.shape[1] == 2
......@@ -448,13 +448,13 @@ class SplineCurve:
curve = curve[~np.all(curve == 0, axis=1)]
else:
raise RuntimeError(self.wrongArraySizeMessage)
raise RuntimeError(self._wrong_array_size_message)
return np.stack(curve)
def parameterToWorld(self, t, dt=False):
if self.coefs is None:
raise RuntimeError(SplineCurve.noCoefsMessage)
raise RuntimeError(SplineCurve._no_coefs_message)
ts = np.array([self._wrapIndex(t, k) for k in range(self.M)])
f = self.basis.firstDerivativeValue if dt else self.basis.value
......@@ -522,24 +522,24 @@ class HermiteSplineCurve(SplineCurve):
raise RuntimeError(self.coefTangentMismatchMessage)
if len(knots.shape) > 2:
raise RuntimeError(SplineCurve.wrongArraySizeMessage)
raise RuntimeError(SplineCurve._wrong_array_size_message)
if len(knots.shape) == 2 and knots.shape[1] != 2:
raise RuntimeError(SplineCurve.wrongDimensionMessage)
raise RuntimeError(SplineCurve._wrong_dimension_message)
self._coefs = knots
self._tangents = tangentAtKnots
def setCoefsFromDenseContour(self, contourPoints, tangentAtPoints):
# TODO
raise NotImplementedError(SplineCurve.unimplementedMessage)
raise NotImplementedError(SplineCurve._unimplemented_message)
def setCoefsFromBinaryMask(self, binaryMask):
# TODO
raise NotImplementedError(SplineCurve.unimplementedMessage)
raise NotImplementedError(SplineCurve._unimplemented_message)
def parameterToWorld(self, t, dt=False):
if self.coefs is None:
raise RuntimeError(SplineCurve.noCoefsMessage)
raise RuntimeError(SplineCurve._no_coefs_message)
value = 0.0
for k in range(0, self.M):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment