1818using namespace std ;
1919using 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+
2180PYDYND_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