Advertisement

在编写Torch代码的过程中可能会遇到的问题

阅读量:

总说

写Lua时经常会碰到一些坑,随手记录,防止一坑不起。2017.2.20第四次更新。

Tensor

Tensor的小问题

  • 获取某一维长度
    当然可以用x:size(dim), 或是(#x)[dim]

  • #x所获得的是张量x维度大小对应的张量。这并非数量类型的张量。在for循环中操作时,请注意如果遇到单维度张量的情况,则应当这样书写代码结构。

复制代码
    for 1,(#x)[1] do
    ...
    end

如果x是table的话,那么直接这样写

复制代码
    for 1,#tl do
    ...
    end
  • clones play a vital role in ensuring the integrity of tensor assignments.
    whenever a tensor is assigned, it's advisable to include a clone() to prevent unintended references; otherwise, the assignment defaults to a reference.
    torch optimizes performance by defaulting to references unle

全部评论 (0)

还没有任何评论哟~