鲲鹏社区首页
中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

cmadd

复数矩阵的加法运算。

函数接口声明如下:

float型函数操作:

void (vsip_cmadd_f)(const vsip_cmview_f *a, const vsip_cmview_f *b, const vsip_cmview_f *r);

参数

参数名

描述

取值范围

输入/输出

a

指向源复数矩阵的指针。

非空

输入

b

指向源复数矩阵的指针。

非空

输入

r

指向目标复数矩阵的指针。

非空

输出

异常输入

空指针输入时,函数直接返回。

示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "kvsip.h"
#include "vsip.h"
#include "vsip_type.h"

void CmaddExample()
{
    int32_t row = 4;
    int32_t col = 3;
    int64_t rowStride = 1;
    int64_t colStride = row * rowStride;
    uint64_t offset = 0;
    int32_t len = 2 * (col * colStride + offset);
    float *src1 = (float *)malloc(len * sizeof(float));
    float *src2 = (float *)malloc(len * sizeof(float));
    float *dst = (float *)malloc(len * sizeof(float));
    for (int32_t i = 0; i < len; ++i) {
        src1[i] = 1 + i / 100.0f;
        src2[i] = 2 + i / 100.0f;
    }

    vsip_cblock_f *block_a = vsip_cblockbind_f(src1, NULL, len, VSIP_MEM_NONE);
    vsip_cblock_f *block_b = vsip_cblockbind_f(src2, NULL, len, VSIP_MEM_NONE);
    vsip_cblock_f *block_r = vsip_cblockbind_f(dst, NULL, len, VSIP_MEM_NONE);

    vsip_cmview_f *a = vsip_cmbind_f(block_a, offset, colStride, col, rowStride, row);
    vsip_cblockadmit_f(block_a, VSIP_TRUE);
    vsip_cmview_f *b = vsip_cmbind_f(block_b, offset, colStride, col, rowStride, row);
    vsip_cblockadmit_f(block_b, VSIP_TRUE);
    vsip_cmview_f *r = vsip_cmbind_f(block_r, offset, colStride, col, rowStride, row);
    vsip_cblockadmit_f(block_r, VSIP_TRUE);

    vsip_cmadd_f(a, b, r);

    vsip_cmalldestroy_f(a);
    vsip_cmalldestroy_f(b);
    vsip_cmalldestroy_f(r);

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

    free(src1);
    free(src2);
    free(dst);
}

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

运行结果:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
src1:
1.00000 1.01000    1.02000 1.03000    1.04000 1.05000    1.06000 1.07000
1.08000 1.09000    1.10000 1.11000    1.12000 1.13000    1.14000 1.15000
1.16000 1.17000    1.18000 1.19000    1.20000 1.21000    1.22000 1.23000

src2:
2.00000 2.01000    2.02000 2.03000    2.04000 2.05000    2.06000 2.07000
2.08000 2.09000    2.10000 2.11000    2.12000 2.13000    2.14000 2.15000
2.16000 2.17000    2.18000 2.19000    2.20000 2.21000    2.22000 2.23000

dst:
3.00000 3.02000    3.04000 3.06000    3.08000 3.10000    3.12000 3.14000
3.16000 3.18000    3.20000 3.22000    3.24000 3.26000    3.28000 3.30000
3.32000 3.34000    3.36000 3.38000    3.40000 3.42000    3.44000 3.46000