objc2_metal_performance_shaders/generated/MPSNeuralNetwork/MPSCNNNormalization.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 /// Specifies the spatial normalization filter.
15 /// The spatial normalization for a feature channel applies the filter over local regions which extend
16 /// spatially, but are in separate feature channels (i.e., they have shape 1 x kernelWidth x kernelHeight).
17 /// For each feature channel, the function computes the sum of squares of X inside each rectangle, N2(i,j).
18 /// It then divides each element of X as follows:
19 /// Y(i,j) = X(i,j) / (delta + alpha/(kw*kh) * N2(i,j))^beta,
20 /// where kw and kh are the kernelWidth and the kernelHeight.
21 /// It is the end-users responsibility to ensure that the combination of the
22 /// parameters delta and alpha does not result in a situation where the denominator
23 /// becomes zero - in such situations the resulting pixel-value is undefined.
24 ///
25 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnspatialnormalization?language=objc)
26 #[unsafe(super(MPSCNNKernel, MPSKernel, NSObject))]
27 #[derive(Debug, PartialEq, Eq, Hash)]
28 #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
29 pub struct MPSCNNSpatialNormalization;
30);
31
32#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
33extern_conformance!(
34 unsafe impl NSCoding for MPSCNNSpatialNormalization {}
35);
36
37#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
38extern_conformance!(
39 unsafe impl NSCopying for MPSCNNSpatialNormalization {}
40);
41
42#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
43unsafe impl CopyingHelper for MPSCNNSpatialNormalization {
44 type Result = Self;
45}
46
47#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
48extern_conformance!(
49 unsafe impl NSObjectProtocol for MPSCNNSpatialNormalization {}
50);
51
52#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
53extern_conformance!(
54 unsafe impl NSSecureCoding for MPSCNNSpatialNormalization {}
55);
56
57#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
58impl MPSCNNSpatialNormalization {
59 extern_methods!(
60 /// The value of alpha. Default is 1.0. Must be non-negative.
61 #[unsafe(method(alpha))]
62 #[unsafe(method_family = none)]
63 pub unsafe fn alpha(&self) -> c_float;
64
65 /// Setter for [`alpha`][Self::alpha].
66 #[unsafe(method(setAlpha:))]
67 #[unsafe(method_family = none)]
68 pub unsafe fn setAlpha(&self, alpha: c_float);
69
70 /// The value of beta. Default is 5.0
71 #[unsafe(method(beta))]
72 #[unsafe(method_family = none)]
73 pub unsafe fn beta(&self) -> c_float;
74
75 /// Setter for [`beta`][Self::beta].
76 #[unsafe(method(setBeta:))]
77 #[unsafe(method_family = none)]
78 pub unsafe fn setBeta(&self, beta: c_float);
79
80 /// The value of delta. Default is 1.0
81 #[unsafe(method(delta))]
82 #[unsafe(method_family = none)]
83 pub unsafe fn delta(&self) -> c_float;
84
85 /// Setter for [`delta`][Self::delta].
86 #[unsafe(method(setDelta:))]
87 #[unsafe(method_family = none)]
88 pub unsafe fn setDelta(&self, delta: c_float);
89
90 /// Initialize a spatial normalization filter
91 ///
92 /// Parameter `device`: The device the filter will run on
93 ///
94 /// Parameter `kernelWidth`: The width of the kernel
95 ///
96 /// Parameter `kernelHeight`: The height of the kernel
97 ///
98 /// Returns: A valid MPSCNNSpatialNormalization object or nil, if failure.
99 ///
100 /// NOTE: For now, kernelWidth must be equal to kernelHeight
101 #[unsafe(method(initWithDevice:kernelWidth:kernelHeight:))]
102 #[unsafe(method_family = init)]
103 pub unsafe fn initWithDevice_kernelWidth_kernelHeight(
104 this: Allocated<Self>,
105 device: &ProtocolObject<dyn MTLDevice>,
106 kernel_width: NSUInteger,
107 kernel_height: NSUInteger,
108 ) -> Retained<Self>;
109
110 /// NSSecureCoding compatability
111 ///
112 /// While the standard NSSecureCoding/NSCoding method
113 /// -initWithCoder: should work, since the file can't
114 /// know which device your data is allocated on, we
115 /// have to guess and may guess incorrectly. To avoid
116 /// that problem, use initWithCoder:device instead.
117 ///
118 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
119 ///
120 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
121 ///
122 /// Returns: A new MPSKernel object, or nil if failure.
123 ///
124 /// # Safety
125 ///
126 /// `a_decoder` possibly has further requirements.
127 #[unsafe(method(initWithCoder:device:))]
128 #[unsafe(method_family = init)]
129 pub unsafe fn initWithCoder_device(
130 this: Allocated<Self>,
131 a_decoder: &NSCoder,
132 device: &ProtocolObject<dyn MTLDevice>,
133 ) -> Option<Retained<Self>>;
134
135 #[unsafe(method(initWithDevice:))]
136 #[unsafe(method_family = init)]
137 pub unsafe fn initWithDevice(
138 this: Allocated<Self>,
139 device: &ProtocolObject<dyn MTLDevice>,
140 ) -> Retained<Self>;
141 );
142}
143
144/// Methods declared on superclass `MPSKernel`.
145#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
146impl MPSCNNSpatialNormalization {
147 extern_methods!(
148 /// Called by NSCoder to decode MPSKernels
149 ///
150 /// This isn't the right interface to decode a MPSKernel, but
151 /// it is the one that NSCoder uses. To enable your NSCoder
152 /// (e.g. NSKeyedUnarchiver) to set which device to use
153 /// extend the object to adopt the MPSDeviceProvider
154 /// protocol. Otherwise, the Metal system default device
155 /// will be used.
156 ///
157 /// # Safety
158 ///
159 /// `a_decoder` possibly has further requirements.
160 #[unsafe(method(initWithCoder:))]
161 #[unsafe(method_family = init)]
162 pub unsafe fn initWithCoder(
163 this: Allocated<Self>,
164 a_decoder: &NSCoder,
165 ) -> Option<Retained<Self>>;
166 );
167}
168
169/// Methods declared on superclass `NSObject`.
170#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
171impl MPSCNNSpatialNormalization {
172 extern_methods!(
173 #[unsafe(method(init))]
174 #[unsafe(method_family = init)]
175 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
176
177 #[unsafe(method(new))]
178 #[unsafe(method_family = new)]
179 pub unsafe fn new() -> Retained<Self>;
180 );
181}
182
183extern_class!(
184 /// Dependencies: This depends on Metal.framework
185 ///
186 /// Specifies the spatial normalization gradient filter.
187 /// The spatial normalization for a feature channel applies the filter over local regions which extend
188 /// spatially, but are in separate feature channels (i.e., they have shape 1 x kernelWidth x kernelHeight).
189 /// For each feature channel, the function computes the sum of squares of X inside each rectangle, N2(i,j).
190 /// It then divides each element of X as follows:
191 /// Y(i,j) = X(i,j) / (delta + alpha/(kw*kh) * N2(i,j))^beta,
192 /// where kw and kh are the kernelWidth and the kernelHeight.
193 /// It is the end-users responsibility to ensure that the combination of the
194 /// parameters delta and alpha does not result in a situation where the denominator
195 /// becomes zero - in such situations the resulting pixel-value is undefined.
196 ///
197 /// T(i,j) = (delta + alpha/(kw*kh) * N2(i,j))
198 /// N = kw * kh
199 ///
200 /// OutputGradient:
201 /// dZ/dX(i,j) = T(i,j)^(-beta) * ( dZ/dY(i,j) - (2*alpha*beta*X(i,j)/T(i,j)) * (sum_{l,k in L(i),K(j)} dZ/dY(l,k)*X(l,k)) )
202 /// N is the kernel size. The window R(k) itself is defined as:
203 /// L(i) = [i-floor((kw-1)/2), i+floor(kw/2]
204 /// K(j) = [j-floor((kh-1)/2), j+floor(kh/2]
205 ///
206 /// For correct gradient computation all parameters must be the same as the original normalization filter.
207 ///
208 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnspatialnormalizationgradient?language=objc)
209 #[unsafe(super(MPSCNNGradientKernel, MPSCNNBinaryKernel, MPSKernel, NSObject))]
210 #[derive(Debug, PartialEq, Eq, Hash)]
211 #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
212 pub struct MPSCNNSpatialNormalizationGradient;
213);
214
215#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
216extern_conformance!(
217 unsafe impl NSCoding for MPSCNNSpatialNormalizationGradient {}
218);
219
220#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
221extern_conformance!(
222 unsafe impl NSCopying for MPSCNNSpatialNormalizationGradient {}
223);
224
225#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
226unsafe impl CopyingHelper for MPSCNNSpatialNormalizationGradient {
227 type Result = Self;
228}
229
230#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
231extern_conformance!(
232 unsafe impl NSObjectProtocol for MPSCNNSpatialNormalizationGradient {}
233);
234
235#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
236extern_conformance!(
237 unsafe impl NSSecureCoding for MPSCNNSpatialNormalizationGradient {}
238);
239
240#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
241impl MPSCNNSpatialNormalizationGradient {
242 extern_methods!(
243 /// The value of alpha. Default is 1.0. Must be non-negative.
244 #[unsafe(method(alpha))]
245 #[unsafe(method_family = none)]
246 pub unsafe fn alpha(&self) -> c_float;
247
248 /// Setter for [`alpha`][Self::alpha].
249 #[unsafe(method(setAlpha:))]
250 #[unsafe(method_family = none)]
251 pub unsafe fn setAlpha(&self, alpha: c_float);
252
253 /// The value of beta. Default is 5.0
254 #[unsafe(method(beta))]
255 #[unsafe(method_family = none)]
256 pub unsafe fn beta(&self) -> c_float;
257
258 /// Setter for [`beta`][Self::beta].
259 #[unsafe(method(setBeta:))]
260 #[unsafe(method_family = none)]
261 pub unsafe fn setBeta(&self, beta: c_float);
262
263 /// The value of delta. Default is 1.0
264 #[unsafe(method(delta))]
265 #[unsafe(method_family = none)]
266 pub unsafe fn delta(&self) -> c_float;
267
268 /// Setter for [`delta`][Self::delta].
269 #[unsafe(method(setDelta:))]
270 #[unsafe(method_family = none)]
271 pub unsafe fn setDelta(&self, delta: c_float);
272
273 /// Initialize a spatial normalization filter
274 ///
275 /// Parameter `device`: The device the filter will run on
276 ///
277 /// Parameter `kernelWidth`: The width of the kernel
278 ///
279 /// Parameter `kernelHeight`: The height of the kernel
280 ///
281 /// Returns: A valid MPSCNNSpatialNormalization object or nil, if failure.
282 ///
283 /// NOTE: For now, kernelWidth must be equal to kernelHeight
284 #[unsafe(method(initWithDevice:kernelWidth:kernelHeight:))]
285 #[unsafe(method_family = init)]
286 pub unsafe fn initWithDevice_kernelWidth_kernelHeight(
287 this: Allocated<Self>,
288 device: &ProtocolObject<dyn MTLDevice>,
289 kernel_width: NSUInteger,
290 kernel_height: NSUInteger,
291 ) -> Retained<Self>;
292
293 /// NSSecureCoding compatability
294 ///
295 /// While the standard NSSecureCoding/NSCoding method
296 /// -initWithCoder: should work, since the file can't
297 /// know which device your data is allocated on, we
298 /// have to guess and may guess incorrectly. To avoid
299 /// that problem, use initWithCoder:device instead.
300 ///
301 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
302 ///
303 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
304 ///
305 /// Returns: A new MPSKernel object, or nil if failure.
306 ///
307 /// # Safety
308 ///
309 /// `a_decoder` possibly has further requirements.
310 #[unsafe(method(initWithCoder:device:))]
311 #[unsafe(method_family = init)]
312 pub unsafe fn initWithCoder_device(
313 this: Allocated<Self>,
314 a_decoder: &NSCoder,
315 device: &ProtocolObject<dyn MTLDevice>,
316 ) -> Option<Retained<Self>>;
317 );
318}
319
320/// Methods declared on superclass `MPSCNNGradientKernel`.
321#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
322impl MPSCNNSpatialNormalizationGradient {
323 extern_methods!(
324 /// Standard init with default properties per filter type
325 ///
326 /// Parameter `device`: The device that the filter will be used on. May not be NULL.
327 ///
328 /// Returns: A pointer to the newly initialized object. This will fail, returning
329 /// nil if the device is not supported. Devices must be
330 /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
331 #[unsafe(method(initWithDevice:))]
332 #[unsafe(method_family = init)]
333 pub unsafe fn initWithDevice(
334 this: Allocated<Self>,
335 device: &ProtocolObject<dyn MTLDevice>,
336 ) -> Retained<Self>;
337 );
338}
339
340/// Methods declared on superclass `MPSKernel`.
341#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
342impl MPSCNNSpatialNormalizationGradient {
343 extern_methods!(
344 /// Called by NSCoder to decode MPSKernels
345 ///
346 /// This isn't the right interface to decode a MPSKernel, but
347 /// it is the one that NSCoder uses. To enable your NSCoder
348 /// (e.g. NSKeyedUnarchiver) to set which device to use
349 /// extend the object to adopt the MPSDeviceProvider
350 /// protocol. Otherwise, the Metal system default device
351 /// will be used.
352 ///
353 /// # Safety
354 ///
355 /// `a_decoder` possibly has further requirements.
356 #[unsafe(method(initWithCoder:))]
357 #[unsafe(method_family = init)]
358 pub unsafe fn initWithCoder(
359 this: Allocated<Self>,
360 a_decoder: &NSCoder,
361 ) -> Option<Retained<Self>>;
362 );
363}
364
365/// Methods declared on superclass `NSObject`.
366#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
367impl MPSCNNSpatialNormalizationGradient {
368 extern_methods!(
369 #[unsafe(method(init))]
370 #[unsafe(method_family = init)]
371 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
372
373 #[unsafe(method(new))]
374 #[unsafe(method_family = new)]
375 pub unsafe fn new() -> Retained<Self>;
376 );
377}
378
379extern_class!(
380 /// Dependencies: This depends on Metal.framework
381 ///
382 /// Specifies the local contrast normalization filter.
383 /// The local contrast normalization is quite similar to spatial normalization
384 /// (see
385 /// MPSCNNSpatialNormalization)in that it applies the filter over local regions which extend
386 /// spatially, but are in separate feature channels (i.e., they have shape 1 x kernelWidth x kernelHeight),
387 /// but instead of dividing by the local "energy" of the feature, the denominator uses the local variance
388 /// of the feature - effectively the mean value of the feature is subtracted from the signal.
389 /// For each feature channel, the function computes the variance VAR(i,j) and
390 /// mean M(i,j) of X(i,j) inside each rectangle around the spatial point (i,j).
391 ///
392 /// Then the result is computed for each element of X as follows:
393 ///
394 /// Y(i,j) = pm + ps * ( X(i,j) - p0 * M(i,j)) / (delta + alpha * VAR(i,j))^beta,
395 ///
396 /// where kw and kh are the kernelWidth and the kernelHeight and pm, ps and p0 are parameters that
397 /// can be used to offset and scale the result in various ways. For example setting
398 /// pm=0, ps=1, p0=1, delta=0, alpha=1.0 and beta=0.5 scales input data so that the result has
399 /// unit variance and zero mean, provided that input variance is positive.
400 /// It is the end-users responsibility to ensure that the combination of the
401 /// parameters delta and alpha does not result in a situation where the denominator
402 /// becomes zero - in such situations the resulting pixel-value is undefined. A good way to guard
403 /// against tiny variances is to regulate the expression with a small value for delta, for example
404 /// delta = 1/1024 = 0.0009765625.
405 ///
406 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnlocalcontrastnormalization?language=objc)
407 #[unsafe(super(MPSCNNKernel, MPSKernel, NSObject))]
408 #[derive(Debug, PartialEq, Eq, Hash)]
409 #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
410 pub struct MPSCNNLocalContrastNormalization;
411);
412
413#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
414extern_conformance!(
415 unsafe impl NSCoding for MPSCNNLocalContrastNormalization {}
416);
417
418#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
419extern_conformance!(
420 unsafe impl NSCopying for MPSCNNLocalContrastNormalization {}
421);
422
423#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
424unsafe impl CopyingHelper for MPSCNNLocalContrastNormalization {
425 type Result = Self;
426}
427
428#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
429extern_conformance!(
430 unsafe impl NSObjectProtocol for MPSCNNLocalContrastNormalization {}
431);
432
433#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
434extern_conformance!(
435 unsafe impl NSSecureCoding for MPSCNNLocalContrastNormalization {}
436);
437
438#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
439impl MPSCNNLocalContrastNormalization {
440 extern_methods!(
441 /// The value of alpha. Default is 0.0
442 ///
443 /// The default value 0.0 is not recommended and is
444 /// preserved for backwards compatibility. With alpha 0,
445 /// it performs a local mean subtraction. The
446 /// MPSCNNLocalContrastNormalizationNode used with
447 /// the MPSNNGraph uses 1.0 as a default.
448 #[unsafe(method(alpha))]
449 #[unsafe(method_family = none)]
450 pub unsafe fn alpha(&self) -> c_float;
451
452 /// Setter for [`alpha`][Self::alpha].
453 #[unsafe(method(setAlpha:))]
454 #[unsafe(method_family = none)]
455 pub unsafe fn setAlpha(&self, alpha: c_float);
456
457 /// The value of beta. Default is 0.5
458 #[unsafe(method(beta))]
459 #[unsafe(method_family = none)]
460 pub unsafe fn beta(&self) -> c_float;
461
462 /// Setter for [`beta`][Self::beta].
463 #[unsafe(method(setBeta:))]
464 #[unsafe(method_family = none)]
465 pub unsafe fn setBeta(&self, beta: c_float);
466
467 /// The value of delta. Default is 1/1024
468 #[unsafe(method(delta))]
469 #[unsafe(method_family = none)]
470 pub unsafe fn delta(&self) -> c_float;
471
472 /// Setter for [`delta`][Self::delta].
473 #[unsafe(method(setDelta:))]
474 #[unsafe(method_family = none)]
475 pub unsafe fn setDelta(&self, delta: c_float);
476
477 /// The value of p0. Default is 1.0
478 #[unsafe(method(p0))]
479 #[unsafe(method_family = none)]
480 pub unsafe fn p0(&self) -> c_float;
481
482 /// Setter for [`p0`][Self::p0].
483 #[unsafe(method(setP0:))]
484 #[unsafe(method_family = none)]
485 pub unsafe fn setP0(&self, p0: c_float);
486
487 /// The value of pm. Default is 0.0
488 #[unsafe(method(pm))]
489 #[unsafe(method_family = none)]
490 pub unsafe fn pm(&self) -> c_float;
491
492 /// Setter for [`pm`][Self::pm].
493 #[unsafe(method(setPm:))]
494 #[unsafe(method_family = none)]
495 pub unsafe fn setPm(&self, pm: c_float);
496
497 /// The value of ps. Default is 1.0
498 #[unsafe(method(ps))]
499 #[unsafe(method_family = none)]
500 pub unsafe fn ps(&self) -> c_float;
501
502 /// Setter for [`ps`][Self::ps].
503 #[unsafe(method(setPs:))]
504 #[unsafe(method_family = none)]
505 pub unsafe fn setPs(&self, ps: c_float);
506
507 /// Initialize a local contrast normalization filter
508 ///
509 /// Parameter `device`: The device the filter will run on
510 ///
511 /// Parameter `kernelWidth`: The width of the kernel
512 ///
513 /// Parameter `kernelHeight`: The height of the kernel
514 ///
515 /// Returns: A valid MPSCNNLocalContrastNormalization object or nil, if failure.
516 ///
517 /// NOTE: For now, kernelWidth must be equal to kernelHeight
518 #[unsafe(method(initWithDevice:kernelWidth:kernelHeight:))]
519 #[unsafe(method_family = init)]
520 pub unsafe fn initWithDevice_kernelWidth_kernelHeight(
521 this: Allocated<Self>,
522 device: &ProtocolObject<dyn MTLDevice>,
523 kernel_width: NSUInteger,
524 kernel_height: NSUInteger,
525 ) -> Retained<Self>;
526
527 /// NSSecureCoding compatability
528 ///
529 /// While the standard NSSecureCoding/NSCoding method
530 /// -initWithCoder: should work, since the file can't
531 /// know which device your data is allocated on, we
532 /// have to guess and may guess incorrectly. To avoid
533 /// that problem, use initWithCoder:device instead.
534 ///
535 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
536 ///
537 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
538 ///
539 /// Returns: A new MPSKernel object, or nil if failure.
540 ///
541 /// # Safety
542 ///
543 /// `a_decoder` possibly has further requirements.
544 #[unsafe(method(initWithCoder:device:))]
545 #[unsafe(method_family = init)]
546 pub unsafe fn initWithCoder_device(
547 this: Allocated<Self>,
548 a_decoder: &NSCoder,
549 device: &ProtocolObject<dyn MTLDevice>,
550 ) -> Option<Retained<Self>>;
551
552 #[unsafe(method(initWithDevice:))]
553 #[unsafe(method_family = init)]
554 pub unsafe fn initWithDevice(
555 this: Allocated<Self>,
556 device: &ProtocolObject<dyn MTLDevice>,
557 ) -> Retained<Self>;
558 );
559}
560
561/// Methods declared on superclass `MPSKernel`.
562#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
563impl MPSCNNLocalContrastNormalization {
564 extern_methods!(
565 /// Called by NSCoder to decode MPSKernels
566 ///
567 /// This isn't the right interface to decode a MPSKernel, but
568 /// it is the one that NSCoder uses. To enable your NSCoder
569 /// (e.g. NSKeyedUnarchiver) to set which device to use
570 /// extend the object to adopt the MPSDeviceProvider
571 /// protocol. Otherwise, the Metal system default device
572 /// will be used.
573 ///
574 /// # Safety
575 ///
576 /// `a_decoder` possibly has further requirements.
577 #[unsafe(method(initWithCoder:))]
578 #[unsafe(method_family = init)]
579 pub unsafe fn initWithCoder(
580 this: Allocated<Self>,
581 a_decoder: &NSCoder,
582 ) -> Option<Retained<Self>>;
583 );
584}
585
586/// Methods declared on superclass `NSObject`.
587#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
588impl MPSCNNLocalContrastNormalization {
589 extern_methods!(
590 #[unsafe(method(init))]
591 #[unsafe(method_family = init)]
592 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
593
594 #[unsafe(method(new))]
595 #[unsafe(method_family = new)]
596 pub unsafe fn new() -> Retained<Self>;
597 );
598}
599
600extern_class!(
601 /// Dependencies: This depends on Metal.framework
602 ///
603 /// Specifies the local contrast normalization gradient filter.
604 /// The local contrast normalization is quite similar to spatial normalization
605 /// (see
606 /// MPSCNNSpatialNormalization)in that it applies the filter over local regions which extend
607 /// spatially, but are in separate feature channels (i.e., they have shape 1 x kernelWidth x kernelHeight),
608 /// but instead of dividing by the local "energy" of the feature, the denominator uses the local variance
609 /// of the feature - effectively the mean value of the feature is subtracted from the signal.
610 /// For each feature channel, the function computes the variance VAR(i,j) and
611 /// mean M(i,j) of X(i,j) inside each rectangle around the spatial point (i,j).
612 ///
613 /// Then the result is computed for each element of X as follows:
614 ///
615 /// Y(i,j) = pm + ps * ( X(i,j) - p0 * M(i,j)) / (delta + alpha * VAR(i,j))^beta,
616 ///
617 /// where kw and kh are the kernelWidth and the kernelHeight and pm, ps and p0 are parameters that
618 /// can be used to offset and scale the result in various ways. For example setting
619 /// pm=0, ps=1, p0=1, delta=0, alpha=1.0 and beta=0.5 scales input data so that the result has
620 /// unit variance and zero mean, provided that input variance is positive.
621 /// It is the end-users responsibility to ensure that the combination of the
622 /// parameters delta and alpha does not result in a situation where the denominator
623 /// becomes zero - in such situations the resulting pixel-value is undefined. A good way to guard
624 /// against tiny variances is to regulate the expression with a small value for delta, for example
625 /// delta = 1/1024 = 0.0009765625.
626 ///
627 /// T(i,j) = (delta + alpha * VAR(i,j))
628 /// N = kw * kh
629 ///
630 /// OutputGradient:
631 /// dZ/dX(i,j) = ps * T(i,j)^(-beta) * ( dZ/dY(i,j) - (sum_{l,k in L(i),K(j)} dZ/dY(l,k) * (((p0/N) + (2*alpha*beta/N)*(X(k,l)-1)*(X(i,j)-M(i,j)*p0)/T(i,j)))) )
632 /// N is the kernel size. The window L(i) and K(j) itself is defined as:
633 /// L(i) = [i-floor((kw-1)/2), i+floor(kw/2]
634 /// K(j) = [j-floor((kh-1)/2), j+floor(kh/2]
635 ///
636 /// For correct gradient computation all parameters must be the same as the original normalization filter.
637 ///
638 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnlocalcontrastnormalizationgradient?language=objc)
639 #[unsafe(super(MPSCNNGradientKernel, MPSCNNBinaryKernel, MPSKernel, NSObject))]
640 #[derive(Debug, PartialEq, Eq, Hash)]
641 #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
642 pub struct MPSCNNLocalContrastNormalizationGradient;
643);
644
645#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
646extern_conformance!(
647 unsafe impl NSCoding for MPSCNNLocalContrastNormalizationGradient {}
648);
649
650#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
651extern_conformance!(
652 unsafe impl NSCopying for MPSCNNLocalContrastNormalizationGradient {}
653);
654
655#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
656unsafe impl CopyingHelper for MPSCNNLocalContrastNormalizationGradient {
657 type Result = Self;
658}
659
660#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
661extern_conformance!(
662 unsafe impl NSObjectProtocol for MPSCNNLocalContrastNormalizationGradient {}
663);
664
665#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
666extern_conformance!(
667 unsafe impl NSSecureCoding for MPSCNNLocalContrastNormalizationGradient {}
668);
669
670#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
671impl MPSCNNLocalContrastNormalizationGradient {
672 extern_methods!(
673 /// The value of alpha. Default is 0.0
674 ///
675 /// The default value 0.0 is not recommended and is
676 /// preserved for backwards compatibility. With alpha 0,
677 /// it performs a local mean subtraction. The
678 /// MPSCNNLocalContrastNormalizationNode used with
679 /// the MPSNNGraph uses 1.0 as a default.
680 #[unsafe(method(alpha))]
681 #[unsafe(method_family = none)]
682 pub unsafe fn alpha(&self) -> c_float;
683
684 /// Setter for [`alpha`][Self::alpha].
685 #[unsafe(method(setAlpha:))]
686 #[unsafe(method_family = none)]
687 pub unsafe fn setAlpha(&self, alpha: c_float);
688
689 /// The value of beta. Default is 0.5
690 #[unsafe(method(beta))]
691 #[unsafe(method_family = none)]
692 pub unsafe fn beta(&self) -> c_float;
693
694 /// Setter for [`beta`][Self::beta].
695 #[unsafe(method(setBeta:))]
696 #[unsafe(method_family = none)]
697 pub unsafe fn setBeta(&self, beta: c_float);
698
699 /// The value of delta. Default is 1/1024
700 #[unsafe(method(delta))]
701 #[unsafe(method_family = none)]
702 pub unsafe fn delta(&self) -> c_float;
703
704 /// Setter for [`delta`][Self::delta].
705 #[unsafe(method(setDelta:))]
706 #[unsafe(method_family = none)]
707 pub unsafe fn setDelta(&self, delta: c_float);
708
709 /// The value of p0. Default is 1.0
710 #[unsafe(method(p0))]
711 #[unsafe(method_family = none)]
712 pub unsafe fn p0(&self) -> c_float;
713
714 /// Setter for [`p0`][Self::p0].
715 #[unsafe(method(setP0:))]
716 #[unsafe(method_family = none)]
717 pub unsafe fn setP0(&self, p0: c_float);
718
719 /// The value of pm. Default is 0.0
720 #[unsafe(method(pm))]
721 #[unsafe(method_family = none)]
722 pub unsafe fn pm(&self) -> c_float;
723
724 /// Setter for [`pm`][Self::pm].
725 #[unsafe(method(setPm:))]
726 #[unsafe(method_family = none)]
727 pub unsafe fn setPm(&self, pm: c_float);
728
729 /// The value of ps. Default is 1.0
730 #[unsafe(method(ps))]
731 #[unsafe(method_family = none)]
732 pub unsafe fn ps(&self) -> c_float;
733
734 /// Setter for [`ps`][Self::ps].
735 #[unsafe(method(setPs:))]
736 #[unsafe(method_family = none)]
737 pub unsafe fn setPs(&self, ps: c_float);
738
739 /// Initialize a local contrast normalization filter
740 ///
741 /// Parameter `device`: The device the filter will run on
742 ///
743 /// Parameter `kernelWidth`: The width of the kernel
744 ///
745 /// Parameter `kernelHeight`: The height of the kernel
746 ///
747 /// Returns: A valid MPSCNNLocalContrastNormalization object or nil, if failure.
748 ///
749 /// NOTE: For now, kernelWidth must be equal to kernelHeight
750 #[unsafe(method(initWithDevice:kernelWidth:kernelHeight:))]
751 #[unsafe(method_family = init)]
752 pub unsafe fn initWithDevice_kernelWidth_kernelHeight(
753 this: Allocated<Self>,
754 device: &ProtocolObject<dyn MTLDevice>,
755 kernel_width: NSUInteger,
756 kernel_height: NSUInteger,
757 ) -> Retained<Self>;
758
759 /// NSSecureCoding compatability
760 ///
761 /// While the standard NSSecureCoding/NSCoding method
762 /// -initWithCoder: should work, since the file can't
763 /// know which device your data is allocated on, we
764 /// have to guess and may guess incorrectly. To avoid
765 /// that problem, use initWithCoder:device instead.
766 ///
767 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
768 ///
769 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
770 ///
771 /// Returns: A new MPSKernel object, or nil if failure.
772 ///
773 /// # Safety
774 ///
775 /// `a_decoder` possibly has further requirements.
776 #[unsafe(method(initWithCoder:device:))]
777 #[unsafe(method_family = init)]
778 pub unsafe fn initWithCoder_device(
779 this: Allocated<Self>,
780 a_decoder: &NSCoder,
781 device: &ProtocolObject<dyn MTLDevice>,
782 ) -> Option<Retained<Self>>;
783 );
784}
785
786/// Methods declared on superclass `MPSCNNGradientKernel`.
787#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
788impl MPSCNNLocalContrastNormalizationGradient {
789 extern_methods!(
790 /// Standard init with default properties per filter type
791 ///
792 /// Parameter `device`: The device that the filter will be used on. May not be NULL.
793 ///
794 /// Returns: A pointer to the newly initialized object. This will fail, returning
795 /// nil if the device is not supported. Devices must be
796 /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
797 #[unsafe(method(initWithDevice:))]
798 #[unsafe(method_family = init)]
799 pub unsafe fn initWithDevice(
800 this: Allocated<Self>,
801 device: &ProtocolObject<dyn MTLDevice>,
802 ) -> Retained<Self>;
803 );
804}
805
806/// Methods declared on superclass `MPSKernel`.
807#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
808impl MPSCNNLocalContrastNormalizationGradient {
809 extern_methods!(
810 /// Called by NSCoder to decode MPSKernels
811 ///
812 /// This isn't the right interface to decode a MPSKernel, but
813 /// it is the one that NSCoder uses. To enable your NSCoder
814 /// (e.g. NSKeyedUnarchiver) to set which device to use
815 /// extend the object to adopt the MPSDeviceProvider
816 /// protocol. Otherwise, the Metal system default device
817 /// will be used.
818 ///
819 /// # Safety
820 ///
821 /// `a_decoder` possibly has further requirements.
822 #[unsafe(method(initWithCoder:))]
823 #[unsafe(method_family = init)]
824 pub unsafe fn initWithCoder(
825 this: Allocated<Self>,
826 a_decoder: &NSCoder,
827 ) -> Option<Retained<Self>>;
828 );
829}
830
831/// Methods declared on superclass `NSObject`.
832#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
833impl MPSCNNLocalContrastNormalizationGradient {
834 extern_methods!(
835 #[unsafe(method(init))]
836 #[unsafe(method_family = init)]
837 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
838
839 #[unsafe(method(new))]
840 #[unsafe(method_family = new)]
841 pub unsafe fn new() -> Retained<Self>;
842 );
843}
844
845extern_class!(
846 /// Dependencies: This depends on Metal.framework
847 ///
848 /// Specifies the normalization filter across feature channels.
849 /// This normalization filter applies the filter to a local region across nearby feature channels,
850 /// but with no spatial extent (i.e., they have shape kernelSize x 1 x 1).
851 /// The normalized output is given by:
852 /// Y(i,j,k) = X(i,j,k) / L(i,j,k)^beta,
853 /// where the normalizing factor is:
854 /// L(i,j,k) = delta + alpha/N * (sum_{q in Q(k)} X(i,j,q)^2, where
855 /// N is the kernel size. The window Q(k) itself is defined as:
856 /// Q(k) = [max(0, k-floor(N/2)), min(D-1, k+floor((N-1)/2)], where
857 ///
858 /// k is the feature channel index (running from 0 to D-1) and
859 /// D is the number of feature channels, and alpha, beta and delta are paremeters.
860 /// It is the end-users responsibility to ensure that the combination of the
861 /// parameters delta and alpha does not result in a situation where the denominator
862 /// becomes zero - in such situations the resulting pixel-value is undefined.
863 ///
864 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnncrosschannelnormalization?language=objc)
865 #[unsafe(super(MPSCNNKernel, MPSKernel, NSObject))]
866 #[derive(Debug, PartialEq, Eq, Hash)]
867 #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
868 pub struct MPSCNNCrossChannelNormalization;
869);
870
871#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
872extern_conformance!(
873 unsafe impl NSCoding for MPSCNNCrossChannelNormalization {}
874);
875
876#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
877extern_conformance!(
878 unsafe impl NSCopying for MPSCNNCrossChannelNormalization {}
879);
880
881#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
882unsafe impl CopyingHelper for MPSCNNCrossChannelNormalization {
883 type Result = Self;
884}
885
886#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
887extern_conformance!(
888 unsafe impl NSObjectProtocol for MPSCNNCrossChannelNormalization {}
889);
890
891#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
892extern_conformance!(
893 unsafe impl NSSecureCoding for MPSCNNCrossChannelNormalization {}
894);
895
896#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
897impl MPSCNNCrossChannelNormalization {
898 extern_methods!(
899 /// The value of alpha. Default is 1.0. Must be non-negative.
900 #[unsafe(method(alpha))]
901 #[unsafe(method_family = none)]
902 pub unsafe fn alpha(&self) -> c_float;
903
904 /// Setter for [`alpha`][Self::alpha].
905 #[unsafe(method(setAlpha:))]
906 #[unsafe(method_family = none)]
907 pub unsafe fn setAlpha(&self, alpha: c_float);
908
909 /// The value of beta. Default is 5.0
910 #[unsafe(method(beta))]
911 #[unsafe(method_family = none)]
912 pub unsafe fn beta(&self) -> c_float;
913
914 /// Setter for [`beta`][Self::beta].
915 #[unsafe(method(setBeta:))]
916 #[unsafe(method_family = none)]
917 pub unsafe fn setBeta(&self, beta: c_float);
918
919 /// The value of delta. Default is 1.0
920 #[unsafe(method(delta))]
921 #[unsafe(method_family = none)]
922 pub unsafe fn delta(&self) -> c_float;
923
924 /// Setter for [`delta`][Self::delta].
925 #[unsafe(method(setDelta:))]
926 #[unsafe(method_family = none)]
927 pub unsafe fn setDelta(&self, delta: c_float);
928
929 /// The size of the square filter window. Default is 5
930 #[unsafe(method(kernelSize))]
931 #[unsafe(method_family = none)]
932 pub unsafe fn kernelSize(&self) -> NSUInteger;
933
934 /// Initialize a local response normalization filter in a channel
935 ///
936 /// Parameter `device`: The device the filter will run on
937 ///
938 /// Parameter `kernelSize`: The kernel filter size in each dimension.
939 ///
940 /// Returns: A valid MPSCNNCrossChannelNormalization object or nil, if failure.
941 #[unsafe(method(initWithDevice:kernelSize:))]
942 #[unsafe(method_family = init)]
943 pub unsafe fn initWithDevice_kernelSize(
944 this: Allocated<Self>,
945 device: &ProtocolObject<dyn MTLDevice>,
946 kernel_size: NSUInteger,
947 ) -> Retained<Self>;
948
949 /// NSSecureCoding compatability
950 ///
951 /// While the standard NSSecureCoding/NSCoding method
952 /// -initWithCoder: should work, since the file can't
953 /// know which device your data is allocated on, we
954 /// have to guess and may guess incorrectly. To avoid
955 /// that problem, use initWithCoder:device instead.
956 ///
957 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
958 ///
959 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
960 ///
961 /// Returns: A new MPSKernel object, or nil if failure.
962 ///
963 /// # Safety
964 ///
965 /// `a_decoder` possibly has further requirements.
966 #[unsafe(method(initWithCoder:device:))]
967 #[unsafe(method_family = init)]
968 pub unsafe fn initWithCoder_device(
969 this: Allocated<Self>,
970 a_decoder: &NSCoder,
971 device: &ProtocolObject<dyn MTLDevice>,
972 ) -> Option<Retained<Self>>;
973
974 #[unsafe(method(initWithDevice:))]
975 #[unsafe(method_family = init)]
976 pub unsafe fn initWithDevice(
977 this: Allocated<Self>,
978 device: &ProtocolObject<dyn MTLDevice>,
979 ) -> Retained<Self>;
980 );
981}
982
983/// Methods declared on superclass `MPSKernel`.
984#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
985impl MPSCNNCrossChannelNormalization {
986 extern_methods!(
987 /// Called by NSCoder to decode MPSKernels
988 ///
989 /// This isn't the right interface to decode a MPSKernel, but
990 /// it is the one that NSCoder uses. To enable your NSCoder
991 /// (e.g. NSKeyedUnarchiver) to set which device to use
992 /// extend the object to adopt the MPSDeviceProvider
993 /// protocol. Otherwise, the Metal system default device
994 /// will be used.
995 ///
996 /// # Safety
997 ///
998 /// `a_decoder` possibly has further requirements.
999 #[unsafe(method(initWithCoder:))]
1000 #[unsafe(method_family = init)]
1001 pub unsafe fn initWithCoder(
1002 this: Allocated<Self>,
1003 a_decoder: &NSCoder,
1004 ) -> Option<Retained<Self>>;
1005 );
1006}
1007
1008/// Methods declared on superclass `NSObject`.
1009#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1010impl MPSCNNCrossChannelNormalization {
1011 extern_methods!(
1012 #[unsafe(method(init))]
1013 #[unsafe(method_family = init)]
1014 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1015
1016 #[unsafe(method(new))]
1017 #[unsafe(method_family = new)]
1018 pub unsafe fn new() -> Retained<Self>;
1019 );
1020}
1021
1022extern_class!(
1023 /// Dependencies: This depends on Metal.framework
1024 ///
1025 /// Specifies the normalization gradient filter across feature channels.
1026 /// This normalization filter applies the filter to a local region across nearby feature channels,
1027 /// but with no spatial extent (i.e., they have shape kernelSize x 1 x 1).
1028 /// The normalized output is given by:
1029 /// Y(i,j,k) = X(i,j,k) / L(i,j,k)^beta,
1030 /// where the normalizing factor is:
1031 /// L(i,j,k) = delta + alpha/N * (sum_{q in Q(k)} X(i,j,q)^2, where
1032 /// N is the kernel size. The window Q(k) itself is defined as:
1033 /// Q(k) = [max(0, k-floor(N/2)), min(D-1, k+floor((N-1)/2)], where
1034 ///
1035 /// k is the feature channel index (running from 0 to D-1) and
1036 /// D is the number of feature channels, and alpha, beta and delta are paremeters.
1037 /// It is the end-users responsibility to ensure that the combination of the
1038 /// parameters delta and alpha does not result in a situation where the denominator
1039 /// becomes zero - in such situations the resulting pixel-value is undefined.
1040 ///
1041 /// OutputGradient:
1042 /// dZ/dX(i,j,k) = dZ/dY(i,j,k) * (L(i,j,k)^-beta) - 2 * alpha * beta * X(i,j,k) * ( sum_{r in R(k)} dZ/dY(i,j,r) * X(i,j,r) * (L(i,j,r) ^ (-beta-1)) )
1043 /// N is the kernel size. The window L(i) and K(j) itself is defined as:
1044 /// R(k) = [max(0, k-floor((N-1)/2)), min(D-1, k+floor(N/2)]
1045 ///
1046 /// For correct gradient computation all parameters must be the same as the original normalization filter.
1047 ///
1048 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnncrosschannelnormalizationgradient?language=objc)
1049 #[unsafe(super(MPSCNNGradientKernel, MPSCNNBinaryKernel, MPSKernel, NSObject))]
1050 #[derive(Debug, PartialEq, Eq, Hash)]
1051 #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1052 pub struct MPSCNNCrossChannelNormalizationGradient;
1053);
1054
1055#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1056extern_conformance!(
1057 unsafe impl NSCoding for MPSCNNCrossChannelNormalizationGradient {}
1058);
1059
1060#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1061extern_conformance!(
1062 unsafe impl NSCopying for MPSCNNCrossChannelNormalizationGradient {}
1063);
1064
1065#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1066unsafe impl CopyingHelper for MPSCNNCrossChannelNormalizationGradient {
1067 type Result = Self;
1068}
1069
1070#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1071extern_conformance!(
1072 unsafe impl NSObjectProtocol for MPSCNNCrossChannelNormalizationGradient {}
1073);
1074
1075#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1076extern_conformance!(
1077 unsafe impl NSSecureCoding for MPSCNNCrossChannelNormalizationGradient {}
1078);
1079
1080#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1081impl MPSCNNCrossChannelNormalizationGradient {
1082 extern_methods!(
1083 /// The value of alpha. Default is 1.0. Must be non-negative.
1084 #[unsafe(method(alpha))]
1085 #[unsafe(method_family = none)]
1086 pub unsafe fn alpha(&self) -> c_float;
1087
1088 /// Setter for [`alpha`][Self::alpha].
1089 #[unsafe(method(setAlpha:))]
1090 #[unsafe(method_family = none)]
1091 pub unsafe fn setAlpha(&self, alpha: c_float);
1092
1093 /// The value of beta. Default is 5.0
1094 #[unsafe(method(beta))]
1095 #[unsafe(method_family = none)]
1096 pub unsafe fn beta(&self) -> c_float;
1097
1098 /// Setter for [`beta`][Self::beta].
1099 #[unsafe(method(setBeta:))]
1100 #[unsafe(method_family = none)]
1101 pub unsafe fn setBeta(&self, beta: c_float);
1102
1103 /// The value of delta. Default is 1.0
1104 #[unsafe(method(delta))]
1105 #[unsafe(method_family = none)]
1106 pub unsafe fn delta(&self) -> c_float;
1107
1108 /// Setter for [`delta`][Self::delta].
1109 #[unsafe(method(setDelta:))]
1110 #[unsafe(method_family = none)]
1111 pub unsafe fn setDelta(&self, delta: c_float);
1112
1113 /// The size of the square filter window. Default is 5
1114 #[unsafe(method(kernelSize))]
1115 #[unsafe(method_family = none)]
1116 pub unsafe fn kernelSize(&self) -> NSUInteger;
1117
1118 /// Initialize a cross channel normalization gradient filter
1119 ///
1120 /// Parameter `device`: The device the filter will run on
1121 ///
1122 /// Parameter `kernelSize`: The kernel filter size in each dimension.
1123 ///
1124 /// Returns: A valid MPSCNNCrossChannelNormalization object or nil, if failure.
1125 #[unsafe(method(initWithDevice:kernelSize:))]
1126 #[unsafe(method_family = init)]
1127 pub unsafe fn initWithDevice_kernelSize(
1128 this: Allocated<Self>,
1129 device: &ProtocolObject<dyn MTLDevice>,
1130 kernel_size: NSUInteger,
1131 ) -> Retained<Self>;
1132
1133 /// NSSecureCoding compatability
1134 ///
1135 /// While the standard NSSecureCoding/NSCoding method
1136 /// -initWithCoder: should work, since the file can't
1137 /// know which device your data is allocated on, we
1138 /// have to guess and may guess incorrectly. To avoid
1139 /// that problem, use initWithCoder:device instead.
1140 ///
1141 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
1142 ///
1143 /// Parameter `device`: The MTLDevice on which to make the MPSKernel
1144 ///
1145 /// Returns: A new MPSKernel object, or nil if failure.
1146 ///
1147 /// # Safety
1148 ///
1149 /// `a_decoder` possibly has further requirements.
1150 #[unsafe(method(initWithCoder:device:))]
1151 #[unsafe(method_family = init)]
1152 pub unsafe fn initWithCoder_device(
1153 this: Allocated<Self>,
1154 a_decoder: &NSCoder,
1155 device: &ProtocolObject<dyn MTLDevice>,
1156 ) -> Option<Retained<Self>>;
1157 );
1158}
1159
1160/// Methods declared on superclass `MPSCNNGradientKernel`.
1161#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1162impl MPSCNNCrossChannelNormalizationGradient {
1163 extern_methods!(
1164 /// Standard init with default properties per filter type
1165 ///
1166 /// Parameter `device`: The device that the filter will be used on. May not be NULL.
1167 ///
1168 /// Returns: A pointer to the newly initialized object. This will fail, returning
1169 /// nil if the device is not supported. Devices must be
1170 /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
1171 #[unsafe(method(initWithDevice:))]
1172 #[unsafe(method_family = init)]
1173 pub unsafe fn initWithDevice(
1174 this: Allocated<Self>,
1175 device: &ProtocolObject<dyn MTLDevice>,
1176 ) -> Retained<Self>;
1177 );
1178}
1179
1180/// Methods declared on superclass `MPSKernel`.
1181#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1182impl MPSCNNCrossChannelNormalizationGradient {
1183 extern_methods!(
1184 /// Called by NSCoder to decode MPSKernels
1185 ///
1186 /// This isn't the right interface to decode a MPSKernel, but
1187 /// it is the one that NSCoder uses. To enable your NSCoder
1188 /// (e.g. NSKeyedUnarchiver) to set which device to use
1189 /// extend the object to adopt the MPSDeviceProvider
1190 /// protocol. Otherwise, the Metal system default device
1191 /// will be used.
1192 ///
1193 /// # Safety
1194 ///
1195 /// `a_decoder` possibly has further requirements.
1196 #[unsafe(method(initWithCoder:))]
1197 #[unsafe(method_family = init)]
1198 pub unsafe fn initWithCoder(
1199 this: Allocated<Self>,
1200 a_decoder: &NSCoder,
1201 ) -> Option<Retained<Self>>;
1202 );
1203}
1204
1205/// Methods declared on superclass `NSObject`.
1206#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1207impl MPSCNNCrossChannelNormalizationGradient {
1208 extern_methods!(
1209 #[unsafe(method(init))]
1210 #[unsafe(method_family = init)]
1211 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1212
1213 #[unsafe(method(new))]
1214 #[unsafe(method_family = new)]
1215 pub unsafe fn new() -> Retained<Self>;
1216 );
1217}