Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pymatlib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rahil Doshi
pymatlib
Commits
4ae24f12
Commit
4ae24f12
authored
5 months ago
by
Rahil Doshi
Browse files
Options
Downloads
Patches
Plain Diff
Update interpolation tests
parent
0e12b296
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pymatlib/core/cpp/test_interpolation.cpp
+6
-6
6 additions, 6 deletions
src/pymatlib/core/cpp/test_interpolation.cpp
src/pymatlib/core/cpp/test_interpolation.py
+5
-5
5 additions, 5 deletions
src/pymatlib/core/cpp/test_interpolation.py
with
11 additions
and
11 deletions
src/pymatlib/core/cpp/test_interpolation.cpp
+
6
−
6
View file @
4ae24f12
#include
"
temperature_from_energy_density_array
_cpp.h"
#include
"
interpolate_binary_search
_cpp.h"
#include
<vector>
#include
<array>
#include
<iostream>
...
...
@@ -13,7 +13,7 @@ void run_cpp_tests() {
try
{
// Test normal interpolation
double
h_in
=
1.695e10
;
double
result
=
temperature_from_energy_density_array
_cpp
(
double
result
=
interpolate_binary_search
_cpp
(
temperatures
,
h_in
,
energy_densities
);
std
::
cout
<<
"Vector test temperature: "
<<
result
<<
std
::
endl
;
assert
(
result
>
3243.15
&&
result
<
3273.15
);
...
...
@@ -21,23 +21,23 @@ void run_cpp_tests() {
// Test with std::array
std
::
array
<
double
,
4
>
temp_arr
=
{
3273.15
,
3263.15
,
3253.15
,
3243.15
};
std
::
array
<
double
,
4
>
energy_arr
=
{
1.71e10
,
1.70e10
,
1.69e10
,
1.68e10
};
result
=
temperature_from_energy_density_array
_cpp
(
temp_arr
,
h_in
,
energy_arr
);
result
=
interpolate_binary_search
_cpp
(
temp_arr
,
h_in
,
energy_arr
);
std
::
cout
<<
"Array test temperature: "
<<
result
<<
std
::
endl
;
assert
(
result
>
3243.15
&&
result
<
3273.15
);
// Test boundary values
result
=
temperature_from_energy_density_array
_cpp
(
result
=
interpolate_binary_search
_cpp
(
temperatures
,
1.67e10
,
energy_densities
);
assert
(
std
::
abs
(
result
-
3243.15
)
<
1e-6
);
result
=
temperature_from_energy_density_array
_cpp
(
result
=
interpolate_binary_search
_cpp
(
temperatures
,
1.72e10
,
energy_densities
);
assert
(
std
::
abs
(
result
-
3273.15
)
<
1e-6
);
// Test error cases
std
::
vector
<
double
>
wrong_size
=
{
1.0
,
2.0
};
try
{
temperature_from_energy_density_array
_cpp
(
temperatures
,
h_in
,
wrong_size
);
interpolate_binary_search
_cpp
(
temperatures
,
h_in
,
wrong_size
);
std
::
cerr
<<
"Expected size mismatch error"
<<
std
::
endl
;
assert
(
false
);
}
catch
(
const
std
::
runtime_error
&
)
{
...
...
This diff is collapsed.
Click to expand it.
src/pymatlib/core/cpp/test_interpolation.py
+
5
−
5
View file @
4ae24f12
import
numpy
as
np
import
pytest
from
pymatlib.core.cpp.fast_interpolation
import
temperature_from_energy_density_array
from
pymatlib.core.cpp.fast_interpolation
import
interpolate_binary_search
def
test_numpy_implementation
():
# Test data
...
...
@@ -9,21 +9,21 @@ def test_numpy_implementation():
h_in
=
1.695e10
# Test normal interpolation
result
=
temperature_from_energy_density_array
(
temperatures
,
h_in
,
energy_densities
)
result
=
interpolate_binary_search
(
temperatures
,
h_in
,
energy_densities
)
assert
3243.15
<
result
<
3273.15
print
(
f
"
NumPy test temperature:
{
result
}
"
)
# Test boundary values
result_min
=
temperature_from_energy_density_array
(
temperatures
,
1.67e10
,
energy_densities
)
result_min
=
interpolate_binary_search
(
temperatures
,
1.67e10
,
energy_densities
)
assert
abs
(
result_min
-
3243.15
)
<
1e-6
result_max
=
temperature_from_energy_density_array
(
temperatures
,
1.72e10
,
energy_densities
)
result_max
=
interpolate_binary_search
(
temperatures
,
1.72e10
,
energy_densities
)
assert
abs
(
result_max
-
3273.15
)
<
1e-6
# Test error cases
with
pytest
.
raises
(
RuntimeError
):
wrong_size
=
np
.
array
([
1.0
,
2.0
])
temperature_from_energy_density_array
(
temperatures
,
h_in
,
wrong_size
)
interpolate_binary_search
(
temperatures
,
h_in
,
wrong_size
)
if
__name__
==
"
__main__
"
:
test_numpy_implementation
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment