cmadd
Add complex matrices.
The function interface declaration is as follows:
Operations on numbers of the float type:
void (vsip_cmadd_f)(const vsip_cmview_f *a, const vsip_cmview_f *b, const vsip_cmview_f *r);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
a |
Pointer to the source complex matrix |
The value cannot be NULL. |
Input |
b |
Pointer to the source complex matrix |
The value cannot be NULL. |
Input |
r |
Pointer to the destination complex matrix |
The value cannot be NULL. |
Output |
Abnormal Input
When a null pointer is input, the function directly returns a result.
Example
#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;
}
Output:
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
Parent topic: Matrix Operation Functions