How to specify a read-only array to jit?

0 views
Skip to first unread message

it...@esss.co

unread,
Mar 15, 2018, 9:55:58 AM3/15/18
to Numba Public Discussion - Public

I can't find a way to write a function signature that takes a read-only array without doing some workaround like:

a=numpy.zeros((1,1))
a
.flags.writeable=False

numba
.jit(void(typeof(a)),nopython=True)
def foo(a):
   
print(a)

Any ideas on how to do it without the dummy variable 'a'?

stuart

unread,
Mar 16, 2018, 5:32:53 AM3/16/18
to Numba Public Discussion - Public
Think you can do this with the `types.Array` constructor like this:

from numba import jit, types

@numba.jit(types.void(types.Array(types.float64, 2, 'C', readonly=True)), nopython=True)
def foo(a):
   
print(a)


which will give a signature:

[(readonly array(float64, 2d, C),)]


Hope this helps?

Thanks,

-- 
stuart
Reply all
Reply to author
Forward
0 new messages