连续张量理解和contiguous()方法使用,view和reshape的区别
连续张量理解和contiguous()方法使用,view和reshape的区别
待办
内存共享:
下边的x内存布局是从0开始的,y内存布局,不是从0开始的张量
For example: when you call transpose(), PyTorch doesn't generate new tensor with new layout, it just modifies meta information in Tensor object so offset and stride are for new shape. The transposed tensor and original tensor are indeed sharing the memory!
^[
> x = torch.randn(3,2) y = torch.transpose(x, 0, 1) x[0, 0] = 42
> print(y[0,0])
> # prints 42
]
This is where the concept of contiguous comes in. Above x is contiguous but y is not because its memory layout is different than a tensor of same shape made from scratch. Note that the word "contiguous" is bit misleading because its not that the content of tensor is spread out around disconnected blocks of memory. Here bytes are still allocated in one block of memory but the order of the elements is different!
When you call contiguous(), it actually makes a copy of tensor so the order of elements would be same as if tensor of same shape created from scratch.
Normally you don't need to worry about this. If PyTorch expects contiguous tensor but if its not then you will get RuntimeError: input is not contiguous and then you just add a call to contiguous()
view 和 reshape 的区别
Another difference is that reshape() can operate on both contiguous
and non-contiguous tensor while view() can only operate on contiguous
tensor. Also see here about the meaning of contiguous.
如果出现不是连续张量的问题,解决方案
Another difference is that reshape() can operate on both contiguous
and non-contiguous tensor while view() can only operate on contiguous
tensor. Also see here about the meaning of contiguous.
连续张量理解和contiguous()方法使用,view和reshape的区别的更多相关文章
- (MTT)连续能量函数最小化方法
(MTT)连续能量函数最小化方法 Multitarget tracking Multi-object tracking 连续能量函数 读"A.Milan,S. Roth, K. Schind ...
- js中的回调函数的理解和使用方法
js中的回调函数的理解和使用方法 一. 回调函数的作用 js代码会至上而下一条线执行下去,但是有时候我们需要等到一个操作结束之后再进行下一个操作,这时候就需要用到回调函数. 二. 回调函数的解释 因为 ...
- 【JVM虚拟机】(8)--深入理解Class中--方法、属性表集合
#[JVM虚拟机](8)--深入理解Class中--方法.属性表集合 之前有关class文件已经写了两篇博客: 1.[JVM虚拟机](5)---深入理解JVM-Class中常量池 2.[JVM虚拟机] ...
- 理解 ES6 Generator-next()方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【读书笔记《Android游戏编程之从零开始》】11.游戏开发基础(SurfaceView 游戏框架、View 和 SurfaceView 的区别)
1. SurfaceView 游戏框架实例 实例效果:就是屏幕上的文本跟着点击的地方移动,效果图如下: 步骤: 新建项目“GameSurfaceView”,首先自定义一个类"MySurfac ...
- View和ViewGroup的区别 -- Touch事件处理
View.java源码: /frameworks/base/core/java/android/view/View.java View.java的 dispatchTouchEvent 方法: 经过一 ...
- 从tcp原理角度理解Broken pipe和Connection reset by peer的区别
从tcp原理角度理解Broken pipe和Connection reset by peer的区别 http://lovestblog.cn/blog/2014/05/20/tcp-broken-pi ...
- Android界面的View以及ViewGroup的区别
因为这个问题会经常成为面试的热点,所以我们来谈谈View以及ViewGroup的区别. 先看看View及ViewGroup类关系 Android View和ViewGroup从组成架构上看,似乎 ...
- Python join() 方法与os.path.join()的区别
Python join() 方法与os.path.join()的区别 pythonJoinos.path.join 今天工作中用到python的join方法,有点分不太清楚join() 方法与os.p ...
随机推荐
- <packaging>pom</packaging>是什么意思
<packaging>pom</packaging>是什么意思? 答: 以下配置<packaging>pom</packaging>的意思是使用mave ...
- 逻辑卷管理(LVM)-快照
1.需要在逻辑卷相同的卷组中创建逻辑卷快照.-s :表示快照 -p r:表示只读 /dev/vg0/mysql 为那个卷的快照 2.查看快照卷信息. 3.快照恢复,必须先取消挂载,还原成功之后,快 ...
- MyBatis中foreach循环的用法
一.在了解foreach之前,先了解一下mybatis传入参数及parameterType 1.我们在Dao层向对应的mapper.xml文件传递参数时,可以传递的参数有: ①.基本数据类型(如int ...
- python数据类型(第三弹)
本文着重介绍python语言的两种数据类型——列表和元组 列表 相比于整型.浮点型等数据类型,列表是一个复合数据类型,它更像一个容器,可以容纳多种不同类型的数据. 如上图:列表a中装进去了字符串&qu ...
- Umi 小白纪实(一)—— 创建项目&常用配置
umi 是一个企业级 react 应用框架,也是蚂蚁金服的底层前端框架 <蚂蚁金服的前端框架和工程化实践> 一.安装脚手架 在创建项目之前,需要保证有 node 8.10 以上的环境 可以 ...
- 怎样在GitHub上新建一个文件夹
GitHub如何创建文件夹 创建新文件的时候名字后面加个斜杠(/)就可以了 点击新建文件,输入文件名的时候后面加上斜杠/就是创建了一个文件夹,没有斜杠就是创建了一个文 创建好后点提交 Commit n ...
- 谷歌更新后,chromedriver如何更换新版本
前天,更新了78版本的谷歌后,chromedriver便不能用了,于是在ChromeDriver仓库下载了相对应版本的chromedriver. 并且放入谷歌文件下C:\Program Files ( ...
- Java设计模式(四)工厂方法模式
定义与类型 定义:定义一个创建对象的接口,但让实现这个接口的类来决定实例化哪个类,工厂方法让类的实例化推迟到子类中进行. 类型:创建型 适用场景 创建对象需要大量重复的代码 客户端(应用层)不依赖于产 ...
- IntelliJ IDEA 如何彻底删除项目的步骤
原文参考链接:https://www.jb51.net/article/129473.htm 本文介绍了IntelliJ IDEA 如何彻底删除项目的步骤,分享给大家,顺便给自己留个笔记,具体如下: ...
- LeetCode 237. 删除链表中的节点 (单链表遍历)
题目链接:https://leetcode-cn.com/problems/delete-node-in-a-linked-list/ 请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点,你将 ...