1use super::*;
2
3impl IntTensorOps<Self> for Dispatch {
4 fn int_autodiff_context(tensor: &IntTensor<Self>) -> ruda_tensor::AutodiffContext {
5 tensor.context()
6 }
7
8 fn int_with_autodiff_context(tensor: IntTensor<Self>, context: ruda_tensor::AutodiffContext) -> IntTensor<Self> {
9 tensor.with_context(context)
10 }
11
12 fn int_empty(shape: Shape, device: &Device<Self>, dtype: IntDType) -> IntTensor<Self> {
13 let selection = Selection::factory(device);
14 macro_rules! call {
15 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
16 let result = <$B>::int_empty(shape, $device, dtype);
17 pack!($mode, $variant, Int, result)
18 }};
19 }
20 dispatch!(selection, call)
21 }
22
23 fn int_into_data( tensor: IntTensor<Self>, ) -> impl Future<Output = Result<TensorData, ExecutionError>> + Send {
24 let selection = Selection::tensors(core::iter::once(&tensor));
25 macro_rules! call {
26 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
27 let future = <$B>::int_into_data(unpack!($mode, $variant, Int, tensor, $context));
28 let future: core::pin::Pin<Box<dyn Future<Output = Result<TensorData, ExecutionError>> + Send>> = Box::pin(async move { future.await });
29 future
30 }};
31 }
32 dispatch!(selection, call)
33 }
34
35 fn int_from_data(data: TensorData, device: &Device<Self>) -> IntTensor<Self> {
36 let selection = Selection::factory(device);
37 macro_rules! call {
38 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
39 let result = <$B>::int_from_data(data, $device);
40 pack!($mode, $variant, Int, result)
41 }};
42 }
43 dispatch!(selection, call)
44 }
45
46 fn int_device(tensor: &IntTensor<Self>) -> Device<Self> {
47 tensor.device()
48 }
49
50 fn int_to_device(tensor: IntTensor<Self>, device: &Device<Self>) -> IntTensor<Self> {
51 crate::transfer::int_to_device(tensor, device)
52 }
53
54 fn int_reshape(tensor: IntTensor<Self>, shape: Shape) -> IntTensor<Self> {
55 let selection = Selection::tensors(core::iter::once(&tensor));
56 macro_rules! call {
57 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
58 let result = <$B>::int_reshape(unpack!($mode, $variant, Int, tensor, $context), shape);
59 pack!($mode, $variant, Int, result)
60 }};
61 }
62 dispatch!(selection, call)
63 }
64
65 fn int_slice(tensor: IntTensor<Self>, slices: &[Slice]) -> IntTensor<Self> {
66 let selection = Selection::tensors(core::iter::once(&tensor));
67 macro_rules! call {
68 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
69 let result = <$B>::int_slice(unpack!($mode, $variant, Int, tensor, $context), slices);
70 pack!($mode, $variant, Int, result)
71 }};
72 }
73 dispatch!(selection, call)
74 }
75
76 fn int_slice_assign( tensor: IntTensor<Self>, slices: &[Slice], value: IntTensor<Self>, ) -> IntTensor<Self> {
77 let selection = Selection::tensors(core::iter::once(&tensor).chain(core::iter::once(&value)));
78 macro_rules! call {
79 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
80 let result = <$B>::int_slice_assign(unpack!($mode, $variant, Int, tensor, $context), slices, unpack!($mode, $variant, Int, value, $context));
81 pack!($mode, $variant, Int, result)
82 }};
83 }
84 dispatch!(selection, call)
85 }
86
87 fn int_into_float(tensor: IntTensor<Self>, out_dtype: FloatDType) -> FloatTensor<Self> {
88 let selection = Selection::tensors(core::iter::once(&tensor));
89 macro_rules! call {
90 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
91 let result = <$B>::int_into_float(unpack!($mode, $variant, Int, tensor, $context), out_dtype);
92 pack!($mode, $variant, Float, result)
93 }};
94 }
95 dispatch!(selection, call)
96 }
97
98 fn int_mask_where( tensor: IntTensor<Self>, mask: BoolTensor<Self>, value: IntTensor<Self>, ) -> IntTensor<Self> {
99 let selection = Selection::tensors(core::iter::once(&tensor).chain(core::iter::once(&mask)).chain(core::iter::once(&value)));
100 macro_rules! call {
101 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
102 let result = <$B>::int_mask_where(unpack!($mode, $variant, Int, tensor, $context), unpack!($mode, $variant, Bool, mask, $context), unpack!($mode, $variant, Int, value, $context));
103 pack!($mode, $variant, Int, result)
104 }};
105 }
106 dispatch!(selection, call)
107 }
108
109 fn int_mask_fill(tensor: IntTensor<Self>, mask: BoolTensor<Self>, value: Scalar) -> IntTensor<Self> {
110 let selection = Selection::tensors(core::iter::once(&tensor).chain(core::iter::once(&mask)));
111 macro_rules! call {
112 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
113 let result = <$B>::int_mask_fill(unpack!($mode, $variant, Int, tensor, $context), unpack!($mode, $variant, Bool, mask, $context), value);
114 pack!($mode, $variant, Int, result)
115 }};
116 }
117 dispatch!(selection, call)
118 }
119
120 fn int_gather(dim: usize, tensor: IntTensor<Self>, indices: IntTensor<Self>) -> IntTensor<Self> {
121 let selection = Selection::tensors(core::iter::once(&tensor).chain(core::iter::once(&indices)));
122 macro_rules! call {
123 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
124 let result = <$B>::int_gather(dim, unpack!($mode, $variant, Int, tensor, $context), unpack!($mode, $variant, Int, indices, $context));
125 pack!($mode, $variant, Int, result)
126 }};
127 }
128 dispatch!(selection, call)
129 }
130
131 fn int_scatter_add( dim: usize, tensor: IntTensor<Self>, indices: IntTensor<Self>, value: IntTensor<Self>, ) -> IntTensor<Self> {
132 let selection = Selection::tensors(core::iter::once(&tensor).chain(core::iter::once(&indices)).chain(core::iter::once(&value)));
133 macro_rules! call {
134 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
135 let result = <$B>::int_scatter_add(dim, unpack!($mode, $variant, Int, tensor, $context), unpack!($mode, $variant, Int, indices, $context), unpack!($mode, $variant, Int, value, $context));
136 pack!($mode, $variant, Int, result)
137 }};
138 }
139 dispatch!(selection, call)
140 }
141
142 fn int_scatter( dim: usize, tensor: IntTensor<Self>, indices: IntTensor<Self>, value: IntTensor<Self>, update: ruda_tensor::tensor::IndexingUpdateOp, ) -> IntTensor<Self> {
143 let selection = Selection::tensors(core::iter::once(&tensor).chain(core::iter::once(&indices)).chain(core::iter::once(&value)));
144 macro_rules! call {
145 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
146 let result = <$B>::int_scatter(dim, unpack!($mode, $variant, Int, tensor, $context), unpack!($mode, $variant, Int, indices, $context), unpack!($mode, $variant, Int, value, $context), update);
147 pack!($mode, $variant, Int, result)
148 }};
149 }
150 dispatch!(selection, call)
151 }
152
153 fn int_scatter_nd( _data: IntTensor<Self>, _indices: IntTensor<Self>, _values: IntTensor<Self>, _reduction: ruda_tensor::tensor::IndexingUpdateOp, ) -> IntTensor<Self> {
154 let selection = Selection::tensors(core::iter::once(&_data).chain(core::iter::once(&_indices)).chain(core::iter::once(&_values)));
155 macro_rules! call {
156 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
157 let result = <$B>::int_scatter_nd(unpack!($mode, $variant, Int, _data, $context), unpack!($mode, $variant, Int, _indices, $context), unpack!($mode, $variant, Int, _values, $context), _reduction);
158 pack!($mode, $variant, Int, result)
159 }};
160 }
161 dispatch!(selection, call)
162 }
163
164 fn int_gather_nd(_data: IntTensor<Self>, _indices: IntTensor<Self>) -> IntTensor<Self> {
165 let selection = Selection::tensors(core::iter::once(&_data).chain(core::iter::once(&_indices)));
166 macro_rules! call {
167 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
168 let result = <$B>::int_gather_nd(unpack!($mode, $variant, Int, _data, $context), unpack!($mode, $variant, Int, _indices, $context));
169 pack!($mode, $variant, Int, result)
170 }};
171 }
172 dispatch!(selection, call)
173 }
174
175 fn int_select(tensor: IntTensor<Self>, dim: usize, indices: IntTensor<Self>) -> IntTensor<Self> {
176 let selection = Selection::tensors(core::iter::once(&tensor).chain(core::iter::once(&indices)));
177 macro_rules! call {
178 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
179 let result = <$B>::int_select(unpack!($mode, $variant, Int, tensor, $context), dim, unpack!($mode, $variant, Int, indices, $context));
180 pack!($mode, $variant, Int, result)
181 }};
182 }
183 dispatch!(selection, call)
184 }
185
186 fn int_select_add( tensor: IntTensor<Self>, dim: usize, indices: IntTensor<Self>, value: IntTensor<Self>, ) -> IntTensor<Self> {
187 let selection = Selection::tensors(core::iter::once(&tensor).chain(core::iter::once(&indices)).chain(core::iter::once(&value)));
188 macro_rules! call {
189 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
190 let result = <$B>::int_select_add(unpack!($mode, $variant, Int, tensor, $context), dim, unpack!($mode, $variant, Int, indices, $context), unpack!($mode, $variant, Int, value, $context));
191 pack!($mode, $variant, Int, result)
192 }};
193 }
194 dispatch!(selection, call)
195 }
196
197 fn int_select_assign( tensor: IntTensor<Self>, dim: usize, indices: IntTensor<Self>, value: IntTensor<Self>, update: ruda_tensor::tensor::IndexingUpdateOp, ) -> IntTensor<Self> {
198 let selection = Selection::tensors(core::iter::once(&tensor).chain(core::iter::once(&indices)).chain(core::iter::once(&value)));
199 macro_rules! call {
200 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
201 let result = <$B>::int_select_assign(unpack!($mode, $variant, Int, tensor, $context), dim, unpack!($mode, $variant, Int, indices, $context), unpack!($mode, $variant, Int, value, $context), update);
202 pack!($mode, $variant, Int, result)
203 }};
204 }
205 dispatch!(selection, call)
206 }
207
208 fn int_repeat_dim(tensor: IntTensor<Self>, dim: usize, times: usize) -> IntTensor<Self> {
209 let selection = Selection::tensors(core::iter::once(&tensor));
210 macro_rules! call {
211 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
212 let result = <$B>::int_repeat_dim(unpack!($mode, $variant, Int, tensor, $context), dim, times);
213 pack!($mode, $variant, Int, result)
214 }};
215 }
216 dispatch!(selection, call)
217 }
218
219 fn int_cat(tensors: Vec<IntTensor<Self>>, dim: usize) -> IntTensor<Self> {
220 let selection = Selection::tensors(tensors.iter());
221 macro_rules! call {
222 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
223 let result = <$B>::int_cat(tensors.into_iter().map(|value| unpack!($mode, $variant, Int, value, $context)).collect(), dim);
224 pack!($mode, $variant, Int, result)
225 }};
226 }
227 dispatch!(selection, call)
228 }
229
230 fn int_equal(lhs: IntTensor<Self>, rhs: IntTensor<Self>, out_dtype: BoolDType) -> BoolTensor<Self> {
231 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
232 macro_rules! call {
233 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
234 let result = <$B>::int_equal(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context), out_dtype);
235 pack!($mode, $variant, Bool, result)
236 }};
237 }
238 dispatch!(selection, call)
239 }
240
241 fn int_not_equal(lhs: IntTensor<Self>, rhs: IntTensor<Self>, out_dtype: BoolDType) -> BoolTensor<Self> {
242 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
243 macro_rules! call {
244 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
245 let result = <$B>::int_not_equal(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context), out_dtype);
246 pack!($mode, $variant, Bool, result)
247 }};
248 }
249 dispatch!(selection, call)
250 }
251
252 fn int_equal_elem(lhs: IntTensor<Self>, rhs: Scalar, out_dtype: BoolDType) -> BoolTensor<Self> {
253 let selection = Selection::tensors(core::iter::once(&lhs));
254 macro_rules! call {
255 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
256 let result = <$B>::int_equal_elem(unpack!($mode, $variant, Int, lhs, $context), rhs, out_dtype);
257 pack!($mode, $variant, Bool, result)
258 }};
259 }
260 dispatch!(selection, call)
261 }
262
263 fn int_not_equal_elem(lhs: IntTensor<Self>, rhs: Scalar, out_dtype: BoolDType) -> BoolTensor<Self> {
264 let selection = Selection::tensors(core::iter::once(&lhs));
265 macro_rules! call {
266 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
267 let result = <$B>::int_not_equal_elem(unpack!($mode, $variant, Int, lhs, $context), rhs, out_dtype);
268 pack!($mode, $variant, Bool, result)
269 }};
270 }
271 dispatch!(selection, call)
272 }
273
274 fn int_greater(lhs: IntTensor<Self>, rhs: IntTensor<Self>, out_dtype: BoolDType) -> BoolTensor<Self> {
275 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
276 macro_rules! call {
277 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
278 let result = <$B>::int_greater(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context), out_dtype);
279 pack!($mode, $variant, Bool, result)
280 }};
281 }
282 dispatch!(selection, call)
283 }
284
285 fn int_greater_elem(lhs: IntTensor<Self>, rhs: Scalar, out_dtype: BoolDType) -> BoolTensor<Self> {
286 let selection = Selection::tensors(core::iter::once(&lhs));
287 macro_rules! call {
288 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
289 let result = <$B>::int_greater_elem(unpack!($mode, $variant, Int, lhs, $context), rhs, out_dtype);
290 pack!($mode, $variant, Bool, result)
291 }};
292 }
293 dispatch!(selection, call)
294 }
295
296 fn int_greater_equal( lhs: IntTensor<Self>, rhs: IntTensor<Self>, out_dtype: BoolDType, ) -> BoolTensor<Self> {
297 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
298 macro_rules! call {
299 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
300 let result = <$B>::int_greater_equal(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context), out_dtype);
301 pack!($mode, $variant, Bool, result)
302 }};
303 }
304 dispatch!(selection, call)
305 }
306
307 fn int_greater_equal_elem( lhs: IntTensor<Self>, rhs: Scalar, out_dtype: BoolDType, ) -> BoolTensor<Self> {
308 let selection = Selection::tensors(core::iter::once(&lhs));
309 macro_rules! call {
310 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
311 let result = <$B>::int_greater_equal_elem(unpack!($mode, $variant, Int, lhs, $context), rhs, out_dtype);
312 pack!($mode, $variant, Bool, result)
313 }};
314 }
315 dispatch!(selection, call)
316 }
317
318 fn int_lower(lhs: IntTensor<Self>, rhs: IntTensor<Self>, out_dtype: BoolDType) -> BoolTensor<Self> {
319 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
320 macro_rules! call {
321 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
322 let result = <$B>::int_lower(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context), out_dtype);
323 pack!($mode, $variant, Bool, result)
324 }};
325 }
326 dispatch!(selection, call)
327 }
328
329 fn int_lower_elem(lhs: IntTensor<Self>, rhs: Scalar, out_dtype: BoolDType) -> BoolTensor<Self> {
330 let selection = Selection::tensors(core::iter::once(&lhs));
331 macro_rules! call {
332 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
333 let result = <$B>::int_lower_elem(unpack!($mode, $variant, Int, lhs, $context), rhs, out_dtype);
334 pack!($mode, $variant, Bool, result)
335 }};
336 }
337 dispatch!(selection, call)
338 }
339
340 fn int_lower_equal(lhs: IntTensor<Self>, rhs: IntTensor<Self>, out_dtype: BoolDType) -> BoolTensor<Self> {
341 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
342 macro_rules! call {
343 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
344 let result = <$B>::int_lower_equal(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context), out_dtype);
345 pack!($mode, $variant, Bool, result)
346 }};
347 }
348 dispatch!(selection, call)
349 }
350
351 fn int_lower_equal_elem(lhs: IntTensor<Self>, rhs: Scalar, out_dtype: BoolDType) -> BoolTensor<Self> {
352 let selection = Selection::tensors(core::iter::once(&lhs));
353 macro_rules! call {
354 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
355 let result = <$B>::int_lower_equal_elem(unpack!($mode, $variant, Int, lhs, $context), rhs, out_dtype);
356 pack!($mode, $variant, Bool, result)
357 }};
358 }
359 dispatch!(selection, call)
360 }
361
362 fn int_add(lhs: IntTensor<Self>, rhs: IntTensor<Self>) -> IntTensor<Self> {
363 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
364 macro_rules! call {
365 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
366 let result = <$B>::int_add(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context));
367 pack!($mode, $variant, Int, result)
368 }};
369 }
370 dispatch!(selection, call)
371 }
372
373 fn int_add_scalar(lhs: IntTensor<Self>, rhs: Scalar) -> IntTensor<Self> {
374 let selection = Selection::tensors(core::iter::once(&lhs));
375 macro_rules! call {
376 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
377 let result = <$B>::int_add_scalar(unpack!($mode, $variant, Int, lhs, $context), rhs);
378 pack!($mode, $variant, Int, result)
379 }};
380 }
381 dispatch!(selection, call)
382 }
383
384 fn int_powi(lhs: IntTensor<Self>, rhs: IntTensor<Self>) -> IntTensor<Self> {
385 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
386 macro_rules! call {
387 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
388 let result = <$B>::int_powi(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context));
389 pack!($mode, $variant, Int, result)
390 }};
391 }
392 dispatch!(selection, call)
393 }
394
395 fn int_powi_scalar(lhs: IntTensor<Self>, rhs: Scalar) -> IntTensor<Self> {
396 let selection = Selection::tensors(core::iter::once(&lhs));
397 macro_rules! call {
398 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
399 let result = <$B>::int_powi_scalar(unpack!($mode, $variant, Int, lhs, $context), rhs);
400 pack!($mode, $variant, Int, result)
401 }};
402 }
403 dispatch!(selection, call)
404 }
405
406 fn int_powi_scalar_impl(lhs: IntTensor<Self>, rhs: Scalar) -> IntTensor<Self> {
407 let selection = Selection::tensors(core::iter::once(&lhs));
408 macro_rules! call {
409 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
410 let result = <$B>::int_powi_scalar_impl(unpack!($mode, $variant, Int, lhs, $context), rhs);
411 pack!($mode, $variant, Int, result)
412 }};
413 }
414 dispatch!(selection, call)
415 }
416
417 fn int_clamp_min(tensor: IntTensor<Self>, min: Scalar) -> IntTensor<Self> {
418 let selection = Selection::tensors(core::iter::once(&tensor));
419 macro_rules! call {
420 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
421 let result = <$B>::int_clamp_min(unpack!($mode, $variant, Int, tensor, $context), min);
422 pack!($mode, $variant, Int, result)
423 }};
424 }
425 dispatch!(selection, call)
426 }
427
428 fn int_clamp_max(tensor: IntTensor<Self>, max: Scalar) -> IntTensor<Self> {
429 let selection = Selection::tensors(core::iter::once(&tensor));
430 macro_rules! call {
431 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
432 let result = <$B>::int_clamp_max(unpack!($mode, $variant, Int, tensor, $context), max);
433 pack!($mode, $variant, Int, result)
434 }};
435 }
436 dispatch!(selection, call)
437 }
438
439 fn int_clamp(tensor: IntTensor<Self>, min: Scalar, max: Scalar) -> IntTensor<Self> {
440 let selection = Selection::tensors(core::iter::once(&tensor));
441 macro_rules! call {
442 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
443 let result = <$B>::int_clamp(unpack!($mode, $variant, Int, tensor, $context), min, max);
444 pack!($mode, $variant, Int, result)
445 }};
446 }
447 dispatch!(selection, call)
448 }
449
450 fn int_sub(lhs: IntTensor<Self>, rhs: IntTensor<Self>) -> IntTensor<Self> {
451 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
452 macro_rules! call {
453 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
454 let result = <$B>::int_sub(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context));
455 pack!($mode, $variant, Int, result)
456 }};
457 }
458 dispatch!(selection, call)
459 }
460
461 fn int_sub_scalar(lhs: IntTensor<Self>, rhs: Scalar) -> IntTensor<Self> {
462 let selection = Selection::tensors(core::iter::once(&lhs));
463 macro_rules! call {
464 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
465 let result = <$B>::int_sub_scalar(unpack!($mode, $variant, Int, lhs, $context), rhs);
466 pack!($mode, $variant, Int, result)
467 }};
468 }
469 dispatch!(selection, call)
470 }
471
472 fn int_mul(lhs: IntTensor<Self>, rhs: IntTensor<Self>) -> IntTensor<Self> {
473 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
474 macro_rules! call {
475 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
476 let result = <$B>::int_mul(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context));
477 pack!($mode, $variant, Int, result)
478 }};
479 }
480 dispatch!(selection, call)
481 }
482
483 fn int_mul_scalar(lhs: IntTensor<Self>, rhs: Scalar) -> IntTensor<Self> {
484 let selection = Selection::tensors(core::iter::once(&lhs));
485 macro_rules! call {
486 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
487 let result = <$B>::int_mul_scalar(unpack!($mode, $variant, Int, lhs, $context), rhs);
488 pack!($mode, $variant, Int, result)
489 }};
490 }
491 dispatch!(selection, call)
492 }
493
494 fn int_div(lhs: IntTensor<Self>, rhs: IntTensor<Self>) -> IntTensor<Self> {
495 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
496 macro_rules! call {
497 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
498 let result = <$B>::int_div(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context));
499 pack!($mode, $variant, Int, result)
500 }};
501 }
502 dispatch!(selection, call)
503 }
504
505 fn int_div_scalar(lhs: IntTensor<Self>, rhs: Scalar) -> IntTensor<Self> {
506 let selection = Selection::tensors(core::iter::once(&lhs));
507 macro_rules! call {
508 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
509 let result = <$B>::int_div_scalar(unpack!($mode, $variant, Int, lhs, $context), rhs);
510 pack!($mode, $variant, Int, result)
511 }};
512 }
513 dispatch!(selection, call)
514 }
515
516 fn int_remainder(lhs: IntTensor<Self>, rhs: IntTensor<Self>) -> IntTensor<Self> {
517 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
518 macro_rules! call {
519 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
520 let result = <$B>::int_remainder(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context));
521 pack!($mode, $variant, Int, result)
522 }};
523 }
524 dispatch!(selection, call)
525 }
526
527 fn int_remainder_scalar(lhs: IntTensor<Self>, rhs: Scalar) -> IntTensor<Self> {
528 let selection = Selection::tensors(core::iter::once(&lhs));
529 macro_rules! call {
530 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
531 let result = <$B>::int_remainder_scalar(unpack!($mode, $variant, Int, lhs, $context), rhs);
532 pack!($mode, $variant, Int, result)
533 }};
534 }
535 dispatch!(selection, call)
536 }
537
538 fn int_matmul(lhs: IntTensor<Self>, rhs: IntTensor<Self>) -> IntTensor<Self> {
539 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
540 macro_rules! call {
541 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
542 let result = <$B>::int_matmul(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context));
543 pack!($mode, $variant, Int, result)
544 }};
545 }
546 dispatch!(selection, call)
547 }
548
549 fn int_neg(tensor: IntTensor<Self>) -> IntTensor<Self> {
550 let selection = Selection::tensors(core::iter::once(&tensor));
551 macro_rules! call {
552 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
553 let result = <$B>::int_neg(unpack!($mode, $variant, Int, tensor, $context));
554 pack!($mode, $variant, Int, result)
555 }};
556 }
557 dispatch!(selection, call)
558 }
559
560 fn int_zeros(shape: Shape, device: &Device<Self>, dtype: IntDType) -> IntTensor<Self> {
561 let selection = Selection::factory(device);
562 macro_rules! call {
563 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
564 let result = <$B>::int_zeros(shape, $device, dtype);
565 pack!($mode, $variant, Int, result)
566 }};
567 }
568 dispatch!(selection, call)
569 }
570
571 fn int_ones(shape: Shape, device: &Device<Self>, dtype: IntDType) -> IntTensor<Self> {
572 let selection = Selection::factory(device);
573 macro_rules! call {
574 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
575 let result = <$B>::int_ones(shape, $device, dtype);
576 pack!($mode, $variant, Int, result)
577 }};
578 }
579 dispatch!(selection, call)
580 }
581
582 fn int_full( shape: Shape, fill_value: Scalar, device: &Device<Self>, dtype: IntDType, ) -> IntTensor<Self> {
583 let selection = Selection::factory(device);
584 macro_rules! call {
585 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
586 let result = <$B>::int_full(shape, fill_value, $device, dtype);
587 pack!($mode, $variant, Int, result)
588 }};
589 }
590 dispatch!(selection, call)
591 }
592
593 fn int_sum(tensor: IntTensor<Self>) -> IntTensor<Self> {
594 let selection = Selection::tensors(core::iter::once(&tensor));
595 macro_rules! call {
596 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
597 let result = <$B>::int_sum(unpack!($mode, $variant, Int, tensor, $context));
598 pack!($mode, $variant, Int, result)
599 }};
600 }
601 dispatch!(selection, call)
602 }
603
604 fn int_sum_dim(tensor: IntTensor<Self>, dim: usize) -> IntTensor<Self> {
605 let selection = Selection::tensors(core::iter::once(&tensor));
606 macro_rules! call {
607 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
608 let result = <$B>::int_sum_dim(unpack!($mode, $variant, Int, tensor, $context), dim);
609 pack!($mode, $variant, Int, result)
610 }};
611 }
612 dispatch!(selection, call)
613 }
614
615 fn int_prod(tensor: IntTensor<Self>) -> IntTensor<Self> {
616 let selection = Selection::tensors(core::iter::once(&tensor));
617 macro_rules! call {
618 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
619 let result = <$B>::int_prod(unpack!($mode, $variant, Int, tensor, $context));
620 pack!($mode, $variant, Int, result)
621 }};
622 }
623 dispatch!(selection, call)
624 }
625
626 fn int_prod_dim(tensor: IntTensor<Self>, dim: usize) -> IntTensor<Self> {
627 let selection = Selection::tensors(core::iter::once(&tensor));
628 macro_rules! call {
629 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
630 let result = <$B>::int_prod_dim(unpack!($mode, $variant, Int, tensor, $context), dim);
631 pack!($mode, $variant, Int, result)
632 }};
633 }
634 dispatch!(selection, call)
635 }
636
637 fn int_mean(tensor: IntTensor<Self>) -> IntTensor<Self> {
638 let selection = Selection::tensors(core::iter::once(&tensor));
639 macro_rules! call {
640 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
641 let result = <$B>::int_mean(unpack!($mode, $variant, Int, tensor, $context));
642 pack!($mode, $variant, Int, result)
643 }};
644 }
645 dispatch!(selection, call)
646 }
647
648 fn int_mean_dim(tensor: IntTensor<Self>, dim: usize) -> IntTensor<Self> {
649 let selection = Selection::tensors(core::iter::once(&tensor));
650 macro_rules! call {
651 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
652 let result = <$B>::int_mean_dim(unpack!($mode, $variant, Int, tensor, $context), dim);
653 pack!($mode, $variant, Int, result)
654 }};
655 }
656 dispatch!(selection, call)
657 }
658
659 fn int_cumsum(tensor: IntTensor<Self>, dim: usize) -> IntTensor<Self> {
660 let selection = Selection::tensors(core::iter::once(&tensor));
661 macro_rules! call {
662 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
663 let result = <$B>::int_cumsum(unpack!($mode, $variant, Int, tensor, $context), dim);
664 pack!($mode, $variant, Int, result)
665 }};
666 }
667 dispatch!(selection, call)
668 }
669
670 fn int_cumprod(tensor: IntTensor<Self>, dim: usize) -> IntTensor<Self> {
671 let selection = Selection::tensors(core::iter::once(&tensor));
672 macro_rules! call {
673 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
674 let result = <$B>::int_cumprod(unpack!($mode, $variant, Int, tensor, $context), dim);
675 pack!($mode, $variant, Int, result)
676 }};
677 }
678 dispatch!(selection, call)
679 }
680
681 fn int_cummin(tensor: IntTensor<Self>, dim: usize) -> IntTensor<Self> {
682 let selection = Selection::tensors(core::iter::once(&tensor));
683 macro_rules! call {
684 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
685 let result = <$B>::int_cummin(unpack!($mode, $variant, Int, tensor, $context), dim);
686 pack!($mode, $variant, Int, result)
687 }};
688 }
689 dispatch!(selection, call)
690 }
691
692 fn int_cummax(tensor: IntTensor<Self>, dim: usize) -> IntTensor<Self> {
693 let selection = Selection::tensors(core::iter::once(&tensor));
694 macro_rules! call {
695 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
696 let result = <$B>::int_cummax(unpack!($mode, $variant, Int, tensor, $context), dim);
697 pack!($mode, $variant, Int, result)
698 }};
699 }
700 dispatch!(selection, call)
701 }
702
703 fn int_argmax(tensor: IntTensor<Self>, dim: usize) -> IntTensor<Self> {
704 let selection = Selection::tensors(core::iter::once(&tensor));
705 macro_rules! call {
706 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
707 let result = <$B>::int_argmax(unpack!($mode, $variant, Int, tensor, $context), dim);
708 pack!($mode, $variant, Int, result)
709 }};
710 }
711 dispatch!(selection, call)
712 }
713
714 fn int_argtopk(tensor: IntTensor<Self>, dim: usize, k: usize) -> IntTensor<Self> {
715 let selection = Selection::tensors(core::iter::once(&tensor));
716 macro_rules! call {
717 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
718 let result = <$B>::int_argtopk(unpack!($mode, $variant, Int, tensor, $context), dim, k);
719 pack!($mode, $variant, Int, result)
720 }};
721 }
722 dispatch!(selection, call)
723 }
724
725 fn int_topk(tensor: IntTensor<Self>, dim: usize, k: usize) -> IntTensor<Self> {
726 let selection = Selection::tensors(core::iter::once(&tensor));
727 macro_rules! call {
728 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
729 let result = <$B>::int_topk(unpack!($mode, $variant, Int, tensor, $context), dim, k);
730 pack!($mode, $variant, Int, result)
731 }};
732 }
733 dispatch!(selection, call)
734 }
735
736 fn int_argmin(tensor: IntTensor<Self>, dim: usize) -> IntTensor<Self> {
737 let selection = Selection::tensors(core::iter::once(&tensor));
738 macro_rules! call {
739 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
740 let result = <$B>::int_argmin(unpack!($mode, $variant, Int, tensor, $context), dim);
741 pack!($mode, $variant, Int, result)
742 }};
743 }
744 dispatch!(selection, call)
745 }
746
747 fn int_max(tensor: IntTensor<Self>) -> IntTensor<Self> {
748 let selection = Selection::tensors(core::iter::once(&tensor));
749 macro_rules! call {
750 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
751 let result = <$B>::int_max(unpack!($mode, $variant, Int, tensor, $context));
752 pack!($mode, $variant, Int, result)
753 }};
754 }
755 dispatch!(selection, call)
756 }
757
758 fn int_max_dim(tensor: IntTensor<Self>, dim: usize) -> IntTensor<Self> {
759 let selection = Selection::tensors(core::iter::once(&tensor));
760 macro_rules! call {
761 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
762 let result = <$B>::int_max_dim(unpack!($mode, $variant, Int, tensor, $context), dim);
763 pack!($mode, $variant, Int, result)
764 }};
765 }
766 dispatch!(selection, call)
767 }
768
769 fn int_max_dim_with_indices(tensor: IntTensor<Self>, dim: usize) -> (IntTensor<Self>, IntTensor<Self>) {
770 let selection = Selection::tensors(core::iter::once(&tensor));
771 macro_rules! call {
772 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
773 let result = <$B>::int_max_dim_with_indices(unpack!($mode, $variant, Int, tensor, $context), dim);
774 { let (value0, value1) = result; (pack!($mode, $variant, Int, value0), pack!($mode, $variant, Int, value1)) }
775 }};
776 }
777 dispatch!(selection, call)
778 }
779
780 fn int_max_abs(tensor: IntTensor<Self>) -> IntTensor<Self> {
781 let selection = Selection::tensors(core::iter::once(&tensor));
782 macro_rules! call {
783 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
784 let result = <$B>::int_max_abs(unpack!($mode, $variant, Int, tensor, $context));
785 pack!($mode, $variant, Int, result)
786 }};
787 }
788 dispatch!(selection, call)
789 }
790
791 fn int_max_abs_dim(tensor: IntTensor<Self>, dim: usize) -> IntTensor<Self> {
792 let selection = Selection::tensors(core::iter::once(&tensor));
793 macro_rules! call {
794 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
795 let result = <$B>::int_max_abs_dim(unpack!($mode, $variant, Int, tensor, $context), dim);
796 pack!($mode, $variant, Int, result)
797 }};
798 }
799 dispatch!(selection, call)
800 }
801
802 fn int_min(tensor: IntTensor<Self>) -> IntTensor<Self> {
803 let selection = Selection::tensors(core::iter::once(&tensor));
804 macro_rules! call {
805 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
806 let result = <$B>::int_min(unpack!($mode, $variant, Int, tensor, $context));
807 pack!($mode, $variant, Int, result)
808 }};
809 }
810 dispatch!(selection, call)
811 }
812
813 fn int_min_dim(tensor: IntTensor<Self>, dim: usize) -> IntTensor<Self> {
814 let selection = Selection::tensors(core::iter::once(&tensor));
815 macro_rules! call {
816 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
817 let result = <$B>::int_min_dim(unpack!($mode, $variant, Int, tensor, $context), dim);
818 pack!($mode, $variant, Int, result)
819 }};
820 }
821 dispatch!(selection, call)
822 }
823
824 fn int_min_dim_with_indices(tensor: IntTensor<Self>, dim: usize) -> (IntTensor<Self>, IntTensor<Self>) {
825 let selection = Selection::tensors(core::iter::once(&tensor));
826 macro_rules! call {
827 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
828 let result = <$B>::int_min_dim_with_indices(unpack!($mode, $variant, Int, tensor, $context), dim);
829 { let (value0, value1) = result; (pack!($mode, $variant, Int, value0), pack!($mode, $variant, Int, value1)) }
830 }};
831 }
832 dispatch!(selection, call)
833 }
834
835 fn int_abs(tensor: IntTensor<Self>) -> IntTensor<Self> {
836 let selection = Selection::tensors(core::iter::once(&tensor));
837 macro_rules! call {
838 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
839 let result = <$B>::int_abs(unpack!($mode, $variant, Int, tensor, $context));
840 pack!($mode, $variant, Int, result)
841 }};
842 }
843 dispatch!(selection, call)
844 }
845
846 fn int_transpose(tensor: IntTensor<Self>) -> IntTensor<Self> {
847 let selection = Selection::tensors(core::iter::once(&tensor));
848 macro_rules! call {
849 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
850 let result = <$B>::int_transpose(unpack!($mode, $variant, Int, tensor, $context));
851 pack!($mode, $variant, Int, result)
852 }};
853 }
854 dispatch!(selection, call)
855 }
856
857 fn int_swap_dims(tensor: IntTensor<Self>, dim1: usize, dim2: usize) -> IntTensor<Self> {
858 let selection = Selection::tensors(core::iter::once(&tensor));
859 macro_rules! call {
860 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
861 let result = <$B>::int_swap_dims(unpack!($mode, $variant, Int, tensor, $context), dim1, dim2);
862 pack!($mode, $variant, Int, result)
863 }};
864 }
865 dispatch!(selection, call)
866 }
867
868 fn int_permute(tensor: IntTensor<Self>, axes: &[usize]) -> IntTensor<Self> {
869 let selection = Selection::tensors(core::iter::once(&tensor));
870 macro_rules! call {
871 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
872 let result = <$B>::int_permute(unpack!($mode, $variant, Int, tensor, $context), axes);
873 pack!($mode, $variant, Int, result)
874 }};
875 }
876 dispatch!(selection, call)
877 }
878
879 fn int_flip(tensor: IntTensor<Self>, axes: &[usize]) -> IntTensor<Self> {
880 let selection = Selection::tensors(core::iter::once(&tensor));
881 macro_rules! call {
882 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
883 let result = <$B>::int_flip(unpack!($mode, $variant, Int, tensor, $context), axes);
884 pack!($mode, $variant, Int, result)
885 }};
886 }
887 dispatch!(selection, call)
888 }
889
890 fn int_random( shape: Shape, distribution: Distribution, device: &Device<Self>, dtype: IntDType, ) -> IntTensor<Self> {
891 let selection = Selection::factory(device);
892 macro_rules! call {
893 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
894 let result = <$B>::int_random(shape, distribution, $device, dtype);
895 pack!($mode, $variant, Int, result)
896 }};
897 }
898 dispatch!(selection, call)
899 }
900
901 fn int_arange_step( range: Range<i64>, step: usize, device: &Device<Self>, dtype: IntDType, ) -> IntTensor<Self> {
902 let selection = Selection::factory(device);
903 macro_rules! call {
904 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
905 let result = <$B>::int_arange_step(range, step, $device, dtype);
906 pack!($mode, $variant, Int, result)
907 }};
908 }
909 dispatch!(selection, call)
910 }
911
912 fn int_arange(range: Range<i64>, device: &Device<Self>, dtype: IntDType) -> IntTensor<Self> {
913 let selection = Selection::factory(device);
914 macro_rules! call {
915 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
916 let result = <$B>::int_arange(range, $device, dtype);
917 pack!($mode, $variant, Int, result)
918 }};
919 }
920 dispatch!(selection, call)
921 }
922
923 fn int_any(tensor: IntTensor<Self>, out_dtype: BoolDType) -> BoolTensor<Self> {
924 let selection = Selection::tensors(core::iter::once(&tensor));
925 macro_rules! call {
926 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
927 let result = <$B>::int_any(unpack!($mode, $variant, Int, tensor, $context), out_dtype);
928 pack!($mode, $variant, Bool, result)
929 }};
930 }
931 dispatch!(selection, call)
932 }
933
934 fn int_any_dim(tensor: IntTensor<Self>, dim: usize, out_dtype: BoolDType) -> BoolTensor<Self> {
935 let selection = Selection::tensors(core::iter::once(&tensor));
936 macro_rules! call {
937 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
938 let result = <$B>::int_any_dim(unpack!($mode, $variant, Int, tensor, $context), dim, out_dtype);
939 pack!($mode, $variant, Bool, result)
940 }};
941 }
942 dispatch!(selection, call)
943 }
944
945 fn int_all(tensor: IntTensor<Self>, out_dtype: BoolDType) -> BoolTensor<Self> {
946 let selection = Selection::tensors(core::iter::once(&tensor));
947 macro_rules! call {
948 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
949 let result = <$B>::int_all(unpack!($mode, $variant, Int, tensor, $context), out_dtype);
950 pack!($mode, $variant, Bool, result)
951 }};
952 }
953 dispatch!(selection, call)
954 }
955
956 fn int_all_dim(tensor: IntTensor<Self>, dim: usize, out_dtype: BoolDType) -> BoolTensor<Self> {
957 let selection = Selection::tensors(core::iter::once(&tensor));
958 macro_rules! call {
959 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
960 let result = <$B>::int_all_dim(unpack!($mode, $variant, Int, tensor, $context), dim, out_dtype);
961 pack!($mode, $variant, Bool, result)
962 }};
963 }
964 dispatch!(selection, call)
965 }
966
967 fn int_sign(tensor: IntTensor<Self>) -> IntTensor<Self> {
968 let selection = Selection::tensors(core::iter::once(&tensor));
969 macro_rules! call {
970 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
971 let result = <$B>::int_sign(unpack!($mode, $variant, Int, tensor, $context));
972 pack!($mode, $variant, Int, result)
973 }};
974 }
975 dispatch!(selection, call)
976 }
977
978 fn int_expand(tensor: IntTensor<Self>, shape: Shape) -> IntTensor<Self> {
979 let selection = Selection::tensors(core::iter::once(&tensor));
980 macro_rules! call {
981 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
982 let result = <$B>::int_expand(unpack!($mode, $variant, Int, tensor, $context), shape);
983 pack!($mode, $variant, Int, result)
984 }};
985 }
986 dispatch!(selection, call)
987 }
988
989 fn int_sort(tensor: IntTensor<Self>, dim: usize, descending: bool) -> IntTensor<Self> {
990 let selection = Selection::tensors(core::iter::once(&tensor));
991 macro_rules! call {
992 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
993 let result = <$B>::int_sort(unpack!($mode, $variant, Int, tensor, $context), dim, descending);
994 pack!($mode, $variant, Int, result)
995 }};
996 }
997 dispatch!(selection, call)
998 }
999
1000 fn int_sort_with_indices( tensor: IntTensor<Self>, dim: usize, descending: bool, ) -> (IntTensor<Self>, IntTensor<Self>) {
1001 let selection = Selection::tensors(core::iter::once(&tensor));
1002 macro_rules! call {
1003 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1004 let result = <$B>::int_sort_with_indices(unpack!($mode, $variant, Int, tensor, $context), dim, descending);
1005 { let (value0, value1) = result; (pack!($mode, $variant, Int, value0), pack!($mode, $variant, Int, value1)) }
1006 }};
1007 }
1008 dispatch!(selection, call)
1009 }
1010
1011 fn int_argsort(tensor: IntTensor<Self>, dim: usize, descending: bool) -> IntTensor<Self> {
1012 let selection = Selection::tensors(core::iter::once(&tensor));
1013 macro_rules! call {
1014 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1015 let result = <$B>::int_argsort(unpack!($mode, $variant, Int, tensor, $context), dim, descending);
1016 pack!($mode, $variant, Int, result)
1017 }};
1018 }
1019 dispatch!(selection, call)
1020 }
1021
1022 fn bitwise_and(lhs: IntTensor<Self>, rhs: IntTensor<Self>) -> IntTensor<Self> {
1023 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
1024 macro_rules! call {
1025 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1026 let result = <$B>::bitwise_and(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context));
1027 pack!($mode, $variant, Int, result)
1028 }};
1029 }
1030 dispatch!(selection, call)
1031 }
1032
1033 fn bitwise_and_scalar(lhs: IntTensor<Self>, rhs: Scalar) -> IntTensor<Self> {
1034 let selection = Selection::tensors(core::iter::once(&lhs));
1035 macro_rules! call {
1036 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1037 let result = <$B>::bitwise_and_scalar(unpack!($mode, $variant, Int, lhs, $context), rhs);
1038 pack!($mode, $variant, Int, result)
1039 }};
1040 }
1041 dispatch!(selection, call)
1042 }
1043
1044 fn bitwise_or(lhs: IntTensor<Self>, rhs: IntTensor<Self>) -> IntTensor<Self> {
1045 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
1046 macro_rules! call {
1047 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1048 let result = <$B>::bitwise_or(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context));
1049 pack!($mode, $variant, Int, result)
1050 }};
1051 }
1052 dispatch!(selection, call)
1053 }
1054
1055 fn bitwise_or_scalar(lhs: IntTensor<Self>, rhs: Scalar) -> IntTensor<Self> {
1056 let selection = Selection::tensors(core::iter::once(&lhs));
1057 macro_rules! call {
1058 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1059 let result = <$B>::bitwise_or_scalar(unpack!($mode, $variant, Int, lhs, $context), rhs);
1060 pack!($mode, $variant, Int, result)
1061 }};
1062 }
1063 dispatch!(selection, call)
1064 }
1065
1066 fn bitwise_xor(lhs: IntTensor<Self>, rhs: IntTensor<Self>) -> IntTensor<Self> {
1067 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
1068 macro_rules! call {
1069 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1070 let result = <$B>::bitwise_xor(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context));
1071 pack!($mode, $variant, Int, result)
1072 }};
1073 }
1074 dispatch!(selection, call)
1075 }
1076
1077 fn bitwise_xor_scalar(lhs: IntTensor<Self>, rhs: Scalar) -> IntTensor<Self> {
1078 let selection = Selection::tensors(core::iter::once(&lhs));
1079 macro_rules! call {
1080 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1081 let result = <$B>::bitwise_xor_scalar(unpack!($mode, $variant, Int, lhs, $context), rhs);
1082 pack!($mode, $variant, Int, result)
1083 }};
1084 }
1085 dispatch!(selection, call)
1086 }
1087
1088 fn bitwise_not(tensor: IntTensor<Self>) -> IntTensor<Self> {
1089 let selection = Selection::tensors(core::iter::once(&tensor));
1090 macro_rules! call {
1091 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1092 let result = <$B>::bitwise_not(unpack!($mode, $variant, Int, tensor, $context));
1093 pack!($mode, $variant, Int, result)
1094 }};
1095 }
1096 dispatch!(selection, call)
1097 }
1098
1099 fn bitwise_left_shift(lhs: IntTensor<Self>, rhs: IntTensor<Self>) -> IntTensor<Self> {
1100 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
1101 macro_rules! call {
1102 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1103 let result = <$B>::bitwise_left_shift(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context));
1104 pack!($mode, $variant, Int, result)
1105 }};
1106 }
1107 dispatch!(selection, call)
1108 }
1109
1110 fn bitwise_left_shift_scalar(lhs: IntTensor<Self>, rhs: Scalar) -> IntTensor<Self> {
1111 let selection = Selection::tensors(core::iter::once(&lhs));
1112 macro_rules! call {
1113 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1114 let result = <$B>::bitwise_left_shift_scalar(unpack!($mode, $variant, Int, lhs, $context), rhs);
1115 pack!($mode, $variant, Int, result)
1116 }};
1117 }
1118 dispatch!(selection, call)
1119 }
1120
1121 fn bitwise_right_shift(lhs: IntTensor<Self>, rhs: IntTensor<Self>) -> IntTensor<Self> {
1122 let selection = Selection::tensors(core::iter::once(&lhs).chain(core::iter::once(&rhs)));
1123 macro_rules! call {
1124 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1125 let result = <$B>::bitwise_right_shift(unpack!($mode, $variant, Int, lhs, $context), unpack!($mode, $variant, Int, rhs, $context));
1126 pack!($mode, $variant, Int, result)
1127 }};
1128 }
1129 dispatch!(selection, call)
1130 }
1131
1132 fn bitwise_right_shift_scalar(lhs: IntTensor<Self>, rhs: Scalar) -> IntTensor<Self> {
1133 let selection = Selection::tensors(core::iter::once(&lhs));
1134 macro_rules! call {
1135 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1136 let result = <$B>::bitwise_right_shift_scalar(unpack!($mode, $variant, Int, lhs, $context), rhs);
1137 pack!($mode, $variant, Int, result)
1138 }};
1139 }
1140 dispatch!(selection, call)
1141 }
1142
1143 fn int_cast(tensor: IntTensor<Self>, dtype: IntDType) -> IntTensor<Self> {
1144 let selection = Selection::tensors(core::iter::once(&tensor));
1145 macro_rules! call {
1146 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1147 let result = <$B>::int_cast(unpack!($mode, $variant, Int, tensor, $context), dtype);
1148 pack!($mode, $variant, Int, result)
1149 }};
1150 }
1151 dispatch!(selection, call)
1152 }
1153
1154 fn int_unfold(tensor: IntTensor<Self>, dim: usize, size: usize, step: usize) -> IntTensor<Self> {
1155 let selection = Selection::tensors(core::iter::once(&tensor));
1156 macro_rules! call {
1157 ($B:ty, $variant:ident, $mode:ident, $device:expr, $context:expr) => {{
1158 let result = <$B>::int_unfold(unpack!($mode, $variant, Int, tensor, $context), dim, size, step);
1159 pack!($mode, $variant, Int, result)
1160 }};
1161 }
1162 dispatch!(selection, call)
1163 }
1164}