cmmag
Calculate the magnitude of a complex matrix.
The function interface declaration is as follows:
Operations on numbers of the float type:
void (vsip_cmmag_f)(const vsip_cmview_f *a, const vsip_mview_f *r);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
a |
Pointer to the source complex matrix |
The value cannot be NULL. |
Input |
r |
Pointer to the destination real-number 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 CmmagExample()
{
int32_t row = 4;
int32_t col = 3;
int64_t rowStride = 1;
int64_t colStride = row * rowStride;
uint64_t offset = 0;
int32_t srcLen = 2 * (col * colStride + offset);
int32_t dstLen = col * colStride + offset;
float *src = (float *)malloc(srcLen * sizeof(float));
float *dst = (float *)malloc(dstLen * sizeof(float));
for (int32_t i = 0; i < srcLen; ++i) {
src[i] = i / 10.0f;
}
vsip_cblock_f *block_a = vsip_cblockbind_f(src, NULL, srcLen, VSIP_MEM_NONE);
vsip_block_f *block_r = vsip_blockbind_f(dst, dstLen, 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_mview_f *r = vsip_mbind_f(block_r, offset, colStride, col, rowStride, row);
vsip_blockadmit_f(block_r, VSIP_TRUE);
vsip_cmmag_f(a, r);
vsip_cmalldestroy_f(a);
vsip_malldestroy_f(r);
printf("src:\n");
for (int32_t i = 0; i < col; ++i) {
for (int32_t j = 0; j < row; ++j) {
printf("%.5f ", src[i * row * 2 + j * 2]);
printf("%.5f ", src[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 + j]);
}
printf("\n");
}
free(src);
free(dst);
}
int main(void) {
CmmagExample();
return 0;
}
Output:
src: 0.00000 0.10000 0.20000 0.30000 0.40000 0.50000 0.60000 0.70000 0.80000 0.90000 1.00000 1.10000 1.20000 1.30000 1.40000 1.50000 1.60000 1.70000 1.80000 1.90000 2.00000 2.10000 2.20000 2.30000 dst: 0.10000 0.36056 0.64031 0.92195 1.20416 1.48661 1.76918 2.05183 2.33452 2.61725 2.90000 3.18277
Parent topic: Matrix Operation Functions