matrix_functions.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /******************************************************************************
  2. * @file matrix_functions.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.10.0
  5. * @date 08 July 2021
  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. /**
  106. * @brief Instance structure for the floating-point matrix structure.
  107. */
  108. typedef struct
  109. {
  110. uint16_t numRows; /**< number of rows of the matrix. */
  111. uint16_t numCols; /**< number of columns of the matrix. */
  112. float32_t *pData; /**< points to the data of the matrix. */
  113. } arm_matrix_instance_f32;
  114. /**
  115. * @brief Instance structure for the floating-point matrix structure.
  116. */
  117. typedef struct
  118. {
  119. uint16_t numRows; /**< number of rows of the matrix. */
  120. uint16_t numCols; /**< number of columns of the matrix. */
  121. float64_t *pData; /**< points to the data of the matrix. */
  122. } arm_matrix_instance_f64;
  123. /**
  124. * @brief Instance structure for the Q7 matrix structure.
  125. */
  126. typedef struct
  127. {
  128. uint16_t numRows; /**< number of rows of the matrix. */
  129. uint16_t numCols; /**< number of columns of the matrix. */
  130. q7_t *pData; /**< points to the data of the matrix. */
  131. } arm_matrix_instance_q7;
  132. /**
  133. * @brief Instance structure for the Q15 matrix structure.
  134. */
  135. typedef struct
  136. {
  137. uint16_t numRows; /**< number of rows of the matrix. */
  138. uint16_t numCols; /**< number of columns of the matrix. */
  139. q15_t *pData; /**< points to the data of the matrix. */
  140. } arm_matrix_instance_q15;
  141. /**
  142. * @brief Instance structure for the Q31 matrix structure.
  143. */
  144. typedef struct
  145. {
  146. uint16_t numRows; /**< number of rows of the matrix. */
  147. uint16_t numCols; /**< number of columns of the matrix. */
  148. q31_t *pData; /**< points to the data of the matrix. */
  149. } arm_matrix_instance_q31;
  150. /**
  151. * @brief Floating-point matrix addition.
  152. * @param[in] pSrcA points to the first input matrix structure
  153. * @param[in] pSrcB points to the second input matrix structure
  154. * @param[out] pDst points to output matrix structure
  155. * @return The function returns either
  156. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  157. */
  158. arm_status arm_mat_add_f32(
  159. const arm_matrix_instance_f32 * pSrcA,
  160. const arm_matrix_instance_f32 * pSrcB,
  161. arm_matrix_instance_f32 * pDst);
  162. /**
  163. * @brief Q15 matrix addition.
  164. * @param[in] pSrcA points to the first input matrix structure
  165. * @param[in] pSrcB points to the second input matrix structure
  166. * @param[out] pDst points to output matrix structure
  167. * @return The function returns either
  168. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  169. */
  170. arm_status arm_mat_add_q15(
  171. const arm_matrix_instance_q15 * pSrcA,
  172. const arm_matrix_instance_q15 * pSrcB,
  173. arm_matrix_instance_q15 * pDst);
  174. /**
  175. * @brief Q31 matrix addition.
  176. * @param[in] pSrcA points to the first input matrix structure
  177. * @param[in] pSrcB points to the second input matrix structure
  178. * @param[out] pDst points to output matrix structure
  179. * @return The function returns either
  180. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  181. */
  182. arm_status arm_mat_add_q31(
  183. const arm_matrix_instance_q31 * pSrcA,
  184. const arm_matrix_instance_q31 * pSrcB,
  185. arm_matrix_instance_q31 * pDst);
  186. /**
  187. * @brief Floating-point, complex, matrix multiplication.
  188. * @param[in] pSrcA points to the first input matrix structure
  189. * @param[in] pSrcB points to the second input matrix structure
  190. * @param[out] pDst points to output matrix structure
  191. * @return The function returns either
  192. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  193. */
  194. arm_status arm_mat_cmplx_mult_f32(
  195. const arm_matrix_instance_f32 * pSrcA,
  196. const arm_matrix_instance_f32 * pSrcB,
  197. arm_matrix_instance_f32 * pDst);
  198. /**
  199. * @brief Q15, complex, matrix multiplication.
  200. * @param[in] pSrcA points to the first input matrix structure
  201. * @param[in] pSrcB points to the second input matrix structure
  202. * @param[out] pDst points to output matrix structure
  203. * @return The function returns either
  204. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  205. */
  206. arm_status arm_mat_cmplx_mult_q15(
  207. const arm_matrix_instance_q15 * pSrcA,
  208. const arm_matrix_instance_q15 * pSrcB,
  209. arm_matrix_instance_q15 * pDst,
  210. q15_t * pScratch);
  211. /**
  212. * @brief Q31, complex, matrix multiplication.
  213. * @param[in] pSrcA points to the first input matrix structure
  214. * @param[in] pSrcB points to the second input matrix structure
  215. * @param[out] pDst points to output matrix structure
  216. * @return The function returns either
  217. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  218. */
  219. arm_status arm_mat_cmplx_mult_q31(
  220. const arm_matrix_instance_q31 * pSrcA,
  221. const arm_matrix_instance_q31 * pSrcB,
  222. arm_matrix_instance_q31 * pDst);
  223. /**
  224. * @brief Floating-point matrix transpose.
  225. * @param[in] pSrc points to the input matrix
  226. * @param[out] pDst points to the output matrix
  227. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  228. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  229. */
  230. arm_status arm_mat_trans_f32(
  231. const arm_matrix_instance_f32 * pSrc,
  232. arm_matrix_instance_f32 * pDst);
  233. /**
  234. * @brief Floating-point matrix transpose.
  235. * @param[in] pSrc points to the input matrix
  236. * @param[out] pDst points to the output matrix
  237. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  238. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  239. */
  240. arm_status arm_mat_trans_f64(
  241. const arm_matrix_instance_f64 * pSrc,
  242. arm_matrix_instance_f64 * pDst);
  243. /**
  244. * @brief Floating-point complex matrix transpose.
  245. * @param[in] pSrc points to the input matrix
  246. * @param[out] pDst points to the output matrix
  247. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  248. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  249. */
  250. arm_status arm_mat_cmplx_trans_f32(
  251. const arm_matrix_instance_f32 * pSrc,
  252. arm_matrix_instance_f32 * pDst);
  253. /**
  254. * @brief Q15 matrix transpose.
  255. * @param[in] pSrc points to the input matrix
  256. * @param[out] pDst points to the output matrix
  257. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  258. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  259. */
  260. arm_status arm_mat_trans_q15(
  261. const arm_matrix_instance_q15 * pSrc,
  262. arm_matrix_instance_q15 * pDst);
  263. /**
  264. * @brief Q15 complex matrix transpose.
  265. * @param[in] pSrc points to the input matrix
  266. * @param[out] pDst points to the output matrix
  267. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  268. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  269. */
  270. arm_status arm_mat_cmplx_trans_q15(
  271. const arm_matrix_instance_q15 * pSrc,
  272. arm_matrix_instance_q15 * pDst);
  273. /**
  274. * @brief Q7 matrix transpose.
  275. * @param[in] pSrc points to the input matrix
  276. * @param[out] pDst points to the output matrix
  277. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  278. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  279. */
  280. arm_status arm_mat_trans_q7(
  281. const arm_matrix_instance_q7 * pSrc,
  282. arm_matrix_instance_q7 * pDst);
  283. /**
  284. * @brief Q31 matrix transpose.
  285. * @param[in] pSrc points to the input matrix
  286. * @param[out] pDst points to the output matrix
  287. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  288. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  289. */
  290. arm_status arm_mat_trans_q31(
  291. const arm_matrix_instance_q31 * pSrc,
  292. arm_matrix_instance_q31 * pDst);
  293. /**
  294. * @brief Q31 complex matrix transpose.
  295. * @param[in] pSrc points to the input matrix
  296. * @param[out] pDst points to the output matrix
  297. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  298. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  299. */
  300. arm_status arm_mat_cmplx_trans_q31(
  301. const arm_matrix_instance_q31 * pSrc,
  302. arm_matrix_instance_q31 * pDst);
  303. /**
  304. * @brief Floating-point matrix multiplication
  305. * @param[in] pSrcA points to the first input matrix structure
  306. * @param[in] pSrcB points to the second input matrix structure
  307. * @param[out] pDst points to output matrix structure
  308. * @return The function returns either
  309. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  310. */
  311. arm_status arm_mat_mult_f32(
  312. const arm_matrix_instance_f32 * pSrcA,
  313. const arm_matrix_instance_f32 * pSrcB,
  314. arm_matrix_instance_f32 * pDst);
  315. /**
  316. * @brief Floating-point matrix multiplication
  317. * @param[in] pSrcA points to the first input matrix structure
  318. * @param[in] pSrcB points to the second input matrix structure
  319. * @param[out] pDst points to output matrix structure
  320. * @return The function returns either
  321. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  322. */
  323. arm_status arm_mat_mult_f64(
  324. const arm_matrix_instance_f64 * pSrcA,
  325. const arm_matrix_instance_f64 * pSrcB,
  326. arm_matrix_instance_f64 * pDst);
  327. /**
  328. * @brief Floating-point matrix and vector multiplication
  329. * @param[in] pSrcMat points to the input matrix structure
  330. * @param[in] pVec points to vector
  331. * @param[out] pDst points to output vector
  332. */
  333. void arm_mat_vec_mult_f32(
  334. const arm_matrix_instance_f32 *pSrcMat,
  335. const float32_t *pVec,
  336. float32_t *pDst);
  337. /**
  338. * @brief Q7 matrix multiplication
  339. * @param[in] pSrcA points to the first input matrix structure
  340. * @param[in] pSrcB points to the second input matrix structure
  341. * @param[out] pDst points to output matrix structure
  342. * @param[in] pState points to the array for storing intermediate results
  343. * @return The function returns either
  344. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  345. */
  346. arm_status arm_mat_mult_q7(
  347. const arm_matrix_instance_q7 * pSrcA,
  348. const arm_matrix_instance_q7 * pSrcB,
  349. arm_matrix_instance_q7 * pDst,
  350. q7_t * pState);
  351. /**
  352. * @brief Q7 matrix and vector multiplication
  353. * @param[in] pSrcMat points to the input matrix structure
  354. * @param[in] pVec points to vector
  355. * @param[out] pDst points to output vector
  356. */
  357. void arm_mat_vec_mult_q7(
  358. const arm_matrix_instance_q7 *pSrcMat,
  359. const q7_t *pVec,
  360. q7_t *pDst);
  361. /**
  362. * @brief Q15 matrix multiplication
  363. * @param[in] pSrcA points to the first input matrix structure
  364. * @param[in] pSrcB points to the second input matrix structure
  365. * @param[out] pDst points to output matrix structure
  366. * @param[in] pState points to the array for storing intermediate results
  367. * @return The function returns either
  368. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  369. */
  370. arm_status arm_mat_mult_q15(
  371. const arm_matrix_instance_q15 * pSrcA,
  372. const arm_matrix_instance_q15 * pSrcB,
  373. arm_matrix_instance_q15 * pDst,
  374. q15_t * pState);
  375. /**
  376. * @brief Q15 matrix and vector multiplication
  377. * @param[in] pSrcMat points to the input matrix structure
  378. * @param[in] pVec points to vector
  379. * @param[out] pDst points to output vector
  380. */
  381. void arm_mat_vec_mult_q15(
  382. const arm_matrix_instance_q15 *pSrcMat,
  383. const q15_t *pVec,
  384. q15_t *pDst);
  385. /**
  386. * @brief Q15 matrix multiplication (fast variant) for Cortex-M3 and Cortex-M4
  387. * @param[in] pSrcA points to the first input matrix structure
  388. * @param[in] pSrcB points to the second input matrix structure
  389. * @param[out] pDst points to output matrix structure
  390. * @param[in] pState points to the array for storing intermediate results
  391. * @return The function returns either
  392. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  393. */
  394. arm_status arm_mat_mult_fast_q15(
  395. const arm_matrix_instance_q15 * pSrcA,
  396. const arm_matrix_instance_q15 * pSrcB,
  397. arm_matrix_instance_q15 * pDst,
  398. q15_t * pState);
  399. /**
  400. * @brief Q31 matrix multiplication
  401. * @param[in] pSrcA points to the first input matrix structure
  402. * @param[in] pSrcB points to the second input matrix structure
  403. * @param[out] pDst points to output matrix structure
  404. * @return The function returns either
  405. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  406. */
  407. arm_status arm_mat_mult_q31(
  408. const arm_matrix_instance_q31 * pSrcA,
  409. const arm_matrix_instance_q31 * pSrcB,
  410. arm_matrix_instance_q31 * pDst);
  411. /**
  412. * @brief Q31 matrix multiplication
  413. * @param[in] pSrcA points to the first input matrix structure
  414. * @param[in] pSrcB points to the second input matrix structure
  415. * @param[out] pDst points to output matrix structure
  416. * @param[in] pState points to the array for storing intermediate results
  417. * @return The function returns either
  418. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  419. */
  420. arm_status arm_mat_mult_opt_q31(
  421. const arm_matrix_instance_q31 * pSrcA,
  422. const arm_matrix_instance_q31 * pSrcB,
  423. arm_matrix_instance_q31 * pDst,
  424. q31_t *pState);
  425. /**
  426. * @brief Q31 matrix and vector multiplication
  427. * @param[in] pSrcMat points to the input matrix structure
  428. * @param[in] pVec points to vector
  429. * @param[out] pDst points to output vector
  430. */
  431. void arm_mat_vec_mult_q31(
  432. const arm_matrix_instance_q31 *pSrcMat,
  433. const q31_t *pVec,
  434. q31_t *pDst);
  435. /**
  436. * @brief Q31 matrix multiplication (fast variant) for Cortex-M3 and Cortex-M4
  437. * @param[in] pSrcA points to the first input matrix structure
  438. * @param[in] pSrcB points to the second input matrix structure
  439. * @param[out] pDst points to output matrix structure
  440. * @return The function returns either
  441. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  442. */
  443. arm_status arm_mat_mult_fast_q31(
  444. const arm_matrix_instance_q31 * pSrcA,
  445. const arm_matrix_instance_q31 * pSrcB,
  446. arm_matrix_instance_q31 * pDst);
  447. /**
  448. * @brief Floating-point matrix subtraction
  449. * @param[in] pSrcA points to the first input matrix structure
  450. * @param[in] pSrcB points to the second input matrix structure
  451. * @param[out] pDst points to output matrix structure
  452. * @return The function returns either
  453. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  454. */
  455. arm_status arm_mat_sub_f32(
  456. const arm_matrix_instance_f32 * pSrcA,
  457. const arm_matrix_instance_f32 * pSrcB,
  458. arm_matrix_instance_f32 * pDst);
  459. /**
  460. * @brief Floating-point matrix subtraction
  461. * @param[in] pSrcA points to the first input matrix structure
  462. * @param[in] pSrcB points to the second input matrix structure
  463. * @param[out] pDst points to output matrix structure
  464. * @return The function returns either
  465. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  466. */
  467. arm_status arm_mat_sub_f64(
  468. const arm_matrix_instance_f64 * pSrcA,
  469. const arm_matrix_instance_f64 * pSrcB,
  470. arm_matrix_instance_f64 * pDst);
  471. /**
  472. * @brief Q15 matrix subtraction
  473. * @param[in] pSrcA points to the first input matrix structure
  474. * @param[in] pSrcB points to the second input matrix structure
  475. * @param[out] pDst points to output matrix structure
  476. * @return The function returns either
  477. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  478. */
  479. arm_status arm_mat_sub_q15(
  480. const arm_matrix_instance_q15 * pSrcA,
  481. const arm_matrix_instance_q15 * pSrcB,
  482. arm_matrix_instance_q15 * pDst);
  483. /**
  484. * @brief Q31 matrix subtraction
  485. * @param[in] pSrcA points to the first input matrix structure
  486. * @param[in] pSrcB points to the second input matrix structure
  487. * @param[out] pDst points to output matrix structure
  488. * @return The function returns either
  489. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  490. */
  491. arm_status arm_mat_sub_q31(
  492. const arm_matrix_instance_q31 * pSrcA,
  493. const arm_matrix_instance_q31 * pSrcB,
  494. arm_matrix_instance_q31 * pDst);
  495. /**
  496. * @brief Floating-point matrix scaling.
  497. * @param[in] pSrc points to the input matrix
  498. * @param[in] scale scale factor
  499. * @param[out] pDst points to the output matrix
  500. * @return The function returns either
  501. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  502. */
  503. arm_status arm_mat_scale_f32(
  504. const arm_matrix_instance_f32 * pSrc,
  505. float32_t scale,
  506. arm_matrix_instance_f32 * pDst);
  507. /**
  508. * @brief Q15 matrix scaling.
  509. * @param[in] pSrc points to input matrix
  510. * @param[in] scaleFract fractional portion of the scale factor
  511. * @param[in] shift number of bits to shift the result by
  512. * @param[out] pDst points to output matrix
  513. * @return The function returns either
  514. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  515. */
  516. arm_status arm_mat_scale_q15(
  517. const arm_matrix_instance_q15 * pSrc,
  518. q15_t scaleFract,
  519. int32_t shift,
  520. arm_matrix_instance_q15 * pDst);
  521. /**
  522. * @brief Q31 matrix scaling.
  523. * @param[in] pSrc points to input matrix
  524. * @param[in] scaleFract fractional portion of the scale factor
  525. * @param[in] shift number of bits to shift the result by
  526. * @param[out] pDst points to output matrix structure
  527. * @return The function returns either
  528. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  529. */
  530. arm_status arm_mat_scale_q31(
  531. const arm_matrix_instance_q31 * pSrc,
  532. q31_t scaleFract,
  533. int32_t shift,
  534. arm_matrix_instance_q31 * pDst);
  535. /**
  536. * @brief Q31 matrix initialization.
  537. * @param[in,out] S points to an instance of the floating-point matrix structure.
  538. * @param[in] nRows number of rows in the matrix.
  539. * @param[in] nColumns number of columns in the matrix.
  540. * @param[in] pData points to the matrix data array.
  541. */
  542. void arm_mat_init_q31(
  543. arm_matrix_instance_q31 * S,
  544. uint16_t nRows,
  545. uint16_t nColumns,
  546. q31_t * pData);
  547. /**
  548. * @brief Q15 matrix initialization.
  549. * @param[in,out] S points to an instance of the floating-point matrix structure.
  550. * @param[in] nRows number of rows in the matrix.
  551. * @param[in] nColumns number of columns in the matrix.
  552. * @param[in] pData points to the matrix data array.
  553. */
  554. void arm_mat_init_q15(
  555. arm_matrix_instance_q15 * S,
  556. uint16_t nRows,
  557. uint16_t nColumns,
  558. q15_t * pData);
  559. /**
  560. * @brief Floating-point matrix initialization.
  561. * @param[in,out] S points to an instance of the floating-point matrix structure.
  562. * @param[in] nRows number of rows in the matrix.
  563. * @param[in] nColumns number of columns in the matrix.
  564. * @param[in] pData points to the matrix data array.
  565. */
  566. void arm_mat_init_f32(
  567. arm_matrix_instance_f32 * S,
  568. uint16_t nRows,
  569. uint16_t nColumns,
  570. float32_t * pData);
  571. /**
  572. * @brief Floating-point matrix inverse.
  573. * @param[in] src points to the instance of the input floating-point matrix structure.
  574. * @param[out] dst points to the instance of the output floating-point matrix structure.
  575. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  576. * If the input matrix is singular (does not have an inverse), then the algorithm terminates and returns error status ARM_MATH_SINGULAR.
  577. */
  578. arm_status arm_mat_inverse_f32(
  579. const arm_matrix_instance_f32 * src,
  580. arm_matrix_instance_f32 * dst);
  581. /**
  582. * @brief Floating-point matrix inverse.
  583. * @param[in] src points to the instance of the input floating-point matrix structure.
  584. * @param[out] dst points to the instance of the output floating-point matrix structure.
  585. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  586. * If the input matrix is singular (does not have an inverse), then the algorithm terminates and returns error status ARM_MATH_SINGULAR.
  587. */
  588. arm_status arm_mat_inverse_f64(
  589. const arm_matrix_instance_f64 * src,
  590. arm_matrix_instance_f64 * dst);
  591. /**
  592. * @brief Floating-point Cholesky decomposition of Symmetric Positive Definite Matrix.
  593. * @param[in] src points to the instance of the input floating-point matrix structure.
  594. * @param[out] dst points to the instance of the output floating-point matrix structure.
  595. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  596. * If the input matrix does not have a decomposition, then the algorithm terminates and returns error status ARM_MATH_DECOMPOSITION_FAILURE.
  597. * If the matrix is ill conditioned or only semi-definite, then it is better using the LDL^t decomposition.
  598. * The decomposition is returning a lower triangular matrix.
  599. */
  600. arm_status arm_mat_cholesky_f64(
  601. const arm_matrix_instance_f64 * src,
  602. arm_matrix_instance_f64 * dst);
  603. /**
  604. * @brief Floating-point Cholesky decomposition of Symmetric Positive Definite Matrix.
  605. * @param[in] src points to the instance of the input floating-point matrix structure.
  606. * @param[out] dst points to the instance of the output floating-point matrix structure.
  607. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  608. * If the input matrix does not have a decomposition, then the algorithm terminates and returns error status ARM_MATH_DECOMPOSITION_FAILURE.
  609. * If the matrix is ill conditioned or only semi-definite, then it is better using the LDL^t decomposition.
  610. * The decomposition is returning a lower triangular matrix.
  611. */
  612. arm_status arm_mat_cholesky_f32(
  613. const arm_matrix_instance_f32 * src,
  614. arm_matrix_instance_f32 * dst);
  615. /**
  616. * @brief Solve UT . X = A where UT is an upper triangular matrix
  617. * @param[in] ut The upper triangular matrix
  618. * @param[in] a The matrix a
  619. * @param[out] dst The solution X of UT . X = A
  620. * @return The function returns ARM_MATH_SINGULAR, if the system can't be solved.
  621. */
  622. arm_status arm_mat_solve_upper_triangular_f32(
  623. const arm_matrix_instance_f32 * ut,
  624. const arm_matrix_instance_f32 * a,
  625. arm_matrix_instance_f32 * dst);
  626. /**
  627. * @brief Solve LT . X = A where LT is a lower triangular matrix
  628. * @param[in] lt The lower triangular matrix
  629. * @param[in] a The matrix a
  630. * @param[out] dst The solution X of LT . X = A
  631. * @return The function returns ARM_MATH_SINGULAR, if the system can't be solved.
  632. */
  633. arm_status arm_mat_solve_lower_triangular_f32(
  634. const arm_matrix_instance_f32 * lt,
  635. const arm_matrix_instance_f32 * a,
  636. arm_matrix_instance_f32 * dst);
  637. /**
  638. * @brief Solve UT . X = A where UT is an upper triangular matrix
  639. * @param[in] ut The upper triangular matrix
  640. * @param[in] a The matrix a
  641. * @param[out] dst The solution X of UT . X = A
  642. * @return The function returns ARM_MATH_SINGULAR, if the system can't be solved.
  643. */
  644. arm_status arm_mat_solve_upper_triangular_f64(
  645. const arm_matrix_instance_f64 * ut,
  646. const arm_matrix_instance_f64 * a,
  647. arm_matrix_instance_f64 * dst);
  648. /**
  649. * @brief Solve LT . X = A where LT is a lower triangular matrix
  650. * @param[in] lt The lower triangular matrix
  651. * @param[in] a The matrix a
  652. * @param[out] dst The solution X of LT . X = A
  653. * @return The function returns ARM_MATH_SINGULAR, if the system can't be solved.
  654. */
  655. arm_status arm_mat_solve_lower_triangular_f64(
  656. const arm_matrix_instance_f64 * lt,
  657. const arm_matrix_instance_f64 * a,
  658. arm_matrix_instance_f64 * dst);
  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_f32(
  670. const arm_matrix_instance_f32 * src,
  671. arm_matrix_instance_f32 * l,
  672. arm_matrix_instance_f32 * d,
  673. uint16_t * pp);
  674. /**
  675. * @brief Floating-point LDL decomposition of Symmetric Positive Semi-Definite Matrix.
  676. * @param[in] src points to the instance of the input floating-point matrix structure.
  677. * @param[out] l points to the instance of the output floating-point triangular matrix structure.
  678. * @param[out] d points to the instance of the output floating-point diagonal matrix structure.
  679. * @param[out] p points to the instance of the output floating-point permutation vector.
  680. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  681. * If the input matrix does not have a decomposition, then the algorithm terminates and returns error status ARM_MATH_DECOMPOSITION_FAILURE.
  682. * The decomposition is returning a lower triangular matrix.
  683. */
  684. arm_status arm_mat_ldlt_f64(
  685. const arm_matrix_instance_f64 * src,
  686. arm_matrix_instance_f64 * l,
  687. arm_matrix_instance_f64 * d,
  688. uint16_t * pp);
  689. #ifdef __cplusplus
  690. }
  691. #endif
  692. #endif /* ifndef _MATRIX_FUNCTIONS_H_ */