help / color / mirror / Atom feed
* Implicit_Dereference for Real_Vectors ?
@ 2023-01-22 21:52 Jim Paloander
  0 siblings, 0 replies; only message in thread
From: Jim Paloander @ 2023-01-22 21:52 UTC (permalink / raw)

Dear ADA experts,
is it possible to extend an inherent ADA package such Real_Arrays with something like this?

type Accessor (Data: not null access Real_Vector) is limited private with Implicit_Dereference => Data;

In the hope that I could somehow declare:
A: Accessor := new Real_Vector ( 1 .. N );
B: Accessor := new Real_Vector ( 1 .. N );
X: Accessor := new Real_Vector ( 1 .. N );

So I could write a statement:
X := A + B;
instead of
X.all := A.all + B.all;
since I am forced to use heap allocation for N > 100,000? Sorry for my ignorance but I am new to ADA and I cannot find enough documentation. Containers seem to be awful in terms of syntax  for mathematical programming and linear algebra, and the fact that Real_Arrays allow clean syntax for operator overloading only if allocated on the limited stack is really extremely  frustrating. I totally understand the preference for stack over heap for certain applications, but for the applications I have in mind the size of the problem is determined at runtime. There is no way to know it in advance. I tried -D1000m -d1000m in the binder options to no avail. Always I get the STACK_OVERFLOW error. My only option is heap. Moreover, I would expect that ADA's Numerics are as efficient as Fortran's overloaded operators and no temporary objects are generated when you do something like:
X := A + B + C + A + B;

Unfortunately ADA introduces a temporary for every addition that is added to the next creating a 2nd temporary and so on.
temp1 := A+B; temp2 := C+temp1; temp3 := B+temp2; temp4 := A+temp3; X := temp4;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-22 21:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-22 21:52 Implicit_Dereference for Real_Vectors ? Jim Paloander

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