// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
// Based on "crates/store/re_sdk_types/definitions/rerun/archetypes/tensor.fbs".

#include "tensor.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    Tensor Tensor::clear_fields() {
        auto archetype = Tensor();
        archetype.data =
            ComponentBatch::empty<rerun::components::TensorData>(Descriptor_data).value_or_throw();
        archetype.value_range =
            ComponentBatch::empty<rerun::components::ValueRange>(Descriptor_value_range)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> Tensor::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(2);
        if (data.has_value()) {
            columns.push_back(data.value().partitioned(lengths_).value_or_throw());
        }
        if (value_range.has_value()) {
            columns.push_back(value_range.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> Tensor::columns() {
        if (data.has_value()) {
            return columns(std::vector<uint32_t>(data.value().length(), 1));
        }
        if (value_range.has_value()) {
            return columns(std::vector<uint32_t>(value_range.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

    Result<Collection<ComponentBatch>> AsComponents<archetypes::Tensor>::as_batches(
        const archetypes::Tensor& archetype
    ) {
        using namespace archetypes;
        std::vector<ComponentBatch> cells;
        cells.reserve(2);

        if (archetype.data.has_value()) {
            cells.push_back(archetype.data.value());
        }
        if (archetype.value_range.has_value()) {
            cells.push_back(archetype.value_range.value());
        }

        return rerun::take_ownership(std::move(cells));
    }
} // namespace rerun
