ruda_tensor/tensor/ops/ordered.rs
1use crate::{
2 Backend, Scalar,
3 tensor::{IntTensor, Numeric},
4};
5
6/// Trait that list all operations that can be applied on all numerical tensors
7/// whose elements have a well-defined ordering.
8///
9/// This includes operations such as comparisons, minimum/maximum reductions,
10/// and other order-dependent computations that are not strictly valid for all numerical
11/// types.
12///
13/// # Warnings
14///
15/// This is an internal trait, use the public API provided by the
16#[cfg_attr(doc, doc = crate::doc_tensor!())]
17#[cfg_attr(not(doc), doc = "`Tensor`")]
18/// struct.
19pub trait Ordered<B: Backend>: Numeric<B> {
20 /// Sort the elements of the input `tensor` by value along a given dimension.
21 ///
22 /// This sort is unstable (i.e., may reorder equal elements).
23 ///
24 /// # Arguments
25 ///
26 /// * `tensor` - The input tensor.
27 /// * `dim` - The axis along which to sort.
28 /// * `descending` - The sorting order.
29 ///
30 /// # Returns
31 ///
32 /// A tensor with the same shape as the input tensor, where the elements are sorted by value.
33 ///
34 /// # Remarks
35 /// This is a low-level function used internally by the library to call different backend functions
36 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
37 /// or use this function directly.
38 ///
39 /// Users should prefer the
40 #[cfg_attr(doc, doc = crate::doc_tensor!("sort"))]
41 #[cfg_attr(not(doc), doc = "`Tensor::sort`")]
42 /// function, which is more high-level and designed for public use.
43 fn sort(tensor: Self::Primitive, dim: usize, descending: bool) -> Self::Primitive;
44
45 /// Sort the elements of the input `tensor` by value along a given dimension.
46 ///
47 /// This sort is unstable (i.e., may reorder equal elements).
48 ///
49 /// # Arguments
50 ///
51 /// * `tensor` - The input tensor.
52 /// * `dim` - The axis along which to sort.
53 /// * `descending` - The sorting order.
54 ///
55 /// # Returns
56 ///
57 /// A tensor with the same shape as the input tensor and corresponding indices, where
58 /// the elements are sorted by value and the indices map back to the original input tensor.
59 ///
60 /// # Remarks
61 /// This is a low-level function used internally by the library to call different backend functions
62 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
63 /// or use this function directly.
64 ///
65 /// For sorting the elements of a tensor, users should prefer the
66 #[cfg_attr(doc, doc = crate::doc_tensor!("sort_with_indices"))]
67 #[cfg_attr(not(doc), doc = "`Tensor::sort_with_indices`")]
68 /// function, which is more high-level and designed for public use.
69 fn sort_with_indices(
70 tensor: Self::Primitive,
71 dim: usize,
72 descending: bool,
73 ) -> (Self::Primitive, IntTensor<B>);
74
75 /// Returns the indices that sort the elements of the input `tensor` by value along a given dimension.
76 ///
77 /// This sort is unstable (i.e., may reorder equal elements).
78 ///
79 /// # Arguments
80 ///
81 /// * `tensor` - The input tensor.
82 /// * `dim` - The axis along which to sort.
83 /// * `descending` - The sorting order.
84 ///
85 /// # Returns
86 ///
87 /// A tensor with the same shape as the input tensor the indices map back to the original input tensor.
88 ///
89 /// # Remarks
90 /// This is a low-level function used internally by the library to call different backend functions
91 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
92 /// or use this function directly.
93 ///
94 /// Users should prefer the
95 #[cfg_attr(doc, doc = crate::doc_tensor!("argsort"))]
96 #[cfg_attr(not(doc), doc = "`Tensor::argsort`")]
97 /// function, which is more high-level and designed for public use.
98 fn argsort(tensor: Self::Primitive, dim: usize, descending: bool) -> IntTensor<B>;
99
100 /// Computes the cumulative minimum of elements along a dimension.
101 ///
102 /// # Arguments
103 ///
104 /// * `tensor` - The tensor to compute the cumulative minimum of.
105 /// * `dim` - The dimension along which to compute the cumulative minimum.
106 ///
107 /// # Returns
108 ///
109 /// A tensor with the same shape as the input tensor, where each element is the minimum
110 /// of all elements up to and including that position along the specified dimension.
111 ///
112 /// # Remarks
113 ///
114 /// This is a low-level function used internally by the library to call different backend functions
115 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
116 /// or use this function directly.
117 ///
118 /// For computing the cumulative minimum of elements along a dimension, users should prefer the
119 #[cfg_attr(doc, doc = crate::doc_tensor!("cummin"))]
120 #[cfg_attr(not(doc), doc = "`Tensor::cummin`")]
121 /// function, which is more high-level and designed for public use.
122 fn cummin(tensor: Self::Primitive, dim: usize) -> Self::Primitive;
123
124 /// Computes the cumulative maximum of elements along a dimension.
125 ///
126 /// # Arguments
127 ///
128 /// * `tensor` - The tensor to compute the cumulative maximum of.
129 /// * `dim` - The dimension along which to compute the cumulative maximum.
130 ///
131 /// # Returns
132 ///
133 /// A tensor with the same shape as the input tensor, where each element is the maximum
134 /// of all elements up to and including that position along the specified dimension.
135 ///
136 /// # Remarks
137 ///
138 /// This is a low-level function used internally by the library to call different backend functions
139 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
140 /// or use this function directly.
141 ///
142 /// For computing the cumulative maximum of elements along a dimension, users should prefer the
143 #[cfg_attr(doc, doc = crate::doc_tensor!("cummax"))]
144 #[cfg_attr(not(doc), doc = "`Tensor::cummax`")]
145 /// function, which is more high-level and designed for public use.
146 fn cummax(tensor: Self::Primitive, dim: usize) -> Self::Primitive;
147
148 /// Element-wise greater than comparison between two tensors.
149 ///
150 /// # Arguments
151 ///
152 /// * `lhs` - The left hand side tensor.
153 /// * `rhs` - The right hand side tensor.
154 ///
155 /// # Returns
156 ///
157 /// A boolean tensor with the same shape as the input tensors, where each element is true if the
158 /// corresponding element of the left hand side tensor is greater than the corresponding element
159 /// of the right hand side tensor, and false otherwise.
160 ///
161 /// # Remarks
162 ///
163 /// This is a low-level function used internally by the library to call different backend functions
164 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
165 /// or use this function directly.
166 ///
167 /// For element-wise greater than comparison between two tensors, users should prefer the
168 #[cfg_attr(doc, doc = crate::doc_tensor!("greater"))]
169 #[cfg_attr(not(doc), doc = "`Tensor::greater`")]
170 /// function, which is more high-level and designed for public use.
171 fn greater(lhs: Self::Primitive, rhs: Self::Primitive) -> B::BoolTensorPrimitive;
172
173 /// Element-wise greater than comparison between a tensor and a scalar.
174 ///
175 /// # Arguments
176 ///
177 /// * `lhs` - The left hand side tensor.
178 /// * `rhs` - The right hand side scalar.
179 ///
180 /// # Returns
181 ///
182 /// A boolean tensor with the same shape as the input tensor, where each element is true if the
183 /// corresponding element of the left hand side tensor is greater than the right hand side
184 /// scalar, and false otherwise.
185 ///
186 /// # Remarks
187 ///
188 /// This is a low-level function used internally by the library to call different backend functions
189 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
190 /// or use this function directly.
191 ///
192 /// For element-wise greater than comparison between a tensor and a scalar, users should prefer the
193 #[cfg_attr(doc, doc = crate::doc_tensor!("greater_elem"))]
194 #[cfg_attr(not(doc), doc = "`Tensor::greater_elem`")]
195 /// function, which is more high-level and designed for public use.
196 fn greater_elem(lhs: Self::Primitive, rhs: Scalar) -> B::BoolTensorPrimitive;
197
198 /// Element-wise greater than or equal comparison between two tensors.
199 ///
200 /// # Arguments
201 ///
202 /// * `lhs` - The left hand side tensor.
203 /// * `rhs` - The right hand side tensor.
204 ///
205 /// # Returns
206 ///
207 /// A boolean tensor with the same shape as the input tensors, where each element is true if the
208 /// corresponding element of the left hand side tensor is greater than or equal to the
209 /// corresponding element of the right hand side tensor, and false otherwise.
210 ///
211 /// # Remarks
212 ///
213 /// This is a low-level function used internally by the library to call different backend functions
214 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
215 /// or use this function directly.
216 ///
217 /// For element-wise greater than or equal comparison between two tensors, users should prefer the
218 #[cfg_attr(doc, doc = crate::doc_tensor!("greater_equal"))]
219 #[cfg_attr(not(doc), doc = "`Tensor::greater_equal`")]
220 /// function, which is more high-level and designed for public use.
221 fn greater_equal(lhs: Self::Primitive, rhs: Self::Primitive) -> B::BoolTensorPrimitive;
222
223 /// Element-wise greater than or equal comparison between a tensor and a scalar.
224 ///
225 /// # Arguments
226 ///
227 /// * `lhs` - The left hand side tensor.
228 /// * `rhs` - The right hand side scalar.
229 ///
230 /// # Returns
231 ///
232 /// A boolean tensor with the same shape as the input tensor, where each element is true if the
233 /// corresponding element of the left hand side tensor is greater than or equal to the right
234 /// hand side scalar, and false otherwise.
235 ///
236 /// # Remarks
237 ///
238 /// This is a low-level function used internally by the library to call different backend functions
239 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
240 /// or use this function directly.
241 ///
242 /// For element-wise greater than or equal comparison between a tensor and a scalar, users should prefer the
243 #[cfg_attr(doc, doc = crate::doc_tensor!("greater_equal_elem"))]
244 #[cfg_attr(not(doc), doc = "`Tensor::greater_equal_elem`")]
245 /// function, which is more high-level and designed for public use.
246 fn greater_equal_elem(lhs: Self::Primitive, rhs: Scalar) -> B::BoolTensorPrimitive;
247
248 /// Element-wise less than comparison between two tensors.
249 ///
250 /// # Arguments
251 ///
252 /// * `lhs` - The left hand side tensor.
253 /// * `rhs` - The right hand side tensor.
254 ///
255 /// # Returns
256 ///
257 /// A boolean tensor with the same shape as the input tensors, where each element is true if the
258 /// corresponding element of the left hand side tensor is less than the corresponding element of
259 /// the right hand side tensor, and false otherwise.
260 ///
261 /// # Remarks
262 ///
263 /// This is a low-level function used internally by the library to call different backend functions
264 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
265 /// or use this function directly.
266 ///
267 /// For element-wise less than comparison between two tensors, users should prefer the
268 #[cfg_attr(doc, doc = crate::doc_tensor!("lower"))]
269 #[cfg_attr(not(doc), doc = "`Tensor::lower`")]
270 /// function, which is more high-level and designed for public use.
271 fn lower(lhs: Self::Primitive, rhs: Self::Primitive) -> B::BoolTensorPrimitive;
272
273 /// Element-wise less than comparison between a tensor and a scalar.
274 ///
275 /// # Arguments
276 ///
277 /// * `lhs` - The left hand side tensor.
278 /// * `rhs` - The right hand side scalar.
279 ///
280 /// # Returns
281 ///
282 /// A boolean tensor with the same shape as the input tensor, where each element is true if the
283 /// corresponding element of the left hand side tensor is less than the right hand side scalar,
284 /// and false otherwise.
285 ///
286 /// # Remarks
287 ///
288 /// This is a low-level function used internally by the library to call different backend functions
289 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
290 /// or use this function directly.
291 ///
292 /// For element-wise less than comparison between a tensor and a scalar, users should prefer the
293 #[cfg_attr(doc, doc = crate::doc_tensor!("lower_elem"))]
294 #[cfg_attr(not(doc), doc = "`Tensor::lower_elem`")]
295 /// function, which is more high-level and designed for public use.
296 fn lower_elem(lhs: Self::Primitive, rhs: Scalar) -> B::BoolTensorPrimitive;
297
298 /// Element-wise less than or equal comparison between two tensors.
299 ///
300 /// # Arguments
301 ///
302 /// * `lhs` - The left hand side tensor.
303 /// * `rhs` - The right hand side tensor.
304 ///
305 /// # Returns
306 ///
307 /// A boolean tensor with the same shape as the input tensors, where each element is true if the
308 /// corresponding element of the left hand side tensor is less than or equal to the corresponding
309 /// element of the right hand side tensor, and false otherwise.
310 ///
311 /// # Remarks
312 ///
313 /// This is a low-level function used internally by the library to call different backend functions
314 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
315 /// or use this function directly.
316 ///
317 /// For element-wise less than or equal comparison between two tensors, users should prefer the
318 #[cfg_attr(doc, doc = crate::doc_tensor!("lower_equal"))]
319 #[cfg_attr(not(doc), doc = "`Tensor::lower_equal`")]
320 /// function, which is more high-level and designed for public use.
321 fn lower_equal(lhs: Self::Primitive, rhs: Self::Primitive) -> B::BoolTensorPrimitive;
322
323 /// Element-wise less than or equal comparison between a tensor and a scalar.
324 ///
325 /// # Arguments
326 ///
327 /// * `lhs` - The left hand side tensor.
328 /// * `rhs` - The right hand side scalar.
329 ///
330 /// # Returns
331 ///
332 /// A boolean tensor with the same shape as the input tensor, where each element is true if the
333 /// corresponding element of the left hand side tensor is less than or equal to the right hand
334 /// side scalar, and false otherwise.
335 ///
336 /// # Remarks
337 ///
338 /// This is a low-level function used internally by the library to call different backend functions
339 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
340 /// or use this function directly.
341 ///
342 /// For element-wise less than or equal comparison between a tensor and a scalar, users should prefer the
343 #[cfg_attr(doc, doc = crate::doc_tensor!("lower_equal_elem"))]
344 #[cfg_attr(not(doc), doc = "`Tensor::lower_equal_elem`")]
345 /// function, which is more high-level and designed for public use.
346 fn lower_equal_elem(lhs: Self::Primitive, rhs: Scalar) -> B::BoolTensorPrimitive;
347
348 /// Gets the indices of the maximum elements of a tensor along an axis.
349 ///
350 /// # Arguments
351 ///
352 /// * `dim` - The axis along which to get the indices of the maximum elements.
353 /// * `tensor` - The tensor to get the indices of the maximum elements from.
354 ///
355 /// # Returns
356 ///
357 /// A tensor where the dimension `dim` has size 1 and all other dimensions
358 /// are the same as the input tensor. Each element is the index of the maximum
359 /// value.
360 ///
361 /// # Remarks
362 ///
363 /// This is a low-level function used internally by the library to call different backend functions
364 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
365 /// or use this function directly.
366 ///
367 /// For getting the indices of the maximum elements of a tensor along an axis, users should prefer the
368 #[cfg_attr(doc, doc = crate::doc_tensor!("argmax"))]
369 #[cfg_attr(not(doc), doc = "`Tensor::argmax`")]
370 /// function, which is more high-level and designed for public use.
371 fn argmax(tensor: Self::Primitive, dim: usize) -> IntTensor<B>;
372
373 /// Gets the indices of the k maximum elements of a tensor along an axis.
374 ///
375 /// # Arguments
376 ///
377 /// * `dim` - The axis along which to get the indices of the maximum elements.
378 /// * `tensor` - The tensor to get the indices of the maximum elements from.
379 /// * `k` - k maximum elements to get
380 ///
381 /// # Returns
382 ///
383 /// A tensor where the dimension `dim` has size `k` and all other dimensions
384 /// are the same as the input tensor. Each element is the index of one of the
385 /// `k` largest values along the specified axis.
386 ///
387 /// # Remarks
388 ///
389 /// This is a low-level function used internally by the library to call different backend functions
390 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
391 /// or use this function directly.
392 ///
393 /// For getting the indices of the k maximum elements of a tensor along an axis, users should prefer the
394 #[cfg_attr(doc, doc = crate::doc_tensor!("argtopk"))]
395 #[cfg_attr(not(doc), doc = "`Tensor::argtopk`")]
396 /// function, which is more high-level and designed for public use.
397 fn argtopk(tensor: Self::Primitive, dim: usize, k: usize) -> IntTensor<B>;
398
399 /// Gets the values of the k maximum elements of a tensor along an axis.
400 ///
401 /// # Arguments
402 ///
403 /// * `dim` - The axis along which to get the values of the maximum elements.
404 /// * `tensor` - The tensor to get the values of the maximum elements from.
405 /// * `k` - k maximum elements to get
406 ///
407 /// # Returns
408 ///
409 /// A tensor where the dimension `dim` has size `k` and all other dimensions
410 /// are the same as the input tensor. Each element is the value of one of the
411 /// `k` largest values along the specified axis.
412 ///
413 /// # Remarks
414 ///
415 /// This is a low-level function used internally by the library to call different backend functions
416 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
417 /// or use this function directly.
418 ///
419 /// For getting the values of the k maximum elements of a tensor along an axis, users should prefer the
420 #[cfg_attr(doc, doc = crate::doc_tensor!("topk"))]
421 #[cfg_attr(not(doc), doc = "`Tensor::topk`")]
422 /// function, which is more high-level and designed for public use.
423 fn topk(tensor: Self::Primitive, dim: usize, k: usize) -> Self::Primitive;
424
425 /// Gets the indices of the minimum elements of a tensor along an axis.
426 ///
427 /// # Arguments
428 ///
429 /// * `dim` - The axis along which to get the indices of the minimum elements.
430 /// * `tensor` - The tensor to get the indices of the minimum elements from.
431 ///
432 /// # Returns
433 ///
434 /// A tensor where the dimension `dim` has size 1 and all other dimensions
435 /// are the same as the input tensor. Each element is the index of the minimum
436 /// value.
437 ///
438 /// # Remarks
439 ///
440 /// This is a low-level function used internally by the library to call different backend functions
441 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
442 /// or use this function directly.
443 ///
444 /// For getting the indices of the minimum elements of a tensor along an axis, users should prefer the
445 #[cfg_attr(doc, doc = crate::doc_tensor!("argmin"))]
446 #[cfg_attr(not(doc), doc = "`Tensor::argmin`")]
447 /// function, which is more high-level and designed for public use.
448 fn argmin(tensor: Self::Primitive, dim: usize) -> IntTensor<B>;
449
450 /// Gets the maximum elements of a tensor along an axis.
451 ///
452 /// # Arguments
453 ///
454 /// * `dim` - The axis along which to get the maximum elements.
455 ///
456 /// # Returns
457 ///
458 /// A single-element tensor containing the maximum element of the input tensor.
459 ///
460 /// # Remarks
461 ///
462 /// This is a low-level function used internally by the library to call different backend functions
463 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
464 /// or use this function directly.
465 ///
466 /// For getting the maximum elements of a tensor along an axis, users should prefer the
467 #[cfg_attr(doc, doc = crate::doc_tensor!("max"))]
468 #[cfg_attr(not(doc), doc = "`Tensor::max`")]
469 /// function, which is more high-level and designed for public use.
470 fn max(tensor: Self::Primitive) -> Self::Primitive;
471
472 /// Gets the maximum elements of a tensor along an axis.
473 ///
474 /// # Arguments
475 ///
476 /// * `tensor` - The tensor to get the maximum elements from.
477 /// * `dim` - The axis along which to get the maximum elements.
478 ///
479 /// # Returns
480 ///
481 /// A tensor with the same rank as the input tensor, but the given dim set to a shape of 1.
482 /// Each element is the maximum element of the corresponding input dim.
483 ///
484 /// # Remarks
485 ///
486 /// This is a low-level function used internally by the library to call different backend functions
487 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
488 /// or use this function directly.
489 ///
490 /// For getting the maximum elements of a tensor along an axis, users should prefer the
491 #[cfg_attr(doc, doc = crate::doc_tensor!("max_dim"))]
492 #[cfg_attr(not(doc), doc = "`Tensor::max_dim`")]
493 /// function, which is more high-level and designed for public use.
494 fn max_dim(tensor: Self::Primitive, dim: usize) -> Self::Primitive;
495
496 /// Gets the maximum elements of a tensor along an axis.
497 ///
498 /// # Arguments
499 ///
500 /// * `tensor` - The tensor to get the maximum elements from.
501 /// * `dim` - The axis along which to get the maximum elements.
502 ///
503 /// # Returns
504 ///
505 /// A tuple containing the maximum element of the input tensor, and a tensor with the same shape
506 /// as the input tensor, where each element is the index of the maximum element of the input tensor
507 /// at the corresponding index along the specified axis.
508 ///
509 /// # Remarks
510 ///
511 /// This is a low-level function used internally by the library to call different backend functions
512 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
513 /// or use this function directly.
514 ///
515 /// For getting the maximum elements of a tensor along an axis, users should prefer the
516 #[cfg_attr(doc, doc = crate::doc_tensor!("max_dim_with_indices"))]
517 #[cfg_attr(not(doc), doc = "`Tensor::max_dim_with_indices`")]
518 /// function, which is more high-level and designed for public use.
519 fn max_dim_with_indices(tensor: Self::Primitive, dim: usize)
520 -> (Self::Primitive, IntTensor<B>);
521
522 /// Gets the maximum elements of a tensor along an axis.
523 ///
524 /// # Arguments
525 ///
526 /// * `dim` - The axis along which to get the maximum elements.
527 ///
528 /// # Returns
529 ///
530 /// A single-element tensor containing the maximum absolute element of the input tensor.
531 ///
532 /// # Remarks
533 ///
534 /// This is a low-level function used internally by the library to call different backend functions
535 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
536 /// or use this function directly.
537 ///
538 /// For getting the maximum absolute elements of a tensor, users should prefer the
539 #[cfg_attr(doc, doc = crate::doc_tensor!("max_abs"))]
540 #[cfg_attr(not(doc), doc = "`Tensor::max_abs`")]
541 /// function, which is more high-level and designed for public use.
542 fn max_abs(tensor: Self::Primitive) -> Self::Primitive;
543
544 /// Gets the maximum elements of a tensor along an axis.
545 ///
546 /// # Arguments
547 ///
548 /// * `tensor` - The tensor to get the maximum elements from.
549 /// * `dim` - The axis along which to get the maximum elements.
550 ///
551 /// # Returns
552 ///
553 /// A tensor with the same rank as the input tensor, but the given dim set to a shape of 1.
554 /// Each element is the maximum absolute element of the corresponding input dim.
555 ///
556 /// # Remarks
557 ///
558 /// This is a low-level function used internally by the library to call different backend functions
559 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
560 /// or use this function directly.
561 ///
562 /// For getting the maximum elements of a tensor along an axis, users should prefer the
563 #[cfg_attr(doc, doc = crate::doc_tensor!("max_abs_dim"))]
564 #[cfg_attr(not(doc), doc = "`Tensor::max_abs_dim`")]
565 /// function, which is more high-level and designed for public use.
566 fn max_abs_dim(tensor: Self::Primitive, dim: usize) -> Self::Primitive;
567
568 /// Gets the minimum elements of a tensor along an axis.
569 ///
570 /// # Arguments
571 ///
572 /// * `tensor` - The tensor to get the minimum elements from.
573 ///
574 /// # Returns
575 ///
576 /// A single-element tensor containing the minimum element of the input tensor.
577 ///
578 /// # Remarks
579 ///
580 /// This is a low-level function used internally by the library to call different backend functions
581 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
582 /// or use this function directly.
583 ///
584 /// For getting the minimum elements of a tensor along an axis, users should prefer the
585 #[cfg_attr(doc, doc = crate::doc_tensor!("min"))]
586 #[cfg_attr(not(doc), doc = "`Tensor::min`")]
587 /// function, which is more high-level and designed for public use.
588 fn min(tensor: Self::Primitive) -> Self::Primitive;
589
590 /// Gets the minimum elements of a tensor along an axis.
591 ///
592 /// # Arguments
593 ///
594 /// * `tensor` - The tensor to get the minimum elements from.
595 /// * `dim` - The axis along which to get the minimum elements.
596 ///
597 /// # Returns
598 ///
599 /// A tensor with the same rank as the input tensor, but the given dim set to a shape of 1.
600 /// Each element is the minimum element of the corresponding input dim.
601 ///
602 /// # Remarks
603 ///
604 /// This is a low-level function used internally by the library to call different backend functions
605 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
606 /// or use this function directly.
607 ///
608 /// For getting the minimum elements of a tensor along an axis, users should prefer the
609 #[cfg_attr(doc, doc = crate::doc_tensor!("min_dim"))]
610 #[cfg_attr(not(doc), doc = "`Tensor::min_dim`")]
611 /// function, which is more high-level and designed for public use.
612 fn min_dim(tensor: Self::Primitive, dim: usize) -> Self::Primitive;
613
614 /// Gets the minimum elements and indices of a tensor along an axis.
615 ///
616 /// # Arguments
617 ///
618 /// * `tensor` - The tensor to get the minimum elements from.
619 ///
620 /// # Returns
621 ///
622 /// A tensor with the same shape as the input tensor and corresponding indices, where
623 /// each element is the minimum element of the input tensor at the corresponding index
624 /// along the specified axis.
625 ///
626 /// # Remarks
627 ///
628 /// This is a low-level function used internally by the library to call different backend functions
629 /// with static dispatch. It is not designed for direct usage by users, and not recommended to import
630 /// or use this function directly.
631 ///
632 /// For getting the minimum elements of a tensor along an axis, users should prefer the
633 #[cfg_attr(doc, doc = crate::doc_tensor!("min_dim_with_indices"))]
634 #[cfg_attr(not(doc), doc = "`Tensor::min_dim_with_indices`")]
635 /// function, which is more high-level and designed for public use.
636 fn min_dim_with_indices(tensor: Self::Primitive, dim: usize)
637 -> (Self::Primitive, IntTensor<B>);
638
639 /// Clamp the tensor between the given min and max values.
640 ///
641 /// # Arguments
642 ///
643 /// * `min` - The minimum value.
644 /// * `max` - The maximum value.
645 ///
646 /// # Returns
647 ///
648 /// A new tensor with the values clamped between the given min and max values.
649 ///
650 /// # Remarks
651 ///
652 /// This is a low-level function used internally by the library to call different backend functions
653 /// with static dispatch. It is not designed for direct usage by users.
654 ///
655 /// For clamping a tensor between the given min and max values, users should prefer the
656 #[cfg_attr(doc, doc = crate::doc_tensor!("clamp"))]
657 #[cfg_attr(not(doc), doc = "`Tensor::clamp`")]
658 /// function, which is more high-level and designed for public use.
659 fn clamp(tensor: Self::Primitive, min: Scalar, max: Scalar) -> Self::Primitive;
660
661 /// Clamps a tensor under a minimum value.
662 ///
663 /// # Arguments
664 ///
665 /// * `tensor` - The tensor to clamp.
666 /// * `min` - The minimum value.
667 ///
668 /// # Returns
669 ///
670 /// A new tensor with the values clamped under the given min value.
671 ///
672 /// # Remarks
673 ///
674 /// This is a low-level function used internally by the library to call different backend functions
675 /// with static dispatch. It is not designed for direct usage by users.
676 ///
677 /// For clamping a tensor under a minimum value, users should prefer the
678 #[cfg_attr(doc, doc = crate::doc_tensor!("clamp_min"))]
679 #[cfg_attr(not(doc), doc = "`Tensor::clamp_min`")]
680 /// function, which is more high-level and designed for public use.
681 fn clamp_min(tensor: Self::Primitive, min: Scalar) -> Self::Primitive;
682
683 /// Clamps a tensor over a maximum value.
684 ///
685 /// # Arguments
686 ///
687 /// * `tensor` - The tensor to clamp.
688 /// * `max` - The maximum value.
689 ///
690 /// # Returns
691 ///
692 /// A new tensor with the values clamped over the given max value.
693 ///
694 /// # Remarks
695 ///
696 /// This is a low-level function used internally by the library to call different backend functions
697 /// with static dispatch. It is not designed for direct usage by users.
698 ///
699 /// For clamping a tensor over a maximum value, users should prefer the
700 #[cfg_attr(doc, doc = crate::doc_tensor!("clamp_max"))]
701 #[cfg_attr(not(doc), doc = "`Tensor::clamp_max`")]
702 /// function, which is more high-level and designed for public use.
703 fn clamp_max(tensor: Self::Primitive, max: Scalar) -> Self::Primitive;
704}