<commit_before>from pythran.tests import TestEnv
from pythran.typing import NDArray, Tuple, List

import numpy

import unittest
import sys

try:
    numpy.float128
    has_float128 = True
except AttributeError:
    has_float128 = False



@TestEnv.module
class TestNdarray(TestEnv):

    def test_ndarray_intc(self):
        self.run_test('def ndarray_intc(a): import numpy as np; return np.intc(a), np.array([a, a], dtype=np.intc)',
                      numpy.intc(5),
                      ndarray_intc=[numpy.intc])

    def test_ndarray_uintc(self):
        self.run_test('def ndarray_uintc(a): import numpy as np; return np.uintc(a), np.array([a, a], dtype=np.uintc)',
                      numpy.uintc(5),
                      ndarray_uintc=[numpy.uintc])

    def test_ndarray_intp(self):
        self.run_test('def ndarray_intp(a): import numpy as np; return np.intp(a), np.array([a, a], dtype=np.intp)',
                      numpy.intp(-5),
                      ndarray_intp=[numpy.intp])

    def test_ndarray_uintp(self):
        self.run_test('def ndarray_uintp(a): import numpy as np; return np.uintp(a), np.array([a, a], dtype=np.uintp)',
                      numpy.uintp(5),
                      ndarray_uintp=[numpy.uintp])

    def test_ndarray_real_attr_read(self):
        self.run_test('def ndarray_real_attr_read(a): return a.real + 1',
                      numpy.arange(100, dtype=numpy.complex128).reshape((10, 10)),
                      ndarray_real_attr_read=[NDArray[complex, :, :]])

    def test_ndarray_imag_attr_read(self):
        self.run_test('def ndarray_imag_attr_read(a): return a.imag + 1',
                      1j * numpy.arange(10, dtype=numpy.complex128),
                      ndarray_imag_attr_read=[NDArray[complex, :]])

    def test_ndarray_real_attr_read_complex64(self):
        self.run_test('def ndarray_real_attr_read_complex64(a): return a.real + 1',
                      numpy.arange(100, dtype=numpy.complex64).reshape((10, 10)),
                      ndarray_real_attr_read_complex64=[NDArray[numpy.complex64, :, :]])

    def test_ndarray_imag_attr_read_complex64(self):
        self.run_test('def ndarray_imag_attr_read_complex64(a): return a.imag + 1',
                      1j * numpy.arange(10, dtype=numpy.complex64),
                      ndarray_imag_attr_read_complex64=[NDArray[numpy.complex64, :]])

    @unittest.expectedFailure
    def test_ndarray_real_attr_write(self):
        self.run_test('def ndarray_real_attr_read(a): a.real = 1 ; return a',
                      numpy.arange(100, dtype=numpy.complex128).reshape((10, 10)),
                      ndarray_real_attr_read=[NDArray[complex, :, :]])

    @unittest.expectedFailure
    def test_ndarray_imag_attr_write(self):
        self.run_test('def ndarray_imag_attr_read(a): a.imag = 1 ; return a',
                      1j * numpy.arange(10, dtype=numpy.complex128),
                      ndarray_imag_attr_read=[NDArray[complex, :]])

    def test_ndarray_real_fun_read(self):
        self.run_test('def ndarray_real_fun_read(a): import numpy as np ; return np.real(a)[1:]',
                      numpy.arange(100, dtype=numpy.complex128).reshape((10, 10)),
                      ndarray_real_fun_read=[NDArray[complex, :, :]])

    def test_ndarray_imag_fun_read(self):
        self.run_test('def ndarray_imag_fun_read(a): import numpy as np ; return - np.imag(a)',
                      1j * numpy.arange(10, dtype=numpy.complex128),
                      ndarray_imag_fun_read=[NDArray[complex, :]])

    def test_numpy_augassign0(self):
        self.run_test('def numpy_augassign0(a): a+=1; return a',
                      numpy.arange(100).reshape((10, 10)),
                      numpy_augassign0=[NDArray[int, :, :]])

    def test_numpy_augassign1(self):
        self.run_test('def numpy_augassign1(a): a*=2; return a',
                      numpy.arange(100).reshape((10, 10)),
                      numpy_augassign1=[NDArray[int, :, :]])

    def test_numpy_augassign2(self):
        self.run_test('def numpy_augassign2(a): a-=2; return a',
                      numpy.arange(100).reshape((10, 10)),
                      numpy_augassign2=[NDArray[int, :, :]])

    @unittest.skipIf(sys.version_info.major == 3, "not supported in pythran3")
    def test_numpy_augassign3(self):<commit_msg>Fix bad naming of numpy test<commit_after>from pythran.tests import TestEnv
from pythran.typing import NDArray, Tuple, List

