Rate This Document
Findability
Accuracy
Completeness
Readability

mrecip

Calculate the reciprocal of a real-number matrix.

The function interface declaration is as follows:

Operations on numbers of the float type:

void (vsip_mrecip_f)(const vsip_mview_f *a, const vsip_mview_f *r);

Parameters

Parameter

Description

Value Range

Input/Output

a

Pointer to the source real-number 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 MrecipExample()
{
    int32_t row = 4;
    int32_t col = 3;
    int64_t rowStride = 1;
    int64_t colStride = row * rowStride;
    uint64_t offset = 0;
    int32_t len = col * colStride + offset;
    float *src = (float *)malloc(len * sizeof(float));
    float *dst = (float *)malloc(len * sizeof(float));
    for (int32_t i = 0; i < len; ++i) {
        src[i] = (i + 1) / 10.0f;
    }

    vsip_block_f *block_a = vsip_blockbind_f(src, len, VSIP_MEM_NONE);
    vsip_block_f *block_r = vsip_blockbind_f(dst, len, VSIP_MEM_NONE);

    vsip_mview_f *a = vsip_mbind_f(block_a, offset, colStride, col, rowStride, row);
    vsip_blockadmit_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_mrecip_f(a, r);

    vsip_malldestroy_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 + j]);
        }
        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) {
    MrecipExample();
    return 0;
}

Output:

src:
0.10000    0.20000    0.30000    0.40000
0.50000    0.60000    0.70000    0.80000
0.90000    1.00000    1.10000    1.20000

dst:
10.00000    5.00000    3.33333    2.50000
2.00000    1.66667    1.42857    1.25000
1.11111    1.00000    0.90909    0.83333