No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

89 líneas
2.0 KiB

  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cosine_distance_f16.c
  4. * Description: Cosine 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 CosineDist Cosine distance
  37. Cosine distance
  38. */
  39. /**
  40. @addtogroup CosineDist
  41. @{
  42. */
  43. /**
  44. * @brief Cosine distance between two vectors
  45. *
  46. * @param[in] pA First vector
  47. * @param[in] pB Second vector
  48. * @param[in] blockSize vector length
  49. * @return distance
  50. *
  51. * @par Description
  52. * cosine_distance(u,v) is 1 - u . v / (Norm(u) Norm(v))
  53. */
  54. float16_t arm_cosine_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize)
  55. {
  56. float16_t pwra,pwrb,dot,tmp;
  57. arm_power_f16(pA, blockSize, &pwra);
  58. arm_power_f16(pB, blockSize, &pwrb);
  59. arm_dot_prod_f16(pA,pB,blockSize,&dot);
  60. arm_sqrt_f16((_Float16)pwra * (_Float16)pwrb, &tmp);
  61. return(1.0f16 - (_Float16)dot / (_Float16)tmp);
  62. }
  63. /**
  64. * @} end of CosineDist group
  65. */
  66. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */