Skip to content

Commit df93d00

Browse files
Moved ndt_typ_from_pylist out of the type_conversions files.
Added a comment block about the purposes of the conversion files.
1 parent a83d77b commit df93d00

5 files changed

Lines changed: 58 additions & 26 deletions

File tree

dynd/include/array_conversions.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
//
2+
// Copyright (C) 2011-16 DyND Developers
3+
// BSD 2-Clause License, see LICENSE.txt
4+
//
5+
6+
/* This file exists to expose whatever functionality from
7+
* nd/array.pyx and nd/callable.pyx needs to be available
8+
* in the C++ portions of the codebase.
9+
* Currently it exists only as a means of
10+
* exporting conversions between the Cython wrapper
11+
* types and their corresponding C++ types.
12+
* Those conversions must be exported from Cython
13+
* to the C++ code since the ABI for the wrapper types
14+
* must be defined there (and depends on Cython's ABI for
15+
* extension types).
16+
*
17+
* The conversions defined here lazily load the modules
18+
* that expose the core ABI for the wrapper types.
19+
*/
20+
121
#pragma once
222

323
#include <Python.h>

dynd/include/type_conversions.hpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
//
2-
// Copyright (C) 2011-15 DyND Developers
2+
// Copyright (C) 2011-16 DyND Developers
33
// BSD 2-Clause License, see LICENSE.txt
44
//
5+
6+
/* This file exists to expose whatever functionality from
7+
* ndt/type.pyx needs to be available throughout the
8+
* C++ codebase. Currently it exists only as a means
9+
* of providing conversions between the Cython wrapper
10+
* types and their corresponding C++ types.
11+
* Those conversions must be exported from Cython
12+
* to the C++ code since the ABI for the wrapper types
13+
* must be defined there (and depends on Cython's ABI for
14+
* extension types).
15+
*
16+
* The conversions defined here lazily load the modules
17+
* that expose the core ABI for the wrapper types.
18+
*/
19+
520
#pragma once
621

722
#include <Python.h>
@@ -17,6 +32,5 @@ PYDYND_API PyTypeObject *get_type_pytypeobject();
1732
PYDYND_API PyObject *type_from_cpp(const dynd::ndt::type &);
1833
PYDYND_API dynd::ndt::type dynd_ndt_as_cpp_type(PyObject *);
1934
PYDYND_API dynd::ndt::type dynd_ndt_cpp_type_for(PyObject *);
20-
PYDYND_API dynd::ndt::type ndt_type_from_pylist(PyObject *);
2135

2236
} // namespace pydynd

dynd/include/type_deduction.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,6 @@ void register_nd_array_type_deduction(PyTypeObject *, dynd::ndt::type (*)(PyObje
161161

162162
PYDYND_API dynd::ndt::type xtype_for_prefix(PyObject *obj);
163163

164+
PYDYND_API dynd::ndt::type ndt_type_from_pylist(PyObject *);
165+
164166
} // namespace pydynd

dynd/src/type_conversions.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#include <cstdint>
2-
3-
#include "type_functions.hpp"
4-
5-
#include "type_deduction.hpp"
1+
#include "type_conversions.hpp"
62

73
#include "type_api.h"
84

@@ -68,22 +64,3 @@ dynd::ndt::type pydynd::dynd_ndt_cpp_type_for(PyObject *o)
6864
}
6965
return cpp_type_for(o);
7066
}
71-
72-
dynd::ndt::type pydynd::ndt_type_from_pylist(PyObject *obj)
73-
{
74-
// TODO: Add ability to specify access flags (e.g. immutable)
75-
// Do a pass through all the data to deduce its type and shape
76-
std::vector<intptr_t> shape;
77-
dynd::ndt::type tp = dynd::ndt::make_type<void>();
78-
Py_ssize_t size = PyList_GET_SIZE(obj);
79-
shape.push_back(size);
80-
for (Py_ssize_t i = 0; i < size; ++i) {
81-
deduce_pylist_shape_and_dtype(PyList_GET_ITEM(obj, i), shape, tp, 1);
82-
}
83-
84-
if (tp.get_id() == dynd::void_id) {
85-
tp = dynd::ndt::make_type<int32_t>();
86-
}
87-
88-
return dynd::ndt::make_type(shape.size(), shape.data(), tp);
89-
}

dynd/src/type_deduction.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,22 @@ dynd::ndt::type pydynd::xtype_for_prefix(PyObject *obj)
323323

324324
return dynd::ndt::type();
325325
}
326+
327+
dynd::ndt::type pydynd::ndt_type_from_pylist(PyObject *obj)
328+
{
329+
// TODO: Add ability to specify access flags (e.g. immutable)
330+
// Do a pass through all the data to deduce its type and shape
331+
std::vector<intptr_t> shape;
332+
dynd::ndt::type tp = dynd::ndt::make_type<void>();
333+
Py_ssize_t size = PyList_GET_SIZE(obj);
334+
shape.push_back(size);
335+
for (Py_ssize_t i = 0; i < size; ++i) {
336+
deduce_pylist_shape_and_dtype(PyList_GET_ITEM(obj, i), shape, tp, 1);
337+
}
338+
339+
if (tp.get_id() == dynd::void_id) {
340+
tp = dynd::ndt::make_type<int32_t>();
341+
}
342+
343+
return dynd::ndt::make_type(shape.size(), shape.data(), tp);
344+
}

0 commit comments

Comments
 (0)