2

I was trying to check whether numba passes arguments by value or by reference, So I wrote this:

@numba.jit(nopython=True)
def f(x):
    return id(x)

Which, when run, resulted in this:

TypingError: cannot determine Numba type of <class 'builtin_function_or_method'>

This totally makes sense (I know id is not necessarily the memory address, but that's what I had in mind). However:

  1. How can I get the memory address of an argument within a jitted function?

  2. Does numba pass arguments by value or by reference (and how can I verify this)?

1 Answer 1

3

In terms of the call to id, you can only use python features that are listed in:

http://numba.pydata.org/numba-doc/latest/reference/pysupported.html

My understanding is that numba follows python's convention of pass-by-reference vs pass-by-value (although it's really neither exactly). It's more like call-by-object. Immutable objects like scalars act like they are passed by value. Mutable objects like lists and arrays behave like a reference.

The easiest way to confirm this is just try passing in variables of different argument types, modify them within the function and see if they change after the function is called.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.