matrix_functions.h 29 KB

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