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
//! 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::*;
extern_class!(
/// Handle to the state buffers.
///
/// A stateful model maintains a state from one prediction to another by storing the information in the state buffers. To use such a model, the client must request the model to create state buffers and get `MLState` object, which is the handle to those buffers. Then, at the prediction time, pass the `MLState` object in one of the stateful prediction functions.
///
/// ```swift
/// // Load a stateful model
/// let modelAsset = try MLModelAsset(url: modelURL)
/// let model = try await MLModel.load(asset: modelAsset, configuration: MLModelConfiguration())
///
/// // Request a state
/// let state = model.newState()
///
/// // Run predictions
/// for _ in 0 ..
/// <
/// 42 {
/// _ = try await model.prediction(from: inputFeatures, using: state)
/// }
///
/// // Access the state buffer.
/// state.withMultiArray(for: "accumulator") { stateMultiArray in
/// ...
/// }
/// ```
///
/// The object is a handle to the state buffers. The client shall not read or write the buffers while a prediction is in-flight.
///
/// Each stateful prediction that uses the same `MLState` must be serialized. Otherwise, if two such predictions run concurrently, the behavior is undefined.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coreml/mlstate?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MLState;
);
unsafe impl Send for MLState {}
unsafe impl Sync for MLState {}
extern_conformance!(
unsafe impl NSObjectProtocol for MLState {}
);
impl MLState {
extern_methods!(
#[cfg(all(feature = "MLMultiArray", feature = "block2"))]
/// Gets a mutable view into a state buffer.
///
/// The underlying state buffer's address can differ for each call; one shall not access the state buffer outside of the closure.
///
/// - Parameters:
/// - handler: Block to access the state buffer through `MLMultiArray`.
#[unsafe(method(getMultiArrayForStateNamed:handler:))]
#[unsafe(method_family = none)]
pub unsafe fn getMultiArrayForStateNamed_handler(
&self,
state_name: &NSString,
handler: &block2::DynBlock<dyn Fn(NonNull<MLMultiArray>) + '_>,
);
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
);
}