octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JIT - automated mexing


From: Alexander Barth
Subject: Re: JIT - automated mexing
Date: Mon, 26 Jul 2010 15:44:30 +0200

On Thu, Jun 24, 2010 at 11:03 PM, David Bateman <address@hidden> wrote:
> Fotios Kasolis wrote:
>>
>> 1) First automated mexing will be done by the user if he/she really wants
>> by calling function so the idea of just in time is absent.
>> 2) What i was thinking is sth like:
>>    - Parse file and find loops (and to make it easy) that do not call any
>> functions!
>>    - analyze <for> blocks
>>    - based on gathered info write mex functions with proper arguments
>> (iterators, vectors, matrices) that implement the same loops.
>>    - system("mex myfunc.mex")
>>    - make new function file with loops replaced by function calls to mex
>> functions.
>>
>> I m not 100% sure but this sounds much easier than embedding JIT. So we
>> just replace loops with function calls.
>>
>>
>
> And how do you type the variables in the mex-file. If you don't do the type
> discovery you'll just end with a code like
>
> http://www.ruena.de/files/Oct_Interpreter_Compiler.pdf
>
> that compiles to oct-files with dynamic typing of the variable and basically
> doesn't give any speed improvements
>
> D.
>
>
Would it be possible to add special directives to declare the type of
variables (similar to pragma directives in C), that would be ignored
by the interpreter but used by a compiler to generate C++-code (or
directly native code) ? For example:

%oct-type complex a
%oct-type double i

a = 1
for i = 0:.1:2
  a += asin(i);
endfor

If one wants to assign a variable of another type, then one would get
a runtime error:
a = 1; % ok
a = 'some string';  % error

I think that this is probably easier to implement than detecting the
type of a variable. For development and debugging, one could use the
interpreter (without type checks) and then when the code works as
desired, one could add the declarations to improve the performance.

Of course, only a subset of the language feature can be used if one
wants to translate m-code into C++-code or native code, but in general
the functions that are numerically intensive are often quite simple
and do not involve variables of a priori unknown types.

Another way to declare the types of the variables (instead of using
directives), would be to require to initialize all variables before
first use with the appropriate type, e.g.:

a = complex(0);
i = double(0);

Declaring the type of variable also improves the readability of the
code and helps to detect errors (such as a misspelled variable):

v1 = double(0);
vl = 2; % v1 misspelled produces an error, because vl is not defined

just my 2cents,

Cheers,
Alex



reply via email to

[Prev in Thread] Current Thread [Next in Thread]