arm_mat_solve_lower_triangular_f64.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mat_solve_lower_triangular_f64.c
  4. * Description: Solve linear system LT X = A with LT lower triangular matrix
  5. *
  6. * $Date: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #include "dsp/matrix_functions.h"
  29. /**
  30. @ingroup groupMatrix
  31. */
  32. /**
  33. @addtogroup MatrixInv
  34. @{
  35. */
  36. /**
  37. * @brief Solve LT . X = A where LT is a lower triangular matrix
  38. * @param[in] lt The lower triangular matrix
  39. * @param[in] a The matrix a
  40. * @param[out] dst The solution X of LT . X = A
  41. * @return The function returns ARM_MATH_SINGULAR, if the system can't be solved.
  42. */
  43. arm_status arm_mat_solve_lower_triangular_f64(
  44. const arm_matrix_instance_f64 * lt,
  45. const arm_matrix_instance_f64 * a,
  46. arm_matrix_instance_f64 * dst)
  47. {
  48. arm_status status; /* status of matrix inverse */
  49. #ifdef ARM_MATH_MATRIX_CHECK
  50. /* Check for matrix mismatch condition */
  51. if ((lt->numRows != lt->numCols) ||
  52. (lt->numRows != a->numRows) )
  53. {
  54. /* Set status as ARM_MATH_SIZE_MISMATCH */
  55. status = ARM_MATH_SIZE_MISMATCH;
  56. }
  57. else
  58. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  59. {
  60. /* a1 b1 c1 x1 = a1
  61. b2 c2 x2 a2
  62. c3 x3 a3
  63. x3 = a3 / c3
  64. x2 = (a2 - c2 x3) / b2
  65. */
  66. int i,j,k,n,cols;
  67. float64_t *pX = dst->pData;
  68. float64_t *pLT = lt->pData;
  69. float64_t *pA = a->pData;
  70. float64_t *lt_row;
  71. float64_t *a_col;
  72. n = dst->numRows;
  73. cols = dst->numCols;
  74. for(j=0; j < cols; j ++)
  75. {
  76. a_col = &pA[j];
  77. for(i=0; i < n ; i++)
  78. {
  79. float64_t tmp=a_col[i * cols];
  80. lt_row = &pLT[n*i];
  81. for(k=0; k < i; k++)
  82. {
  83. tmp -= lt_row[k] * pX[cols*k+j];
  84. }
  85. if (lt_row[i]==0.0)
  86. {
  87. return(ARM_MATH_SINGULAR);
  88. }
  89. tmp = tmp / lt_row[i];
  90. pX[i*cols+j] = tmp;
  91. }
  92. }
  93. status = ARM_MATH_SUCCESS;
  94. }
  95. /* Return to application */
  96. return (status);
  97. }
  98. /**
  99. @} end of MatrixInv group
  100. */