| 362 | |
| 363 | template <typename T> |
| 364 | mx::array array_from_list_impl( |
| 365 | T pl, |
| 366 | const PyScalarT& inferred_type, |
| 367 | std::optional<mx::Dtype> specified_type, |
| 368 | const mx::Shape& shape) { |
| 369 | // Make the array |
| 370 | switch (inferred_type) { |
| 371 | case pybool: { |
| 372 | std::vector<bool> vals; |
| 373 | fill_vector(pl, vals); |
| 374 | return mx::array(vals.begin(), shape, specified_type.value_or(mx::bool_)); |
| 375 | } |
| 376 | case pyint: { |
| 377 | auto dtype = specified_type.value_or(mx::int32); |
| 378 | if (dtype == mx::int64) { |
| 379 | std::vector<int64_t> vals; |
| 380 | fill_vector(pl, vals); |
| 381 | return mx::array(vals.begin(), shape, dtype); |
| 382 | } else if (dtype == mx::uint64) { |
| 383 | std::vector<uint64_t> vals; |
| 384 | fill_vector(pl, vals); |
| 385 | return mx::array(vals.begin(), shape, dtype); |
| 386 | } else if (dtype == mx::uint32) { |
| 387 | std::vector<uint32_t> vals; |
| 388 | fill_vector(pl, vals); |
| 389 | return mx::array(vals.begin(), shape, dtype); |
| 390 | } else if (mx::issubdtype(dtype, mx::inexact)) { |
| 391 | std::vector<float> vals; |
| 392 | fill_vector(pl, vals); |
| 393 | return mx::array(vals.begin(), shape, dtype); |
| 394 | } else { |
| 395 | std::vector<int> vals; |
| 396 | fill_vector(pl, vals); |
| 397 | return mx::array(vals.begin(), shape, dtype); |
| 398 | } |
| 399 | } |
| 400 | case pyfloat: { |
| 401 | auto out_type = specified_type.value_or(mx::float32); |
| 402 | if (out_type == mx::float64) { |
| 403 | std::vector<double> vals; |
| 404 | fill_vector(pl, vals); |
| 405 | return mx::array(vals.begin(), shape, out_type); |
| 406 | } else { |
| 407 | std::vector<float> vals; |
| 408 | fill_vector(pl, vals); |
| 409 | return mx::array(vals.begin(), shape, out_type); |
| 410 | } |
| 411 | } |
| 412 | case pycomplex: { |
| 413 | std::vector<std::complex<float>> vals; |
| 414 | fill_vector(pl, vals); |
| 415 | return mx::array( |
| 416 | reinterpret_cast<mx::complex64_t*>(vals.data()), |
| 417 | shape, |
| 418 | specified_type.value_or(mx::complex64)); |
| 419 | } |
| 420 | default: { |
| 421 | std::ostringstream msg; |
no test coverage detected