[Oberon] Oberon-V?

John Drake jmdrake_98 at yahoo.com
Mon Mar 7 03:51:01 CET 2005


--- Felix Friedrich <friedrich at gsf.de> wrote:

> Yes, there the old efficency problem is also present
> since computing the 
> index means calling a procedure. The basic
> principle, however, is the same.
> 
> Felix.

Right.  But the efficiency problem is only present
when you quit thinking "vector math" and start
doing "matrix elements".  Take your code for
mean - sum of squares for a matrix.  

Array2dRe.MeanSsq

PROCEDURE MeanSsq*(VAR s: ARRAY OF ARRAY OF Value; x,
y, w, h: Index;  VAR mean, ssq: Value );  
(* mean and ssq distance of mean by provisional means
algorithm *)

VAR d: Value;  val: Value;  i, j: Index;  
BEGIN 
  Array1dBytes.RangeCheck2(x,y,w,h,LEN(s[0]),LEN(s)); 


  mean := 0;  ssq := 0;  
  FOR i := 0 TO h - 1 DO 
    FOR j := 0 TO w - 1 DO 
      val := s[i + y, j + x];  
      d := val - mean;  
      mean := mean + d / ((i * w + j) + 1);  
      ssq := ssq + d * (val - mean);  
    END 
  END;  
END MeanSsq;  

This accesses every element in matrix the normal
way.  As I'm sure you're aware, the "MultiArrays"
package stores everything as a one dimentional
vector even if you're using matrices or higher
dimensions.  Going from this I implemented
MeanSsq as a MultiArray proc.

PROCEDURE MeanSsq(a : MultiArrays.Array; VAR mean, ssq
: REAL);
VAR
  i : LONGINT;
  d, val : REAL;
		
BEGIN
  mean := 0; ssq := 0;
  WITH a : MultiArrays.RealArray DO
    FOR i := 0 TO a.len - 1 DO
      val := a.x[i]; 
      d := val - mean; 
      mean := mean + d / (i + 1); 
      ssq := ssq + d * (val - mean);
    END;
  END;
END MeanSsq;

Tests show a 20% speedup over the first 
procedure.  I thought about implementing
this the way I saw you implement other CAPO
matrix procs where the inner loop passes
a row to a vector procedure, but alas I
was hurting my braining thinking about
it. :) I'd be interested to see how such
an implementation would fare speedwise.

Anyway, lets say for the sake of argument
that we did have vector extensions. 
Whenever there was code like s[i, j] 
the vector extensions wouldn't make
a difference right?  On the other hand
there seem to be a lot of places where
speedups can be done with the current
compiler.  I only saw one procedure that
used MMX extensions for instance.  It's
good to have non Intel specific code
for portability, but for speed it would
be good to have MMX and SSE instructions
where the potential speedup justifies it.

Regards,

John M. Drake

P.S. I've been thinking of a fast way to
to matrix multiplication the MultiArray
way.  When I work it out, I'll post it.



	
		
__________________________________ 
Celebrate Yahoo!'s 10th Birthday! 
Yahoo! Netrospective: 100 Moments of the Web 
http://birthday.yahoo.com/netrospective/



More information about the Oberon mailing list