tensor.praat 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. writeInfoLine: "vectors and matrices..."
  2. a# = zero#(16)
  3. a#[3] = 4
  4. assert a#[3] = 4
  5. asserterror Vector b# does not exist.
  6. b# [5] = 3
  7. asserterror A vector index cannot be less than 1 (the index you supplied is 0).
  8. a# [0] = 932875289
  9. asserterror A vector index cannot be greater than the number of elements (here 16). The index you supplied is 20.
  10. a# [20] = 45786457
  11. assert numberOfRows (zero## (5, 6)) = 5
  12. assert numberOfColumns (zero## (5, 6)) = 6
  13. a## = zero## (5, 6)
  14. assert numberOfRows (a##) = 5
  15. assert a## [3, 4] = 0
  16. a## [5, 6] = 567
  17. assert a##[5,6] = 567
  18. c# = linear# (0, 100, 101)
  19. assert c# [98] = 97
  20. c# = linear# (0, 100, 101, 0)
  21. assert c# [98] = 97
  22. c# = linear# (0, 100, 100, 1)
  23. assert c# [98] = 97.5
  24. d# = randomGauss# (c#, 20, 1)
  25. a = d# [98]
  26. b = d# [99]
  27. c = d# [100]
  28. appendInfoLine: a, " ", b, " ", c
  29. d# = randomUniform# (c#, 7, 10)
  30. a = d# [98]
  31. b = d# [99]
  32. c = d# [100]
  33. appendInfoLine: a, " ", b, " ", c
  34. d# = randomInteger# (c#, 7, 10)
  35. a = d# [98]
  36. b = d# [99]
  37. c = d# [100]
  38. appendInfoLine: a, " ", b, " ", c
  39. e# = a# + a#
  40. assert e# [3] = 8
  41. asserterror numbers of elements should be equal
  42. e# = a# + d#
  43. ; q### =
  44. ; data####
  45. ;e# = d# + c#
  46. ;speaker$# = empty$# [2]
  47. ;speaker$# [1] = "JM"
  48. ;speaker$# [2] = "PB"
  49. ;speaker$ [1] = "JM"
  50. ;speaker$ [2] = "PB"
  51. #
  52. # outer##
  53. #
  54. n# = zero# (100)
  55. x# = randomInteger# (n#, 1, 1e7)
  56. y# = randomInteger# (n#, 1, 1e7)
  57. mat## = outer## (x#, y#)
  58. for row to 100
  59. for col to 100
  60. assert mat## [row, col] = x# [row] * y# [col]
  61. endfor
  62. endfor
  63. squares# = { 1, 4, 9, 16, 25 }
  64. assert sum (squares#) = 55
  65. assert mean (squares#) = 11
  66. assert abs (mean (squares#) - sum (squares#) / 5) < 1e-14
  67. assert abs (stdev (squares#) - 9.669539802906858) < 1e-14
  68. assert abs (stdev (squares#) - sqrt (sumOver (i to 5, (squares# [i] - mean (squares#)) ^ 2) / 4)) < 1e-14
  69. assert abs (center (squares#) - 4.090909090909091) < 1e-14
  70. assert abs (center (squares#) - sumOver (i to 5, i * squares# [i]) / sum (squares#)) < 1e-14
  71. other# = { 2, 1.5, 1, 0.5, 0 }
  72. assert inner (squares#, other#) = 25
  73. assert sumOver (i to 5, squares# [i] * other# [i]) = 25
  74. combi## = { squares#, other# }
  75. assert combi## = { { 1, 4, 9, 16, 25 }, { 2, 1.5, 1, 0.5, 0 } }
  76. a# = squares# + 5
  77. assert a# = { 6, 9, 14, 21, 30 }
  78. b# = a# + { 3.14, 2.72, 3.16, -1, 7.5 }
  79. assert b# = { 9.14, 11.72, 17.16, 20, 37.5 }
  80. c# = b# / 2
  81. appendInfoLine: c#
  82. assert c# = { 4.57, 5.86, 8.58, 10, 18.75 }
  83. d# = b# * c#
  84. norm = norm (d# - { 41.7698, 68.6792, 147.2328, 200, 703.125 })
  85. assert norm < 1e-13 ; 'norm'
  86. stopwatch
  87. iterations = 1e5
  88. for i to iterations
  89. a = 10+5
  90. a = 10+5
  91. a = 10+5
  92. a = 10+5
  93. a = 10+5
  94. a = 10+5
  95. a = 10+5
  96. a = 10+5
  97. a = 10+5
  98. a = 10+5
  99. endfor
  100. t = stopwatch / 10 * 1e9 / iterations
  101. appendInfoLine: t, " ns"
  102. stopwatch
  103. a# = { 4, 9, 16 }
  104. b# = { 25, 36, 49 }
  105. iterations = 1e5
  106. for i to iterations
  107. c# = a# - b#
  108. c# = a# - b#
  109. c# = a# - b#
  110. c# = a# - b#
  111. c# = a# - b#
  112. c# = a# - b#
  113. c# = a# - b#
  114. c# = a# - b#
  115. c# = a# - b#
  116. c# = a# - b#
  117. endfor
  118. t = stopwatch / 10 * 1e9 / iterations / 3
  119. appendInfoLine: t, " ns"
  120. stopwatch
  121. n = 100
  122. z# = zero# (n)
  123. a# = randomGauss# (z#, 0, 1)
  124. b# = randomGauss# (z#, 0, 1)
  125. iterations = 1e4
  126. for i to iterations
  127. m## = outer## (a#, b#)
  128. m## = outer## (a#, b#)
  129. m## = outer## (a#, b#)
  130. m## = outer## (a#, b#)
  131. m## = outer## (a#, b#)
  132. m## = outer## (a#, b#)
  133. m## = outer## (a#, b#)
  134. m## = outer## (a#, b#)
  135. m## = outer## (a#, b#)
  136. m## = outer## (a#, b#)
  137. endfor
  138. t = stopwatch / 10 * 1e9 / iterations / n^2
  139. appendInfoLine: t, " ns"
  140. appendInfoLine: "OK"