mirror of
https://github.com/vale981/SecondaryValue
synced 2025-03-04 16:41:38 -05:00
add missing symbol detection
This commit is contained in:
parent
9139ac9289
commit
bafb6d44fa
1 changed files with 15 additions and 2 deletions
|
@ -29,8 +29,8 @@ class SecondaryValue:
|
|||
self._parsed = sympify(self._expr) if isinstance(self._expr, str) \
|
||||
else self._expr
|
||||
|
||||
self._symbols = [symbol.__str__() \
|
||||
for symbol in self._parsed.free_symbols]
|
||||
self._symbols = set([symbol.__str__() \
|
||||
for symbol in self._parsed.free_symbols])
|
||||
|
||||
self._deps = {name: dependency \
|
||||
for name, dependency in dependencies.items() \
|
||||
|
@ -79,6 +79,11 @@ class SecondaryValue:
|
|||
|
||||
kwargs, dep_values = self._calc_deps(**kwargs)
|
||||
|
||||
# check for missing symbols
|
||||
if not self._symbols <= set(kwargs.keys()):
|
||||
return RuntimeError('Missing symbols: ' +
|
||||
(self._symbols - set(kwargs.keys())).__str__())
|
||||
|
||||
# filter out unneeded
|
||||
kwargs = {var: val for var, val in kwargs.items() if var in self._symbols}
|
||||
|
||||
|
@ -137,3 +142,11 @@ class SecondaryValue:
|
|||
terms = [(sympy.simplify(derivs[var]) * sympy.Dummy('Delta_' + var))**2 \
|
||||
for var in variables]
|
||||
return sympy.sqrt(sum(terms))
|
||||
|
||||
def get_symbols(self):
|
||||
"""
|
||||
:returns: The symbols that can be substituted.
|
||||
:rtype: List
|
||||
"""
|
||||
|
||||
return self._symbols
|
||||
|
|
Loading…
Add table
Reference in a new issue