bool Recordio_protobuf_reader::Decoder::append_to_builder()

in src/mlio/recordio_protobuf_reader.cc [802:850]


bool Recordio_protobuf_reader::Decoder::append_to_builder(const Protobuf_tensor &tensor) const
{
    if (tensor.keys_size() != tensor.values_size()) {
        if (state_->warn_bad_instance || state_->error_bad_example) {
            auto msg = fmt::format(
                "The sparse feature '{2}' of the instance #{1:n} in the data store '{0}' has {3:n} key(s) but {4:n} value(s).",
                instance_->data_store().id(),
                instance_->index(),
                attr_->name(),
                tensor.keys_size(),
                tensor.values_size());

            if (state_->warn_bad_instance) {
                logger::warn(msg);
            }

            if (state_->error_bad_example) {
                throw Invalid_instance_error{msg};
            }
        }

        return false;
    }

    auto &builder =
        static_cast<Coo_tensor_builder_impl<dt> &>(*state_->coo_tensor_builders[attr_idx_]);

    if (builder.append(tensor.values(), tensor.keys())) {
        return true;
    }

    if (state_->warn_bad_instance || state_->error_bad_example) {
        auto msg = fmt::format(
            "The sparse feature '{2}' of the instance #{1:n} in the data store '{0}' has one or more invalid keys.",
            instance_->data_store().id(),
            instance_->index(),
            attr_->name());

        if (state_->warn_bad_instance) {
            logger::warn(msg);
        }

        if (state_->error_bad_example) {
            throw Invalid_instance_error{msg};
        }
    }

    return false;
}