From 340c295f18e7b0c990bfc36b38e4987f59b83a51 Mon Sep 17 00:00:00 2001 From: Benjamin Reese Date: Mon, 30 Sep 2024 13:02:15 -0700 Subject: [PATCH 01/11] Update numpy set functions to be stride aware --- src/rogue/interfaces/memory/Block.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/rogue/interfaces/memory/Block.cpp b/src/rogue/interfaces/memory/Block.cpp index 2c81292ea..7474b9f52 100644 --- a/src/rogue/interfaces/memory/Block.cpp +++ b/src/rogue/interfaces/memory/Block.cpp @@ -903,6 +903,7 @@ void rim::Block::setUIntPy(bp::object& value, rim::Variable* var, int32_t index) PyArrayObject* arr = reinterpret_cast(value.ptr()); npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); + npy_intp* strides = PyArray_STRIDES(arr); if (ndims != 1) throw(rogue::GeneralError::create("Block::setUIntPy", @@ -921,10 +922,18 @@ void rim::Block::setUIntPy(bp::object& value, rim::Variable* var, int32_t index) if (PyArray_TYPE(arr) == NPY_UINT64) { uint64_t* src = reinterpret_cast(PyArray_DATA(arr)); - for (x = 0; x < dims[0]; x++) setUInt(src[x], var, index + x); + uint64_t value = 0; + for (x = 0; x < dims[0]; x++) { + value = &(src + x * strides[0]); + setUInt(value, var, index + x); + } } else if (PyArray_TYPE(arr) == NPY_UINT32) { uint32_t* src = reinterpret_cast(PyArray_DATA(arr)); - for (x = 0; x < dims[0]; x++) setUInt(src[x], var, index + x); + uint32_t vlaue = 0; + for (x = 0; x < dims[0]; x++) { + value = &(src + x * strides[0]); + setUInt(value, var, index + x); + } } else { throw(rogue::GeneralError::create("Block::setUIntPy", "Passed nparray is not of type (uint64 or uint32) for %s", From ca8b0a1159f2baa5375d5a68001c1594ccb0ccb0 Mon Sep 17 00:00:00 2001 From: Benjamin Reese Date: Mon, 30 Sep 2024 13:35:12 -0700 Subject: [PATCH 02/11] Fix all of the set calls --- src/rogue/interfaces/memory/Block.cpp | 53 +++++++++++++++++++++------ 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/src/rogue/interfaces/memory/Block.cpp b/src/rogue/interfaces/memory/Block.cpp index 7474b9f52..c9c697be3 100644 --- a/src/rogue/interfaces/memory/Block.cpp +++ b/src/rogue/interfaces/memory/Block.cpp @@ -922,17 +922,17 @@ void rim::Block::setUIntPy(bp::object& value, rim::Variable* var, int32_t index) if (PyArray_TYPE(arr) == NPY_UINT64) { uint64_t* src = reinterpret_cast(PyArray_DATA(arr)); - uint64_t value = 0; + uint64_t* value = src; for (x = 0; x < dims[0]; x++) { - value = &(src + x * strides[0]); - setUInt(value, var, index + x); + value = src + x * strides[0]; + setUInt(*value, var, index + x); } } else if (PyArray_TYPE(arr) == NPY_UINT32) { uint32_t* src = reinterpret_cast(PyArray_DATA(arr)); - uint32_t vlaue = 0; + uint32_t* value = src; for (x = 0; x < dims[0]; x++) { - value = &(src + x * strides[0]); - setUInt(value, var, index + x); + value = src + x * strides[0]; + setUInt(*value, var, index + x); } } else { throw(rogue::GeneralError::create("Block::setUIntPy", @@ -1070,6 +1070,7 @@ void rim::Block::setIntPy(bp::object& value, rim::Variable* var, int32_t index) PyArrayObject* arr = reinterpret_cast(value.ptr()); npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); + npy_intp* strides = PyArray_STRIDES(arr); if (ndims != 1) throw(rogue::GeneralError::create("Block::setIntPy", @@ -1088,10 +1089,18 @@ void rim::Block::setIntPy(bp::object& value, rim::Variable* var, int32_t index) if (PyArray_TYPE(arr) == NPY_INT64) { int64_t* src = reinterpret_cast(PyArray_DATA(arr)); - for (x = 0; x < dims[0]; x++) setInt(src[x], var, index + x); + int64_t* value = src; + for (x = 0; x < dims[0]; x++) { + value = src + x * strides[0]; + setInt(*value, var, index + x); + } } else if (PyArray_TYPE(arr) == NPY_INT32) { int32_t* src = reinterpret_cast(PyArray_DATA(arr)); - for (x = 0; x < dims[0]; x++) setInt(src[x], var, index + x); + int32_t* value = src; + for (x = 0; x < dims[0]; x++) { + value = src + x * strides[0]; + setInt(*value, var, index + x); + } } else { throw(rogue::GeneralError::create("Block::setIntPy", "Passed nparray is not of type (int64 or int32) for %s", @@ -1232,6 +1241,7 @@ void rim::Block::setBoolPy(bp::object& value, rim::Variable* var, int32_t index) PyArrayObject* arr = reinterpret_cast(value.ptr()); npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); + npy_intp* strides = PyArray_STRIDES(arr); if (ndims != 1) throw(rogue::GeneralError::create("Block::setBoolPy", @@ -1250,7 +1260,11 @@ void rim::Block::setBoolPy(bp::object& value, rim::Variable* var, int32_t index) if (PyArray_TYPE(arr) == NPY_BOOL) { bool* src = reinterpret_cast(PyArray_DATA(arr)); - for (x = 0; x < dims[0]; x++) setBool(src[x], var, index + x); + bool* value = src; + for (x = 0; x < dims[0]; x++) { + value = src + x * strides[0]; + setBool(*value, var, index + x); + } } else { throw(rogue::GeneralError::create("Block::setBoolPy", "Passed nparray is not of type (bool) for %s", @@ -1440,6 +1454,7 @@ void rim::Block::setFloatPy(bp::object& value, rim::Variable* var, int32_t index PyArrayObject* arr = reinterpret_cast(value.ptr()); npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); + npy_intp* strides = PyArray_STRIDES(arr); if (ndims != 1) throw(rogue::GeneralError::create("Block::setFloatPy", @@ -1458,7 +1473,11 @@ void rim::Block::setFloatPy(bp::object& value, rim::Variable* var, int32_t index if (PyArray_TYPE(arr) == NPY_FLOAT32) { float* src = reinterpret_cast(PyArray_DATA(arr)); - for (x = 0; x < dims[0]; x++) setFloat(src[x], var, index + x); + float* value = src; + for (x = 0; x < dims[0]; x++) { + value = src + x * strides[0]; + setFloat(*value, var, index + x); + } } else { throw(rogue::GeneralError::create("Block::setFLoatPy", "Passed nparray is not of type (float32) for %s", @@ -1585,6 +1604,7 @@ void rim::Block::setDoublePy(bp::object& value, rim::Variable* var, int32_t inde PyArrayObject* arr = reinterpret_cast(value.ptr()); npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); + npy_intp* strides = PyArray_STRIDES(arr); if (ndims != 1) throw(rogue::GeneralError::create("Block::setDoublePy", @@ -1603,7 +1623,11 @@ void rim::Block::setDoublePy(bp::object& value, rim::Variable* var, int32_t inde if (PyArray_TYPE(arr) == NPY_FLOAT64) { double* src = reinterpret_cast(PyArray_DATA(arr)); - for (x = 0; x < dims[0]; x++) setDouble(src[x], var, index + x); + double* value = src; + for (x = 0; x < dims[0]; x++) { + value = src + x * strides[0]; + setDouble(*value, var, index + x); + } } else { throw(rogue::GeneralError::create("Block::setFLoatPy", "Passed nparray is not of type (double) for %s", @@ -1730,6 +1754,7 @@ void rim::Block::setFixedPy(bp::object& value, rim::Variable* var, int32_t index PyArrayObject* arr = reinterpret_cast(value.ptr()); npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); + npy_intp* strides = PyArray_STRIDES(arr); if (ndims != 1) throw(rogue::GeneralError::create("Block::setFixedPy", @@ -1748,7 +1773,11 @@ void rim::Block::setFixedPy(bp::object& value, rim::Variable* var, int32_t index if (PyArray_TYPE(arr) == NPY_FLOAT64) { double* src = reinterpret_cast(PyArray_DATA(arr)); - for (x = 0; x < dims[0]; x++) setFixed(src[x], var, index + x); + double* value = src; + for (x = 0; x < dims[0]; x++) { + value = src + x * strides[0]; + setFixed(*value, var, index + x); + } } else { throw(rogue::GeneralError::create("Block::setFixedPy", "Passed nparray is not of type (double) for %s", From a9bee4931d761ba7c1fec360032f7ce74e9a4c47 Mon Sep 17 00:00:00 2001 From: Benjamin Reese Date: Mon, 30 Sep 2024 13:37:27 -0700 Subject: [PATCH 03/11] Whitespace --- src/rogue/interfaces/memory/Block.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/rogue/interfaces/memory/Block.cpp b/src/rogue/interfaces/memory/Block.cpp index c9c697be3..55bf142bc 100644 --- a/src/rogue/interfaces/memory/Block.cpp +++ b/src/rogue/interfaces/memory/Block.cpp @@ -1070,7 +1070,7 @@ void rim::Block::setIntPy(bp::object& value, rim::Variable* var, int32_t index) PyArrayObject* arr = reinterpret_cast(value.ptr()); npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); - npy_intp* strides = PyArray_STRIDES(arr); + npy_intp* strides = PyArray_STRIDES(arr); if (ndims != 1) throw(rogue::GeneralError::create("Block::setIntPy", @@ -1241,7 +1241,7 @@ void rim::Block::setBoolPy(bp::object& value, rim::Variable* var, int32_t index) PyArrayObject* arr = reinterpret_cast(value.ptr()); npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); - npy_intp* strides = PyArray_STRIDES(arr); + npy_intp* strides = PyArray_STRIDES(arr); if (ndims != 1) throw(rogue::GeneralError::create("Block::setBoolPy", @@ -1264,7 +1264,7 @@ void rim::Block::setBoolPy(bp::object& value, rim::Variable* var, int32_t index) for (x = 0; x < dims[0]; x++) { value = src + x * strides[0]; setBool(*value, var, index + x); - } + } } else { throw(rogue::GeneralError::create("Block::setBoolPy", "Passed nparray is not of type (bool) for %s", @@ -1454,7 +1454,7 @@ void rim::Block::setFloatPy(bp::object& value, rim::Variable* var, int32_t index PyArrayObject* arr = reinterpret_cast(value.ptr()); npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); - npy_intp* strides = PyArray_STRIDES(arr); + npy_intp* strides = PyArray_STRIDES(arr); if (ndims != 1) throw(rogue::GeneralError::create("Block::setFloatPy", @@ -1477,7 +1477,7 @@ void rim::Block::setFloatPy(bp::object& value, rim::Variable* var, int32_t index for (x = 0; x < dims[0]; x++) { value = src + x * strides[0]; setFloat(*value, var, index + x); - } + } } else { throw(rogue::GeneralError::create("Block::setFLoatPy", "Passed nparray is not of type (float32) for %s", @@ -1627,7 +1627,7 @@ void rim::Block::setDoublePy(bp::object& value, rim::Variable* var, int32_t inde for (x = 0; x < dims[0]; x++) { value = src + x * strides[0]; setDouble(*value, var, index + x); - } + } } else { throw(rogue::GeneralError::create("Block::setFLoatPy", "Passed nparray is not of type (double) for %s", @@ -1754,7 +1754,7 @@ void rim::Block::setFixedPy(bp::object& value, rim::Variable* var, int32_t index PyArrayObject* arr = reinterpret_cast(value.ptr()); npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); - npy_intp* strides = PyArray_STRIDES(arr); + npy_intp* strides = PyArray_STRIDES(arr); if (ndims != 1) throw(rogue::GeneralError::create("Block::setFixedPy", @@ -1777,7 +1777,7 @@ void rim::Block::setFixedPy(bp::object& value, rim::Variable* var, int32_t index for (x = 0; x < dims[0]; x++) { value = src + x * strides[0]; setFixed(*value, var, index + x); - } + } } else { throw(rogue::GeneralError::create("Block::setFixedPy", "Passed nparray is not of type (double) for %s", From e9a1c3b2e8f84b608644fe716d37c87b124edda1 Mon Sep 17 00:00:00 2001 From: Benjamin Reese Date: Mon, 30 Sep 2024 13:50:36 -0700 Subject: [PATCH 04/11] Fix pointer math --- src/rogue/interfaces/memory/Block.cpp | 41 +++++++++++---------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/rogue/interfaces/memory/Block.cpp b/src/rogue/interfaces/memory/Block.cpp index 55bf142bc..4a8e939d8 100644 --- a/src/rogue/interfaces/memory/Block.cpp +++ b/src/rogue/interfaces/memory/Block.cpp @@ -904,6 +904,7 @@ void rim::Block::setUIntPy(bp::object& value, rim::Variable* var, int32_t index) npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); + void* src = PyArray_DATA(arr); if (ndims != 1) throw(rogue::GeneralError::create("Block::setUIntPy", @@ -921,17 +922,15 @@ void rim::Block::setUIntPy(bp::object& value, rim::Variable* var, int32_t index) var->name_.c_str())); if (PyArray_TYPE(arr) == NPY_UINT64) { - uint64_t* src = reinterpret_cast(PyArray_DATA(arr)); - uint64_t* value = src; + uint64_t* value = reinterpret_cast(src); for (x = 0; x < dims[0]; x++) { - value = src + x * strides[0]; + value = reinterpret_cast(src + x * strides[0]); setUInt(*value, var, index + x); } } else if (PyArray_TYPE(arr) == NPY_UINT32) { - uint32_t* src = reinterpret_cast(PyArray_DATA(arr)); - uint32_t* value = src; + uint32_t* value = reinterpret_cast(src); for (x = 0; x < dims[0]; x++) { - value = src + x * strides[0]; + value = reinterpret_cast(src + x * strides[0]); setUInt(*value, var, index + x); } } else { @@ -1088,17 +1087,15 @@ void rim::Block::setIntPy(bp::object& value, rim::Variable* var, int32_t index) var->name_.c_str())); if (PyArray_TYPE(arr) == NPY_INT64) { - int64_t* src = reinterpret_cast(PyArray_DATA(arr)); - int64_t* value = src; + int64_t* value = reinterpret_cast(src); for (x = 0; x < dims[0]; x++) { - value = src + x * strides[0]; + value = reinterpret_cast(src + x * strides[0]); setInt(*value, var, index + x); } } else if (PyArray_TYPE(arr) == NPY_INT32) { - int32_t* src = reinterpret_cast(PyArray_DATA(arr)); - int32_t* value = src; + int32_t* value = reinterpret_cast(src); for (x = 0; x < dims[0]; x++) { - value = src + x * strides[0]; + value = reinterpret_cast(src + x * strides[0]); setInt(*value, var, index + x); } } else { @@ -1259,10 +1256,9 @@ void rim::Block::setBoolPy(bp::object& value, rim::Variable* var, int32_t index) var->name_.c_str())); if (PyArray_TYPE(arr) == NPY_BOOL) { - bool* src = reinterpret_cast(PyArray_DATA(arr)); - bool* value = src; + bool* value = reinterpret_cast(src); for (x = 0; x < dims[0]; x++) { - value = src + x * strides[0]; + value = reinterpret_cast(src + x * strides[0]); setBool(*value, var, index + x); } } else { @@ -1472,10 +1468,9 @@ void rim::Block::setFloatPy(bp::object& value, rim::Variable* var, int32_t index var->name_.c_str())); if (PyArray_TYPE(arr) == NPY_FLOAT32) { - float* src = reinterpret_cast(PyArray_DATA(arr)); - float* value = src; + float* value = reinterpret_cast(src); for (x = 0; x < dims[0]; x++) { - value = src + x * strides[0]; + value = reinterpret_cast(src + x * strides[0]); setFloat(*value, var, index + x); } } else { @@ -1622,10 +1617,9 @@ void rim::Block::setDoublePy(bp::object& value, rim::Variable* var, int32_t inde var->name_.c_str())); if (PyArray_TYPE(arr) == NPY_FLOAT64) { - double* src = reinterpret_cast(PyArray_DATA(arr)); - double* value = src; + double* value = reinterpret_cast(src); for (x = 0; x < dims[0]; x++) { - value = src + x * strides[0]; + value = reinterpret_cast(src + x * strides[0]); setDouble(*value, var, index + x); } } else { @@ -1772,10 +1766,9 @@ void rim::Block::setFixedPy(bp::object& value, rim::Variable* var, int32_t index var->name_.c_str())); if (PyArray_TYPE(arr) == NPY_FLOAT64) { - double* src = reinterpret_cast(PyArray_DATA(arr)); - double* value = src; + double* value = reinterpret_cast(src); for (x = 0; x < dims[0]; x++) { - value = src + x * strides[0]; + value = reinterpret_cast(src + x * strides[0]); setFixed(*value, var, index + x); } } else { From 342bb2550ee4329870c86f4ccd21e514207fb546 Mon Sep 17 00:00:00 2001 From: Benjamin Reese Date: Mon, 30 Sep 2024 13:50:51 -0700 Subject: [PATCH 05/11] Whitespace --- src/rogue/interfaces/memory/Block.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rogue/interfaces/memory/Block.cpp b/src/rogue/interfaces/memory/Block.cpp index 4a8e939d8..72f933a4c 100644 --- a/src/rogue/interfaces/memory/Block.cpp +++ b/src/rogue/interfaces/memory/Block.cpp @@ -904,7 +904,7 @@ void rim::Block::setUIntPy(bp::object& value, rim::Variable* var, int32_t index) npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); - void* src = PyArray_DATA(arr); + void* src = PyArray_DATA(arr); if (ndims != 1) throw(rogue::GeneralError::create("Block::setUIntPy", From 1f5f06061bba05dddf00b360ed2515c3f6e3f8de Mon Sep 17 00:00:00 2001 From: Benjamin Reese Date: Mon, 30 Sep 2024 13:54:28 -0700 Subject: [PATCH 06/11] Add test for non-contiguous numpy set --- tests/test_list_memory.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_list_memory.py b/tests/test_list_memory.py index 8e4c80e2e..16fcc25bc 100644 --- a/tests/test_list_memory.py +++ b/tests/test_list_memory.py @@ -423,6 +423,9 @@ def test_memory(): root.ListDevice.UInt32List.set(UInt32ListA) root.ListDevice.Int32List.set(Int32ListA) + root.ListDevice.UInt32List.set(UInt32ListA[::2]) + root.ListDevice.Int32List.set(Int32ListA[::2] + root.ListDevice.UInt32List.set(np.array([1,2,3],np.uint32),index=7) root.ListDevice.Int32List.set([1,-22,-33],index=5) From 4af31c3fc3f3c8efd3d4d367a73c6fbd6ba94f12 Mon Sep 17 00:00:00 2001 From: Benjamin Reese Date: Mon, 30 Sep 2024 14:01:29 -0700 Subject: [PATCH 07/11] Fix pointer math --- src/rogue/interfaces/memory/Block.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rogue/interfaces/memory/Block.cpp b/src/rogue/interfaces/memory/Block.cpp index 72f933a4c..03db142e6 100644 --- a/src/rogue/interfaces/memory/Block.cpp +++ b/src/rogue/interfaces/memory/Block.cpp @@ -904,7 +904,7 @@ void rim::Block::setUIntPy(bp::object& value, rim::Variable* var, int32_t index) npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); - void* src = PyArray_DATA(arr); + uint8_t* src = reinterpret_cast(PyArray_DATA(arr)); if (ndims != 1) throw(rogue::GeneralError::create("Block::setUIntPy", @@ -1070,6 +1070,7 @@ void rim::Block::setIntPy(bp::object& value, rim::Variable* var, int32_t index) npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); + uint8_t* src = reinterpret_cast(PyArray_DATA(arr)); if (ndims != 1) throw(rogue::GeneralError::create("Block::setIntPy", @@ -1239,6 +1240,7 @@ void rim::Block::setBoolPy(bp::object& value, rim::Variable* var, int32_t index) npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); + uint8_t* src = reinterpret_cast(PyArray_DATA(arr)); if (ndims != 1) throw(rogue::GeneralError::create("Block::setBoolPy", @@ -1451,6 +1453,7 @@ void rim::Block::setFloatPy(bp::object& value, rim::Variable* var, int32_t index npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); + uint8_t* src = reinterpret_cast(PyArray_DATA(arr)); if (ndims != 1) throw(rogue::GeneralError::create("Block::setFloatPy", @@ -1600,6 +1603,7 @@ void rim::Block::setDoublePy(bp::object& value, rim::Variable* var, int32_t inde npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); + uint8_t* src = reinterpret_cast(PyArray_DATA(arr)); if (ndims != 1) throw(rogue::GeneralError::create("Block::setDoublePy", @@ -1749,6 +1753,7 @@ void rim::Block::setFixedPy(bp::object& value, rim::Variable* var, int32_t index npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); + uint8_t* src = reinterpret_cast(PyArray_DATA(arr)); if (ndims != 1) throw(rogue::GeneralError::create("Block::setFixedPy", From 29ade9d0208b86b4e4128ab136320926a7c39734 Mon Sep 17 00:00:00 2001 From: Benjamin Reese Date: Mon, 30 Sep 2024 14:15:39 -0700 Subject: [PATCH 08/11] Cleanup --- src/rogue/interfaces/memory/Block.cpp | 54 ++++++++++++--------------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/src/rogue/interfaces/memory/Block.cpp b/src/rogue/interfaces/memory/Block.cpp index 03db142e6..563d5c923 100644 --- a/src/rogue/interfaces/memory/Block.cpp +++ b/src/rogue/interfaces/memory/Block.cpp @@ -904,7 +904,6 @@ void rim::Block::setUIntPy(bp::object& value, rim::Variable* var, int32_t index) npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); - uint8_t* src = reinterpret_cast(PyArray_DATA(arr)); if (ndims != 1) throw(rogue::GeneralError::create("Block::setUIntPy", @@ -922,16 +921,16 @@ void rim::Block::setUIntPy(bp::object& value, rim::Variable* var, int32_t index) var->name_.c_str())); if (PyArray_TYPE(arr) == NPY_UINT64) { - uint64_t* value = reinterpret_cast(src); + uint64_t* src = reinterpret_cast(PyArray_DATA(arr)); + npy_intp stride = strides[0] / sizeof(uint64_t); for (x = 0; x < dims[0]; x++) { - value = reinterpret_cast(src + x * strides[0]); - setUInt(*value, var, index + x); + setUInt(src[x * stride], var, index + x); } } else if (PyArray_TYPE(arr) == NPY_UINT32) { - uint32_t* value = reinterpret_cast(src); + uint32_t* src = reinterpret_cast(PyArray_DATA(arr)); + npy_intp stride = strides[0] / sizeof(uint32_t); for (x = 0; x < dims[0]; x++) { - value = reinterpret_cast(src + x * strides[0]); - setUInt(*value, var, index + x); + setUInt(src[x * stride], var, index + x); } } else { throw(rogue::GeneralError::create("Block::setUIntPy", @@ -1070,7 +1069,6 @@ void rim::Block::setIntPy(bp::object& value, rim::Variable* var, int32_t index) npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); - uint8_t* src = reinterpret_cast(PyArray_DATA(arr)); if (ndims != 1) throw(rogue::GeneralError::create("Block::setIntPy", @@ -1088,16 +1086,16 @@ void rim::Block::setIntPy(bp::object& value, rim::Variable* var, int32_t index) var->name_.c_str())); if (PyArray_TYPE(arr) == NPY_INT64) { - int64_t* value = reinterpret_cast(src); + int64_t* src = reinterpret_cast(PyArray_DATA(arr)); + npy_intp stride = strides[0] / sizeof(int64_t); for (x = 0; x < dims[0]; x++) { - value = reinterpret_cast(src + x * strides[0]); - setInt(*value, var, index + x); + setInt(src[x * stride], var, index + x); } } else if (PyArray_TYPE(arr) == NPY_INT32) { - int32_t* value = reinterpret_cast(src); + int32_t* src = reinterpret_cast(PyArray_DATA(arr)); + npy_intp stride = strides[0] / sizeof(int32_t); for (x = 0; x < dims[0]; x++) { - value = reinterpret_cast(src + x * strides[0]); - setInt(*value, var, index + x); + setInt(src[x * stride], var, index + x); } } else { throw(rogue::GeneralError::create("Block::setIntPy", @@ -1240,7 +1238,6 @@ void rim::Block::setBoolPy(bp::object& value, rim::Variable* var, int32_t index) npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); - uint8_t* src = reinterpret_cast(PyArray_DATA(arr)); if (ndims != 1) throw(rogue::GeneralError::create("Block::setBoolPy", @@ -1258,10 +1255,10 @@ void rim::Block::setBoolPy(bp::object& value, rim::Variable* var, int32_t index) var->name_.c_str())); if (PyArray_TYPE(arr) == NPY_BOOL) { - bool* value = reinterpret_cast(src); + bool* src = reinterpret_cast(PyArray_DATA(arr)); + npy_intp stride = strides[0] / sizeof(bool); for (x = 0; x < dims[0]; x++) { - value = reinterpret_cast(src + x * strides[0]); - setBool(*value, var, index + x); + setBool(src[x * stride], var, index + x); } } else { throw(rogue::GeneralError::create("Block::setBoolPy", @@ -1453,7 +1450,6 @@ void rim::Block::setFloatPy(bp::object& value, rim::Variable* var, int32_t index npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); - uint8_t* src = reinterpret_cast(PyArray_DATA(arr)); if (ndims != 1) throw(rogue::GeneralError::create("Block::setFloatPy", @@ -1471,10 +1467,10 @@ void rim::Block::setFloatPy(bp::object& value, rim::Variable* var, int32_t index var->name_.c_str())); if (PyArray_TYPE(arr) == NPY_FLOAT32) { - float* value = reinterpret_cast(src); + float* src = reinterpret_cast(PyArray_DATA(arr)); + npy_intp stride = strides[0] / sizeof(float); for (x = 0; x < dims[0]; x++) { - value = reinterpret_cast(src + x * strides[0]); - setFloat(*value, var, index + x); + setFloat(src[x * stride], var, index + x); } } else { throw(rogue::GeneralError::create("Block::setFLoatPy", @@ -1603,7 +1599,6 @@ void rim::Block::setDoublePy(bp::object& value, rim::Variable* var, int32_t inde npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); - uint8_t* src = reinterpret_cast(PyArray_DATA(arr)); if (ndims != 1) throw(rogue::GeneralError::create("Block::setDoublePy", @@ -1621,10 +1616,10 @@ void rim::Block::setDoublePy(bp::object& value, rim::Variable* var, int32_t inde var->name_.c_str())); if (PyArray_TYPE(arr) == NPY_FLOAT64) { - double* value = reinterpret_cast(src); + double* src = reinterpret_cast(PyArray_DATA(arr)); + npy_intp stride = strides[0] / sizeof(double); for (x = 0; x < dims[0]; x++) { - value = reinterpret_cast(src + x * strides[0]); - setDouble(*value, var, index + x); + setDouble(src[x * stride], var, index + x); } } else { throw(rogue::GeneralError::create("Block::setFLoatPy", @@ -1753,7 +1748,6 @@ void rim::Block::setFixedPy(bp::object& value, rim::Variable* var, int32_t index npy_intp ndims = PyArray_NDIM(arr); npy_intp* dims = PyArray_SHAPE(arr); npy_intp* strides = PyArray_STRIDES(arr); - uint8_t* src = reinterpret_cast(PyArray_DATA(arr)); if (ndims != 1) throw(rogue::GeneralError::create("Block::setFixedPy", @@ -1771,10 +1765,10 @@ void rim::Block::setFixedPy(bp::object& value, rim::Variable* var, int32_t index var->name_.c_str())); if (PyArray_TYPE(arr) == NPY_FLOAT64) { - double* value = reinterpret_cast(src); + double* src = reinterpret_cast(PyArray_DATA(arr)); + npy_intp stride = strides[0] / sizeof(double); for (x = 0; x < dims[0]; x++) { - value = reinterpret_cast(src + x * strides[0]); - setFixed(*value, var, index + x); + setFixed(src[x * stride], var, index + x); } } else { throw(rogue::GeneralError::create("Block::setFixedPy", From 59ed5655bb11fd31476fe00b738a3af237f0189e Mon Sep 17 00:00:00 2001 From: Benjamin Reese Date: Mon, 30 Sep 2024 14:19:33 -0700 Subject: [PATCH 09/11] Fix syntax error --- tests/test_list_memory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_list_memory.py b/tests/test_list_memory.py index 16fcc25bc..a042d9926 100644 --- a/tests/test_list_memory.py +++ b/tests/test_list_memory.py @@ -424,7 +424,7 @@ def test_memory(): root.ListDevice.Int32List.set(Int32ListA) root.ListDevice.UInt32List.set(UInt32ListA[::2]) - root.ListDevice.Int32List.set(Int32ListA[::2] + root.ListDevice.Int32List.set(Int32ListA[::2]) root.ListDevice.UInt32List.set(np.array([1,2,3],np.uint32),index=7) root.ListDevice.Int32List.set([1,-22,-33],index=5) From b13c62ca5c7956d975a321c9a70bd3e5a0ec3085 Mon Sep 17 00:00:00 2001 From: Benjamin Reese Date: Mon, 30 Sep 2024 14:38:41 -0700 Subject: [PATCH 10/11] Update test --- tests/test_list_memory.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/test_list_memory.py b/tests/test_list_memory.py index a042d9926..576a6a0de 100644 --- a/tests/test_list_memory.py +++ b/tests/test_list_memory.py @@ -423,9 +423,6 @@ def test_memory(): root.ListDevice.UInt32List.set(UInt32ListA) root.ListDevice.Int32List.set(Int32ListA) - root.ListDevice.UInt32List.set(UInt32ListA[::2]) - root.ListDevice.Int32List.set(Int32ListA[::2]) - root.ListDevice.UInt32List.set(np.array([1,2,3],np.uint32),index=7) root.ListDevice.Int32List.set([1,-22,-33],index=5) @@ -447,6 +444,30 @@ def test_memory(): # Test value shift _ = resA[0] >> 5 + root.ListDevice.UInt32List.set(UInt32ListA[::2]) + root.ListDevice.Int32List.set(Int32ListA[::2]) + + resA = root.ListDevice.UInt32List.get() + resB = root.ListDevice.Int32List.get() + + for i in range(16): + + if resA[i] != UInt32ListA[::2][i]: + raise AssertionError(f'Stripe Verification Failure for UInt32ListA at position {i}') + + if resB[i] != Int32ListA[::2][i]: + raise AssertionError(f'Stripe Verification Failure for Int32ListA at position {i}') + + for i in range(16, 32): + + if resA[i] != UInt32ListA[i]: + raise AssertionError(f'Stripe Verification Failure for UInt32ListA at position {i}') + + if resB[i] != Int32ListA[i]: + raise AssertionError(f'Stripe Verification Failure for Int32ListA at position {i}') + + + def run_gui(): import pyrogue.pydm From 8f094c6a4b92587cea483553eadc290eaf558bfe Mon Sep 17 00:00:00 2001 From: Benjamin Reese Date: Mon, 30 Sep 2024 14:46:58 -0700 Subject: [PATCH 11/11] Whitespace --- tests/test_list_memory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_list_memory.py b/tests/test_list_memory.py index 576a6a0de..fb1016a9f 100644 --- a/tests/test_list_memory.py +++ b/tests/test_list_memory.py @@ -457,7 +457,7 @@ def test_memory(): if resB[i] != Int32ListA[::2][i]: raise AssertionError(f'Stripe Verification Failure for Int32ListA at position {i}') - + for i in range(16, 32): if resA[i] != UInt32ListA[i]: @@ -466,7 +466,7 @@ def test_memory(): if resB[i] != Int32ListA[i]: raise AssertionError(f'Stripe Verification Failure for Int32ListA at position {i}') - + def run_gui(): import pyrogue.pydm