icegood

290 Reputation

14 Badges

16 years, 183 days

MaplePrimes Activity


These are replies submitted by icegood

Thanks but it's rather minor change. For major ones i'm looking forward to have good results from Compiler:-Compile but for now i cannot even compile H itself in right way as i want. I mean

ggg:=unapply(H,y,a,b):
ggg2:=(y,a,b)->ggg(y,a,b):
s:=Compiler:-Compile(ggg2);

works with

Warning, the function names {ggg} are not recognized in the target language.

That means that compiled rather bridge to ggg than representation of H itself.

 

While 

ggg:=unapply(H,y,a,b):

s:=Compiler:-Compile(ggg);

it at least tried to comlpile H itself without success thought :(. And there is not only compiler fault. At least i don't understand why  it did argument change and... convert them to integer O_o:

cg3 = mrt_get_integer_arg( ___k___, (MRT_ARG( 1 )), 1, TYPE_NOSUCHTYPE );
cg = mrt_get_integer_arg( ___k___, (MRT_ARG( 2 )), 2, TYPE_NOSUCHTYPE );
cg1 = mrt_get_integer_arg( ___k___, (MRT_ARG( 3 )), 3, TYPE_NOSUCHTYPE );

I already installed new watcom compiler 1.9 and transmit all maple headers/lbraries there and added tmp directory. Without suceess :(



OK. Now without simplify function calls of even 4th derivative are fast! Now i need to your suggestion with evalhf of that. How to make it work?

OK. Now without simplify function calls of even 4th derivative are fast! Now i need to your suggestion with evalhf of that. How to make it work?

So, after adding opton "numerical" to unupply evalhf finally work. But... in test case. In main case it still doesn't because of

"Error, unsupported type `complex(float)` in evalhf". It doesn't work in worksheet, you can try  ( see attach main.mw).

Hot to make it work?

--------

For Axel Vogt: i will explain from the end :)  I know 'c' muuuch better than maple and i happy that many things that doesn't simply work by default in maple, just work in my code. It includes overcoming such stupid like "solutions may lost" for solve/fsolve and so on. IMHO, you had completly different task i.e. you replacing but i haven't. If you want see all code including c library project - i can send whole svn (http://subversion.tigris.org/) url for you. But i would concetrate on current questions because my library already works great on "small" test functions. Now troubles with those evalf/evalhf

 

And yes, 4th derivatives still calculated in unreasonable time. What else can i do for it?

So, after adding opton "numerical" to unupply evalhf finally work. But... in test case. In main case it still doesn't because of

"Error, unsupported type `complex(float)` in evalhf". It doesn't work in worksheet, you can try  ( see attach main.mw).

Hot to make it work?

--------

For Axel Vogt: i will explain from the end :)  I know 'c' muuuch better than maple and i happy that many things that doesn't simply work by default in maple, just work in my code. It includes overcoming such stupid like "solutions may lost" for solve/fsolve and so on. IMHO, you had completly different task i.e. you replacing but i haven't. If you want see all code including c library project - i can send whole svn (http://subversion.tigris.org/) url for you. But i would concetrate on current questions because my library already works great on "small" test functions. Now troubles with those evalf/evalhf

 

And yes, 4th derivatives still calculated in unreasonable time. What else can i do for it?

I did as you suggested but nevertheless MainFDerivative... should be function calls. But as expressions they refused to calculate numerically from external program. I mean, evalhf doesn't work in sheet itself while evalf works in sheet but EvalMapleProc in c library doesn't work.

Code of c library call you can find in last answer of: http://www.mapleprimes.com/questions/126686-External-Dll-EvalMapleStatement.

 

Only for evalf version one line substituted to:

return (ice_real_TReal)MapleToFloat64(ExternalKernel, EvalMapleProc(ExternalKernel, f, 3, args));

 

Now i really want to know in which version of symbolic expressions calculation will work that code. At least in  my version of code and EvalhfMapleProc call it works. Preferably want it to work with EvalhfMapleProc i.e. evalhf from sheet.

Test file is in attach.

test_external.mw

I did as you suggested but nevertheless MainFDerivative... should be function calls. But as expressions they refused to calculate numerically from external program. I mean, evalhf doesn't work in sheet itself while evalf works in sheet but EvalMapleProc in c library doesn't work.

Code of c library call you can find in last answer of: http://www.mapleprimes.com/questions/126686-External-Dll-EvalMapleStatement.

 

Only for evalf version one line substituted to:

return (ice_real_TReal)MapleToFloat64(ExternalKernel, EvalMapleProc(ExternalKernel, f, 3, args));

 

Now i really want to know in which version of symbolic expressions calculation will work that code. At least in  my version of code and EvalhfMapleProc call it works. Preferably want it to work with EvalhfMapleProc i.e. evalhf from sheet.

Test file is in attach.

test_external.mw

I really use a custom wrapper. And i understand that defining of arguments is not necessary. I did such syntax for InitInternal only because have many parameters...

I really use a custom wrapper. And i understand that defining of arguments is not necessary. I did such syntax for InitInternal only because have many parameters...

Have external function

 

 

with(Optimization): with(ExternalCalling):

MyTargetMultArgsFunctionExt := define_external('MyTargetMultArgsFunctionExt', 'MAPLE', 'LIB' = "maple_library.dll"); MyTargetMultArgsFunctionInt := proc (V::Vector) MyTargetMultArgsFunctionExt(0, V[1], V[2]) end proc; MyTargetMultArgsFunctionIntGrad := proc (V::Vector, grad::Vector) local A; A := MyTargetMultArgsFunctionExt(1, V[1], V[2]); grad[1] = A[1][1]; grad[2] = A[1][2]; NULL end proc

 Tried to solve in matrix form (because of http://www.mapleprimes.com/questions/127339-Optimization-Of-External-One) in both cases with default method

 

NLPSolve(2, MyTargetMultArgsFunctionInt, objectivegradient = MyTargetMultArgsFunctionIntGrad)

NLPSolve(2, MyTargetMultArgsFunctionInt, [], NULL, [-100, 100], objectivegradient = MyTargetMultArgsFunctionIntGrad, initialpoint = Vector([-12.0, 1.0], datatype = float), optimalitytolerance = 0.001)

 

In first case obtained error

Error, (in Optimization:-NLPSolve) the objective gradients at the initial point are too small
In second :

Warning, no iterations performed as initial point satisfies first-order conditions

What is that? Is it at least smth that works 100% in maple? Debugged my external call:

EXPORT_DECL ALGEB M_DECL MyTargetMultArgsFunctionExt(MKernelVector MKernel, ALGEB *args)
{
  ice_real_TReal rargs[2];
  static ice_real_TReal res[2];
  static int RTableCreated;
  static ALGEB RTableRes;
  static FLOAT64* rtdata;
  int i, diffno;
  //
  diffno=MapleToInteger32(MKernel, args[1]);
  for(i=0;i<2;i++)
    rargs[i]=MapleToFloat64(MKernel, args[i+2]);
  MyTargetMultArgsFunction(rargs, 2, diffno, res);
  if (diffno==0)
    return ToMapleFloat(MKernel, res[0]);
  else
  {
    if (!RTableCreated)
    {
      RTableRes=ice_TableUtils_CreateRTable(ExternalKernel,1, 2);
      rtdata = (FLOAT64*)RTableDataBlock(ExternalKernel,RTableRes);
      RTableCreated=1;
    }
    rtdata[0]=res[0];
    rtdata[1]=res[1];
    return RTableRes;
  }
}

- it works great and all values returned are correct.

Also tried other methods of solving like pcg (same error), Modified Newton (bad story, warning, propose for assure recalc also hessian)

Have external function

 

 

with(Optimization): with(ExternalCalling):

MyTargetMultArgsFunctionExt := define_external('MyTargetMultArgsFunctionExt', 'MAPLE', 'LIB' = "maple_library.dll"); MyTargetMultArgsFunctionInt := proc (V::Vector) MyTargetMultArgsFunctionExt(0, V[1], V[2]) end proc; MyTargetMultArgsFunctionIntGrad := proc (V::Vector, grad::Vector) local A; A := MyTargetMultArgsFunctionExt(1, V[1], V[2]); grad[1] = A[1][1]; grad[2] = A[1][2]; NULL end proc

 Tried to solve in matrix form (because of http://www.mapleprimes.com/questions/127339-Optimization-Of-External-One) in both cases with default method

 

NLPSolve(2, MyTargetMultArgsFunctionInt, objectivegradient = MyTargetMultArgsFunctionIntGrad)

NLPSolve(2, MyTargetMultArgsFunctionInt, [], NULL, [-100, 100], objectivegradient = MyTargetMultArgsFunctionIntGrad, initialpoint = Vector([-12.0, 1.0], datatype = float), optimalitytolerance = 0.001)

 

In first case obtained error

Error, (in Optimization:-NLPSolve) the objective gradients at the initial point are too small
In second :

Warning, no iterations performed as initial point satisfies first-order conditions

What is that? Is it at least smth that works 100% in maple? Debugged my external call:

EXPORT_DECL ALGEB M_DECL MyTargetMultArgsFunctionExt(MKernelVector MKernel, ALGEB *args)
{
  ice_real_TReal rargs[2];
  static ice_real_TReal res[2];
  static int RTableCreated;
  static ALGEB RTableRes;
  static FLOAT64* rtdata;
  int i, diffno;
  //
  diffno=MapleToInteger32(MKernel, args[1]);
  for(i=0;i<2;i++)
    rargs[i]=MapleToFloat64(MKernel, args[i+2]);
  MyTargetMultArgsFunction(rargs, 2, diffno, res);
  if (diffno==0)
    return ToMapleFloat(MKernel, res[0]);
  else
  {
    if (!RTableCreated)
    {
      RTableRes=ice_TableUtils_CreateRTable(ExternalKernel,1, 2);
      rtdata = (FLOAT64*)RTableDataBlock(ExternalKernel,RTableRes);
      RTableCreated=1;
    }
    rtdata[0]=res[0];
    rtdata[1]=res[1];
    return RTableRes;
  }
}

- it works great and all values returned are correct.

Also tried other methods of solving like pcg (same error), Modified Newton (bad story, warning, propose for assure recalc also hessian)

Thank you for answer but main problem that is external call.

Direct syntax

Minimize(MyTargetMultArgsFunctionExt)

 

doesn't work because of error:

Error, (in Optimization:-NLPSolve) problem must have at least one variable.

 

In other words define_external is not function definition itself as i understand. But already read in help

 

"For more control over the solution process, or to use the more efficient Matrix form of input described in Optimization/MatrixForm, use LPSolve, QPSolve, or NLPSolve directly".

Will try that way+ see that option objectivegradient.

Thank you for answer but main problem that is external call.

Direct syntax

Minimize(MyTargetMultArgsFunctionExt)

 

doesn't work because of error:

Error, (in Optimization:-NLPSolve) problem must have at least one variable.

 

In other words define_external is not function definition itself as i understand. But already read in help

 

"For more control over the solution process, or to use the more efficient Matrix form of input described in Optimization/MatrixForm, use LPSolve, QPSolve, or NLPSolve directly".

Will try that way+ see that option objectivegradient.

It's incredible! Tried EvalhfMapleProc amd after that both time and memory consuptions are fster in a couple of orders! Everything is OK now!

It's incredible! Tried EvalhfMapleProc amd after that both time and memory consuptions are fster in a couple of orders! Everything is OK now!

First 6 7 8 9 10 Page 8 of 10