Skip to content

Commit 3fae633

Browse files
authored
Update using-executorch-ios.md (#13142)
1 parent 047587e commit 3fae633

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

docs/source/using-executorch-ios.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ let imageBuffer: UnsafeMutableRawPointer = ... // Existing image buffer
243243
let inputTensor = Tensor<Float>(&imageBuffer, shape: [1, 3, 224, 224])
244244
245245
// Execute the 'forward' method with the given input tensor and get an output tensor back.
246-
let outputTensor: Tensor<Float> = try module.forward(inputTensor)!
246+
let outputTensor = try Tensor<Float>(module.forward(inputTensor))
247247
248248
// Copy the tensor data into logits array for easier access.
249249
let logits = outputTensor.scalars()
@@ -711,7 +711,10 @@ Inputs can be any type conforming to `ValueConvertible` (like `Tensor`, `Int`, `
711711
- `forward(_:)`: A convenient shortcut for executing the common "forward" method.
712712

713713
The API provides overloads for single inputs, multiple inputs, or no inputs.
714-
Outputs are always returned as an array of `Value`.
714+
715+
Outputs are returned in two ways:
716+
- As an array of `Value`s, letting you inspect and cast results yourself.
717+
- As your expected type. The generic overloads decode the result directly into your desired Swift type (such as a single `Tensor<Float>`, an array, or any custom type conforming to the `ValueSequenceConstructible` protocol). If the output doesn’t match the expected type (e.g. multiple Values returned when a single object is expected, or a tensor data type mismatch), an invalid type error is thrown.
715718

716719
Objective-C:
717720

@@ -777,6 +780,10 @@ do {
777780
let logits = try outputTensor.scalars()
778781
print("First 5 logits: \(logits.prefix(5))")
779782
}
783+
784+
// Try casting the outputs to a single typed object.
785+
let tensorOutput = try Tensor<Float>(module.forward(inputTensor1, inputTensor2))
786+
let logits = tensorOutput.scalars()
780787
} catch {
781788
print("Execution failed: \(error)")
782789
}

0 commit comments

Comments
 (0)