import numpy

import unittest
import sys

try:
    numpy.float128
    has_float128 = True
except AttributeError:
    has_float128 = False



@TestEnv.module
class TestNdarray(TestEnv):

    def test_ndarray_intc(self):
        self.run_test('def ndarray_intc(a): import numpy as np; return np.intc(a), np.array([a, a], dtype=np.intc)',
                      numpy.intc(5),
                      ndarray_intc=[numpy.intc])

    def test_ndarray_uintc(self):
        self.run_test('def ndarray_uintc(a): import numpy as np; return np.uintc(a), np.array([a, a], dtype=np.uintc)',
                      numpy.uintc(5),
                      ndarray_uintc=[numpy.uintc])

    def test_ndarray_intp(self):
        self.run_test('def ndarray_intp(a): import numpy as np; return np.intp(a), np.array([a, a], dtype=np.intp)',
                      numpy.intp(-5),
                      ndarray_intp=[numpy.intp])

    def test_ndarray_uintp(self):
        self.run_test('def ndarray_uintp(a): import numpy as np; return np.uintp(a), np.array([a, a], dtype=np.uintp)',
                      numpy.uintp(5),
                      ndarray_uintp=[numpy.uintp])

    def test_ndarray_real_attr_read(self):
        self.run_test('def ndarray_real_attr_read(a): return a.real + 1',
                      numpy.arange(100, dtype=numpy.complex128).reshape((10, 10)),
                      ndarray_real_attr_read=[NDArray[complex, :, :]])

    def test_ndarray_imag_attr_read(self):
        self.run_test('def ndarray_imag_attr_read(a): return a.imag + 1',
                      1j * numpy.arange(10, dtype=numpy.complex128),
                      ndarray_imag_attr_read=[NDArray[complex, :]])

    def test_ndarray_real_attr_read_complex64(self):
        self.run_test('def ndarray_real_attr_read_complex64(a): return a.real + 1',
                      numpy.arange(100, dtype=numpy.complex64).reshape((10, 10)),
                      ndarray_real_attr_read_complex64=[NDArray[numpy.complex64, :, :]])

    def test_ndarray_imag_attr_read_complex64(self):
        self.run_test('def ndarray_imag_attr_read_complex64(a): return a.imag + 1',
                      1j * numpy.arange(10, dtype=numpy.complex64),
                      ndarray_imag_attr_read_complex64=[NDArray[numpy.complex64, :]])

    def test_ndarray_real_attr_write(self):
        self.run_test('def ndarray_real_attr_write(a): a.real = 1 ; return a',
                      numpy.arange(100, dtype=numpy.complex128).reshape((10, 10)),
                      ndarray_real_attr_write=[NDArray[complex, :, :]])

    def test_ndarray_imag_attr_write(self):
        self.run_test('def ndarray_imag_attr_write(a): a.imag = 1 ; return a',
                      1j * numpy.arange(10, dtype=numpy.complex128),
                      ndarray_imag_attr_write=[NDArray[complex, :]])

    def test_ndarray_real_fun_read(self):
        self.run_test('def ndarray_real_fun_read(a): import numpy as np ; return np.real(a)[1:]',
                      numpy.arange(100, dtype=numpy.complex128).reshape((10, 10)),
                      ndarray_real_fun_read=[NDArray[complex, :, :]])

    def test_ndarray_imag_fun_read(self):
        self.run_test('def ndarray_imag_fun_read(a): import numpy as np ; return - np.imag(a)',
                      1j * numpy.arange(10, dtype=numpy.complex128),
                      ndarray_imag_fun_read=[NDArray[complex, :]])

    def test_numpy_augassign0(self):
        self.run_test('def numpy_augassign0(a): a+=1; return a',
                      numpy.arange(100).reshape((10, 10)),
                      numpy_augassign0=[NDArray[int, :, :]])

    def test_numpy_augassign1(self):
        self.run_test('def numpy_augassign1(a): a*=2; return a',
                      numpy.arange(100).reshape((10, 10)),
                      numpy_augassign1=[NDArray[int, :, :]])

    def test_numpy_augassign2(self):
        self.run_test('def numpy_augassign2(a): a-=2; return a',
                      numpy.arange(100).reshape((10, 10)),
                      numpy_augassign2=[NDArray[int, :, :]])

    @unittest.skipIf(sys.version_info.major == 3, "not supported in pythran3")
    def test_numpy_augassign3(self):
{'fraction_non_alphanumeric': 0.12602803197034634, 'fraction_numerical': 0.03104366963975443, 'mean_word_length': 2.515472312703583, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5975919', 'n_tokens_mistral': 3049, 'n_tokens_neox': 2849, 'n_words': 448}