creating an array with Structured Scalar dtype, inside a jitted function

0 views
Skip to first unread message

Anthony Morgan

unread,
Aug 31, 2017, 12:37:47 PM8/31/17
to Numba Public Discussion - Public
The documentation implies this is possible:

Numba supports the following Numpy scalar types:

Integers: all integers of either signedness, and any width up to 64 bits

Datetimes and timestamps: of any unit
...
Structured scalars: structured scalars made of any of the types above and arrays of the types above
...
Numpy arrays of any of the scalar types above are supported, regardless of the shape or layout.
...
numpy.array() (only the 2 first arguments)


The following simplified example however doesn't work,

import numpy as np
from numba import jit

CUSTOM_TYPE = np.dtype([('time', '<M8[ns]'), ('a', '<i4'), ('b', '<i4'), ('c', '<i4')])

@jit(nopython=True)
def test(a,b,c,d):
    return np.array([(a,b,c,d)], dtype=CUSTOM_TYPE)

test(np.datetime64(0,'ns'),1,2,3)

yielding the following error:
cannot convert (datetime64(ns), int64, int64, int64) to a homogenous type

have I misunderstood the support? 


    Anthony Morgan

    unread,
    Aug 31, 2017, 1:17:54 PM8/31/17
    to numba...@continuum.io
    Ah, please disregard. I understand now, the tuple is causing the conversion error not the array constructor, as this works:

    @jit(nopython=True)
    def test(a,b,c,d):
        x = np.empty((1,), dtype=CUSTOM_TYPE)
        x[0].time = np.int64(a) // 10000000
        x[0].a = b
        x[0].b = c
        x[0].c = d
        return x

    --
    You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+unsubscribe@continuum.io.
    To post to this group, send email to numba...@continuum.io.
    To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/9d7069fd-bbea-4136-b641-25d55458d7b0%40continuum.io.
    For more options, visit https://groups.google.com/a/continuum.io/d/optout.

    Reply all
    Reply to author
    Forward
    0 new messages