def test_nonzero(): equals(nonzero(np.array([1, 2, 3], dtype=np.double)), tuple_(npy_intp[:], 1)) equals(nonzero(np.array([[1, 2, 3]], dtype=np.double)), tuple_(npy_intp[:], 2)) equals(nonzero(np.array((((1, 2, 3),),), dtype=np.double)), tuple_(npy_intp[:], 3))
def test_nonzero(): equals(nonzero(np.array([1, 2, 3], dtype=np.double)), tuple_(npy_intp[:], 1)) equals(nonzero(np.array([[1, 2, 3]], dtype=np.double)), tuple_(npy_intp[:], 2)) equals(nonzero(np.array((((1, 2, 3), ), ), dtype=np.double)), tuple_(npy_intp[:], 3))
def visit_Tuple(self, node): self.check_context(node) sig, lfunc = self.context.external_library.declare(self.llvm_module, 'PyTuple_Pack') objs = self.visitlist(nodes.CoercionNode.coerce(node.elts, object_)) n = nodes.ConstNode(len(node.elts), Py_ssize_t) args = [n] + objs new_node = nodes.NativeCallNode(sig, args, lfunc, name='tuple') # TODO: determine element type of node.elts new_node.type = typesystem.tuple_(object_, size=len(node.elts)) return nodes.ObjectTempNode(new_node)
def test_where(): equals(where(np.array([1, 2, 3], dtype=np.double)), tuple_(npy_intp[:], 1)) equals( where3(np.array([True, False, True]), np.array([1, 2, 3], dtype=np.double), np.array([1, 2, 3], dtype=np.complex128)), complex128[:]) equals( where3(np.array([True, False, True]), np.array([1, 2, 3], dtype=np.float32), np.array([1, 2, 3], dtype=np.int64)), float64[:])
def test_where(): equals(where(np.array([1, 2, 3], dtype=np.double)), tuple_(npy_intp[:], 1)) equals(where3(np.array([True, False, True]), np.array([1, 2, 3], dtype=np.double), np.array([1, 2, 3], dtype=np.complex128)), complex128[:]) equals(where3(np.array([True, False, True]), np.array([1, 2, 3], dtype=np.float32), np.array([1, 2, 3], dtype=np.int64)), float64[:])
def _nonzero(type): if type.is_array: return typesystem.tuple_(index_array_t, type.ndim) else: return typesystem.tuple_(index_array_t)
# -*- coding: utf-8 -*- from __future__ import print_function, division, absolute_import import numpy as np from numba import autojit, register_callable, npy_intp, typesystem restype = typesystem.tuple_(npy_intp[:, :], 2) @register_callable(restype(npy_intp[:], npy_intp[:])) def meshgrid(x, y): return np.meshgrid(x, y) @autojit def run_meshgrid(size): x1d = np.arange(-size, size + 1) y1d = np.arange(-size, size + 1) x, y = meshgrid(x1d, y1d) return x, y if __name__ == '__main__': size = 3 nb_gauss = run_meshgrid(size)