Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions runtime/core/evalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

namespace executorch {
namespace runtime {

// Specialize for list of optional tensors, as nullptr is a valid std::nullopt.
// For non-optional types, nullptr is invalid.

template <>
executorch::aten::ArrayRef<std::optional<executorch::aten::Tensor>>
BoxedEvalueList<std::optional<executorch::aten::Tensor>>::get() const {
Expand All @@ -27,5 +31,26 @@ BoxedEvalueList<std::optional<executorch::aten::Tensor>>::get() const {
return executorch::aten::ArrayRef<std::optional<executorch::aten::Tensor>>{
unwrapped_vals_, wrapped_vals_.size()};
}

template <>
Result<executorch::aten::ArrayRef<std::optional<executorch::aten::Tensor>>>
BoxedEvalueList<std::optional<executorch::aten::Tensor>>::tryGet() const {
for (typename executorch::aten::ArrayRef<
std::optional<executorch::aten::Tensor>>::size_type i = 0;
i < wrapped_vals_.size();
i++) {
if (wrapped_vals_[i] == nullptr) {
unwrapped_vals_[i] = std::nullopt;
continue;
}
auto r = wrapped_vals_[i]->tryToOptional<executorch::aten::Tensor>();
if (!r.ok()) {
return r.error();
}
unwrapped_vals_[i] = std::move(r.get());
}
return executorch::aten::ArrayRef<std::optional<executorch::aten::Tensor>>{
unwrapped_vals_, wrapped_vals_.size()};
}
} // namespace runtime
} // namespace executorch
Loading
Loading