Skip to content

Commit

Permalink
Fix all of the set calls
Browse files Browse the repository at this point in the history
  • Loading branch information
bengineerd committed Sep 30, 2024
1 parent 340c295 commit ca8b0a1
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions src/rogue/interfaces/memory/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t*>(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<uint32_t*>(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",
Expand Down Expand Up @@ -1070,6 +1070,7 @@ void rim::Block::setIntPy(bp::object& value, rim::Variable* var, int32_t index)
PyArrayObject* arr = reinterpret_cast<decltype(arr)>(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",
Expand All @@ -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<int64_t*>(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<int32_t*>(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",
Expand Down Expand Up @@ -1232,6 +1241,7 @@ void rim::Block::setBoolPy(bp::object& value, rim::Variable* var, int32_t index)
PyArrayObject* arr = reinterpret_cast<decltype(arr)>(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",
Expand All @@ -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<bool*>(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",
Expand Down Expand Up @@ -1440,6 +1454,7 @@ void rim::Block::setFloatPy(bp::object& value, rim::Variable* var, int32_t index
PyArrayObject* arr = reinterpret_cast<decltype(arr)>(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",
Expand All @@ -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<float*>(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",
Expand Down Expand Up @@ -1585,6 +1604,7 @@ void rim::Block::setDoublePy(bp::object& value, rim::Variable* var, int32_t inde
PyArrayObject* arr = reinterpret_cast<decltype(arr)>(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",
Expand All @@ -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<double*>(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",
Expand Down Expand Up @@ -1730,6 +1754,7 @@ void rim::Block::setFixedPy(bp::object& value, rim::Variable* var, int32_t index
PyArrayObject* arr = reinterpret_cast<decltype(arr)>(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",
Expand All @@ -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<double*>(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",
Expand Down

0 comments on commit ca8b0a1

Please sign in to comment.