1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
use crate::*;
/// MLState.
#[cfg(feature = "MLModel")]
impl MLModel {
extern_methods!(
#[cfg(feature = "MLState")]
/// Creates a new state object.
///
/// Core ML framework will allocate the state buffers declared in the model.
///
/// The allocated state buffers are initialized to zeros. To initialize with different values, use `.withMultiArray(for:)` to get the mutable `MLMultiArray`-view to the state buffer.
///
/// It returns an empty state when the model is stateless. One can use the empty state with stateful prediction functions such as `prediction(from:using:)` and those predictions will be stateless. This simplifies the call site which may or may not use a stateful model.
///
/// ```swift
/// // Create state that contains two state buffers: s1 and s2.
/// // Then, initialize s1 to 1.0 and s2 to 2.0.
/// let state = model.newState()
/// state.withMultiArray(for: "s1") { stateMultiArray in
/// stateMultiArray[0] = 1.0
/// }
/// state.withMultiArray(for: "s2") { stateMultiArray in
/// stateMultiArray[0] = 2.0
/// }
/// ```
#[unsafe(method(newState))]
#[unsafe(method_family = new)]
pub unsafe fn newState(&self) -> Retained<MLState>;
#[cfg(all(feature = "MLFeatureProvider", feature = "MLState"))]
/// Run a stateful prediction synchronously.
///
/// Use this method to run predictions on a stateful model.
///
/// ```swift
/// let state = model.newState()
/// let prediction = try model.prediction(from: inputFeatures, using: state)
/// ```
///
/// - Parameters:
/// - inputFeatures: The input features as declared in the model description.
/// - state: The state object created by `newState()` method.
/// - error: The output parameter to receive an error information on failure.
#[unsafe(method(predictionFromFeatures:usingState:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn predictionFromFeatures_usingState_error(
&self,
input_features: &ProtocolObject<dyn MLFeatureProvider>,
state: &MLState,
) -> Result<Retained<ProtocolObject<dyn MLFeatureProvider>>, Retained<NSError>>;
#[cfg(all(
feature = "MLFeatureProvider",
feature = "MLPredictionOptions",
feature = "MLState"
))]
/// Run a stateful prediction synchronously with options.
///
/// Use this method to run predictions on a stateful model.
///
/// ```swift
/// let state = model.newState()
/// let prediction = try model.prediction(from: inputFeatures, using: state, options: predictionOptions)
/// ```
///
/// - Parameters:
/// - inputFeatures: The input features as declared in the model description.
/// - state: The state object created by `newState()` method.
/// - options: The prediction options.
/// - error: The output parameter to receive an error information on failure.
#[unsafe(method(predictionFromFeatures:usingState:options:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn predictionFromFeatures_usingState_options_error(
&self,
input_features: &ProtocolObject<dyn MLFeatureProvider>,
state: &MLState,
options: &MLPredictionOptions,
) -> Result<Retained<ProtocolObject<dyn MLFeatureProvider>>, Retained<NSError>>;
#[cfg(all(
feature = "MLFeatureProvider",
feature = "MLPredictionOptions",
feature = "MLState",
feature = "block2"
))]
/// Run a stateful prediction asynchronously.
///
/// Use this method to run predictions on a stateful model.
///
/// Do not request a prediction while another prediction that shares the same state is in-flight, otherwise the behavior is undefined.
///
/// ```swift
/// let state = model.newState()
/// let prediction = try await model.prediction(from: inputFeatures, using: state)
/// ```
///
/// - Parameters
/// - input: The input features to make a prediction from.
/// - state: The state object created by `newState()` method.
/// - options: Prediction options to modify how the prediction is run.
/// - completionHandler: A block that will be invoked once the prediction has completed successfully or unsuccessfully. On success, it is invoked with a valid model output. On failure, it is invoked with a nil output and NSError
#[unsafe(method(predictionFromFeatures:usingState:options:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn predictionFromFeatures_usingState_options_completionHandler(
&self,
input_features: &ProtocolObject<dyn MLFeatureProvider>,
state: &MLState,
options: &MLPredictionOptions,
completion_handler: &block2::DynBlock<
dyn Fn(*mut ProtocolObject<dyn MLFeatureProvider>, *mut NSError),
>,
);
);
}