Skip to content

Commit 90894d0

Browse files
committed
add: method that checks whether a Function is bijective.
1 parent 029c57a commit 90894d0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

rocketpy/Function.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,10 +2112,21 @@ def integralFunction(self, lower=None, upper=None, datapoints=100):
21122112
inputs=self.__inputs__,
21132113
outputs=[o + " Integral" for o in self.__outputs__])
21142114

2115-
def inverseFunction(self, lower=None, upper=None, datapoints=100):
2115+
def isBijective(self):
2116+
"""Checks whether the Function is bijective. Only applicable to Functions whose source is a list of points, raises an error otherwise.
2117+
2118+
Returns
2119+
-------
2120+
result : bool
2121+
True if the Function is bijective, False otherwise.
21162122
"""
2117-
Returns the inverse of the Function. The inverse function of F is a function that undoes the operation of F. The
2118-
inverse of F exists if and only if F is bijective. Makes the domain the range and the range the domain.
2123+
if isinstance(self.source, np.ndarray):
2124+
xDataDistinct = set(self.source[:, 0])
2125+
yDataDistinct = set(self.source[:, 1])
2126+
distinctMap = set(zip(xDataDistinct, yDataDistinct))
2127+
return len(distinctMap) == len(xDataDistinct) == len(yDataDistinct)
2128+
else:
2129+
raise TypeError("Only Functions whose source is a list of points can be checked for bijectivity.")
21192130

21202131
Parameters
21212132
----------

0 commit comments

Comments
 (0)