tl. diag function supports main diagonal only with Tensorflow backend
Describe the bug
Tensorly diag function has an input k to select diagonal. However, this option doesn't work properly with Tensorflow backend.
Steps or Code to Reproduce
Selected vector is always being on the main diagonal. For instance:
tl.diag([1,1,1], 1)
array([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]], dtype=int32)>
Same function with tensorflow gives an expected output:
tf.linalg.diag([1,1,1], k=1)
array([[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1],
[0, 0, 0, 0]], dtype=int32)>
Most probably, reason is the place of k in the Tensorflow function. But I couldn't find how to fix it in Tensorly.
I think the problem is the use of tf.linalg.tensor_diag instead of tf.linalg.diag in tensorly. The former only supports the main diagonal. So I guess an easy fix would be to change this in:
https://github.com/tensorly/tensorly/blob/10d0babc24ceb689ad59b19d2a794ebd8bbf10f8/tensorly/backend/tensorflow_backend.py#L175
Tkanks @merajhashemi . I submitted a PR #321 to solve this issue.