int ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel *model, int32_t index,
const void *buffer, size_t length)
{
+ const bool isOptional = ((buffer == nullptr) && (length == 0));
+
if ((model == nullptr) || ((buffer == nullptr) && (length != 0)))
{
return ANEURALNETWORKS_UNEXPECTED_NULL;
}
auto &obj = model->deref().operands().at(ind);
- if (obj.operandSize() != length)
+ if ((obj.operandSize() != length) && !isOptional)
{
return ANEURALNETWORKS_BAD_DATA;
}
using ::neurun::graph::operand::CachedData;
using ::neurun::graph::operand::ExternalData;
+ // Remain operands.at(ind).data()->base() as nullptr for optional operand
+ // This will be filled when model finished
+ if (isOptional)
+ {
+ model->setOptionalOperand(ind);
+ }
+
// NNAPI spec in NeuralNetworks.h
// For values of length greater than ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES,
// the application is responsible for not changing the content of this region