k2-fsa / k2

FSA/FST algorithms, differentiable, with PyTorch compatibility.
https://k2-fsa.github.io/k2
Apache License 2.0
1.11k stars 213 forks source link

fix ragged_ops.cu StackAxis0 ans.rowids #1157

Closed zh794390558 closed 1 year ago

zh794390558 commented 1 year ago

使用引用,否则ans.RowIds(axis)没有被设置?

csukuangfj commented 1 year ago

加不加引用,都可以。

原因如下:

  1. Array1 核心成员是 https://github.com/k2-fsa/k2/blob/9426c9f730820d291f5dcb06be337662595fa7b4/k2/csrc/array.h#L493

  2. RegionPtr 是一个 shared_ptr

  3. Array1 之间,可以直接 copy, 它们共享一个 RegionPtr https://github.com/k2-fsa/k2/blob/9426c9f730820d291f5dcb06be337662595fa7b4/k2/csrc/array.h#L454

  4. 我们最终想要修改的,是一片内存,即 RegionPtr 指向的东西。

  5. 所以,是不是引用,都可以

zh794390558 commented 1 year ago

明白,是浅拷贝。多谢。