gforth
[Top][All Lists]
Advanced

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

Re: [gforth] Gforth's fsl-util.*


From: Bernd Paysan
Subject: Re: [gforth] Gforth's fsl-util.*
Date: Mon, 26 Nov 2012 01:13:16 +0100
User-agent: KMail/4.8.5 (Linux/3.4.11-2.16-desktop; KDE/4.8.5; x86_64; ; )

Am Montag, 26. November 2012, 00:04:23 schrieb David Kuehling:
> I am aware that } and }} are suboptimal for various reasons.  However,
> From the standponit of a person who just wants to quickly implement some
> readable math code, using concepts and semantics not too different from
> Octave (MatLab) or Fortran, they do their job very well.

Unlike Fortran, MatLab/Octave have a number of nice higher order functions to 
deal with things like matrix multiplication and row/column vectors of these.  
And they build on LAPACK/BLAS, which gives them high-performance 
implementations of these.

> No, people hacking math algorithms usually don't want to think about
> iterators and data-flow, or about vector-multiplication factors.  At
> least not for the first version.  Ideally the syntax in Forth doesn't
> look too different from the math formulas used on paper to derive the
> algorithm in the first place.

Hm, have you actually looked at math formulas for matrix multiplication on 
paper?  The wikipedia article contains several expressions, and the one with 
the dot product of rows/colums is part of it:

http://en.wikipedia.org/wiki/Matrix_multiplication#Matrix_product_.28two_matrices.29

(AB)_{ij}=a_i * b_j, with a_i being a row of A, and b_j being a column of B.

That's the mathematical formula, as usual omitting the actual loops (implicit 
iterator).

> If you want to optimize, you'll usually have to think about block matrix
> algorithms, at which point your code will lose all its mathematical
> clearness anyway.

It's not really that awful.  Block matrix multiplication is actually the same 
equation as elementary matrix multiplication, just that you use submatrices as 
elements.  Actually, what you esentially do on a block matrix multiplication 
is to change the evaluation order within the three nested loops.

> So here is a person very happy with } and }} asking for as much
> performance as possible for his non-optimized (but readable)
> script-language-style math code.

I simply see a considerable amount of improvement.  One is that most of these 
vectors are arrays of float (fixed size, known at compile time), and yet, they 
have to multiply by a variable in memory each time.  Well, FSL was 
deliberately created to translate Fortran code 1:1 to Forth, so I see your 
point.

I just would strongly discourage to use FSL's arrays outside FSL itself.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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