Optimized matrix multiplication functions for pascal?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Optimized matrix multiplication functions for pascal?

Bo Berglund
I am translating a bunch of Fortran functions to FPC and I
have now come across a problem with a couple of built-in
Fortran90 functions:

MATMUL multiplies two matrices (arrays) and returns the result.

TRANSPOSE reorders the array elemsnts in some predefined way.

The call in the Fortran routine is like this:

b = matmul(transpose(a), a)

where a and b are equal sized dynamic arrays of double.

So I need to get hold of two Delphi functions:

function matmul(X, Y: array of double): array of double;
and
function transpose(X: array of double): array of double;

Where can I find such functions?
I am not a matematician myself so I don't know what these
functions really do...

--
Bo Berglund

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Optimized matrix multiplication functions for pascal?

Honza-5
2010/10/9 Bo Berglund <[hidden email]>:
> So I need to get hold of two Delphi functions:
>
> function matmul(X, Y: array of double): array of double;
> and
> function transpose(X: array of double): array of double;
>
> Where can I find such functions?
> I am not a matematician myself so I don't know what these
> functions really do...

The machinery is depicted e.g. here:
http://en.wikipedia.org/wiki/Matrix_multiplication
http://en.wikipedia.org/wiki/Matrix_transpose

IMO it's not really tough to implement them in FPC.

--
bflm
freepascal-bits.blogspot.com
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Optimized matrix multiplication functions for pascal?

Michael Van Canneyt
In reply to this post by Bo Berglund


You may want to look at the matrix.pp unit included in the rtl.
It contains many matrix operations.

Michael.

On Sat, 9 Oct 2010, Bo Berglund wrote:

> I am translating a bunch of Fortran functions to FPC and I
> have now come across a problem with a couple of built-in
> Fortran90 functions:
>
> MATMUL multiplies two matrices (arrays) and returns the result.
>
> TRANSPOSE reorders the array elemsnts in some predefined way.
>
> The call in the Fortran routine is like this:
>
> b = matmul(transpose(a), a)
>
> where a and b are equal sized dynamic arrays of double.
>
> So I need to get hold of two Delphi functions:
>
> function matmul(X, Y: array of double): array of double;
> and
> function transpose(X: array of double): array of double;
>
> Where can I find such functions?
> I am not a matematician myself so I don't know what these
> functions really do...
>
> --
> Bo Berglund
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Optimized matrix multiplication functions for pascal?

Reimar Grabowski
In reply to this post by Bo Berglund
On Sat, 9 Oct 2010 14:42:47 +0200
"Bo Berglund" <[hidden email]> wrote:

> Where can I find such functions?
> I am not a matematician myself so I don't know what these
> functions really do...

Take a look here: http://www.j3d.org/matrix_faq/matrfaq_latest.html

R.
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Optimized matrix multiplication functions for pascal?

Adriaan van Os-2
In reply to this post by Bo Berglund
Bo Berglund wrote:
> I am translating a bunch of Fortran functions to FPC and I
> have now come across a problem with a couple of built-in
> Fortran90 functions:

Matrix functions can be implemented efficiently using SSE, see e.g.
<http://www.cortstratton.org/articles/OptimizingForSSE.php>.

Regards,

Adriaan van Os
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Optimized matrix multiplication functions for pascal?

Reimar Grabowski
On Sat, 09 Oct 2010 16:40:12 +0200
Adriaan van Os <[hidden email]> wrote:

> Matrix functions can be implemented efficiently using SSE, see e.g.
> <http://www.cortstratton.org/articles/OptimizingForSSE.php>.
FPC can generate the SSE instructions for you on compilation. My tests showed that this is faster than writing the functions using SSE myself. If you have written matrix routines using SSE that are faster than mine written in pascal and optimized by the compiler I am really interested in seeing them.

R.
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal