MKL库---v?Add

提示:该函数属于Vector Mathematical Functions 章节

文章目录


前言

Vector Mathematical Functions章节主要提供向量之间的运算函数,Intel官网说明链接如下。https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2024-2/v-add.html#GUID-01F0BFF5-554F-4419-9758-36AE1B9CBBA1

一、v?Add函数

v?Add函数的功能是计算两个向量相加的和,适用于float,double,MKL_Complex8,MKL_Complex16类型的向量,其中?代表了传进去的数据类型,前面的四种数据类型分别对应的字母分别为s,d,c,z。

使用语法为v?Add(n, a, b, y),n为指定要计算向量的元素个数,a和b为指向输入进行计算的向量的指针,y为指向输出结果的指针。

较新版的MKL库还提供可以指导计算步长的函数,即v?AddI(n,a,inca,b,incb,y,incy),其中inca,incb和incy分别指代在a,b和y向量元素中跳跃的步长,假如a = [2 4 6 8],b = [1 3 5 7],inca和incb为2,incy为1,则计算a中[2 6]和b中[1 5]相加的结果,放到y中第1和第2个位置。

下面提供在C语言中应用v?Add的例子。

二、使用示例

1.引入库

代码如下(示例):

#include <stdio.h>
#include "mkl.h"

2.引用v?Add函数进行向量相加

代码如下(示例):

int main()
{
    float* a = (float*)mkl_calloc(4, sizeof(float), 64);
    float* b = (float*)mkl_calloc(4, sizeof(float), 64);
    float* y = (float*)mkl_calloc(4, sizeof(float), 64); // 内存分配
    for (int ii = 0; ii < 3; ii++)
    {
        a[ii] = ii * 2 + 2;
        b[ii] = ii * 2 + 1;
    }
    vsAdd(4, a, b, y);
    for (int ii = 0; ii < 3; ii++)
    {
        printf("a[%d] is %f, ", ii, a[ii]);
        printf("b[%d] is %f, ", ii, b[ii]);
        printf("y[%d] is %f\n", ii, y[ii]); // 打印计算结果
    }

    vsAddI(2, a, 2, b, 2, y, 1); // 计算元素步长为2
    for (int ii = 0; ii < 3; ii += 2)
    {
        printf("a[%d] is %f, ", ii, a[ii]);
        printf("b[%d] is %f, ", ii, b[ii]);
        printf("y[%d] is %f\n", ii, y[ii]); // 打印计算结果
    }
    mkl_free(a);
    mkl_free(b);
    mkl_free(y);
}

运行结果如下。


总结

以上即为MKL库的v?Add函数的简介和示例。

PySimpleGUI is now located on a private PyPI server. Please add to your pip command: -i https://PySimpleGUI.net/install The version you just installed should uninstalled: python -m pip uninstall PySimpleGUI python -m pip cache purge Then install the latest from the private server: python -m pip install --upgrade --extra-index-url https://PySimpleGUI.net/install PySimpleGUI You can also force a reinstall using this command and it'll install the latest regardless of what you have installed currently python -m pip install --force-reinstall --extra-index-url https://PySimpleGUI.net/install PySimpleGUI Use python3 command if you're running on the Mac or Linux Error: Can not import paddle core while this file exists: C:\Users\11628\.conda\envs\Video-subtitle-remover\lib\site-packages\paddle\base\libpaddle.pyd Traceback (most recent call last): File "F:\pytharm\Video-subtitle-remover\video-subtitle-remover\gui.py", line 17, in <module> import backend.main File "F:\pytharm\Video-subtitle-remover\video-subtitle-remover\backend\main.py", line 12, in <module> import config File "F:\pytharm\Video-subtitle-remover\video-subtitle-remover\backend\config.py", line 10, in <module> import paddle File "C:\Users\11628\.conda\envs\Video-subtitle-remover\lib\site-packages\paddle\__init__.py", line 28, in <module> from .base import core # noqa: F401 File "C:\Users\11628\.conda\envs\Video-subtitle-remover\lib\site-packages\paddle\base\__init__.py", line 36, in <module> from . import core File "C:\Users\11628\.conda\envs\Video-subtitle-remover\lib\site-packages\paddle\base\core.py", line 380, in <module> raise e File "C:\Users\11628\.conda\envs\Video-subtitle-remover\lib\site-packages\paddle\base\core.py", line 268, in <module> from . import libpaddle ImportError: generic_type: type "_gpuDeviceProperties" is already registered!
03-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值