objc2-core-ml 0.3.2

Bindings to the CoreML framework
Documentation
//! 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>;
    );
}