连续张量理解和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. VScode搭建OpenCV环境

    用vscode来写opencv代码需要自己编译OpenCV,主要用到MinGW-w64和CMake工具.由于可能存在的版本兼容问题,下载这些工具前最好先访问网站: https://github.com ...

  2. Treap总结

    \(Treap = Tree + Heap\) 树堆(Treap),在数据结构中也称Treap,是指有一个随机附加域满足堆的性质的二叉搜索树,其结构相当于以随机数据插入的二叉搜索树.其基本操作的期望时 ...

  3. 9.16java总结

    枚举   EnunTest.java 运行结果 falsefalsetrueSMALLMEDIUMLARGE 枚举类型可以直接用==来判断是否相等,即代表数据串,又有数的属性.是引用类型. 浮点数计算 ...

  4. 安装PHP到Ubuntu(APT)

    运行环境 系统版本:Ubuntu 16.04.2 LTS 软件版本:PHP-5.6 硬件要求:无 安装过程 1.安装APT存储库 APT存储库由PPA提供. root@localhost:~# apt ...

  5. Android8.0自定义广播接收不到问题

    https://blog.csdn.net/kongqwesd12/article/details/78998151

  6. HTTP Status 404 – 未找到 spring mvc

    HTTP Status 404 – 未找到 Type Status Report 消息 /houseSale//houseSaleController/houseSaleList 描述 源服务器未能找 ...

  7. Qt文件发布

    1.打开Qt文件夹下的,其他版本可能为Qt (版本号)for Desktop cmd 2.将Release文件下的exe文件复制到别的文件夹,我这里为G:\Qt\QT_project\ff 3.在Qt ...

  8. Java商城秒杀系统的设计与实战视频教程(SpringBoot版)

    课程目标掌握如何基于Spring Boot构建秒杀系统或者高并发业务系统,以及构建系统时采用的前后端技术栈适用人群Spring Boot实战者,微服务或分布式系统架构实战者,秒杀系统和高并发实战者,中 ...

  9. 2-1.了解Pod对象

    1.Pod参数定义 # 必填,版本号 apiVersion: string kind: Pod # 必填,元数据 metadata: # 必填,Pod对象的名称(命名规范需要符合RFC 1035规范) ...

  10. Spark kafka flume

    Flume Flume 是一个分布式.可靠.和高可用的海量日志聚合的系统,支持在系统中定制各类数据发送方,通过监控整个文件目录或者某一个特定文件,用于收集数据:同时Flume也 提供数据写到各种数据接 ...