MCPcopy Create free account
hub / github.com/LBANN/lbann / coerce

Method coerce

src/data_readers/data_reader_HDF5.cpp:757–801  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

755}
756
757void hdf5_data_reader::coerce(const conduit::Node& metadata,
758 hid_t file_handle,
759 const std::string& original_path,
760 const std::string& new_pathname,
761 conduit::Node& node)
762{
763 conduit::Node tmp;
764 conduit::relay::io::hdf5_read(file_handle, original_path, tmp);
765
766 // https://github.com/LLNL/conduit/blob/develop/src/libs/conduit/conduit_data_type.hpp
767 if (!tmp.dtype().is_number()) {
768 LBANN_ERROR(
769 "source data in field ",
770 original_path,
771 " is not integer or real format; ",
772 "please update the data set or experiment schema to exclude the field: ",
773 tmp.dtype().to_string());
774 }
775
776 const std::string& coerce_to =
777 conduit_to_string(metadata[HDF5_METADATA_KEY_COERCE]);
778
779 // Example of data coercion taken from
780 // https://github.com/LLNL/conduit/blob/develop/src/tests/conduit/t_conduit_node_to_array.cpp
781 conduit::DataType::TypeID coerced_tid;
782 if (coerce_to == "float") {
783 coerced_tid = conduit::DataType::FLOAT32_ID;
784 }
785 else if (coerce_to == "double") {
786 coerced_tid = conduit::DataType::FLOAT64_ID;
787 }
788 else if (coerce_to == "int") {
789 coerced_tid = conduit::DataType::INT32_ID;
790 }
791 else if (coerce_to == "long" || coerce_to == "int64") {
792 coerced_tid = conduit::DataType::INT64_ID;
793 }
794 else {
795 LBANN_ERROR("Un-implemented type requested for coercion: ",
796 coerce_to,
797 "; you need to update the data reader to support this");
798 }
799 // https://github.com/LLNL/conduit/blob/develop/src/libs/conduit/conduit_node.hpp#L3263
800 tmp.to_data_type(coerced_tid, node[new_pathname]);
801}
802
803void hdf5_data_reader::repack_image(conduit::Node& node,
804 const std::string& path,

Callers

nothing calls this directly

Calls 2

conduit_to_stringFunction · 0.85
to_stringMethod · 0.45

Tested by

no test coverage detected