question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Array assignment to a structure's nested array

See original GitHub issue

Impossible 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:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gmarkallcommented, Dec 7, 2021

Now that #7359 is merged, this is fixed. (cc @luk-f-a)

0reactions
luk-f-acommented, Dec 12, 2021

wow, so many issues addressed by that PR

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found