Skip to content

Commit 8cdef57

Browse files
committed
Merge pull request #615 from skrah/separate_datashape
Separate ndt from array and callables.
2 parents 798b4ad + 9b2b8c4 commit 8cdef57

27 files changed

+375
-184
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ BreakBeforeBraces: Stroustrup
66
Cpp11BracedListStyle: true
77
NamespaceIndentation: Inner
88
AlwaysBreakTemplateDeclarations: true
9-
9+
ColumnLimit: 120

CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,26 +157,33 @@ cython_add_module(dynd.nd.array dynd.nd.array_pyx True
157157
dynd/src/array_as_pep3118.cpp
158158
dynd/src/array_as_numpy.cpp
159159
dynd/src/array_from_py.cpp
160-
dynd/src/array_from_py_typededuction.cpp
161160
dynd/src/assign.cpp
162-
dynd/src/conversions.cpp
161+
dynd/src/array_conversions.cpp
163162
dynd/src/copy_from_numpy_arrfunc.cpp
164163
dynd/src/init.cpp
165164
dynd/src/functional.cpp
166165
dynd/src/numpy_interop.cpp
166+
dynd/src/type_conversions.cpp
167+
dynd/src/type_deduction.cpp
167168
dynd/src/types/pyobject_type.cpp
168169
)
169170

170171
cython_add_module(dynd.config dynd.config_pyx True
171172
dynd/include/exception_translation.hpp
172-
dynd/src/conversions.cpp
173+
dynd/src/array_conversions.cpp
174+
dynd/src/type_conversions.cpp
175+
dynd/src/type_deduction.cpp
173176
${CMAKE_CURRENT_BINARY_DIR}/dynd/src/git_version.cpp
174177
)
175178

176179
foreach(module dynd.ndt.type dynd.ndt.json dynd.nd.callable dynd.nd.functional dynd.nd.registry)
177-
cython_add_module(${module} ${module}_pyx True dynd/src/conversions.cpp)
180+
cython_add_module(${module} ${module}_pyx True
181+
# Additional C++ source files:
182+
dynd/src/type_conversions.cpp
183+
dynd/src/array_conversions.cpp)
178184
endforeach(module)
179185

186+
180187
# Run a postprocess script to work around some Cython bugs
181188
# that haven't been fixed in the latest release.
182189
postprocess_cython( postprocess.py dynd.ndt.type_postprocess dynd.ndt.type_pyx dynd.ndt.type)

dynd/cpp/types/categorical_type.pxd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2+
# Disabled until categorical_type::make takes a std::vector<T>
3+
4+
"""
15
from ..type cimport type
26
from ..array cimport array
37
@@ -6,3 +10,4 @@ from ...config cimport translate_exception
610
cdef extern from "dynd/types/categorical_type.hpp" namespace "dynd::ndt":
711
type dynd_make_categorical_type "dynd::ndt::categorical_type::make" (array&) except +translate_exception
812
type factor_categorical(array&) except +translate_exception
13+
"""

dynd/include/conversions.hpp renamed to dynd/include/array_conversions.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44

55
#include <dynd/array.hpp>
66
#include <dynd/callable.hpp>
7-
#include <dynd/type.hpp>
87

98
#include "visibility.hpp"
109

