Skip to content

Commit 8468285

Browse files
committed
Merge pull request #566 from izaid/type
Updates to match libdynd changes
2 parents a0c8938 + 5495791 commit 8468285

6 files changed

Lines changed: 31 additions & 8 deletions

File tree

dynd/cpp/types/callable_type.pxd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from ..type cimport type
22
from ..array cimport array
3+
from libcpp.vector cimport vector
34

45
cdef extern from 'dynd/types/callable_type.hpp':
5-
type make_callable 'dynd::ndt::callable_type::make'(type &, array &)
6+
type make_callable 'dynd::ndt::callable_type::make'(type &, vector[type] &)
67
type make_callable 'dynd::ndt::callable_type::make'(type &, type &, type &)

dynd/cpp/types/struct_type.pxd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from libcpp.vector cimport vector
2+
13
from ..array cimport array
24
from ..type cimport type
35

@@ -6,5 +8,5 @@ from ...config cimport translate_exception
68
cdef extern from 'dynd/types/struct_type.hpp':
79
type make_struct 'dynd::ndt::struct_type::make'() \
810
except +translate_exception
9-
type make_struct 'dynd::ndt::struct_type::make'(const array &, const array &) \
11+
type make_struct 'dynd::ndt::struct_type::make'(const array &, const vector[type] &) \
1012
except +translate_exception

dynd/cpp/types/tuple_type.pxd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from libcpp.vector cimport vector
2+
13
from ..type cimport type
24
from ..array cimport array
35

@@ -6,5 +8,5 @@ from ...config cimport translate_exception
68
cdef extern from 'dynd/types/tuple_type.hpp':
79
type make_tuple 'dynd::ndt::tuple_type::make'() \
810
except +translate_exception
9-
type make_tuple 'dynd::ndt::tuple_type::make'(const array &) \
11+
type make_tuple 'dynd::ndt::tuple_type::make'(const vector[type] &) \
1012
except +translate_exception

dynd/include/kernels/apply_pyobject_kernel.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,16 @@ struct apply_pyobject_kernel : dynd::nd::base_kernel<apply_pyobject_kernel> {
159159
{
160160
pydynd::PyGILState_RAII pgs;
161161

162+
std::vector<dynd::ndt::type> src_tp_copy(nsrc);
163+
for (int i = 0; i < nsrc; ++i) {
164+
src_tp_copy[i] = src_tp[i];
165+
}
166+
162167
intptr_t ckb_offset = ckb->m_size;
163168
ckb->emplace_back<apply_pyobject_kernel>(kernreq);
164169
apply_pyobject_kernel *self =
165170
ckb->get_at<apply_pyobject_kernel>(ckb_offset);
166-
self->m_proto =
167-
dynd::ndt::callable_type::make(dst_tp, dynd::nd::array(src_tp, nsrc));
171+
self->m_proto = dynd::ndt::callable_type::make(dst_tp, src_tp_copy);
168172
self->m_pyfunc = *reinterpret_cast<PyObject **>(static_data);
169173
Py_XINCREF(self->m_pyfunc);
170174
self->m_dst_arrmeta = dst_arrmeta;

dynd/nd/functional.pyx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ cdef public object _jit(object func, intptr_t nsrc, const _type *src_tp):
9494
library.add_ir_module(ir_module)
9595
library.finalize()
9696

97-
return dynd_nd_callable_from_cpp(_apply_jit(make_callable(dst_tp, _array(src_tp, nsrc)),
97+
cdef vector[_type] src_tp_copy
98+
for i in range(nsrc):
99+
src_tp_copy.push_back(src_tp[i])
100+
101+
return dynd_nd_callable_from_cpp(_apply_jit(make_callable(dst_tp, src_tp_copy),
98102
library.get_pointer_to_function('single')))
99103

100104
def apply(func = None, jit = _import_numba(), *args, **kwds):

dynd/ndt/type.pyx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from libc.stdint cimport (intptr_t, int8_t, int16_t, int32_t, int64_t,
55
uint8_t, uint16_t, uint32_t, uint64_t)
66
from libcpp.map cimport map
77
from libcpp.string cimport string
8+
from libcpp.vector cimport vector
89
from libcpp cimport bool as cpp_bool
910

1011
import datetime
@@ -692,6 +693,7 @@ complex_float64 = type(complex_float64_id)
692693
void = type(void_id)
693694

694695
def tuple(*args):
696+
cdef vector[_type] _args
695697

696698
if args:
697699
# TODO: Use a different interface that doesn't involve nd.array.
@@ -700,17 +702,25 @@ def tuple(*args):
700702
# that can then be used to create a tuple type.
701703
# Constructing an array from the list is really
702704
# only partially correct.
703-
return dynd_ndt_type_from_cpp(_make_tuple(as_cpp_array(args)))
705+
for arg in args:
706+
_args.push_back(as_cpp_type(arg))
707+
708+
return dynd_ndt_type_from_cpp(_make_tuple(_args))
704709

705710
return dynd_ndt_type_from_cpp(_make_tuple())
706711

707712
def struct(**kwds):
708713
# TODO: require an ordered dict here since struct types are ordered.
709714
# TODO: Use something other than dynd arrays to pass these arguments.
710715
# See the comment in the tuple function for details.
716+
cdef vector[_type] _kwds
717+
711718
if kwds:
719+
for kwd in kwds.values():
720+
_kwds.push_back(as_cpp_type(kwd))
721+
712722
return dynd_ndt_type_from_cpp(_make_struct(
713-
as_cpp_array(list(kwds.keys())), as_cpp_array(list(kwds.values()))))
723+
as_cpp_array(list(kwds.keys())), _kwds))
714724

715725
return dynd_ndt_type_from_cpp(_make_struct())
716726

0 commit comments

Comments
 (0)