comp.lang.ada
 help / color / mirror / Atom feed
From: "Alexander Boucke" <alexb@lufmech.rwth-aachen.de>
Subject: Re: efficient vector/matrix operations in Ada
Date: Tue, 14 Aug 2001 10:17:22 +0200
Date: 2001-08-14T08:17:26+00:00	[thread overview]
Message-ID: <9lamqm$ehp$1@nets3.rz.RWTH-Aachen.DE> (raw)
In-Reply-To: bebbba07.0108132046.53d265dc@posting.google.com


> > Here's how you write "A = B + C + D;" efficiently:
> >
> >     A  = B;
> >     A += C;
> >     A += D;
> >
> > This requires no temporary matrices or passing by value. The original
> > form (A=B+C+D) is fine for rapid prototyping, but the efficient form
> > is preferable for production code. As far as I am concerned, Ada
> > really needs arithmetic assignment operators. Sure, you can use
> > procedures, but they're intent and effect is not as obvious to the
> > reader.


There is a way to do the same (regarding efficiency) in Ada 95 using the A:=
B + C + D form. For my work I've written a Matrix-Vector package, that
encapsulates the Arrays using access-types. The only temporary objects you
get now are access-types. There would have been a problem with the RAM
slowly filling up, so I used controlled types to do reference-counting.
Together with a temporary vector holding all results from sums, this leads
to equivalent efficiency as using the += operators. You have to deal with
the overhead due to the garbage collection using controlled types, but that
is negligible when using large vectors/matrices as in typical finite element
programs.

How this could look (simplified):

package vectors is

...

  type Vector is new Ada.Finalization.Controlled with private;

  function "+" (left,right : vector) return vector;

...

private

  type value_array is array (<>) of real;
  type handled_vector (first,last : integer) is
     record
        value : value_array(first, last);
        count : natural; -- for reference counting
     end record;

  type handled_vector_access is access handled_vector;

  type vector is new ada.finalization.controlled with
     record
        the_vector : handled_vector_access;
     end record;

end vectors;


Regards,

Alexander Boucke






  parent reply	other threads:[~2001-08-14  8:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-07  1:13 efficient vector/matrix operations in Ada Russ
2001-08-07  2:18 ` Dale Stanbrough
2001-08-07  2:21 ` tmoran
2001-08-07  3:04   ` Russ P.
2001-08-10 16:54     ` B.Gaffney
2001-08-13  7:50       ` Dmitry Kazakov
2001-08-13 19:45       ` Russ
2001-08-13 20:23         ` Larry Hazel
2001-08-13 21:26           ` Ted Dennison
2001-08-14  4:46           ` Russ
2001-08-14  5:28             ` David Starner
2001-08-14  8:17             ` Alexander Boucke [this message]
2001-08-14  8:56             ` Lutz Donnerhacke
2001-08-14 10:54             ` Jacob Sparre Andersen
2001-08-13 21:30         ` Ted Dennison
2001-08-14  4:56           ` Russ
2001-08-14  7:32             ` efficient vector/matrix operations in Fortran, was Re: ... " tmoran
2001-08-14 14:05             ` efficient vector/matrix operations " Ted Dennison
  -- strict thread matches above, loose matches on Subject: below --
2001-08-07 11:36 Gautier Write-only-address
2001-08-14 12:37 Gautier Write-only-address
replies disabled

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