arm_mat_solve_upper_triangular_f64.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mat_solve_upper_triangular_f64.c
  4. * Description: Solve linear system UT X = A with UT upper 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 UT . X = A where UT is an upper triangular matrix
  38. * @param[in] ut The upper triangular matrix
  39. * @param[in] a The matrix a
  40. * @param[out] dst The solution X of UT . X = A
  41. * @return The function returns ARM_MATH_SINGULAR, if the system can't be solved.
  42. */
  43. arm_status arm_mat_solve_upper_triangular_f64(
  44. const arm_matrix_instance_f64 * ut,
  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 ((ut->numRows != ut->numCols) ||
  52. (ut->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. int i,j,k,n,cols;
  61. float64_t *pX = dst->pData;
  62. float64_t *pUT = ut->pData;
  63. float64_t *pA = a->pData;
  64. float64_t *ut_row;
  65. float64_t *a_col;
  66. n = dst->numRows;
  67. cols = dst->numCols;
  68. for(j=0; j < cols; j ++)
  69. {
  70. a_col = &pA[j];
  71. for(i=n-1; i >= 0 ; i--)
  72. {
  73. float64_t tmp=a_col[i * cols];
  74. ut_row = &pUT[n*i];
  75. for(k=n-1; k > i; k--)
  76. {
  77. tmp -= ut_row[k] * pX[cols*k+j];
  78. }
  79. if (ut_row[i]==0.0)
  80. {
  81. return(ARM_MATH_SINGULAR);
  82. }
  83. tmp = tmp / ut_row[i];
  84. pX[i*cols+j] = tmp;
  85. }
  86. }
  87. status = ARM_MATH_SUCCESS;
  88. }
  89. /* Return to application */
  90. return (status);
  91. }
  92. /**
  93. @} end of MatrixInv group
  94. */