Skip to content

Commit 7079e65

Browse files
committed
Merge pull request #607 from izaid/kind2
Removed uses of get_kind()
2 parents 387b11e + 50758d9 commit 7079e65

7 files changed

Lines changed: 45 additions & 48 deletions

dynd/include/array_functions.hpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ inline dynd::nd::array make_strided_array(const dynd::ndt::type &dtp,
5353

5454
dynd::intrusive_ptr<dynd::memory_block_data> result;
5555
char *data_ptr = NULL;
56-
if (array_tp.get_kind() == dynd::memory_kind) {
56+
if (array_tp.get_base_id() == dynd::memory_id) {
5757
result = dynd::make_array_memory_block(array_tp.get_arrmeta_size());
5858
array_tp.extended<dynd::ndt::base_memory_type>()->data_alloc(&data_ptr,
5959
data_size);
@@ -66,7 +66,7 @@ inline dynd::nd::array make_strided_array(const dynd::ndt::type &dtp,
6666
}
6767

6868
if (array_tp.get_flags() & dynd::type_flag_zeroinit) {
69-
if (array_tp.get_kind() == dynd::memory_kind) {
69+
if (array_tp.get_base_id() == dynd::memory_id) {
7070
array_tp.extended<dynd::ndt::base_memory_type>()->data_zeroinit(
7171
data_ptr, data_size);
7272
}
@@ -163,12 +163,12 @@ inline std::string array_repr(const dynd::nd::array &n)
163163
inline PyObject *array_nonzero(const dynd::nd::array &n)
164164
{
165165
// Implements the nonzero/conversion to boolean slot
166-
switch (n.get_type().value_type().get_kind()) {
167-
case dynd::bool_kind:
168-
case dynd::uint_kind:
169-
case dynd::sint_kind:
170-
case dynd::real_kind:
171-
case dynd::complex_kind:
166+
switch (n.get_type().value_type().get_base_id()) {
167+
case dynd::bool_kind_id:
168+
case dynd::uint_kind_id:
169+
case dynd::int_kind_id:
170+
case dynd::float_kind_id:
171+
case dynd::complex_kind_id:
172172
// Follow Python in not raising errors here
173173
if (n.as<bool>(dynd::assign_error_nocheck)) {
174174
Py_INCREF(Py_True);
@@ -178,7 +178,7 @@ inline PyObject *array_nonzero(const dynd::nd::array &n)
178178
Py_INCREF(Py_False);
179179
return Py_False;
180180
}
181-
case dynd::string_kind: {
181+
case dynd::string_kind_id: {
182182
// Follow Python, return True if the string is nonempty, False otherwise
183183
dynd::nd::array n_eval = n.eval();
184184
const dynd::ndt::base_string_type *bsd =
@@ -195,7 +195,7 @@ inline PyObject *array_nonzero(const dynd::nd::array &n)
195195
return Py_False;
196196
}
197197
}
198-
case dynd::bytes_kind: {
198+
case dynd::bytes_kind_id: {
199199
// Return True if there is a non-zero byte, False otherwise
200200
dynd::nd::array n_eval = n.eval();
201201
const dynd::ndt::base_bytes_type *bbd =
@@ -215,12 +215,6 @@ inline PyObject *array_nonzero(const dynd::nd::array &n)
215215
Py_INCREF(Py_False);
216216
return Py_False;
217217
}
218-
case dynd::datetime_kind: {
219-
// Dates and datetimes are never zero
220-
// TODO: What to do with NA value?
221-
Py_INCREF(Py_True);
222-
return Py_True;
223-
}
224218
default:
225219
// TODO: Implement nd.any and nd.all, mention them
226220
// here like NumPy does.
@@ -401,7 +395,7 @@ inline dynd::nd::array nd_fields(const dynd::nd::array &n, PyObject *field_list)
401395

402396
// TODO: Move this implementation into dynd
403397
dynd::ndt::type fdt = n.get_dtype();
404-
if (fdt.get_kind() != dynd::struct_kind) {
398+
if (fdt.get_id() != dynd::struct_id) {
405399
std::stringstream ss;
406400
ss << "nd.fields must be given a dynd array of 'struct' kind, not ";
407401
ss << fdt;
@@ -457,7 +451,7 @@ inline dynd::nd::array nd_fields(const dynd::nd::array &n, PyObject *field_list)
457451
char *dst_arrmeta = result.get()->metadata();
458452
const char *src_arrmeta = n.get()->metadata();
459453
while (tmp_dt.get_ndim() > 0) {
460-
if (tmp_dt.get_kind() != dynd::dim_kind) {
454+
if (tmp_dt.get_base_id() != dynd::dim_kind_id) {
461455
throw std::runtime_error(
462456
"nd.fields doesn't support dimensions with pointers yet");
463457
}

dynd/include/kernels/assign_from_pyobject_kernel.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ struct assign_from_pyobject_kernel<option_id, any_kind_id>
531531
pydynd::nd::typed_data_assign(dst_tp, dst_arrmeta, dst,
532532
pydynd::array_to_cpp_ref(src_obj));
533533
}
534-
else if (dst_tp.get_kind() != dynd::string_kind &&
534+
else if (dst_tp.get_base_id() != dynd::string_kind_id &&
535535
PyUnicode_Check(src_obj)) {
536536
// Copy from the string
537537
pydynd::pyobject_ownref utf8(PyUnicode_AsUTF8String(src_obj));
@@ -549,7 +549,7 @@ struct assign_from_pyobject_kernel<option_id, any_kind_id>
549549
reinterpret_cast<const char *>(&str_d));
550550
#if PY_VERSION_HEX < 0x03000000
551551
}
552-
else if (dst_tp.get_kind() != dynd::string_kind &&
552+
else if (dst_tp.get_base_id() != dynd::string_kind_id &&
553553
PyString_Check(src_obj)) {
554554
// Copy from the string
555555
char *s = NULL;

dynd/include/kernels/assign_to_pyarrayobject_kernel.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ struct assign_to_pyarrayobject_kernel
8282
}
8383

8484
if (PyDataType_HASFIELDS(dtype)) {
85-
if (src_tp[0].get_kind() != dynd::struct_kind &&
86-
src_tp[0].get_kind() != dynd::tuple_kind) {
85+
if (src_tp[0].get_id() != dynd::struct_id &&
86+
src_tp[0].get_id() != dynd::tuple_id) {
8787
std::stringstream ss;
8888
pydynd::pyobject_ownref dtype_str(PyObject_Str((PyObject *)dtype));
8989
ss << "Cannot assign from source dynd type " << src_tp[0]
@@ -110,7 +110,7 @@ struct assign_to_pyarrayobject_kernel
110110
// Permute the numpy fields to match with the dynd fields
111111
std::vector<PyArray_Descr *> field_dtypes;
112112
std::vector<size_t> field_offsets;
113-
if (src_tp[0].get_kind() == dynd::struct_kind) {
113+
if (src_tp[0].get_id() == dynd::struct_id) {
114114
field_dtypes.resize(field_count);
115115
field_offsets.resize(field_count);
116116
for (intptr_t i = 0; i < field_count; ++i) {

dynd/include/numpy_interop.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,18 +456,18 @@ dynd::ndt::type array_from_numpy_scalar2(PyObject *obj);
456456
*/
457457
inline char numpy_kindchar_of(const dynd::ndt::type &d)
458458
{
459-
switch (d.get_kind()) {
460-
case dynd::bool_kind:
459+
switch (d.get_base_id()) {
460+
case dynd::bool_kind_id:
461461
return 'b';
462-
case dynd::sint_kind:
462+
case dynd::int_kind_id:
463463
return 'i';
464464
case dynd::uint_kind:
465465
return 'u';
466-
case dynd::real_kind:
466+
case dynd::float_kind_id:
467467
return 'f';
468-
case dynd::complex_kind:
468+
case dynd::complex_kind_id:
469469
return 'c';
470-
case dynd::string_kind:
470+
case dynd::string_kind_id:
471471
if (d.get_id() == dynd::fixed_string_id) {
472472
const dynd::ndt::base_string_type *esd =
473473
d.extended<dynd::ndt::base_string_type>();

dynd/src/array_as_numpy.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static void make_numpy_dtype_for_copy(pyobject_ownref *out_numpy_dtype,
226226
}
227227
}
228228

229-
if (dt.get_kind() == expr_kind) {
229+
if (dt.get_base_id() == expr_kind_id) {
230230
// Convert the value type for the copy
231231
make_numpy_dtype_for_copy(out_numpy_dtype, ndim, dt.value_type(), NULL);
232232
return;
@@ -433,7 +433,7 @@ static void as_numpy_analysis(pyobject_ownref *out_numpy_dtype,
433433
}
434434
}
435435

436-
if (dt.get_kind() == expr_kind) {
436+
if (dt.get_base_id() == expr_kind_id) {
437437
// If none of the prior checks caught this expression,
438438
// a copy is required.
439439
out_numpy_dtype->clear();
@@ -545,12 +545,12 @@ PyObject *pydynd::array_as_numpy(PyObject *a_obj, bool allow_copy)
545545
// Because 'allow_copy' is true
546546
// we can evaluate any expressions and
547547
// make copies of strings
548-
if (a.get_type().get_kind() == expr_kind) {
548+
if (a.get_type().get_base_id() == expr_kind_id) {
549549
// If it's an expression kind
550550
pyobject_ownref n_tmp(pydynd::array_from_cpp(a.eval()));
551551
return array_as_numpy(n_tmp.get(), true);
552552
}
553-
else if (a.get_type().get_kind() == string_kind) {
553+
else if (a.get_type().get_base_id() == string_kind_id) {
554554
nd::array res = nd::empty(ndt::make_type<pyobject_type>());
555555
res.assign(a);
556556
PyObject *res_obj = *reinterpret_cast<PyObject **>(res.data());

dynd/src/array_from_py_typededuction.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ void pydynd::init_array_from_py_typededuction()
3333

3434
size_t pydynd::get_nonragged_dim_count(const ndt::type &tp, size_t max_count)
3535
{
36-
switch (tp.get_kind()) {
37-
case kind_kind:
38-
case pattern_kind:
36+
if (tp.is_symbolic()) {
3937
if (tp.is_scalar()) {
4038
return 0;
4139
}
42-
case dim_kind:
40+
}
41+
42+
if (!tp.is_scalar()) {
4343
if (max_count <= 1) {
4444
return max_count;
4545
}
@@ -50,8 +50,11 @@ size_t pydynd::get_nonragged_dim_count(const ndt::type &tp, size_t max_count)
5050
->get_element_type(),
5151
max_count - 1));
5252
}
53-
case struct_kind:
54-
case tuple_kind:
53+
}
54+
55+
switch (tp.get_id()) {
56+
case struct_id:
57+
case tuple_id:
5558
if (max_count <= 1) {
5659
return max_count;
5760
}
@@ -150,7 +153,7 @@ void pydynd::deduce_pyseq_shape_using_dtype(PyObject *obj, const ndt::type &tp,
150153
if (initial_pass) {
151154
shape.push_back(size);
152155
}
153-
else if (tp.get_kind() == struct_kind || tp.get_kind() == tuple_kind) {
156+
else if (tp.get_id() == struct_id || tp.get_id() == tuple_id) {
154157
// Signal that this is a dimension which is sometimes scalar, to allow
155158
// for
156159
// raggedness in the struct type's fields
@@ -176,7 +179,7 @@ void pydynd::deduce_pyseq_shape_using_dtype(PyObject *obj, const ndt::type &tp,
176179
}
177180
}
178181
else {
179-
if (PyDict_Check(obj) && tp.get_kind() == struct_kind) {
182+
if (PyDict_Check(obj) && tp.get_id() == struct_id) {
180183
if (shape.size() == current_axis) {
181184
shape.push_back(pydynd_shape_deduction_dict);
182185
}
@@ -185,7 +188,7 @@ void pydynd::deduce_pyseq_shape_using_dtype(PyObject *obj, const ndt::type &tp,
185188
}
186189
}
187190
else if (shape.size() != current_axis) {
188-
if (tp.get_kind() == struct_kind || tp.get_kind() == tuple_kind) {
191+
if (tp.get_id() == struct_id || tp.get_id() == tuple_id) {
189192
shape[current_axis] = pydynd_shape_deduction_ragged;
190193
}
191194
else {
@@ -207,10 +210,10 @@ static intptr_t get_leading_dim_count(const dynd::ndt::type &tp)
207210
if (ndim) {
208211
return ndim + get_leading_dim_count(tp.get_dtype());
209212
}
210-
else if (tp.get_kind() == expr_kind) {
213+
else if (tp.get_base_id() == expr_kind_id) {
211214
return get_leading_dim_count(tp.value_type());
212215
}
213-
else if (tp.get_kind() == tuple_kind || tp.get_kind() == struct_kind) {
216+
else if (tp.get_id() == tuple_id || tp.get_id() == struct_id) {
214217
if (tp.extended<ndt::tuple_type>()->get_field_count() == 0) {
215218
return 1;
216219
}
@@ -234,7 +237,7 @@ bool pydynd::broadcast_as_scalar(const dynd::ndt::type &tp, PyObject *obj)
234237
for (;;) {
235238
// Don't treat these types as sequences
236239
if (PyDict_Check(v)) {
237-
if (tp.get_dtype().get_kind() == struct_kind) {
240+
if (tp.get_dtype().get_id() == struct_id) {
238241
// If the object to assign to a dynd struct ends in a dict, apply
239242
// the dict as the struct's value
240243
return (tp.get_ndim() > obj_ndim);

dynd/src/copy_from_numpy_arrfunc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ void pydynd::nd::copy_from_numpy_kernel::instantiate(
7171
return;
7272
}
7373
else if (PyDataType_HASFIELDS(dtype)) {
74-
if (dst_tp.get_kind() != dynd::struct_kind &&
75-
dst_tp.get_kind() != dynd::tuple_kind) {
74+
if (dst_tp.get_id() != dynd::struct_id &&
75+
dst_tp.get_id() != dynd::tuple_id) {
7676
stringstream ss;
7777
ss << "Cannot assign from numpy type " << pyobject_repr((PyObject *)dtype)
7878
<< " to dynd type " << dst_tp;
@@ -97,7 +97,7 @@ void pydynd::nd::copy_from_numpy_kernel::instantiate(
9797
// Permute the numpy fields to match with the dynd fields
9898
vector<PyArray_Descr *> field_dtypes;
9999
vector<size_t> field_offsets;
100-
if (dst_tp.get_kind() == dynd::struct_kind) {
100+
if (dst_tp.get_id() == dynd::struct_id) {
101101
field_dtypes.resize(field_count);
102102
field_offsets.resize(field_count);
103103
for (intptr_t i = 0; i < field_count; ++i) {

0 commit comments

Comments
 (0)