arm_chebyshev_distance_f64.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_chebyshev_distance_f64.c
  4. * Description: Chebyshev distance between two vectors
  5. *
  6. * $Date: 10 August 2022
  7. * $Revision: V1.10.1
  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/distance_functions.h"
  29. #include <limits.h>
  30. #include <math.h>
  31. /**
  32. @addtogroup Chebyshev
  33. @{
  34. */
  35. /**
  36. * @brief Chebyshev distance between two vectors
  37. * @param[in] pA First vector
  38. * @param[in] pB Second vector
  39. * @param[in] blockSize vector length
  40. * @return distance
  41. *
  42. */
  43. float64_t arm_chebyshev_distance_f64(const float64_t *pA,const float64_t *pB, uint32_t blockSize)
  44. {
  45. float64_t diff=0., maxVal,tmpA, tmpB;
  46. uint32_t blkCnt;
  47. maxVal = F64_MIN;
  48. #if defined(ARM_MATH_NEON) && defined(__aarch64__)
  49. float64x2_t diffV , tmpAV , tmpBV , maxValV ;
  50. maxValV = vdupq_n_f64(maxVal);
  51. blkCnt = blockSize >> 1U ;
  52. while(blkCnt > 0U)
  53. {
  54. tmpAV = vld1q_f64(pA);
  55. tmpBV = vld1q_f64(pB);
  56. diffV = vabsq_f64((vsubq_f64(tmpAV, tmpBV)));
  57. maxValV = vmaxq_f64(maxValV, diffV);
  58. pA+=2;
  59. pB+=2;
  60. blkCnt--;
  61. }
  62. maxVal =vgetq_lane_f64(maxValV, 0);
  63. if(maxVal < vgetq_lane_f64(maxValV, 1))
  64. {
  65. maxVal = vgetq_lane_f64(maxValV, 1);
  66. }
  67. blkCnt = blockSize & 1;
  68. #else
  69. blkCnt = blockSize;
  70. #endif
  71. while(blkCnt > 0)
  72. {
  73. tmpA = *pA++;
  74. tmpB = *pB++;
  75. diff = fabs(tmpA - tmpB);
  76. if (diff > maxVal)
  77. {
  78. maxVal = diff;
  79. }
  80. blkCnt --;
  81. }
  82. return(maxVal);
  83. }
  84. /**
  85. * @} end of Chebyshev group
  86. */