Skip to content
Merged
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
120 changes: 120 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorch+Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,123 @@ public extension Module {
try execute("forward")
}
}

@available(*, deprecated, message: "This API is experimental.")
public extension Module {
/// Sets a single input value for a method at the specified index.
///
/// - Parameters:
/// - value: The input as a `ValueConvertible`.
/// - method: The method name.
/// - index: Zero-based input index.
/// - Throws: If setting the input fails.
func setInput(_ value: ValueConvertible, for method: String, at index: Int) throws {
try __setInput(value.asValue(), forMethod: method, at: index)
}

/// Sets a single input value for a method at index 0.
///
/// - Parameters:
/// - value: The input as a `ValueConvertible`.
/// - method: The method name.
/// - Throws: If setting the input fails.
func setInput(_ value: ValueConvertible, for method: String) throws {
try setInput(value, for: method, at: 0)
}

/// Sets a single input value for the "forward" method at the specified index.
///
/// - Parameters:
/// - value: The input as a `ValueConvertible`.
/// - index: Zero-based input index.
/// - Throws: If setting the input fails.
func setInput(_ value: ValueConvertible, at index: Int) throws {
try setInput(value, for: "forward", at: index)
}

/// Sets the first input value (index 0) for the "forward" method.
///
/// - Parameter value: The input as a `ValueConvertible`.
/// - Throws: If setting the input fails.
func setInput(_ value: ValueConvertible) throws {
try setInput(value, for: "forward", at: 0)
}

/// Sets all input values for a method.
///
/// - Parameters:
/// - values: The inputs as an array of `ValueConvertible`.
/// - method: The method name.
/// - Throws: If setting the inputs fails.
func setInputs(_ values: [ValueConvertible], for method: String) throws {
try __setInputs(values.map { $0.asValue() }, forMethod: method)
}

/// Sets all input values for the "forward" method.
///
/// - Parameter values: The inputs as an array of `ValueConvertible`.
/// - Throws: If setting the inputs fails.
func setInputs(_ values: [ValueConvertible]) throws {
try setInputs(values, for: "forward")
}

/// Sets all input values for a method using variadic arguments.
///
/// - Parameters:
/// - values: The inputs as a variadic list of `ValueConvertible`.
/// - method: The method name.
/// - Throws: If setting the inputs fails.
func setInputs(_ values: ValueConvertible..., for method: String) throws {
try setInputs(values, for: method)
}

/// Sets all input values for the "forward" method using variadic arguments.
///
/// - Parameter values: The inputs as a variadic list of `ValueConvertible`.
/// - Throws: If setting the inputs fails.
func setInputs(_ values: ValueConvertible...) throws {
try setInputs(values, for: "forward")
}

/// Sets the output location for a method at the specified index.
///
/// Only tensor outputs are supported. The provided value must wrap a tensor
/// with compatible shape and data type for the method’s output slot.
///
/// - Parameters:
/// - value: The output buffer as a `ValueConvertible` (tensor).
/// - method: The method name.
/// - index: Zero-based output index.
/// - Throws: If setting the output fails.
func setOutput(_ value: ValueConvertible, for method: String, at index: Int) throws {
try __setOutput(value.asValue(), forMethod: method, at: index)
}

/// Sets the output location for a method at index 0.
///
/// - Parameters:
/// - value: The output buffer as a `ValueConvertible` (tensor).
/// - method: The method name.
/// - Throws: If setting the output fails.
func setOutput(_ value: ValueConvertible, for method: String) throws {
try setOutput(value, for: method, at: 0)
}

/// Sets the output location for the "forward" method at the specified index.
///
/// - Parameters:
/// - value: The output buffer as a `ValueConvertible` (tensor).
/// - index: Zero-based output index.
/// - Throws: If setting the output fails.
func setOutput(_ value: ValueConvertible, at index: Int) throws {
try setOutput(value, for: "forward", at: index)
}

/// Sets the first output location (index 0) for the "forward" method.
///
/// - Parameter value: The output buffer as a `ValueConvertible` (tensor).
/// - Throws: If setting the output fails.
func setOutput(_ value: ValueConvertible) throws {
try setOutput(value, for: "forward", at: 0)
}
}
139 changes: 139 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorchModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,145 @@ __attribute__((deprecated("This API is experimental.")))
NS_SWIFT_UNAVAILABLE("")
NS_RETURNS_RETAINED;

