| 576 | |
| 577 | template <typename T> |
| 578 | inline T value(int64_t index) const |
| 579 | { |
| 580 | if constexpr (!dtype_is_numeric(dtype_enum_v<T>)) { |
| 581 | throw non_numeric_dtype(dtype_to_str(dtype_enum_v<T>)); |
| 582 | } else { |
| 583 | if (is_dynamic()) { |
| 584 | return dynamic_value<T>(index); |
| 585 | } |
| 586 | ASSERT(index >= 0); |
| 587 | ASSERT(index < volume()); |
| 588 | switch (dtype()) { |
| 589 | case dtype::boolean: |
| 590 | return static_cast<T>(base::bit_cast<bool>(byte_1_value(index))); |
| 591 | case dtype::uint8: |
| 592 | return static_cast<T>(base::bit_cast<uint8_t>(byte_1_value(index))); |
| 593 | case dtype::int8: |
| 594 | return static_cast<T>(base::bit_cast<int8_t>(byte_1_value(index))); |
| 595 | case dtype::uint16: |
| 596 | return static_cast<T>(base::bit_cast<uint16_t>(byte_2_value(index))); |
| 597 | case dtype::int16: |
| 598 | return static_cast<T>(base::bit_cast<int16_t>(byte_2_value(index))); |
| 599 | case dtype::uint32: |
| 600 | return static_cast<T>(base::bit_cast<uint32_t>(byte_4_value(index))); |
| 601 | case dtype::int32: |
| 602 | return static_cast<T>(base::bit_cast<int32_t>(byte_4_value(index))); |
| 603 | case dtype::uint64: |
| 604 | return static_cast<T>(base::bit_cast<uint64_t>(byte_8_value(index))); |
| 605 | case dtype::int64: |
| 606 | return static_cast<T>(base::bit_cast<int64_t>(byte_8_value(index))); |
| 607 | case dtype::bfloat16: |
| 608 | return static_cast<T>(base::bit_cast<base::bfloat16>(byte_2_value(index))); |
| 609 | case dtype::float16: |
| 610 | return static_cast<T>(base::bit_cast<base::half>(byte_2_value(index))); |
| 611 | case dtype::float32: |
| 612 | return static_cast<T>(base::bit_cast<float>(byte_4_value(index))); |
| 613 | case dtype::float64: |
| 614 | return static_cast<T>(base::bit_cast<double>(byte_8_value(index))); |
| 615 | case dtype::string: |
| 616 | throw non_numeric_dtype(dtype_to_str(dtype::string)); |
| 617 | case dtype::object: |
| 618 | throw non_numeric_dtype(dtype_to_str(dtype::object)); |
| 619 | case dtype::byte: |
| 620 | throw non_numeric_dtype(dtype_to_str(dtype::byte)); |
| 621 | case dtype::unknown: |
| 622 | throw unknown_dtype(); |
| 623 | } |
| 624 | return T(); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | dict dict_value(int64_t index) const; |
| 629 |
no test coverage detected