You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

138 rivejä
3.1 KiB

  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_minkowski_distance_f16.c
  4. * Description: Minkowski distance between two vectors
  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/distance_functions_f16.h"
  29. #if defined(ARM_FLOAT16_SUPPORTED)
  30. #include <limits.h>
  31. #include <math.h>
  32. /**
  33. @ingroup FloatDist
  34. */
  35. /**
  36. @defgroup Minkowski Minkowski distance
  37. Minkowski distance
  38. */
  39. /**
  40. @addtogroup Minkowski
  41. @{
  42. */
  43. /**
  44. * @brief Minkowski distance between two vectors
  45. *
  46. * @param[in] pA First vector
  47. * @param[in] pB Second vector
  48. * @param[in] order Distance order
  49. * @param[in] blockSize Number of samples
  50. * @return distance
  51. *
  52. */
  53. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  54. #include "arm_helium_utils.h"
  55. #include "arm_vec_math_f16.h"
  56. float16_t arm_minkowski_distance_f16(const float16_t *pA,const float16_t *pB, int32_t order, uint32_t blockSize)
  57. {
  58. uint32_t blkCnt;
  59. f16x8_t a, b, tmpV, sumV;
  60. sumV = vdupq_n_f16(0.0f);
  61. blkCnt = blockSize >> 3;
  62. while (blkCnt > 0U) {
  63. a = vld1q(pA);
  64. b = vld1q(pB);
  65. tmpV = vabdq(a, b);
  66. tmpV = vpowq_f16(tmpV, vdupq_n_f16(order));
  67. sumV = vaddq(sumV, tmpV);
  68. pA += 8;
  69. pB += 8;
  70. blkCnt--;
  71. }
  72. /*
  73. * tail
  74. * (will be merged thru tail predication)
  75. */
  76. blkCnt = blockSize & 7;
  77. if (blkCnt > 0U) {
  78. mve_pred16_t p0 = vctp16q(blkCnt);
  79. a = vldrhq_z_f16(pA, p0);
  80. b = vldrhq_z_f16(pB, p0);
  81. tmpV = vabdq(a, b);
  82. tmpV = vpowq_f16(tmpV, vdupq_n_f16(order));
  83. sumV = vaddq_m(sumV, sumV, tmpV, p0);
  84. }
  85. return (powf((float32_t)vecAddAcrossF16Mve(sumV), (1.0f / (float32_t) order)));
  86. }
  87. #else
  88. float16_t arm_minkowski_distance_f16(const float16_t *pA,const float16_t *pB, int32_t order, uint32_t blockSize)
  89. {
  90. _Float16 sum;
  91. uint32_t i;
  92. sum = 0.0f16;
  93. for(i=0; i < blockSize; i++)
  94. {
  95. sum += (_Float16)powf(fabsf((float32_t)((_Float16)pA[i] - (_Float16)pB[i])),order);
  96. }
  97. return(_Float16)(powf((float32_t)sum,(1.0f/(float32_t)order)));
  98. }
  99. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  100. /**
  101. * @} end of Minkowski group
  102. */
  103. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */