<commit_before># -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import

import math
import unittest

from numba2 import jit, types, int32, float64, Type
from numba2.runtime import ffi

# ______________________________________________________________________

class TestFFI(unittest.TestCase):

    def test_malloc(self):
        raise unittest.SkipTest

        @jit
        def f():
            p = ffi.malloc(2, types.int32)
            p[0] = 4
            p[1] = 5
            return p

        p = f()
        self.assertEqual(p[0], 4)
        self.assertEqual(p[1], 5)

    def test_sizeof(self):
        def func(x):
            return ffi.sizeof(x)

        def apply(signature, arg):
            return jit(signature)(func)(arg)

        self.assertEqual(apply('int32 -> int64', 10), 4)
        self.assertEqual(apply('Type[int32] -> int64', int32), 4)
        self.assertEqual(apply('float64 -> int64', 10.0), 8)
        self.assertEqual(apply('Type[float64] -> int64', float64), 8)


# ______________________________________________________________________

if __name__ == "__main__":
    unittest.main()<commit_msg>Insert explicit cast to malloc implementation<commit_after># -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import

import math
import unittest

from numba2 import jit, types, int32, float64, Type, cast
from numba2.runtime import ffi

# ______________________________________________________________________

class TestFFI(unittest.TestCase):

    def test_malloc(self):
        @jit
        def f():
            p = ffi.malloc(cast(2, types.int64), types.int32)
            p[0] = 4
            p[1] = 5
            return p

        p = f()
        self.assertEqual(p[0], 4)
        self.assertEqual(p[1], 5)

    def test_sizeof(self):
        def func(x):
            return ffi.sizeof(x)

        def apply(signature, arg):
            return jit(signature)(func)(arg)

        self.assertEqual(apply('int32 -> int64', 10), 4)
        self.assertEqual(apply('Type[int32] -> int64', int32), 4)
        self.assertEqual(apply('float64 -> int64', 10.0), 8)
        self.assertEqual(apply('Type[float64] -> int64', float64), 8)


# ______________________________________________________________________

if __name__ == "__main__":
    unittest.main()
{'fraction_non_alphanumeric': 0.11774744027303755, 'fraction_numerical': 0.040955631399317405, 'mean_word_length': 2.80064829821718, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, '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': '6793242', 'n_tokens_mistral': 728, 'n_tokens_neox': 664, 'n_words': 164}