objc2_metal_performance_shaders_graph/generated/MPSGraphLossOps.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2::__framework_prelude::*;
5use objc2_foundation::*;
6
7use crate::*;
8
9/// The type of the reduction the graph applies in the loss operations.
10///
11/// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphlossreductiontype?language=objc)
12// NS_ENUM
13#[repr(transparent)]
14#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
15pub struct MPSGraphLossReductionType(pub u64);
16impl MPSGraphLossReductionType {
17 /// Computes the loss without reduction.
18 #[doc(alias = "MPSGraphLossReductionTypeNone")]
19 pub const None: Self = Self(0);
20 /// Computes the loss without reduction.
21 #[doc(alias = "MPSGraphLossReductionTypeAxis")]
22 pub const Axis: Self = Self(MPSGraphLossReductionType::None.0);
23 /// Reduces the loss down to a scalar with a sum operation.
24 #[doc(alias = "MPSGraphLossReductionTypeSum")]
25 pub const Sum: Self = Self(1);
26 /// Reduces the loss down to a scalar with a mean operation.
27 #[doc(alias = "MPSGraphLossReductionTypeMean")]
28 pub const Mean: Self = Self(2);
29}
30
31unsafe impl Encode for MPSGraphLossReductionType {
32 const ENCODING: Encoding = u64::ENCODING;
33}
34
35unsafe impl RefEncode for MPSGraphLossReductionType {
36 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
37}
38
39/// MPSGraphLossOps.
40#[cfg(all(feature = "MPSGraph", feature = "MPSGraphCore"))]
41impl MPSGraph {
42 extern_methods!(
43 #[cfg(feature = "MPSGraphTensor")]
44 /// Creates a softmax cross-entropy loss operation and returns the result tensor.
45 ///
46 /// The softmax cross-entropy operation computes:
47 /// ```md
48 /// loss = reduction( - labels*ln( softmax(source) )), where
49 /// sotfmax(source) = exp(source) / sum( exp(source) ), and
50 /// ```
51 /// the operation performs the reduction over the `axis` dimension.
52 ///
53 /// - Parameters:
54 /// - sourceTensor: The source tensor.
55 /// - labelsTensor: The labels tensor.
56 /// - axis: The axis over which the operation computes the softmax reduction.
57 /// - reductionType: The type of reduction MPSGraph uses to reduce across all other axes than `axis`. See: ``MPSGraphLossReductionType``.
58 /// - name: The name for the operation.
59 /// - Returns: A valid MPSGraphTensor object.
60 #[unsafe(method(softMaxCrossEntropyWithSourceTensor:labelsTensor:axis:reductionType:name:))]
61 #[unsafe(method_family = none)]
62 pub unsafe fn softMaxCrossEntropyWithSourceTensor_labelsTensor_axis_reductionType_name(
63 &self,
64 source_tensor: &MPSGraphTensor,
65 labels_tensor: &MPSGraphTensor,
66 axis: NSInteger,
67 reduction_type: MPSGraphLossReductionType,
68 name: Option<&NSString>,
69 ) -> Retained<MPSGraphTensor>;
70
71 #[cfg(feature = "MPSGraphTensor")]
72 /// Creates the gradient of a softmax cross-entropy loss operation and returns the result tensor.
73 ///
74 /// - Parameters:
75 /// - gradientTensor: The input gradientTensor. Note: in most cases this is the initial gradient tensor, which is a constant tensor with value one.
76 /// - sourceTensor: The source tensor.
77 /// - labelsTensor: The labels tensor.
78 /// - axis: The axis over which the operation computes the softmax reduction.
79 /// - reductionType: The type of reduction MPSGraph uses to reduce across all other axes than `axis`. See: ``MPSGraphLossReductionType``.
80 /// - name: The name for the operation.
81 /// - Returns: A valid MPSGraphTensor object.
82 #[unsafe(method(softMaxCrossEntropyGradientWithIncomingGradientTensor:sourceTensor:labelsTensor:axis:reductionType:name:))]
83 #[unsafe(method_family = none)]
84 pub unsafe fn softMaxCrossEntropyGradientWithIncomingGradientTensor_sourceTensor_labelsTensor_axis_reductionType_name(
85 &self,
86 gradient_tensor: &MPSGraphTensor,
87 source_tensor: &MPSGraphTensor,
88 labels_tensor: &MPSGraphTensor,
89 axis: NSInteger,
90 reduction_type: MPSGraphLossReductionType,
91 name: Option<&NSString>,
92 ) -> Retained<MPSGraphTensor>;
93 );
94}