comp.lang.ada
 help / color / mirror / Atom feed
From: Jim Paloander <dhmos.altiotis@gmail.com>
Subject: Implicit_Dereference for Real_Vectors ?
Date: Sun, 22 Jan 2023 13:52:36 -0800 (PST)	[thread overview]
Message-ID: <ce32beb1-373d-411a-8b05-2c293df7249dn@googlegroups.com> (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;


                 reply	other threads:[~2023-01-22 21:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
replies disabled

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