-
Notifications
You must be signed in to change notification settings - Fork 69
Add element stride calculation and alignment methods #1406
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
Open
cyrush
wants to merge
5
commits into
develop
Choose a base branch
from
add-element-stride-methods
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
42cbe0b
Add element stride calculation and alignment methods
cyrush 312d1d0
Update CHANGELOG.md with element stride methods
cyrush e73e463
Added element stride methods to Python API
cyrush e675449
Added element stride methods to C API
cyrush 170de44
Added element stride methods to Fortran API
cyrush File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -144,6 +144,14 @@ subroutine t_node_datatype_ids | |||||
| call assert_true( conduit_datatype_element_bytes(dataType) == 8) | ||||||
| call assert_true( conduit_datatype_stride(dataType) == 8) | ||||||
| call assert_true( conduit_datatype_offset(dataType) == 0) | ||||||
|
|
||||||
| ! Test the new element stride methods | ||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| call assert_true( conduit_datatype_element_stride(dataType) == 1) ! 8/8 = 1 | ||||||
| call assert_true( c_conduit_datatype_is_stride_element_aligned(dataType) == 1) ! 8 % 8 = 0 | ||||||
| call assert_true( c_conduit_datatype_is_stride_aligned(dataType, 8) == 1) ! 8 % 8 = 0 | ||||||
| call assert_true( c_conduit_datatype_is_stride_aligned(dataType, 4) == 1) ! 8 % 4 = 0 | ||||||
| call assert_true( c_conduit_datatype_is_stride_aligned(dataType, 2) == 1) ! 8 % 2 = 0 | ||||||
|
|
||||||
| call assert_true( c_conduit_datatype_is_number(dataType) == 1) | ||||||
| call assert_true( c_conduit_datatype_is_integer(dataType) == 0) | ||||||
| call assert_true( c_conduit_datatype_is_signed_integer(dataType) == 0) | ||||||
|
|
||||||
This file contains hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -257,7 +257,57 @@ def test_to_string_and_friends(self): | |||||
| self.assertEqual(d.to_string("yaml"),d.to_yaml()) | ||||||
| self.assertEqual(d.to_string("json"),d.to_json()) | ||||||
|
|
||||||
|
|
||||||
| def test_stride_methods(self): | ||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| # Regular and aligned stride case | ||||||
| dt = DataType() | ||||||
| dt.set(dtype_id = DataType.name_to_id("uint32"), | ||||||
| num_elements = 10, | ||||||
| offset = 0, | ||||||
| stride = 8, | ||||||
| element_bytes = 4) | ||||||
|
|
||||||
| # Element stride should be stride / element_bytes (8 / 4 = 2) | ||||||
| self.assertEqual(dt.element_stride(), 2) | ||||||
| # Stride is aligned with element boundaries (8 % 4 = 0) | ||||||
| self.assertTrue(dt.is_stride_element_aligned()) | ||||||
| # Stride is aligned with 2-byte boundary (8 % 2 = 0) | ||||||
| self.assertTrue(dt.is_stride_aligned(2)) | ||||||
| # Stride is aligned with 4-byte boundary (8 % 4 = 0) | ||||||
| self.assertTrue(dt.is_stride_aligned(4)) | ||||||
| # Stride is not aligned with 3-byte boundary (8 % 3 != 0) | ||||||
| self.assertFalse(dt.is_stride_aligned(3)) | ||||||
|
|
||||||
| # Non-aligned stride case | ||||||
| dt.set_stride(6) | ||||||
| # Element stride should be integer division (6 / 4 = 1) | ||||||
| self.assertEqual(dt.element_stride(), 1) | ||||||
| # Stride is not aligned with element boundaries (6 % 4 != 0) | ||||||
| self.assertFalse(dt.is_stride_element_aligned()) | ||||||
| # Stride is aligned with 2-byte boundary (6 % 2 = 0) | ||||||
| self.assertTrue(dt.is_stride_aligned(2)) | ||||||
| # Stride is aligned with 3-byte boundary (6 % 3 = 0) | ||||||
| self.assertTrue(dt.is_stride_aligned(3)) | ||||||
| # Stride is not aligned with 4-byte boundary (6 % 4 != 0) | ||||||
| self.assertFalse(dt.is_stride_aligned(4)) | ||||||
|
|
||||||
| # Special case - zero stride | ||||||
| dt.set_stride(0) | ||||||
| # Element stride should be 0 for zero stride (0 / 4 = 0) | ||||||
| self.assertEqual(dt.element_stride(), 0) | ||||||
| # Zero stride is considered element aligned | ||||||
| self.assertTrue(dt.is_stride_element_aligned()) | ||||||
| # Zero stride is aligned with any byte boundary | ||||||
| self.assertTrue(dt.is_stride_aligned(4)) | ||||||
| self.assertTrue(dt.is_stride_aligned(3)) | ||||||
| self.assertTrue(dt.is_stride_aligned(2)) | ||||||
|
|
||||||
| # Special case - zero element_bytes | ||||||
| dt.set_stride(8) | ||||||
| dt.set_element_bytes(0) | ||||||
| # Element stride is currently defined to return 0 for zero element_bytes case | ||||||
| self.assertEqual(dt.element_stride(), 0) | ||||||
| # Element alignment is currently defined to return true for zero element_bytes | ||||||
| self.assertTrue(dt.is_stride_element_aligned()) | ||||||
|
|
||||||
|
|
||||||
| if __name__ == '__main__': | ||||||
|
|
||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
intreturn is consistent with other c api functions that provide boolean answers