Rate This Document
Findability
Accuracy
Completeness
Readability

ReplaceNAN

Replaces the found NaN values in a vector with a specified value.

The function interface is declared as follows:

HmppResult HMPPS_ReplaceNAN_32f_I(float *srcDst, int32_t len, float value);

HmppResult HMPPS_ReplaceNAN_64f_I(double *srcDst, int32_t len, double value);

Parameters

Parameter

Description

Value Range

Input/Output

srcDst

Pointer to the source vector for in-place operations

The value cannot be NULL.

Input/Output

len

Vector length

(0, INT_MAX]

Input

value

Specified value

Not limited, depending on the type

Input

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 srcDst is NULL.

HMPP_STS_SIZE_ERR

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

Example

#define BUFFER_SIZE_T 10

void ReplaceNANExample(void)
{
    const float nan = 0.0/0.0;
    float src[BUFFER_SIZE_T] = {3.28, nan, 2.05, -8.41, nan, 1.69, 7.91, nan, nan, 1.55};
    float repVal = 3.14;

    HmppResult result = HMPPS_ReplaceNAN_32f_I(src, BUFFER_SIZE_T, repVal);
    printf("ReplaceNAN: result = %d.\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    printf("dst =");
    for (int i = 0; i < BUFFER_SIZE_T; i++) {
        printf("   %.2f", src[i]);
    }
    printf("\n");
}

Output:

ReplaceNAN: result = 0
dst =   3.28   3.14   2.05   -8.41   3.14   1.69   7.91   3.14   3.14   1.55