1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use super::AxesOrTensor;
use crate::{Graph, Tensor, ns_number_array_from_slice};
use objc2::{msg_send, rc::Retained};
use objc2_foundation::NSString;
impl Graph {
/// Reverses `tensor` along the provided `axes`.
///
/// Semantics match TensorFlow’s *reverse* op.
///
/// # Arguments
///
/// * `tensor` – Tensor to reverse.
/// * `axes` – Axes to flip (slice or tensor; must be unique and within
/// range).
/// * `name` – Optional debug label.
///
/// # Returns
///
/// A [`Tensor`] with the specified axes reversed.
pub fn reverse_with_axes<'a>(
&self,
tensor: &Tensor,
axes: AxesOrTensor<'a>,
name: Option<&str>,
) -> Retained<Tensor> {
match axes {
AxesOrTensor::Axes(axes) => unsafe {
msg_send![
self,
reverseTensor: tensor,
axes: &*ns_number_array_from_slice(axes),
name: name.map(NSString::from_str).as_deref(),
]
},
AxesOrTensor::Tensor(tensor) => unsafe {
msg_send![
self,
reverseTensor: tensor,
axesTensor: tensor,
name: name.map(NSString::from_str).as_deref(),
]
},
}
}
/// Reverses `tensor` along *all* axes.
///
/// # Arguments
///
/// * `tensor` – Tensor to reverse.
/// * `name` – Optional debug label.
///
/// # Returns
///
/// A fully reversed [`Tensor`].
pub fn reverse(&self, tensor: &Tensor, name: Option<&str>) -> Retained<Tensor> {
unsafe {
msg_send![
self,
reverseTensor: tensor,
name: name.map(NSString::from_str).as_deref(),
]
}
}
}