我要评分
获取效率
正确性
完整性
易理解

SumLn

Calculates the sum of natural logarithms of all elements in a vector.

The calculation formula is: .

The function interface declaration is as follows:

  • Operations on floating-point numbers:

    HmppResult HMPPS_SumLn_32f(const float* src, int32_t len, float* sum);

    HmppResult HMPPS_SumLn_64f(const double* src, int32_t len, double* sum);

  • Variable-length operations on floating-point numbers:

    HmppResult HMPPS_SumLn_32f64f(const float* src, int32_t len, double* sum);

  • Operations converting an integer to a floating-point number:

    HmppResult HMPPS_SumLn_16s32f(const int16_t* src, int32_t len, float* sum);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the source vector

The value cannot be NULL.

Input

len

Vector length

(0, INT_MAX]

Input

sum

Pointer to the result

The value cannot be NULL.

Output

Return Value

  • Success: HMPP_STS_NO_ERR
  • Failure: An error code is returned.

Error Codes

Error Code

Description

HMPP_STS_NULL_PTR_ERR

The value of src or sum is NULL.

HMPP_STS_SIZE_ERR

The value of len is less than or equal to 0.

Example

#define  BUFFER_SIZE_T 10

void SumLnExample(void)
{
    float src[BUFFER_SIZE_T] = {11.44, 0.07, 10.23, 8.78, 0.30, 1.72, 1.37, 3.39, 7.37, 7.40};
    float dst = 0.00;  

    HmppResult result = HMPPS_SumLn_32f(src, BUFFER_SIZE_T, &dst);
    printf("result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    printf("dst = %.2f \n", dst);
} 

Output:

result = 0
dst = 5954088960.00