octave-maintainers
[Top][All Lists]
Advanced

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

Re: Looking at Type inferencing compiler


From: David Bateman
Subject: Re: Looking at Type inferencing compiler
Date: Mon, 11 Dec 2006 22:30:47 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

John W. Eaton wrote:
> On 11-Dec-2006, David Bateman wrote:
> 
> | So the only example above that is faster than the m-file is yours!!! Do
> | you or anyone else know where I'm paying the speed penalty for the
> | octave in-built classes? In any case I suspect that the improvement you
> | showed in the example in your thesis was largely due to the different
> | matrix class that the type inferencing, though further benchmarks will
> | be needed to prove that.
> 
> |     inline operator octave_value(){ 
> |     Matrix m(rows,cols); for (int i = 0; i<rows; ++i) for ( int j = 0 ; 
> j<cols; ++j ) m(i,j) = rep[i][j];
> |     return m;
> |     };
> 
> It's not clear to me whether this conversion operator is being used,
> but it will be slow because the indexing operator for the Matrix class
> must check the reference count each time it is called.  You can fix
> that by doing
> 
>   inline operator octave_value(){ 
>     Matrix m(rows,cols);
>     double *mp = m.fortran_vec ();
>     int k = 0;
>     for (int j = 0 ; j<cols; ++j)
>       for (int i = 0; i<rows; ++i)
>         mp[k++] = rep[i][j];
>     return m;
>   }
> 
> jwe
> 

Ok, but it in fact makes the situation even slightly worse. Jens code
with the matrix class without reference counting is slightly faster
again. There are 10000 matrix multiplies and only one octave_value
method called, and so this is not a big additional cost however.. In
fact I can't easily measure it.

In fact I think I can see why using intNDArray is so slow. The basic *
operator is given by

  octave_int<T>& operator *= (const octave_int<T>& x)
  {
    double t = static_cast<double> (value ());
    double tx = static_cast<double> (x.value ());
    ival = OCTAVE_INT_FIT_TO_RANGE (t * tx, T);
    return *this;
  }

and so everything is done in double and then reconverted to an int,
which is of course slower than a straight integer multiple as Jens used.

What I don't understand is that the version cast as Matrix is so much
slower than the m-file...


D.


reply via email to

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