From 2faccae446e90c44ccd53e546f08f4fce1e1bef1 Mon Sep 17 00:00:00 2001 From: Ian Henriksen Date: Wed, 2 Mar 2016 17:14:34 -0700 Subject: [PATCH 1/3] Reorganized the pxd files in dynd/cpp to match their C++ counterparts in the core C++ library. Also moved pyobject_type.pxd out of the cpp directory entirely since it deals with python-specific functionality and could trigger an include from outside of the main dynd include directory if someone were to cimport from it. cimporting from it is fine in dynd-python, but that's not the kind of thing users should be doing right now. --- dynd/cpp/array.pxd | 2 +- dynd/cpp/{func => }/callable.pxd | 7 +++---- dynd/cpp/{func => }/callable_registry.pxd | 2 +- dynd/cpp/func/elwise.pxd | 2 +- dynd/cpp/func/reduction.pxd | 2 +- dynd/cpp/json_parser.pxd | 2 -- dynd/cpp/type.pxd | 2 +- .../{fixed_dim_kind_type.pxd => base_fixed_dim_type.pxd} | 0 dynd/nd/array.pxd | 2 +- dynd/nd/array.pyx | 5 ++--- dynd/nd/callable.pxd | 2 +- dynd/nd/callable.pyx | 2 +- dynd/nd/functional.pyx | 2 +- dynd/nd/registry.pyx | 4 ++-- dynd/ndt/type.pyx | 4 ++-- dynd/{cpp/types => }/pyobject_type.pxd | 2 -- 16 files changed, 18 insertions(+), 24 deletions(-) rename dynd/cpp/{func => }/callable.pxd (78%) rename dynd/cpp/{func => }/callable_registry.pxd (93%) rename dynd/cpp/types/{fixed_dim_kind_type.pxd => base_fixed_dim_type.pxd} (100%) rename dynd/{cpp/types => }/pyobject_type.pxd (81%) diff --git a/dynd/cpp/array.pxd b/dynd/cpp/array.pxd index 46e61cb7..368b645f 100644 --- a/dynd/cpp/array.pxd +++ b/dynd/cpp/array.pxd @@ -5,7 +5,7 @@ from libcpp.map cimport map from libcpp.string cimport string from libcpp.vector cimport vector from .type cimport type -from .func.callable cimport callable +from .callable cimport callable cdef extern from 'dynd/array.hpp' namespace 'dynd::nd' nogil: diff --git a/dynd/cpp/func/callable.pxd b/dynd/cpp/callable.pxd similarity index 78% rename from dynd/cpp/func/callable.pxd rename to dynd/cpp/callable.pxd index 8c471df2..44b86509 100644 --- a/dynd/cpp/func/callable.pxd +++ b/dynd/cpp/callable.pxd @@ -2,9 +2,9 @@ from libc.string cimport const_char from libcpp.pair cimport pair from libcpp cimport bool -from ...config cimport translate_exception -from ..array cimport array -from ..type cimport type +from ..config cimport translate_exception +from .array cimport array +from .type cimport type ctypedef const_char* const_charptr @@ -21,4 +21,3 @@ cdef extern from 'dynd/callable.hpp' namespace 'dynd::nd' nogil: callable make_callable 'dynd::nd::callable::make'[T](...) except +translate_exception - callable apply[T](T) except +translate_exception diff --git a/dynd/cpp/func/callable_registry.pxd b/dynd/cpp/callable_registry.pxd similarity index 93% rename from dynd/cpp/func/callable_registry.pxd rename to dynd/cpp/callable_registry.pxd index 98c33cb8..24af6ace 100644 --- a/dynd/cpp/func/callable_registry.pxd +++ b/dynd/cpp/callable_registry.pxd @@ -3,7 +3,7 @@ from libcpp.string cimport string from .callable cimport callable -from ...config cimport translate_exception +from ..config cimport translate_exception cdef extern from "dynd/callable_registry.hpp" namespace "dynd::nd" nogil: cdef cppclass callable_registry: diff --git a/dynd/cpp/func/elwise.pxd b/dynd/cpp/func/elwise.pxd index 90230daa..bf72d0a5 100644 --- a/dynd/cpp/func/elwise.pxd +++ b/dynd/cpp/func/elwise.pxd @@ -1,4 +1,4 @@ -from .callable cimport callable +from ..callable cimport callable from ...config cimport translate_exception cdef extern from 'dynd/func/elwise.hpp' namespace 'dynd::nd::functional' nogil: diff --git a/dynd/cpp/func/reduction.pxd b/dynd/cpp/func/reduction.pxd index 519c92e2..bd7b6c69 100644 --- a/dynd/cpp/func/reduction.pxd +++ b/dynd/cpp/func/reduction.pxd @@ -1,4 +1,4 @@ -from .callable cimport callable +from ..callable cimport callable from ...config cimport translate_exception cdef extern from 'dynd/func/reduction.hpp' namespace 'dynd::nd::functional' nogil: diff --git a/dynd/cpp/json_parser.pxd b/dynd/cpp/json_parser.pxd index 98fc5757..7b6bd00f 100644 --- a/dynd/cpp/json_parser.pxd +++ b/dynd/cpp/json_parser.pxd @@ -7,5 +7,3 @@ from .array cimport array cdef extern from 'dynd/json_parser.hpp' namespace 'dynd::ndt::json': type discover(string) except +translate_exception -#cdef extern from 'dynd/parse.hpp' namespace 'dynd::nd::json': -# array parse(type, string) except +translate_exception diff --git a/dynd/cpp/type.pxd b/dynd/cpp/type.pxd index a2e79019..75d0e31c 100644 --- a/dynd/cpp/type.pxd +++ b/dynd/cpp/type.pxd @@ -6,7 +6,7 @@ from .types.type_id cimport * from ..config cimport translate_exception from .array cimport array -from .func.callable cimport callable +from .callable cimport callable cdef extern from 'dynd/type.hpp' namespace 'dynd::ndt' nogil: cdef cppclass type: diff --git a/dynd/cpp/types/fixed_dim_kind_type.pxd b/dynd/cpp/types/base_fixed_dim_type.pxd similarity index 100% rename from dynd/cpp/types/fixed_dim_kind_type.pxd rename to dynd/cpp/types/base_fixed_dim_type.pxd diff --git a/dynd/nd/array.pxd b/dynd/nd/array.pxd index 55821ca7..c69605d4 100644 --- a/dynd/nd/array.pxd +++ b/dynd/nd/array.pxd @@ -1,7 +1,7 @@ from cpython.object cimport PyObject from ..cpp.array cimport array as _array -from ..cpp.func.callable cimport callable as _callable +from ..cpp.callable cimport callable as _callable from ..cpp.type cimport type as _type cdef api class array(object)[object dynd_nd_array_pywrapper, diff --git a/dynd/nd/array.pyx b/dynd/nd/array.pyx index 312f8554..cbf72d38 100644 --- a/dynd/nd/array.pyx +++ b/dynd/nd/array.pyx @@ -16,14 +16,13 @@ import numpy as _np from ..cpp.array cimport (groupby as dynd_groupby, array_add, array_subtract, array_multiply, array_divide, empty as cpp_empty, dtyped_zeros, dtyped_ones, dtyped_empty) -from ..cpp.func.callable cimport callable as _callable -from ..cpp.func.callable_registry cimport callable_registry +from ..cpp.callable_registry cimport callable_registry from ..cpp.type cimport get_builtin_type_dynamic_array_properties, make_type from ..cpp.types.categorical_type cimport dynd_make_categorical_type from ..cpp.types.datashape_formatter cimport format_datashape as dynd_format_datashape from ..cpp.types.type_id cimport * from ..cpp.view cimport view as _view -from ..cpp.types.pyobject_type cimport pyobject_id +from ..pyobject_type cimport pyobject_id from ..config cimport translate_exception from ..ndt.type cimport type as _py_type, dynd_ndt_type_to_cpp, as_cpp_type diff --git a/dynd/nd/callable.pxd b/dynd/nd/callable.pxd index f900b329..a3abffa2 100644 --- a/dynd/nd/callable.pxd +++ b/dynd/nd/callable.pxd @@ -1,4 +1,4 @@ -from ..cpp.func.callable cimport callable as _callable +from ..cpp.callable cimport callable as _callable cdef api class callable(object)[object dynd_nd_callable_pywrapper, type dynd_nd_callable_pywrapper_type]: diff --git a/dynd/nd/callable.pyx b/dynd/nd/callable.pyx index f71d9aa9..1a22b752 100644 --- a/dynd/nd/callable.pyx +++ b/dynd/nd/callable.pyx @@ -3,7 +3,7 @@ from libcpp.vector cimport vector from libcpp.pair cimport pair from ..cpp.array cimport array as _array -from ..cpp.func.callable cimport const_charptr +from ..cpp.callable cimport const_charptr from ..config cimport translate_exception from .array cimport as_cpp_array, dynd_nd_array_from_cpp diff --git a/dynd/nd/functional.pyx b/dynd/nd/functional.pyx index e163b35e..f68aa212 100644 --- a/dynd/nd/functional.pyx +++ b/dynd/nd/functional.pyx @@ -1,7 +1,7 @@ from libc.stdint cimport intptr_t from libcpp.vector cimport vector -from ..cpp.func.callable cimport callable as _callable +from ..cpp.callable cimport callable as _callable from ..cpp.type cimport type as _type from ..cpp.types.callable_type cimport make_callable from ..cpp.func.elwise cimport elwise as _elwise diff --git a/dynd/nd/registry.pyx b/dynd/nd/registry.pyx index 9def334e..e539874c 100644 --- a/dynd/nd/registry.pyx +++ b/dynd/nd/registry.pyx @@ -1,7 +1,7 @@ # cython: c_string_type=str, c_string_encoding=ascii -from ..cpp.func.callable cimport callable -from ..cpp.func.callable_registry cimport callable_registry +from ..cpp.callable cimport callable +from ..cpp.callable_registry cimport callable_registry from ..config cimport translate_exception from .callable cimport dynd_nd_callable_from_cpp diff --git a/dynd/ndt/type.pyx b/dynd/ndt/type.pyx index ab7319c7..a6cedb35 100644 --- a/dynd/ndt/type.pyx +++ b/dynd/ndt/type.pyx @@ -26,14 +26,14 @@ from ..cpp.type cimport make_type from ..cpp.types.datashape_formatter cimport format_datashape as dynd_format_datashape from ..cpp.types.categorical_type cimport dynd_make_categorical_type from ..cpp.types.fixed_bytes_type cimport make_fixed_bytes as dynd_make_fixed_bytes_type -from ..cpp.types.fixed_dim_kind_type cimport dynd_make_fixed_dim_kind_type +from ..cpp.types.base_fixed_dim_type cimport dynd_make_fixed_dim_kind_type from ..cpp.types.var_dim_type cimport dynd_make_var_dim_type from ..cpp.types.tuple_type cimport make_tuple as _make_tuple from ..cpp.types.struct_type cimport make_struct as _make_struct from ..cpp.types.callable_type cimport make_callable from ..cpp.types.string_type cimport string_type from ..cpp.types.bytes_type cimport make as make_bytes_type -from ..cpp.func.callable cimport callable as _callable +from ..cpp.callable cimport callable as _callable from ..cpp.type cimport make_type from ..cpp.complex cimport complex as dynd_complex diff --git a/dynd/cpp/types/pyobject_type.pxd b/dynd/pyobject_type.pxd similarity index 81% rename from dynd/cpp/types/pyobject_type.pxd rename to dynd/pyobject_type.pxd index f20d70d7..1581c3a6 100644 --- a/dynd/cpp/types/pyobject_type.pxd +++ b/dynd/pyobject_type.pxd @@ -1,5 +1,3 @@ -from ..type cimport type - cdef extern from 'types/pyobject_type.hpp': int pyobject_id From e326813900a9b62a25cc8d36de74c906d0439d66 Mon Sep 17 00:00:00 2001 From: Ian Henriksen Date: Wed, 2 Mar 2016 18:20:26 -0700 Subject: [PATCH 2/3] Add a minimal wrapper for apply. --- dynd/cpp/functional.pxd | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 dynd/cpp/functional.pxd diff --git a/dynd/cpp/functional.pxd b/dynd/cpp/functional.pxd new file mode 100644 index 00000000..60e12b49 --- /dev/null +++ b/dynd/cpp/functional.pxd @@ -0,0 +1,5 @@ +from ..config cimport translate_exception +from .callable cimport callable + +cdef extern from "dynd/functional.hpp" namespace "dynd::nd::functional" nogil: + callable apply(...) except +translate_exception From d456970472a1bdf31af3e6503b0434b4c83ab68a Mon Sep 17 00:00:00 2001 From: Ian Henriksen Date: Wed, 2 Mar 2016 18:25:27 -0700 Subject: [PATCH 3/3] Remove pxd reference to array::get_properties(). --- dynd/cpp/array.pxd | 3 --- 1 file changed, 3 deletions(-) diff --git a/dynd/cpp/array.pxd b/dynd/cpp/array.pxd index 368b645f..b4c24d27 100644 --- a/dynd/cpp/array.pxd +++ b/dynd/cpp/array.pxd @@ -5,7 +5,6 @@ from libcpp.map cimport map from libcpp.string cimport string from libcpp.vector cimport vector from .type cimport type -from .callable cimport callable cdef extern from 'dynd/array.hpp' namespace 'dynd::nd' nogil: @@ -31,8 +30,6 @@ cdef extern from 'dynd/array.hpp' namespace 'dynd::nd' nogil: array p(string) - map[string, callable] get_properties() - char *data() const const char *cdata() const