Array assignment to a structure's nested array
See original GitHub issueImpossible to assign an array to the nested array in the structured array. Without numba all the options below are working, but with numba only the last option works.
- The first option falls with an error “Can only insert i8 at [0] in [1024 x i8]: got i8*”.
- The second option falls with “Buffer dtype cannot be buffer, have dtype: nestedarray(uint8, (1024,))”
- The third option falls with “Buffer dtype cannot be buffer, have dtype: nestedarray(uint8, (1024,))”
import numba as nb
import numpy as np
BLOCK = np.dtype([("id", np.uint64), ("props", (np.uint8, 1024))])
@nb.njit()
def set_props1(_source, _target):
_target[0]["props"] = _source[0]["props"]
@nb.njit()
def set_props2(_source, _target):
_target["props"][0] = _source["props"][0]
@nb.njit()
def set_props3(_source, _target):
for i in range(1024):
_target["props"][0, i] = 1
@nb.njit()
def set_props4(_source, _target):
for i in range(1024):
_target[0]["props"][i] = 1
source = np.ones(1, dtype=BLOCK)
target = np.zeros(1, dtype=BLOCK)
set_props1(source, target)
print(target)
set_props2(source, target)
print(target)
set_props3(source, target)
print(target)
set_props4(source, target)
print(target)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Assign value to field in array of nested structs - Stack Overflow
Assign value to field in array of nested structs · 1. Try this: outerStruct->innerStructsArr[0]. · Should that definitely work? I've tried that as ......
Read more >Nested structure array assignment - MATLAB Answers
Suppose I have several arrays called array1,array2,....,arrayN and need to assign those to a nested structure, whose 'nestedStruct' and 'Field' names also ...
Read more >Array of Structures vs. Array within a Structure in C/C++
A structure is a data type in C/C++ that allows a group of related variables to be treated as a single unit instead...
Read more >Nesting Structures :: Data Types (Programming) - MatLab
You can build nested structure arrays using direct assignment statements. These statements add a second element to the array: A(2).data = [9 3...
Read more >Structures and Cell Arrays (Programming and Data Types)
You can build nested structure arrays using direct assignment statements. These statements add a second element to the array.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Now that #7359 is merged, this is fixed. (cc @luk-f-a)
wow, so many issues addressed by that PR