当前位置:网站首页>Pytorch之contiguous函数
Pytorch之contiguous函数
2022-06-22 03:53:00 【子燕若水】
1 先看看官方中英文doc:
torch.Tensor.contiguous (Python method, in torch.Tensor)
torch.Tensor.is_contiguous (Python method, in torch.Tensor)1.1 contiguous() → Tensor
Returns a contiguous tensor containing the same data as self tensor. If self tensor is contiguous, this function returns the self tensor.1.2 contiguous() → Tensor
返回一个内存连续的有相同数据的tensor,如果原tensor内存连续,则返回原tensor;2 pytorch contiguous的使用
contiguous一般与transpose,permute,view搭配使用:使用transpose或permute进行维度变换后,调用contiguous,然后方可使用view对维度进行变形(如:tensor_var.contiguous().view() )
具体原因有两种说法:
1 transpose、permute等维度变换操作后,tensor在内存中不再是连续存储的,而view操作要求tensor的内存连续存储,所以需要contiguous来返回一个contiguous copy;
2 维度变换后的变量是之前变量的浅拷贝,指向同一区域,即view操作会连带原来的变量一同变形,这是不合法的,所以也会报错;---- 这个解释有部分道理,也即contiguous返回了tensor的深拷贝contiguous copy数据;
边栏推荐
- read stream 特别注意
- CentOS uses composer install to report an error - phpunitphppunit 8
- Huffman tree
- Beifu TwinCAT 3 cylinder action program compilation
- Es next new features
- How to implement dart asynchrony
- Code of ultrasonic rangefinder based on 51 (screenshot version)
- Use of markdown markup language
- Dart异步是怎麼實現
- PHP connection to mysql8.0 reports an error: illuminate\database\queryexception
猜你喜欢

Clue binary tree

冒泡排序
![SSM based blog system [with background management]](/img/6b/6a488f5d6926de07c8b1b365362ff6.png)
SSM based blog system [with background management]

System vulnerability exploitation and right raising

Flutter-状态管理

Online text batch inversion by line tool

Convenient and easy to master, vivo intelligent remote control function realizes the control of household appliances in the whole house

Comment dart asynchrone est implémenté

Is the first woman coming to the 3A mobile game? Recognized by IGN, can "in shining name" stand out from the encirclement

快速掌握 ASP.NET 身份认证框架 Identity - 用户注册
随机推荐
Beifu twincat3 ads error query list
Larave database backup scheduled task
Key program of TwinCAT 3 RS232 communication
Existing requirements synchronize other database user information to our system. Their primary key ID is string and our primary key is long
希尔排序
Convenient and easy to master, vivo intelligent remote control function realizes the control of household appliances in the whole house
首個女性向3A手遊要來了?獲IGN認可,《以閃亮之名》能否突出重圍
Code of ultrasonic rangefinder based on 51 (screenshot version)
fastadmin列表多图预览(放大预览,轮播)一行代码
Shell Sort
Flutter performance optimization
图的基本概念
PHP connection to mysql8.0 reports an error: illuminate\database\queryexception
Seven thousand word explanation of Alibaba cloud's new generation cloud computing architecture cipu
Wechat applet uploading seven cattle cloud laravel
冒泡排序
Ora-48132 ora-48170 appears in the alarm log
Dart异步是怎麼實現
La première femme vient à 3A? Est - ce que Bright name, approuvé par IGN, peut mettre en évidence le classement
Solend闹剧背后的「DeFi道德悖论」