UnaryF32.cpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. #include "UnaryF32.h"
  2. #include "Error.h"
  3. /* Upper bound of maximum matrix dimension used by Python */
  4. #define MAXMATRIXDIM 40
  5. /*
  6. Offset in input test pattern for matrix of dimension d * d.
  7. Must be coherent with Python script Matrix.py
  8. */
  9. static int cholesky_offset(int d)
  10. {
  11. int offset=14;
  12. switch (d)
  13. {
  14. case 4:
  15. offset = 14;
  16. break;
  17. case 8:
  18. offset = 79;
  19. break;
  20. case 9:
  21. offset = 143;
  22. break;
  23. case 15:
  24. offset = 224;
  25. break;
  26. case 16:
  27. offset = 449;
  28. break;
  29. default:
  30. offset = 14;
  31. break;
  32. }
  33. return(offset);
  34. }
  35. void UnaryF32::test_mat_scale_f32()
  36. {
  37. arm_mat_scale_f32(&this->in1,0.5,&this->out);
  38. }
  39. void UnaryF32::test_mat_inverse_f32()
  40. {
  41. arm_mat_inverse_f32(&this->in1,&this->out);
  42. }
  43. void UnaryF32::test_mat_trans_f32()
  44. {
  45. arm_mat_trans_f32(&this->in1,&this->out);
  46. }
  47. void UnaryF32::test_mat_cmplx_trans_f32()
  48. {
  49. arm_mat_cmplx_trans_f32(&this->in1,&this->out);
  50. }
  51. void UnaryF32::test_mat_add_f32()
  52. {
  53. arm_mat_add_f32(&this->in1,&this->in1,&this->out);
  54. }
  55. void UnaryF32::test_mat_sub_f32()
  56. {
  57. arm_mat_sub_f32(&this->in1,&this->in1,&this->out);
  58. }
  59. void UnaryF32::test_mat_vec_mult_f32()
  60. {
  61. arm_mat_vec_mult_f32(&this->in1, vecp, outp);
  62. }
  63. void UnaryF32::test_mat_cholesky_dpo_f32()
  64. {
  65. arm_mat_cholesky_f32(&this->in1,&this->out);
  66. }
  67. void UnaryF32::test_solve_upper_triangular_f32()
  68. {
  69. arm_mat_solve_upper_triangular_f32(&this->in1,&this->in2,&this->out);
  70. }
  71. void UnaryF32::test_solve_lower_triangular_f32()
  72. {
  73. arm_mat_solve_lower_triangular_f32(&this->in1,&this->in2,&this->out);
  74. }
  75. void UnaryF32::test_ldlt_decomposition_f32()
  76. {
  77. arm_mat_ldlt_f32(&this->in1,&this->outll,&this->outd,(uint16_t*)outp);
  78. }
  79. void UnaryF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  80. {
  81. std::vector<Testing::param_t>::iterator it = params.begin();
  82. this->nbr = *it++;
  83. this->nbc = *it;
  84. switch(id)
  85. {
  86. case TEST_MAT_VEC_MULT_F32_6:
  87. input1.reload(UnaryF32::INPUTA_F32_ID,mgr,this->nbr*this->nbc);
  88. vec.reload(UnaryF32::INPUTVEC1_F32_ID,mgr,this->nbc);
  89. output.create(this->nbr,UnaryF32::OUT_F32_ID,mgr);
  90. vecp=vec.ptr();
  91. outp=output.ptr();
  92. this->in1.numRows = this->nbr;
  93. this->in1.numCols = this->nbc;
  94. this->in1.pData = input1.ptr();
  95. break;
  96. case TEST_MAT_TRANS_F32_3:
  97. input1.reload(UnaryF32::INPUTA_F32_ID,mgr,this->nbr*this->nbc);
  98. output.create(this->nbr*this->nbc,UnaryF32::OUT_F32_ID,mgr);
  99. this->out.numRows = this->nbc;
  100. this->out.numCols = this->nbr;
  101. this->out.pData = output.ptr();
  102. this->in1.numRows = this->nbr;
  103. this->in1.numCols = this->nbc;
  104. this->in1.pData = input1.ptr();
  105. break;
  106. case TEST_MAT_CMPLX_TRANS_F32_7:
  107. input1.reload(UnaryF32::INPUTAC_F32_ID,mgr,2*this->nbr*this->nbc);
  108. output.create(2*this->nbr*this->nbc,UnaryF32::OUT_F32_ID,mgr);
  109. this->out.numRows = this->nbc;
  110. this->out.numCols = this->nbr;
  111. this->out.pData = output.ptr();
  112. this->in1.numRows = this->nbr;
  113. this->in1.numCols = this->nbc;
  114. this->in1.pData = input1.ptr();
  115. break;
  116. case TEST_MAT_CHOLESKY_DPO_F32_8:
  117. {
  118. int offset=14;
  119. float32_t *p;
  120. float32_t *aPtr;
  121. input1.reload(UnaryF32::INPUTSCHOLESKY1_DPO_F32_ID,mgr);
  122. output.create(this->nbc * this->nbr,UnaryF32::OUT_F32_ID,mgr);
  123. a.create(this->nbr*this->nbc,UnaryF32::TMPA_F32_ID,mgr);
  124. /* Offsets must be coherent with the sizes used in python script
  125. Matrix.py for pattern generation */
  126. offset=cholesky_offset(this->nbr);
  127. p = input1.ptr();
  128. aPtr = a.ptr();
  129. memcpy(aPtr,p + offset,sizeof(float32_t)*this->nbr*this->nbr);
  130. this->out.numRows = this->nbr;
  131. this->out.numCols = this->nbc;
  132. this->out.pData = output.ptr();
  133. this->in1.numRows = this->nbr;
  134. this->in1.numCols = this->nbc;
  135. this->in1.pData = aPtr;
  136. }
  137. break;
  138. case TEST_SOLVE_UPPER_TRIANGULAR_F32_9:
  139. {
  140. int offset=14;
  141. float32_t *p;
  142. float32_t *aPtr;
  143. float32_t *bPtr;
  144. input1.reload(UnaryF32::INPUT_UT_DPO_F32_ID,mgr);
  145. input2.reload(UnaryF32::INPUT_RNDA_DPO_F32_ID,mgr);
  146. output.create(this->nbc * this->nbr,UnaryF32::OUT_F32_ID,mgr);
  147. a.create(this->nbr*this->nbc,UnaryF32::TMPA_F32_ID,mgr);
  148. b.create(this->nbr*this->nbc,UnaryF32::TMPB_F32_ID,mgr);
  149. /* Offsets must be coherent with the sizes used in python script
  150. Matrix.py for pattern generation */
  151. offset=cholesky_offset(this->nbr);
  152. p = input1.ptr();
  153. aPtr = a.ptr();
  154. memcpy(aPtr,&p[offset],sizeof(float32_t)*this->nbr*this->nbr);
  155. p = input2.ptr();
  156. bPtr = b.ptr();
  157. memcpy(bPtr,&p[offset],sizeof(float32_t)*this->nbr*this->nbr);
  158. this->out.numRows = this->nbr;
  159. this->out.numCols = this->nbc;
  160. this->out.pData = output.ptr();
  161. this->in1.numRows = this->nbr;
  162. this->in1.numCols = this->nbc;
  163. this->in1.pData = aPtr;
  164. this->in2.numRows = this->nbr;
  165. this->in2.numCols = this->nbc;
  166. this->in2.pData = bPtr;
  167. }
  168. break;
  169. case TEST_SOLVE_LOWER_TRIANGULAR_F32_10:
  170. {
  171. int offset=14;
  172. float32_t *p;
  173. float32_t *aPtr;
  174. float32_t *bPtr;
  175. input1.reload(UnaryF32::INPUT_LT_DPO_F32_ID,mgr);
  176. input2.reload(UnaryF32::INPUT_RNDA_DPO_F32_ID,mgr);
  177. output.create(this->nbc * this->nbr,UnaryF32::OUT_F32_ID,mgr);
  178. a.create(this->nbr*this->nbc,UnaryF32::TMPA_F32_ID,mgr);
  179. b.create(this->nbr*this->nbc,UnaryF32::TMPB_F32_ID,mgr);
  180. /* Offsets must be coherent with the sizes used in python script
  181. Matrix.py for pattern generation */
  182. offset=cholesky_offset(this->nbr);
  183. p = input1.ptr();
  184. aPtr = a.ptr();
  185. memcpy(aPtr,&p[offset],sizeof(float32_t)*this->nbr*this->nbr);
  186. p = input2.ptr();
  187. bPtr = b.ptr();
  188. memcpy(bPtr,&p[offset],sizeof(float32_t)*this->nbr*this->nbr);
  189. this->out.numRows = this->nbr;
  190. this->out.numCols = this->nbc;
  191. this->out.pData = output.ptr();
  192. this->in1.numRows = this->nbr;
  193. this->in1.numCols = this->nbc;
  194. this->in1.pData = aPtr;
  195. this->in2.numRows = this->nbr;
  196. this->in2.numCols = this->nbc;
  197. this->in2.pData = bPtr;
  198. }
  199. break;
  200. case TEST_LDLT_DECOMPOSITION_F32_11:
  201. {
  202. float32_t *p, *aPtr;
  203. int offset=14;
  204. input1.reload(UnaryF32::INPUTSCHOLESKY1_DPO_F32_ID,mgr);
  205. outputll.create(this->nbr*this->nbr,UnaryF32::LL_F32_ID,mgr);
  206. outputd.create(this->nbr*this->nbr,UnaryF32::D_F32_ID,mgr);
  207. outputp.create(this->nbr,UnaryF32::PERM_S16_ID,mgr);
  208. a.create(MAXMATRIXDIM*MAXMATRIXDIM,UnaryF32::TMPA_F32_ID,mgr);
  209. /* Offsets must be coherent with the sizes used in python script
  210. Matrix.py for pattern generation */
  211. offset=cholesky_offset(this->nbr);
  212. p = input1.ptr();
  213. aPtr = a.ptr();
  214. memcpy(aPtr,&p[offset],sizeof(float32_t)*this->nbr*this->nbr);
  215. this->in1.numRows = this->nbr;
  216. this->in1.numCols = this->nbc;
  217. this->in1.pData = aPtr;
  218. this->outll.numRows = this->nbr;
  219. this->outll.numCols = this->nbc;
  220. this->outll.pData = outputll.ptr();
  221. this->outd.numRows = this->nbr;
  222. this->outd.numCols = this->nbc;
  223. this->outd.pData = outputd.ptr();
  224. outpp = outputp.ptr();
  225. }
  226. break;
  227. default:
  228. input1.reload(UnaryF32::INPUTA_F32_ID,mgr,this->nbr*this->nbc);
  229. output.create(this->nbr*this->nbc,UnaryF32::OUT_F32_ID,mgr);
  230. this->out.numRows = this->nbr;
  231. this->out.numCols = this->nbc;
  232. this->out.pData = output.ptr();
  233. this->in1.numRows = this->nbr;
  234. this->in1.numCols = this->nbc;
  235. this->in1.pData = input1.ptr();
  236. break;
  237. }
  238. }
  239. void UnaryF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  240. {
  241. }