objc2_metal_performance_shaders/generated/MPSNeuralNetwork/
MPSMatrixNeuron.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
11extern_class!(
12    /// Dependencies: This depends on Metal.framework.
13    ///
14    ///
15    /// A neuron activation kernel that operates on matrices.
16    ///
17    ///
18    /// A MPSMatrixNeuron object computes:
19    ///
20    /// y = neuron(alpha * x + bias)
21    ///
22    /// y is the output matrix, x is the input matrix corresponding
23    /// to a collection of input vectors and bias is a vector which is broadcast
24    /// and accumulated to each row of the intermediate result.
25    /// alpha is a scale factor applied to the input.
26    ///
27    /// neuron() defines the pointwise function that is applied to the intermediate result.
28    ///
29    /// Note: This function computes the same result as MPSMatrixFullyConnected that has
30    /// unit weight matrix.
31    ///
32    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixneuron?language=objc)
33    #[unsafe(super(MPSMatrixUnaryKernel, MPSKernel, NSObject))]
34    #[derive(Debug, PartialEq, Eq, Hash)]
35    #[cfg(all(
36        feature = "MPSCore",
37        feature = "MPSKernel",
38        feature = "MPSMatrix",
39        feature = "MPSMatrixTypes"
40    ))]
41    pub struct MPSMatrixNeuron;
42);
43
44#[cfg(all(
45    feature = "MPSCore",
46    feature = "MPSKernel",
47    feature = "MPSMatrix",
48    feature = "MPSMatrixTypes"
49))]
50extern_conformance!(
51    unsafe impl NSCoding for MPSMatrixNeuron {}
52);
53
54#[cfg(all(
55    feature = "MPSCore",
56    feature = "MPSKernel",
57    feature = "MPSMatrix",
58    feature = "MPSMatrixTypes"
59))]
60extern_conformance!(
61    unsafe impl NSCopying for MPSMatrixNeuron {}
62);
63
64#[cfg(all(
65    feature = "MPSCore",
66    feature = "MPSKernel",
67    feature = "MPSMatrix",
68    feature = "MPSMatrixTypes"
69))]
70unsafe impl CopyingHelper for MPSMatrixNeuron {
71    type Result = Self;
72}
73
74#[cfg(all(
75    feature = "MPSCore",
76    feature = "MPSKernel",
77    feature = "MPSMatrix",
78    feature = "MPSMatrixTypes"
79))]
80extern_conformance!(
81    unsafe impl NSObjectProtocol for MPSMatrixNeuron {}
82);
83
84#[cfg(all(
85    feature = "MPSCore",
86    feature = "MPSKernel",
87    feature = "MPSMatrix",
88    feature = "MPSMatrixTypes"
89))]
90extern_conformance!(
91    unsafe impl NSSecureCoding for MPSMatrixNeuron {}
92);
93
94#[cfg(all(
95    feature = "MPSCore",
96    feature = "MPSKernel",
97    feature = "MPSMatrix",
98    feature = "MPSMatrixTypes"
99))]
100impl MPSMatrixNeuron {
101    extern_methods!(
102        /// The number of input vectors which make up the input array.  This
103        /// is equivalent to the number of rows to consider from the primary
104        /// source matrix.
105        /// This property is modifiable and defaults to NSUIntegerMax.  At encode
106        /// time the larger of this property or the available number of inputs is
107        /// used.  The value of NSUIntegerMax thus indicates that all available input
108        /// rows (beginning at sourceMatrixOrigin.x) should be considered.
109        #[unsafe(method(sourceNumberOfFeatureVectors))]
110        #[unsafe(method_family = none)]
111        pub unsafe fn sourceNumberOfFeatureVectors(&self) -> NSUInteger;
112
113        /// Setter for [`sourceNumberOfFeatureVectors`][Self::sourceNumberOfFeatureVectors].
114        #[unsafe(method(setSourceNumberOfFeatureVectors:))]
115        #[unsafe(method_family = none)]
116        pub unsafe fn setSourceNumberOfFeatureVectors(
117            &self,
118            source_number_of_feature_vectors: NSUInteger,
119        );
120
121        /// The input size to to use in the operation.  This is equivalent to the
122        /// number of columns in the primary (input array) source matrix to consider
123        /// and the number of channels to produce for the output matrix.
124        /// This property is modifiable and defaults to NSUIntegerMax.  At encode
125        /// time the larger of this property or the available input size is used.
126        /// The value of NSUIntegerMax thus indicates that all available columns in
127        /// the input array (beginning at sourceMatrixOrigin.y) should be considered.
128        /// Defines also the number of output feature channels.
129        /// Note: The value used in the operation will be
130        /// MIN(inputMatrix.columns - sourceMatrixOrigin.y, sourceInputFeatureChannels)
131        #[unsafe(method(sourceInputFeatureChannels))]
132        #[unsafe(method_family = none)]
133        pub unsafe fn sourceInputFeatureChannels(&self) -> NSUInteger;
134
135        /// Setter for [`sourceInputFeatureChannels`][Self::sourceInputFeatureChannels].
136        #[unsafe(method(setSourceInputFeatureChannels:))]
137        #[unsafe(method_family = none)]
138        pub unsafe fn setSourceInputFeatureChannels(
139            &self,
140            source_input_feature_channels: NSUInteger,
141        );
142
143        /// The scale factor to apply to the input.  Specified in double
144        /// precision.  Will be converted to the appropriate precision in the
145        /// implementation subject to rounding and/or clamping as necessary.
146        /// Defaults to 1.0 at initialization time.
147        #[unsafe(method(alpha))]
148        #[unsafe(method_family = none)]
149        pub unsafe fn alpha(&self) -> c_double;
150
151        /// Setter for [`alpha`][Self::alpha].
152        #[unsafe(method(setAlpha:))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn setAlpha(&self, alpha: c_double);
155
156        #[cfg(feature = "MPSCNNNeuronType")]
157        /// Specifies a neuron activation function to be used.
158        ///
159        ///
160        /// This method can be used to add a neuron activation funtion of given type with
161        /// associated scalar parameters A, B, and C that are shared across all output values.
162        /// Note that this method can only be used to specify neurons which are specified by three (or fewer)
163        /// parameters shared across all output values (or channels, in CNN nomenclature). It is an error to call
164        /// this method for neuron activation functions like MPSCNNNeuronTypePReLU,
165        /// which require per-channel parameter values. For those kind of neuron activation functions,
166        /// use appropriate setter functions.  An MPSMatrixNeuron kernel is initialized
167        /// with a default neuron function of MPSCNNNeuronTypeNone.
168        ///
169        ///
170        /// Parameter `neuronType`: Type of neuron activation function. For full list see MPSCNNNeuronType.h
171        ///
172        /// Parameter `parameterA`: parameterA of neuron activation that is shared across all output values.
173        ///
174        /// Parameter `parameterB`: parameterB of neuron activation that is shared across all output values.
175        ///
176        /// Parameter `parameterC`: parameterC of neuron activation that is shared across all output values.
177        #[unsafe(method(setNeuronType:parameterA:parameterB:parameterC:))]
178        #[unsafe(method_family = none)]
179        pub unsafe fn setNeuronType_parameterA_parameterB_parameterC(
180            &self,
181            neuron_type: MPSCNNNeuronType,
182            parameter_a: c_float,
183            parameter_b: c_float,
184            parameter_c: c_float,
185        );
186
187        #[cfg(feature = "MPSCNNNeuronType")]
188        /// Getter funtion for neuronType set using setNeuronType:parameterA:parameterB:parameterC method
189        #[unsafe(method(neuronType))]
190        #[unsafe(method_family = none)]
191        pub unsafe fn neuronType(&self) -> MPSCNNNeuronType;
192
193        /// Getter funtion for neuronType set using setNeuronType:parameterA:parameterB:parameterC method
194        #[unsafe(method(neuronParameterA))]
195        #[unsafe(method_family = none)]
196        pub unsafe fn neuronParameterA(&self) -> c_float;
197
198        /// Getter funtion for neuronType set using setNeuronType:parameterA:parameterB:parameterC method
199        #[unsafe(method(neuronParameterB))]
200        #[unsafe(method_family = none)]
201        pub unsafe fn neuronParameterB(&self) -> c_float;
202
203        /// Getter funtion for neuronType set using setNeuronType:parameterA:parameterB:parameterC method
204        #[unsafe(method(neuronParameterC))]
205        #[unsafe(method_family = none)]
206        pub unsafe fn neuronParameterC(&self) -> c_float;
207
208        /// Add per output value neuron parameters A for PReLu neuron activation functions.
209        ///
210        ///
211        /// This method sets the neuron to PReLU, zeros parameters A and B and sets the per output value
212        /// neuron parameters A to an array containing a unique value of A for each output value.
213        ///
214        /// If the neuron function is f(v,a,b), it will apply
215        ///
216        /// resultMatrix(i, j) = f( input(i, j), A[j], B[j] )
217        /// where j in [0, sourceInputFeatureChannels]
218        ///
219        /// See https://arxiv.org/pdf/1502.01852.pdf for details.
220        ///
221        /// All other neuron types, where parameter A
222        /// and parameter B are shared across output values must be set using
223        /// -setNeuronType:parameterA:parameterB:
224        ///
225        ///
226        /// Parameter `A`: An array containing float values for neuron parameter A.
227        /// Number of entries must be equal to MIN(inputMatrix.columns - sourceMatrixOrigin.y, sourceInputFeatureChannels)
228        #[unsafe(method(setNeuronToPReLUWithParametersA:))]
229        #[unsafe(method_family = none)]
230        pub unsafe fn setNeuronToPReLUWithParametersA(&self, a: &NSData);
231
232        #[unsafe(method(initWithDevice:))]
233        #[unsafe(method_family = init)]
234        pub unsafe fn initWithDevice(
235            this: Allocated<Self>,
236            device: &ProtocolObject<dyn MTLDevice>,
237        ) -> Retained<Self>;
238
239        /// Encode a MPSMatrixNeuron object to a command buffer.
240        ///
241        ///
242        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded kernel.
243        ///
244        ///
245        /// Parameter `inputMatrix`: A valid MPSMatrix object which specifies the input array.
246        ///
247        ///
248        /// Parameter `biasVector`: A valid MPSVector object which specifies the bias values, or
249        /// a null object to indicate that no bias is to be applied.
250        ///
251        ///
252        /// Parameter `resultMatrix`: A valid MPSMatrix object which specifies the output array.
253        ///
254        ///
255        /// Encodes the operation to the specified command buffer.  resultMatrix
256        /// must be large enough to hold a
257        /// MIN(sourceNumberOfFeatureVectors, inputMatrix.rows - sourceMatrixOrigin.x)
258        /// x
259        /// MIN(inputMatrix.columns - sourceMatrixOrigin.y, sourceInputFeatureChannels) array.
260        ///
261        /// The bias vector must contain at least
262        /// MIN(inputMatrix.columns - sourceMatrixOrigin.y, sourceInputFeatureChannels) elements.
263        #[unsafe(method(encodeToCommandBuffer:inputMatrix:biasVector:resultMatrix:))]
264        #[unsafe(method_family = none)]
265        pub unsafe fn encodeToCommandBuffer_inputMatrix_biasVector_resultMatrix(
266            &self,
267            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
268            input_matrix: &MPSMatrix,
269            bias_vector: Option<&MPSVector>,
270            result_matrix: &MPSMatrix,
271        );
272
273        /// NSSecureCoding compatability
274        ///
275        /// See
276        /// MPSKernel#initWithCoder.
277        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSMatrixNeuron
278        ///
279        /// Parameter `device`: The MTLDevice on which to make the MPSMatrixNeuron object.
280        ///
281        /// Returns: A new MPSMatrixNeuron object, or nil if failure.
282        ///
283        /// # Safety
284        ///
285        /// `a_decoder` possibly has further requirements.
286        #[unsafe(method(initWithCoder:device:))]
287        #[unsafe(method_family = init)]
288        pub unsafe fn initWithCoder_device(
289            this: Allocated<Self>,
290            a_decoder: &NSCoder,
291            device: &ProtocolObject<dyn MTLDevice>,
292        ) -> Option<Retained<Self>>;
293
294        /// Make a copy of this kernel for a new device -
295        ///
296        /// See: MPSKernel
297        ///
298        /// Parameter `zone`: The NSZone in which to allocate the object
299        ///
300        /// Parameter `device`: The device for the new MPSKernel. If nil, then use
301        /// self.device.
302        ///
303        /// Returns: A pointer to a copy of this MPSKernel. This will fail, returning
304        /// nil if the device is not supported. Devices must be
305        /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
306        ///
307        /// # Safety
308        ///
309        /// `zone` must be a valid pointer or null.
310        #[unsafe(method(copyWithZone:device:))]
311        #[unsafe(method_family = copy)]
312        pub unsafe fn copyWithZone_device(
313            &self,
314            zone: *mut NSZone,
315            device: Option<&ProtocolObject<dyn MTLDevice>>,
316        ) -> Retained<Self>;
317    );
318}
319
320/// Methods declared on superclass `MPSKernel`.
321#[cfg(all(
322    feature = "MPSCore",
323    feature = "MPSKernel",
324    feature = "MPSMatrix",
325    feature = "MPSMatrixTypes"
326))]
327impl MPSMatrixNeuron {
328    extern_methods!(
329        /// Called by NSCoder to decode MPSKernels
330        ///
331        /// This isn't the right interface to decode a MPSKernel, but
332        /// it is the one that NSCoder uses. To enable your NSCoder
333        /// (e.g. NSKeyedUnarchiver) to set which device to use
334        /// extend the object to adopt the MPSDeviceProvider
335        /// protocol. Otherwise, the Metal system default device
336        /// will be used.
337        ///
338        /// # Safety
339        ///
340        /// `a_decoder` possibly has further requirements.
341        #[unsafe(method(initWithCoder:))]
342        #[unsafe(method_family = init)]
343        pub unsafe fn initWithCoder(
344            this: Allocated<Self>,
345            a_decoder: &NSCoder,
346        ) -> Option<Retained<Self>>;
347    );
348}
349
350/// Methods declared on superclass `NSObject`.
351#[cfg(all(
352    feature = "MPSCore",
353    feature = "MPSKernel",
354    feature = "MPSMatrix",
355    feature = "MPSMatrixTypes"
356))]
357impl MPSMatrixNeuron {
358    extern_methods!(
359        #[unsafe(method(init))]
360        #[unsafe(method_family = init)]
361        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
362
363        #[unsafe(method(new))]
364        #[unsafe(method_family = new)]
365        pub unsafe fn new() -> Retained<Self>;
366    );
367}
368
369extern_class!(
370    /// Dependencies: This depends on Metal.framework.
371    ///
372    ///
373    /// A neuron gradient activation kernel that operates on matrices.
374    ///
375    ///
376    /// A MPSMatrixNeuronGradient object computes the results of backpropagating
377    /// the gradients of a loss function with respect to the outputs of an
378    /// MPSMatrixNeuron object.  The corresponding properties and data used by
379    /// the MPSMatrixNeuronGradient object should correspond to those used by
380    /// the forward MPSMatrixNeuron object for which the gradient is being computed.
381    ///
382    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixneurongradient?language=objc)
383    #[unsafe(super(MPSMatrixBinaryKernel, MPSKernel, NSObject))]
384    #[derive(Debug, PartialEq, Eq, Hash)]
385    #[cfg(all(
386        feature = "MPSCore",
387        feature = "MPSKernel",
388        feature = "MPSMatrix",
389        feature = "MPSMatrixTypes"
390    ))]
391    pub struct MPSMatrixNeuronGradient;
392);
393
394#[cfg(all(
395    feature = "MPSCore",
396    feature = "MPSKernel",
397    feature = "MPSMatrix",
398    feature = "MPSMatrixTypes"
399))]
400extern_conformance!(
401    unsafe impl NSCoding for MPSMatrixNeuronGradient {}
402);
403
404#[cfg(all(
405    feature = "MPSCore",
406    feature = "MPSKernel",
407    feature = "MPSMatrix",
408    feature = "MPSMatrixTypes"
409))]
410extern_conformance!(
411    unsafe impl NSCopying for MPSMatrixNeuronGradient {}
412);
413
414#[cfg(all(
415    feature = "MPSCore",
416    feature = "MPSKernel",
417    feature = "MPSMatrix",
418    feature = "MPSMatrixTypes"
419))]
420unsafe impl CopyingHelper for MPSMatrixNeuronGradient {
421    type Result = Self;
422}
423
424#[cfg(all(
425    feature = "MPSCore",
426    feature = "MPSKernel",
427    feature = "MPSMatrix",
428    feature = "MPSMatrixTypes"
429))]
430extern_conformance!(
431    unsafe impl NSObjectProtocol for MPSMatrixNeuronGradient {}
432);
433
434#[cfg(all(
435    feature = "MPSCore",
436    feature = "MPSKernel",
437    feature = "MPSMatrix",
438    feature = "MPSMatrixTypes"
439))]
440extern_conformance!(
441    unsafe impl NSSecureCoding for MPSMatrixNeuronGradient {}
442);
443
444#[cfg(all(
445    feature = "MPSCore",
446    feature = "MPSKernel",
447    feature = "MPSMatrix",
448    feature = "MPSMatrixTypes"
449))]
450impl MPSMatrixNeuronGradient {
451    extern_methods!(
452        /// The number of input vectors which make up the input array.
453        #[unsafe(method(sourceNumberOfFeatureVectors))]
454        #[unsafe(method_family = none)]
455        pub unsafe fn sourceNumberOfFeatureVectors(&self) -> NSUInteger;
456
457        /// Setter for [`sourceNumberOfFeatureVectors`][Self::sourceNumberOfFeatureVectors].
458        #[unsafe(method(setSourceNumberOfFeatureVectors:))]
459        #[unsafe(method_family = none)]
460        pub unsafe fn setSourceNumberOfFeatureVectors(
461            &self,
462            source_number_of_feature_vectors: NSUInteger,
463        );
464
465        /// The number of feature channels in the input vectors.
466        #[unsafe(method(sourceInputFeatureChannels))]
467        #[unsafe(method_family = none)]
468        pub unsafe fn sourceInputFeatureChannels(&self) -> NSUInteger;
469
470        /// Setter for [`sourceInputFeatureChannels`][Self::sourceInputFeatureChannels].
471        #[unsafe(method(setSourceInputFeatureChannels:))]
472        #[unsafe(method_family = none)]
473        pub unsafe fn setSourceInputFeatureChannels(
474            &self,
475            source_input_feature_channels: NSUInteger,
476        );
477
478        /// The scale factor to apply to the input.
479        #[unsafe(method(alpha))]
480        #[unsafe(method_family = none)]
481        pub unsafe fn alpha(&self) -> c_double;
482
483        /// Setter for [`alpha`][Self::alpha].
484        #[unsafe(method(setAlpha:))]
485        #[unsafe(method_family = none)]
486        pub unsafe fn setAlpha(&self, alpha: c_double);
487
488        #[cfg(feature = "MPSCNNNeuronType")]
489        /// Specifies a neuron activation function to be used.
490        ///
491        ///
492        /// This method can be used to add a neuron activation funtion of given type with
493        /// associated scalar parameters A, B, and C that are shared across all output values.
494        /// Note that this method can only be used to specify neurons which are specified by three (or fewer)
495        /// parameters shared across all output values (or channels, in CNN nomenclature). It is an error to call
496        /// this method for neuron activation functions like MPSCNNNeuronTypePReLU,
497        /// which require per-channel parameter values. For those kind of neuron activation functions,
498        /// use appropriate setter functions.  An MPSMatrixNeuron kernel is initialized
499        /// with a default neuron function of MPSCNNNeuronTypeNone.
500        ///
501        ///
502        /// Parameter `neuronType`: Type of neuron activation function. For full list see MPSCNNNeuronType.h
503        ///
504        /// Parameter `parameterA`: parameterA of neuron activation that is shared across all output values.
505        ///
506        /// Parameter `parameterB`: parameterB of neuron activation that is shared across all output values.
507        ///
508        /// Parameter `parameterC`: parameterC of neuron activation that is shared across all output values.
509        #[unsafe(method(setNeuronType:parameterA:parameterB:parameterC:))]
510        #[unsafe(method_family = none)]
511        pub unsafe fn setNeuronType_parameterA_parameterB_parameterC(
512            &self,
513            neuron_type: MPSCNNNeuronType,
514            parameter_a: c_float,
515            parameter_b: c_float,
516            parameter_c: c_float,
517        );
518
519        #[cfg(feature = "MPSCNNNeuronType")]
520        /// Getter funtion for neuronType set using setNeuronType:parameterA:parameterB:parameterC method
521        #[unsafe(method(neuronType))]
522        #[unsafe(method_family = none)]
523        pub unsafe fn neuronType(&self) -> MPSCNNNeuronType;
524
525        /// Getter funtion for neuronType set using setNeuronType:parameterA:parameterB:parameterC method
526        #[unsafe(method(neuronParameterA))]
527        #[unsafe(method_family = none)]
528        pub unsafe fn neuronParameterA(&self) -> c_float;
529
530        /// Getter funtion for neuronType set using setNeuronType:parameterA:parameterB:parameterC method
531        #[unsafe(method(neuronParameterB))]
532        #[unsafe(method_family = none)]
533        pub unsafe fn neuronParameterB(&self) -> c_float;
534
535        /// Getter funtion for neuronType set using setNeuronType:parameterA:parameterB:parameterC method
536        #[unsafe(method(neuronParameterC))]
537        #[unsafe(method_family = none)]
538        pub unsafe fn neuronParameterC(&self) -> c_float;
539
540        /// Add per output value neuron parameters A for PReLu neuron activation functions.
541        ///
542        ///
543        /// This method sets the neuron to PReLU, zeros parameters A and B and sets the per output value
544        /// neuron parameters A to an array containing a unique value of A for each output value.
545        ///
546        /// If the neuron function is f(v,a,b), it will apply
547        ///
548        /// resultMatrix(i, j) = f( input(i, j), A[j], B[j] )
549        /// where j in [0, sourceInputFeatureChannels]
550        ///
551        /// See https://arxiv.org/pdf/1502.01852.pdf for details.
552        ///
553        /// All other neuron types, where parameter A
554        /// and parameter B are shared across output values must be set using
555        /// -setNeuronType:parameterA:parameterB:
556        ///
557        ///
558        /// Parameter `A`: An array containing float values for neuron parameter A.
559        /// Number of entries must be equal to MIN(inputMatrix.columns - sourceMatrixOrigin.y, sourceInputFeatureChannels)
560        #[unsafe(method(setNeuronToPReLUWithParametersA:))]
561        #[unsafe(method_family = none)]
562        pub unsafe fn setNeuronToPReLUWithParametersA(&self, a: &NSData);
563
564        #[unsafe(method(initWithDevice:))]
565        #[unsafe(method_family = init)]
566        pub unsafe fn initWithDevice(
567            this: Allocated<Self>,
568            device: &ProtocolObject<dyn MTLDevice>,
569        ) -> Retained<Self>;
570
571        /// Encode a MPSMatrixNeuronGradient object to a command buffer and compute
572        /// its gradient with respect to its input data.
573        ///
574        ///
575        /// Parameter `commandBuffer`: The commandBuffer on which to encode the operation.
576        ///
577        ///
578        /// Parameter `gradientMatrix`: A matrix whose values represent the gradient of a
579        /// loss function with respect to the results of a forward
580        /// MPSMatrixNeuron operation.
581        ///
582        ///
583        /// Parameter `inputMatrix`: A matrix containing the inputs to a forward MPSMatrixNeuron
584        /// operation for which the gradient values are to be computed.
585        ///
586        ///
587        /// Parameter `biasVector`: A vector containing the bias terms.
588        ///
589        ///
590        /// Parameter `resultGradientForDataMatrix`: The matrix containing the resulting gradient values.
591        ///
592        ///
593        /// Parameter `resultGradientForBiasVector`: If non-NULL the vector containing gradients for the bias
594        /// terms.
595        #[unsafe(method(encodeToCommandBuffer:gradientMatrix:inputMatrix:biasVector:resultGradientForDataMatrix:resultGradientForBiasVector:))]
596        #[unsafe(method_family = none)]
597        pub unsafe fn encodeToCommandBuffer_gradientMatrix_inputMatrix_biasVector_resultGradientForDataMatrix_resultGradientForBiasVector(
598            &self,
599            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
600            gradient_matrix: &MPSMatrix,
601            input_matrix: &MPSMatrix,
602            bias_vector: Option<&MPSVector>,
603            result_gradient_for_data_matrix: &MPSMatrix,
604            result_gradient_for_bias_vector: Option<&MPSVector>,
605        );
606
607        /// NSSecureCoding compatability
608        ///
609        /// See
610        /// MPSKernel#initWithCoder.
611        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSMatrixNeuronGradient
612        ///
613        /// Parameter `device`: The MTLDevice on which to make the MPSMatrixNeuronGradient object.
614        ///
615        /// Returns: A new MPSMatrixNeuronGradient object, or nil if failure.
616        ///
617        /// # Safety
618        ///
619        /// `a_decoder` possibly has further requirements.
620        #[unsafe(method(initWithCoder:device:))]
621        #[unsafe(method_family = init)]
622        pub unsafe fn initWithCoder_device(
623            this: Allocated<Self>,
624            a_decoder: &NSCoder,
625            device: &ProtocolObject<dyn MTLDevice>,
626        ) -> Option<Retained<Self>>;
627
628        /// Make a copy of this kernel for a new device -
629        ///
630        /// See: MPSKernel
631        ///
632        /// Parameter `zone`: The NSZone in which to allocate the object
633        ///
634        /// Parameter `device`: The device for the new MPSKernel. If nil, then use
635        /// self.device.
636        ///
637        /// Returns: A pointer to a copy of this MPSKernel. This will fail, returning
638        /// nil if the device is not supported. Devices must be
639        /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
640        ///
641        /// # Safety
642        ///
643        /// `zone` must be a valid pointer or null.
644        #[unsafe(method(copyWithZone:device:))]
645        #[unsafe(method_family = copy)]
646        pub unsafe fn copyWithZone_device(
647            &self,
648            zone: *mut NSZone,
649            device: Option<&ProtocolObject<dyn MTLDevice>>,
650        ) -> Retained<Self>;
651    );
652}
653
654/// Methods declared on superclass `MPSKernel`.
655#[cfg(all(
656    feature = "MPSCore",
657    feature = "MPSKernel",
658    feature = "MPSMatrix",
659    feature = "MPSMatrixTypes"
660))]
661impl MPSMatrixNeuronGradient {
662    extern_methods!(
663        /// Called by NSCoder to decode MPSKernels
664        ///
665        /// This isn't the right interface to decode a MPSKernel, but
666        /// it is the one that NSCoder uses. To enable your NSCoder
667        /// (e.g. NSKeyedUnarchiver) to set which device to use
668        /// extend the object to adopt the MPSDeviceProvider
669        /// protocol. Otherwise, the Metal system default device
670        /// will be used.
671        ///
672        /// # Safety
673        ///
674        /// `a_decoder` possibly has further requirements.
675        #[unsafe(method(initWithCoder:))]
676        #[unsafe(method_family = init)]
677        pub unsafe fn initWithCoder(
678            this: Allocated<Self>,
679            a_decoder: &NSCoder,
680        ) -> Option<Retained<Self>>;
681    );
682}
683
684/// Methods declared on superclass `NSObject`.
685#[cfg(all(
686    feature = "MPSCore",
687    feature = "MPSKernel",
688    feature = "MPSMatrix",
689    feature = "MPSMatrixTypes"
690))]
691impl MPSMatrixNeuronGradient {
692    extern_methods!(
693        #[unsafe(method(init))]
694        #[unsafe(method_family = init)]
695        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
696
697        #[unsafe(method(new))]
698        #[unsafe(method_family = new)]
699        pub unsafe fn new() -> Retained<Self>;
700    );
701}