open-space-toolkit-mathematics 4.6.0__py39-none-manylinux2014_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- open_space_toolkit_mathematics-4.6.0.dist-info/METADATA +28 -0
- open_space_toolkit_mathematics-4.6.0.dist-info/RECORD +68 -0
- open_space_toolkit_mathematics-4.6.0.dist-info/WHEEL +5 -0
- open_space_toolkit_mathematics-4.6.0.dist-info/top_level.txt +1 -0
- open_space_toolkit_mathematics-4.6.0.dist-info/zip-safe +1 -0
- ostk/__init__.py +1 -0
- ostk/mathematics/OpenSpaceToolkitMathematicsPy.cpython-39-aarch64-linux-gnu.so +0 -0
- ostk/mathematics/__init__.py +5 -0
- ostk/mathematics/__init__.pyi +11 -0
- ostk/mathematics/curve_fitting/__init__.pyi +155 -0
- ostk/mathematics/curve_fitting/interpolator.pyi +243 -0
- ostk/mathematics/geometry/__init__.pyi +504 -0
- ostk/mathematics/geometry/d2/__init__.pyi +809 -0
- ostk/mathematics/geometry/d2/object.pyi +1779 -0
- ostk/mathematics/geometry/d3/__init__.pyi +1032 -0
- ostk/mathematics/geometry/d3/object.pyi +3709 -0
- ostk/mathematics/geometry/d3/transformation/__init__.pyi +3 -0
- ostk/mathematics/geometry/d3/transformation/rotation.pyi +1358 -0
- ostk/mathematics/libopen-space-toolkit-mathematics.so.4 +0 -0
- ostk/mathematics/object.pyi +387 -0
- ostk/mathematics/solver.pyi +342 -0
- ostk/mathematics/test/__init__.py +1 -0
- ostk/mathematics/test/curve_fitting/__init__.py +1 -0
- ostk/mathematics/test/curve_fitting/interpolator/__init__.py +1 -0
- ostk/mathematics/test/curve_fitting/interpolator/test_barycentric_rational.py +44 -0
- ostk/mathematics/test/curve_fitting/interpolator/test_cubic_spline.py +55 -0
- ostk/mathematics/test/curve_fitting/interpolator/test_interpolator.py +71 -0
- ostk/mathematics/test/curve_fitting/interpolator/test_linear.py +45 -0
- ostk/mathematics/test/geometry/__init__.py +1 -0
- ostk/mathematics/test/geometry/d2/__init__.py +1 -0
- ostk/mathematics/test/geometry/d2/conftest.py +79 -0
- ostk/mathematics/test/geometry/d2/object/__init__.py +1 -0
- ostk/mathematics/test/geometry/d2/object/test_composite.py +93 -0
- ostk/mathematics/test/geometry/d2/object/test_line.py +57 -0
- ostk/mathematics/test/geometry/d2/object/test_linestring.py +174 -0
- ostk/mathematics/test/geometry/d2/object/test_multipolygon.py +94 -0
- ostk/mathematics/test/geometry/d2/object/test_point.py +213 -0
- ostk/mathematics/test/geometry/d2/object/test_point_set.py +100 -0
- ostk/mathematics/test/geometry/d2/object/test_polygon.py +370 -0
- ostk/mathematics/test/geometry/d2/object/test_segment.py +104 -0
- ostk/mathematics/test/geometry/d2/test_object.py +25 -0
- ostk/mathematics/test/geometry/d2/test_transformation.py +84 -0
- ostk/mathematics/test/geometry/d3/__init__.py +1 -0
- ostk/mathematics/test/geometry/d3/object/__init__.py +1 -0
- ostk/mathematics/test/geometry/d3/object/test_composite.py +262 -0
- ostk/mathematics/test/geometry/d3/object/test_cuboid.py +20 -0
- ostk/mathematics/test/geometry/d3/object/test_line.py +68 -0
- ostk/mathematics/test/geometry/d3/object/test_linestring.py +168 -0
- ostk/mathematics/test/geometry/d3/object/test_point.py +234 -0
- ostk/mathematics/test/geometry/d3/object/test_point_set.py +113 -0
- ostk/mathematics/test/geometry/d3/object/test_polygon.py +141 -0
- ostk/mathematics/test/geometry/d3/object/test_segment.py +120 -0
- ostk/mathematics/test/geometry/d3/objects/test_cuboid.py +20 -0
- ostk/mathematics/test/geometry/d3/test_intersection.py +3 -0
- ostk/mathematics/test/geometry/d3/test_object.py +3 -0
- ostk/mathematics/test/geometry/d3/test_transformation.py +3 -0
- ostk/mathematics/test/geometry/d3/transformation/__init__.py +1 -0
- ostk/mathematics/test/geometry/d3/transformation/rotation/__init__.py +1 -0
- ostk/mathematics/test/geometry/d3/transformation/rotation/test_euler_angle.py +138 -0
- ostk/mathematics/test/geometry/d3/transformation/rotation/test_quaternion.py +189 -0
- ostk/mathematics/test/geometry/d3/transformation/rotation/test_rotation_matrix.py +40 -0
- ostk/mathematics/test/geometry/d3/transformation/rotation/test_rotation_vector.py +47 -0
- ostk/mathematics/test/geometry/test_angle.py +345 -0
- ostk/mathematics/test/object/__init__.py +1 -0
- ostk/mathematics/test/object/test_interval.py +515 -0
- ostk/mathematics/test/object/test_vector.py +5 -0
- ostk/mathematics/test/solver/test_numerical_solver.py +176 -0
- ostk/mathematics/test/test_object.py +24 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import numpy
|
|
3
|
+
import ostk.core.type
|
|
4
|
+
import typing
|
|
5
|
+
__all__ = ['NumericalSolver']
|
|
6
|
+
class NumericalSolver:
|
|
7
|
+
class LogType:
|
|
8
|
+
"""
|
|
9
|
+
Members:
|
|
10
|
+
|
|
11
|
+
NoLog
|
|
12
|
+
|
|
13
|
+
LogConstant
|
|
14
|
+
|
|
15
|
+
LogAdaptive
|
|
16
|
+
"""
|
|
17
|
+
LogAdaptive: typing.ClassVar[NumericalSolver.LogType] # value = <LogType.LogAdaptive: 2>
|
|
18
|
+
LogConstant: typing.ClassVar[NumericalSolver.LogType] # value = <LogType.LogConstant: 1>
|
|
19
|
+
NoLog: typing.ClassVar[NumericalSolver.LogType] # value = <LogType.NoLog: 0>
|
|
20
|
+
__members__: typing.ClassVar[dict[str, NumericalSolver.LogType]] # value = {'NoLog': <LogType.NoLog: 0>, 'LogConstant': <LogType.LogConstant: 1>, 'LogAdaptive': <LogType.LogAdaptive: 2>}
|
|
21
|
+
def __eq__(self, other: typing.Any) -> bool:
|
|
22
|
+
...
|
|
23
|
+
def __getstate__(self) -> int:
|
|
24
|
+
...
|
|
25
|
+
def __hash__(self) -> int:
|
|
26
|
+
...
|
|
27
|
+
def __index__(self) -> int:
|
|
28
|
+
...
|
|
29
|
+
def __init__(self, value: int) -> None:
|
|
30
|
+
...
|
|
31
|
+
def __int__(self) -> int:
|
|
32
|
+
...
|
|
33
|
+
def __ne__(self, other: typing.Any) -> bool:
|
|
34
|
+
...
|
|
35
|
+
def __repr__(self) -> str:
|
|
36
|
+
...
|
|
37
|
+
def __setstate__(self, state: int) -> None:
|
|
38
|
+
...
|
|
39
|
+
def __str__(self) -> str:
|
|
40
|
+
...
|
|
41
|
+
@property
|
|
42
|
+
def name(self) -> str:
|
|
43
|
+
...
|
|
44
|
+
@property
|
|
45
|
+
def value(self) -> int:
|
|
46
|
+
...
|
|
47
|
+
class StepperType:
|
|
48
|
+
"""
|
|
49
|
+
Members:
|
|
50
|
+
|
|
51
|
+
RungeKutta4
|
|
52
|
+
|
|
53
|
+
RungeKuttaCashKarp54
|
|
54
|
+
|
|
55
|
+
RungeKuttaFehlberg78
|
|
56
|
+
|
|
57
|
+
RungeKuttaDopri5
|
|
58
|
+
"""
|
|
59
|
+
RungeKutta4: typing.ClassVar[NumericalSolver.StepperType] # value = <StepperType.RungeKutta4: 0>
|
|
60
|
+
RungeKuttaCashKarp54: typing.ClassVar[NumericalSolver.StepperType] # value = <StepperType.RungeKuttaCashKarp54: 1>
|
|
61
|
+
RungeKuttaDopri5: typing.ClassVar[NumericalSolver.StepperType] # value = <StepperType.RungeKuttaDopri5: 3>
|
|
62
|
+
RungeKuttaFehlberg78: typing.ClassVar[NumericalSolver.StepperType] # value = <StepperType.RungeKuttaFehlberg78: 2>
|
|
63
|
+
__members__: typing.ClassVar[dict[str, NumericalSolver.StepperType]] # value = {'RungeKutta4': <StepperType.RungeKutta4: 0>, 'RungeKuttaCashKarp54': <StepperType.RungeKuttaCashKarp54: 1>, 'RungeKuttaFehlberg78': <StepperType.RungeKuttaFehlberg78: 2>, 'RungeKuttaDopri5': <StepperType.RungeKuttaDopri5: 3>}
|
|
64
|
+
def __eq__(self, other: typing.Any) -> bool:
|
|
65
|
+
...
|
|
66
|
+
def __getstate__(self) -> int:
|
|
67
|
+
...
|
|
68
|
+
def __hash__(self) -> int:
|
|
69
|
+
...
|
|
70
|
+
def __index__(self) -> int:
|
|
71
|
+
...
|
|
72
|
+
def __init__(self, value: int) -> None:
|
|
73
|
+
...
|
|
74
|
+
def __int__(self) -> int:
|
|
75
|
+
...
|
|
76
|
+
def __ne__(self, other: typing.Any) -> bool:
|
|
77
|
+
...
|
|
78
|
+
def __repr__(self) -> str:
|
|
79
|
+
...
|
|
80
|
+
def __setstate__(self, state: int) -> None:
|
|
81
|
+
...
|
|
82
|
+
def __str__(self) -> str:
|
|
83
|
+
...
|
|
84
|
+
@property
|
|
85
|
+
def name(self) -> str:
|
|
86
|
+
...
|
|
87
|
+
@property
|
|
88
|
+
def value(self) -> int:
|
|
89
|
+
...
|
|
90
|
+
__hash__: typing.ClassVar[None] = None
|
|
91
|
+
@staticmethod
|
|
92
|
+
def default() -> NumericalSolver:
|
|
93
|
+
"""
|
|
94
|
+
Create a default numerical solver.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
NumericalSolver: A solver with default settings.
|
|
98
|
+
|
|
99
|
+
Example:
|
|
100
|
+
>>> solver = NumericalSolver.default()
|
|
101
|
+
>>> solver.is_defined() # True
|
|
102
|
+
"""
|
|
103
|
+
@staticmethod
|
|
104
|
+
def string_from_log_type(log_type: typing.Any) -> ostk.core.type.String:
|
|
105
|
+
"""
|
|
106
|
+
Get string representation of a log type.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
log_type (NumericalSolver.LogType): The log type.
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
str: String representation of the log type.
|
|
113
|
+
|
|
114
|
+
Example:
|
|
115
|
+
>>> NumericalSolver.string_from_log_type(NumericalSolver.LogType.NoLog)
|
|
116
|
+
"""
|
|
117
|
+
@staticmethod
|
|
118
|
+
def string_from_stepper_type(stepper_type: typing.Any) -> ostk.core.type.String:
|
|
119
|
+
"""
|
|
120
|
+
Get string representation of a stepper type.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
stepper_type (NumericalSolver.StepperType): The stepper type.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
str: String representation of the stepper type.
|
|
127
|
+
|
|
128
|
+
Example:
|
|
129
|
+
>>> NumericalSolver.string_from_stepper_type(NumericalSolver.StepperType.RungeKutta4)
|
|
130
|
+
"""
|
|
131
|
+
@staticmethod
|
|
132
|
+
def undefined() -> NumericalSolver:
|
|
133
|
+
"""
|
|
134
|
+
Create an undefined numerical solver.
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
NumericalSolver: An undefined solver.
|
|
138
|
+
|
|
139
|
+
Example:
|
|
140
|
+
>>> solver = NumericalSolver.undefined()
|
|
141
|
+
>>> solver.is_defined() # False
|
|
142
|
+
"""
|
|
143
|
+
def __eq__(self, arg0: NumericalSolver) -> bool:
|
|
144
|
+
...
|
|
145
|
+
def __init__(self, log_type: typing.Any, stepper_type: typing.Any, time_step: ostk.core.type.Real, relative_tolerance: ostk.core.type.Real, absolute_tolerance: ostk.core.type.Real) -> None:
|
|
146
|
+
"""
|
|
147
|
+
Create a numerical solver with specified parameters.
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
log_type (NumericalSolver.LogType): The logging type for the solver.
|
|
151
|
+
stepper_type (NumericalSolver.StepperType): The stepper algorithm to use.
|
|
152
|
+
time_step (float): The time step for integration.
|
|
153
|
+
relative_tolerance (float): The relative tolerance for adaptive steppers.
|
|
154
|
+
absolute_tolerance (float): The absolute tolerance for adaptive steppers.
|
|
155
|
+
|
|
156
|
+
Example:
|
|
157
|
+
>>> solver = NumericalSolver(
|
|
158
|
+
... NumericalSolver.LogType.NoLog,
|
|
159
|
+
... NumericalSolver.StepperType.RungeKutta4,
|
|
160
|
+
... 1.0, 1e-12, 1e-12
|
|
161
|
+
... )
|
|
162
|
+
"""
|
|
163
|
+
def __ne__(self, arg0: NumericalSolver) -> bool:
|
|
164
|
+
...
|
|
165
|
+
def __repr__(self) -> str:
|
|
166
|
+
...
|
|
167
|
+
def __str__(self) -> str:
|
|
168
|
+
...
|
|
169
|
+
def get_absolute_tolerance(self) -> ostk.core.type.Real:
|
|
170
|
+
"""
|
|
171
|
+
Get the absolute tolerance of the solver.
|
|
172
|
+
|
|
173
|
+
Returns:
|
|
174
|
+
float: The absolute tolerance value.
|
|
175
|
+
|
|
176
|
+
Example:
|
|
177
|
+
>>> solver = NumericalSolver.default()
|
|
178
|
+
>>> abs_tol = solver.get_absolute_tolerance()
|
|
179
|
+
"""
|
|
180
|
+
def get_log_type(self) -> ...:
|
|
181
|
+
"""
|
|
182
|
+
Get the log type of the solver.
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
NumericalSolver.LogType: The log type.
|
|
186
|
+
|
|
187
|
+
Example:
|
|
188
|
+
>>> solver = NumericalSolver.default()
|
|
189
|
+
>>> log_type = solver.get_log_type()
|
|
190
|
+
"""
|
|
191
|
+
def get_observed_state_vectors(self) -> list[tuple[numpy.ndarray[numpy.float64[m, 1]], float]]:
|
|
192
|
+
"""
|
|
193
|
+
Get the observed state vectors from the last integration.
|
|
194
|
+
|
|
195
|
+
Returns:
|
|
196
|
+
list: List of observed state vectors during integration.
|
|
197
|
+
|
|
198
|
+
Example:
|
|
199
|
+
>>> solver = NumericalSolver.default()
|
|
200
|
+
>>> # After performing integration...
|
|
201
|
+
>>> states = solver.get_observed_state_vectors()
|
|
202
|
+
"""
|
|
203
|
+
def get_relative_tolerance(self) -> ostk.core.type.Real:
|
|
204
|
+
"""
|
|
205
|
+
Get the relative tolerance of the solver.
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
float: The relative tolerance value.
|
|
209
|
+
|
|
210
|
+
Example:
|
|
211
|
+
>>> solver = NumericalSolver.default()
|
|
212
|
+
>>> rel_tol = solver.get_relative_tolerance()
|
|
213
|
+
"""
|
|
214
|
+
def get_stepper_type(self) -> ...:
|
|
215
|
+
"""
|
|
216
|
+
Get the stepper type of the solver.
|
|
217
|
+
|
|
218
|
+
Returns:
|
|
219
|
+
NumericalSolver.StepperType: The stepper type.
|
|
220
|
+
|
|
221
|
+
Example:
|
|
222
|
+
>>> solver = NumericalSolver.default()
|
|
223
|
+
>>> stepper_type = solver.get_stepper_type()
|
|
224
|
+
"""
|
|
225
|
+
def get_time_step(self) -> ostk.core.type.Real:
|
|
226
|
+
"""
|
|
227
|
+
Get the time step of the solver.
|
|
228
|
+
|
|
229
|
+
Returns:
|
|
230
|
+
float: The time step value.
|
|
231
|
+
|
|
232
|
+
Example:
|
|
233
|
+
>>> solver = NumericalSolver.default()
|
|
234
|
+
>>> time_step = solver.get_time_step()
|
|
235
|
+
"""
|
|
236
|
+
@typing.overload
|
|
237
|
+
def integrate_duration(self, arg0: numpy.ndarray[numpy.float64[m, 1]], arg1: ostk.core.type.Real, arg2: typing.Any) -> tuple[numpy.ndarray[numpy.float64[m, 1]], float]:
|
|
238
|
+
"""
|
|
239
|
+
Integrate a system of differential equations for a specified duration.
|
|
240
|
+
|
|
241
|
+
Args:
|
|
242
|
+
state_vector (StateVector): Initial state vector.
|
|
243
|
+
duration_in_seconds (float): Integration duration in seconds.
|
|
244
|
+
system_of_equations (callable): Function defining the system of ODEs.
|
|
245
|
+
Signature: f(x, dxdt, t) -> StateVector
|
|
246
|
+
|
|
247
|
+
Returns:
|
|
248
|
+
StateVector: Final state vector after integration.
|
|
249
|
+
|
|
250
|
+
Example:
|
|
251
|
+
>>> def equations(x, dxdt, t):
|
|
252
|
+
... dxdt[0] = x[1] # dx/dt = v
|
|
253
|
+
... dxdt[1] = -x[0] # dv/dt = -x (harmonic oscillator)
|
|
254
|
+
... return dxdt
|
|
255
|
+
>>> solver = NumericalSolver.default()
|
|
256
|
+
>>> initial_state = [1.0, 0.0] # x=1, v=0
|
|
257
|
+
>>> final_state = solver.integrate_duration(initial_state, 1.0, equations)
|
|
258
|
+
"""
|
|
259
|
+
@typing.overload
|
|
260
|
+
def integrate_duration(self, arg0: numpy.ndarray[numpy.float64[m, 1]], arg1: list[ostk.core.type.Real], arg2: typing.Any) -> list[tuple[numpy.ndarray[numpy.float64[m, 1]], float]]:
|
|
261
|
+
"""
|
|
262
|
+
Integrate a system of differential equations at multiple duration points.
|
|
263
|
+
|
|
264
|
+
Args:
|
|
265
|
+
state_vector (StateVector): Initial state vector.
|
|
266
|
+
duration_array (list): Array of duration values in seconds.
|
|
267
|
+
system_of_equations (callable): Function defining the system of ODEs.
|
|
268
|
+
Signature: f(x, dxdt, t) -> StateVector
|
|
269
|
+
|
|
270
|
+
Returns:
|
|
271
|
+
list: State vectors at each duration point.
|
|
272
|
+
|
|
273
|
+
Example:
|
|
274
|
+
>>> def equations(x, dxdt, t):
|
|
275
|
+
... dxdt[0] = x[1] # dx/dt = v
|
|
276
|
+
... dxdt[1] = -x[0] # dv/dt = -x (harmonic oscillator)
|
|
277
|
+
... return dxdt
|
|
278
|
+
>>> solver = NumericalSolver.default()
|
|
279
|
+
>>> initial_state = [1.0, 0.0]
|
|
280
|
+
>>> durations = [0.5, 1.0, 1.5]
|
|
281
|
+
>>> states = solver.integrate_duration(initial_state, durations, equations)
|
|
282
|
+
"""
|
|
283
|
+
@typing.overload
|
|
284
|
+
def integrate_time(self, arg0: numpy.ndarray[numpy.float64[m, 1]], arg1: ostk.core.type.Real, arg2: ostk.core.type.Real, arg3: typing.Any) -> tuple[numpy.ndarray[numpy.float64[m, 1]], float]:
|
|
285
|
+
"""
|
|
286
|
+
Integrate a system of differential equations from start to end time.
|
|
287
|
+
|
|
288
|
+
Args:
|
|
289
|
+
state_vector (StateVector): Initial state vector.
|
|
290
|
+
start_time (float): Integration start time.
|
|
291
|
+
end_time (float): Integration end time.
|
|
292
|
+
system_of_equations (callable): Function defining the system of ODEs.
|
|
293
|
+
Signature: f(x, dxdt, t) -> StateVector
|
|
294
|
+
|
|
295
|
+
Returns:
|
|
296
|
+
StateVector: Final state vector at end time.
|
|
297
|
+
|
|
298
|
+
Example:
|
|
299
|
+
>>> def equations(x, dxdt, t):
|
|
300
|
+
... dxdt[0] = x[1] # dx/dt = v
|
|
301
|
+
... dxdt[1] = -x[0] # dv/dt = -x (harmonic oscillator)
|
|
302
|
+
... return dxdt
|
|
303
|
+
>>> solver = NumericalSolver.default()
|
|
304
|
+
>>> initial_state = [1.0, 0.0]
|
|
305
|
+
>>> final_state = solver.integrate_time(initial_state, 0.0, 2.0, equations)
|
|
306
|
+
"""
|
|
307
|
+
@typing.overload
|
|
308
|
+
def integrate_time(self, arg0: numpy.ndarray[numpy.float64[m, 1]], arg1: ostk.core.type.Real, arg2: list[ostk.core.type.Real], arg3: typing.Any) -> list[tuple[numpy.ndarray[numpy.float64[m, 1]], float]]:
|
|
309
|
+
"""
|
|
310
|
+
Integrate a system of differential equations at specified time points.
|
|
311
|
+
|
|
312
|
+
Args:
|
|
313
|
+
state_vector (StateVector): Initial state vector.
|
|
314
|
+
start_time (float): Integration start time.
|
|
315
|
+
time_array (list): Array of time points to evaluate at.
|
|
316
|
+
system_of_equations (callable): Function defining the system of ODEs.
|
|
317
|
+
Signature: f(x, dxdt, t) -> StateVector
|
|
318
|
+
|
|
319
|
+
Returns:
|
|
320
|
+
list: State vectors at each time point.
|
|
321
|
+
|
|
322
|
+
Example:
|
|
323
|
+
>>> def equations(x, dxdt, t):
|
|
324
|
+
... dxdt[0] = x[1] # dx/dt = v
|
|
325
|
+
... dxdt[1] = -x[0] # dv/dt = -x (harmonic oscillator)
|
|
326
|
+
... return dxdt
|
|
327
|
+
>>> solver = NumericalSolver.default()
|
|
328
|
+
>>> initial_state = [1.0, 0.0]
|
|
329
|
+
>>> times = [0.5, 1.0, 1.5, 2.0]
|
|
330
|
+
>>> states = solver.integrate_time(initial_state, 0.0, times, equations)
|
|
331
|
+
"""
|
|
332
|
+
def is_defined(self) -> bool:
|
|
333
|
+
"""
|
|
334
|
+
Check if the numerical solver is defined.
|
|
335
|
+
|
|
336
|
+
Returns:
|
|
337
|
+
bool: True if the solver is defined, False otherwise.
|
|
338
|
+
|
|
339
|
+
Example:
|
|
340
|
+
>>> solver = NumericalSolver.default()
|
|
341
|
+
>>> solver.is_defined() # True
|
|
342
|
+
"""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from ostk.mathematics.curve_fitting import Interpolator
|
|
6
|
+
from ostk.mathematics.curve_fitting.interpolator import BarycentricRational
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.fixture
|
|
10
|
+
def interpolator() -> BarycentricRational:
|
|
11
|
+
return BarycentricRational(
|
|
12
|
+
x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0], y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0]
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TestBarycentricRational:
|
|
17
|
+
def test_constructor_success(self, interpolator: BarycentricRational):
|
|
18
|
+
assert interpolator is not None
|
|
19
|
+
assert isinstance(interpolator, Interpolator)
|
|
20
|
+
assert isinstance(interpolator, BarycentricRational)
|
|
21
|
+
|
|
22
|
+
def test_evaluate(self, interpolator: BarycentricRational):
|
|
23
|
+
|
|
24
|
+
assert interpolator.evaluate(0.0) == 0.0
|
|
25
|
+
assert interpolator.evaluate(1.0) == 3.0
|
|
26
|
+
assert interpolator.evaluate(2.0) == 6.0
|
|
27
|
+
assert interpolator.evaluate(4.0) == 9.0
|
|
28
|
+
assert interpolator.evaluate(5.0) == 17.0
|
|
29
|
+
assert interpolator.evaluate(6.0) == 5.0
|
|
30
|
+
|
|
31
|
+
assert (
|
|
32
|
+
interpolator.evaluate(x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0])
|
|
33
|
+
== [0.0, 3.0, 6.0, 9.0, 17.0, 5.0]
|
|
34
|
+
).all()
|
|
35
|
+
|
|
36
|
+
def test_compute_derivative(self):
|
|
37
|
+
interpolator = BarycentricRational(
|
|
38
|
+
x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0],
|
|
39
|
+
y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0],
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
assert interpolator.compute_derivative(1.5) is not None
|
|
43
|
+
|
|
44
|
+
assert interpolator.compute_derivative([1.5]) is not None
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from ostk.mathematics.curve_fitting import Interpolator
|
|
8
|
+
from ostk.mathematics.curve_fitting.interpolator import CubicSpline
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.fixture
|
|
12
|
+
def interpolator() -> CubicSpline:
|
|
13
|
+
return CubicSpline(
|
|
14
|
+
x=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0], y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0]
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TestCubicSpline:
|
|
19
|
+
def test_constructor_success(self, interpolator: CubicSpline):
|
|
20
|
+
assert interpolator is not None
|
|
21
|
+
assert isinstance(interpolator, Interpolator)
|
|
22
|
+
assert isinstance(interpolator, CubicSpline)
|
|
23
|
+
|
|
24
|
+
def test_default_constructor_2(self):
|
|
25
|
+
CubicSpline(y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0], x_0=0.0, h=1.0)
|
|
26
|
+
|
|
27
|
+
def test_evaluate(self):
|
|
28
|
+
y: list[float] = [
|
|
29
|
+
-4.632122947015880607e06,
|
|
30
|
+
-4.638362755234977230e06,
|
|
31
|
+
-4.644761115514834411e06,
|
|
32
|
+
-4.650595795951002277e06,
|
|
33
|
+
-4.655866062354639173e06,
|
|
34
|
+
-4.660571249500595033e06,
|
|
35
|
+
-4.664710761221675202e06,
|
|
36
|
+
-4.668284070493859239e06,
|
|
37
|
+
-4.671290719512360170e06,
|
|
38
|
+
-4.673730319758670405e06,
|
|
39
|
+
]
|
|
40
|
+
interpolator = CubicSpline(y, 0.0, 10.0)
|
|
41
|
+
|
|
42
|
+
for i in range(10):
|
|
43
|
+
assert pytest.approx(interpolator.evaluate(i * 10.0)) == y[i]
|
|
44
|
+
|
|
45
|
+
assert pytest.approx(interpolator.evaluate(np.linspace(0.0, 90.0, 10))) == y
|
|
46
|
+
|
|
47
|
+
def test_compute_derivative(self):
|
|
48
|
+
interpolator = CubicSpline(
|
|
49
|
+
x=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0],
|
|
50
|
+
y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
assert interpolator.compute_derivative(1.5) is not None
|
|
54
|
+
|
|
55
|
+
assert interpolator.compute_derivative([1.5]) is not None
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from ostk.mathematics.curve_fitting import Interpolator
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@pytest.fixture
|
|
9
|
+
def interpolation_type() -> Interpolator.Type:
|
|
10
|
+
return Interpolator.Type.Linear
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@pytest.fixture
|
|
14
|
+
def interpolator(interpolation_type: Interpolator.Type) -> Interpolator:
|
|
15
|
+
class MyInterpolator(Interpolator):
|
|
16
|
+
def evaluate(self, x: list[float]) -> list[float]:
|
|
17
|
+
return x
|
|
18
|
+
|
|
19
|
+
def evaluate(self, x: float) -> float:
|
|
20
|
+
return x
|
|
21
|
+
|
|
22
|
+
return MyInterpolator(interpolation_type=interpolation_type)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TestInterpolator:
|
|
26
|
+
def test_subclass(self, interpolator: Interpolator):
|
|
27
|
+
assert interpolator is not None
|
|
28
|
+
assert isinstance(interpolator, Interpolator)
|
|
29
|
+
|
|
30
|
+
def test_get_interpolation_type(
|
|
31
|
+
self,
|
|
32
|
+
interpolator: Interpolator,
|
|
33
|
+
interpolation_type: Interpolator.Type,
|
|
34
|
+
):
|
|
35
|
+
assert interpolator.get_interpolation_type() == interpolation_type
|
|
36
|
+
|
|
37
|
+
@pytest.mark.parametrize(
|
|
38
|
+
"parametrized_interpolation_type, x, y",
|
|
39
|
+
[
|
|
40
|
+
(
|
|
41
|
+
Interpolator.Type.BarycentricRational,
|
|
42
|
+
[0.0, 1.0, 2.0, 4.0, 5.0, 6.0],
|
|
43
|
+
[0.0, 3.0, 6.0, 9.0, 17.0, 5.0],
|
|
44
|
+
),
|
|
45
|
+
(
|
|
46
|
+
Interpolator.Type.CubicSpline,
|
|
47
|
+
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0],
|
|
48
|
+
[0.0, 3.0, 6.0, 9.0, 17.0, 5.0],
|
|
49
|
+
),
|
|
50
|
+
(
|
|
51
|
+
Interpolator.Type.Linear,
|
|
52
|
+
[0.0, 1.0, 2.0, 4.0, 5.0, 6.0],
|
|
53
|
+
[0.0, 3.0, 6.0, 9.0, 17.0, 5.0],
|
|
54
|
+
),
|
|
55
|
+
],
|
|
56
|
+
)
|
|
57
|
+
def test_generate_interpolators(
|
|
58
|
+
self,
|
|
59
|
+
parametrized_interpolation_type: Interpolator.Type,
|
|
60
|
+
x: list[float],
|
|
61
|
+
y: list[float],
|
|
62
|
+
):
|
|
63
|
+
interpolator: Interpolator = Interpolator.generate_interpolator(
|
|
64
|
+
interpolation_type=parametrized_interpolation_type,
|
|
65
|
+
x=x,
|
|
66
|
+
y=y,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
assert interpolator is not None
|
|
70
|
+
assert isinstance(interpolator, Interpolator)
|
|
71
|
+
assert interpolator.get_interpolation_type() == parametrized_interpolation_type
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from ostk.mathematics.curve_fitting import Interpolator
|
|
6
|
+
from ostk.mathematics.curve_fitting.interpolator import Linear
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.fixture
|
|
10
|
+
def interpolator() -> Linear:
|
|
11
|
+
return Linear(x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0], y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0])
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestLinear:
|
|
15
|
+
def test_constructor_success(self, interpolator: Linear):
|
|
16
|
+
assert interpolator is not None
|
|
17
|
+
assert isinstance(interpolator, Interpolator)
|
|
18
|
+
assert isinstance(interpolator, Linear)
|
|
19
|
+
|
|
20
|
+
def test_evaluate(self):
|
|
21
|
+
interpolator = Linear(
|
|
22
|
+
x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0], y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0]
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
assert interpolator.evaluate(0.0) == 0.0
|
|
26
|
+
assert interpolator.evaluate(1.0) == 3.0
|
|
27
|
+
assert interpolator.evaluate(2.0) == 6.0
|
|
28
|
+
assert interpolator.evaluate(4.0) == 9.0
|
|
29
|
+
assert interpolator.evaluate(5.0) == 17.0
|
|
30
|
+
assert interpolator.evaluate(6.0) == 5.0
|
|
31
|
+
|
|
32
|
+
assert (
|
|
33
|
+
interpolator.evaluate(x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0])
|
|
34
|
+
== [0.0, 3.0, 6.0, 9.0, 17.0, 5.0]
|
|
35
|
+
).all()
|
|
36
|
+
|
|
37
|
+
def test_compute_derivative(self):
|
|
38
|
+
interpolator = Linear(
|
|
39
|
+
x=[0.0, 1.0, 2.0, 4.0, 5.0, 6.0],
|
|
40
|
+
y=[0.0, 3.0, 6.0, 9.0, 17.0, 5.0],
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
assert interpolator.compute_derivative(1.5) is not None
|
|
44
|
+
|
|
45
|
+
assert interpolator.compute_derivative([1.5]) is not None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from ostk.mathematics.geometry.d2.object import Point
|
|
8
|
+
from ostk.mathematics.geometry.d2.object import PointSet
|
|
9
|
+
from ostk.mathematics.geometry.d2.object import Line
|
|
10
|
+
from ostk.mathematics.geometry.d2.object import Segment
|
|
11
|
+
from ostk.mathematics.geometry.d2.object import Polygon
|
|
12
|
+
from ostk.mathematics.geometry.d2.object import Composite
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@pytest.fixture
|
|
16
|
+
def point() -> Point:
|
|
17
|
+
return Point(-2.0, 5.0)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@pytest.fixture
|
|
21
|
+
def point_set() -> PointSet:
|
|
22
|
+
return PointSet([Point(1.0, 2.0), Point(2.0, 3.0)])
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest.fixture
|
|
26
|
+
def line() -> Line:
|
|
27
|
+
return Line(Point(1.0, 2.0), np.array((1.0, 1.0)))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.fixture
|
|
31
|
+
def segment() -> Segment:
|
|
32
|
+
return Segment(Point(0.0, 0.0), Point(0.0, 2.0))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.fixture
|
|
36
|
+
def polygon() -> Polygon:
|
|
37
|
+
point_1: Point = Point(-1.0, 1.0)
|
|
38
|
+
point_2: Point = Point(1.0, 1.0)
|
|
39
|
+
point_3: Point = Point(1.0, -1.0)
|
|
40
|
+
point_4: Point = Point(-1.0, -1.0)
|
|
41
|
+
|
|
42
|
+
return Polygon([point_1, point_2, point_3, point_4])
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def square(center: Point) -> Polygon:
|
|
46
|
+
point_1: Point = center + [0.5, 0.5]
|
|
47
|
+
point_2: Point = center + [0.5, -0.5]
|
|
48
|
+
point_3: Point = center + [-0.5, -0.5]
|
|
49
|
+
point_4: Point = center + [-0.5, 0.5]
|
|
50
|
+
|
|
51
|
+
return Polygon([point_1, point_2, point_3, point_4])
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@pytest.fixture
|
|
55
|
+
def square_1() -> Polygon:
|
|
56
|
+
return square(Point(0.0, 0.0))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@pytest.fixture
|
|
60
|
+
def square_2() -> Polygon:
|
|
61
|
+
return square(Point(0.0, 10.0))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@pytest.fixture
|
|
65
|
+
def square_3() -> Polygon:
|
|
66
|
+
return square(Point(0.5, 0.0))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@pytest.fixture
|
|
70
|
+
def square_4() -> Polygon:
|
|
71
|
+
return square(Point(1.0, 0.0))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@pytest.fixture
|
|
75
|
+
def composite(polygon: Polygon, point: Point) -> Composite:
|
|
76
|
+
composite = Composite(polygon)
|
|
77
|
+
composite += Composite(point)
|
|
78
|
+
|
|
79
|
+
return composite
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Apache License 2.0
|