HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/anaconda3/Lib/site-packages/numba/cuda/tests/cudapy/test_py2_div_issue.py
import numpy as np
from numba import cuda, float32, int32, void
from numba.cuda.testing import unittest, CUDATestCase


class TestCudaPy2Div(CUDATestCase):
    def test_py2_div_issue(self):
        @cuda.jit(void(float32[:], float32[:], float32[:], int32))
        def preCalc(y, yA, yB, numDataPoints):
            i = cuda.grid(1)
            # k is unused, but may be part of the trigger for the bug this
            # tests for.
            k = i % numDataPoints  # noqa: F841

            ans = float32(1.001 * float32(i))

            y[i] = ans
            yA[i] = ans * 1.0
            yB[i] = ans / 1.0

        numDataPoints = 15

        y = np.zeros(numDataPoints, dtype=np.float32)
        yA = np.zeros(numDataPoints, dtype=np.float32)
        yB = np.zeros(numDataPoints, dtype=np.float32)
        preCalc[1, 15](y, yA, yB, numDataPoints)

        self.assertTrue(np.all(y == yA))
        self.assertTrue(np.all(y == yB))


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