distance_functions_f16.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /******************************************************************************
  2. * @file distance_functions_f16.h
  3. * @brief Public header file for NMSIS DSP Library
  4. * @version V1.10.0
  5. * @date 08 July 2021
  6. * Target Processor: RISC-V Cores
  7. ******************************************************************************/
  8. /*
  9. * Copyright (c) 2010-2020 Arm Limited or its affiliates. All rights reserved.
  10. * Copyright (c) 2019 Nuclei Limited. All rights reserved.
  11. *
  12. * SPDX-License-Identifier: Apache-2.0
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the License); you may
  15. * not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  22. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. #ifndef DISTANCE_FUNCTIONS_F16_H_
  27. #define DISTANCE_FUNCTIONS_F16_H_
  28. #include "riscv_math_types_f16.h"
  29. #include "riscv_math_memory.h"
  30. #include "dsp/none.h"
  31. #include "dsp/utils.h"
  32. /* 6.14 bug */
  33. #include "dsp/statistics_functions_f16.h"
  34. #include "dsp/basic_math_functions_f16.h"
  35. #include "dsp/fast_math_functions_f16.h"
  36. #ifdef __cplusplus
  37. extern "C"
  38. {
  39. #endif
  40. #if defined(RISCV_FLOAT16_SUPPORTED)
  41. /**
  42. * @brief Euclidean distance between two vectors
  43. * @param[in] pA First vector
  44. * @param[in] pB Second vector
  45. * @param[in] blockSize vector length
  46. * @return distance
  47. */
  48. float16_t riscv_euclidean_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
  49. /**
  50. * @brief Bray-Curtis distance between two vectors
  51. * @param[in] pA First vector
  52. * @param[in] pB Second vector
  53. * @param[in] blockSize vector length
  54. * @return distance
  55. */
  56. float16_t riscv_braycurtis_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
  57. /**
  58. * @brief Canberra distance between two vectors
  59. *
  60. * This function may divide by zero when samples pA[i] and pB[i] are both zero.
  61. * The result of the computation will be correct. So the division per zero may be
  62. * ignored.
  63. *
  64. * @param[in] pA First vector
  65. * @param[in] pB Second vector
  66. * @param[in] blockSize vector length
  67. * @return distance
  68. */
  69. float16_t riscv_canberra_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
  70. /**
  71. * @brief Chebyshev distance between two vectors
  72. * @param[in] pA First vector
  73. * @param[in] pB Second vector
  74. * @param[in] blockSize vector length
  75. * @return distance
  76. */
  77. float16_t riscv_chebyshev_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
  78. /**
  79. * @brief Cityblock (Manhattan) distance between two vectors
  80. * @param[in] pA First vector
  81. * @param[in] pB Second vector
  82. * @param[in] blockSize vector length
  83. * @return distance
  84. */
  85. float16_t riscv_cityblock_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
  86. /**
  87. * @brief Correlation distance between two vectors
  88. *
  89. * The input vectors are modified in place !
  90. *
  91. * @param[in] pA First vector
  92. * @param[in] pB Second vector
  93. * @param[in] blockSize vector length
  94. * @return distance
  95. */
  96. float16_t riscv_correlation_distance_f16(float16_t *pA,float16_t *pB, uint32_t blockSize);
  97. /**
  98. * @brief Cosine distance between two vectors
  99. *
  100. * @param[in] pA First vector
  101. * @param[in] pB Second vector
  102. * @param[in] blockSize vector length
  103. * @return distance
  104. */
  105. float16_t riscv_cosine_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
  106. /**
  107. * @brief Jensen-Shannon distance between two vectors
  108. *
  109. * This function is assuming that elements of second vector are > 0
  110. * and 0 only when the corresponding element of first vector is 0.
  111. * Otherwise the result of the computation does not make sense
  112. * and for speed reasons, the cases returning NaN or Infinity are not
  113. * managed.
  114. *
  115. * When the function is computing x log (x / y) with x 0 and y 0,
  116. * it will compute the right value (0) but a division per zero will occur
  117. * and shoudl be ignored in client code.
  118. *
  119. * @param[in] pA First vector
  120. * @param[in] pB Second vector
  121. * @param[in] blockSize vector length
  122. * @return distance
  123. */
  124. float16_t riscv_jensenshannon_distance_f16(const float16_t *pA,const float16_t *pB,uint32_t blockSize);
  125. /**
  126. * @brief Minkowski distance between two vectors
  127. *
  128. * @param[in] pA First vector
  129. * @param[in] pB Second vector
  130. * @param[in] n Norm order (>= 2)
  131. * @param[in] blockSize vector length
  132. * @return distance
  133. */
  134. float16_t riscv_minkowski_distance_f16(const float16_t *pA,const float16_t *pB, int32_t order, uint32_t blockSize);
  135. #endif /*defined(RISCV_FLOAT16_SUPPORTED)*/
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif /* ifndef _DISTANCE_FUNCTIONS_F16_H_ */