1110
namespace pydynd {
1211

13-
PYDYND_API dynd::ndt::type &type_to_cpp_ref(PyObject *);
14-
PYDYND_API PyTypeObject *get_type_pytypeobject();
15-
PYDYND_API PyObject *type_from_cpp(const dynd::ndt::type &);
16-
PYDYND_API dynd::ndt::type dynd_ndt_as_cpp_type(PyObject *);
17-
PYDYND_API dynd::ndt::type dynd_ndt_cpp_type_for(PyObject *);
18-
1912
PYDYND_API dynd::nd::array &array_to_cpp_ref(PyObject *);
2013
PYDYND_API PyTypeObject *get_array_pytypeobject();
2114
PYDYND_API PyObject *array_from_cpp(const dynd::nd::array &);

dynd/include/array_from_py.hpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <dynd/types/type_id.hpp>
1212

13-
#include "array_from_py_typededuction.hpp"
1413
#include "visibility.hpp"
1514

1615
#include <dynd/array.hpp>
@@ -35,24 +34,6 @@ PYDYND_API dynd::nd::array array_from_py(PyObject *obj, uint32_t access_flags,
3534

3635
PYDYND_API dynd::ndt::type xtype_for_prefix(PyObject *obj);
3736

38-
inline dynd::ndt::type xarray_from_pylist(PyObject *obj)
39-
{
40-
// TODO: Add ability to specify access flags (e.g. immutable)
41-
// Do a pass through all the data to deduce its type and shape
42-
std::vector<intptr_t> shape;
43-
dynd::ndt::type tp(dynd::void_id);
44-
Py_ssize_t size = PyList_GET_SIZE(obj);
45-
shape.push_back(size);
46-
for (Py_ssize_t i = 0; i < size; ++i) {
47-
deduce_pylist_shape_and_dtype(PyList_GET_ITEM(obj, i), shape, tp, 1);
48-
}
49-
50-
if (tp.get_id() == dynd::void_id) {
51-
tp = dynd::ndt::type(dynd::int32_id);
52-
}
53-
54-
return dynd::ndt::make_type(shape.size(), shape.data(), tp);
55-
}
5637

5738
void init_array_from_py();
5839

dynd/include/array_functions.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
#include "array_as_numpy.hpp"
2727
#include "array_as_pep3118.hpp"
2828
#include "array_from_py.hpp"
29-
#include "conversions.hpp"
29+
#include "array_conversions.hpp"
30+
#include "utility_functions.hpp"
3031
#include "type_functions.hpp"
3132
#include "types/pyobject_type.hpp"
32-
#include "utility_functions.hpp"
3333
#include "visibility.hpp"
3434

3535
namespace pydynd {

dynd/include/kernels/apply_jit_kernel.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include <dynd/kernels/base_kernel.hpp>
44
#include <array_functions.hpp>
55
#include <utility_functions.hpp>
6-
#include <type_functions.hpp>
76

8-
#include "conversions.hpp"
7+
#include "type_functions.hpp"
8+
#include "array_conversions.hpp"
99

1010
namespace pydynd {
1111
namespace nd {

dynd/include/kernels/apply_pyobject_kernel.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <dynd/kernels/base_kernel.hpp>
44
#include <dynd/func/assignment.hpp>
55

6+
#include "array_conversions.hpp"
67
#include "type_functions.hpp"
78
#include "types/pyobject_type.hpp"
89

dynd/include/kernels/assign_from_pyobject_kernel.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
#include <dynd/types/categorical_type.hpp>
1515
#include <dynd/types/var_dim_type.hpp>
1616

17-
#include "array_from_py_typededuction.hpp"
1817
#include "array_functions.hpp"
19-
#include "conversions.hpp"
18+
#include "array_conversions.hpp"
2019
#include "copy_from_numpy_arrfunc.hpp"
2120
#include "type_functions.hpp"
21+
#include "type_deduction.hpp"
2222
#include "types/pyobject_type.hpp"
2323

2424
using namespace dynd;

dynd/include/numpy_interop.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <vector>
1616

1717
#include "utility_functions.hpp"
18+
#include "type_functions.hpp"
1819

1920
// Define this to 1 or 0 depending on whether numpy interop
2021
// should be compiled in.
@@ -48,6 +49,7 @@
4849
#include <dynd/array.hpp>
4950
#include <dynd/type.hpp>
5051
#include <dynd/types/fixed_string_type.hpp>
52+
#include <dynd/types/struct_type.hpp>
5153

5254
#include <numpy/ndarrayobject.h>
5355
#include <numpy/ufuncobject.h>
@@ -538,6 +540,4 @@ typedef struct {
538540
} // namespace pydynd
539541
#endif // !DYND_NUMPY_INTEROP
540542

541-
#include "type_functions.hpp"
542-
543543
#endif // _DYND__NUMPY_INTEROP_HPP_

dynd/include/type_conversions.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Copyright (C) 2011-15 DyND Developers
3+
// BSD 2-Clause License, see LICENSE.txt
4+
//
5+
#pragma once
6+
7+
#include <Python.h>
8+
9+
#include <dynd/type.hpp>
10+
11+
#include "visibility.hpp"
12+
13+
namespace pydynd {
14+
15+
PYDYND_API dynd::ndt::type &type_to_cpp_ref(PyObject *);
16+
PYDYND_API PyTypeObject *get_type_pytypeobject();
17+
PYDYND_API PyObject *type_from_cpp(const dynd::ndt::type &);
18+
PYDYND_API dynd::ndt::type dynd_ndt_as_cpp_type(PyObject *);
19+
PYDYND_API dynd::ndt::type dynd_ndt_cpp_type_for(PyObject *);
20+
PYDYND_API dynd::ndt::type ndt_type_from_pylist(PyObject *);
21+
22+
} // namespace pydynd

dynd/include/array_from_py_typededuction.hpp renamed to dynd/include/type_deduction.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22
// Copyright (C) 2011-15 DyND Developers
33
// BSD 2-Clause License, see LICENSE.txt
44
//
5-
6-
#ifndef _DYND__ARRAY_FROM_PY_TYPEDEDUCTION_HPP_
7-
#define _DYND__ARRAY_FROM_PY_TYPEDEDUCTION_HPP_
5+
#pragma once
86

97
#include <Python.h>
108

11-
#include <dynd/array.hpp>
129
#include <dynd/type.hpp>
1310
#include <dynd/type_promotion.hpp>
1411
#include <dynd/types/string_type.hpp>
1512
#include <dynd/types/type_id.hpp>
1613

17-
#include "conversions.hpp"
14+
#include "type_conversions.hpp"
1815

1916
namespace pydynd {
2017

@@ -168,5 +165,3 @@ bool broadcast_as_scalar(const dynd::ndt::type &tp, PyObject *obj);
168165
void init_array_from_py_typededuction();
169166

170167
} // namespace pydynd
171-
172-
#endif // _DYND__ARRAY_FROM_PY_TYPEDEDUCTION_HPP_

dynd/include/type_functions.hpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@
1313
#include <dynd/string_encodings.hpp>
1414
#include <dynd/type.hpp>
1515

16-
#include "conversions.hpp"
17-
#include "numpy_interop.hpp"
18-
#include "utility_functions.hpp"
19-
#include "visibility.hpp"
20-
21-
#include <dynd/shape_tools.hpp>
2216
#include <dynd/types/bytes_type.hpp>
2317
#include <dynd/types/fixed_dim_type.hpp>
2418
#include <dynd/types/fixed_string_type.hpp>
25-
//#include <dynd/types/pointer_type.hpp>
2619
#include <dynd/types/string_type.hpp>
2720
#include <dynd/types/struct_type.hpp>
2821
#include <dynd/types/type_type.hpp>
2922

23+
#include "utility_functions.hpp"
24+
#include "type_conversions.hpp"
25+
#include "visibility.hpp"
26+
27+
3028
// Python's datetime C API
3129
#include "datetime.h"
3230

31+
3332
namespace pydynd {
3433

3534
inline std::string _type_str(const dynd::ndt::type &d)
@@ -59,9 +58,6 @@ inline PyObject *_type_get_shape(const dynd::ndt::type &d)
5958
}
6059
}
6160

62-
inline dynd::ndt::type
63-
dynd_make_fixed_dim_type(PyObject *shape, const dynd::ndt::type &element_tp);
64-
6561
inline dynd::string_encoding_t encoding_from_pyobject(PyObject *encoding_obj)
6662
{
6763
// Default is utf-8
@@ -143,9 +139,9 @@ inline dynd::ndt::type dynd_make_fixed_string_type(intptr_t size,
143139
return dynd::ndt::fixed_string_type::make(size, encoding);
144140
}
145141

146-
inline dynd::ndt::type dynd_make_string_type(PyObject *encoding_obj)
142+
inline dynd::ndt::type dynd_make_string_type(PyObject *DYND_UNUSED(encoding_obj))
147143
{
148-
dynd::string_encoding_t encoding = encoding_from_pyobject(encoding_obj);
144+
// dynd::string_encoding_t encoding = encoding_from_pyobject(encoding_obj);
149145

150146
return dynd::ndt::make_type<dynd::ndt::string_type>();
151147
}
@@ -155,6 +151,18 @@ inline dynd::ndt::type dynd_make_pointer_type(const dynd::ndt::type &target_tp)
155151
return dynd::ndt::pointer_type::make(target_tp);
156152
}
157153

154+
inline void
155+
pyobject_as_vector__type(PyObject *list_of_types,
156+
std::vector<dynd::ndt::type> &vector_of__types)
157+
{
158+
Py_ssize_t size = PySequence_Size(list_of_types);
159+
vector_of__types.resize(size);
160+
for (Py_ssize_t i = 0; i < size; ++i) {
161+
pyobject_ownref item(PySequence_GetItem(list_of_types, i));
162+
vector_of__types[i] = dynd_ndt_as_cpp_type(item.get());
163+
}
164+
}
165+
158166
inline dynd::ndt::type dynd_make_struct_type(PyObject *field_types,
159167
PyObject *field_names)
160168
{

0 commit comments

Comments
 (0)