Skip to content

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
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

cyrush
Copy link
Member

@cyrush cyrush commented Mar 27, 2025

This change adds three new methods to the DataType class that help with element-based stride calculations and alignment checks:

  1. element_stride(): Returns stride in elements instead of bytes
  2. is_stride_element_aligned(): Tests if stride is aligned with element boundaries
  3. is_stride_aligned(nbytes): Tests if stride is a multiple of given bytes

Fixes issue #1207

🤖 Generated with Claude Code

This change adds three new methods to the DataType class that help with
element-based stride calculations and alignment checks:

1. element_stride(): Returns stride in elements instead of bytes
2. is_stride_element_aligned(): Tests if stride is aligned with element boundaries
3. is_stride_aligned(nbytes): Tests if stride is a multiple of given bytes

Fixes issue #1207

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
dt.set(DataType::FLOAT64_ID,
10, // 10 elements
0, // 0 offset
sizeof(float64)*2, // stride = 16 bytes (2 elements)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments here are wrong

cyrush and others added 4 commits March 27, 2025 17:36
Added Python bindings and tests for:
- element_stride()
- is_stride_element_aligned()
- is_stride_aligned()

Part of #1207

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added C bindings and tests for:
- element_stride()
- is_stride_element_aligned()
- is_stride_aligned()

Part of #1207

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added Fortran bindings and tests for:
- element_stride()
- is_stride_element_aligned()
- is_stride_aligned()

Part of #1207

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
! Test the new element stride methods
! Test the element stride methods

@@ -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):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_stride_methods(self):
def test_element_stride_methods(self):

return cpp_datatype_ref(cdatatype).is_stride_element_aligned() ? 1 : 0;
}

int conduit_datatype_is_stride_aligned(const conduit_datatype *cdatatype, conduit_index_t nbytes)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int return is consistent with other c api functions that provide boolean answers

@cyrush
Copy link
Member Author

cyrush commented Mar 28, 2025

2025-03-27T19:48:52.5528270Z 64: ======================================================================
2025-03-27T19:48:52.5529091Z 64: FAIL: test_stride_methods (t_python_conduit_datatype.Test_Conduit_Node)
2025-03-27T19:48:52.5530669Z 64: ----------------------------------------------------------------------
2025-03-27T19:48:52.5531475Z 64: Traceback (most recent call last):
2025-03-27T19:48:52.5532186Z 64:   File "/__w/1/s/src/tests/conduit/python/t_python_conduit_datatype.py", line 310, in test_stride_methods
2025-03-27T19:48:52.5532520Z 64:     self.assertTrue(dt.is_stride_element_aligned())
2025-03-27T19:48:52.5532967Z 64: AssertionError: False is not true

@rhornung67
Copy link
Member

Give the state of the world today, False and True seem to be interchangeable. 😞

@cyrush
Copy link
Member Author

cyrush commented Mar 28, 2025

Give the state of the world today, False and True seem to be interchangeable. 😞

I want to respond with True, but maybe I should use False? Or -- I agree .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants