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

cvdot

Compute the dot product of complex vectors.

The function interface declaration is as follows:

Operations on numbers of the float type:

vsip_cscalar_f (vsip_cvdot_f)(const vsip_cvview_f *a, const vsip_cvview_f *b);

Parameters

Parameter

Description

Value Range

Input/Output

a

Pointer to the source complex vector

The value cannot be NULL.

Input

b

Pointer to the source complex vector

The value cannot be NULL.

Input

Abnormal Input

When a null pointer is input, the function directly returns a complex NaN value. When the data length is 0, the function returns a complex zero.

Example

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "kvsip.h"
#include "vsip.h"
#include "vsip_type.h"

#define BUFFER_SIZE_T 10
void CvdotExample()
{
    float src1[BUFFER_SIZE_T] = {1.64f, 1.63f, -1.09f, 0.71f, -3.20f, -0.43f, 0.41f, -4.83f, 5.36f, -4.40f};
    float src2[BUFFER_SIZE_T] = {-0.23f, 3.15f, -7.11f, 5.94f, 4.38f, 6.51f, -7.28f, -3.27f, 1.08f, 3.28f};
    int64_t stride = 1;
    int64_t cvLen = BUFFER_SIZE_T / 2;
    uint64_t offset = 0;

    vsip_cblock_f *block_a = vsip_cblockbind_f(src1, NULL, cvLen, VSIP_MEM_NONE);
    vsip_cblock_f *block_b = vsip_cblockbind_f(src2, NULL, cvLen, VSIP_MEM_NONE);

    vsip_cvview_f *a = vsip_cvbind_f(block_a, offset, stride, cvLen);
    vsip_cblockadmit_f(block_a, VSIP_TRUE);
    vsip_cvview_f *b = vsip_cvbind_f(block_b, offset, stride, cvLen);
    vsip_cblockadmit_f(block_b, VSIP_TRUE);

    vsip_cscalar_f dst = vsip_cvdot_f(a, b);

    vsip_cvalldestroy_f(a);
    vsip_cvalldestroy_f(b);

    printf("src1:\n");
    for (int32_t i = 0; i < cvLen; ++i) {
        printf("%.4f ", src1[i * 2]);
        printf("%.4f    ", src1[i * 2 + 1]);
    }
    printf("\nsrc2:\n");
    for (int32_t i = 0; i < cvLen; ++i) {
        printf("%.4f ", src2[i * 2]);
        printf("%.4f    ", src2[i * 2 + 1]);
    }
    printf("\ndst: %.4f %.4f\n", dst.r, dst.i);
}

int main(void) {
    CvdotExample();
    return 0;
}

Output:

src1:
1.6400 1.6300    -1.0900 0.7100    -3.2000 -0.4300    0.4100 -4.8300    5.3600 -4.4000
src2:
-0.2300 3.1500    -7.1100 5.9400    4.3800 6.5100    -7.2800 -3.2700    1.0800 3.2800
dst: -11.7540 17.2035