objc2_core_ml/generated/
MLPredictionOptions.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    /// MLPredictionOptions
12    ///
13    /// An object to hold options / controls / parameters of how
14    /// model prediction is performed
15    ///
16    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreml/mlpredictionoptions?language=objc)
17    #[unsafe(super(NSObject))]
18    #[derive(Debug, PartialEq, Eq, Hash)]
19    pub struct MLPredictionOptions;
20);
21
22extern_conformance!(
23    unsafe impl NSObjectProtocol for MLPredictionOptions {}
24);
25
26impl MLPredictionOptions {
27    extern_methods!(
28        /// Set to YES to force computation to be on the CPU only
29        #[deprecated]
30        #[unsafe(method(usesCPUOnly))]
31        #[unsafe(method_family = none)]
32        pub unsafe fn usesCPUOnly(&self) -> bool;
33
34        /// Setter for [`usesCPUOnly`][Self::usesCPUOnly].
35        #[deprecated]
36        #[unsafe(method(setUsesCPUOnly:))]
37        #[unsafe(method_family = none)]
38        pub unsafe fn setUsesCPUOnly(&self, uses_cpu_only: bool);
39
40        /// Propose the model to use the specified backing objects for the
41        /// output feature values.
42        ///
43        ///
44        /// Use the property to get the inference result directly into the
45        /// client allocated buffer when possible for efficient memory management.
46        ///
47        /// The property is a dictionary of the feature name and the output backing
48        /// object.
49        ///
50        /// The framework may not use the specified backing object and instead allocates
51        /// one by itself if the outputBacking dictionary doesn't contain the entry for
52        /// the feature name, the model doesn't support the user allocated buffers, or in
53        /// the batch prediction mode. To check if the backing object was used, compare
54        /// the output prediction and the backing object by object identity.
55        ///
56        ///
57        /// ```text
58        ///   CVPixelBufferRef outputBacking = ...;
59        ///   [options setOutputBackings:@{@"outputImage" : (__bridge id)outputBacking}];
60        ///   id<MLFeatureProvider> prediction = [model predictionFromFeatures:inputFeatures options:options error:&error];
61        ///   if ([prediction featureValueForName:@"outputImage"].imageBufferValue == outputBacking) {
62        ///     // backing was used.
63        ///   }
64        ///   else {
65        ///     // backing was NOT used.
66        ///   }
67        /// ```
68        ///
69        /// The backing object must be either CVPixelBuffer or MLMultiArray depending on
70        /// the feature value type.
71        ///
72        /// Do not lock the base address of the CVPixelBuffer. In the case of a MLMultiArray
73        /// backed by a pixel buffer, make sure not to lock the underlying pixel buffer by not
74        /// calling any data methods such as `.dataPointer` and subscript methods before the
75        /// prediction.
76        ///
77        /// The framework ignores a backing object with an unknown feature name.
78        ///
79        /// For the best performance, use page-aligned address in MLMultiArray.
80        ///
81        ///
82        /// ```text
83        ///   #import <mach/vm_page_size.h>
84        ///   :
85        ///   void *backingBuffer = aligned_alloc(vm_page_size, round_page(backingBufferSize));
86        ///   if (backingBuffer == NULL) { ... error handling ... }
87        ///   MLMultiArray *outputBacking = [[MLMultiArray alloc] initWithDataPointer:(char *)backingBuffer
88        ///                                                                         ...
89        ///                                                               deallocator:^(void *) { free(backingBuffer); }
90        ///                                                                         ... ];
91        /// ```
92        ///
93        /// For CVPixelBuffer backing, consider to use IOSurface-backed CVPixelBuffer
94        /// created by CVPixelBufferPool because it is often the most efficient choice for
95        /// memory footprint and performance, especially when the pixel buffers are
96        /// subsequently used for playback or export. (See also AVSampleBufferDisplayLayer
97        /// and AVAssetWriter.)
98        ///
99        /// The output backing object must satisfy the output feature description's
100        /// `-isAllowedValue:` test, or the framework reporets an error at the prediction
101        /// time. The exception is FP16 MLMultiArray backed by CVPixelBuffer, which may be
102        /// accepted in Double or Float32 multi array output feature depending on the
103        /// underlying inference engine.
104        #[unsafe(method(outputBackings))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn outputBackings(&self) -> Retained<NSDictionary<NSString, AnyObject>>;
107
108        /// Setter for [`outputBackings`][Self::outputBackings].
109        #[unsafe(method(setOutputBackings:))]
110        #[unsafe(method_family = none)]
111        pub unsafe fn setOutputBackings(&self, output_backings: &NSDictionary<NSString, AnyObject>);
112    );
113}
114
115/// Methods declared on superclass `NSObject`.
116impl MLPredictionOptions {
117    extern_methods!(
118        #[unsafe(method(init))]
119        #[unsafe(method_family = init)]
120        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
121
122        #[unsafe(method(new))]
123        #[unsafe(method_family = new)]
124        pub unsafe fn new() -> Retained<Self>;
125    );
126}