3 #include <ATen/core/Tensor.h> 4 #include <c10/core/Scalar.h> 5 #include <c10/macros/Macros.h> 6 #include <ATen/core/SparseTensorRef.h> 7 #include <ATen/core/Type.h> 8 #include <c10/core/TensorOptions.h> 12 inline Tensor Tensor::toType(
const Type & t,
bool non_blocking)
const {
15 return t.copy(*
this, non_blocking);
18 inline Tensor Tensor::cpu()
const {
19 return toType(type().cpu());
22 inline Tensor Tensor::cuda()
const {
23 return toType(type().cuda());
26 inline Tensor Tensor::hip()
const {
27 return toType(type().hip());
30 inline Tensor & Tensor::copy_(
const Tensor & src,
bool non_blocking) {
31 return type().copy_(*
this, src, non_blocking);
34 inline Tensor Tensor::toType(ScalarType t)
const {
35 return toType(type().toScalarType(t));
38 inline Tensor Tensor::toBackend(Backend b)
const {
39 return toType(type().toBackend(b));
53 type().backward(*
this, std::move(gradient), keep_graph, create_graph);
56 inline void Tensor::set_data(
Tensor new_data) {
57 type().set_data(*
this, new_data);
61 inline Tensor Tensor::abs()
const {
62 return type().abs(*
this);
64 inline Tensor & Tensor::abs_() {
65 return type().abs_(*
this);
67 inline Tensor Tensor::acos()
const {
68 return type().acos(*
this);
70 inline Tensor & Tensor::acos_() {
71 return type().acos_(*
this);
74 return type().add(*
this, other, alpha);
77 return type().add_(*
this, other, alpha);
80 return type().add(*
this, other, alpha);
83 return type().add_(*
this, other, alpha);
86 return type().addmv(*
this, mat, vec, beta, alpha);
89 return type().addmv_(*
this, mat, vec, beta, alpha);
92 return type().addr(*
this, vec1, vec2, beta, alpha);
95 return type().addr_(*
this, vec1, vec2, beta, alpha);
97 inline Tensor Tensor::all(int64_t dim,
bool keepdim)
const {
98 return type().all(*
this, dim, keepdim);
100 inline bool Tensor::allclose(
const Tensor & other,
double rtol,
double atol,
bool equal_nan)
const {
101 return type().allclose(*
this, other, rtol, atol, equal_nan);
103 inline Tensor Tensor::any(int64_t dim,
bool keepdim)
const {
104 return type().any(*
this, dim, keepdim);
107 return type().argmax(*
this, dim, keepdim);
110 return type().argmin(*
this, dim, keepdim);
113 return type().as_strided(*
this, size, stride, storage_offset);
116 return type().as_strided_(*
this, size, stride, storage_offset);
118 inline Tensor Tensor::asin()
const {
119 return type().asin(*
this);
121 inline Tensor & Tensor::asin_() {
122 return type().asin_(*
this);
124 inline Tensor Tensor::atan()
const {
125 return type().atan(*
this);
127 inline Tensor & Tensor::atan_() {
128 return type().atan_(*
this);
131 return type().baddbmm(*
this, batch1, batch2, beta, alpha);
134 return type().baddbmm_(*
this, batch1, batch2, beta, alpha);
137 return type().bernoulli(*
this, generator);
140 return type().bernoulli_(*
this, p, generator);
143 return type().bernoulli_(*
this, p, generator);
145 inline Tensor Tensor::bernoulli(
double p,
Generator * generator)
const {
146 return type().bernoulli(*
this, p, generator);
148 inline Tensor Tensor::bincount(
const Tensor & weights, int64_t minlength)
const {
149 return type().bincount(*
this, weights, minlength);
152 return type().bmm(*
this, mat2);
154 inline Tensor Tensor::ceil()
const {
155 return type().ceil(*
this);
157 inline Tensor & Tensor::ceil_() {
158 return type().ceil_(*
this);
160 inline std::vector<Tensor> Tensor::chunk(int64_t chunks, int64_t dim)
const {
161 return type().chunk(*
this, chunks, dim);
164 return type().clamp(*
this, min, max);
167 return type().clamp_(*
this, min, max);
170 return type().clamp_max(*
this, max);
173 return type().clamp_max_(*
this, max);
176 return type().clamp_min(*
this, min);
179 return type().clamp_min_(*
this, min);
181 inline Tensor Tensor::contiguous()
const {
182 return type().contiguous(*
this);
184 inline Tensor Tensor::cos()
const {
185 return type().cos(*
this);
187 inline Tensor & Tensor::cos_() {
188 return type().cos_(*
this);
190 inline Tensor Tensor::cosh()
const {
191 return type().cosh(*
this);
193 inline Tensor & Tensor::cosh_() {
194 return type().cosh_(*
this);
196 inline Tensor Tensor::cumsum(int64_t dim, ScalarType
dtype)
const {
197 return type().cumsum(*
this, dim, dtype);
199 inline Tensor Tensor::cumsum(int64_t dim)
const {
200 return type().cumsum(*
this, dim);
202 inline Tensor Tensor::cumprod(int64_t dim, ScalarType dtype)
const {
203 return type().cumprod(*
this, dim, dtype);
205 inline Tensor Tensor::cumprod(int64_t dim)
const {
206 return type().cumprod(*
this, dim);
208 inline Tensor Tensor::det()
const {
209 return type().det(*
this);
211 inline Tensor Tensor::diag_embed(int64_t offset, int64_t dim1, int64_t dim2)
const {
212 return type().diag_embed(*
this, offset, dim1, dim2);
214 inline Tensor Tensor::diagflat(int64_t offset)
const {
215 return type().diagflat(*
this, offset);
217 inline Tensor Tensor::diagonal(int64_t offset, int64_t dim1, int64_t dim2)
const {
218 return type().diagonal(*
this, offset, dim1, dim2);
221 return type().div(*
this, other);
224 return type().div_(*
this, other);
227 return type().div(*
this, other);
230 return type().div_(*
this, other);
232 inline Tensor Tensor::dot(
const Tensor & tensor)
const {
233 return type().dot(*
this, tensor);
236 return type().resize_(*
this, size);
238 inline Tensor Tensor::erf()
const {
239 return type().erf(*
this);
241 inline Tensor & Tensor::erf_() {
242 return type().erf_(*
this);
244 inline Tensor Tensor::erfc()
const {
245 return type().erfc(*
this);
247 inline Tensor & Tensor::erfc_() {
248 return type().erfc_(*
this);
250 inline Tensor Tensor::exp()
const {
251 return type().exp(*
this);
253 inline Tensor & Tensor::exp_() {
254 return type().exp_(*
this);
256 inline Tensor Tensor::expm1()
const {
257 return type().expm1(*
this);
259 inline Tensor & Tensor::expm1_() {
260 return type().expm1_(*
this);
263 return type().expand(*
this, size, implicit);
265 inline Tensor Tensor::expand_as(
const Tensor & other)
const {
266 return type().expand_as(*
this, other);
268 inline Tensor Tensor::flatten(int64_t start_dim, int64_t end_dim)
const {
269 return type().flatten(*
this, start_dim, end_dim);
272 return type().fill_(*
this, value);
275 return type().fill_(*
this, value);
277 inline Tensor Tensor::floor()
const {
278 return type().floor(*
this);
280 inline Tensor & Tensor::floor_() {
281 return type().floor_(*
this);
284 return type().ger(*
this, vec2);
286 inline Tensor Tensor::fft(int64_t signal_ndim,
bool normalized)
const {
287 return type().fft(*
this, signal_ndim, normalized);
289 inline Tensor Tensor::ifft(int64_t signal_ndim,
bool normalized)
const {
290 return type().ifft(*
this, signal_ndim, normalized);
292 inline Tensor Tensor::rfft(int64_t signal_ndim,
bool normalized,
bool onesided)
const {
293 return type().rfft(*
this, signal_ndim, normalized, onesided);
295 inline Tensor Tensor::irfft(int64_t signal_ndim,
bool normalized,
bool onesided,
IntArrayRef signal_sizes)
const {
296 return type().irfft(*
this, signal_ndim, normalized, onesided, signal_sizes);
299 return type().index(*
this, indices);
301 inline Tensor & Tensor::index_copy_(int64_t dim,
const Tensor & index,
const Tensor & source) {
302 return type().index_copy_(*
this, dim, index, source);
304 inline Tensor Tensor::index_copy(int64_t dim,
const Tensor & index,
const Tensor & source)
const {
305 return type().index_copy(*
this, dim, index, source);
308 return type().index_put_(*
this, indices, values, accumulate);
311 return type().index_put(*
this, indices, values, accumulate);
313 inline Tensor Tensor::inverse()
const {
314 return type().inverse(*
this);
316 inline Tensor Tensor::isclose(
const Tensor & other,
double rtol,
double atol,
bool equal_nan)
const {
317 return type().isclose(*
this, other, rtol, atol, equal_nan);
319 inline bool Tensor::is_distributed()
const {
320 return type().is_distributed(*
this);
322 inline bool Tensor::is_floating_point()
const {
323 return type().is_floating_point(*
this);
325 inline bool Tensor::is_complex()
const {
326 return type().is_complex(*
this);
328 inline bool Tensor::is_nonzero()
const {
329 return type().is_nonzero(*
this);
331 inline bool Tensor::is_same_size(
const Tensor & other)
const {
332 return type().is_same_size(*
this, other);
334 inline bool Tensor::is_signed()
const {
335 return type().is_signed(*
this);
337 inline std::tuple<Tensor,Tensor> Tensor::kthvalue(int64_t k, int64_t dim,
bool keepdim)
const {
338 return type().kthvalue(*
this, k, dim, keepdim);
340 inline Tensor Tensor::log()
const {
341 return type().log(*
this);
343 inline Tensor & Tensor::log_() {
344 return type().log_(*
this);
346 inline Tensor Tensor::log10()
const {
347 return type().log10(*
this);
349 inline Tensor & Tensor::log10_() {
350 return type().log10_(*
this);
352 inline Tensor Tensor::log1p()
const {
353 return type().log1p(*
this);
355 inline Tensor & Tensor::log1p_() {
356 return type().log1p_(*
this);
358 inline Tensor Tensor::log2()
const {
359 return type().log2(*
this);
361 inline Tensor & Tensor::log2_() {
362 return type().log2_(*
this);
364 inline Tensor Tensor::logdet()
const {
365 return type().logdet(*
this);
367 inline Tensor Tensor::log_softmax(int64_t dim, ScalarType dtype)
const {
368 return type().log_softmax(*
this, dim, dtype);
370 inline Tensor Tensor::log_softmax(int64_t dim)
const {
371 return type().log_softmax(*
this, dim);
374 return type().logsumexp(*
this, dim, keepdim);
376 inline Tensor Tensor::matmul(
const Tensor & other)
const {
377 return type().matmul(*
this, other);
379 inline Tensor Tensor::matrix_power(int64_t n)
const {
380 return type().matrix_power(*
this, n);
382 inline std::tuple<Tensor,Tensor> Tensor::max(int64_t dim,
bool keepdim)
const {
383 return type().max(*
this, dim, keepdim);
386 return type().max_values(*
this, dim, keepdim);
388 inline Tensor Tensor::mean(ScalarType dtype)
const {
389 return type().mean(*
this, dtype);
391 inline Tensor Tensor::mean()
const {
392 return type().mean(*
this);
394 inline Tensor Tensor::mean(
IntArrayRef dim,
bool keepdim, ScalarType dtype)
const {
395 return type().mean(*
this, dim, keepdim, dtype);
398 return type().mean(*
this, dim, keepdim);
401 return type().mean(*
this, dim, dtype);
403 inline std::tuple<Tensor,Tensor> Tensor::median(int64_t dim,
bool keepdim)
const {
404 return type().median(*
this, dim, keepdim);
406 inline std::tuple<Tensor,Tensor> Tensor::min(int64_t dim,
bool keepdim)
const {
407 return type().min(*
this, dim, keepdim);
410 return type().min_values(*
this, dim, keepdim);
413 return type().mm(*
this, mat2);
415 inline std::tuple<Tensor,Tensor> Tensor::mode(int64_t dim,
bool keepdim)
const {
416 return type().mode(*
this, dim, keepdim);
419 return type().mul(*
this, other);
422 return type().mul_(*
this, other);
425 return type().mul(*
this, other);
428 return type().mul_(*
this, other);
431 return type().mv(*
this, vec);
433 inline Tensor Tensor::mvlgamma(int64_t p)
const {
434 return type().mvlgamma(*
this, p);
436 inline Tensor & Tensor::mvlgamma_(int64_t p) {
437 return type().mvlgamma_(*
this, p);
439 inline Tensor Tensor::narrow_copy(int64_t dim, int64_t start, int64_t length)
const {
440 return type().narrow_copy(*
this, dim, start, length);
442 inline Tensor Tensor::narrow(int64_t dim, int64_t start, int64_t length)
const {
443 return type().narrow(*
this, dim, start, length);
446 return type().permute(*
this, dims);
448 inline Tensor Tensor::pin_memory()
const {
449 return type().pin_memory(*
this);
451 inline Tensor Tensor::pinverse(
double rcond)
const {
452 return type().pinverse(*
this, rcond);
455 return type().repeat(*
this, repeats);
458 return type().reshape(*
this, shape);
460 inline Tensor Tensor::reshape_as(
const Tensor & other)
const {
461 return type().reshape_as(*
this, other);
463 inline Tensor Tensor::round()
const {
464 return type().round(*
this);
466 inline Tensor & Tensor::round_() {
467 return type().round_(*
this);
469 inline Tensor Tensor::relu()
const {
470 return type().relu(*
this);
472 inline Tensor & Tensor::relu_() {
473 return type().relu_(*
this);
475 inline Tensor Tensor::prelu(
const Tensor & weight)
const {
476 return type().prelu(*
this, weight);
478 inline std::tuple<Tensor,Tensor> Tensor::prelu_backward(
const Tensor & grad_output,
const Tensor & weight)
const {
479 return type().prelu_backward(grad_output, *
this, weight);
482 return type().hardshrink(*
this, lambd);
484 inline Tensor Tensor::hardshrink_backward(
const Tensor & grad_out,
Scalar lambd)
const {
485 return type().hardshrink_backward(grad_out, *
this, lambd);
487 inline Tensor Tensor::rsqrt()
const {
488 return type().rsqrt(*
this);
490 inline Tensor & Tensor::rsqrt_() {
491 return type().rsqrt_(*
this);
493 inline Tensor Tensor::select(int64_t dim, int64_t index)
const {
494 return type().select(*
this, dim, index);
496 inline Tensor Tensor::sigmoid()
const {
497 return type().sigmoid(*
this);
499 inline Tensor & Tensor::sigmoid_() {
500 return type().sigmoid_(*
this);
502 inline Tensor Tensor::sin()
const {
503 return type().sin(*
this);
505 inline Tensor & Tensor::sin_() {
506 return type().sin_(*
this);
508 inline Tensor Tensor::sinh()
const {
509 return type().sinh(*
this);
511 inline Tensor & Tensor::sinh_() {
512 return type().sinh_(*
this);
514 inline Tensor Tensor::detach()
const {
515 return type().detach(*
this);
517 inline Tensor & Tensor::detach_() {
518 return type().detach_(*
this);
520 inline int64_t Tensor::size(int64_t dim)
const {
521 return type().size(*
this, dim);
523 inline Tensor Tensor::slice(int64_t dim, int64_t start, int64_t end, int64_t step)
const {
524 return type().slice(*
this, dim, start, end, step);
526 inline std::tuple<Tensor,Tensor> Tensor::slogdet()
const {
527 return type().slogdet(*
this);
530 return type().smm(*
this, mat2);
532 inline Tensor Tensor::softmax(int64_t dim, ScalarType dtype)
const {
533 return type().softmax(*
this, dim, dtype);
535 inline Tensor Tensor::softmax(int64_t dim)
const {
536 return type().softmax(*
this, dim);
538 inline std::vector<Tensor> Tensor::split(int64_t split_size, int64_t dim)
const {
539 return type().split(*
this, split_size, dim);
541 inline std::vector<Tensor> Tensor::split_with_sizes(
IntArrayRef split_sizes, int64_t dim)
const {
542 return type().split_with_sizes(*
this, split_sizes, dim);
544 inline Tensor Tensor::squeeze()
const {
545 return type().squeeze(*
this);
547 inline Tensor Tensor::squeeze(int64_t dim)
const {
548 return type().squeeze(*
this, dim);
550 inline Tensor & Tensor::squeeze_() {
551 return type().squeeze_(*
this);
553 inline Tensor & Tensor::squeeze_(int64_t dim) {
554 return type().squeeze_(*
this, dim);
557 return type().sspaddmm(*
this, mat1, mat2, beta, alpha);
560 return type().stft(*
this, n_fft, hop_length, win_length, window, normalized, onesided);
562 inline int64_t Tensor::stride(int64_t dim)
const {
563 return type().stride(*
this, dim);
565 inline Tensor Tensor::sum(ScalarType dtype)
const {
566 return type().sum(*
this, dtype);
568 inline Tensor Tensor::sum()
const {
569 return type().sum(*
this);
571 inline Tensor Tensor::sum(
IntArrayRef dim,
bool keepdim, ScalarType dtype)
const {
572 return type().sum(*
this, dim, keepdim, dtype);
575 return type().sum(*
this, dim, keepdim);
578 return type().sum(*
this, dim, dtype);
581 return type().sum_to_size(*
this, size);
583 inline Tensor Tensor::sqrt()
const {
584 return type().sqrt(*
this);
586 inline Tensor & Tensor::sqrt_() {
587 return type().sqrt_(*
this);
589 inline Tensor Tensor::std(
bool unbiased)
const {
590 return type().std(*
this, unbiased);
593 return type().std(*
this, dim, unbiased, keepdim);
595 inline Tensor Tensor::prod(ScalarType dtype)
const {
596 return type().prod(*
this, dtype);
598 inline Tensor Tensor::prod()
const {
599 return type().prod(*
this);
601 inline Tensor Tensor::prod(int64_t dim,
bool keepdim, ScalarType dtype)
const {
602 return type().prod(*
this, dim, keepdim, dtype);
604 inline Tensor Tensor::prod(int64_t dim,
bool keepdim)
const {
605 return type().prod(*
this, dim, keepdim);
607 inline Tensor Tensor::prod(int64_t dim, ScalarType dtype)
const {
608 return type().prod(*
this, dim, dtype);
610 inline Tensor Tensor::t()
const {
611 return type().t(*
this);
613 inline Tensor & Tensor::t_() {
614 return type().t_(*
this);
616 inline Tensor Tensor::tan()
const {
617 return type().tan(*
this);
619 inline Tensor & Tensor::tan_() {
620 return type().tan_(*
this);
622 inline Tensor Tensor::tanh()
const {
623 return type().tanh(*
this);
625 inline Tensor & Tensor::tanh_() {
626 return type().tanh_(*
this);
628 inline Tensor Tensor::transpose(int64_t dim0, int64_t dim1)
const {
629 return type().transpose(*
this, dim0, dim1);
631 inline Tensor & Tensor::transpose_(int64_t dim0, int64_t dim1) {
632 return type().transpose_(*
this, dim0, dim1);
635 return type().flip(*
this, dims);
638 return type().roll(*
this, shifts, dims);
641 return type().rot90(*
this, k, dims);
643 inline Tensor Tensor::trunc()
const {
644 return type().trunc(*
this);
646 inline Tensor & Tensor::trunc_() {
647 return type().trunc_(*
this);
649 inline Tensor Tensor::type_as(
const Tensor & other)
const {
650 return type().type_as(*
this, other);
652 inline Tensor Tensor::unsqueeze(int64_t dim)
const {
653 return type().unsqueeze(*
this, dim);
655 inline Tensor & Tensor::unsqueeze_(int64_t dim) {
656 return type().unsqueeze_(*
this, dim);
658 inline Tensor Tensor::var(
bool unbiased)
const {
659 return type().var(*
this, unbiased);
662 return type().var(*
this, dim, unbiased, keepdim);
664 inline Tensor Tensor::view_as(
const Tensor & other)
const {
665 return type().view_as(*
this, other);
668 return type().where(condition, *
this, other);
671 return type().norm(*
this, p, dtype);
674 return type().norm(*
this, p);
677 return type().norm(*
this, p, dim, keepdim, dtype);
680 return type().norm(*
this, p, dim, keepdim);
682 inline Tensor Tensor::clone()
const {
683 return type().clone(*
this);
685 inline Tensor & Tensor::resize_as_(
const Tensor & the_template) {
686 return type().resize_as_(*
this, the_template);
689 return type().pow(*
this, exponent);
691 inline Tensor & Tensor::zero_() {
692 return type().zero_(*
this);
695 return type().sub(*
this, other, alpha);
698 return type().sub_(*
this, other, alpha);
701 return type().sub(*
this, other, alpha);
704 return type().sub_(*
this, other, alpha);
707 return type().addmm(*
this, mat1, mat2, beta, alpha);
710 return type().addmm_(*
this, mat1, mat2, beta, alpha);
712 inline Tensor & Tensor::sparse_resize_(
IntArrayRef size, int64_t sparse_dim, int64_t dense_dim) {
713 return type().sparse_resize_(*
this, size, sparse_dim, dense_dim);
715 inline Tensor & Tensor::sparse_resize_and_clear_(
IntArrayRef size, int64_t sparse_dim, int64_t dense_dim) {
716 return type().sparse_resize_and_clear_(*
this, size, sparse_dim, dense_dim);
719 return type().sparse_mask(*
this, mask);
721 inline Tensor Tensor::to_dense()
const {
722 return type().to_dense(*
this);
724 inline int64_t Tensor::sparse_dim()
const {
725 return type().sparse_dim(*
this);
727 inline int64_t Tensor::_dimI()
const {
728 return type()._dimI(*
this);
730 inline int64_t Tensor::dense_dim()
const {
731 return type().dense_dim(*
this);
733 inline int64_t Tensor::_dimV()
const {
734 return type()._dimV(*
this);
736 inline int64_t Tensor::_nnz()
const {
737 return type()._nnz(*
this);
739 inline Tensor Tensor::coalesce()
const {
740 return type().coalesce(*
this);
742 inline bool Tensor::is_coalesced()
const {
743 return type().is_coalesced(*
this);
745 inline Tensor Tensor::_indices()
const {
746 return type()._indices(*
this);
748 inline Tensor Tensor::_values()
const {
749 return type()._values(*
this);
751 inline Tensor & Tensor::_coalesced_(
bool coalesced) {
752 return type()._coalesced_(*
this, coalesced);
754 inline Tensor Tensor::indices()
const {
755 return type().indices(*
this);
757 inline Tensor Tensor::values()
const {
758 return type().values(*
this);
760 inline int64_t Tensor::numel()
const {
761 return type().numel(*
this);
763 inline std::vector<Tensor> Tensor::unbind(int64_t dim)
const {
764 return type().unbind(*
this, dim);
766 inline Tensor Tensor::to_sparse(int64_t sparse_dim)
const {
767 return type().to_sparse(*
this, sparse_dim);
769 inline Tensor Tensor::to_sparse()
const {
770 return type().to_sparse(*
this);
773 return type().to(*
this, options, non_blocking, copy);
775 inline Tensor Tensor::to(
Device device, ScalarType dtype,
bool non_blocking,
bool copy)
const {
776 return type().to(*
this, device, dtype, non_blocking, copy);
778 inline Tensor Tensor::to(ScalarType dtype,
bool non_blocking,
bool copy)
const {
779 return type().to(*
this, dtype, non_blocking, copy);
781 inline Tensor Tensor::to(
const Tensor & other,
bool non_blocking,
bool copy)
const {
782 return type().to(*
this, other, non_blocking, copy);
784 inline Scalar Tensor::item()
const {
785 return type().item(*
this);
787 inline void* Tensor::data_ptr()
const {
788 return type().data_ptr(*
this);
791 return type().set_(*
this, source);
794 return type().set_(*
this, source, storage_offset, size, stride);
797 return type().set_(*
this, source);
799 inline Tensor & Tensor::set_() {
800 return type().set_(*
this);
802 inline bool Tensor::is_set_to(
const Tensor & tensor)
const {
803 return type().is_set_to(*
this, tensor);
806 return type().masked_fill_(*
this, mask, value);
809 return type().masked_fill(*
this, mask, value);
812 return type().masked_fill_(*
this, mask, value);
815 return type().masked_fill(*
this, mask, value);
818 return type().masked_scatter_(*
this, mask, source);
820 inline Tensor Tensor::masked_scatter(
const Tensor & mask,
const Tensor & source)
const {
821 return type().masked_scatter(*
this, mask, source);
824 return type().view(*
this, size);
826 inline Tensor & Tensor::put_(
const Tensor & index,
const Tensor & source,
bool accumulate) {
827 return type().put_(*
this, index, source, accumulate);
829 inline Tensor & Tensor::index_add_(int64_t dim,
const Tensor & index,
const Tensor & source) {
830 return type().index_add_(*
this, dim, index, source);
832 inline Tensor Tensor::index_add(int64_t dim,
const Tensor & index,
const Tensor & source)
const {
833 return type().index_add(*
this, dim, index, source);
835 inline Tensor & Tensor::index_fill_(int64_t dim,
const Tensor & index,
Scalar value) {
836 return type().index_fill_(*
this, dim, index, value);
838 inline Tensor Tensor::index_fill(int64_t dim,
const Tensor & index,
Scalar value)
const {
839 return type().index_fill(*
this, dim, index, value);
841 inline Tensor & Tensor::index_fill_(int64_t dim,
const Tensor & index,
const Tensor & value) {
842 return type().index_fill_(*
this, dim, index, value);
844 inline Tensor Tensor::index_fill(int64_t dim,
const Tensor & index,
const Tensor & value)
const {
845 return type().index_fill(*
this, dim, index, value);
847 inline Tensor & Tensor::scatter_(int64_t dim,
const Tensor & index,
const Tensor & src) {
848 return type().scatter_(*
this, dim, index, src);
850 inline Tensor Tensor::scatter(int64_t dim,
const Tensor & index,
const Tensor & src)
const {
851 return type().scatter(*
this, dim, index, src);
854 return type().scatter_(*
this, dim, index, value);
856 inline Tensor Tensor::scatter(int64_t dim,
const Tensor & index,
Scalar value)
const {
857 return type().scatter(*
this, dim, index, value);
859 inline Tensor & Tensor::scatter_add_(int64_t dim,
const Tensor & index,
const Tensor & src) {
860 return type().scatter_add_(*
this, dim, index, src);
862 inline Tensor Tensor::scatter_add(int64_t dim,
const Tensor & index,
const Tensor & src)
const {
863 return type().scatter_add(*
this, dim, index, src);
866 return type().lt_(*
this, other);
869 return type().lt_(*
this, other);
872 return type().gt_(*
this, other);
875 return type().gt_(*
this, other);
878 return type().le_(*
this, other);
881 return type().le_(*
this, other);
884 return type().ge_(*
this, other);
887 return type().ge_(*
this, other);
890 return type().eq_(*
this, other);
893 return type().eq_(*
this, other);
896 return type().ne_(*
this, other);
899 return type().ne_(*
this, other);
902 return type().__and__(*
this, other);
904 inline Tensor Tensor::__and__(
const Tensor & other)
const {
905 return type().__and__(*
this, other);
908 return type().__iand__(*
this, other);
910 inline Tensor & Tensor::__iand__(
const Tensor & other) {
911 return type().__iand__(*
this, other);
914 return type().__or__(*
this, other);
916 inline Tensor Tensor::__or__(
const Tensor & other)
const {
917 return type().__or__(*
this, other);
920 return type().__ior__(*
this, other);
923 return type().__ior__(*
this, other);
926 return type().__xor__(*
this, other);
928 inline Tensor Tensor::__xor__(
const Tensor & other)
const {
929 return type().__xor__(*
this, other);
932 return type().__ixor__(*
this, other);
934 inline Tensor & Tensor::__ixor__(
const Tensor & other) {
935 return type().__ixor__(*
this, other);
938 return type().__lshift__(*
this, other);
940 inline Tensor Tensor::__lshift__(
const Tensor & other)
const {
941 return type().__lshift__(*
this, other);
944 return type().__ilshift__(*
this, other);
946 inline Tensor & Tensor::__ilshift__(
const Tensor & other) {
947 return type().__ilshift__(*
this, other);
950 return type().__rshift__(*
this, other);
952 inline Tensor Tensor::__rshift__(
const Tensor & other)
const {
953 return type().__rshift__(*
this, other);
956 return type().__irshift__(*
this, other);
958 inline Tensor & Tensor::__irshift__(
const Tensor & other) {
959 return type().__irshift__(*
this, other);
961 inline Tensor & Tensor::lgamma_() {
962 return type().lgamma_(*
this);
965 return type().atan2_(*
this, other);
967 inline Tensor & Tensor::tril_(int64_t diagonal) {
968 return type().tril_(*
this, diagonal);
970 inline Tensor & Tensor::triu_(int64_t diagonal) {
971 return type().triu_(*
this, diagonal);
973 inline Tensor & Tensor::digamma_() {
974 return type().digamma_(*
this);
976 inline Tensor & Tensor::polygamma_(int64_t n) {
977 return type().polygamma_(*
this, n);
979 inline Tensor & Tensor::erfinv_() {
980 return type().erfinv_(*
this);
982 inline Tensor & Tensor::frac_() {
983 return type().frac_(*
this);
986 return type().renorm_(*
this, p, dim, maxnorm);
988 inline Tensor & Tensor::reciprocal_() {
989 return type().reciprocal_(*
this);
991 inline Tensor & Tensor::neg_() {
992 return type().neg_(*
this);
995 return type().pow_(*
this, exponent);
998 return type().pow_(*
this, exponent);
1001 return type().lerp_(*
this, end, weight);
1004 return type().lerp_(*
this, end, weight);
1006 inline Tensor & Tensor::sign_() {
1007 return type().sign_(*
this);
1010 return type().fmod_(*
this, other);
1013 return type().fmod_(*
this, other);
1016 return type().remainder_(*
this, other);
1018 inline Tensor & Tensor::remainder_(
const Tensor & other) {
1019 return type().remainder_(*
this, other);
1022 return type().addbmm_(*
this, batch1, batch2, beta, alpha);
1025 return type().addbmm(*
this, batch1, batch2, beta, alpha);
1028 return type().addcmul_(*
this, tensor1, tensor2, value);
1031 return type().addcdiv_(*
this, tensor1, tensor2, value);
1033 inline Tensor & Tensor::random_(int64_t from, int64_t to,
Generator * generator) {
1034 return type().random_(*
this, from, to, generator);
1037 return type().random_(*
this, to, generator);
1040 return type().random_(*
this, generator);
1042 inline Tensor & Tensor::uniform_(
double from,
double to,
Generator * generator) {
1043 return type().uniform_(*
this, from, to, generator);
1046 return type().normal_(*
this, mean, std, generator);
1048 inline Tensor & Tensor::cauchy_(
double median,
double sigma,
Generator * generator) {
1049 return type().cauchy_(*
this, median, sigma, generator);
1051 inline Tensor & Tensor::log_normal_(
double mean,
double std,
Generator * generator) {
1052 return type().log_normal_(*
this, mean, std, generator);
1054 inline Tensor & Tensor::exponential_(
double lambd,
Generator * generator) {
1055 return type().exponential_(*
this, lambd, generator);
1058 return type().geometric_(*
this, p, generator);
1060 inline Tensor Tensor::diag(int64_t diagonal)
const {
1061 return type().diag(*
this, diagonal);
1063 inline Tensor Tensor::cross(
const Tensor & other, int64_t dim)
const {
1064 return type().cross(*
this, other, dim);
1066 inline Tensor Tensor::triu(int64_t diagonal)
const {
1067 return type().triu(*
this, diagonal);
1069 inline Tensor Tensor::tril(int64_t diagonal)
const {
1070 return type().tril(*
this, diagonal);
1072 inline Tensor Tensor::trace()
const {
1073 return type().trace(*
this);
1076 return type().ne(*
this, other);
1079 return type().ne(*
this, other);
1082 return type().eq(*
this, other);
1085 return type().eq(*
this, other);
1088 return type().ge(*
this, other);
1091 return type().ge(*
this, other);
1094 return type().le(*
this, other);
1097 return type().le(*
this, other);
1100 return type().gt(*
this, other);
1103 return type().gt(*
this, other);
1106 return type().lt(*
this, other);
1109 return type().lt(*
this, other);
1111 inline Tensor Tensor::take(
const Tensor & index)
const {
1112 return type().take(*
this, index);
1114 inline Tensor Tensor::index_select(int64_t dim,
const Tensor & index)
const {
1115 return type().index_select(*
this, dim, index);
1117 inline Tensor Tensor::masked_select(
const Tensor & mask)
const {
1118 return type().masked_select(*
this, mask);
1120 inline Tensor Tensor::nonzero()
const {
1121 return type().nonzero(*
this);
1123 inline Tensor Tensor::gather(int64_t dim,
const Tensor & index,
bool sparse_grad)
const {
1124 return type().gather(*
this, dim, index, sparse_grad);
1127 return type().addcmul(*
this, tensor1, tensor2, value);
1130 return type().addcdiv(*
this, tensor1, tensor2, value);
1132 inline std::tuple<Tensor,Tensor> Tensor::gels(
const Tensor &
A)
const {
1133 return type().gels(*
this, A);
1135 inline std::tuple<Tensor,Tensor> Tensor::trtrs(
const Tensor & A,
bool upper,
bool transpose,
bool unitriangular)
const {
1136 return type().trtrs(*
this, A, upper, transpose, unitriangular);
1138 inline std::tuple<Tensor,Tensor> Tensor::symeig(
bool eigenvectors,
bool upper)
const {
1139 return type().symeig(*
this, eigenvectors, upper);
1141 inline std::tuple<Tensor,Tensor> Tensor::eig(
bool eigenvectors)
const {
1142 return type().eig(*
this, eigenvectors);
1144 inline std::tuple<Tensor,Tensor,Tensor> Tensor::svd(
bool some,
bool compute_uv)
const {
1145 return type().svd(*
this, some, compute_uv);
1147 inline Tensor Tensor::cholesky(
bool upper)
const {
1148 return type().cholesky(*
this, upper);
1150 inline Tensor Tensor::cholesky_solve(
const Tensor & input2,
bool upper)
const {
1151 return type().cholesky_solve(*
this, input2, upper);
1153 inline std::tuple<Tensor,Tensor> Tensor::solve(
const Tensor & A)
const {
1154 return type().solve(*
this, A);
1156 inline Tensor Tensor::potri(
bool upper)
const {
1157 return type().potri(*
this, upper);
1159 inline std::tuple<Tensor,Tensor> Tensor::pstrf(
bool upper,
Scalar tol)
const {
1160 return type().pstrf(*
this, upper, tol);
1162 inline std::tuple<Tensor,Tensor> Tensor::qr()
const {
1163 return type().qr(*
this);
1165 inline std::tuple<Tensor,Tensor> Tensor::geqrf()
const {
1166 return type().geqrf(*
this);
1168 inline Tensor Tensor::orgqr(
const Tensor & input2)
const {
1169 return type().orgqr(*
this, input2);
1171 inline Tensor Tensor::ormqr(
const Tensor & input2,
const Tensor & input3,
bool left,
bool transpose)
const {
1172 return type().ormqr(*
this, input2, input3, left, transpose);
1174 inline std::tuple<Tensor,Tensor> Tensor::btrifact(
bool pivot)
const {
1175 return type().btrifact(*
this, pivot);
1177 inline std::tuple<Tensor,Tensor,Tensor> Tensor::btrifact_with_info(
bool pivot)
const {
1178 return type().btrifact_with_info(*
this, pivot);
1180 inline Tensor Tensor::btrisolve(
const Tensor & LU_data,
const Tensor & LU_pivots)
const {
1181 return type().btrisolve(*
this, LU_data, LU_pivots);
1183 inline Tensor Tensor::multinomial(int64_t num_samples,
bool replacement,
Generator * generator)
const {
1184 return type().multinomial(*
this, num_samples, replacement, generator);
1186 inline Tensor Tensor::lgamma()
const {
1187 return type().lgamma(*
this);
1189 inline Tensor Tensor::digamma()
const {
1190 return type().digamma(*
this);
1192 inline Tensor Tensor::polygamma(int64_t n)
const {
1193 return type().polygamma(n, *
this);
1195 inline Tensor Tensor::erfinv()
const {
1196 return type().erfinv(*
this);
1198 inline Tensor Tensor::frac()
const {
1199 return type().frac(*
this);
1202 return type().dist(*
this, other, p);
1204 inline Tensor Tensor::reciprocal()
const {
1205 return type().reciprocal(*
this);
1207 inline Tensor Tensor::neg()
const {
1208 return type().neg(*
this);
1210 inline Tensor Tensor::atan2(
const Tensor & other)
const {
1211 return type().atan2(*
this, other);
1214 return type().lerp(*
this, end, weight);
1217 return type().lerp(*
this, end, weight);
1220 return type().histc(*
this, bins, min, max);
1222 inline Tensor Tensor::sign()
const {
1223 return type().sign(*
this);
1226 return type().fmod(*
this, other);
1228 inline Tensor Tensor::fmod(
const Tensor & other)
const {
1229 return type().fmod(*
this, other);
1232 return type().remainder(*
this, other);
1234 inline Tensor Tensor::remainder(
const Tensor & other)
const {
1235 return type().remainder(*
this, other);
1237 inline Tensor Tensor::min(
const Tensor & other)
const {
1238 return type().min(*
this, other);
1240 inline Tensor Tensor::min()
const {
1241 return type().min(*
this);
1243 inline Tensor Tensor::max(
const Tensor & other)
const {
1244 return type().max(*
this, other);
1246 inline Tensor Tensor::max()
const {
1247 return type().max(*
this);
1249 inline Tensor Tensor::median()
const {
1250 return type().median(*
this);
1252 inline std::tuple<Tensor,Tensor> Tensor::sort(int64_t dim,
bool descending)
const {
1253 return type().sort(*
this, dim, descending);
1255 inline Tensor Tensor::argsort(int64_t dim,
bool descending)
const {
1256 return type().argsort(*
this, dim, descending);
1258 inline std::tuple<Tensor,Tensor> Tensor::topk(int64_t k, int64_t dim,
bool largest,
bool sorted)
const {
1259 return type().topk(*
this, k, dim, largest, sorted);
1261 inline Tensor Tensor::all()
const {
1262 return type().all(*
this);
1264 inline Tensor Tensor::any()
const {
1265 return type().any(*
this);
1268 return type().renorm(*
this, p, dim, maxnorm);
1270 inline Tensor Tensor::unfold(int64_t dimension, int64_t size, int64_t step)
const {
1271 return type().unfold(*
this, dimension, size, step);
1273 inline bool Tensor::equal(
const Tensor & other)
const {
1274 return type().equal(*
this, other);
1276 inline Tensor Tensor::pow(
const Tensor & exponent)
const {
1277 return type().pow(*
this, exponent);
1279 inline Tensor Tensor::alias()
const {
1280 return type().alias(*
this);
1288 return impl_->
dtype();
1292 return impl_->layout();
1296 return impl_->device();
1301 return impl_->get_device();
1305 return self.get_device();
1310 return impl_->is_cuda();
1314 return self.is_cuda();
1319 return impl_->is_hip();
1323 return self.is_hip();
1328 return impl_->is_sparse();
1332 return self.is_sparse();
1335 #define DEFINE_CAST(T, name, _) \ 1337 inline T* Tensor::data() const { \ 1339 scalar_type() == ScalarType::name, \ 1340 "expected scalar type ", \ 1343 c10::toString(scalar_type())); \ 1344 return static_cast<T*>(this->data_ptr()); \ 1347 AT_FORALL_SCALAR_TYPES_WITH_COMPLEX_EXCEPT_COMPLEX_HALF(DEFINE_CAST)
1350 #define DEFINE_ITEM(T, name, _) \ 1352 inline T Tensor::item() const { \ 1353 return item().to##name(); \ 1356 AT_FORALL_SCALAR_TYPES_WITH_COMPLEX_EXCEPT_COMPLEX_HALF(DEFINE_ITEM)
void backward(c10::optional< Tensor > gradient=c10::nullopt, bool keep_graph=false, bool create_graph=false)
Computes the gradient of current tensor w.r.t. graph leaves.
C10_NODISCARD TensorOptions device(c10::optional< Device > device) const noexcept
Return a copy of TensorOptions with device set to the given one, or cleared if device is nullopt...
bool is_variable() const
True if a tensor is a variable.
bool is_hip() const
Returns if a Tensor has HIP backend.
TensorOptions options() const
Returns the TensorOptions corresponding to this Tensor.
Scalar represents a 0-dimensional tensor which contains a single element.
const caffe2::TypeMeta & dtype() const
Returns the TypeMeta of a tensor, which describes what data type it is (e.g., int, float, ...)
int64_t get_device() const
Returns a Tensor's device index.
Layout layout() const noexcept
Returns a Tensor's layout. Defined in Type.h.
caffe2::TypeMeta dtype() const noexcept
Returns a Tensor's dtype (TypeMeta). Defined in TensorMethods.h.
Represents a a compute device on which a tensor is located.
bool is_variable() const noexcept
Returns true if the Tensor is actually a torch::autograd::Variable.
bool is_cuda() const
Returns if a Tensor has CUDA backend.
Device device() const
Returns a Tensor's device.
bool is_sparse() const
Returns if a Tensor has sparse backend.
C10_NODISCARD TensorOptions dtype(c10::optional< caffe2::TypeMeta > dtype) const noexcept
Return a copy of TensorOptions with dtype set to the given one.
C10_NODISCARD TensorOptions is_variable(c10::optional< bool > is_variable) const noexcept
Sets the is_variable property on the TensorOptions.
Flush-To-Zero and Denormals-Are-Zero mode.
C10_NODISCARD TensorOptions layout(c10::optional< Layout > layout) const noexcept
Sets the layout of the TensorOptions.