-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add numjac test and refactor the files
- Loading branch information
Showing
32 changed files
with
297 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import List | ||
|
||
from Solverz.code_printer.py_printer import render_modules as py_render | ||
from Solverz.equation.equations import AE, FDAE, DAE | ||
from Solverz.variable.variables import Vars | ||
|
||
|
||
class module_printer: | ||
def __init__(self, | ||
mdl: AE | FDAE | DAE, | ||
variables: Vars | List[Vars], | ||
name: str, | ||
lang='python', | ||
directory=None, | ||
jit=False): | ||
self.name = name | ||
self.lang = lang | ||
self.mdl = mdl | ||
if isinstance(variables, Vars): | ||
self.variables = [variables] | ||
else: | ||
self.variables = variables | ||
self.directory = directory | ||
self.jit = jit | ||
|
||
def render(self): | ||
if self.lang == 'python': | ||
py_render(self.mdl, | ||
*self.variables, | ||
name=self.name, | ||
directory=self.directory, | ||
numba=self.jit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import numpy as np | ||
|
||
from Solverz.code_printer.py_printer import made_numerical | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Callable, Dict | ||
|
||
import numpy as np | ||
|
||
from Solverz.equation.param import TimeSeriesParam | ||
from Solverz.variable.variables import Vars, TimeVars, combine_Vars | ||
|
||
|
||
class nAE: | ||
|
||
def __init__(self, | ||
F: Callable, | ||
J: Callable, | ||
p: Dict): | ||
self.F = F | ||
self.J = J | ||
self.p = p | ||
|
||
|
||
class nFDAE: | ||
|
||
def __init__(self, | ||
F: callable, | ||
J: callable, | ||
p: dict, | ||
nstep: int = 0): | ||
self.F = F | ||
self.J = J | ||
self.p = p | ||
self.nstep = nstep | ||
|
||
|
||
class nDAE: | ||
|
||
def __init__(self, | ||
M, | ||
F: Callable, | ||
J: Callable, | ||
p: Dict): | ||
self.M = M | ||
self.F = F | ||
self.J = J | ||
self.p = p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
2 changes: 1 addition & 1 deletion
2
...rz/numerical_interface/test/test_Array.py → Solverz/num_api/test/test_Array.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rical_interface/test/test_code_printer.py → Solverz/num_api/test/test_code_printer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import numpy as np | ||
|
||
from Solverz.num_api.numjac import numjac_ae | ||
|
||
|
||
def f(x): | ||
a = 1 + np.exp(x[0]) + np.sin(x[1]) | ||
b = x[1] ** 2 + np.cos(x[0]) | ||
return np.array([a, b]) | ||
|
||
|
||
def Janaly(x): | ||
return np.array([[np.exp(x[0]), np.cos(x[1])], | ||
[-np.sin(x[0]), 2 * x[1]]]) | ||
|
||
|
||
def Jnum(x): | ||
return numjac_ae(lambda xi: f(xi), | ||
x, | ||
np.ones(len(x)) * 1.e-12)[0] | ||
|
||
|
||
point = np.array([1.0, 2.0]) | ||
|
||
np.testing.assert_allclose(Jnum(point).toarray(), Janaly(point), rtol=1e-5) |
Oops, something went wrong.