MCPcopy Create free account
hub / github.com/activeloopai/deeplake / value

Method value

cpp/nd/array.hpp:578–626  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 5

byte_1_valueMethod · 0.45
byte_2_valueMethod · 0.45
byte_4_valueMethod · 0.45
byte_8_valueMethod · 0.45
dict_valueMethod · 0.45

Calls 4

dtype_is_numericFunction · 0.85
non_numeric_dtypeClass · 0.85
unknown_dtypeClass · 0.85
dtypeEnum · 0.70

Tested by

no test coverage detected