comp.lang.ada
 help / color / mirror / Atom feed
From: johnscpg@googlemail.com
Subject: Re: ANN: miscellaneous Math routines, GPL'd
Date: Wed, 13 May 2009 02:25:30 -0700 (PDT)
Date: 2009-05-13T02:25:30-07:00	[thread overview]
Message-ID: <46c1db7c-e6b4-48a1-9a4a-a777a1baaf60@r13g2000vbr.googlegroups.com> (raw)
In-Reply-To: 7f7fcafe-189e-423e-a24d-5933bfd6f754@n7g2000prc.googlegroups.com

On May 12, 10:02 pm, "lancebo...@qwest.net" <lancebo...@qwest.net>
wrote:
> On May 12, 9:38 am, johns...@googlemail.com wrote:
>
>
>
> > Dear All,
>
> > For those of you who like Ada with their numerics (is there
> > anyone who doesn't?!) I have released a collection of math
> > routines under the GPL license. Find them at:
>
> >  http://web.am.qub.ac.uk/users/j.parker/miscellany
>
> > The full set is tarred in the file:
>
> >   miscellany.10may09.tar.gz
>
> > in the directory given above.
>
> > Most are old classics I have found useful over the years
> > (SVD, QR, LU, Runge-Kutta, FFT, Arbitrary precision floating point).
> > The random number generators are very new; the documentation
> > should explain why I recommend them. The random number generators
> > and the Arbitrary precision floating point are designed to
> > make good use of the new 64-bit CPU's.
>
> > Cheers,
> > Jonathan
>
> > j.parker/at/qub/point/ac/point/uk
>
> Wow--numerical code that I can actually read! This looks awesome.
>
> I suppose that it would not be hard to adapt the code to use the
> vector and matrix declarations in the Annex G.3 part of Ada 2005, e.g.
>
> type Real_Vector is array (Integer range <>) of Real'Base;
> type Real_Matrix is array (Integer range <>, Integer range <>)
>                                                    of Real'Base;
>
> replacing the scattered declarations such as
>
> type Data_Array is array (Array_Index) of Real;
> type A_Matrix is array(R_Index, C_Index) of Real;
>
> I really like the "standardized" way of these Ada 2005 declarations.
>
> Jerry


To instantiate the lin. alg. generics (in directory linearly)
using the unconstrained arrays you typed above, declare a subtype m3:

   subtype Index is Integer range 1..191;

 --type Real_Matrix is array (Integer range <>, Integer  range <>) of
Real;

   subtype m3 is Real_Matrix (Index, Index);

The generics can now be instantiated with m3.

Another interesting question is whether the generics (and the
subprograms
declared by the generic package) should be using unconstrained arrays:

  generic
     type Real is digits <>;
     type Matrix is array (Integer range <>, Integer  range <>) of
Real;

In the old days if I did that the program would run way slow.. seemed
to put the compiler under much stress ... maybe ok now but I am not
going to be the one to prove it.

Here's another problem:  Very common for an application to
require transformation of an arbitrary diagonal block of a
matrix (or any block) rather than the full matrix.
Unconstrained arrays don't provide any special benefit here ...
you still have to copy
the block to another matrix, or handle it the way I do in
these routines (tell the routine to operate on a specified block
only). Once you've gone to this trouble, the benefit of
unconstrained arrays is small.

Another irritation:  suppose user declares

  V : Vector (1..10);
  M : Matrix (0..9, 0..9);
or worse
  M : Matrix (0..9, 2..11);
or worse still
  M : Matrix (0..11, 2..11);

How do you handle it?
1. shift indices during iteration inside loops in the lin alg program.
2. slide arrays so indices coincide.
3. Raise constraint_error;
4. Assume they won't do it.

I do 3. (See for example procedure Choleski_Decompose at end of
Disorderly-Random-Deviates.adb  and near bottom of
Disorderly-Random-Deviates.ads.)   But I'm not sure what to do.
(I was going ask here on comp.lang.ada, but got lazy.)
Generics with constrained arrays work ok for me here.

cheers,
jonathan




  reply	other threads:[~2009-05-13  9:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-12 16:38 ANN: miscellaneous Math routines, GPL'd johnscpg
2009-05-12 18:45 ` John B. Matthews
2009-05-13  9:39   ` johnscpg
2009-05-13 13:40     ` John B. Matthews
2009-05-12 19:03 ` Dmitry A. Kazakov
2009-05-12 21:02 ` lanceboyle
2009-05-13  9:25   ` johnscpg [this message]
2009-05-13 11:52     ` gautier_niouzes
2009-05-13 13:43       ` johnscpg
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox