1

In PyTorch, people usually call tensor.permute(2,0,1,3).contiguous(). If I call this function in tensorflow 2.0, is it enough to just call tf.reshape(tensor, perm = [2, 0, 1, 3])?

or what is a contiguous function in tensorflow 2.0?

Innat
  • 16,113
  • 6
  • 53
  • 101
alryosha
  • 641
  • 1
  • 8
  • 15
  • You stated a potential solution (`tf.reshape..`). So, haven't you tried it already? If so, what's the issue (error or reliability)? – Innat Jan 17 '22 at 07:41
  • There is no issue, but I don't know whether the memory of tensor become contiguous or not. Therefore, I want to explicitly make tensor contiguous, but I can't find contiguous function in Tensorflow. – alryosha Jan 19 '22 at 11:28
  • 1
    Can you go through this question and conversation? https://stackoverflow.com/q/53398721/9215780 – Innat Jan 19 '22 at 14:07

1 Answers1

2

From the official docs of tf.transpose,

In NumPy, transposes are memory-efficient constant time operations as they simply return a new view of the same data with adjusted strides. TensorFlow does not support strides, so transpose returns a new tensor with the items permuted.

Also, TensorFlow doesn't seem to support Fortran (Column-Major) ordering. Hence, I think we automatically get Contiguous (Row-Major) ordering tensor.

Awsaf
  • 66
  • 5