/**
* Sets a single input value for the "forward" method at index 0.
*
* @param value The input value.
* @param error On failure, set to an NSError describing the issue.
* @return YES on success; NO otherwise.
*/
- (BOOL)setInput:(ExecuTorchValue *)value
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");

/**
* Sets a single input value for the "forward" method at the specified index.
*
* @param value The input value.
* @param index Zero-based input index.
* @param error On failure, set to an NSError describing the issue.
* @return YES on success; NO otherwise.
*/
- (BOOL)setInput:(ExecuTorchValue *)value
atIndex:(NSInteger)index
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");

/**
* Sets a single input value for the specified method at index 0.
*
* @param value The input value.
* @param methodName The method name.
* @param error On failure, set to an NSError describing the issue.
* @return YES on success; NO otherwise.
*/
- (BOOL)setInput:(ExecuTorchValue *)value
forMethod:(NSString *)methodName
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");

/**
* Sets a single input value for the specified method at the given index.
*
* The module retains the provided value to keep its backing storage alive
* until the value is overwritten or the module is deallocated.
*
* @param value The input value.
* @param methodName The method name.
* @param index Zero-based input index.
* @param error On failure, set to an NSError describing the issue.
* @return YES on success; NO otherwise.
*/
- (BOOL)setInput:(ExecuTorchValue *)value
forMethod:(NSString *)methodName
atIndex:(NSInteger)index
error:(NSError **)error NS_REFINED_FOR_SWIFT;

/**
* Sets all input values for the "forward" method.
*
* The number and types of values must match the method’s declared inputs.
*
* @param values The input values, one per declared input.
* @param error On failure, set to an NSError describing the issue.
* @return YES on success; NO otherwise.
*/
- (BOOL)setInputs:(NSArray<ExecuTorchValue *> *)values
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");

/**
* Sets all input values for the specified method.
*
* The module retains the provided values to keep their backing storage alive
* until the values are overwritten or the module is deallocated.
*
* @param values The input values, one per declared input.
* @param methodName The method name.
* @param error On failure, set to an NSError describing the issue.
* @return YES on success; NO otherwise.
*/
- (BOOL)setInputs:(NSArray<ExecuTorchValue *> *)values
forMethod:(NSString *)methodName
error:(NSError **)error NS_REFINED_FOR_SWIFT;

/**
* Sets the output buffer for the "forward" method at index 0.
*
* Only tensor outputs are supported. The provided value must wrap a tensor
* compatible with the method’s output slot.
*
* @param value The output buffer (must wrap a tensor).
* @param error On failure, set to an NSError describing the issue.
* @return YES on success; NO otherwise.
*/
- (BOOL)setOutput:(ExecuTorchValue *)value
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");

/**
* Sets the output buffer for the "forward" method at the specified index.
*
* Only tensor outputs are supported. The provided value must wrap a tensor
* compatible with the method’s output slot.
*
* @param value The output buffer (must wrap a tensor).
* @param index Zero-based output index.
* @param error On failure, set to an NSError describing the issue.
* @return YES on success; NO otherwise.
*/
- (BOOL)setOutput:(ExecuTorchValue *)value
atIndex:(NSInteger)index
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");

/**
* Sets the output buffer for the specified method at index 0.
*
* Only tensor outputs are supported. The provided value must wrap a tensor
* compatible with the method’s output slot.
*
* @param value The output buffer (must wrap a tensor).
* @param methodName The method name.
* @param error On failure, set to an NSError describing the issue.
* @return YES on success; NO otherwise.
*/
- (BOOL)setOutput:(ExecuTorchValue *)value
forMethod:(NSString *)methodName
error:(NSError **)error NS_SWIFT_UNAVAILABLE("");

/**
* Sets the output buffer for the specified method at the given index.
*
* The module retains the provided value to keep its backing storage alive
* until the value is overwritten or the module is deallocated.
* Only tensor outputs are supported.
*
* @param value The output buffer (must wrap a tensor).
* @param methodName The method name.
* @param index Zero-based output index.
* @param error On failure, set to an NSError describing the issue.
* @return YES on success; NO otherwise.
*/
- (BOOL)setOutput:(ExecuTorchValue *)value
forMethod:(NSString *)methodName
atIndex:(NSInteger)index
error:(NSError **)error NS_REFINED_FOR_SWIFT;

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

Expand Down
Loading
Loading