Items tagged with codegen

Feed

Hey,

I am using codegen to generate code from Maple expressions. More specifically I want to export non quadratic matix. The export works for matrices that have more columns than rows, but not for matrices with more rows than columns. There I receive the error:

Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2

A workaround would be to transpose the matrix before the export, and to transpose on the import (in Matlab) but I don't want to overcomplicate my code. Thanks for your help!

I have attached a demonstration worksheet below.

 

## test codegen non quadratic returnarray

## works
#Myfun := Matrix(3,3)

## works
#Myfun := Matrix(2,3):Myfun(2,3):= 3*b;

## does not work
Myfun := Matrix(3,2):Myfun(3,2):= 3*b;

Myfun := Matrix(3, 2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 3*b})

(1)

Myfun(1):= 7*a;

Myfun := Matrix(3, 2, {(1, 1) = 7*a, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 3*b})

(2)

## codegen works best with arraybased matrices, and call by reference becomes possible

returnArray:= convert(Myfun,matrix)

returnArray := Matrix(3, 2, {(1, 1) = 7*a, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 3*b})

(3)

codegen[makeproc](Myfun,[a,b])

Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2

 

codegen[makeproc](returnArray,[returnArray,a,b])

Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2

 

codegen[makeproc](returnArray,[a,b])

Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2

 

 


 

Download codegen_rectangular_matrix.mw

 

Hi Maple Users

I am trying to use GRADIENT (with(codegen)) with a proc that includes hypergeom function but it produces the following error:

Error, (in GRAD/givedname) incorrect syntax in parse: unexpected end of input (near 4th character of parsed string)

When I remove the bits including hepergeom function it works so there seems to be some parsing problem with hypergeom. The proc is below ( I have simplified the code by assignig values to some variables). Any help is appreciated.

OV := proc(d1, d2, o)
    local noc, lambda1, lambda2, nu1, nu2, z1, z2, a1, a2, p1, p2, x1, x2, Be1, Be2, q1, q2, w1, w2, aprime, zprime, nx, nBe;
    local hg1, hg2, hg3, hg4;
       
    lambda1 := 5.22;
    lambda2 := 2.36;
    nu1 := 12.96;
    nu2 := 4.23;
    z1 := 4.99;
    z2 := 1.43;
    
    a1 := lambda1 * nu1;
    a2 := lambda2 * nu2;
    
    p1 := 1;
    p2 := 1;


    x1 := exp(a1/z1 + lnGAMMA(d1/z1 + 1) - d1/z1 * ln(a1/z1));
    x2 := exp(a2/z2 + lnGAMMA(d2/z2 + 1) - d2/z2 * ln(a2/z2));
    
    Be1 := 1 / (GAMMA(d1/z1 + 1, a1/z1) * x1 / GAMMA(d1/z1 + 1));
    Be2 := 1 / (GAMMA(d2/z2 + 1, a2/z2) * x2 / GAMMA(d2/z2 + 1));
    
    q1 := lambda1 * nu1 * Be1;
    q2 := lambda2 * nu2 * Be2;
        
     hg1 := hypergeom([p1, -d1 / z1 + 1 , a1 / z1 + p1 + 1], [a1 / z1 + p1], -z1 / a1);
     hg2 := hypergeom([-d1 / z1 + 1, p1 + 1, a1 / z1 + p1 + 2], [a1 / z1 + p1 + 1], -z1 / a1);
     hg3 := hypergeom([p2, -d2 / z2 + 1 , a2 / z2 + p2 + 1], [a2 / z2 + p2],-z2 / a2 );
     hg4 := hypergeom([-d2 / z2 + 1, p2 + 1, a2 / z2 + p2 + 2], [a2 / z2 + p2 + 1], -z2 / a2);
     
    w1 := z1 - q1 + a1 * (a1 + p1 * z1) * hg1 / ((a1 + p1 * z1 + z1) * p1 * hg2 );
                    
    w2 := z2 - q2 + a2 * (a2 + p2 * z2) * hg3 / ((a2 + p2 * z2 + z2) * p2 * hg4 );
    
    aprime := q1 + q2;
    zprime := (w1 * q1 + w2 * q2) / aprime;

    nx := exp(aprime/zprime + lnGAMMA(o/zprime + 1) - o/zprime * ln(aprime/zprime));
    nBe := 1 / (GAMMA(o/zprime + 1, aprime/zprime) * nx / GAMMA(o/zprime + 1));
          
end proc:

GRADIENT(OV);

 

I'm trying to use the CodeGeneration package to generate code for a series expansion. I'd like to wrap it in a function that specifies the arguments, so that the code generation package can generate a complete function definition along with definitions for all the temporary variables.

with(CodeGeneration):
f := proc(r): x->r end proc:
to_translate := f(convert(series(sin(x),x,20),polynom));

to_translate := proc (x) options operator, arrow; x-(1/6)*x^3+(1/120)*x^5-(1/5040)*x^7+(1/362880)*x^9-(1/39916800)*x^11+(1/6227020800)*x^13-(1/1307674368000)*x^15+(1/355687428096000)*x^17-(1/121645100408832000)*x^19 end proc


CodeGeneration['C']( to_translate );


Warning, procedure/module options ignored
double to_translate (double x)
{
  return(r);
}

Instead of using the value for 'r' passed in, CodeGenerate is producing a function which returns the bare symbol 'r' which is treated as a double. It shouldn't be an issue with lazy evalution because 'to_translate' is evaluated on the statement before the call to CodeGeneration, and to_translate has the full expression that I want to generate code for. How do I get CodeGeneration to produce the intented result?

that can run without maple using my own maple code?

And how about Maplesim? I heard that Maplesim can generate executable file

Hello,

I use maple for the determination of the symbolic relations between the geometric relations on multibody system.

I would like to create a dll function for the functions that I have determined symbolically.

I have already a paper presenting : 
- the transformation Maple --> code C with the package with(CodeGeneration)
- and the transformation code C --> another software.

I would like to directly create a dll function from my maple function with using code C. Is it possible and how ?

Thanks a lot for your help.

 

Hi all,

I'm using MAPLE 13 and I'd like to know if someone knows how to generate the variables associated to the CodeGeneration for C code. At this moment I need to create manually the variable generated from the C code.

Example:

JJ := Jacobian(convert(Pint, Vector), [P1xenu, P1yenu, P1zenu, roll, pitch, yaw, D1xbody, D1ybody, P2xenu, P2yenu, P2zenu, ROLL, PITCH, YAW, D2xbody, D2ybody]);

CodeGeneration['C'](JJ, optimize);

Output:

t1 = cov2 * cov2;
t2 = cov1 * cov1;
t4 = 0.1e1 / (t1 + t2);
t5.......

And in the C code I need to create:

double t1, t2, t3..... manually

I can I solve this issue?

Best regards

André Dias

The version 16 of Maple does not know the function "pow", it is replaced by "power". Nevertheless, the codegen[optimize] procedure still generates it!  Moreower, it's not optimal even to write poser(..., 1/2)  as, most probably, the function sqrt must run faster. 

  Here's an example: (the function being optimized just contains some nested square roots)

> iang10 := [codegen[optimize](Re(int11), tryhard)];
[ 2 t17
Page 1 of 1