objc2_core_ml/generated/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
10extern_class!(
11 /// Handle to the state buffers.
12 ///
13 /// 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.
14 ///
15 /// ```swift
16 /// // Load a stateful model
17 /// let modelAsset = try MLModelAsset(url: modelURL)
18 /// let model = try await MLModel.load(asset: modelAsset, configuration: MLModelConfiguration())
19 ///
20 /// // Request a state
21 /// let state = model.newState()
22 ///
23 /// // Run predictions
24 /// for _ in 0 ..
25 /// <
26 /// 42 {
27 /// _ = try await model.prediction(from: inputFeatures, using: state)
28 /// }
29 ///
30 /// // Access the state buffer.
31 /// state.withMultiArray(for: "accumulator") { stateMultiArray in
32 /// ...
33 /// }
34 /// ```
35 ///
36 /// The object is a handle to the state buffers. The client shall not read or write the buffers while a prediction is in-flight.
37 ///
38 /// Each stateful prediction that uses the same `MLState` must be serialized. Otherwise, if two such predictions run concurrently, the behavior is undefined.
39 ///
40 /// See also [Apple's documentation](https://developer.apple.com/documentation/coreml/mlstate?language=objc)
41 #[unsafe(super(NSObject))]
42 #[derive(Debug, PartialEq, Eq, Hash)]
43 pub struct MLState;
44);
45
46unsafe impl Send for MLState {}
47
48unsafe impl Sync for MLState {}
49
50extern_conformance!(
51 unsafe impl NSObjectProtocol for MLState {}
52);
53
54impl MLState {
55 extern_methods!(
56 #[cfg(all(feature = "MLMultiArray", feature = "block2"))]
57 /// Gets a mutable view into a state buffer.
58 ///
59 /// The underlying state buffer's address can differ for each call; one shall not access the state buffer outside of the closure.
60 ///
61 /// - Parameters:
62 /// - handler: Block to access the state buffer through `MLMultiArray`.
63 #[unsafe(method(getMultiArrayForStateNamed:handler:))]
64 #[unsafe(method_family = none)]
65 pub unsafe fn getMultiArrayForStateNamed_handler(
66 &self,
67 state_name: &NSString,
68 handler: &block2::DynBlock<dyn Fn(NonNull<MLMultiArray>) + '_>,
69 );
70
71 #[unsafe(method(init))]
72 #[unsafe(method_family = init)]
73 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
74
75 #[unsafe(method(new))]
76 #[unsafe(method_family = new)]
77 pub unsafe fn new() -> Retained<Self>;
78 );
79}