in src/mlio/recordio_protobuf_reader.cc [479:533]
bool Recordio_protobuf_reader::Decoder::decode(std::size_t row_idx, const Instance &instance)
{
row_idx_ = row_idx;
instance_ = &instance;
const aialgs::data::Record *proto_msg = parse_proto(instance);
if (proto_msg == nullptr) {
return false;
}
std::size_t num_features_read = 0;
for (auto &[label, value] : proto_msg->label()) {
if (!decode_feature("label_" + label, value)) {
return false;
}
num_features_read++;
}
for (auto &[label, value] : proto_msg->features()) {
if (!decode_feature(label, value)) {
return false;
}
num_features_read++;
}
const auto &schema = state_->reader->schema();
// Make sure that we read all features for which we have an
// attribute in the schema.
if (num_features_read == schema->attributes().size()) {
return true;
}
if (state_->warn_bad_instance || state_->error_bad_example) {
auto msg = fmt::format(
"The instance #{1:n} in the data store '{0}' has {2:n} feature(s) while it is expected to have {3:n} features.",
instance_->data_store().id(),
instance_->index(),
num_features_read,
schema->attributes().size());
if (state_->warn_bad_instance) {
logger::warn(msg);
}
if (state_->error_bad_example) {
throw Invalid_instance_error{msg};
}
}
return false;
}