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!(
    /// MLModel
    ///
    /// Construct a model and evaluate on a specific set of input features.
    /// Inputs and outputs are accessed via the MLFeatureProvider protocol.
    /// Returns a model or nil if there is an error.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreml/mlmodel?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct MLModel;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for MLModel {}
);

impl MLModel {
    extern_methods!(
        #[cfg(feature = "MLModelDescription")]
        /// A model holds a description of its required inputs and expected outputs.
        #[unsafe(method(modelDescription))]
        #[unsafe(method_family = none)]
        pub unsafe fn modelDescription(&self) -> Retained<MLModelDescription>;

        #[cfg(feature = "MLModelConfiguration")]
        /// The load-time parameters used to instantiate this MLModel object.
        #[unsafe(method(configuration))]
        #[unsafe(method_family = none)]
        pub unsafe fn configuration(&self) -> Retained<MLModelConfiguration>;

        /// Construct a model with a default MLModelConfiguration object
        #[unsafe(method(modelWithContentsOfURL:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn modelWithContentsOfURL_error(
            url: &NSURL,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        #[cfg(feature = "MLModelConfiguration")]
        /// Construct a model given the location of its on-disk representation. Returns nil on error.
        #[unsafe(method(modelWithContentsOfURL:configuration:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn modelWithContentsOfURL_configuration_error(
            url: &NSURL,
            configuration: &MLModelConfiguration,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        #[cfg(all(feature = "MLModelConfiguration", feature = "block2"))]
        /// Construct a model asynchronously given the location of its on-disk representation and configuration.
        ///
        /// Model loading may take time when the model content is not immediately available (e.g. encrypted model). Use this factory method especially when the caller is on the main thread.
        ///
        ///
        /// Parameter `url`: the location of its on-disk representation (.mlmodelc directory).
        ///
        /// Parameter `configuration`: The model configuration
        ///
        /// Parameter `handler`: When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid MLModel instance or NSError object.
        #[unsafe(method(loadContentsOfURL:configuration:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadContentsOfURL_configuration_completionHandler(
            url: &NSURL,
            configuration: &MLModelConfiguration,
            handler: &block2::DynBlock<dyn Fn(*mut MLModel, *mut NSError)>,
        );

        #[cfg(feature = "MLFeatureProvider")]
        /// Run a prediction on a model synchronously.
        ///
        /// This is a convenience overload method of `prediction(from:options:)` that uses the default prediction options.
        ///
        /// - Parameters
        /// - input: The input features to make a prediction from.
        /// - error: The output parameter to be filled with error information on failure.
        /// - Returns: The output features from the prediction.
        #[unsafe(method(predictionFromFeatures:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn predictionFromFeatures_error(
            &self,
            input: &ProtocolObject<dyn MLFeatureProvider>,
        ) -> Result<Retained<ProtocolObject<dyn MLFeatureProvider>>, Retained<NSError>>;

        #[cfg(all(feature = "MLFeatureProvider", feature = "MLPredictionOptions"))]
        /// Run a prediction on a model synchronously
        ///
        /// - Parameters
        /// - input: The input features to make a prediction from.
        /// - options: Prediction options to modify how the prediction is run.
        /// - error: The output parameter to be filled with error information on failure.
        /// - Returns: The output features from the prediction.
        #[unsafe(method(predictionFromFeatures:options:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn predictionFromFeatures_options_error(
            &self,
            input: &ProtocolObject<dyn MLFeatureProvider>,
            options: &MLPredictionOptions,
        ) -> Result<Retained<ProtocolObject<dyn MLFeatureProvider>>, Retained<NSError>>;

        #[cfg(all(feature = "MLFeatureProvider", feature = "block2"))]
        /// Run a prediction on a model asynchronously.
        ///
        /// This is a convenience overload method of `prediction(from:options:) async` that uses the default prediction options.
        ///
        /// - Parameters
        /// - input: The input features to make a prediction from.
        /// - 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:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predictionFromFeatures_completionHandler(
            &self,
            input: &ProtocolObject<dyn MLFeatureProvider>,
            completion_handler: &block2::DynBlock<
                dyn Fn(*mut ProtocolObject<dyn MLFeatureProvider>, *mut NSError),
            >,
        );

        #[cfg(all(
            feature = "MLFeatureProvider",
            feature = "MLPredictionOptions",
            feature = "block2"
        ))]
        /// Run a prediction on a model asynchronously.
        ///
        /// - Parameters
        /// - input: The input features to make a prediction from.
        /// - 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:options:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn predictionFromFeatures_options_completionHandler(
            &self,
            input: &ProtocolObject<dyn MLFeatureProvider>,
            options: &MLPredictionOptions,
            completion_handler: &block2::DynBlock<
                dyn Fn(*mut ProtocolObject<dyn MLFeatureProvider>, *mut NSError),
            >,
        );

        #[cfg(feature = "MLBatchProvider")]
        /// Batch prediction without explicit options
        #[unsafe(method(predictionsFromBatch:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn predictionsFromBatch_error(
            &self,
            input_batch: &ProtocolObject<dyn MLBatchProvider>,
        ) -> Result<Retained<ProtocolObject<dyn MLBatchProvider>>, Retained<NSError>>;

        #[cfg(all(feature = "MLBatchProvider", feature = "MLPredictionOptions"))]
        /// Batch prediction with explicit options
        #[unsafe(method(predictionsFromBatch:options:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn predictionsFromBatch_options_error(
            &self,
            input_batch: &ProtocolObject<dyn MLBatchProvider>,
            options: &MLPredictionOptions,
        ) -> Result<Retained<ProtocolObject<dyn MLBatchProvider>>, Retained<NSError>>;

        #[cfg(all(feature = "MLKey", feature = "MLParameterKey"))]
        /// Provides value for the given parameter. Returns nil on error.
        #[unsafe(method(parameterValueForKey:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn parameterValueForKey_error(
            &self,
            key: &MLParameterKey,
        ) -> Result<Retained<AnyObject>, Retained<NSError>>;

        #[cfg(all(
            feature = "MLModelAsset",
            feature = "MLModelConfiguration",
            feature = "block2"
        ))]
        /// Construct a model asynchronously from a compiled model asset.
        ///
        ///
        /// Parameter `asset`: Compiled model asset derived from in-memory or on-disk Core ML model
        ///
        /// Parameter `configuration`: Model configuration that hold options for loading a model
        ///
        /// Parameter `handler`: When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid MLModel instance or NSError object.
        #[unsafe(method(loadModelAsset:configuration:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadModelAsset_configuration_completionHandler(
            asset: &MLModelAsset,
            configuration: &MLModelConfiguration,
            handler: &block2::DynBlock<dyn Fn(*mut MLModel, *mut NSError)>,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl MLModel {
    extern_methods!(
        #[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>;
    );
}