matrix_functions.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. /******************************************************************************
  2. * @file matrix_functions.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.10.1
  5. * @date 10 August 2022
  6. * Target Processor: Cortex-M and Cortex-A cores
  7. ******************************************************************************/
  8. /*
  9. * Copyright (c) 2010-2020 Arm Limited or its affiliates. All rights reserved.
  10. *
  11. * SPDX-License-Identifier: Apache-2.0
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the License); you may
  14. * not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  21. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. #ifndef _MATRIX_FUNCTIONS_H_
  26. #define _MATRIX_FUNCTIONS_H_
  27. #include "arm_math_types.h"
  28. #include "arm_math_memory.h"
  29. #include "dsp/none.h"
  30. #include "dsp/utils.h"
  31. #ifdef __cplusplus
  32. extern "C"
  33. {
  34. #endif
  35. /**
  36. * @defgroup groupMatrix Matrix Functions
  37. *
  38. * This set of functions provides basic matrix math operations.
  39. * The functions operate on matrix data structures. For example,
  40. * the type
  41. * definition for the floating-point matrix structure is shown
  42. * below:
  43. * <pre>
  44. * typedef struct
  45. * {
  46. * uint16_t numRows; // number of rows of the matrix.
  47. * uint16_t numCols; // number of columns of the matrix.
  48. * float32_t *pData; // points to the data of the matrix.
  49. * } arm_matrix_instance_f32;
  50. * </pre>
  51. * There are similar definitions for Q15 and Q31 data types.
  52. *
  53. * The structure specifies the size of the matrix and then points to
  54. * an array of data. The array is of size <code>numRows X numCols</code>
  55. * and the values are arranged in row order. That is, the
  56. * matrix element (i, j) is stored at:
  57. * <pre>
  58. * pData[i*numCols + j]
  59. * </pre>
  60. *
  61. * \par Init Functions
  62. * There is an associated initialization function for each type of matrix
  63. * data structure.
  64. * The initialization function sets the values of the internal structure fields.
  65. * Refer to \ref arm_mat_init_f32(), \ref arm_mat_init_q31() and \ref arm_mat_init_q15()
  66. * for floating-point, Q31 and Q15 types, respectively.
  67. *
  68. * \par
  69. * Use of the initialization function is optional. However, if initialization function is used
  70. * then the instance structure cannot be placed into a const data section.
  71. * To place the instance structure in a const data
  72. * section, manually initialize the data structure. For example:
  73. * <pre>
  74. * <code>arm_matrix_instance_f32 S = {nRows, nColumns, pData};</code>
  75. * <code>arm_matrix_instance_q31 S = {nRows, nColumns, pData};</code>
  76. * <code>arm_matrix_instance_q15 S = {nRows, nColumns, pData};</code>
  77. * </pre>
  78. * where <code>nRows</code> specifies the number of rows, <code>nColumns</code>
  79. * specifies the number of columns, and <code>pData</code> points to the
  80. * data array.
  81. *
  82. * \par Size Checking
  83. * By default all of the matrix functions perform size checking on the input and
  84. * output matrices. For example, the matrix addition function verifies that the
  85. * two input matrices and the output matrix all have the same number of rows and
  86. * columns. If the size check fails the functions return:
  87. * <pre>
  88. * ARM_MATH_SIZE_MISMATCH
  89. * </pre>
  90. * Otherwise the functions return
  91. * <pre>
  92. * ARM_MATH_SUCCESS
  93. * </pre>
  94. * There is some overhead associated with this matrix size checking.
  95. * The matrix size checking is enabled via the \#define
  96. * <pre>
  97. * ARM_MATH_MATRIX_CHECK
  98. * </pre>
  99. * within the library project settings. By default this macro is defined
  100. * and size checking is enabled. By changing the project settings and
  101. * undefining this macro size checking is eliminated and the functions
  102. * run a bit faster. With size checking disabled the functions always
  103. * return <code>ARM_MATH_SUCCESS</code>.
  104. */
  105. #define DEFAULT_HOUSEHOLDER_THRESHOLD_F64 (1.0e-16)
  106. #define DEFAULT_HOUSEHOLDER_THRESHOLD_F32 (1.0e-12f)
  107. /**
  108. * @brief Instance structure for the floating-point matrix structure.
  109. */
  110. typedef struct
  111. {
  112. uint16_t numRows; /**< number of rows of the matrix. */
  113. uint16_t numCols; /**< number of columns of the matrix. */
  114. float32_t *pData; /**< points to the data of the matrix. */
  115. } arm_matrix_instance_f32;
  116. /**
  117. * @brief Instance structure for the floating-point matrix structure.
  118. */
  119. typedef struct
  120. {
  121. uint16_t numRows; /**< number of rows of the matrix. */
  122. uint16_t numCols; /**< number of columns of the matrix. */
  123. float64_t *pData; /**< points to the data of the matrix. */
  124. } arm_matrix_instance_f64;
  125. /**
  126. * @brief Instance structure for the Q7 matrix structure.
  127. */
  128. typedef struct
  129. {
  130. uint16_t numRows; /**< number of rows of the matrix. */
  131. uint16_t numCols; /**< number of columns of the matrix. */
  132. q7_t *pData; /**< points to the data of the matrix. */
  133. } arm_matrix_instance_q7;
  134. /**
  135. * @brief Instance structure for the Q15 matrix structure.
  136. */
  137. typedef struct
  138. {
  139. uint16_t numRows; /**< number of rows of the matrix. */
  140. uint16_t numCols; /**< number of columns of the matrix. */
  141. q15_t *pData; /**< points to the data of the matrix. */
  142. } arm_matrix_instance_q15;
  143. /**
  144. * @brief Instance structure for the Q31 matrix structure.
  145. */
  146. typedef struct
  147. {
  148. uint16_t numRows; /**< number of rows of the matrix. */
  149. uint16_t numCols; /**< number of columns of the matrix. */
  150. q31_t *pData; /**< points to the data of the matrix. */
  151. } arm_matrix_instance_q31;
  152. /**
  153. * @brief Floating-point matrix addition.
  154. * @param[in] pSrcA points to the first input matrix structure
  155. * @param[in] pSrcB points to the second input matrix structure
  156. * @param[out] pDst points to output matrix structure
  157. * @return The function returns either
  158. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  159. */
  160. arm_status arm_mat_add_f32(
  161. const arm_matrix_instance_f32 * pSrcA,
  162. const arm_matrix_instance_f32 * pSrcB,
  163. arm_matrix_instance_f32 * pDst);
  164. /**
  165. * @brief Q15 matrix addition.
  166. * @param[in] pSrcA points to the first input matrix structure
  167. * @param[in] pSrcB points to the second input matrix structure
  168. * @param[out] pDst points to output matrix structure
  169. * @return The function returns either
  170. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  171. */
  172. arm_status arm_mat_add_q15(
  173. const arm_matrix_instance_q15 * pSrcA,
  174. const arm_matrix_instance_q15 * pSrcB,
  175. arm_matrix_instance_q15 * pDst);
  176. /**
  177. * @brief Q31 matrix addition.
  178. * @param[in] pSrcA points to the first input matrix structure
  179. * @param[in] pSrcB points to the second input matrix structure
  180. * @param[out] pDst points to output matrix structure
  181. * @return The function returns either
  182. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  183. */
  184. arm_status arm_mat_add_q31(
  185. const arm_matrix_instance_q31 * pSrcA,
  186. const arm_matrix_instance_q31 * pSrcB,
  187. arm_matrix_instance_q31 * pDst);
  188. /**
  189. * @brief Floating-point, complex, matrix multiplication.
  190. * @param[in] pSrcA points to the first input matrix structure
  191. * @param[in] pSrcB points to the second input matrix structure
  192. * @param[out] pDst points to output matrix structure
  193. * @return The function returns either
  194. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  195. */
  196. arm_status arm_mat_cmplx_mult_f32(
  197. const arm_matrix_instance_f32 * pSrcA,
  198. const arm_matrix_instance_f32 * pSrcB,
  199. arm_matrix_instance_f32 * pDst);
  200. /**
  201. * @brief Q15, complex, matrix multiplication.
  202. * @param[in] pSrcA points to the first input matrix structure
  203. * @param[in] pSrcB points to the second input matrix structure
  204. * @param[out] pDst points to output matrix structure
  205. * @return The function returns either
  206. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  207. */
  208. arm_status arm_mat_cmplx_mult_q15(
  209. const arm_matrix_instance_q15 * pSrcA,
  210. const arm_matrix_instance_q15 * pSrcB,
  211. arm_matrix_instance_q15 * pDst,
  212. q15_t * pScratch);
  213. /**
  214. * @brief Q31, complex, matrix multiplication.
  215. * @param[in] pSrcA points to the first input matrix structure
  216. * @param[in] pSrcB points to the second input matrix structure
  217. * @param[out] pDst points to output matrix structure
  218. * @return The function returns either
  219. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  220. */
  221. arm_status arm_mat_cmplx_mult_q31(
  222. const arm_matrix_instance_q31 * pSrcA,
  223. const arm_matrix_instance_q31 * pSrcB,
  224. arm_matrix_instance_q31 * pDst);
  225. /**
  226. * @brief Floating-point matrix transpose.
  227. * @param[in] pSrc points to the input matrix
  228. * @param[out] pDst points to the output matrix
  229. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  230. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  231. */
  232. arm_status arm_mat_trans_f32(
  233. const arm_matrix_instance_f32 * pSrc,
  234. arm_matrix_instance_f32 * pDst);
  235. /**
  236. * @brief Floating-point matrix transpose.
  237. * @param[in] pSrc points to the input matrix
  238. * @param[out] pDst points to the output matrix
  239. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  240. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  241. */
  242. arm_status arm_mat_trans_f64(
  243. const arm_matrix_instance_f64 * pSrc,
  244. arm_matrix_instance_f64 * pDst);
  245. /**
  246. * @brief Floating-point complex matrix transpose.
  247. * @param[in] pSrc points to the input matrix
  248. * @param[out] pDst points to the output matrix
  249. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  250. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  251. */
  252. arm_status arm_mat_cmplx_trans_f32(
  253. const arm_matrix_instance_f32 * pSrc,
  254. arm_matrix_instance_f32 * pDst);
  255. /**
  256. * @brief Q15 matrix transpose.
  257. * @param[in] pSrc points to the input matrix
  258. * @param[out] pDst points to the output matrix
  259. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  260. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  261. */
  262. arm_status arm_mat_trans_q15(
  263. const arm_matrix_instance_q15 * pSrc,
  264. arm_matrix_instance_q15 * pDst);
  265. /**
  266. * @brief Q15 complex matrix transpose.
  267. * @param[in] pSrc points to the input matrix
  268. * @param[out] pDst points to the output matrix
  269. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  270. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  271. */
  272. arm_status arm_mat_cmplx_trans_q15(
  273. const arm_matrix_instance_q15 * pSrc,
  274. arm_matrix_instance_q15 * pDst);
  275. /**
  276. * @brief Q7 matrix transpose.
  277. * @param[in] pSrc points to the input matrix
  278. * @param[out] pDst points to the output matrix
  279. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  280. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  281. */
  282. arm_status arm_mat_trans_q7(
  283. const arm_matrix_instance_q7 * pSrc,
  284. arm_matrix_instance_q7 * pDst);
  285. /**
  286. * @brief Q31 matrix transpose.
  287. * @param[in] pSrc points to the input matrix
  288. * @param[out] pDst points to the output matrix
  289. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  290. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  291. */
  292. arm_status arm_mat_trans_q31(
  293. const arm_matrix_instance_q31 * pSrc,
  294. arm_matrix_instance_q31 * pDst);
  295. /**
  296. * @brief Q31 complex matrix transpose.
  297. * @param[in] pSrc points to the input matrix
  298. * @param[out] pDst points to the output matrix
  299. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  300. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  301. */
  302. arm_status arm_mat_cmplx_trans_q31(
  303. const arm_matrix_instance_q31 * pSrc,
  304. arm_matrix_instance_q31 * pDst);
  305. /**
  306. * @brief Floating-point matrix multiplication
  307. * @param[in] pSrcA points to the first input matrix structure
  308. * @param[in] pSrcB points to the second input matrix structure
  309. * @param[out] pDst points to output matrix structure
  310. * @return The function returns either
  311. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  312. */
  313. arm_status arm_mat_mult_f32(
  314. const arm_matrix_instance_f32 * pSrcA,
  315. const arm_matrix_instance_f32 * pSrcB,
  316. arm_matrix_instance_f32 * pDst);
  317. /**
  318. * @brief Floating-point matrix multiplication
  319. * @param[in] pSrcA points to the first input matrix structure
  320. * @param[in] pSrcB points to the second input matrix structure
  321. * @param[out] pDst points to output matrix structure
  322. * @return The function returns either
  323. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  324. */
  325. arm_status arm_mat_mult_f64(
  326. const arm_matrix_instance_f64 * pSrcA,
  327. const arm_matrix_instance_f64 * pSrcB,
  328. arm_matrix_instance_f64 * pDst);
  329. /**
  330. * @brief Floating-point matrix and vector multiplication
  331. * @param[in] pSrcMat points to the input matrix structure
  332. * @param[in] pVec points to vector
  333. * @param[out] pDst points to output vector
  334. */
  335. void arm_mat_vec_mult_f32(
  336. const arm_matrix_instance_f32 *pSrcMat,
  337. const float32_t *pVec,
  338. float32_t *pDst);
  339. /**
  340. * @brief Q7 matrix multiplication
  341. * @param[in] pSrcA points to the first input matrix structure
  342. * @param[in] pSrcB points to the second input matrix structure
  343. * @param[out] pDst points to output matrix structure
  344. * @param[in] pState points to the array for storing intermediate results
  345. * @return The function returns either
  346. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  347. */
  348. arm_status arm_mat_mult_q7(
  349. const arm_matrix_instance_q7 * pSrcA,
  350. const arm_matrix_instance_q7 * pSrcB,
  351. arm_matrix_instance_q7 * pDst,
  352. q7_t * pState);
  353. /**
  354. * @brief Q7 matrix and vector multiplication
  355. * @param[in] pSrcMat points to the input matrix structure
  356. * @param[in] pVec points to vector
  357. * @param[out] pDst points to output vector
  358. */
  359. void arm_mat_vec_mult_q7(
  360. const arm_matrix_instance_q7 *pSrcMat,
  361. const q7_t *pVec,
  362. q7_t *pDst);
  363. /**
  364. * @brief Q15 matrix multiplication
  365. * @param[in] pSrcA points to the first input matrix structure
  366. * @param[in] pSrcB points to the second input matrix structure
  367. * @param[out] pDst points to output matrix structure
  368. * @param[in] pState points to the array for storing intermediate results
  369. * @return The function returns either
  370. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  371. */
  372. arm_status arm_mat_mult_q15(
  373. const arm_matrix_instance_q15 * pSrcA,
  374. const arm_matrix_instance_q15 * pSrcB,
  375. arm_matrix_instance_q15 * pDst,
  376. q15_t * pState);
  377. /**
  378. * @brief Q15 matrix and vector multiplication
  379. * @param[in] pSrcMat points to the input matrix structure
  380. * @param[in] pVec points to vector
  381. * @param[out] pDst points to output vector
  382. */
  383. void arm_mat_vec_mult_q15(
  384. const arm_matrix_instance_q15 *pSrcMat,
  385. const q15_t *pVec,
  386. q15_t *pDst);
  387. /**
  388. * @brief Q15 matrix multiplication (fast variant) for Cortex-M3 and Cortex-M4
  389. * @param[in] pSrcA points to the first input matrix structure
  390. * @param[in] pSrcB points to the second input matrix structure
  391. * @param[out] pDst points to output matrix structure
  392. * @param[in] pState points to the array for storing intermediate results
  393. * @return The function returns either
  394. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  395. */
  396. arm_status arm_mat_mult_fast_q15(
  397. const arm_matrix_instance_q15 * pSrcA,
  398. const arm_matrix_instance_q15 * pSrcB,
  399. arm_matrix_instance_q15 * pDst,
  400. q15_t * pState);
  401. /**
  402. * @brief Q31 matrix multiplication
  403. * @param[in] pSrcA points to the first input matrix structure
  404. * @param[in] pSrcB points to the second input matrix structure
  405. * @param[out] pDst points to output matrix structure
  406. * @return The function returns either
  407. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  408. */
  409. arm_status arm_mat_mult_q31(
  410. const arm_matrix_instance_q31 * pSrcA,
  411. const arm_matrix_instance_q31 * pSrcB,
  412. arm_matrix_instance_q31 * pDst);
  413. /**
  414. * @brief Q31 matrix multiplication
  415. * @param[in] pSrcA points to the first input matrix structure
  416. * @param[in] pSrcB points to the second input matrix structure
  417. * @param[out] pDst points to output matrix structure
  418. * @param[in] pState points to the array for storing intermediate results
  419. * @return The function returns either
  420. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  421. */
  422. arm_status arm_mat_mult_opt_q31(
  423. const arm_matrix_instance_q31 * pSrcA,
  424. const arm_matrix_instance_q31 * pSrcB,
  425. arm_matrix_instance_q31 * pDst,
  426. q31_t *pState);
  427. /**
  428. * @brief Q31 matrix and vector multiplication
  429. * @param[in] pSrcMat points to the input matrix structure
  430. * @param[in] pVec points to vector
  431. * @param[out] pDst points to output vector
  432. */
  433. void arm_mat_vec_mult_q31(
  434. const arm_matrix_instance_q31 *pSrcMat,
  435. const q31_t *pVec,
  436. q31_t *pDst);
  437. /**
  438. * @brief Q31 matrix multiplication (fast variant) for Cortex-M3 and Cortex-M4
  439. * @param[in] pSrcA points to the first input matrix structure
  440. * @param[in] pSrcB points to the second input matrix structure
  441. * @param[out] pDst points to output matrix structure
  442. * @return The function returns either
  443. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  444. */
  445. arm_status arm_mat_mult_fast_q31(
  446. const arm_matrix_instance_q31 * pSrcA,
  447. const arm_matrix_instance_q31 * pSrcB,
  448. arm_matrix_instance_q31 * pDst);
  449. /**
  450. * @brief Floating-point matrix subtraction
  451. * @param[in] pSrcA points to the first input matrix structure
  452. * @param[in] pSrcB points to the second input matrix structure
  453. * @param[out] pDst points to output matrix structure
  454. * @return The function returns either
  455. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  456. */
  457. arm_status arm_mat_sub_f32(
  458. const arm_matrix_instance_f32 * pSrcA,
  459. const arm_matrix_instance_f32 * pSrcB,
  460. arm_matrix_instance_f32 * pDst);
  461. /**
  462. * @brief Floating-point matrix subtraction
  463. * @param[in] pSrcA points to the first input matrix structure
  464. * @param[in] pSrcB points to the second input matrix structure
  465. * @param[out] pDst points to output matrix structure
  466. * @return The function returns either
  467. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  468. */
  469. arm_status arm_mat_sub_f64(
  470. const arm_matrix_instance_f64 * pSrcA,
  471. const arm_matrix_instance_f64 * pSrcB,
  472. arm_matrix_instance_f64 * pDst);
  473. /**
  474. * @brief Q15 matrix subtraction
  475. * @param[in] pSrcA points to the first input matrix structure
  476. * @param[in] pSrcB points to the second input matrix structure
  477. * @param[out] pDst points to output matrix structure
  478. * @return The function returns either
  479. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  480. */
  481. arm_status arm_mat_sub_q15(
  482. const arm_matrix_instance_q15 * pSrcA,
  483. const arm_matrix_instance_q15 * pSrcB,
  484. arm_matrix_instance_q15 * pDst);
  485. /**
  486. * @brief Q31 matrix subtraction
  487. * @param[in] pSrcA points to the first input matrix structure
  488. * @param[in] pSrcB points to the second input matrix structure
  489. * @param[out] pDst points to output matrix structure
  490. * @return The function returns either
  491. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  492. */
  493. arm_status arm_mat_sub_q31(
  494. const arm_matrix_instance_q31 * pSrcA,
  495. const arm_matrix_instance_q31 * pSrcB,
  496. arm_matrix_instance_q31 * pDst);
  497. /**
  498. * @brief Floating-point matrix scaling.
  499. * @param[in] pSrc points to the input matrix
  500. * @param[in] scale scale factor
  501. * @param[out] pDst points to the output matrix
  502. * @return The function returns either
  503. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  504. */
  505. arm_status arm_mat_scale_f32(
  506. const arm_matrix_instance_f32 * pSrc,
  507. float32_t scale,
  508. arm_matrix_instance_f32 * pDst);
  509. /**
  510. * @brief Q15 matrix scaling.
  511. * @param[in] pSrc points to input matrix
  512. * @param[in] scaleFract fractional portion of the scale factor
  513. * @param[in] shift number of bits to shift the result by
  514. * @param[out] pDst points to output matrix
  515. * @return The function returns either
  516. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  517. */
  518. arm_status arm_mat_scale_q15(
  519. const arm_matrix_instance_q15 * pSrc,
  520. q15_t scaleFract,
  521. int32_t shift,
  522. arm_matrix_instance_q15 * pDst);
  523. /**
  524. * @brief Q31 matrix scaling.
  525. * @param[in] pSrc points to input matrix
  526. * @param[in] scaleFract fractional portion of the scale factor
  527. * @param[in] shift number of bits to shift the result by
  528. * @param[out] pDst points to output matrix structure
  529. * @return The function returns either
  530. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  531. */
  532. arm_status arm_mat_scale_q31(
  533. const arm_matrix_instance_q31 * pSrc,
  534. q31_t scaleFract,
  535. int32_t shift,
  536. arm_matrix_instance_q31 * pDst);
  537. /**
  538. * @brief Q31 matrix initialization.
  539. * @param[in,out] S points to an instance of the floating-point matrix structure.
  540. * @param[in] nRows number of rows in the matrix.
  541. * @param[in] nColumns number of columns in the matrix.
  542. * @param[in] pData points to the matrix data array.
  543. */
  544. void arm_mat_init_q31(
  545. arm_matrix_instance_q31 * S,
  546. uint16_t nRows,
  547. uint16_t nColumns,
  548. q31_t * pData);
  549. /**
  550. * @brief Q15 matrix initialization.
  551. * @param[in,out] S points to an instance of the floating-point matrix structure.
  552. * @param[in] nRows number of rows in the matrix.
  553. * @param[in] nColumns number of columns in the matrix.
  554. * @param[in] pData points to the matrix data array.
  555. */
  556. void arm_mat_init_q15(
  557. arm_matrix_instance_q15 * S,
  558. uint16_t nRows,
  559. uint16_t nColumns,
  560. q15_t * pData);
  561. /**
  562. * @brief Floating-point matrix initialization.
  563. * @param[in,out] S points to an instance of the floating-point matrix structure.
  564. * @param[in] nRows number of rows in the matrix.
  565. * @param[in] nColumns number of columns in the matrix.
  566. * @param[in] pData points to the matrix data array.
  567. */
  568. void arm_mat_init_f32(
  569. arm_matrix_instance_f32 * S,
  570. uint16_t nRows,
  571. uint16_t nColumns,
  572. float32_t * pData);
  573. /**
  574. * @brief Floating-point matrix initialization.
  575. * @param[in,out] S points to an instance of the floating-point matrix structure.
  576. * @param[in] nRows number of rows in the matrix.
  577. * @param[in] nColumns number of columns in the matrix.
  578. * @param[in] pData points to the matrix data array.
  579. */
  580. void arm_mat_init_f64(
  581. arm_matrix_instance_f64 * S,
  582. uint16_t nRows,
  583. uint16_t nColumns,
  584. float64_t * pData);
  585. /**
  586. * @brief Floating-point matrix inverse.
  587. * @param[in] src points to the instance of the input floating-point matrix structure.
  588. * @param[out] dst points to the instance of the output floating-point matrix structure.
  589. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  590. * If the input matrix is singular (does not have an inverse), then the algorithm terminates and returns error status ARM_MATH_SINGULAR.
  591. */
  592. arm_status arm_mat_inverse_f32(
  593. const arm_matrix_instance_f32 * src,
  594. arm_matrix_instance_f32 * dst);
  595. /**
  596. * @brief Floating-point matrix inverse.
  597. * @param[in] src points to the instance of the input floating-point matrix structure.
  598. * @param[out] dst points to the instance of the output floating-point matrix structure.
  599. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  600. * If the input matrix is singular (does not have an inverse), then the algorithm terminates and returns error status ARM_MATH_SINGULAR.
  601. */
  602. arm_status arm_mat_inverse_f64(
  603. const arm_matrix_instance_f64 * src,
  604. arm_matrix_instance_f64 * dst);
  605. /**
  606. * @brief Floating-point Cholesky decomposition of Symmetric Positive Definite Matrix.
  607. * @param[in] src points to the instance of the input floating-point matrix structure.
  608. * @param[out] dst points to the instance of the output floating-point matrix structure.
  609. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  610. * If the input matrix does not have a decomposition, then the algorithm terminates and returns error status ARM_MATH_DECOMPOSITION_FAILURE.
  611. * If the matrix is ill conditioned or only semi-definite, then it is better using the LDL^t decomposition.
  612. * The decomposition is returning a lower triangular matrix.
  613. */
  614. arm_status arm_mat_cholesky_f64(
  615. const arm_matrix_instance_f64 * src,
  616. arm_matrix_instance_f64 * dst);
  617. /**
  618. * @brief Floating-point Cholesky decomposition of Symmetric Positive Definite Matrix.
  619. * @param[in] src points to the instance of the input floating-point matrix structure.
  620. * @param[out] dst points to the instance of the output floating-point matrix structure.
  621. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  622. * If the input matrix does not have a decomposition, then the algorithm terminates and returns error status ARM_MATH_DECOMPOSITION_FAILURE.
  623. * If the matrix is ill conditioned or only semi-definite, then it is better using the LDL^t decomposition.
  624. * The decomposition is returning a lower triangular matrix.
  625. */
  626. arm_status arm_mat_cholesky_f32(
  627. const arm_matrix_instance_f32 * src,
  628. arm_matrix_instance_f32 * dst);
  629. /**
  630. * @brief Solve UT . X = A where UT is an upper triangular matrix
  631. * @param[in] ut The upper triangular matrix
  632. * @param[in] a The matrix a
  633. * @param[out] dst The solution X of UT . X = A
  634. * @return The function returns ARM_MATH_SINGULAR, if the system can't be solved.
  635. */
  636. arm_status arm_mat_solve_upper_triangular_f32(
  637. const arm_matrix_instance_f32 * ut,
  638. const arm_matrix_instance_f32 * a,
  639. arm_matrix_instance_f32 * dst);
  640. /**
  641. * @brief Solve LT . X = A where LT is a lower triangular matrix
  642. * @param[in] lt The lower triangular matrix
  643. * @param[in] a The matrix a
  644. * @param[out] dst The solution X of LT . X = A
  645. * @return The function returns ARM_MATH_SINGULAR, if the system can't be solved.
  646. */
  647. arm_status arm_mat_solve_lower_triangular_f32(
  648. const arm_matrix_instance_f32 * lt,
  649. const arm_matrix_instance_f32 * a,
  650. arm_matrix_instance_f32 * dst);
  651. /**
  652. * @brief Solve UT . X = A where UT is an upper triangular matrix
  653. * @param[in] ut The upper triangular matrix
  654. * @param[in] a The matrix a
  655. * @param[out] dst The solution X of UT . X = A
  656. * @return The function returns ARM_MATH_SINGULAR, if the system can't be solved.
  657. */
  658. arm_status arm_mat_solve_upper_triangular_f64(
  659. const arm_matrix_instance_f64 * ut,
  660. const arm_matrix_instance_f64 * a,
  661. arm_matrix_instance_f64 * dst);
  662. /**
  663. * @brief Solve LT . X = A where LT is a lower triangular matrix
  664. * @param[in] lt The lower triangular matrix
  665. * @param[in] a The matrix a
  666. * @param[out] dst The solution X of LT . X = A
  667. * @return The function returns ARM_MATH_SINGULAR, if the system can't be solved.
  668. */
  669. arm_status arm_mat_solve_lower_triangular_f64(
  670. const arm_matrix_instance_f64 * lt,
  671. const arm_matrix_instance_f64 * a,
  672. arm_matrix_instance_f64 * dst);
  673. /**
  674. * @brief Floating-point LDL decomposition of Symmetric Positive Semi-Definite Matrix.
  675. * @param[in] src points to the instance of the input floating-point matrix structure.
  676. * @param[out] l points to the instance of the output floating-point triangular matrix structure.
  677. * @param[out] d points to the instance of the output floating-point diagonal matrix structure.
  678. * @param[out] p points to the instance of the output floating-point permutation vector.
  679. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  680. * If the input matrix does not have a decomposition, then the algorithm terminates and returns error status ARM_MATH_DECOMPOSITION_FAILURE.
  681. * The decomposition is returning a lower triangular matrix.
  682. */
  683. arm_status arm_mat_ldlt_f32(
  684. const arm_matrix_instance_f32 * src,
  685. arm_matrix_instance_f32 * l,
  686. arm_matrix_instance_f32 * d,
  687. uint16_t * pp);
  688. /**
  689. * @brief Floating-point LDL decomposition of Symmetric Positive Semi-Definite Matrix.
  690. * @param[in] src points to the instance of the input floating-point matrix structure.
  691. * @param[out] l points to the instance of the output floating-point triangular matrix structure.
  692. * @param[out] d points to the instance of the output floating-point diagonal matrix structure.
  693. * @param[out] p points to the instance of the output floating-point permutation vector.
  694. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  695. * If the input matrix does not have a decomposition, then the algorithm terminates and returns error status ARM_MATH_DECOMPOSITION_FAILURE.
  696. * The decomposition is returning a lower triangular matrix.
  697. */
  698. arm_status arm_mat_ldlt_f64(
  699. const arm_matrix_instance_f64 * src,
  700. arm_matrix_instance_f64 * l,
  701. arm_matrix_instance_f64 * d,
  702. uint16_t * pp);
  703. /**
  704. @brief QR decomposition of a m x n floating point matrix with m >= n.
  705. @param[in] pSrc points to input matrix structure. The source matrix is modified by the function.
  706. @param[in] threshold norm2 threshold.
  707. @param[out] pOutR points to output R matrix structure of dimension m x n
  708. @param[out] pOutQ points to output Q matrix structure of dimension m x m
  709. @param[out] pOutTau points to Householder scaling factors of dimension n
  710. @param[inout] pTmpA points to a temporary vector of dimension m.
  711. @param[inout] pTmpB points to a temporary vector of dimension n.
  712. @return execution status
  713. - \ref ARM_MATH_SUCCESS : Operation successful
  714. - \ref ARM_MATH_SIZE_MISMATCH : Matrix size check failed
  715. - \ref ARM_MATH_SINGULAR : Input matrix is found to be singular (non-invertible)
  716. */
  717. arm_status arm_mat_qr_f32(
  718. const arm_matrix_instance_f32 * pSrc,
  719. const float32_t threshold,
  720. arm_matrix_instance_f32 * pOutR,
  721. arm_matrix_instance_f32 * pOutQ,
  722. float32_t * pOutTau,
  723. float32_t *pTmpA,
  724. float32_t *pTmpB
  725. );
  726. /**
  727. @brief QR decomposition of a m x n floating point matrix with m >= n.
  728. @param[in] pSrc points to input matrix structure. The source matrix is modified by the function.
  729. @param[in] threshold norm2 threshold.
  730. @param[out] pOutR points to output R matrix structure of dimension m x n
  731. @param[out] pOutQ points to output Q matrix structure of dimension m x m
  732. @param[out] pOutTau points to Householder scaling factors of dimension n
  733. @param[inout] pTmpA points to a temporary vector of dimension m.
  734. @param[inout] pTmpB points to a temporary vector of dimension n.
  735. @return execution status
  736. - \ref ARM_MATH_SUCCESS : Operation successful
  737. - \ref ARM_MATH_SIZE_MISMATCH : Matrix size check failed
  738. - \ref ARM_MATH_SINGULAR : Input matrix is found to be singular (non-invertible)
  739. */
  740. arm_status arm_mat_qr_f64(
  741. const arm_matrix_instance_f64 * pSrc,
  742. const float64_t threshold,
  743. arm_matrix_instance_f64 * pOutR,
  744. arm_matrix_instance_f64 * pOutQ,
  745. float64_t * pOutTau,
  746. float64_t *pTmpA,
  747. float64_t *pTmpB
  748. );
  749. /**
  750. @brief Householder transform of a floating point vector.
  751. @param[in] pSrc points to the input vector.
  752. @param[in] threshold norm2 threshold.
  753. @param[in] blockSize dimension of the vector space.
  754. @param[outQ] pOut points to the output vector.
  755. @return beta return the scaling factor beta
  756. */
  757. float32_t arm_householder_f32(
  758. const float32_t * pSrc,
  759. const float32_t threshold,
  760. uint32_t blockSize,
  761. float32_t * pOut
  762. );
  763. /**
  764. @brief Householder transform of a double floating point vector.
  765. @param[in] pSrc points to the input vector.
  766. @param[in] threshold norm2 threshold.
  767. @param[in] blockSize dimension of the vector space.
  768. @param[outQ] pOut points to the output vector.
  769. @return beta return the scaling factor beta
  770. */
  771. float64_t arm_householder_f64(
  772. const float64_t * pSrc,
  773. const float64_t threshold,
  774. uint32_t blockSize,
  775. float64_t * pOut
  776. );
  777. #ifdef __cplusplus
  778. }
  779. #endif
  780. #endif /* ifndef _MATRIX_FUNCTIONS_H_ */