コード例 #1
0
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))
コード例 #2
0
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))
コード例 #3
0
ファイル: transforms.py プロジェクト: FrancescAlted/numba
    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)
コード例 #4
0
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[:])
コード例 #5
0
    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)
コード例 #6
0
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[:])
コード例 #7
0
ファイル: numpymodule.py プロジェクト: hfeeki/numba
def _nonzero(type):
    if type.is_array:
        return typesystem.tuple_(index_array_t, type.ndim)
    else:
        return typesystem.tuple_(index_array_t)
コード例 #8
0
def _nonzero(type):
    if type.is_array:
        return typesystem.tuple_(index_array_t, type.ndim)
    else:
        return typesystem.tuple_(index_array_t)
コード例 #9
0
ファイル: test_issue_112.py プロジェクト: winstonewert/numba
# -*- 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)
コード例 #10
0
ファイル: test_issue_112.py プロジェクト: ASPP/numba
# -*- 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)