gpt4 book ai didi

c - 有没有实现张量积的C库?

转载 作者:行者123 更新时间:2023-12-02 02:01:51 25 4
gpt4 key购买 nike

Mathematica中,我可以通过内置的 Dot[] 进行张量乘积计算,例如,这里是一个等级为 pts 的张量 6 :

SeedRandom[10];
pts = RandomReal[1, {7, 7, 7, 5, 6, 5}];

(*coeffs = {c1, c2, c3, c4}*)
coeff = BernsteinBasis[#1, Range[0, #1], #2] & @@@
Thread@{(Dimensions[pts, 4] - 1), {0.1, 0.2, 0.3, 0.4}};
(*
{{0.531441,0.354294,0.098415,0.01458,0.001215,0.000054,1.*10^-6},
{0.262144,0.393216,0.24576,0.08192,0.01536,0.001536,0.000064},
{0.117649,0.302526,0.324135,0.18522,0.059535,0.010206,0.000729},
{0.1296,0.3456,0.3456,0.1536,0.0256}}
*)

(*do tensor product calculation ---> c4.(c3.(c2.(c1.pts))) *)
Fold[#2.#1 &, pts, coeff]

enter image description here

enter image description here

我 Google 了关键字 tensor product in C ,然后我发现大多数张量库都是用 C++ 编写的,而不是 ANSI C。

所以我想知道:

  • 是否有实现 Dot[] 操作的 C 库?

最佳答案

您可能必须使用 BLAS 矩阵产品例程,例如 cblas_gemm()用C接口(interface)来模拟张量积。它基本上是在重做那些 C++ 张量库所做的事情。

你的张量积

c1(1x7) * pts(7x7x7x5x6x5)

可以看作矩阵乘积

c1(1x7) * mat_pts(7x(7*7*5*6*5*6))

其中 pts 是 6 维张量,而 mat_pts 是 2-D 矩阵。

因此您可以使用矩阵乘积来计算张量乘积。

关于c - 有没有实现张量积的C库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38550065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com