连续张量理解和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 ...
随机推荐
- MySQL概述及入门(一)
MySql概述及入门(一) 什么是MySQL? MySQL是当今主流的关系型数据库管理系统(记录是有行有列的数据库) , 可以与Oracle 和SQL Server 竞争 , 是最好RDBMS( ...
- dsu on tree[树上启发式合并学习笔记]
dsu on tree 本质上是一个 启发式合并 复杂度 \(O(n\log n)\) 不支持修改 只能支持子树统计 不能支持链上统计- 先跑一遍树剖的dfs1 搞出来轻重儿子- 求每个节点的子树上有 ...
- 网络流最大流——dinic算法
前言 网络流问题是一个很深奥的问题,对应也有许多很优秀的算法.但是本文只会讲述dinic算法 最近写了好多网络流的题目,想想看还是写一篇来总结一下网络流和dinic算法以免以后自己忘了... 网络流问 ...
- Windows配置JDK环境
在系统变量里新建JAVA_HOME变量,变量值为:D:\Program Files\Java\jdk1.8.0_161(根据自己的安装路径填写) 在系统变量里新建classpath变量,变量值为:;% ...
- Elasticsearch启动、停止脚本
注:本文出自博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 本文源链接:https://www.cnblogs.com/chloneda/p/es-shell ...
- P1341 当然是选择AC它了!(字符串处理)
A. 当然是选择AC它了! 题目描述 听闻第八届程序设计大赛马上就要开始了,已经报名的童鞋们都纷纷去 OJ 刷题.但你的女朋友 (tan90°) 想知道她写的 "A + B 问题" ...
- 怎么解决MySQL密码问题
mysql 如何设置远程连接 听语音 原创 | 浏览:2726 | 更新:2019-01-22 17:32 1 2 3 4 5 6 7 分步阅读 mysql默认是不允许被远程连接的,只有本地机器才能连 ...
- win10c盘被下满文件解决办法
今天更新系统,发现一个巨坑,好不容易软件配置的环境,开始以为是病毒,重装后在弄发现还是这个问题.经过两天的亲测解决办法: win7 svchost.exe占用内存和CPU很高,电脑很卡的解决方法:ht ...
- C++常见编译问题记录
1.类名重复问题 在同一个项目下,分文件编译时,所有的文件最后会被编译到一个可执行程序或dll中,所以同一个项目下文件中不能出现两个相同的类名,否则编译器无法区分使用的到底是那个类,就会出现LINK2 ...
- HTML-入门
HTML——超文本标记语言(Hyper Text Markup Language)html——W3C制定的标准超文本——除了文本,还有图片.视频.音频等丰富的元素标记(标签)——用来展示内容表型:标签 ...