comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: on using array index, vectorized operation
Date: Mon, 28 Mar 2011 21:50:40 -0500
Date: 2011-03-28T21:50:40-05:00	[thread overview]
Message-ID: <imrhe3$2m5$1@munin.nbi.dk> (raw)
In-Reply-To: imodcl$4sk$1@speranza.aioe.org

"Nasser M. Abbasi" <nma@12000.org> wrote in message 
news:imodcl$4sk$1@speranza.aioe.org...
> On 3/27/2011 3:09 PM, Phil Clayton wrote:
>> Do we now have vectorized arithmetic operations, e.g. + on array
>> types?

Not on all array types, but the Generic_Real_Arrays provides vector and 
matrix operations. Unfortunately, only for float values.

> Does not look like it either, not directly any way:
>
> ---------------------
> procedure foo2 is
>
> type array_t is  array(natural range <>) of integer;
> u : array_t(1..10) := (others=>0);
>
> begin
>    u := u + 1;
> end foo2;

You can do this for float values by using Generic_Real_Arrays:

with Ada.Numerics.Generic_Real_Arrays;
procedure foo3 is

   package My_Vectors is new Ada.Numerics.Generic_Real_Arrays (Float);
   use My_Vectors;

   subtype  array_t is Real_Vector;

   u : array_t(1..10) := (others=>0.0);

begin
    u := u + (others => 1.0);
    u := u * 1.0;
end foo3;

I'd suggest writing your own package similar to Generic Real_Arrays to 
define your own vector types, complete with overloaded operators. You only 
have to do that once, and the uses can be much simpler in your code. That's 
a much better option than writing loads of loops in your code that ruin the 
readability.

Just because something isn't provided for free with Ada doesn't mean that 
you can't write a similar replacement...

                                   Randy.







  reply	other threads:[~2011-03-29  2:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-27  1:31 on using array index, vectorized operation Nasser M. Abbasi
2011-03-27 18:48 ` Nasser M. Abbasi
2011-03-27 20:01 ` Cyrille
2011-03-27 20:44   ` Nasser M. Abbasi
2011-03-27 21:02     ` Pascal Obry
2011-03-27 21:30     ` Shark8
2011-03-27 22:00       ` Nasser M. Abbasi
2011-03-27 22:37         ` Phil Clayton
2011-03-27 22:43           ` Nasser M. Abbasi
2011-03-27 22:59             ` Phil Clayton
2011-03-27 22:09     ` Phil Clayton
2011-03-27 22:12       ` Nasser M. Abbasi
2011-03-27 22:23       ` Nasser M. Abbasi
2011-03-29  2:50         ` Randy Brukardt [this message]
2011-03-29  4:55           ` Nasser M. Abbasi
2011-03-29 20:11             ` Phil Clayton
2011-03-29 21:17               ` Nasser M. Abbasi
2011-03-29 22:49                 ` Phil Clayton
2011-03-29 23:47                   ` Nasser M. Abbasi
2011-03-30 13:00                     ` Robert A Duff
replies disabled

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