comp.lang.ada
 help / color / mirror / Atom feed
* Re: efficient vector/matrix operations in Fortran, was Re: ... in Ada
@ 2001-08-14 10:11 Gautier Write-only-address
  2001-08-14 10:37 ` Lutz Donnerhacke
  0 siblings, 1 reply; 3+ messages in thread
From: Gautier Write-only-address @ 2001-08-14 10:11 UTC (permalink / raw)
  To: comp.lang.ada

>   The existence of Fortran, which has long been used successfully
>for highly efficient vector/matrix code, demonstrates that += is
>not required.
>   One possible reason is that significant matrix/vector programs
>don't normally spend a lot of their time doing a += b type O(n**2)
>operations, but rather spend their time doing O(n**3) operations.
>+= would be of minor benefit in that case.

The real reason is the "+" operator is defined in the language
for vectors or matrices, not a programmable function like in Ada.
Or, say, it has a pragma Import(intrinsic,...) like for functions
in Standard or Interfaces.
So the Fortran compiler optimizes with full latitude.
With a <<function "+"(a,b:vector) return vector>>, and no
trick to tell the compiler that it is intrisic,
you have a local variable in your function, perform the addition,
and return the variable. Maybe a pragma Inline and a strong
optimization can do the job on some compilers. It would be
interesting to see if at least one is able to suppress the
local variable in an inlined call. If not, there is no chance
that a user-defined "+" is as efficient as a user-defined "+=".

________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: Do not answer to sender address, visit the Web site!
    Ne r�pondez pas � l'exp�diteur, visitez le site ouaibe!


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




^ permalink raw reply	[flat|nested] 3+ messages in thread
* Re: efficient vector/matrix operations in Ada
@ 2001-08-14  4:56 Russ
  2001-08-14  7:32 ` efficient vector/matrix operations in Fortran, was Re: ... " tmoran
  0 siblings, 1 reply; 3+ messages in thread
From: Russ @ 2001-08-14  4:56 UTC (permalink / raw)


Ted Dennison<dennison@telepath.com> wrote in message news:<aGXd7.88$2u.23428@www.newsranger.com>...
> In article <bebbba07.0108131145.8e90df5@posting.google.com>, Russ says...
> (talking about matrices with redefined math ops)
> >Here's how you write "A = B + C + D;" efficiently:
> >
> >    A  = B;
> >    A += C;
> >    A += D;
> >
> >really needs arithmetic assignment operators. Sure, you can use
> >procedures, but they're intent and effect is not as obvious to the
> >reader.
> 
> Perhaps to a reader who is *already* familiar with the idiom above that is true.
> I'm not, and it took me a couple of takes to see what you were doing here (and a
> bit of thought to figure out why). For someone starting from ground zero, I
> think the point is quite arguable.

If you know even a tiny bit of C++, the "+=" notation is very obvious.
And it's use here in my example of matrix addition is perfectly
consistent with its use for normal scalar addition. No, you don't
absolutely need those operators, but neither do you need to be able
define your own "+", "-", etc. in Ada either. So why does Ada have
some nice-looking operators but not have the operators one really
needs for efficient code? I guess the goofy syntax isn't the only
problem with Ada, eh?

Russ



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-08-14 10:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-14 10:11 efficient vector/matrix operations in Fortran, was Re: ... in Ada Gautier Write-only-address
2001-08-14 10:37 ` Lutz Donnerhacke
  -- strict thread matches above, loose matches on Subject: below --
2001-08-14  4:56 efficient vector/matrix operations " Russ
2001-08-14  7:32 ` efficient vector/matrix operations in Fortran, was Re: ... " tmoran

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