Optimized matrix multiplication functions for pascal?

classic Classic list List threaded Threaded
7 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?

Paulo Costa
On 09/10/2010 06:59, 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...

Try:

http://paginas.fe.up.pt/~paco/pmwiki/index.php?n=DynMatrix.DynMatrix

It is a bit more than just those functions but it could solve, for a
while, your problem.

Paulo Costa


_______________________________________________
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?

David W Noon
In reply to this post by Bo Berglund
On Sat, 9 Oct 2010 07:59:26 +0200, Bo Berglund wrote about [fpc-pascal]
Optimized matrix multiplication functions for pascal?:

[snip]
> Where can I find such functions?

They are available in a library named LAPACK.  You can find downloads
by doing a Google search on this name.  It is coded in FORTRAN though.

> I am not a matematician myself so I don't know what these
> functions really do...

They are easy to code, as they are simple linear algebra.  A good
textbook on linear algebra would be a great help to you.

However, LAPACK gets mighty complicated when it gets into other areas
of numerical linear algebra.  If your FORTRAN code uses more
complicated routines, you might find it convenient simply to call the
LAPACK FORTRAN code directly.  Maintaining a Pascal version of LAPACK
would be a non-trivial -- even arduous -- task, but you could check the
FPC Wiki to see if somebody might already have done that for you.
--
Regards,

Dave  [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[hidden email] (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Optimized matrix multiplication functions for pascal?

Adriaan van Os-2
David W Noon wrote:
> On Sat, 9 Oct 2010 07:59:26 +0200, Bo Berglund wrote about [fpc-pascal]
> Optimized matrix multiplication functions for pascal?:
>
> [snip]
>> Where can I find such functions?
>
> They are available in a library named LAPACK.  You can find downloads
> by doing a Google search on this name.  It is coded in FORTRAN though.

There is also a C version of LAPACK, see

<http://www.netlib.org/clapack/>
<http://developer.apple.com/hardwaredrivers/ve/vector_libraries.html>

with prebuilt Windows libraries
<http://www.netlib.org/clapack/LIB_WINDOWS/prebuilt_libraries_windows.html>.

It should be possible to call into those libs from FPC.

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?

Sven Barth-2
In reply to this post by Bo Berglund
Am 09.10.2010 07:59, schrieb 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...
>

Try the unit matrix.pp which is part of FPC's RTL. It also includes
overloaded operators if you need them. ^^

(In Lazarus: enter the unit name in the uses clause and do a Ctrl+left
mouse button on it to view its contents)

Regards,
Sven
_______________________________________________
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?

Marco van de Voort
In our previous episode, Sven Barth said:
> Try the unit matrix.pp which is part of FPC's RTL. It also includes
> overloaded operators if you need them. ^^

Afaik matrix only defines 4x4 or less.
 
Numlib also has a large number of matrix routines (including determinant,
eigen values etc), but is not entirely documented. (actually there is
documentation, but it is in dutch)

_______________________________________________
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?

Sven Barth-2
On 10.10.2010 14:17, Marco van de Voort wrote:
> In our previous episode, Sven Barth said:
>> Try the unit matrix.pp which is part of FPC's RTL. It also includes
>> overloaded operators if you need them. ^^
>
> Afaik matrix only defines 4x4 or less.
>
> Numlib also has a large number of matrix routines (including determinant,
> eigen values etc), but is not entirely documented. (actually there is
> documentation, but it is in dutch)

Ok... I didn't realize that he has dynamic arrays as parameters... So
some other code than that in matrix.pp might be better here.

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal