3
在數學,我可以通過做張量積計算內置Dot[]
,例如,這裏是一個張pts
秩6
:是否有C庫實現張量積?
SeedRandom[10];
pts = RandomReal[1, {7, 7, 7, 5, 6, 5}];
(*coeffs = {c1, c2, c3, c4}*)
coeff = BernsteinBasis[#1, Range[0, #1], #2] & @@@
[email protected]{(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]
我Google關鍵詞tensor product in C
,然後我發現大多數張量庫都是用C++編寫的,而不是ANSI C編寫的。
,所以我想知道:
- 有Ç庫,實現了
Dot[]
操作?
您可能必須使用帶有C接口的BLAS矩陣產品例程(如[cblas_gemm()](https://software.intel.com/zh-cn/node/520775)來模擬張量積。它基本上是重做那些C++張量庫所做的。 – kangshiyin
@ kangshiyin感謝您的建議。事實上,我需要一個張量積的c庫來通過* Mathematica LibraryLink * wrapper實現'b-spline函數'。請參閱[這裏](http://mathematica.stackexchange.com/questions/120384/why-does-this-librarylink-function-crash) – xyz
我相信它也可以通過矩陣產品來實現。 – kangshiyin