<commit_before>from __future__ import print_function, division, absolute_import
import numpy as np
from numba import cuda, float32
from numba.cuda.testing import unittest
from numba.macro import MacroError

GLOBAL_CONSTANT = 5
GLOBAL_CONSTANT_2 = 6
GLOBAL_CONSTANT_TUPLE = 5, 6


def udt_global_constants(A):
    sa = cuda.shared.array(shape=GLOBAL_CONSTANT, dtype=float32)
    i = cuda.grid(1)
    A[i] = sa[i]


def udt_global_build_tuple(A):
    sa = cuda.shared.array(shape=(GLOBAL_CONSTANT, GLOBAL_CONSTANT_2),
                           dtype=float32)
    i, j = cuda.grid(2)
    A[i, j] = sa[i, j]


def udt_global_build_list(A):
    sa = cuda.shared.array(shape=[GLOBAL_CONSTANT, GLOBAL_CONSTANT_2],
                           dtype=float32)
    i, j = cuda.grid(2)
    A[i, j] = sa[i, j]


def udt_global_constant_tuple(A):
    sa = cuda.shared.array(shape=GLOBAL_CONSTANT_TUPLE, dtype=float32)
    i, j = cuda.grid(2)
    A[i, j] = sa[i, j]


def udt_invalid_1(A):
    sa = cuda.shared.array(shape=A[0], dtype=float32)
    i = cuda.grid(1)
    A[i] = sa[i]


def udt_invalid_2(A):
    sa = cuda.shared.array(shape=(1, A[0]), dtype=float32)
    i, j = cuda.grid(2)
    A[i, j] = sa[i, j]


class TestMacro(unittest.TestCase):
    def getarg(self):
        return np.array(100, dtype=np.float32)

    def test_global_constants(self):
        udt = cuda.jit((float32[:],))(udt_global_constants)
        udt(self.getarg())

    def test_global_build_tuple(self):
        udt = cuda.jit((float32[:, :],))(udt_global_build_tuple)
        udt(self.getarg())

    def test_global_build_list(self):
        with self.assertRaises(MacroError) as raises:
            cuda.jit((float32[:, :],))(udt_global_build_list)

        self.assertIn("invalid type for shape; got <class 'list'>",
                      str(raises.exception))

    def test_global_constant_tuple(self):
        udt = cuda.jit((float32[:, :],))(udt_global_constant_tuple)
        udt(self.getarg())

    def test_invalid_1(self):
        with self.assertRaises(ValueError) as raises:
            cuda.jit((float32[:],))(udt_invalid_1)
<commit_msg>Fix test - in python2, repr(list) is different<commit_after>from __future__ import print_function, division, absolute_import
import numpy as np
from numba import cuda, float32
from numba.cuda.testing import unittest
from numba.macro import MacroError

GLOBAL_CONSTANT = 5
GLOBAL_CONSTANT_2 = 6
GLOBAL_CONSTANT_TUPLE = 5, 6


def udt_global_constants(A):
    sa = cuda.shared.array(shape=GLOBAL_CONSTANT, dtype=float32)
    i = cuda.grid(1)
    A[i] = sa[i]


def udt_global_build_tuple(A):
    sa = cuda.shared.array(shape=(GLOBAL_CONSTANT, GLOBAL_CONSTANT_2),
                           dtype=float32)
    i, j = cuda.grid(2)
    A[i, j] = sa[i, j]


def udt_global_build_list(A):
    sa = cuda.shared.array(shape=[GLOBAL_CONSTANT, GLOBAL_CONSTANT_2],
                           dtype=float32)
    i, j = cuda.grid(2)
    A[i, j] = sa[i, j]


def udt_global_constant_tuple(A):
    sa = cuda.shared.array(shape=GLOBAL_CONSTANT_TUPLE, dtype=float32)
    i, j = cuda.grid(2)
    A[i, j] = sa[i, j]


def udt_invalid_1(A):
    sa = cuda.shared.array(shape=A[0], dtype=float32)
    i = cuda.grid(1)
    A[i] = sa[i]


def udt_invalid_2(A):
    sa = cuda.shared.array(shape=(1, A[0]), dtype=float32)
    i, j = cuda.grid(2)
    A[i, j] = sa[i, j]


class TestMacro(unittest.TestCase):
    def getarg(self):
        return np.array(100, dtype=np.float32)

    def test_global_constants(self):
        udt = cuda.jit((float32[:],))(udt_global_constants)
        udt(self.getarg())

    def test_global_build_tuple(self):
        udt = cuda.jit((float32[:, :],))(udt_global_build_tuple)
        udt(self.getarg())

    def test_global_build_list(self):
        with self.assertRaises(MacroError) as raises:
            cuda.jit((float32[:, :],))(udt_global_build_list)

        self.assertIn("invalid type for shape; got {0}".format(list),
                      str(raises.exception))

    def test_global_constant_tuple(self):
        udt = cuda.jit((float32[:, :],))(udt_global_constant_tuple)
        udt(self.getarg())

    def test_invalid_1(self):
        with self.assertRaises(ValueError) as raises:
            cuda.jit((float32[:],))(udt_invalid_1)

{'fraction_non_alphanumeric': 0.13569252402156082, 'fraction_numerical': 0.023435669088352474, 'mean_word_length': 3.204926108374384, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7375384', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1642, 'n_words': 297}