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