2016-07-24 45 views
3

數學,我可以通過做張量積計算內置Dot[],例如,這裏是一個張pts6是否有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] 

enter image description here

enter image description here

我Google關鍵詞tensor product in C,然後我發現大多數張量庫都是用C++編寫的,而不是ANSI C編寫的。

,所以我想知道:

  • Ç庫,實現了Dot[]操作?
+1

您可能必須使用帶有C接口的BLAS矩陣產品例程(如[cblas_gemm()](https://software.intel.com/zh-cn/node/520775)來模擬張量積。它基本上是重做那些C++張量庫所做的。 – kangshiyin

+0

@ kangshiyin感謝您的建議。事實上,我需要一個張量積的c庫來通過* Mathematica LibraryLink * wrapper實現'b-spline函數'。請參閱[這裏](http://mathematica.stackexchange.com/questions/120384/why-does-this-librarylink-function-crash) – xyz

+0

我相信它也可以通過矩陣產品來實現。 – kangshiyin

回答

3

您可能不得不使用BLAS矩陣產品例程,如帶有C接口的​​來模擬張量積。它基本上是重做那些C++張量庫所做的。

你的張量積

c1(1x7) * pts(7x7x7x5x6x5) 

可以被看作是一個矩陣乘積

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

pts其中是6-d張量,但mat_pts是2- d矩陣。

因此,您可以使用矩陣乘積來計算張量積。