Question: How to fix this Error, (in Compiler:-Compile) Array parameter types must specify a hardware datatype?

I was trying to answer a question by torabi 25, August 14, 2017 to speed up his calculations. I got this idea of converting the original code to a procedure - that was not easy, run the procedure and obtain a value of time() to establish a baseline, and making sure the answer from the procedure was the same as from torabi 25. So far so good. Then I would compile the procedure, execute it, and get another value for time(). Hopefully the compiled procedure will be faster than the uncompiled procedure. I am close, but - please see if you can fix my compiler error. Thanks!


 

restart

pa := proc (k::integer, h::float, N::float, nu::float, E_m::float, E_c::float, rho_m::float, rho_c::float, d::(Matrix()))::float; local lambda_m::float, lambda_c::float, mu_m::float, mu_c::float, Z::float, U::float, S::float, e2::float, f::float, W::float, z::float, b::integer, alpha::integer, beta::integer; lambda_m := nu*E_m/((1+nu)*(1-2*nu)); lambda_c := nu*E_c/((1+nu)*(1-2*nu)); mu_m := E_m/(2+2*nu); mu_c := E_c/(2+2*nu); Z := rho_m+(rho_c-rho_m)*(1/2+z/h)^N; U := lambda_m+(lambda_c-lambda_m)*(1/2+z/h)^N; S := mu_m+(mu_c-mu_m)*(1/2+z/h)^N; e2 := 0.; for alpha from 0 to k-2 do for b from 0 to k-2 do for beta from 0 to k-1 do f := 2*S*d[beta+1, alpha+1]*W(beta)*sqrt(alpha+1/2)*orthopoly:-P(alpha, z)*d[2, b+1]*sqrt(b+1/2)*orthopoly:-P(b, z); e2 := e2-(int(f, z = -(1/2)*h .. (1/2)*h)) end do end do end do end proc

NULL

k := 6; h := 1.; N := .5; nu := .3; E_m := 7.0*10^10; E_c := 3.80*10^11; rho_m := 2702.; rho_c := 3800.; d := Matrix([evalf([0, 0, 0, 0, 0, 0, 0, 0]), evalf([sqrt(3), 0, 0, 0, 0, 0, 0, 0]), evalf([0, sqrt(15), 0, 0, 0, 0, 0, 0]), evalf([sqrt(7), 0, sqrt(35), 0, 0, 0, 0, 0]), evalf([0, sqrt(27), 0, sqrt(63), 0, 0, 0, 0]), evalf([sqrt(11), 0, sqrt(55), 0, sqrt(99), 0, 0, 0]), evalf([0, sqrt(39), 0, sqrt(91), 0, sqrt(143), 0, 0]), evalf([sqrt(15), 0, sqrt(75), 0, sqrt(135), 0, sqrt(195), 0])], datatype = float[8])

time(pa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d))

2.156

(1)

pa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d)

-0.3192307695e12*W(1)+0.4396880666e12*W(3)-0.1474586302e12*W(5)-0.9235575679e11*W(2)+0.1979090107e12*W(4)

(2)

# Original Answer:        -3.192307692*10^11*W(1)+4.396880662*10^11*W(3)-1.474586301*10^11*W(5)-9.235575669*10^10*W(2)+1.979090105*10^11*W(4);NULL

cpa := Compiler:-Compile(pa)

Error, (in Compiler:-Compile) Array parameter types must specify a hardware datatype

 

time(cpa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d))

0.

(3)

cpa(k, h, N, nu, E_m, E_c, rho_m, rho_c, d)

NULL


 

Download for_(5).mw

 

Please Wait...