SciNim / flambeau

Nim bindings to libtorch
85 stars 3 forks source link

Comparing Tensor of different type segfault #19

Closed Clonkk closed 3 years ago

Clonkk commented 3 years ago

Tensor comparaison cause segfault :

      let shape = [2'i64, 3]
      let t = zeros(shape.asTorchView(), kFloat32)
      check t == [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]].toTensor

This is caused by toTensor creating "implicitly" a float64 Tensor.

This can be solved by :

      let shape = [2'i64, 3]
      let t = zeros(shape.asTorchView(), kFloat32)
      check t == [[0.0'f32, 0.0, 0.0], [0.0'f32, 0.0, 0.0]].toTensor

Can be reproduced with equal function.

==, equal operator should check for Tensor type and potentially raise an exception (?) to avoid crashing the program. This can be solved with generic Tensor type ;)

Clonkk commented 3 years ago

By construction of the higher level API Tensor[T], only the low-level bindings have this issue, si this will be marked as a won't fix.