Skip to content

Commit 7d9a389

Browse files
committed
Merge pull request #708 from izaid/id2
Removed references to detail::infos
2 parents 51cdda5 + 622b4b1 commit 7d9a389

3 files changed

Lines changed: 64 additions & 22 deletions

File tree

dynd/cpp/type.pxd

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,3 @@ cdef extern from 'dynd/type.hpp' namespace 'dynd::ndt' nogil:
3636
type_id_t get_base_id() const
3737

3838
type make_type[T]() except +translate_exception
39-
40-
cppclass reg_info_t:
41-
type tp
42-
43-
# Ideally we wouldn't use the detail namespace, but this is currently
44-
# needed to map a type id back to the corresponding type.
45-
cdef extern from "<dynd/type.hpp>" nogil:
46-
# Function doesn't really exist.
47-
# Use this to avoid Cython's odd handling of lvalue references
48-
reg_info_t _get_reg_info "dynd::ndt::detail::infos().operator[]"(type_id_t) except +translate_exception

dynd/ndt/type.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ from ..cpp.types.callable_type cimport callable_type as _callable_type
3333
from ..cpp.types.string_type cimport string_type
3434
from ..cpp.types.bytes_type cimport bytes_type
3535
from ..cpp.types.fixed_bytes_type cimport fixed_bytes_type
36-
from ..cpp.type cimport make_type, _get_reg_info
36+
from ..cpp.type cimport make_type
3737
from ..cpp.complex cimport complex as dynd_complex
3838

3939
from ..config cimport translate_exception
@@ -726,8 +726,8 @@ cdef as_numba_type(_type tp):
726726
return _to_numba_type[tp.get_id()]
727727

728728
cdef _type from_numba_type(tp):
729-
730-
return _get_reg_info((<type_id_t> _from_numba_type[tp])).tp
729+
pass
730+
# return _get_reg_info((<type_id_t> _from_numba_type[tp])).tp
731731

732732
cdef _type cpp_type_for(object obj) except *:
733733
cdef _type tp = xtype_for_prefix(obj)

dynd/src/assign.cpp

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,65 @@
1818
using namespace std;
1919
using namespace dynd;
2020

21+
// This is a temporary thing until the type inheritance changes are finished
22+
static ndt::type type_for_id(type_id_t id)
23+
{
24+
switch (id) {
25+
case bool_id:
26+
return ndt::make_type<bool>();
27+
case int8_id:
28+
return ndt::make_type<int8_t>();
29+
case int16_id:
30+
return ndt::make_type<int16_t>();
31+
case int32_id:
32+
return ndt::make_type<int32_t>();
33+
case int64_id:
34+
return ndt::make_type<int64_t>();
35+
case int128_id:
36+
return ndt::make_type<int128>();
37+
case uint8_id:
38+
return ndt::make_type<uint8_t>();
39+
case uint16_id:
40+
return ndt::make_type<uint16_t>();
41+
case uint32_id:
42+
return ndt::make_type<uint32_t>();
43+
case uint64_id:
44+
return ndt::make_type<uint64_t>();
45+
case uint128_id:
46+
return ndt::make_type<uint128>();
47+
case float32_id:
48+
return ndt::make_type<float>();
49+
case float64_id:
50+
return ndt::make_type<double>();
51+
case complex_float32_id:
52+
return ndt::make_type<dynd::complex<float>>();
53+
case complex_float64_id:
54+
return ndt::make_type<dynd::complex<double>>();
55+
case bytes_id:
56+
return ndt::make_type<ndt::bytes_type>();
57+
case fixed_bytes_id:
58+
return ndt::make_type<ndt::fixed_bytes_kind_type>();
59+
case string_id:
60+
return ndt::make_type<ndt::string_type>();
61+
case fixed_string_id:
62+
return ndt::make_type<ndt::fixed_string_kind_type>();
63+
case option_id:
64+
return ndt::make_type<ndt::option_type>();
65+
case type_id:
66+
return ndt::make_type<ndt::type>();
67+
case tuple_id:
68+
return ndt::make_type<ndt::tuple_type>();
69+
case struct_id:
70+
return ndt::make_type<ndt::struct_type>();
71+
case fixed_dim_id:
72+
return ndt::make_type<ndt::fixed_dim_kind_type>();
73+
case var_dim_id:
74+
return ndt::make_type<ndt::var_dim_type>();
75+
default:
76+
throw std::runtime_error("unmappable type id " + std::to_string(id) + " in assign_init");
77+
}
78+
}
79+
2180
PYDYND_API void assign_init()
2281
{
2382
typedef type_sequence<bool, int8_t, int16_t, int32_t, int64_t, int128, uint8_t, uint16_t, uint32_t, uint64_t, uint128,
@@ -27,19 +86,12 @@ PYDYND_API void assign_init()
2786
types;
2887

2988
PyDateTime_IMPORT;
30-
// TODO: There should be an interface that allows adding overloads
31-
// based on type id rather than on actual type. The current interface
32-
// makes for a lot of mapping back and forth between types and their
33-
// corresponding type ids.
34-
// For now, just use the infos vector from the type registry to map
35-
// ids back to their corresponding types.
36-
auto infos = ndt::detail::infos();
3789

3890
for (const auto &pair : nd::callable::make_all<pydynd::nd::assign_from_pyobject_callable, types>()) {
39-
nd::assign.overload(infos[pair.first[0]].tp, {ndt::make_type<pyobject_type>()}, pair.second);
91+
nd::assign.overload(type_for_id(pair.first[0]), {ndt::make_type<pyobject_type>()}, pair.second);
4092
}
4193
for (const auto &pair : nd::callable::make_all<pydynd::nd::assign_to_pyobject_callable, types>()) {
42-
nd::assign.overload(ndt::make_type<pyobject_type>(), {infos[pair.first[0]].tp}, pair.second);
94+
nd::assign.overload(ndt::make_type<pyobject_type>(), {type_for_id(pair.first[0])}, pair.second);
4395
}
4496
}
4597

0 commit comments

Comments
 (0)