-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit test for SimpleArray
#445
Conversation
Please review the CI failures. And please make sure all tests are clean before filing a PR. |
@ThreeMonth03 The profiler test is not stable. When running it locally I can feel its slowness too. Those are 2 issues. Could you please help take a look at the first and we find time to discuss for the second. GHA log https://github.com/solvcon/modmesh/actions/runs/12493102514/job/34861154319?pr=445#step:10:348 :
|
tests/test_simplearray.py
Outdated
@@ -0,0 +1,20 @@ | |||
from modmesh import SimpleArrayUint64, SimpleArrayFloat64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will prefer to put the code at test_buffer.py
, where we put all other array tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I concur. Do not add a new test file for this simple test.
@yungyuc @tigercosmos thanks for the suggestion, I'll inform you after I review and refine the code. |
99456c2
to
2d83fd3
Compare
@yungyuc I've moved the test into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also test using the original testing code in issue #437:
import unittest
from modmesh import SimpleArrayUint64, SimpleArrayFloat64
import numpy as np
class TimeBuffer(unittest.TestCase):
a = np.ndarray(shape= (5,5,5,5), dtype=float)
for i in range(5):
for j in range(5):
for k in range(5):
for l in range(5):
a[i,j,k,l] = i*1000 + j*100 + k*10 + l
b_copy = SimpleArrayFloat64(array=a)
print(b_copy.ndarray)
Also address the following:
tests/test_buffer.py
Outdated
@@ -436,6 +437,11 @@ def test_SimpleArray_from_ndarray(self): | |||
sarr_from_cpp = modmesh.SimpleArrayFloat64(shape=(2, 3, 4)) | |||
self.assertFalse(sarr_from_cpp.is_from_python) | |||
|
|||
shape = (2, 2, 2, 2) | |||
np_sarr = np.ndarray(shape=shape, dtype=np.float64) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use string for the argument dtype
, i.e., write dtype='float64'
. modmesh uses a convention to use string for numpy dtype
argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I'll fix it
tests/test_buffer.py
Outdated
@@ -436,6 +437,11 @@ def test_SimpleArray_from_ndarray(self): | |||
sarr_from_cpp = modmesh.SimpleArrayFloat64(shape=(2, 3, 4)) | |||
self.assertFalse(sarr_from_cpp.is_from_python) | |||
|
|||
shape = (2, 2, 2, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please also test with the shape in which each element different from others? (2, 2, 2, 2)
is too simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, I'll make it to (2, 3, 5, 7).
Here, I'm somehow curious about how to measure how "interesting" the shape is. I don't really know how to make the number reasonable but still effective as a test case. For example, (111, 222, 333, 444) might be an unreasonable test case due to its huge memory consumption.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(2, 3, 5, 7)
looks sufficiently interesting.
Please leave a global comment every time when you are ready for requesting the next review. |
@yungyuc Oh, thanks for reminding. Now is ready for next review! |
0c95076
to
e3a4812
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I make some tweaks and rebase to the latest master
.
tests/test_buffer.py
Outdated
@@ -436,6 +437,22 @@ def test_SimpleArray_from_ndarray(self): | |||
sarr_from_cpp = modmesh.SimpleArrayFloat64(shape=(2, 3, 4)) | |||
self.assertFalse(sarr_from_cpp.is_from_python) | |||
|
|||
shape = (2, 3, 5, 7) | |||
np_sarr = np.array(shape=shape, dtype='float64') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use np.array
instead of np.ndarray
. The latter is not a numpy coding convention. We do not usually directly call the ndarray
constructor. Instead, we use the helpers array
, empty
, ones
, zeros
, full
, etc.
e3a4812
to
ea79063
Compare
ea79063
to
6962dcf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The testing code looks good. I squashed all changes to prepare for merging.
This is a follow up of PR #444 that test the constructor of
SimpleArray
.