Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numba/cuda/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def load_additional_registries(self):
# side effect of import needed for numba.cpython.*, the builtins
# registry is updated at import time.
from numba.cpython import numbers, tupleobj, slicing # noqa: F401
from numba.cpython import rangeobj, unicode # noqa: F401
from numba.cpython import charseq, rangeobj, unicode # noqa: F401
from numba.cpython import cmathimpl
from numba.np import arrayobj # noqa: F401
from numba.np import npdatetime # noqa: F401
Expand Down
28 changes: 26 additions & 2 deletions numba/cuda/tests/cudapy/test_const_string.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import re
from numba.cuda.testing import unittest, skip_on_cudasim
import numpy as np
from numba import cuda
from numba.cuda.testing import unittest, skip_on_cudasim, CUDATestCase
from llvmlite import ir


@skip_on_cudasim("This is testing CUDA backend code generation")
class TestCudaConstString(unittest.TestCase):
class TestConstStringCodegen(unittest.TestCase):
def test_const_string(self):
# These imports are incompatible with CUDASIM
from numba.cuda.descriptor import cuda_target
Expand Down Expand Up @@ -52,5 +54,27 @@ def test_const_string(self):
self.assertEqual(len(matches), 1)


class TestConstString(CUDATestCase):
def test_assign_const_string(self):
# Inspired by the reproducer from Issue #7041.

@cuda.jit
def str_assign(arr):
i = cuda.grid(1)
if i < len(arr):
arr[i] = "XYZ"

n_strings = 8
arr = np.zeros(n_strings + 1, dtype="<U12")
str_assign[1, n_strings](arr)

# Expected result, e.g.:
# ['XYZ' 'XYZ' 'XYZ' 'XYZ' 'XYZ' 'XYZ' 'XYZ' 'XYZ' '']
expected = np.zeros_like(arr)
expected[:-1] = 'XYZ'

Comment thread
gmarkall marked this conversation as resolved.
Resolved
np.testing.assert_equal(arr, expected)


if __name__ == '__main__':
unittest.main()