ttensor.nim 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. discard """
  2. output: '''
  3. before tensor2:
  4. [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0]
  5. before tensor3:
  6. [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0]
  7. after tensor3:
  8. [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0]
  9. a3:
  10. [1000.0, 1001.0, 1002.0, 1003.0, 1004.0, 1005.0, 1006.0, 1007.0, 1008.0, 1009.0, 1010.0, 1011.0, 1012.0, 1013.0, 1014.0, 1015.0, 1016.0, 1017.0, 1018.0, 1019.0, 1020.0, 1021.0, 1022.0, 1023.0, 1024.0, 1025.0, 1026.0]'''
  11. """
  12. import macros
  13. type
  14. Tensor[Dim : static[int]] = object
  15. data: array[Dim, float64]
  16. proc transpose(tensor: Tensor): Tensor =
  17. # fake implementation, don't transpose anything at all
  18. # just do something to see a change happening
  19. for i in 0 ..< tensor.data.len:
  20. result.data[i] = 1000 + tensor.data[i]
  21. var tensor2: Tensor[24]
  22. var tensor3: Tensor[27]
  23. for i, x in tensor2.data.mpairs():
  24. x = float64(i)
  25. for i, x in tensor3.data.mpairs():
  26. x = float64(i)
  27. echo "before tensor2:\n", tensor2.data.repr
  28. echo "before tensor3:\n", tensor3.data.repr
  29. var a3 = transpose(tensor3)
  30. echo "after tensor3:\n", tensor3.data.repr
  31. echo "a3:\n", a3.data.repr