Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support string datatype declaration for numpy array creation #6258

Closed
mha-py opened this issue Sep 20, 2020 · 3 comments
Closed

Support string datatype declaration for numpy array creation #6258

mha-py opened this issue Sep 20, 2020 · 3 comments
Labels
duplicate feature_request no action required No action was needed to resolve. question Notes an issue as a question

Comments

@mha-py
Copy link

mha-py commented Sep 20, 2020

Hey!

When you have code like

arr = np.zeros((N, M), dtype='uint8')

you cant just put the jit decorator in front of the function because numba doesnt recognize the string declaration. What is working is from numba.types import bytes and use that type instead. Problem is, that this type declaration is only working with numba, not without. Means that numpy throws an error when there is no jit decorator anymore.
So i guess it would be cool if numba would recoginze string declarations of data type!

@gmarkall
Copy link
Member

You can use the np.uint8 dtype (and other dtypes in the np module in general) to keep the code working with and without the decorator, e.g.:

from numba import njit
import numpy as np

@njit
def make_zeros_numba():
    return np.zeros(1, dtype=np.uint8)

def make_zeros_python():
    return np.zeros(1, dtype=np.uint8)

make_zeros_numba()
make_zeros_python()

compiles successfully.

@gmarkall gmarkall added feature_request question Notes an issue as a question labels Sep 21, 2020
@gmarkall
Copy link
Member

Additionally, marking as a feature request for support for strings for the dtype name.

@esc
Copy link
Member

esc commented Sep 21, 2020

@mha-py thank your for asking about this. I will close this as it is a duplicate of (the long standing issue) #2201.

@esc esc added duplicate no action required No action was needed to resolve. labels Sep 21, 2020
@esc esc closed this as completed Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate feature_request no action required No action was needed to resolve. question Notes an issue as a question
Projects
None yet
Development

No branches or pull requests

3 participants