Is np.record() supported?

Numpy records pop up when numpy structured arrays are discussed. But I have not seen whether the use of np.record() is possible within a jitted function such as,

import numpy as np
import numba as nb
from numba import njit

dummyDtype = np.dtype([('x', 'f4'), ('y', 'f4')])
dummyNBtype = nb.from_dtype(dummyDtype)
@njit 
def dummy(a, b):
  return np.record((a, b), dtype=dummyNBtype)

The program you posted worked for me… what error did you see?

Hey @MLLO,

Numpy structured array support in Numba is not “feature complete”.
To my knowledge there is no implementation for np.record(), yet.
If there is no direct solution, you can still create a new structured array, fill in the data from the source object and extract the record if that is what you need.

import numpy as np
import numba as nb

entryDtype = np.dtype([('error', 'f4'), ('triangle_id', 'i8')])
entryNBtype = nb.from_dtype(entryDtype)

@nb.njit
def copy_entry(entry):
    dummy = np.empty(1, dtype=entryDtype)
    dummy['error'][...] = entry.error
    dummy['triangle_id'][...] = entry.triangle_id
    return dummy[0]

entry = np.record((0.75, 1), dtype=entryNBtype)
entry_copied = copy_entry(entry)

Hi @nelson2005,

If you actually call the function ,e.g.

dummy(1.0, 1.0)

it gives an error. At least when I try to do this.