连续张量理解和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的区别的更多相关文章

  1. (MTT)连续能量函数最小化方法

    (MTT)连续能量函数最小化方法 Multitarget tracking Multi-object tracking 连续能量函数 读"A.Milan,S. Roth, K. Schind ...

  2. js中的回调函数的理解和使用方法

    js中的回调函数的理解和使用方法 一. 回调函数的作用 js代码会至上而下一条线执行下去,但是有时候我们需要等到一个操作结束之后再进行下一个操作,这时候就需要用到回调函数. 二. 回调函数的解释 因为 ...

  3. 【JVM虚拟机】(8)--深入理解Class中--方法、属性表集合

    #[JVM虚拟机](8)--深入理解Class中--方法.属性表集合 之前有关class文件已经写了两篇博客: 1.[JVM虚拟机](5)---深入理解JVM-Class中常量池 2.[JVM虚拟机] ...

  4. 理解 ES6 Generator-next()方法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 【读书笔记《Android游戏编程之从零开始》】11.游戏开发基础(SurfaceView 游戏框架、View 和 SurfaceView 的区别)

    1. SurfaceView 游戏框架实例 实例效果:就是屏幕上的文本跟着点击的地方移动,效果图如下: 步骤: 新建项目“GameSurfaceView”,首先自定义一个类"MySurfac ...

  6. View和ViewGroup的区别 -- Touch事件处理

    View.java源码: /frameworks/base/core/java/android/view/View.java View.java的 dispatchTouchEvent 方法: 经过一 ...

  7. 从tcp原理角度理解Broken pipe和Connection reset by peer的区别

    从tcp原理角度理解Broken pipe和Connection reset by peer的区别 http://lovestblog.cn/blog/2014/05/20/tcp-broken-pi ...

  8. Android界面的View以及ViewGroup的区别

    因为这个问题会经常成为面试的热点,所以我们来谈谈View以及ViewGroup的区别. 先看看View及ViewGroup类关系    Android View和ViewGroup从组成架构上看,似乎 ...

  9. Python join() 方法与os.path.join()的区别

    Python join() 方法与os.path.join()的区别 pythonJoinos.path.join 今天工作中用到python的join方法,有点分不太清楚join() 方法与os.p ...

随机推荐

  1. fatal: HttpRequestException encountered

    报错:fatal: HttpRequestException encountered 解决方法 Github 禁用了TLS v1.0 and v1.1,必须更新Windows的git凭证管理器,才行. ...

  2. LeetCode 面试题 02.07. 链表相交

    题目链接:https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci/ 给定两个(单向)链表,判定它们是否相交并返回交 ...

  3. python——面向对象(1),基础

    """面向对象:抽象化编程思想.类,对象:用类来创建(实例化)对象.类:一系列特征和行为相同的事物总和, 1.属性:特征 2.行为:方法 定义类 :PEP 8要求标识符的 ...

  4. Jstree在加载时和加载完成的回调方法-sunziren

    1.有时候在使用jstree的时候我们想在它加载完成后立刻执行某个方法,于是我们可以用下面这个jstree自带的回调: .on('ready.jstree', function(event, obj) ...

  5. libgdiplus安装配置

    1.下载安装包:wget http://download.mono-project.com/sources/libgdiplus/libgdiplus0-6.0.4.tar.gz2.解压缩.编译安装 ...

  6. 吴裕雄--天生自然HADOOP操作实验学习笔记:hdfs分布式文件系统安装

    实验目的 复习安装jdk 学习免密码登录 掌握安装配置hdfs集群的方法 掌握hdfs集群的简单使用和检查其工作状态 实验原理 1.hdfs是什么 hadoop安装的第一部分是安装hdfs,hdfs是 ...

  7. MySQL优化(四)——读写分离

    1.MySQL高可用        主从复制      一主多备      多主多备        读写分离      减少IO开销,防止阻塞等等 2.主从复制参考 https://www.cnblo ...

  8. Laravel框架中通过EasyWeChat发送公众号模板消息

    环境要求 PHP >= 7.0 PHP cURL 扩展 PHP OpenSSL 扩展 PHP SimpleXML 扩展 PHP fileinfo 拓展 使用composer安装: $ compo ...

  9. 获取redis实例中最大的top-N key

    需求:获取redis实例中最大的top-N key 说明:由于redis 4.x才引入了memory usage keyname的语法.3.x不支持! db_ip=5.5.5.101 db_port= ...

  10. vue的$nextTick

    https://segmentfault.com/a/1190000012861862 简单来说:如果你修改了某个dom中的数据,视图并不会立即更新.Vue 实现响应式并不是数据发生变化之后 DOM ...