objc2_metal_performance_shaders/generated/MPSMatrix/
MPSMatrixDecomposition.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::*;
7use objc2_metal::*;
8
9use crate::*;
10
11/// [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixdecompositionstatus?language=objc)
12// NS_ENUM
13#[repr(transparent)]
14#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
15pub struct MPSMatrixDecompositionStatus(pub c_int);
16impl MPSMatrixDecompositionStatus {
17    #[doc(alias = "MPSMatrixDecompositionStatusSuccess")]
18    pub const Success: Self = Self(0);
19    #[doc(alias = "MPSMatrixDecompositionStatusFailure")]
20    pub const Failure: Self = Self(-1);
21    #[doc(alias = "MPSMatrixDecompositionStatusSingular")]
22    pub const Singular: Self = Self(-2);
23    #[doc(alias = "MPSMatrixDecompositionStatusNonPositiveDefinite")]
24    pub const NonPositiveDefinite: Self = Self(-3);
25}
26
27unsafe impl Encode for MPSMatrixDecompositionStatus {
28    const ENCODING: Encoding = c_int::ENCODING;
29}
30
31unsafe impl RefEncode for MPSMatrixDecompositionStatus {
32    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
33}
34
35extern_class!(
36    /// Dependencies: This depends on Metal.framework.
37    ///
38    ///
39    /// A kernel for computing the LU factorization of a matrix using
40    /// partial pivoting with row interchanges.
41    ///
42    ///
43    /// A MPSMatrixDecompositionLU object computes an LU factorization:
44    ///
45    /// P * A = L * U
46    ///
47    /// A is a matrix for which the LU factorization is to be computed.
48    /// L is a unit lower triangular matrix and U is an upper triangular
49    /// matrix.  P is a permutation matrix.
50    ///
51    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixdecompositionlu?language=objc)
52    #[unsafe(super(MPSMatrixUnaryKernel, MPSKernel, NSObject))]
53    #[derive(Debug, PartialEq, Eq, Hash)]
54    #[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
55    pub struct MPSMatrixDecompositionLU;
56);
57
58#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
59extern_conformance!(
60    unsafe impl NSCoding for MPSMatrixDecompositionLU {}
61);
62
63#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
64extern_conformance!(
65    unsafe impl NSCopying for MPSMatrixDecompositionLU {}
66);
67
68#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
69unsafe impl CopyingHelper for MPSMatrixDecompositionLU {
70    type Result = Self;
71}
72
73#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
74extern_conformance!(
75    unsafe impl NSObjectProtocol for MPSMatrixDecompositionLU {}
76);
77
78#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
79extern_conformance!(
80    unsafe impl NSSecureCoding for MPSMatrixDecompositionLU {}
81);
82
83#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
84impl MPSMatrixDecompositionLU {
85    extern_methods!(
86        /// Initialize an MPSMatrixDecompositionLU object on a device
87        ///
88        ///
89        /// Parameter `device`: The device on which the kernel will execute.
90        ///
91        ///
92        /// Parameter `rows`: The number of rows in the source matrix.
93        ///
94        ///
95        /// Parameter `columns`: The number of columns in the source matrix.
96        ///
97        ///
98        /// Returns: A valid MPSMatrixDecompositionLU object or nil, if failure.
99        #[unsafe(method(initWithDevice:rows:columns:))]
100        #[unsafe(method_family = init)]
101        pub unsafe fn initWithDevice_rows_columns(
102            this: Allocated<Self>,
103            device: &ProtocolObject<dyn MTLDevice>,
104            rows: NSUInteger,
105            columns: NSUInteger,
106        ) -> Retained<Self>;
107
108        /// Encode a MPSMatrixDecompositionLU kernel into a command Buffer.
109        ///
110        ///
111        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded filter
112        ///
113        ///
114        /// Parameter `sourceMatrix`: A valid MPSMatrix containing the source data.  Must have
115        /// enough space to hold a rows x columns matrix.
116        ///
117        ///
118        /// Parameter `resultMatrix`: A valid MPSMatrix to contain the result.  Must have enough
119        /// space to hold a rows x columns matrix.
120        ///
121        ///
122        /// Parameter `pivotIndices`: A valid MPSMatrix to contain the pivot indices. Must have enough space
123        /// to hold an array of size 1xmin(rows, columns) values.
124        /// Element type must be MPSDataTypeUInt32.
125        ///
126        ///
127        /// Parameter `status`: A MTLBuffer which indicates the resulting MPSMatrixDecompositionStatus
128        /// value.
129        ///
130        ///
131        /// This function encodes the MPSMatrixDecompositionLU object to a valid
132        /// command buffer.
133        ///
134        /// Upon completion the array pivotIndices contains, for each index i,
135        /// the row interchanged with row i.
136        ///
137        /// If during the computation U[k, k], for some k, is determined to be
138        /// exactly zero MPSMatrixDecompositionStatusSingular will be returned in the
139        /// provided status buffer.  The data referenced by the MTLBuffer is not valid
140        /// until the command buffer has completed execution.  If the matrix
141        /// return status is not desired NULL may be provided.
142        ///
143        /// Upon successful factorization, resultMatrix contains the resulting
144        /// lower triangular factor (without the unit diagonal elements) in its
145        /// strictly lower triangular region and the upper triangular factor in
146        /// its upper triangular region.
147        ///
148        /// This kernel functions either in-place, if the result matrix
149        /// completely aliases the source matrix, or out-of-place.  If there
150        /// is any partial overlap between input and output data the results
151        /// are undefined.
152        ///
153        /// # Safety
154        ///
155        /// - `status` may need to be synchronized.
156        /// - `status` may be unretained, you must ensure it is kept alive while in use.
157        /// - `status` contents should be of the correct type.
158        #[unsafe(method(encodeToCommandBuffer:sourceMatrix:resultMatrix:pivotIndices:status:))]
159        #[unsafe(method_family = none)]
160        pub unsafe fn encodeToCommandBuffer_sourceMatrix_resultMatrix_pivotIndices_status(
161            &self,
162            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
163            source_matrix: &MPSMatrix,
164            result_matrix: &MPSMatrix,
165            pivot_indices: &MPSMatrix,
166            status: Option<&ProtocolObject<dyn MTLBuffer>>,
167        );
168    );
169}
170
171/// Methods declared on superclass `MPSKernel`.
172#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
173impl MPSMatrixDecompositionLU {
174    extern_methods!(
175        /// Standard init with default properties per filter type
176        ///
177        /// Parameter `device`: The device that the filter will be used on. May not be NULL.
178        ///
179        /// Returns: a pointer to the newly initialized object. This will fail, returning
180        /// nil if the device is not supported. Devices must be
181        /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
182        #[unsafe(method(initWithDevice:))]
183        #[unsafe(method_family = init)]
184        pub unsafe fn initWithDevice(
185            this: Allocated<Self>,
186            device: &ProtocolObject<dyn MTLDevice>,
187        ) -> Retained<Self>;
188
189        /// Called by NSCoder to decode MPSKernels
190        ///
191        /// This isn't the right interface to decode a MPSKernel, but
192        /// it is the one that NSCoder uses. To enable your NSCoder
193        /// (e.g. NSKeyedUnarchiver) to set which device to use
194        /// extend the object to adopt the MPSDeviceProvider
195        /// protocol. Otherwise, the Metal system default device
196        /// will be used.
197        ///
198        /// # Safety
199        ///
200        /// `a_decoder` possibly has further requirements.
201        #[unsafe(method(initWithCoder:))]
202        #[unsafe(method_family = init)]
203        pub unsafe fn initWithCoder(
204            this: Allocated<Self>,
205            a_decoder: &NSCoder,
206        ) -> Option<Retained<Self>>;
207
208        /// NSSecureCoding compatability
209        ///
210        /// While the standard NSSecureCoding/NSCoding method
211        /// -initWithCoder: should work, since the file can't
212        /// know which device your data is allocated on, we
213        /// have to guess and may guess incorrectly.  To avoid
214        /// that problem, use initWithCoder:device instead.
215        ///
216        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
217        ///
218        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
219        ///
220        /// Returns: A new MPSKernel object, or nil if failure.
221        ///
222        /// # Safety
223        ///
224        /// `a_decoder` possibly has further requirements.
225        #[unsafe(method(initWithCoder:device:))]
226        #[unsafe(method_family = init)]
227        pub unsafe fn initWithCoder_device(
228            this: Allocated<Self>,
229            a_decoder: &NSCoder,
230            device: &ProtocolObject<dyn MTLDevice>,
231        ) -> Option<Retained<Self>>;
232    );
233}
234
235/// Methods declared on superclass `NSObject`.
236#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
237impl MPSMatrixDecompositionLU {
238    extern_methods!(
239        #[unsafe(method(init))]
240        #[unsafe(method_family = init)]
241        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
242
243        #[unsafe(method(new))]
244        #[unsafe(method_family = new)]
245        pub unsafe fn new() -> Retained<Self>;
246    );
247}
248
249extern_class!(
250    /// Dependencies: This depends on Metal.framework.
251    ///
252    ///
253    /// A kernel for computing the Cholesky factorization of a matrix.
254    ///
255    ///
256    /// A MPSMatrixDecompositionLU object computes one of the following
257    /// factorizations of a matrix A:
258    ///
259    /// A = L * L**T
260    /// A = U**T * U
261    ///
262    /// A is a symmetric positive-definite matrix for which the
263    /// factorization is to be computed. L and U are lower and upper
264    /// triangular matrices respectively.
265    ///
266    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixdecompositioncholesky?language=objc)
267    #[unsafe(super(MPSMatrixUnaryKernel, MPSKernel, NSObject))]
268    #[derive(Debug, PartialEq, Eq, Hash)]
269    #[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
270    pub struct MPSMatrixDecompositionCholesky;
271);
272
273#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
274extern_conformance!(
275    unsafe impl NSCoding for MPSMatrixDecompositionCholesky {}
276);
277
278#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
279extern_conformance!(
280    unsafe impl NSCopying for MPSMatrixDecompositionCholesky {}
281);
282
283#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
284unsafe impl CopyingHelper for MPSMatrixDecompositionCholesky {
285    type Result = Self;
286}
287
288#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
289extern_conformance!(
290    unsafe impl NSObjectProtocol for MPSMatrixDecompositionCholesky {}
291);
292
293#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
294extern_conformance!(
295    unsafe impl NSSecureCoding for MPSMatrixDecompositionCholesky {}
296);
297
298#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
299impl MPSMatrixDecompositionCholesky {
300    extern_methods!(
301        /// Initialize an MPSMatrixDecompositionCholesky object on a device
302        ///
303        ///
304        /// Parameter `device`: The device on which the kernel will execute.
305        ///
306        ///
307        /// Parameter `lower`: A boolean value indicating if the lower triangular
308        /// part of the source matrix is stored.  If lower = YES
309        /// the lower triangular part will be used and the factor
310        /// will be written to the lower triangular part of the
311        /// result, otherwise the upper triangular part will be used
312        /// and the factor will be written to the upper triangular
313        /// part.
314        ///
315        ///
316        /// Parameter `order`: The number of rows and columns in the source matrix.
317        ///
318        ///
319        /// Returns: A valid MPSMatrixDecompositionCholesky object or nil, if failure.
320        #[unsafe(method(initWithDevice:lower:order:))]
321        #[unsafe(method_family = init)]
322        pub unsafe fn initWithDevice_lower_order(
323            this: Allocated<Self>,
324            device: &ProtocolObject<dyn MTLDevice>,
325            lower: bool,
326            order: NSUInteger,
327        ) -> Retained<Self>;
328
329        /// Encode a MPSMatrixDecompositionCholesky kernel into a command Buffer.
330        ///
331        ///
332        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded filter
333        ///
334        ///
335        /// Parameter `sourceMatrix`: A valid MPSMatrix containing the source data.  Must have
336        /// enough space to hold a order x order matrix.
337        ///
338        ///
339        /// Parameter `resultMatrix`: A valid MPSMatrix to contain the result.  Must have enough
340        /// space to hold a order x order matrix.
341        ///
342        ///
343        /// Parameter `status`: A MTLBuffer which indicates the resulting MPSMatrixDecompositionStatus
344        /// value.
345        ///
346        ///
347        /// This function encodes the MPSMatrixDecompositionCholesky object to a valid
348        /// command buffer.
349        ///
350        /// If during the factorization a leading minor of the matrix is found to be
351        /// not positive definite, MPSMatrixDecompositionNonPositiveDefinite will be returned
352        /// in the provided status buffer.  Previously computed pivots and the non positive
353        /// pivot are written to the result, but the factorization does not complete.
354        /// The data referenced by the MTLBuffer is not valid until the command buffer has completed
355        /// execution.  If the matrix return status is not desired NULL may be provided.
356        ///
357        /// If the return status is MPSMatrixDecompositionStatusSuccess, resultMatrix
358        /// contains the resulting factors in its lower or upper triangular regions
359        /// respectively.
360        ///
361        /// This kernel functions either in-place, if the result matrix
362        /// completely aliases the source matrix, or out-of-place.  If there
363        /// is any partial overlap between input and output data the results
364        /// are undefined.
365        ///
366        /// # Safety
367        ///
368        /// - `status` may need to be synchronized.
369        /// - `status` may be unretained, you must ensure it is kept alive while in use.
370        /// - `status` contents should be of the correct type.
371        #[unsafe(method(encodeToCommandBuffer:sourceMatrix:resultMatrix:status:))]
372        #[unsafe(method_family = none)]
373        pub unsafe fn encodeToCommandBuffer_sourceMatrix_resultMatrix_status(
374            &self,
375            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
376            source_matrix: &MPSMatrix,
377            result_matrix: &MPSMatrix,
378            status: Option<&ProtocolObject<dyn MTLBuffer>>,
379        );
380    );
381}
382
383/// Methods declared on superclass `MPSKernel`.
384#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
385impl MPSMatrixDecompositionCholesky {
386    extern_methods!(
387        /// Standard init with default properties per filter type
388        ///
389        /// Parameter `device`: The device that the filter will be used on. May not be NULL.
390        ///
391        /// Returns: a pointer to the newly initialized object. This will fail, returning
392        /// nil if the device is not supported. Devices must be
393        /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
394        #[unsafe(method(initWithDevice:))]
395        #[unsafe(method_family = init)]
396        pub unsafe fn initWithDevice(
397            this: Allocated<Self>,
398            device: &ProtocolObject<dyn MTLDevice>,
399        ) -> Retained<Self>;
400
401        /// Called by NSCoder to decode MPSKernels
402        ///
403        /// This isn't the right interface to decode a MPSKernel, but
404        /// it is the one that NSCoder uses. To enable your NSCoder
405        /// (e.g. NSKeyedUnarchiver) to set which device to use
406        /// extend the object to adopt the MPSDeviceProvider
407        /// protocol. Otherwise, the Metal system default device
408        /// will be used.
409        ///
410        /// # Safety
411        ///
412        /// `a_decoder` possibly has further requirements.
413        #[unsafe(method(initWithCoder:))]
414        #[unsafe(method_family = init)]
415        pub unsafe fn initWithCoder(
416            this: Allocated<Self>,
417            a_decoder: &NSCoder,
418        ) -> Option<Retained<Self>>;
419
420        /// NSSecureCoding compatability
421        ///
422        /// While the standard NSSecureCoding/NSCoding method
423        /// -initWithCoder: should work, since the file can't
424        /// know which device your data is allocated on, we
425        /// have to guess and may guess incorrectly.  To avoid
426        /// that problem, use initWithCoder:device instead.
427        ///
428        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
429        ///
430        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
431        ///
432        /// Returns: A new MPSKernel object, or nil if failure.
433        ///
434        /// # Safety
435        ///
436        /// `a_decoder` possibly has further requirements.
437        #[unsafe(method(initWithCoder:device:))]
438        #[unsafe(method_family = init)]
439        pub unsafe fn initWithCoder_device(
440            this: Allocated<Self>,
441            a_decoder: &NSCoder,
442            device: &ProtocolObject<dyn MTLDevice>,
443        ) -> Option<Retained<Self>>;
444    );
445}
446
447/// Methods declared on superclass `NSObject`.
448#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
449impl MPSMatrixDecompositionCholesky {
450    extern_methods!(
451        #[unsafe(method(init))]
452        #[unsafe(method_family = init)]
453        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
454
455        #[unsafe(method(new))]
456        #[unsafe(method_family = new)]
457        pub unsafe fn new() -> Retained<Self>;
458    );
459}