@@ -296,11 +296,11 @@ class ndarray : public ndarray_base {
296
296
297
297
ndarray (const int32 value) : data(value) {}
298
298
299
- ndarray (const int_ value) : data(value) {}
299
+ ndarray (const int_ value) : data(static_cast <T>( value) ) {}
300
300
301
301
ndarray (const float32 value) : data(value) {}
302
302
303
- ndarray (const float64 value) : data(value) {}
303
+ ndarray (const float64 value) : data(static_cast <T>( value) ) {}
304
304
305
305
ndarray (const pkpy::numpy::ndarray<T>& _arr) : data(_arr) {}
306
306
@@ -394,7 +394,9 @@ class ndarray : public ndarray_base {
394
394
}
395
395
396
396
py::object min () const override {
397
- if constexpr (std::is_same_v<T, bool_> || std::is_same_v<T, int8> || std::is_same_v<T, int16> ||
397
+ if constexpr (std::is_same_v<T, bool_>) {
398
+ return py::bool_ (data.min ());
399
+ } else if constexpr (std::is_same_v<T, int8> || std::is_same_v<T, int16> ||
398
400
std::is_same_v<T, int32> || std::is_same_v<T, int64>) {
399
401
return py::int_ (data.min ());
400
402
} else if constexpr (std::is_same_v<T, float32> || std::is_same_v<T, float64>) {
@@ -426,8 +428,10 @@ class ndarray : public ndarray_base {
426
428
}
427
429
428
430
py::object max () const override {
429
- if constexpr (std::is_same_v<T, bool_> || std::is_same_v<T, int8> || std::is_same_v<T, int16> ||
430
- std::is_same_v<T, int32> || std::is_same_v<T, int64>) {
431
+ if constexpr (std::is_same_v<T, bool_>) {
432
+ return py::bool_ (data.max ());
433
+ } else if constexpr (std::is_same_v<T, int8> || std::is_same_v<T, int16> ||
434
+ std::is_same_v<T, int32> || std::is_same_v<T, int64>) {
431
435
return py::int_ (data.max ());
432
436
} else if constexpr (std::is_same_v<T, float32> || std::is_same_v<T, float64>) {
433
437
return py::float_ (data.max ());
@@ -548,7 +552,7 @@ class ndarray : public ndarray_base {
548
552
std::is_same_v<T, int32> || std::is_same_v<T, int64>) {
549
553
return py::int_ (data.argmin ());
550
554
} else if constexpr (std::is_same_v<T, float32> || std::is_same_v<T, float64>) {
551
- return py::float_ (data.argmin ());
555
+ return py::int_ (data.argmin ());
552
556
} else {
553
557
throw std::runtime_error (" Unsupported type" );
554
558
}
@@ -561,7 +565,7 @@ class ndarray : public ndarray_base {
561
565
std::is_same_v<T, int32> || std::is_same_v<T, int64>) {
562
566
return py::int_ (data.argmax ());
563
567
} else if constexpr (std::is_same_v<T, float32> || std::is_same_v<T, float64>) {
564
- return py::float_ (data.argmax ());
568
+ return py::int_ (data.argmax ());
565
569
} else {
566
570
throw std::runtime_error (" Unsupported type" );
567
571
}
@@ -1910,7 +1914,7 @@ class ndarray : public ndarray_base {
1910
1914
}
1911
1915
} else if constexpr (std::is_same_v<T, float64>) {
1912
1916
if (data.ndim () == 1 ) {
1913
- data.set_item (index, value);
1917
+ data.set_item (index, static_cast <T>( value) );
1914
1918
} else {
1915
1919
data.set_item (index, (pkpy::numpy::adapt<int_>(std::vector{value})).astype <float64>());
1916
1920
}
@@ -1958,7 +1962,7 @@ class ndarray : public ndarray_base {
1958
1962
}
1959
1963
} else if constexpr (std::is_same_v<T, int_>) {
1960
1964
if (data.ndim () == 1 ) {
1961
- data.set_item (index, value);
1965
+ data.set_item (index, static_cast <T>( value) );
1962
1966
} else {
1963
1967
data.set_item (index, (pkpy::numpy::adapt<float64>(std::vector{value})).astype <int_>());
1964
1968
}
@@ -2010,13 +2014,13 @@ class ndarray : public ndarray_base {
2010
2014
data.set_item (index, (pkpy::numpy::adapt<int_>(std::vector{value})).astype <float64>());
2011
2015
}
2012
2016
} else if (indices.size () == 2 && indices.size () <= data.ndim ())
2013
- data.set_item_2d (indices[0 ], indices[1 ], value);
2017
+ data.set_item_2d (indices[0 ], indices[1 ], static_cast <T>( value) );
2014
2018
else if (indices.size () == 3 && indices.size () <= data.ndim ())
2015
- data.set_item_3d (indices[0 ], indices[1 ], indices[2 ], value);
2019
+ data.set_item_3d (indices[0 ], indices[1 ], indices[2 ], static_cast <T>( value) );
2016
2020
else if (indices.size () == 4 && indices.size () <= data.ndim ())
2017
- data.set_item_4d (indices[0 ], indices[1 ], indices[2 ], indices[3 ], value);
2021
+ data.set_item_4d (indices[0 ], indices[1 ], indices[2 ], indices[3 ], static_cast <T>( value) );
2018
2022
else if (indices.size () == 5 && indices.size () <= data.ndim ())
2019
- data.set_item_5d (indices[0 ], indices[1 ], indices[2 ], indices[3 ], indices[4 ], value);
2023
+ data.set_item_5d (indices[0 ], indices[1 ], indices[2 ], indices[3 ], indices[4 ], static_cast <T>( value) );
2020
2024
}
2021
2025
2022
2026
void set_item_tuple_float (py::tuple args, float64 value) override {
@@ -2032,13 +2036,13 @@ class ndarray : public ndarray_base {
2032
2036
data.set_item (index, (pkpy::numpy::adapt<float64>(std::vector{value})).astype <int_>());
2033
2037
}
2034
2038
} else if (indices.size () == 2 && indices.size () <= data.ndim ())
2035
- data.set_item_2d (indices[0 ], indices[1 ], value);
2039
+ data.set_item_2d (indices[0 ], indices[1 ], static_cast <T>( value) );
2036
2040
else if (indices.size () == 3 && indices.size () <= data.ndim ())
2037
- data.set_item_3d (indices[0 ], indices[1 ], indices[2 ], value);
2041
+ data.set_item_3d (indices[0 ], indices[1 ], indices[2 ], static_cast <T>( value) );
2038
2042
else if (indices.size () == 4 && indices.size () <= data.ndim ())
2039
- data.set_item_4d (indices[0 ], indices[1 ], indices[2 ], indices[3 ], value);
2043
+ data.set_item_4d (indices[0 ], indices[1 ], indices[2 ], indices[3 ], static_cast <T>( value) );
2040
2044
else if (indices.size () == 5 && indices.size () <= data.ndim ())
2041
- data.set_item_5d (indices[0 ], indices[1 ], indices[2 ], indices[3 ], indices[4 ], value);
2045
+ data.set_item_5d (indices[0 ], indices[1 ], indices[2 ], indices[3 ], indices[4 ], static_cast <T>( value) );
2042
2046
}
2043
2047
2044
2048
void set_item_vector_int1 (const std::vector<int >& indices, int_ value) override {
0 commit comments