comp.lang.ada
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: Real_Arrays on heap with overloaded operators and clean syntax
  2023-01-23  1:14  7%           ` Leo Brewin
@ 2023-01-23  6:01  0%             ` Jim Paloander
  0 siblings, 0 replies; 114+ results
From: Jim Paloander @ 2023-01-23  6:01 UTC (permalink / raw)


On Monday, January 23, 2023 at 2:14:58 AM UTC+1, Leo Brewin wrote:
> Here is a slight variation on the solution suggested by Gautier. It uses 
> Aad's "rename" syntax so that you can avoid all the .all stuff. I use 
> this construction extensively in my large scale scientific computations. 
> 
> with Ada.Numerics.Generic_Real_Arrays; 
> with Ada.Unchecked_Deallocation;
> procedure Test_Large is 
> 
> type Float_15 is digits 15; 
> 
> package F15_R_A is new Ada.Numerics.Generic_Real_Arrays (Float_15); 
> 
> use F15_R_A; 
> 
> procedure Solve_it 
> (x : in Real_Vector; 
> y : out Real_Vector; 
> A : in Real_Matrix) is 
> begin 
> null; -- Here, the big number-crunching 
> end; 
> 
> n : constant := 10_000; 
> 
> type Vector_Access is access Real_Vector; 
> type Matrix_Access is access Real_Matrix;
> x_ptr, y_ptr : Vector_Access := new Real_Vector (1 .. n); 
> A_ptr : Matrix_Access := new Real_Matrix (1 .. n, 1 .. n); 
> 
> x : Real_Vector renames x_ptr.all; 
> y : Real_Vector renames y_ptr.all; 
> A : Real_Matrix renames A_ptr.all; 
> 
> procedure FreeVector is new 
> Ada.Unchecked_Deallocation (Real_Vector,Vector_Access); 
> procedure FreeMatrix is new 
> Ada.Unchecked_Deallocation (Real_Matrix,Matrix_Access); 
> 
> begin 
> Solve_it (x, y, A); 
> -- Deallocation here 
> FreeVector (x_ptr); 
> FreeVector (y_ptr); 
> FreeMatrix (A_ptr); 
> end;

Thank you very much, would a       for Real_Vector_Access'Storage_Pool use localPool; save you from the need to free the vectors and matrix yourself?

On the other hand, is there any  way of avoiding temporaries? Possibly a modern version of the Real_Array using expression generic syntax or something similar? Since you are using scientific computationas extensively, you must be aware of Fortran. Have you compared Fortran's complex numbers with ADA's for inner products or similar computations to see who is faster? You see, I like a lot of things about ADA, but the syntax is really difficult to follow. Sometimes it gives me the impression that it is more difficult than really needed to be. For example there should be a way for Real_Arrays to allocate memory internally and not on the stack directly like containers. And for containers to provide an indexer Vector(i) and overloaded operators similarly to Real_Vectors. But the fact that they do not give me the impression that this Language although being designed by the army for mission critical applications never realized that modern mission critical need to simplify mathematical calculations providing an easy syntax. I am surprised that after so many years and so many updates to the Standard the designers of the Language did not realized that such mathematical syntax should be simplified to attract more people from scientific computing, who are tired with Fortran 10000 ways of declaring something a variable.

^ permalink raw reply	[relevance 0%]

* Re: Real_Arrays on heap with overloaded operators and clean syntax
  2023-01-22 23:14  7%         ` Gautier write-only address
@ 2023-01-23  1:14  7%           ` Leo Brewin
  2023-01-23  6:01  0%             ` Jim Paloander
  0 siblings, 1 reply; 114+ results
From: Leo Brewin @ 2023-01-23  1:14 UTC (permalink / raw)


Here is a slight variation on the solution suggested by Gautier. It uses 
Aad's "rename" syntax so that you can avoid all the .all stuff. I use 
this construction extensively in my large scale scientific computations.

with Ada.Numerics.Generic_Real_Arrays;
with Ada.Unchecked_Deallocation;

procedure Test_Large is

   type Float_15 is digits 15;

   package F15_R_A is new Ada.Numerics.Generic_Real_Arrays (Float_15);

   use F15_R_A;

   procedure Solve_it
     (x : in     Real_Vector;
      y :    out Real_Vector;
      A : in     Real_Matrix) is
   begin
     null;  --  Here, the big number-crunching
   end;

   n : constant := 10_000;

   type Vector_Access is access Real_Vector;
   type Matrix_Access is access Real_Matrix;

   x_ptr, y_ptr : Vector_Access := new Real_Vector (1 .. n);
   A_ptr        : Matrix_Access := new Real_Matrix (1 .. n, 1 .. n);

   x : Real_Vector renames x_ptr.all;
   y : Real_Vector renames y_ptr.all;
   A : Real_Matrix renames A_ptr.all;

   procedure FreeVector is new
      Ada.Unchecked_Deallocation (Real_Vector,Vector_Access);
   procedure FreeMatrix is new
      Ada.Unchecked_Deallocation (Real_Matrix,Matrix_Access);

begin
   Solve_it (x, y, A);
   -- Deallocation here
   FreeVector (x_ptr);
   FreeVector (y_ptr);
   FreeMatrix (A_ptr);
end;

^ permalink raw reply	[relevance 7%]

* Re: Real_Arrays on heap with overloaded operators and clean syntax
  @ 2023-01-22 23:14  7%         ` Gautier write-only address
  2023-01-23  1:14  7%           ` Leo Brewin
  0 siblings, 1 reply; 114+ results
From: Gautier write-only address @ 2023-01-22 23:14 UTC (permalink / raw)


Note that Real_Arrays does not specify where things are allocated (heap or stack).
Only when you define "x : Real_Vector (1 .. n)", it is on stack. You can always write something like the snippet below.
Anyway, after a certain size, you may have to find compromises, like avoiding operators (they do too many allocations & deallocations in the background, even assuming elegant heap-allocated objects) and also give up plain matrices, against sparse matrices or band-stored matrices, typically for solving Partial Differential Equations.

with Ada.Numerics.Generic_Real_Arrays;

procedure Test_Large is

  type Float_15 is digits 15;

  package F15_R_A is new Ada.Numerics.Generic_Real_Arrays (Float_15);

  use F15_R_A;

  procedure Solve_it
    (x : in     Real_Vector;
     y :    out Real_Vector;
     A : in     Real_Matrix) is
  begin
    null;  --  Here, the big number-crunching
  end;
  
  n : constant := 10_000;

  type Vector_Access is access Real_Vector;
  type Matrix_Access is access Real_Matrix;

  x, y : Vector_Access := new Real_Vector (1 .. n);
  A    : Matrix_Access := new Real_Matrix (1 .. n, 1 .. n);
  
begin
  Solve_it (x.all, y.all, A.all);
  --  !! Deallocation here
end;

^ permalink raw reply	[relevance 7%]

* Re: generic with function procedure
  2020-06-05 14:52  7% ` gautier_niouzes
@ 2020-06-05 15:45  0%   ` Gilbert Gosseyn
  0 siblings, 0 replies; 114+ results
From: Gilbert Gosseyn @ 2020-06-05 15:45 UTC (permalink / raw)


On Friday, June 5, 2020 at 4:52:13 PM UTC+2, gautier...@hotmail.com wrote:
> It depends on how you have defined g1 and h1...
> You may also want to pass Real as a generic parameter to make your "denm" package work for any precision. Perhaps doing so will solve your problem by the way.
> Here is a package from Mathpaqs, as an inspiration.
> 
> with Ada.Numerics.Generic_Real_Arrays;
> 
> generic
>   type Real is digits <>;
>   with package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
>   type Integer_Vector is array (Integer range <>) of Integer;
> 
> package Generic_Real_Linear_Equations is
> 
>   use Real_Arrays;
> 
>   function Linear_Equations ( A : Real_Matrix ;
>                               Y : Real_Vector ) return Real_Vector ;
> ...

I used already:
type Real is digits 18;
package Real_Arrays is instantiated with type Real from above.

Please explain: "It depends on how you have defined g1 and h1...". The functions g1 and h1 are defined in the same manner a f1. If I restrict the numer of with-clauses to one, then there is no error-message.

Thank you for your example. I am still studying it and I can see that it uses different methods in seperate programs with usual parameters. However, there are no functions as parameters involved. As in Ada you cannot use  functions as parameters eg in a procedure, the with clause may be used. My problem is still how to use the with clause correctly?

^ permalink raw reply	[relevance 0%]

* Re: generic with function procedure
  @ 2020-06-05 14:52  7% ` gautier_niouzes
  2020-06-05 15:45  0%   ` Gilbert Gosseyn
  0 siblings, 1 reply; 114+ results
From: gautier_niouzes @ 2020-06-05 14:52 UTC (permalink / raw)


It depends on how you have defined g1 and h1...
You may also want to pass Real as a generic parameter to make your "denm" package work for any precision. Perhaps doing so will solve your problem by the way.
Here is a package from Mathpaqs, as an inspiration.

with Ada.Numerics.Generic_Real_Arrays;

generic
  type Real is digits <>;
  with package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
  type Integer_Vector is array (Integer range <>) of Integer;

package Generic_Real_Linear_Equations is

  use Real_Arrays;

  function Linear_Equations ( A : Real_Matrix ;
                              Y : Real_Vector ) return Real_Vector ;
...

^ permalink raw reply	[relevance 7%]

* Re: The answer to "Can Ada replace FORTRAN for numerical computation?
  @ 2019-07-23  1:35  6% ` Brad Moore
  0 siblings, 0 replies; 114+ results
From: Brad Moore @ 2019-07-23  1:35 UTC (permalink / raw)


On Sunday, July 21, 2019 at 10:38:16 PM UTC-6, Nasser M. Abbasi wrote:
> In 1980 there was a paper titled "Can Ada replace FORTRAN for numerical computation?"
> 
> ACM SIGPLAN Notices
> Volume 16, Number 12, December, 1981
> 
> 
> https://dl.acm.org/citation.cfm?id=954264
> 
> "
> In July 1980, the proposed final form of the Ada programming
> language was released by the U.S. Department of Defense [1]. Even
> though Ada was not designed specifically for general numeric
> scientific computation, nevertheless the question arises to whether
> it is appropriate for this purpose. This question can best
> be answered by consideration of the following question: Is Ada
> a suitable replacement for the programming language FORTRAN? This
> paper discusses those constructs of Ada which are pertinent to the
> matter and are considered defective. It is noted that the array defects
> are exceptionally critical, not providing needed capabilities
> that exist in FORTRAN and have been extensively used for
>   a quarter century."
> 
> I can't find free version of the paper, any one knows of one? but
> there was more discussion on it here:
> 
> https://archive.org/stream/DTIC_ADA139224/DTIC_ADA139224_djvu.txt
> 
> (just search for string "can ada")
> 
> _But_ to answer the question in the title of the paper, and
> after FORTY years, it is clear now that the answer is a
> resounding NO.

If the goal was to have Ada replace Fortran, that was never a realistic goal to begin with, for many reasons. One being that there exists a lot of legacy Fortran code out there, and secondly I cannot think of any cases where language X replaced language Y. There will likely always be supporters existing for language Y, expecially if it better fits a particular niche.

> 
> Too bad, because Ada could have been best language for numerical
> computation due to its strong typing. But its lack of support
> for many things related to linear algebra and such, as discussed
> in the above, Ada could not replace Fortran.

That being said, a lot has happenned to Ada since Ada 83, when those articles were written, including support for things like linear algebra and such. See Ada.Numerics.Generic_Real_Arrays and Ada.Numerics. Ada.Numerics.Generic_Complex_Arrays, which include routes to Solve matrices, and perform various other operations on them.

e.g.

    --  Real_Matrix inversion and related operations

   function Solve (A : Real_Matrix; X : Real_Vector) return Real_Vector;
   function Solve (A, X : Real_Matrix) return Real_Matrix;
   function Inverse (A : Real_Matrix) return Real_Matrix;
   function Determinant (A : Real_Matrix) return Real'Base;

Brad

^ permalink raw reply	[relevance 6%]

* Re: old problem
  2019-05-30 10:26  7% old problem Gilbert Gosseyn
  2019-05-30 17:08  0% ` Anh Vo
  2019-05-31  1:04  0% ` Keith Thompson
@ 2019-05-31 12:37  8% ` Simon Wright
  2 siblings, 0 replies; 114+ results
From: Simon Wright @ 2019-05-31 12:37 UTC (permalink / raw)


Gilbert Gosseyn <hnptz@yahoo.de> writes:

> How to keep the dimensions Dx,Dy,gK open until execution?

You could make allx a generic, as in the following. I used gnatpp &
adjusted casing; I used 'Range rather than 1 .. Dx etc, but it would
have been possible to make the values visible in the generic
instantiation, e.g.

   Actual_Dx : constant := Dx;

but using the attribute ('Range) is better.

with Ada.Numerics.Generic_Real_Arrays;
generic
   with package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (<>);
   Dx, Dy, gK : Positive;
package Allx is
   subtype RM is Real_Arrays.Real_Matrix (1 .. Dy, 1 .. Dx);
   type Weight_Array is array (1 .. gK) of RM;
end Allx;

with Ada.Numerics.Generic_Real_Arrays;
with Allx;
with Ada.Text_IO; use Ada.Text_IO;
procedure Testall is
   type Real is digits 18;
   package RIO is new Ada.Text_IO.Float_IO (Real);
   package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
   package My_Allx is new Allx (Real_Arrays => Real_Arrays,
                                Dx => 3,
                                Dy => 5,
                                Gk => 3);
   use My_Allx;
   W : Weight_Array;
   D : RM := (others => (others => 1.0));
   procedure Testallx (D1 : RM; W1 : in out Weight_Array) is
      use Real_Arrays;
   begin
      for I in W1'Range loop
         W1 (I) := Real (I) * D1;
      end loop;
   end Testallx;
begin
   Testallx (D, W);
   for K in D'Range (2) loop
      New_Line;
      for I in D'Range (1) loop
         New_Line;
         for J in W'Range loop
            RIO.Put (W (K) (I, J));
         end loop;
      end loop;
      New_Line;
   end loop;
end Testall;

^ permalink raw reply	[relevance 8%]

* Re: old problem
  2019-05-30 10:26  7% old problem Gilbert Gosseyn
  2019-05-30 17:08  0% ` Anh Vo
@ 2019-05-31  1:04  0% ` Keith Thompson
  2019-05-31 12:37  8% ` Simon Wright
  2 siblings, 0 replies; 114+ results
From: Keith Thompson @ 2019-05-31  1:04 UTC (permalink / raw)


Gilbert Gosseyn <hnptz@yahoo.de> writes:
> with Ada.Numerics; use Ada.Numerics;
> with Ada.Numerics.Generic_Real_Arrays;
> package allx is
>    type Real is digits 18;
>    package RA is new Ada.Numerics.Generic_Real_Arrays(Real);
>    use RA;
>    Dx,Dy,gK : Positive;
>    subtype RM is Real_Matrix(1..Dy,1..Dx);
>    type weight_array is array(1..gK) of RM;
> end allx;
[...]

Dy and Dx are uninitialized when Real_Matrix is defined.  Their values
will be arbitrary garbage when the declaration of RM is elaborated.
(I'm a bit surprised you didn't get a compile-time warning.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

^ permalink raw reply	[relevance 0%]

* Re: old problem
  2019-05-30 10:26  7% old problem Gilbert Gosseyn
@ 2019-05-30 17:08  0% ` Anh Vo
  2019-05-31  1:04  0% ` Keith Thompson
  2019-05-31 12:37  8% ` Simon Wright
  2 siblings, 0 replies; 114+ results
From: Anh Vo @ 2019-05-30 17:08 UTC (permalink / raw)


On Thursday, May 30, 2019 at 3:26:17 AM UTC-7, Gilbert Gosseyn wrote:
> with Ada.Numerics; use Ada.Numerics;
> with Ada.Numerics.Generic_Real_Arrays;
> package allx is
>    type Real is digits 18;
>    package RA is new Ada.Numerics.Generic_Real_Arrays(Real);
>    use RA;
>    Dx,Dy,gK : Positive;
>    subtype RM is Real_Matrix(1..Dy,1..Dx);
>    type weight_array is array(1..gK) of RM;
> end allx;
> 
> with allx; use allx;
> with Ada.Text_IO;use Ada.Text_IO;
> procedure testall is
>    package RIO is new Float_IO(Real);
>    use RIO;
>    use allx.RA;
>    W : weight_array;
>    D : RM := (others => (others => 1.0));
>    procedure testallx(D1 : RM;
>                       W1 : in out weight_array) is
>    begin
>       for i in 1..gK loop
>          W1(i) := Real(i)*D1;
>       end loop;
>    end testallx;
> 
> begin
>    Dx := 3;
>    Dy := 5;
>    gK := 3;
>    testallx(D,W);
>    for k in 1..Dx loop
>       new_line(2);
>       for i in 1..Dy loop
>          new_line;
>          for j in 1..gK loop
>             RIO.put(W(k)(i,j));
>          end loop;
>       end loop;
>    end loop;
> end testall;
> 
> raised CONSTRAINT_ERROR : testall.adb:13  (W1(i) := ...)  index check failed, and of course if I use numbers in package allx, then W1(i) is known.
> How to keep the dimensions Dx,Dy,gK open until execution?

Lines 7 and 8 will trigger a CONSTRAINT_ERROR warning when this problem is compiled under GNAT. 

Replace 

   subtype RM is Real_Matrix(1..Dy,1..Dx); 
   type weight_array is array(1..gK) of RM; 

with 
   
   Max : constant := 100;  -- can be adjusted
   subtype Index_Range is Positive range 1 .. Max;
   subtype RM is Real_Matrix(Index_Range, Index_Range); 
   type weight_array is array(Index_Range) of RM; 

Anh Vo


^ permalink raw reply	[relevance 0%]

* old problem
@ 2019-05-30 10:26  7% Gilbert Gosseyn
  2019-05-30 17:08  0% ` Anh Vo
                   ` (2 more replies)
  0 siblings, 3 replies; 114+ results
From: Gilbert Gosseyn @ 2019-05-30 10:26 UTC (permalink / raw)


with Ada.Numerics; use Ada.Numerics;
with Ada.Numerics.Generic_Real_Arrays;
package allx is
   type Real is digits 18;
   package RA is new Ada.Numerics.Generic_Real_Arrays(Real);
   use RA;
   Dx,Dy,gK : Positive;
   subtype RM is Real_Matrix(1..Dy,1..Dx);
   type weight_array is array(1..gK) of RM;
end allx;

with allx; use allx;
with Ada.Text_IO;use Ada.Text_IO;
procedure testall is
   package RIO is new Float_IO(Real);
   use RIO;
   use allx.RA;
   W : weight_array;
   D : RM := (others => (others => 1.0));
   procedure testallx(D1 : RM;
                      W1 : in out weight_array) is
   begin
      for i in 1..gK loop
         W1(i) := Real(i)*D1;
      end loop;
   end testallx;

begin
   Dx := 3;
   Dy := 5;
   gK := 3;
   testallx(D,W);
   for k in 1..Dx loop
      new_line(2);
      for i in 1..Dy loop
         new_line;
         for j in 1..gK loop
            RIO.put(W(k)(i,j));
         end loop;
      end loop;
   end loop;
end testall;

raised CONSTRAINT_ERROR : testall.adb:13  (W1(i) := ...)  index check failed, and of course if I use numbers in package allx, then W1(i) is known.
How to keep the dimensions Dx,Dy,gK open until execution?


^ permalink raw reply	[relevance 7%]

* Generic library design
@ 2018-04-06 13:22  7% Marius Amado-Alves
  0 siblings, 0 replies; 114+ results
From: Marius Amado-Alves @ 2018-04-06 13:22 UTC (permalink / raw)


Hello hive mind. Designing a few generic libraries involving real and complex number types and arrays thereof. Undecided as to the type of generic parameter(s). Namely:

When should the parameter(s) be the base real type like (examples drawn from the standard, please extrapolate)

   generic
      type Real is digits <>;
   package Ada.Numerics.Generic_Real_Arrays is
   ...

with the necessary sidekicks e.g. Generic_Elementary_Functions instantiated internally,

when should it be one or more packages like 

   generic
      with package Real_Arrays   is new
         Ada.Numerics.Generic_Real_Arrays   (<>);
      use Real_Arrays;
      with package Complex_Types is new
         Ada.Numerics.Generic_Complex_Types (Real);
      use Complex_Types;
   package Ada.Numerics.Generic_Complex_Arrays is
   ...

with the set or a subset of the necessary entities "pre-instantiated" by the user? Is there a design "rule"?

Consider the running example: why is Ada.Numerics.Generic_Complex_Arrays parametrized by packages, instead of just a Real type and then instantiate the packages intarnally?

And are compilers smart enough to merge identical instances w.r.t. to their generic arguments? Maybe with help of qualification pragmas telling there is no state?

No need to answer to all questions at once:-)

Thanks a lot.


^ permalink raw reply	[relevance 7%]

* Re: Mathpaqs release 13-Mar-2018
  @ 2018-03-16 17:59  5%   ` gautier_niouzes
  0 siblings, 0 replies; 114+ results
From: gautier_niouzes @ 2018-03-16 17:59 UTC (permalink / raw)


Hi Vincent,

> Just a few questions :
> - why not use the standard Generic Real Arrays ?
Good point! I'll update the web site with a remark from g_matrices.ads: "NB: For Ada 2005+ and real numbers implemented as floating-point numbers, it is better to use Ada.Numerics.Generic_Real_Arrays instead.". An usage of G_Matrices can be for complex, rational, "bignum"-rationals, etc. ...

> - Are the G_Matrices stored in Fortran convention, i.e. Column Major Order ?
By default not, but you can add a pragma Convention.

> - Are they compatible with Blas & Lapack ?
Some stuff in the lin_alg area is, but frankly it is a bit rusty (in my head)...

> - Are the SparseB matrices compatible with Matlab matrices (i.e. CSC matrices)
SparseB is just a helper for Sparse package (I did it in Ada 83 around end 1990's, it would be a private child package now (tbd)...).
There are two bodies for sparseb: one standalone, one using Blas (sparseb.blas.adb)

> - Are both format interoperable ?
> - Are they interchangeable, i.e is there a common class type to manipulate them?

I've used for research purposes, interchangeably:
- plain matrices,
- band matrices (a matrix with zeroes outside diagonals and the cells just above and below) and
- sparse matrices.
I did it through generics.

^ permalink raw reply	[relevance 5%]

* Re: 64-bit unsigned integer?
  @ 2018-03-01  8:35  6%               ` Simon Wright
  0 siblings, 0 replies; 114+ results
From: Simon Wright @ 2018-03-01  8:35 UTC (permalink / raw)


Niklas Holsti <niklas.holsti@tidorum.invalid> writes:

> As long as the new numeric libraries let us write computations using
> the normal algebraic syntax (A * B + C), I have nothing against
> library solutions.

See Ada.Numerics.Generic_Real_Arrays.

Also, operator precedence is defined by the operator, not the package in
which it's declared for a particular type.


^ permalink raw reply	[relevance 6%]

* Re: GNAT can't vectorize Real_Matrix multiplication from Ada.Numerics.Real_Arrays. What a surprise!
  @ 2018-02-18 22:50  5%             ` Bojan Bozovic
  0 siblings, 0 replies; 114+ results
From: Bojan Bozovic @ 2018-02-18 22:50 UTC (permalink / raw)


On Sunday, February 18, 2018 at 10:48:42 PM UTC+1, Nasser M. Abbasi wrote:
> On 2/18/2018 1:38 PM, Bojan Bozovic wrote:
> 
> If you are doing A*B by hand, then you are doing something
> wrong. Almost all languages end up calling Blas
> Fortran libraries for these operations. Your code and
> the Ada code can't be faster.
> 
> http://www.netlib.org/blas/
> 
> Intel Math Kernel Library has all these.
> 
> https://en.wikipedia.org/wiki/Math_Kernel_Library
> 
> --Nasser

Well I wanted to compare how Ada would do against C simply in 4x4 matrix multiplication, and I was surprised to see several times slower results, so I tried then to code 'by hand' to attempt to achieve the same speed with Ada (and the speed is comparable). I'm just learning the language and so I was unaware of it's finesses (such as making new instance of Ada.Numerics.Generic_Real_Arrays). Thanks for the links. I will have to bookmark them.


^ permalink raw reply	[relevance 5%]

* Re: GNAT can't vectorize Real_Matrix multiplication from Ada.Numerics.Real_Arrays. What a surprise!
  2018-02-18 13:31  6%       ` Jeffrey R. Carter
@ 2018-02-18 19:38  0%         ` Bojan Bozovic
    0 siblings, 1 reply; 114+ results
From: Bojan Bozovic @ 2018-02-18 19:38 UTC (permalink / raw)


On Sunday, February 18, 2018 at 2:31:18 PM UTC+1, Jeffrey R. Carter wrote:
> On 02/18/2018 01:05 PM, Bojan Bozovic wrote:
> > Thanks very much for clarification! It's always good to learn something new, I suppose.
> 
> The real optimization in your example seems to be that the compiler optimizes 
> away the 10E6 loop around the in-line code, but not around the call to "*". 
> Removing both loops gives similar times for both multiplications. The call to 
> "*" will never be as fast because it copies its result into your variable. 
> Replacing Ada.Numerics.Real_Arrays with an instantiation of 
> Ada.Numerics.Generic_Real_Arrays gives an additional factor of 2 reduction.
> 
> -- 
> Jeff Carter
> Just as Khan was hindered by two-dimensional thinking in a
> three-dimensional situation, so many developers are hindered
> by sequential thinking in concurrent situations.
> 118

And indeed, now everything is in its place, as I don't see matrix multiplication several times slower than doing things 'by hand'. I have used aggressive optimization because in this day its custom a program to manipulate over gigabytes or even terabytes of data, while being at most megabytes in size - so compiling for various processors of the same family and using launcher program which will query processor capability and run optimally optimized program is nothing new - one might say most computation now is done on GPU but then also exact capabilities of GPU must be known. Thanks for making my Ada learning experience an enjoyment!

^ permalink raw reply	[relevance 0%]

* Re: GNAT can't vectorize Real_Matrix multiplication from Ada.Numerics.Real_Arrays. What a surprise!
  @ 2018-02-18 13:31  6%       ` Jeffrey R. Carter
  2018-02-18 19:38  0%         ` Bojan Bozovic
  0 siblings, 1 reply; 114+ results
From: Jeffrey R. Carter @ 2018-02-18 13:31 UTC (permalink / raw)


On 02/18/2018 01:05 PM, Bojan Bozovic wrote:
> Thanks very much for clarification! It's always good to learn something new, I suppose.

The real optimization in your example seems to be that the compiler optimizes 
away the 10E6 loop around the in-line code, but not around the call to "*". 
Removing both loops gives similar times for both multiplications. The call to 
"*" will never be as fast because it copies its result into your variable. 
Replacing Ada.Numerics.Real_Arrays with an instantiation of 
Ada.Numerics.Generic_Real_Arrays gives an additional factor of 2 reduction.

-- 
Jeff Carter
Just as Khan was hindered by two-dimensional thinking in a
three-dimensional situation, so many developers are hindered
by sequential thinking in concurrent situations.
118

^ permalink raw reply	[relevance 6%]

* Re: GNAT can't vectorize Real_Matrix multiplication from Ada.Numerics.Real_Arrays. What a surprise!
  @ 2018-02-18 10:35  7%   ` Jeffrey R. Carter
    0 siblings, 1 reply; 114+ results
From: Jeffrey R. Carter @ 2018-02-18 10:35 UTC (permalink / raw)


On 02/18/2018 02:51 AM, Bojan Bozovic wrote:
> 
> Apart from response that they don't offer support on GPL versions of compiler, I got no response. I hope this will be useful to someone.

Nor should you expect anything to happen, since you have not found an error. An 
error is when the compiler accepts illegal code, rejects legal code, or produces 
object code that gives incorrect results. At best you have found an opportunity 
for better optimization. Even that seems unlikely.

Remember that Ada.Numerics.Real_Arrays."*" is a general-purpose library 
function. As such, it has to do things that your specific implementation of 
matrix multiplication doesn't: It has to check that Left'Length (2) = 
Right'Length (1) and raise an exception if they're not equal. Your code doesn't, 
and any such check should be optimized away because its condition will be 
statically False. The general code has to handle the case where Left'First (2) 
/= Right'First (1). Even when the offset is zero, that's still an extra addition 
in the inner loop.

Also, Ada.Numerics.Real_Arrays is provided precompiled, and is surely compiled 
with different optimization options than your code. (IIRC, -O3 is considered 
experimental, and AdaCore is not going to compile its library code with 
experimental optimization.)

You can find GNAT's implementation of matrix multiplication as 
System.Generic_Array_Operations.Matrix_Matrix_Product. This is extremely 
general, allowing for non-numeric matrix components (complex numbers, for 
example), and different component types for the left, right, and result 
matrices. This may introduce additional barriers to optimization.

Since Ada.Numerics.Real_Arrays is an instantiation of 
Ada.Numerics.Generic_Real_Arrays for Float, and GNAT does macro expansion of 
generics, if you use an explicit instantiation of 
Ada.Numerics.Generic_Real_Arrays in your code, it should be compiled with your 
compiler options and thus remove that variable from your comparison. Doing that 
in your code, and building with

gnatmake -O3 -mavx2 matrix_mul -largs -s

cuts the reported time for "*" by a factor of about 4. Not surprisingly, still 
slower. YMMV

-- 
Jeff Carter
Just as Khan was hindered by two-dimensional thinking in a
three-dimensional situation, so many developers are hindered
by sequential thinking in concurrent situations.
118

^ permalink raw reply	[relevance 7%]

* Re: How to access an array using two different indexing schemes
  2017-11-24 17:37  7% ` A. Cervetti
  2017-11-24 21:48  0%   ` Jerry
@ 2017-11-28  1:25  0%   ` Randy Brukardt
  1 sibling, 0 replies; 114+ results
From: Randy Brukardt @ 2017-11-28  1:25 UTC (permalink / raw)


"A. Cervetti" <andrea.cervetti@gmail.com> wrote in message 
news:e3a1f97e-7cbd-4327-aef6-c18ca9e74bc2@googlegroups.com...
>use attribute 'Address:
>
>with Ada.Text_IO; use Ada.Text_IO;
>with Ada.Float_Text_IO; use Ada.Float_Text_IO;
>with Ada.Numerics.Generic_Real_Arrays;
>
>procedure Double_Array is
>   package Real_Array is new Ada.Numerics.Generic_Real_Arrays(Float);
>   use Real_Array;
>
>   x : Real_Vector(0 .. 4) := (1.0, 2.0, 3.0, 4.0, 5.0);
>   y : Real_Vector(1 .. 5);
>   for Y'Address use X'Address; -- <<<<<<<<<<<<<<<<<<<<

An evil and not guaranteed to work on all implementation technique.

The OP just needs to use an appropriate type conversion to change the bounds 
of their array (odd no one has mentioned that):

If one has:

   subtype RV1_5 is Real_Vector(1..5);

Then the type conversion:
    RV1_5(X) has the new bounds, and (by itself) doesn't copy any memory.

Thus, using a subprogram to temporarily bind the object shouldn't result in 
any copying of the data (no guarantees, of course, but it will always work - 
rememberm avoid premature optimization!):

    procedure Do_Y (Y : RV1_5) is
    begin
         -- Operations on Y.
    end Do_Y;

    ...
    Do_Y (RV1_5(X));

This is the best way to change the bounds of an array (or part of an array) 
in Ada.

                                                            Randy.



begin
   X(0) := 20.0;
   Put(X(0), 0, 0, 0); New_Line;
   Put(Y(1), 0, 0, 0); New_Line;
end Double_Array;

A. 


^ permalink raw reply	[relevance 0%]

* Re: How to access an array using two different indexing schemes
  2017-11-24 17:37  7% ` A. Cervetti
@ 2017-11-24 21:48  0%   ` Jerry
  2017-11-28  1:25  0%   ` Randy Brukardt
  1 sibling, 0 replies; 114+ results
From: Jerry @ 2017-11-24 21:48 UTC (permalink / raw)


On Friday, November 24, 2017 at 10:37:30 AM UTC-7, A. Cervetti wrote:
> use attribute 'Address:
> 
> with Ada.Text_IO; use Ada.Text_IO;
> with Ada.Float_Text_IO; use Ada.Float_Text_IO;
> with Ada.Numerics.Generic_Real_Arrays;
> 
> procedure Double_Array is
>    package Real_Array is new Ada.Numerics.Generic_Real_Arrays(Float);
>    use Real_Array;
>    
>    x : Real_Vector(0 .. 4) := (1.0, 2.0, 3.0, 4.0, 5.0);
>    y : Real_Vector(1 .. 5);
>    for Y'Address use X'Address; -- <<<<<<<<<<<<<<<<<<<<
>    
> begin
>    X(0) := 20.0;
>    Put(X(0), 0, 0, 0); New_Line;
>    Put(Y(1), 0, 0, 0); New_Line;
> end Double_Array;

Nice. Thank you. That solves the "version control" or "bookkeeping" problem, but it still requires allocating double memory, for y.

I had hoped to use an access variable for the role of y so that only a tiny amount of additional memory would be required, and somehow do a type conversion of the y-pointer as it points at x, but I haven't been able yet to figure out how to do the pointer type conversion. Is this even possible?

Jerry


^ permalink raw reply	[relevance 0%]

* Re: How to access an array using two different indexing schemes
  @ 2017-11-24 17:37  7% ` A. Cervetti
  2017-11-24 21:48  0%   ` Jerry
  2017-11-28  1:25  0%   ` Randy Brukardt
  0 siblings, 2 replies; 114+ results
From: A. Cervetti @ 2017-11-24 17:37 UTC (permalink / raw)


Il giorno venerdì 24 novembre 2017 12:42:08 UTC+1, Jerry ha scritto:

> I'm currently looking at System.Address_To_Access_Conversions but I thought I would query the list in the meantime.

use attribute 'Address:

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Numerics.Generic_Real_Arrays;

procedure Double_Array is
   package Real_Array is new Ada.Numerics.Generic_Real_Arrays(Float);
   use Real_Array;
   
   x : Real_Vector(0 .. 4) := (1.0, 2.0, 3.0, 4.0, 5.0);
   y : Real_Vector(1 .. 5);
   for Y'Address use X'Address; -- <<<<<<<<<<<<<<<<<<<<
   
begin
   X(0) := 20.0;
   Put(X(0), 0, 0, 0); New_Line;
   Put(Y(1), 0, 0, 0); New_Line;
end Double_Array;

A.

^ permalink raw reply	[relevance 7%]

* Re: Help needed - "Storage_Error stack overflow or erroneous memory access"
  @ 2017-06-19  4:53  6%             ` reinert
  0 siblings, 0 replies; 114+ results
From: reinert @ 2017-06-19  4:53 UTC (permalink / raw)


OK, for those having interest:

I have somehow sorted out the problem. 
The lesson learned is that I may have done something wrong when using "with invariant .." and the compiler error message could be more helpful for programmers like me :-) 

Here is a test program illustrating. It compiles without error on my debian 8.8 (jessie) machine, but the debian 9 (stretch) gives a cryptic error message.
Could anybody confirm? And maybe elaborate?

with frame1;         use frame1;
procedure c0 is
   df : df_t;
begin
   df.center0 (True);
end c0;

-- package:

with Ada.Numerics.Generic_Real_Arrays;

package frame1 is

   subtype real is float;

   package gra is new Ada.Numerics.Generic_Real_Arrays (real);
   use gra;

   type frame_t is tagged private;

   procedure center0 (frame : in out frame_t; b : Boolean);

   type df_t is new frame_t with private;

private

   type frame_t is tagged record
      a, b                           : Boolean := False;
      r_a, r_b                       : real_vector(1..2);
      set_modus                      : Boolean := False;
      dynamic_frame1, dynamic_frame2 : real_vector (1 .. 2);
      center0                        : Boolean := False;
      active1                        : Boolean := False;
      w1,w2                          : real_vector(1..2);
   end record with
       type_invariant =>
             ((if
               frame_t.set_modus
         then
           frame_t.dynamic_frame1 (1) <= frame_t.dynamic_frame2 (1) and
           frame_t.dynamic_frame1 (2) >= frame_t.dynamic_frame2 (2)));

   type df_t is new frame_t with record
      focus1 : Boolean              := False;
   end record;

end frame1;

package body frame1 is

   procedure center0 (frame : in out frame_t; b : Boolean) is
   begin
      frame.center0 := b;
   end center0;

end frame1;




~        

^ permalink raw reply	[relevance 6%]

* Re: Arrays in Ada 2020
  @ 2017-06-18 12:06  6%     ` Robert Eachus
  0 siblings, 0 replies; 114+ results
From: Robert Eachus @ 2017-06-18 12:06 UTC (permalink / raw)


On Saturday, June 17, 2017 at 11:00:15 PM UTC-4, Nasser M. Abbasi wrote:
> On 6/17/2017 9:14 PM, Ivan Levashev wrote:
> > 
> > FYI Ada 2020 is about to bring some improvements:
> > 
> > http://www.ada-auth.org/standards/2xrm/html/RM-4-3-3.html
> > 
> >> G : constant Matrix :=
> >>      (for I in 1 .. 4 =>
> >>         (for J in 1 .. 4 =>
> >>            (if I = J then 1.0 else 0.0))); -- Identity matrix
> > 
> > Best Regards,
> > Ivan Levashev,
> > Barnaul
> 
> That is nice. But still too much code for such common operation.

What about:

with Ada.Numerics.Generic_Real_Arrays;
procedure Main is
   package My_Arrays is new Ada.Numerics.Generic_Real_Arrays(Long_Float);
   use My_Arrays;
   Identity_4: Real_Matrix := Unit_Matrix(4); 
begin null; end Main;

On a different but related subject, the body of Unit_Matrix should look like:
    function Unit_Matrix (Order           : Positive;
                         First_1, First_2 : Integer := 1)
                                            return Real_Matrix is
      Result: Real_Matrix(First_1..First_1+Order,
                     First_2..First_2+Order) := (others => 
                                                (others => 0.0));
   begin
     for I in First_1..First_1+Order loop
        Result(I, I-First_1+First_2) := 1.0;
     end loop;
     return Result;
   end Unit_Matrix;

On modern virtual memory machines, new space (as opposed to reused stack space) is cleared to zeros and the compiler knows it.  If you are allocating a large chunk of memory (in theory on the stack), the compiler can grab new memory and put a pointer on the stack.  If you are working with large matrices, you either expect this to happen or handle it yourself.  Setting the diagonal values to 1.0 is an operation repeated Order times not Order squared times, so let the compiler do the zeros as fast as possible, then worry about the ones.

Oh, and the compiler should create Result in place, rather than copying back.  The fact that the view of the object that Unit_Matrix is assigned to may be constant won't affect things, the view of Result inside Unix_Matrix is not constant.

^ permalink raw reply	[relevance 6%]

* Re: Question about sets and expression
  @ 2017-05-09  5:48  7%     ` reinert
  0 siblings, 0 replies; 114+ results
From: reinert @ 2017-05-09  5:48 UTC (permalink / raw)


Could anybody try this simple program below?

I get the output (debian, gnat-4.9):

--------------------------------------------------------------------------
** A: 
** B: 

raised PROGRAM_ERROR : test1b.adb:29 finalize/adjust raised exception
--------------------------------------------------------------------------
 Why "finalize/adjust raised exception" ?

reinert
https://korsnesbiocomputing.no/


with Ada.Numerics;
use  Ada.Numerics;
with Ada.Numerics.Generic_Real_Arrays;
with Ada.Containers.Ordered_Sets;

with Text_IO;use Text_IO;
procedure test1b is

   subtype real is Float;
   subtype degree_t is real range 0.0 .. 360.0;
   package gra is new Ada.Numerics.Generic_Real_Arrays (real);
   use gra;
   subtype real_vector2d is gra.real_vector (1 .. 2);
   type target_t is (cnil,C000,C001,C002,C003,C004);
   package cell_names_sets is new Ada.Containers.Ordered_Sets (target_t);

   type cell_state_t is
     (live,
      apoptosis,
      necrotic,
      dead,
      mitosis,
      mitotic_catastrophe,
      refusion,
      unknown,
      out_of_scene,
      ghost);

   type cell_observation_t is record
      id                  : target_t;
      state               : cell_state_t         := live;
      r, dr               : real_vector2d        := (0.0, 0.0);
      axis                : degree_t;
      children1           : cell_names_sets.set  := cell_names_sets.empty_set;
      pre_cell, next_cell : target_t             := cnil;
   end record;

   function "<"
     (left, right : cell_observation_t) return Boolean is
     (left.id < right.id);
   function "="
     (left, right : cell_observation_t) return Boolean is
     (left.id = right.id);

    package cell_observation_set is new Ada.Containers.Ordered_Sets
     (Element_Type => cell_observation_t);
    use cell_observation_set;

    os : cell_observation_set.set := to_set((id => C003,others => <>));
    c : cell_observation_t;
    d : cell_observation_t := (id => Cnil,others => <>);

begin

 Put_Line(" ** A: ");
 c := (if not os.is_empty then os.first_element else d);
 Put_Line(" ** B: ");
 c := (if not os.is_empty then os.first_element else (id => Cnil, others => <>));
 Put_Line(" ** C ");

end test1b;


^ permalink raw reply	[relevance 7%]

* A thicker binding for Lapack
@ 2012-12-27 18:48  5% jpwoodruff
  0 siblings, 0 replies; 114+ results
From: jpwoodruff @ 2012-12-27 18:48 UTC (permalink / raw)


There is a complete thin binding for lapack available which was
evidently started by Wasu Chaopanon in about 1996 and was recently
finished by Nasser Abbasi.  There about 1000 subroutines; their
parameter signatures exactly translate the Fortran, and each procedure
is Pragma Imported.

I've been considering adding value to that binding to address two
perceived problems:

The specification involving the integer index used for matrix types is
inconsistent between the binding and Ada.Numerics.Generic_Real_Arrays.
The binding declares that type because the user's code must comply
with Fortran's integer.  The Ada compiler is obliged to use that same
type.  Unfortunately Generic_Real_Arrays uses the base type integer
for index, so there is no expectation that the representation would be
the same as Fortran-compiled library.

Another issue to resolve is that lapack, being Fortran, defines
column-major storage while Ada is row-major.  Parameters passing
between these two conventions evidently must be transposed.

I think I have a technique for interoperating with the Ada.Numerics
types.  My plan involves "wrapping" the lapack routines in a layer
that converts types and transposes matrices.

Here is a typical procedure specification as translated directly from
the fortran, with my transformation to Ada standard types.

   procedure SGESV
     (N    : Natural;
      NRHS : Natural;
      A    : in out Real_Arrays.Real_Matrix;   -- instance of Generic_
      LDA  : Natural ;
      IPIV : out Integer_Vector;
      B    : in out Real_Arrays.Real_Matrix;
      LDB  : Natural ;
      INFO : out Integer) ;

The math requirements for this procedure are very much like the
"Solve" that was discussed in a recent thread.

   -- function Solve (A : Real_Matrix; X : Real_Vector) return
   -- Real_Vector;

The B parameter in sgesv resembles X in the "Why X as argument name?"
discussion.  I am trying to make the lapack item as serviceable as the
gnat standard item.

My trials at maintaining parameter definitions that echo the Fortran
binding have led only to grief.  The integer inputs N, NRHS, LDA, LDB
make precious little sense, considering the transposition of the
matrices that takes place inside the body of procedure sgesv.

After several drafts I'm thinking that a thick binding might look
like this:

   procedure SGESV
      (A   : in out Real_Arrays.Real_Matrix;
      IPIV : out Integer_Vector;
      B    : in out Real_Arrays.Real_Matrix;
      INFO : out Integer) ;

Programming with Ada attributes seems to clarify the relations between
the several parameters.  Now I think that the integer parameters will
be computed inside the body of the overlay procedure.  Still working
on the details.

Guided by the spiral model I'll try a couple examples.  Later if there
is a benefit to Ada programmers interested in numeric analysis I'll
address the scale of the massive lapack library.

Suggestions are welcome!

John



^ permalink raw reply	[relevance 5%]

* Re: problem with Real_Matrix*Real_Matrix
  2012-09-17 13:37  7% problem with Real_Matrix*Real_Matrix reinkor
@ 2012-09-17 17:01  0% ` Niklas Holsti
  0 siblings, 0 replies; 114+ results
From: Niklas Holsti @ 2012-09-17 17:01 UTC (permalink / raw)


On 12-09-17 16:37 , reinkor wrote:
> Dear All,
> 
> I am confused about my result from the multiplication r*M where
> r is Real_Vector and M is Real_Matrix. Enclosed is my test program
> including comments.  Could someone look at it and maybe help me out
> of my bubble?
> 
> 
> I use gcc-ada-4.7-2.1.1.x86_64 under OpenSuse 12.2

I get the expected result:

** r*M :
  3010.0  4020.0

on my Mac, with GNAT 4.5.0 20100221 (experimental) [trunk revision 156937].

I suspect your Ada installation is broken, but I don't have any advice
on how to fix it, sorry.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .


> 
> reinert
> 
> 
> with Text_IO;
> use  Text_IO;
> with   ada.numerics.Generic_Real_Arrays;
> 
> with Ada.Strings.Fixed;
> use  Ada.Strings,Ada.Strings.Fixed;
> 
> 
> procedure test3 is
> 
>   type Real is new Float;
> 
>   package Real_Io is new Text_IO.Float_Io   (Real);
>   use Real_Io;
> 
>   package Int_Io is new Text_IO.Integer_Io (Integer);
>   use Int_Io;
> 
>   package GRA is new Ada.Numerics.Generic_Real_Arrays(Real);
>   use GRA;
> 
>   procedure Put (X : Real_Vector) is
>   begin
>       for I in X'Range (1) loop
>           Put (X (I),6,1,0);
>       end loop;
>   end Put;
> 
>   M : Real_Matrix := ((1.0, 2.0),
>                       (3.0, 4.0));
> 
>   r : Real_Vector := (10.0,1000.0);
> 
> begin
> 
>    Put("** r*M : ");New_Line;
>    Put(r*M);
> 
> -- Extect: r*M = (10*1 + 1000*3, 10*2 + 1000*4) = (3010,4020)
> -- i.e. should r*M consists of the inner product between r and 
> -- the columns of M ?   But my program gives: 
> --
> -- ** r*M : 
> --     40.0  6000.0
> --      
> 
> end test3;
> 
> 




^ permalink raw reply	[relevance 0%]

* problem with Real_Matrix*Real_Matrix
@ 2012-09-17 13:37  7% reinkor
  2012-09-17 17:01  0% ` Niklas Holsti
  0 siblings, 1 reply; 114+ results
From: reinkor @ 2012-09-17 13:37 UTC (permalink / raw)


Dear All,

I am confused about my result from the multiplication r*M where
r is Real_Vector and M is Real_Matrix. Enclosed is my test program
including comments.  Could someone look at it and maybe help me out
of my bubble?


I use gcc-ada-4.7-2.1.1.x86_64 under OpenSuse 12.2

reinert


with Text_IO;
use  Text_IO;
with   ada.numerics.Generic_Real_Arrays;

with Ada.Strings.Fixed;
use  Ada.Strings,Ada.Strings.Fixed;


procedure test3 is

  type Real is new Float;

  package Real_Io is new Text_IO.Float_Io   (Real);
  use Real_Io;

  package Int_Io is new Text_IO.Integer_Io (Integer);
  use Int_Io;

  package GRA is new Ada.Numerics.Generic_Real_Arrays(Real);
  use GRA;

  procedure Put (X : Real_Vector) is
  begin
      for I in X'Range (1) loop
          Put (X (I),6,1,0);
      end loop;
  end Put;

  M : Real_Matrix := ((1.0, 2.0),
                      (3.0, 4.0));

  r : Real_Vector := (10.0,1000.0);

begin

   Put("** r*M : ");New_Line;
   Put(r*M);

-- Extect: r*M = (10*1 + 1000*3, 10*2 + 1000*4) = (3010,4020)
-- i.e. should r*M consists of the inner product between r and 
-- the columns of M ?   But my program gives: 
--
-- ** r*M : 
--     40.0  6000.0
--      

end test3;





^ permalink raw reply	[relevance 7%]

* Reason for elements of 'ada.numerics.generic_real_arrays' real_vector and real_matrix types not being aliased ?
@ 2012-06-30  2:40  7% rodakay
  0 siblings, 0 replies; 114+ results
From: rodakay @ 2012-06-30  2:40 UTC (permalink / raw)


Hi folks,

    I guess the subject speaks for itself. Would anyone know the
reason ?


regards,
Rod.



^ permalink raw reply	[relevance 7%]

* Re: Eigenvalues to find roots of polynomials
  @ 2011-07-26 15:40  7%   ` marius63
  0 siblings, 0 replies; 114+ results
From: marius63 @ 2011-07-26 15:40 UTC (permalink / raw)


And the winner is...

> <http://home.roadrunner.com/~jbmatthews/misc/groots.html>

John B. Matthews Ada...Generic_Roots works like a charm.
It passed the simple test case, and solved my quintic problem x^5 -
4178x + 4177

$ ./find_roots_mathews 1 0 0 0 -4178 4177
Index =>  0, Position =>  6, Value => 4177
Index =>  1, Position =>  5, Value => -4178
Index =>  2, Position =>  4, Value => 0
Index =>  3, Position =>  3, Value => 0
Index =>  4, Position =>  2, Value => 0
Index =>  5, Position =>  1, Value => 1
Root 1 => (Re=> 1.00000000000000E+00, Im=> 0.00000000000000E+00)
Root 2 => (Re=>-2.47582467311450E-01, Im=>-8.05881611194044E+00)
Root 3 => (Re=> 7.76752669636581E+00, Im=>-1.40129846432482E-45)
Root 4 => (Re=>-2.47582467311450E-01, Im=> 8.05881611194044E+00)
Root 5 => (Re=>-8.27236176174291E+00, Im=> 0.00000000000000E+00)

I know from previous mathematical derivation (the polynomial comes
from extracting a variable in a summation), that the solution is a non-
negative scalar different from one, so Root 3 is my number, with the
non-zero but very small value of the imaginary part certainly only a
residue of computation done inside Matthews's magic machine. Thanks a
very great lot. Source code follows. Sorry for the mispelling,
"Mathews".

--  Trying to compute the roots of a polynomial using John Mathews
procedure.

with Ada.Command_Line;
with Ada.Numerics.Generic_Real_Arrays;
with Ada.Text_IO;
with Ada.Numerics.Generic_Complex_Types;
with Ada.Numerics.Generic_Complex_Arrays;
with Ada.Numerics.Generic_Complex_Arrays.Generic_Roots;

procedure Find_Roots_Mathews is
   type Real is digits 15;
   package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
   package Complex_Types is new Ada.Numerics.Generic_Complex_Types
(Real);
   package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays
(Real_Arrays, Complex_Types);
   procedure Complex_Roots is new Complex_Arrays.Generic_Roots;
   M, N : Natural;
begin
   M := Ada.Command_Line.Argument_Count;
   N := M - 1;
   --  N = number of arguments = degree of the polynomial + 1.
   --  The input consists of all coficients in descending degree,
   --  e.g. for polynomial
   --     x^3 - 2x^2 - x + 2
   --  the input is
   --     1 -2 -1 2
   --  Roots of the above (for testing):
   --     -1, 1, 2

   declare
      P : Complex_Arrays.Complex_Vector (0 .. N);
      R : Complex_Arrays.Complex_Vector (1 .. N);
      use Ada.Text_IO;
   begin
      for I in 0 .. N loop
         Put_Line ("Index => " & I'img &
                   ", Position => " & Integer'Image(M - I) &
                   ", Value => " & Ada.Command_Line.Argument (M - I));
         P (I) := (Re => Real'Value (Ada.Command_Line.Argument (M -
I)), Im => 0.0);
      end loop;
      Complex_Roots (P, R);
      for I in R'Range loop
         Put_Line ("Root" & I'img &
                   " => (Re=>" & R(I).Re'img &
                   ", Im=>" & R(I).Im'img & ")");
      end loop;
   end;
end;



^ permalink raw reply	[relevance 7%]

* Eigenvalues to find roots of polynomials
@ 2011-07-25 17:36  7% marius63
    0 siblings, 1 reply; 114+ results
From: marius63 @ 2011-07-25 17:36 UTC (permalink / raw)


I am trying to use Eigenvalues methods to find the roots of
polynomials... and failing miserably!
My math ability is not stellar. I used the information at

(1)
http://mathworld.wolfram.com/PolynomialRoots.html (equation 12)

and

(2)
http://en.wikipedia.org/wiki/Root_finding
(One possibility is to form the companion matrix of the polynomial.
Since the eigenvalues of this matrix coincide with the roots of the
polynomial, one can use any eigenvalue algorithm to find the roots of
the polynomial.)
http://en.wikipedia.org/wiki/Companion_matrix

I tried both schemes with the test data in (1). The output is first
the matrix, for verification, then the (wrong) roots (they should be
-1, 1, 2) and the result of applying them to the polynomial (and
yielding miserably non-zero values of course). The source code
follows. What am I missing? Thanks a lot.

$ ./find_roots 1 -2 -1 2
 5.00000E-01 1.00000E+00-5.00000E-01
 1.00000E+00 0.00000E+00 0.00000E+00
 0.00000E+00 1.00000E+00 0.00000E+00
-7.6156E-01=> 4.2003E-01
 4.1249E+00=>-1.6015E+01
 6.3667E-01=> 5.9465E-01

$ ./find_roots_wikipedia -2 -1 2
 0.00000000000000E+00,  0.00000000000000E+00, -2.00000000000000E+00,
 1.00000000000000E+00,  0.00000000000000E+00,  1.00000000000000E+00,
 0.00000000000000E+00,  1.00000000000000E+00,  2.00000000000000E+00,
-1.17008648662603E+00 => -3.38499151386795E-02
 6.88892182534018E-01 =>  1.96496630422799E+00
 2.48119430409202E+00 =>  3.00688836109107E+01


--  Trying to compute the roots of a polynomial using the method
--  described in eq. (12) of http://mathworld.wolfram.com/PolynomialRoots.html
--  (consulted July 2011)

with Ada.Command_Line;
with Ada.Numerics.Generic_Real_Arrays;
with Ada.Text_IO;
with Ada.Numerics.Generic_Complex_Types;
with Ada.Numerics.Generic_Complex_Arrays;

procedure Find_Roots is
   type Real is digits 5;
   package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
   package Complex_Types is new Ada.Numerics.Generic_Complex_Types
(Real);
   package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays
(Real_Arrays, Complex_Types);
   N, M : Natural;
begin
   N := Ada.Command_Line.Argument_Count;
   --  N = number of arguments = degree of the polynomial.
   --  The input consists of all coficients in descending degree,
   --  e.g. for polynomial
   --     x^3 - 2x^2 - x + 2
   --  the input is
   --     1 -2 -1 2
   --  Roots of the above (for testing):
   --     -1, 1, 2

   declare
      C : Complex_Arrays.Complex_Matrix (1 .. N - 1, 1 .. N - 1) :=
(others => (others => (0.0, 0.0)));
      --  Using a complex matrix because real matrices for eigenvalues
must be symmetric.
      --  Below we convert all real values to complex (with null Im
part).
      --  The complex matrix must be Hamiltonian;
      --  I thought a non-symmetric converted to complex would
      --  yield a non-Hamiltonian matrix, but I tried and it
worked :-)... hmm... NOT :-(
      A0 : Real := Real'Value (Ada.Command_Line.Argument (N));
      use Ada.Text_IO;
   begin
      for I in 1 .. N - 1 loop
         C (1, I).Re := - Real'Value (Ada.Command_Line.Argument (N -
I)) / A0;
         if I < N - 1 then
            C (I + 1, I).Re := 1.0;
         end if;
      end loop;

      --  inspect matrix
      for i in c'range(1) loop
         for j in c'range(2) loop
            put (c(i,j).re'img);
         end loop;
         new_line;
      end loop;

      declare
         V : Real_Arrays.Real_Vector := Complex_Arrays.Eigenvalues
(C);
         use Real_Arrays;
         Z : Real;
         use Ada.Text_IO;
      begin
         for I in V'Range loop
            V (I) := 1.0 / V (I);
            Put (Real'Image (V (I)));
            Z := 0.0;
            for J in 1 .. N - 1 loop
               Z := Z + C (1, J).Re * V (I) ** J;
            end loop;
            Put ("=>" & Real'Image (Z));
            New_Line;
         end loop;
      end;
   end;
end;

--  Build with:
--  gnatmake find_roots -largs /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/
libblas.dylib /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/liblapack.dylib


--  Given an Nth degree polynomial A(N)X**N + ... + A(1)X + A(0),
--  the roots can be found by finding the eigenvalues L(I) of the
matrix
--     _                                                           _
--    |   -A(1)/A(0)   -A(2)/A(0)   -A(3)/A(0)   ...   -A(N)/A(0)   |
--    |        1            0            0       ...        0       |
--    |        0            1            0       ...        0       |
--    |       ...          ...           1       ...        0       |
--    |_       0            0            0       ...        0      _|
--
--  and taking R(i) = 1/L(I). This method can be computationally
expensive,
--  but is fairly robust at finding close and multiple roots.
--    (wolphram)


--  This program computes the roots of a polynomial using the method
--  described in http://en.wikipedia.org/wiki/Companion_matrix

--  This method is for monic polynomials, i.e. with coficient of the
term
--  of greater degree equal to 1, so the input is for the remainder
terms,
--  in descending order e.g. for polynomial
--     x^3 - 2x^2 - x + 2
--  the input is
--     -2 -1 2

with Ada.Command_Line;
with Ada.Numerics.Generic_Real_Arrays;
with Ada.Text_IO;
with Ada.Numerics.Generic_Complex_Types;
with Ada.Numerics.Generic_Complex_Arrays;

procedure Find_Roots_Wikipedia is
   type Real is digits 15;
   package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
   package Complex_Types is new Ada.Numerics.Generic_Complex_Types
(Real);
   package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays
(Real_Arrays, Complex_Types);
   N : Natural;
begin
   N := Ada.Command_Line.Argument_Count;
   declare
      C : Complex_Arrays.Complex_Matrix (1 .. N, 1 .. N) := (others =>
(others => (0.0, 0.0)));
      --  Using a complex matrix because real matrices for eigenvalues
must be symmetric.
      --  Below we convert all real values to complex (with null Im
part).
      --  (Still, the complex matrix must be Hamiltonian...)
      use Ada.Text_IO;
   begin
      for I in 1 .. N loop
         C (I, N).Re := - Real'Value (Ada.Command_Line.Argument (N - I
+ 1));
         if I > 1 then
            C (I, I - 1).Re := 1.0;
         end if;
      end loop;

      --  inspect matrix
      for i in c'range(1) loop
         for j in c'range(2) loop
            put (c(i,j).re'img & ", ");
         end loop;
         new_line;
      end loop;

      declare
         V : Real_Arrays.Real_Vector := Complex_Arrays.Eigenvalues
(C);
         use Real_Arrays;
         Z : Real;
         use Ada.Text_IO;
      begin
         for I in V'Range loop
            Put (Real'Image (V (I)));
            Z := V (I) ** N;
            for J in 1 .. N loop
               Z := Z + C (N, J).Re * V (I) ** (J - 1);
            end loop;
            Put (" => " & Real'Image (Z));
            New_Line;
         end loop;
      end;
   end;
end;

--  Build with:
--  gnatmake find_roots_wikipedia -largs /Developer/SDKs/
MacOSX10.4u.sdk/usr/lib/libblas.dylib /Developer/SDKs/MacOSX10.4u.sdk/
usr/lib/liblapack.dylib



^ permalink raw reply	[relevance 7%]

* Re: Incorrect error?
  2011-07-18  8:47  8% Incorrect error? ldries46
  2011-07-18  9:45  5% ` stefan-lucks
  2011-07-18 10:39  8% ` Nicholas Collin Paul de Glouceſter
@ 2011-07-18 15:58  0% ` Adam Beneschan
  2 siblings, 0 replies; 114+ results
From: Adam Beneschan @ 2011-07-18 15:58 UTC (permalink / raw)


On Jul 18, 1:47 am, "ldries46" <bertus.dr...@planet.nl> wrote:
> I'm using Ada.Numerics.Generic_Real_Arrays. While Compiling I got the
> following error message:
>
> 65:21     expected type "Ada.Numerics.Generic_Real_Arrays.Real_Vector" from
> instance at line 6
> 65:21     found type "Ada.Numerics.Generic_Real_Arrays.Real_Matrix" from
> instance at line 6
>
> As can be seen Cross, a and b declared as Real_Vector .
> What do I do wrong?

As others have said, you're trying to do something that isn't
defined.  There is no "*" operation in Generic_Real_Arrays that takes
two Real_Vector arguments and returns a Real_Vector.

However, I think the error message GNAT is reporting is wrong, and
this should be reported as a GNAT bug.  It's no wonder you were
confused.  If there were just one function like this:

   function Product (Left : Real_Vector; Right : Real_Matrix) return
Real_Vector;

and you tried

   Cross := Product (A, B);

GNAT would say "expected type Real_Matrix ... found type Real_Vector",
which is pretty clear.  Changing "Product" to "*" and using it as an
operator causes GNAT to generate a different message "there is no
applicable operator".  But in the actual package, there are eight
definitions of "*", and the error message GNAT produces doesn't make
sense for any of them, since it's implying that you're actually using
a Real_Matrix as a parameter, when of course you aren't.

                                        -- Adam





> L. Dries
>
> Code:
>
> package Float_Arrays is new Ada.Numerics.Generic_Real_Arrays (float);
> use Float_Arrays;
>
> function Volume (ObjID : integer; Obj : ptrS_Object) return float is
>    ok     : boolean;
>    n      : integer := 1;
>    Volume : float;
>    a      : Real_Vector(0 .. 2);
>    b      : Real_Vector(0 .. 2);
>    X0     : Real_Vector(0 .. 2);
>    X1     : Real_Vector(0 .. 2);
>    X2     : Real_Vector(0 .. 2);
>    cross  : Real_Vector(0 .. 2);
>    nA     : Real_Vector(0 .. 2);
>    p      : ptrNode_Object;
>    TempS  : ptrS_Object;
>    TempT  : ptrTriangle_Object;
> begin
>    TempS := Obj;
>    while n /= ObjID loop
>       n := n + 1;
>       TempS := TempS.next;
>       if TempS = null then
>          declare
>             NO_NODE_OBJECT : exception;
>          begin
>             raise NO_NODE_OBJECT;
>          end;
>       end if;
>    end loop;
>    n := TempS.PosFaces(0);
>    TempT := stT_Object;
>    ok := TempT = null;
>    while not ok loop
>       if TempT.nr = n then
>          ok := true;
>       else
>          TempT := TempT.next;
>          ok := TempT = null;
>       end if;
>    end loop;
>    while n < TempS.PosFaces(1) loop
>       p := GetPoint(TempT.P1);
>       X0(0) := p.pRectangular(x);
>       X0(1) := p.pRectangular(y);
>       X0(2) := p.pRectangular(z);
>       p := GetPoint(TempT.P2);
>       X1(0) := p.pRectangular(x);
>       X1(1) := p.pRectangular(y);
>       X1(2) := p.pRectangular(z);
>       p := GetPoint(TempT.P3);
>       X2(0) := p.pRectangular(x);
>       X2(1) := p.pRectangular(y);
>       X2(2) := p.pRectangular(z);
>       a := X1 - X0; -- VecSub( a, X1, X0 );
>       b := X2 - X0; -- VecSub( b, X2, X0 );
>      Cross := a * b; -- VecCross( a, b, Cross );
> <---------------- line 65 the cursor is standing just before *
>       nA := Cross * 0.5; -- VecMultScalar( nA, Cross, 0.5 );
>       -- Volume = Volume + fabs(VecDot( X0, nA ));
>       Volume := Volume + X0(0)*nA(0) + X0(1)*nA(1) + X0(2)*nA(2);
>       n := n + 1;
>    end loop;
>    Volume := Volume/3.0;
>    return Volume;
> end Volume;




^ permalink raw reply	[relevance 0%]

* Re: Incorrect error?
  2011-07-18 10:40  0%   ` AdaMagica
  2011-07-18 12:39  0%     ` Dmitry A. Kazakov
@ 2011-07-18 12:45  0%     ` stefan-lucks
  1 sibling, 0 replies; 114+ results
From: stefan-lucks @ 2011-07-18 12:45 UTC (permalink / raw)


[-- Attachment #1: Type: TEXT/PLAIN, Size: 2516 bytes --]

On Mon, 18 Jul 2011, AdaMagica wrote:

> Overloading in this way might be seen as unfortunate.
> 
> > Ada.Numerics.Generic_Real_Arrays actually provides both:
> >
> > � �function "*" (Left, Right : Real_Vector) return Real'Base;
> > � �function "*" (Left, Right : Real_Vector) return Real_Matrix;
> 
> So if you have three vectors, what should A * B * C mean? Even with
> parentheses, it's awkward to read. 

I would always prefer to write such an expression with parenthesis. So 
look at the expression (A * B) * C, where A, B, and C are vectors.  
 -> A * B is either a matrix M or a number N. 
 -> M * C would be a vector. 
 -> N * C would also be a vector. 
 ===> The result type is a vector. 

But wait a minute! There are two different results (either "M * C2 or "N * 
C"), and we don't know which is the correct one. So the compiler should 
reject this.

The issue is that the result type of "A * B" is different from the types 
of A and B. But, as strange as it seems, this is what generations of 
Mathematicians and Engineers seem to have found convenient for their work. 

I am sure, they where able to understand such expressions from context, 
and to provide the context if necessary. Most authors would probably 
prefer to write 

   "M * C with the matrix M being A * B" 

instead of "(A * B) * C" with or without "(", ")". They would thus provide 
the type information, much like any Ada programmer would (have to) do.

> Now image we have a third function
> function "*" (Left, Right : Real_Vector) return Real_Vector;
> 
> BTW: What would such a function return for vectors of less or more
> than 3 dimensions?

It should raise an exception, exactly like 

  function "+" (Left, Right : Real_Vector) return Real_Vector;

from the Ada.Numerics.Generic_Real_Array package. 

I hope the "aspect specifications" from Ada 2012 will allow to specify 
that the vector dimensions fit. In an ideal world (or maybe in Ada 2017), 
the compiler would then statically reject the program if the vector 
dimensions don't fit.

> Why is 'Base the return value? You might instantiate the package with
> a constrained subtype of Float. 'Base is the unconstrained range. Thus
> as long as you stay in the base range, the operators will not
> propagate exceptions.

Ah, that makes sense! Thank you!


-- 
------ Stefan Lucks   --  Bauhaus-University Weimar  --   Germany  ------
               Stefan dot Lucks at uni minus weimar dot de
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------

^ permalink raw reply	[relevance 0%]

* Re: Incorrect error?
  2011-07-18 10:40  0%   ` AdaMagica
@ 2011-07-18 12:39  0%     ` Dmitry A. Kazakov
  2011-07-18 12:45  0%     ` stefan-lucks
  1 sibling, 0 replies; 114+ results
From: Dmitry A. Kazakov @ 2011-07-18 12:39 UTC (permalink / raw)


On Mon, 18 Jul 2011 03:40:59 -0700 (PDT), AdaMagica wrote:

> Overloading in this way might be seen as unfortunate.
> 
>> Ada.Numerics.Generic_Real_Arrays actually provides both:
>>
>> � �function "*" (Left, Right : Real_Vector) return Real'Base;
>> � �function "*" (Left, Right : Real_Vector) return Real_Matrix;
> 
> So if you have three vectors, what should A * B * C mean? Even with
> parentheses, it's awkward to read.

There is one or more transpose operation missing, e.g.

   A * Transpose (B) * C
   Transpose (A) * Transpose (B) * C
   Transpose (A) * B * Transpose (C)

etc

> Now image we have a third function
> 
> function "*" (Left, Right : Real_Vector) return Real_Vector;

Ah, but vector product has the x-notation. Was introduction of Unicode in
Ada for nothing? (:-))

   function "�" (Left, Right : Real_Vector) return Real_Matrix;
 
> BTW: What would such a function return for vectors of less or more
> than 3 dimensions?

It is also well defined in mathematics, but the problem is same as with
measurement units. The constraints on the matrix dimensions of the
arguments statically determine the constraints of the result matrix
product. One cannot express this in the Ada's type system, otherwise than
by a massive set of overloaded subprograms, which, like for the case of
measurement units, is not a solution. We need some universal mechanism to
describe such cases based on subtypes with static checks of those when the
constraints are static.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[relevance 0%]

* Re: Incorrect error?
  2011-07-18  9:45  5% ` stefan-lucks
@ 2011-07-18 10:40  0%   ` AdaMagica
  2011-07-18 12:39  0%     ` Dmitry A. Kazakov
  2011-07-18 12:45  0%     ` stefan-lucks
  0 siblings, 2 replies; 114+ results
From: AdaMagica @ 2011-07-18 10:40 UTC (permalink / raw)


Overloading in this way might be seen as unfortunate.

> Ada.Numerics.Generic_Real_Arrays actually provides both:
>
>    function "*" (Left, Right : Real_Vector) return Real'Base;
>    function "*" (Left, Right : Real_Vector) return Real_Matrix;

So if you have three vectors, what should A * B * C mean? Even with
parentheses, it's awkward to read. Now image we have a third function

function "*" (Left, Right : Real_Vector) return Real_Vector;

BTW: What would such a function return for vectors of less or more
than 3 dimensions?

Why is 'Base the return value? You might instantiate the package with
a constrained subtype of Float. 'Base is the unconstrained range. Thus
as long as you stay in the base range, the operators will not
propagate exceptions.



^ permalink raw reply	[relevance 0%]

* Re: Incorrect error?
  2011-07-18  8:47  8% Incorrect error? ldries46
  2011-07-18  9:45  5% ` stefan-lucks
@ 2011-07-18 10:39  8% ` Nicholas Collin Paul de Glouceſter
  2011-07-18 15:58  0% ` Adam Beneschan
  2 siblings, 0 replies; 114+ results
From: Nicholas Collin Paul de Glouceſter @ 2011-07-18 10:39 UTC (permalink / raw)


L. Dries <bertus.dries@Planet.NL> sent on July 18th, 2011:
|--------------------------------------------------------------------------------|
|"I'm using Ada.Numerics.Generic_Real_Arrays. While Compiling I got the following|
|error message:                                                                  |
|                                                                                |
|65:21     expected type "Ada.Numerics.Generic_Real_Arrays.Real_Vector" from     |
|instance at line 6                                                              |
|65:21     found type "Ada.Numerics.Generic_Real_Arrays.Real_Matrix" from        |
|instance at line 6                                                              |
|                                                                                |
|As can be seen Cross, a and b declared as Real_Vector .                         |
|What do I do wrong?                                                             |
|                                                                                |
|L. Dries                                                                        |
|                                                                                |
|[..]                                                                            |
|  a      : Real_Vector(0 .. 2);                                                 |
|  b      : Real_Vector(0 .. 2);                                                 |
|[..]                                                                            |
|  cross  : Real_Vector(0 .. 2);                                                 |
|[..]                                                                            |
|     a := X1 - X0; -- VecSub( a, X1, X0 );                                      |
|     b := X2 - X0; -- VecSub( b, X2, X0 );                                      |
|    Cross := a * b; -- VecCross( a, b, Cross ); <---------------- line 65 the   |
|cursor is standing just before *                                                |
|[..]"                                                                           |
|--------------------------------------------------------------------------------|


The product of a 3x1 vector and a 1x3 vector is a 3x3 matrix.
The product of a 3x1 vector and a 3x1 vector can not exist.
You are trying to assign a 2d matrix (that is a * b) to a variable
declared to be a 1d vector.



^ permalink raw reply	[relevance 8%]

* Re: Incorrect error?
  2011-07-18  8:47  8% Incorrect error? ldries46
@ 2011-07-18  9:45  5% ` stefan-lucks
  2011-07-18 10:40  0%   ` AdaMagica
  2011-07-18 10:39  8% ` Nicholas Collin Paul de Glouceſter
  2011-07-18 15:58  0% ` Adam Beneschan
  2 siblings, 1 reply; 114+ results
From: stefan-lucks @ 2011-07-18  9:45 UTC (permalink / raw)


On Mon, 18 Jul 2011, ldries46 wrote:

[...]
>   a      : Real_Vector(0 .. 2);
>   b      : Real_Vector(0 .. 2);
>   cross  : Real_Vector(0 .. 2);
> begin
[...]
>     Cross := a * b; -- VecCross( a, b, Cross ); <---------------- line 65 the

Why do you expect the product of two vectors to be an vector? 

Mathematical convention knows the "inner product" of two vectors (a 
single real value) and the "outer product" (a matrix).  

Ada.Numerics.Generic_Real_Arrays actually provides both:

   function "*"   (Left, Right : Real_Vector) return Real'Base;
   function "*"   (Left, Right : Real_Vector) return Real_Matrix;

So if M is a Real_Matrix(0..2,0..2) and F a float, you can write either

   M := a * b;  -- outer product 

or 
 
   F := a * b;  -- inner product

but not

  Cross := a * b; -- there is no such "*" defined in Ada.Num.Gen_Re_Arr. 

Please don't ask me why the inner product is of type "Real'Base", instead 
of "Real". I'd like to know that myself. ;-)
  
BTW, the error messages are not very helpful (at least not until you have 
seen many of them and are able to translate them for yourself):

>65:21     expected type "Ada.Numerics.Generic_Real_Arrays.Real_Vector" 
>          from instance at line 6
>65:21     found type "Ada.Numerics.Generic_Real_Arrays.Real_Matrix" from 
>          instance at line 6

This really means is that there is no function "*" with two Real_Vector 
parameters as the input and returning a Real_Vector in scope. 



-- 
------ Stefan Lucks   --  Bauhaus-University Weimar  --   Germany  ------
               Stefan dot Lucks at uni minus weimar dot de
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------




^ permalink raw reply	[relevance 5%]

* Incorrect error?
@ 2011-07-18  8:47  8% ldries46
  2011-07-18  9:45  5% ` stefan-lucks
                   ` (2 more replies)
  0 siblings, 3 replies; 114+ results
From: ldries46 @ 2011-07-18  8:47 UTC (permalink / raw)


I'm using Ada.Numerics.Generic_Real_Arrays. While Compiling I got the 
following error message:

65:21     expected type "Ada.Numerics.Generic_Real_Arrays.Real_Vector" from 
instance at line 6
65:21     found type "Ada.Numerics.Generic_Real_Arrays.Real_Matrix" from 
instance at line 6

As can be seen Cross, a and b declared as Real_Vector .
What do I do wrong?

L. Dries

Code:

package Float_Arrays is new Ada.Numerics.Generic_Real_Arrays (float);
use Float_Arrays;

function Volume (ObjID : integer; Obj : ptrS_Object) return float is
   ok     : boolean;
   n      : integer := 1;
   Volume : float;
   a      : Real_Vector(0 .. 2);
   b      : Real_Vector(0 .. 2);
   X0     : Real_Vector(0 .. 2);
   X1     : Real_Vector(0 .. 2);
   X2     : Real_Vector(0 .. 2);
   cross  : Real_Vector(0 .. 2);
   nA     : Real_Vector(0 .. 2);
   p      : ptrNode_Object;
   TempS  : ptrS_Object;
   TempT  : ptrTriangle_Object;
begin
   TempS := Obj;
   while n /= ObjID loop
      n := n + 1;
      TempS := TempS.next;
      if TempS = null then
         declare
            NO_NODE_OBJECT : exception;
         begin
            raise NO_NODE_OBJECT;
         end;
      end if;
   end loop;
   n := TempS.PosFaces(0);
   TempT := stT_Object;
   ok := TempT = null;
   while not ok loop
      if TempT.nr = n then
         ok := true;
      else
         TempT := TempT.next;
         ok := TempT = null;
      end if;
   end loop;
   while n < TempS.PosFaces(1) loop
      p := GetPoint(TempT.P1);
      X0(0) := p.pRectangular(x);
      X0(1) := p.pRectangular(y);
      X0(2) := p.pRectangular(z);
      p := GetPoint(TempT.P2);
      X1(0) := p.pRectangular(x);
      X1(1) := p.pRectangular(y);
      X1(2) := p.pRectangular(z);
      p := GetPoint(TempT.P3);
      X2(0) := p.pRectangular(x);
      X2(1) := p.pRectangular(y);
      X2(2) := p.pRectangular(z);
      a := X1 - X0; -- VecSub( a, X1, X0 );
      b := X2 - X0; -- VecSub( b, X2, X0 );
     Cross := a * b; -- VecCross( a, b, Cross ); 
<---------------- line 65 the cursor is standing just before *
      nA := Cross * 0.5; -- VecMultScalar( nA, Cross, 0.5 );
      -- Volume = Volume + fabs(VecDot( X0, nA ));
      Volume := Volume + X0(0)*nA(0) + X0(1)*nA(1) + X0(2)*nA(2);
      n := n + 1;
   end loop;
   Volume := Volume/3.0;
   return Volume;
end Volume;




^ permalink raw reply	[relevance 8%]

* Re: Interfacing Ada multidimensional arrays with Fortran.
  @ 2011-06-09  7:55  6%     ` David Sauvage
  0 siblings, 0 replies; 114+ results
From: David Sauvage @ 2011-06-09  7:55 UTC (permalink / raw)


On May 28, 8:45 pm, Simon Wright <si...@pushface.org> wrote:
...
> -O1:
> Transposition: 1200 us
> Assignment:     300 us
>
> -O2:
> Transposition:  500 us
> Assignment:     300 us

Using this testcase [1], here are my results using Intel Atom CPU N270
@ 1.60GHz / Linux (launched with root privilege) :

 -O1:
 Transposition: 2202 us
 Assignment:    1014 us

 -O2:
 Transposition: 2556 us
 Assignment:     885 us

Transposition (using assignment via pragma Convention) seems to be
quicker than Transposition (without pragma Convention).
The reason why pragma Convention (Fortran, Type) is not used in
Interfaces.Fortran... is unknown and seems to give slower compute
time.

[1]
-- gnatmake -f compare.adb -cargs -gnat05 -O2
-- gnatmake -f compare.adb -cargs -gnat05 -O1
with Interfaces.Fortran.BLAS;

with Ada.Text_IO,
     Ada.Calendar,
     Ada.Numerics.Generic_Real_Arrays;

procedure Compare is
   Start, Stop : Ada.Calendar.Time;
   use type Ada.Calendar.Time;

   type Real_Matrix is
     array (Integer range <>, Integer range <>) of
Interfaces.Fortran.Real;
   pragma Convention (Fortran, Real_Matrix);

   package GRA is new Ada.Numerics.Generic_Real_Arrays (
      Interfaces.Fortran.Real);

   Row, Column : constant Positive := 100;
   Iteration   : constant Positive := 10;

   M : Real_Matrix (1 .. Row, 1 .. Column)      := (others => (others
=> 2.0));
   pragma Volatile (M);

   MFA, MFB : GRA.Real_Matrix (1 .. Row, 1 .. Column) := (others =>
(others => 2.0));
   pragma Volatile (MFA);
   pragma Volatile (MFB);

   use type Interfaces.Fortran.Real;
begin

   Start := Ada.Calendar.Clock;
   for I in 1 .. Iteration loop
      M := Real_Matrix (MFB);
   end loop;
   Stop := Ada.Calendar.Clock;
   Ada.Text_IO.Put_Line
     ("Assignation (Transposition via pragma Convention)" &
      Duration'Image (Stop - Start));

   Start := Ada.Calendar.Clock;
   for I in 1 .. Iteration loop
      MFA := GRA.Transpose (MFB);
   end loop;
   Stop := Ada.Calendar.Clock;
   Ada.Text_IO.Put_Line
     ("Transposition" & Duration'Image (Stop - Start));

end Compare;



^ permalink raw reply	[relevance 6%]

* Re: Interfacing Ada multidimensional arrays with Fortran.
  @ 2011-05-28  9:41  6% ` Simon Wright
    0 siblings, 1 reply; 114+ results
From: Simon Wright @ 2011-05-28  9:41 UTC (permalink / raw)


David Sauvage <sauvage.david@gmail.com> writes:

> Concerning multidimensional arrays, Ada use row-major order [0] while
> Fortran use column-major order [1].

> 3 - Concerning BLAS & LAPACK routines, there are parameters to
> indicates the form of the array (transposed or not) to the Fortran
> code, so that the Fortran code load the array properly.

This is true of BLAS, but I don't believe it's true of LAPACK.

> In Interfaces.Fortran.BLAS, there are Multidimensional arrays types
> that are already defined ;
> (Real_Matrix, Double_Precision_Matrix, Complex_Matrix,
> Double_Complex_Matrix)
> But the corresponding pragma Convention (Fortran, type) are not
> defined for them. So any user that would re-use those types can not
> use pragma Convention, and use possibility 2 or 3 above,

Interfaces.Fortran.BLAS is an internal GNAT unit, ie part of GNAT's
implementation of the standard Ada.Numerics.Generic_*_Arrays, not part
of the standard itself.

> It would be interesting to know the story behind the scene of why
> array types declared in  Interfaces.Fortran.BLAS do not use pragma
> Convention (Fortran, *) ?

There I can't help you.

The implementor of Ada.Numerics.Generic_Real_Arrays has decided to
declare Interfaces.Fortran.BLAS using Ada order, so that to convert from
the Ada order required in the standard for these units he uses the
Transpose operation (note, a copy is required anyway because LAPACK
doesn't preserve the input matrix).

Functionally, he could equally well have declared in Fortran order, as
you suggest:

   with Ada.Text_IO; use Ada.Text_IO;
   with Interfaces.Fortran.BLAS;
   procedure Sauvage is
      type Real_Matrix is array (Integer range <>, Integer range <>)
        of Interfaces.Fortran.Real;
      pragma Convention (Fortran, Real_Matrix);
      Theirs : constant Interfaces.Fortran.BLAS.Real_Matrix :=
        (1 => (1 => 1.0, 2 => 2.0),
         2 => (1 => 3.0, 2 => 4.0));
      Mine : Real_Matrix (1 .. 2, 1 .. 2);
   begin
      Mine := Real_Matrix (Theirs);      -- transposition occurs here
      for J in Mine'Range (1) loop
         for K in Mine'Range (2) loop
            Put_Line (Mine (J, K)'Img);
         end loop;
      end loop;
   end Sauvage;

and it might have been quicker.

Quite how the implementor of Ada.Numerics.Generic_Complex_Arrays managed
the transposition is less than clear to me!

> What are the performance issues by using the three possibilities
> above ? (may be the community already had some interesting information
> about this)

I haven't measured this. Anyone else?

> Some would think the pragma Convention (Fortran, type) should be more
> efficient, but may be it is not that simple, as apparently the choice
> has been made to avoid [4] pragma Convention (Fortran, type).



^ permalink raw reply	[relevance 6%]

* Re: on using array index, vectorized operation
  2011-03-29  2:50  8%         ` Randy Brukardt
@ 2011-03-29  4:55  0%           ` Nasser M. Abbasi
  0 siblings, 0 replies; 114+ results
From: Nasser M. Abbasi @ 2011-03-29  4:55 UTC (permalink / raw)


On 3/28/2011 7:50 PM, Randy Brukardt wrote:
> "Nasser M. Abbasi"<nma@12000.org>  wrote in message


>> 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.
>
>

Thanks Randy !  That really helped. I am a newbie at Ada and did
not know about such package. (but strange it is only for float?
But I suppose one can duplicate it for other types).

I rewrote the procedure using this package (I am using float, so
it worked for me), and was really surprised that now I able
to remove the loop and use vectorized statement:

-------------
       subtype r is Natural range o.u'First + 1 .. o.u'Last - 1;
       subtype r_plus_1 is Natural range r'First + 1 .. r'Last + 1;
       subtype r_minus_1 is Integer range r'First - 1 .. r'Last - 1;

    begin

       u (r) := u (r) -
                (a / 2.0) * (u (r_plus_1) - u (r_minus_1)) +
                (a ** 2) / 2.0 *
                (u (r_minus_1) - 2.0 * u (r) + u(r_plus_1));

-------------

It is now almost the same form as in Fortran and Matlab !

Only extra thing is the need to define those subtype's for
the ranges. (r, r_plus_1, r_minus_1) .

In Fortran, I would have written the above as

-----------------------------------------
       u (i) := u (i) -
                (a / 2.0) * (u (i+1) - u (i-1)) +
                (a ** 2) / 2.0 *
                (u (i-1) - 2.0 * u (i) + u(i+1) )
----------------------------------------------

Where 'i' is an array of the index range I am interested in.

It would be great if there is another 'trick' to allow
me to write it as such in Ada. I am still not too happy
with having to do this, but this is a very minor thing now
for me and I can life with it.

Removing the loop is a major improvement from what I started
with. I like Ada now again :) since I am able to write
the code in a much close form as I am used to.

Fyi, I've updated my small Ada Lax-Wendroff package here which
I used to practice on.

http://12000.org/my_notes/solve_advection_1D_in_Ada/index.htm

thanks again for all who helped.

--Nasser



^ permalink raw reply	[relevance 0%]

* Re: on using array index, vectorized operation
  @ 2011-03-29  2:50  8%         ` Randy Brukardt
  2011-03-29  4:55  0%           ` Nasser M. Abbasi
  0 siblings, 1 reply; 114+ results
From: Randy Brukardt @ 2011-03-29  2:50 UTC (permalink / raw)


"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.







^ permalink raw reply	[relevance 8%]

* Re: Ann: Mathpaqs, release Feb. 2011
  @ 2011-02-21 23:59  6% ` Nasser M. Abbasi
  0 siblings, 0 replies; 114+ results
From: Nasser M. Abbasi @ 2011-02-21 23:59 UTC (permalink / raw)


On 2/21/2011 10:43 AM, Gautier write-only wrote:
> Hello,
>
> There is a new release of Mathpaqs @ http://sf.net/projects/mathpaqs/
> .
>
> What's new:
>
> - *new* Discrete_random_simulation package (this is for simulating any
> discrete random distribution)
> - updated the Finite_distributed_random function (this is for
> simulating a random distribution for an enumerated type)
> - cleanup of ConjGrad (Conjugate gradient iterative methods for
> solving the matrix equation Ax=b)
>

Thanks Gautier,

I do not use Ada now, but I was looking at your ConjGrad solver,
and was just wondering, why new Matrix and Vectors are
defined in that package, since with Ada now, there exist
such types now?

For example, in  ConjGrad.ads it says

type Vector is array(Index range <>) of Real

type Any_matrix (<>) is private;
   -- NB: 2 syntaxes for instanciating that as unconstrained type :
   -- [Ada 95+] type Any_matrix (<>) is private;
   -- [Ada 83]  type Any_matrix is private;

But when I look at Ada 2005,

http://www.adaic.org/resources/add_content/standards/05rat/html/Rat-7-6.html

"Ada 2005 includes two new packages which are Ada.Numerics.Generic_Real_Arrays and Ada.Numerics.Generic_Complex_Arrays.

type Real_Vector is array (Integer range <>) of Real'Base;
type Real_Matrix is array (Integer range <>, Integer range <>) of Real'Base;
"

So, was just wondering the reasoning, to learn something, that's all.

I wrote a conjugate gradient solver myself for a HW, with preconditioning
in Matlab, and I saw your post, so wanted to see how it would 'look' in Ada.

thanks
--Nasser



^ permalink raw reply	[relevance 6%]

* Re: How to include vector operators?
  2010-12-06 21:37  6% ` Adam Beneschan
@ 2010-12-07 11:11  0%   ` tolkamp
  0 siblings, 0 replies; 114+ results
From: tolkamp @ 2010-12-07 11:11 UTC (permalink / raw)


On 6 dec, 22:37, Adam Beneschan <a...@irvine.com> wrote:
> On Dec 6, 1:03 pm, tolkamp <f.tolk...@gmail.com> wrote:
>
>
>
>
>
> > In my application the package Ada.Numerics.Generic_Real_Arrays  is
> > included.
>
> > Code:
>
> > with Ada.Numerics.Generic_Real_Arrays;
> > package Vectors is new Ada.Numerics.Generic_Real_Arrays(Float);
>
> > How to include the vector operators like "+" and "-" ?
>
> > I tried the follwing:
> > function "+" (Left, Right : Vectors.Real_Vector) return
> > Vectors.Real_Vector
> >                renames
> > Ada.Numerics.Generic_Real_Arrays.Instantiations."+";
>
> > However this gives the error:
> > invalid prefix in selected component "Generic_Real_Arrays".
>
> function "+" (Left, Right : Vectors.Real_Vector) return
> Vectors.Real_Vector
>    renames Vectors."+";
>
> But you probably really want to use this, which will make all the
> operators visible:
>
>    use type Vectors.Real_Vector;
>
> (and maybe the same for Real_Matrix).
>
> But NOT this:
>
>    use type Ada.Numerics.Generic_Real_Arrays.Real_Vector;
>
> You can't access declarations in a generic package directly.  You have
> to access the declarations in a generic *instance*.
>
>                                 -- Adam- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Thank you for your solution. Now it works correct.

Fred



^ permalink raw reply	[relevance 0%]

* Re: How to include vector operators?
  2010-12-06 21:03  9% How to include vector operators? tolkamp
  2010-12-06 21:37  6% ` Adam Beneschan
@ 2010-12-07  2:53  0% ` Gautier write-only
  1 sibling, 0 replies; 114+ results
From: Gautier write-only @ 2010-12-07  2:53 UTC (permalink / raw)


> with Ada.Numerics.Generic_Real_Arrays;

Since it's generic, you can't use it directly. It's why you have:

> package Vectors is new Ada.Numerics.Generic_Real_Arrays(Float);
>
> How to include the vector operators like "+" and "-" ?

I guess you want to write things like (i):
  u+v
whereas now you need to write (ii)
  Vectors."+"(u,v)

To be able to write the form (i), you can put
  use Vectors;
after the above definition (package Vectors is new ...)
and you'll be happy.
______________________________________________________________
Gautier's Ada programming -- http://gautiersblog.blogspot.com/
NB: follow the above link for a working e-mail address



^ permalink raw reply	[relevance 0%]

* Re: How to include vector operators?
  2010-12-06 21:03  9% How to include vector operators? tolkamp
@ 2010-12-06 21:37  6% ` Adam Beneschan
  2010-12-07 11:11  0%   ` tolkamp
  2010-12-07  2:53  0% ` Gautier write-only
  1 sibling, 1 reply; 114+ results
From: Adam Beneschan @ 2010-12-06 21:37 UTC (permalink / raw)


On Dec 6, 1:03 pm, tolkamp <f.tolk...@gmail.com> wrote:
> In my application the package Ada.Numerics.Generic_Real_Arrays  is
> included.
>
> Code:
>
> with Ada.Numerics.Generic_Real_Arrays;
> package Vectors is new Ada.Numerics.Generic_Real_Arrays(Float);
>
> How to include the vector operators like "+" and "-" ?
>
> I tried the follwing:
> function "+" (Left, Right : Vectors.Real_Vector) return
> Vectors.Real_Vector
>                renames
> Ada.Numerics.Generic_Real_Arrays.Instantiations."+";
>
> However this gives the error:
> invalid prefix in selected component "Generic_Real_Arrays".

function "+" (Left, Right : Vectors.Real_Vector) return
Vectors.Real_Vector
   renames Vectors."+";

But you probably really want to use this, which will make all the
operators visible:

   use type Vectors.Real_Vector;

(and maybe the same for Real_Matrix).

But NOT this:

   use type Ada.Numerics.Generic_Real_Arrays.Real_Vector;

You can't access declarations in a generic package directly.  You have
to access the declarations in a generic *instance*.

                                -- Adam




^ permalink raw reply	[relevance 6%]

* How to include vector operators?
@ 2010-12-06 21:03  9% tolkamp
  2010-12-06 21:37  6% ` Adam Beneschan
  2010-12-07  2:53  0% ` Gautier write-only
  0 siblings, 2 replies; 114+ results
From: tolkamp @ 2010-12-06 21:03 UTC (permalink / raw)


In my application the package Ada.Numerics.Generic_Real_Arrays  is
included.

Code:

with Ada.Numerics.Generic_Real_Arrays;
package Vectors is new Ada.Numerics.Generic_Real_Arrays(Float);

How to include the vector operators like "+" and "-" ?

I tried the follwing:
function "+" (Left, Right : Vectors.Real_Vector) return
Vectors.Real_Vector
               renames
Ada.Numerics.Generic_Real_Arrays.Instantiations."+";

However this gives the error:
invalid prefix in selected component "Generic_Real_Arrays".



^ permalink raw reply	[relevance 9%]

* Re: Large arrays passed to arithmetic operators overflows GNAT stack
  @ 2010-12-05  1:22  5%   ` Jerry
  0 siblings, 0 replies; 114+ results
From: Jerry @ 2010-12-05  1:22 UTC (permalink / raw)


On Dec 4, 7:17 am, "Peter C. Chapin" <PCha...@vtc.vsc.edu> wrote:
> On 2010-12-04 01:32, Jerry wrote:
>
> > with
> >     Ada.Numerics.Long_Real_Arrays;
> > use
> >     Ada.Numerics.Long_Real_Arrays;
> > procedure array_test is
> >     type Real_Vector_Access    is access Real_Vector;
> >     N : Integer := 1_048_130;
> >     t_Ptr : Real_Vector_Access := new Real_Vector(0 .. N);
> >       t : Real_Vector renames t_Ptr.all;
>
> I don't think you need this renaming. If you do t_Ptr'Range or t_Ptr(i)
> the compiler will forward those operations directly to the object.
>  ...
> Peter

That is true but the renaming is still convenient for other reasons.
For example,
the lines

t      : Real_Vector_Access := new Real_Vector(0 .. N);
t_Diff : Real_Vector_Access := new Real_Vector(0 .. N - 1);
...
[Line 14] t_Diff := t(1 .. N);

causes the complaints

expected type "Real_Vector_Access" defined at line 14
found type "Ada.Numerics.Generic_Real_Arrays.Real_Vector" from
instance at a-nlrear.ads:18

And passing t to a vector cosine (e.g.) function that expects to see a
Real_Vector will also fail. Of course, with two like pointers t and x,
assignment  t := x assigns the pointers, not the array contents, and
with three like pointers t, x, y, t := x - y fails to find an
applicable operator function.

This clever renaming trick was mentioned by Brian Drummond in this
thread:
http://groups.google.com/group/comp.lang.ada/browse_thread/thread/ae395e5c11de7bc9/bda8d61bd3a66ee9?hl=en&q=Jerry+stack&lnk=nl&

Jerry



^ permalink raw reply	[relevance 5%]

* Re: heap size exceeded for large matrices
  2010-08-29 10:42  0%   ` Simon Wright
@ 2010-08-29 15:33  0%     ` John Raymond Dore
  0 siblings, 0 replies; 114+ results
From: John Raymond Dore @ 2010-08-29 15:33 UTC (permalink / raw)
  Cc: John Raymond Doré

On Aug 29, 11:42 am, Simon Wright <si...@pushface.org> wrote:
> "Yannick Duchêne (Hibou57)" <yannick_duch...@yahoo.fr> writes:
>
> > Le Sun, 29 Aug 2010 10:50:39 +0200, John Raymond Dore
> > <johnrd...@gmail.com> a écrit:
> >> I have no difficulty in increasing the storage size of a task.
> >> I cannot do the same for matrices within a procedure
> > Forgive my question is this ever happens to looks stupid: is your
> > matrix allocated as a local object of that procedure ?
> > If so, the stack may have a maximum limit which cannot be exceeded,
> > and dynamic allocation may solve the case.
> > If not, an excerpt from the source could help to see.
>
> > Do you use Ada.Numerics.Generic_Real_Arrays.Real_Matrix ? (that is
> > what I supposed, may need to be confirmed).
>
I just need a large matrix (1..10000, 1..10000) of long_float would
suffice accessible from a procedure.
It does not have to be declared within a procedure.
My computer is running 64bit Ubuntu
> The implementation of the Ada.Numerics.Generic*Arrays in GNAT (and inhttps://sourceforge.net/projects/gnat-math-extn/) allocates temporary
> arrays on the stack, which will be of similar sizes to the original.
>
> Can you call the matrix operations from a task with a large stack?
>
> I'm not sure that generalized algorithms are going to meet your needs
> (you're going to be perilously close to your 8GB of real memory, when
> you consider temporary space, which is going to risk much swapping; and
> won't you need a 64-bit OS?) Are there any sparse matrix algorithms?




^ permalink raw reply	[relevance 0%]

* Re: heap size exceeded for large matrices
  2010-08-29  9:51  5% ` Yannick Duchêne (Hibou57)
@ 2010-08-29 10:42  0%   ` Simon Wright
  2010-08-29 15:33  0%     ` John Raymond Dore
  0 siblings, 1 reply; 114+ results
From: Simon Wright @ 2010-08-29 10:42 UTC (permalink / raw)


"Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr> writes:

> Le Sun, 29 Aug 2010 10:50:39 +0200, John Raymond Dore
> <johnrdore@gmail.com> a écrit:
>> I have no difficulty in increasing the storage size of a task.
>> I cannot do the same for matrices within a procedure
> Forgive my question is this ever happens to looks stupid: is your
> matrix allocated as a local object of that procedure ?
> If so, the stack may have a maximum limit which cannot be exceeded,
> and dynamic allocation may solve the case.
> If not, an excerpt from the source could help to see.
>
> Do you use Ada.Numerics.Generic_Real_Arrays.Real_Matrix ? (that is
> what I supposed, may need to be confirmed).

The implementation of the Ada.Numerics.Generic*Arrays in GNAT (and in
https://sourceforge.net/projects/gnat-math-extn/) allocates temporary
arrays on the stack, which will be of similar sizes to the original.

Can you call the matrix operations from a task with a large stack?

I'm not sure that generalized algorithms are going to meet your needs
(you're going to be perilously close to your 8GB of real memory, when
you consider temporary space, which is going to risk much swapping; and
won't you need a 64-bit OS?) Are there any sparse matrix algorithms?



^ permalink raw reply	[relevance 0%]

* Re: heap size exceeded for large matrices
  @ 2010-08-29  9:51  5% ` Yannick Duchêne (Hibou57)
  2010-08-29 10:42  0%   ` Simon Wright
  0 siblings, 1 reply; 114+ results
From: Yannick Duchêne (Hibou57) @ 2010-08-29  9:51 UTC (permalink / raw)


Le Sun, 29 Aug 2010 10:50:39 +0200, John Raymond Dore
<johnrdore@gmail.com> a écrit:
> I have no difficulty in increasing the storage size of a task.
> I cannot do the same for matrices within a procedure
Forgive my question is this ever happens to looks stupid: is your matrix  
allocated as a local object of that procedure ?
If so, the stack may have a maximum limit which cannot be exceeded, and  
dynamic allocation may solve the case.
If not, an excerpt from the source could help to see.

Do you use Ada.Numerics.Generic_Real_Arrays.Real_Matrix ? (that is what I  
supposed, may need to be confirmed).


-- 
“Dual licensing is the Perl's way to disinfect the GNU General Public  
Virus!” (anonymous)



^ permalink raw reply	[relevance 5%]

* Re: ANN: Ada 2005 Math Extensions, 20100810 release
  2010-08-14  1:05  9%       ` Stephen Leake
@ 2010-08-14 16:26  0%         ` Simon Wright
  0 siblings, 0 replies; 114+ results
From: Simon Wright @ 2010-08-14 16:26 UTC (permalink / raw)


Stephen Leake <stephen_leake@stephe-leake.org> writes:

> sjw <simon.j.wright@mac.com> writes:

>>    generic
>>       with package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Real);
>>       with package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays
>>         (Generic_Real_Arrays, Complex_Types);
>
> I see the problem. Generic_Real_Arrays is the name of the parent generic
> package; that's not a concrete package, so it can't be used here.

Exactly so.

> This compiles:
>
> with Ada.Numerics.Generic_Complex_Arrays;
> with Ada.Numerics.Generic_Complex_Types;
> with Ada.Numerics.Generic_Real_Arrays;
> generic
>    type Real is digits <>;
>    with package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
>    with package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Real);
>    with package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays (Real_Arrays, Complex_Types);
> package Extensions is
>
>    function Eigenvalues (A : Real_Arrays.Real_Matrix) return Complex_Arrays.Complex_Vector;
>
> end Extensions;
>
> Is there some reason you want Extensions to be a child of
> Generic_Real_Arrays?

Umm.

In the past, I've often introduced "extensions' in child (generic)
packages, usually because the extension needed visibility of the private
part of the original. That's not so in this case, as it happens, but I
find the idiom comfortable.

Given that, the function taking Complex_Matrix and returning
Complex_Vector has "obviously" to be in a child of
Generic_Complex_Arrays.

So I thought that the function taking Real_Matrix should be in a child
of Generic_Real_Arrays, in spite of the fact it returns a Complex_Vector.

Clearly this is not the way Nature intended!



^ permalink raw reply	[relevance 0%]

* Re: ANN: Ada 2005 Math Extensions, 20100810 release
  2010-08-12 12:48  9%     ` sjw
@ 2010-08-14  1:05  9%       ` Stephen Leake
  2010-08-14 16:26  0%         ` Simon Wright
  0 siblings, 1 reply; 114+ results
From: Stephen Leake @ 2010-08-14  1:05 UTC (permalink / raw)


sjw <simon.j.wright@mac.com> writes:

> On Aug 12, 11:36 am, Stephen Leake <stephen_le...@stephe-leake.org>
> wrote:
>
>> Post complete code, I'll try it on my version of gnat.
>
> Thanks.
>
> Remember -gnatpg!
>
> The code I posted above is the complete spec (not going to bother to
> write the body if can't get the spec to compile!):
>
>    with Ada.Numerics.Generic_Complex_Arrays;
>    with Ada.Numerics.Generic_Complex_Types;
>
>    generic
>       with package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Real);
>       with package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays
>         (Generic_Real_Arrays, Complex_Types);

I see the problem. Generic_Real_Arrays is the name of the parent generic
package; that's not a concrete package, so it can't be used here.


>    use Complex_Arrays; 
>    package Ada.Numerics.Generic_Real_Arrays.Extensions is
>
>       function Eigenvalues (A : Real_Matrix) return Complex_Vector;
>
>    end Ada.Numerics.Generic_Real_Arrays.Extensions;

This compiles:

with Ada.Numerics.Generic_Complex_Arrays;
with Ada.Numerics.Generic_Complex_Types;
with Ada.Numerics.Generic_Real_Arrays;
generic
   type Real is digits <>;
   with package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
   with package Complex_Types is new Ada.Numerics.Generic_Complex_Types (Real);
   with package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays (Real_Arrays, Complex_Types);
package Extensions is

   function Eigenvalues (A : Real_Arrays.Real_Matrix) return Complex_Arrays.Complex_Vector;

end Extensions;

Is there some reason you want Extensions to be a child of Generic_Real_Arrays?

-- 
-- Stephe



^ permalink raw reply	[relevance 9%]

* Re: ANN: Ada 2005 Math Extensions, 20100810 release
  2010-08-12 19:45  6%     ` Simon Wright
@ 2010-08-13  6:27  0%       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 114+ results
From: Dmitry A. Kazakov @ 2010-08-13  6:27 UTC (permalink / raw)


On Thu, 12 Aug 2010 20:45:33 +0100, Simon Wright wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> Further I would name it
>>
>> generic
>> package Ada.Numerics.Generic_Complex_Arrays.
>>    Generic_Real_Extensions;
>>    ^^^^
>> or Generic_Real_Valued_Extensions;
>>    ^^^^^
>>
>> It is always helpful to keep all name spaces clean of generic names.
> 
> Not quite sure what you mean here?
> 
> I think you're recommending that all names of generic units should
> include an indication that they're generic, so that people don't get
> confused as to generic vs instantiation?

More important is that names of generics do not hide other names. Sooner or
later it becomes a problem.

> In other places I've tacked _G on the end of the 'obvious' name:
> 
>    generic
>    package ColdFrame.Events_G.Standard_G.Callback_Manager_G is
> 
> and I saw someone else (Ludovic?) doing the same here recently.

I used plural suffix 's' before, but it Generic is clearer and it seems
like a semi-standard now.

> I think that people are going to get confused instantiating children of
> generic packages, and that there's nothing like a helpful example to
> clarify.
> 
> Currently I have (with elsewhere, "type Real is digits <>;")
> 
>    package Real_Arrays
>    is new Ada.Numerics.Generic_Real_Arrays (Real);
>    package Complex_Types
>    is new Ada.Numerics.Generic_Complex_Types (Real);
>    package Complex_Arrays
>    is new Ada.Numerics.Generic_Complex_Arrays (Real_Arrays, Complex_Types);
>    package Extensions
>    is new Complex_Arrays.Extensions;
> 
> Do people feel this would be clearer if the last 2 lines read instead
> 
>    package Extensions
>    is new Complex_Arrays.Generic_Extensions;
> 
> (and if so, how much clearer?!)

Yes, especially because of two "Extensions". I had immense problems with
names. Look at this:

   http://www.dmitry-kazakov.de/ada/fuzzy_packages.gif

Somewhere down deep the hierarchy the user starts to become incomprehensive
error messages upon instantiation within the generic(!) bodies. It is
practically impossible to understand what is wrong, is it a compiler bug
(in GNAT case) or something else. For the user it would be a nightmare to
fight this.

Another rule of thumb (I don't know if this is going to be fixed in Ada
2012), is that a child should always rename formal generic arguments in its
specifications. Under certain circumstances, usually in children, they
might become unavailable. I mean this:

generic
   with package P is new Generic_P (<>);
package Generic_S is
   package P_Of renames P; -- You will need this!

Sometimes you need to "rename" formal types as well:

generic
   type Foo is ...
package Generic_S is
   subtype Foo_Of is Foo; -- What a mess!

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[relevance 0%]

* Re: ANN: Ada 2005 Math Extensions, 20100810 release
  2010-08-12  5:57  0%   ` Dmitry A. Kazakov
@ 2010-08-12 19:45  6%     ` Simon Wright
  2010-08-13  6:27  0%       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 114+ results
From: Simon Wright @ 2010-08-12 19:45 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> Further I would name it
>
> generic
> package Ada.Numerics.Generic_Complex_Arrays.
>    Generic_Real_Extensions;
>    ^^^^
> or Generic_Real_Valued_Extensions;
>    ^^^^^
>
> It is always helpful to keep all name spaces clean of generic names.

Not quite sure what you mean here?

I think you're recommending that all names of generic units should
include an indication that they're generic, so that people don't get
confused as to generic vs instantiation?

In other places I've tacked _G on the end of the 'obvious' name:

   generic
   package ColdFrame.Events_G.Standard_G.Callback_Manager_G is

and I saw someone else (Ludovic?) doing the same here recently.


I think that people are going to get confused instantiating children of
generic packages, and that there's nothing like a helpful example to
clarify.

Currently I have (with elsewhere, "type Real is digits <>;")

   package Real_Arrays
   is new Ada.Numerics.Generic_Real_Arrays (Real);
   package Complex_Types
   is new Ada.Numerics.Generic_Complex_Types (Real);
   package Complex_Arrays
   is new Ada.Numerics.Generic_Complex_Arrays (Real_Arrays, Complex_Types);
   package Extensions
   is new Complex_Arrays.Extensions;

Do people feel this would be clearer if the last 2 lines read instead

   package Extensions
   is new Complex_Arrays.Generic_Extensions;

(and if so, how much clearer?!)



^ permalink raw reply	[relevance 6%]

* Re: ANN: Ada 2005 Math Extensions, 20100810 release
  2010-08-12 10:36  0%   ` Stephen Leake
@ 2010-08-12 12:48  9%     ` sjw
  2010-08-14  1:05  9%       ` Stephen Leake
  0 siblings, 1 reply; 114+ results
From: sjw @ 2010-08-12 12:48 UTC (permalink / raw)


On Aug 12, 11:36 am, Stephen Leake <stephen_le...@stephe-leake.org>
wrote:

> Post complete code, I'll try it on my version of gnat.

Thanks.

Remember -gnatpg!

The code I posted above is the complete spec (not going to bother to
write the body if can't get the spec to compile!):

   with Ada.Numerics.Generic_Complex_Arrays;
   with Ada.Numerics.Generic_Complex_Types;

   generic
      with package Complex_Types is new
Ada.Numerics.Generic_Complex_Types
        (Real);
      with package Complex_Arrays is new
Ada.Numerics.Generic_Complex_Arrays
        (Generic_Real_Arrays, Complex_Types);            --
<<<<<<<<<<<<<<<<<<
      use Complex_Arrays;
   package Ada.Numerics.Generic_Real_Arrays.Extensions is

      function Eigenvalues (A : Real_Matrix) return Complex_Vector;

   end Ada.Numerics.Generic_Real_Arrays.Extensions;



^ permalink raw reply	[relevance 9%]

* Re: ANN: Ada 2005 Math Extensions, 20100810 release
  2010-08-11 21:38  9% ` Simon Wright
  2010-08-12  5:57  0%   ` Dmitry A. Kazakov
@ 2010-08-12 10:36  0%   ` Stephen Leake
  2010-08-12 12:48  9%     ` sjw
  1 sibling, 1 reply; 114+ results
From: Stephen Leake @ 2010-08-12 10:36 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> Starting from the declaration of Generic_Complex_Arrays, I arrived at
>
>    with Ada.Numerics.Generic_Complex_Arrays;
>    with Ada.Numerics.Generic_Complex_Types;
>
>    generic
>       with package Complex_Types is new Ada.Numerics.Generic_Complex_Types
>         (Real);
>       with package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays
>         (Generic_Real_Arrays, Complex_Types);            -- <<<<<<<<<<<<<<<<<<
>       use Complex_Arrays;
>    package Ada.Numerics.Generic_Real_Arrays.Extensions is
>
>       function Eigenvalues (A : Real_Matrix) return Complex_Vector;
>
>    end Ada.Numerics.Generic_Real_Arrays.Extensions;
>
> but GNAT complains about Generic_Real_Arrays where I've indicated,
> saying it expects a package instance to instantiate a formal.

What is the actual error message? this idiom works for me in SAL:

generic
   with package Elementary is new Ada.Numerics.Generic_Elementary_Functions (Real_Type);
   with package Math_Scalar is new SAL.Gen_Math.Gen_Scalar (Elementary);
package SAL.Gen_Math.Gen_DOF_3 is


> I'd been hoping that -- in the context of a child of
> Generic_Real_Arrays -- the name would mean 'the current instantiation',
> but clearly not (GNAT GPL 2010, GCC 4.5.0).

Post complete code, I'll try it on my version of gnat.

-- 
-- Stephe



^ permalink raw reply	[relevance 0%]

* Re: ANN: Ada 2005 Math Extensions, 20100810 release
  2010-08-11 21:38  9% ` Simon Wright
@ 2010-08-12  5:57  0%   ` Dmitry A. Kazakov
  2010-08-12 19:45  6%     ` Simon Wright
  2010-08-12 10:36  0%   ` Stephen Leake
  1 sibling, 1 reply; 114+ results
From: Dmitry A. Kazakov @ 2010-08-12  5:57 UTC (permalink / raw)


On Wed, 11 Aug 2010 22:38:46 +0100, Simon Wright wrote:

> I was thinking about the next release, and contemplating
> 
>    --  Obtain the eigenvalues of a non-symmetric real matrix.
>    function Eigenvalues (A : Real_Matrix) return Complex_Vector;
> 
> It's easy enough to implement this in
> Ada.Numerics.Generic_Complex_Arrays.Extensions, but it seems slightly
> more natural to put it into Ada.Numerics.Generic_Real_Arrays.Extensions.
> 
> However, I'm puzzled about how to get Complex_Vector in there, because
> it's declared in Generic_Complex_Arrays (and of course you'd want to use
> the same instantiation throughout, not a local one).
> 
> Starting from the declaration of Generic_Complex_Arrays, I arrived at
> 
>    with Ada.Numerics.Generic_Complex_Arrays;
>    with Ada.Numerics.Generic_Complex_Types;
> 
>    generic
>       with package Complex_Types is new Ada.Numerics.Generic_Complex_Types
>         (Real);
>       with package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays
>         (Generic_Real_Arrays, Complex_Types);            -- <<<<<<<<<<<<<<<<<<
>       use Complex_Arrays;
>    package Ada.Numerics.Generic_Real_Arrays.Extensions is
> 
>       function Eigenvalues (A : Real_Matrix) return Complex_Vector;
> 
>    end Ada.Numerics.Generic_Real_Arrays.Extensions;
> 
> but GNAT complains about Generic_Real_Arrays where I've indicated,
> saying it expects a package instance to instantiate a formal.
>
> I'd been hoping that -- in the context of a child of
> Generic_Real_Arrays -- the name would mean 'the current instantiation',
> but clearly not (GNAT GPL 2010, GCC 4.5.0).

AFAIK it does not work, I tried something similar before. You cannot name
the parent package instance in the generic child declarations.
 
> Any thoughts?

(as always the first thought is: what a mess generics are! (:-))

I would not do that. It would only make instantiation tricky.
Generic_Complex_Arrays already has all types involved, so for the end user
it is much simpler when the extension package were its child.

Further I would name it 

generic
package Ada.Numerics.Generic_Complex_Arrays.
   Generic_Real_Extensions;
   ^^^^
or Generic_Real_Valued_Extensions;
   ^^^^^

It is always helpful to keep all name spaces clean of generic names.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[relevance 0%]

* Re: ANN: Ada 2005 Math Extensions, 20100810 release
  @ 2010-08-11 21:38  9% ` Simon Wright
  2010-08-12  5:57  0%   ` Dmitry A. Kazakov
  2010-08-12 10:36  0%   ` Stephen Leake
  0 siblings, 2 replies; 114+ results
From: Simon Wright @ 2010-08-11 21:38 UTC (permalink / raw)


I was thinking about the next release, and contemplating

   --  Obtain the eigenvalues of a non-symmetric real matrix.
   function Eigenvalues (A : Real_Matrix) return Complex_Vector;

It's easy enough to implement this in
Ada.Numerics.Generic_Complex_Arrays.Extensions, but it seems slightly
more natural to put it into Ada.Numerics.Generic_Real_Arrays.Extensions.

However, I'm puzzled about how to get Complex_Vector in there, because
it's declared in Generic_Complex_Arrays (and of course you'd want to use
the same instantiation throughout, not a local one).

Starting from the declaration of Generic_Complex_Arrays, I arrived at

   with Ada.Numerics.Generic_Complex_Arrays;
   with Ada.Numerics.Generic_Complex_Types;

   generic
      with package Complex_Types is new Ada.Numerics.Generic_Complex_Types
        (Real);
      with package Complex_Arrays is new Ada.Numerics.Generic_Complex_Arrays
        (Generic_Real_Arrays, Complex_Types);            -- <<<<<<<<<<<<<<<<<<
      use Complex_Arrays;
   package Ada.Numerics.Generic_Real_Arrays.Extensions is

      function Eigenvalues (A : Real_Matrix) return Complex_Vector;

   end Ada.Numerics.Generic_Real_Arrays.Extensions;

but GNAT complains about Generic_Real_Arrays where I've indicated,
saying it expects a package instance to instantiate a formal.

I'd been hoping that -- in the context of a child of
Generic_Real_Arrays -- the name would mean 'the current instantiation',
but clearly not (GNAT GPL 2010, GCC 4.5.0).

Any thoughts?



^ permalink raw reply	[relevance 9%]

* Generic_Roots
@ 2010-08-11 14:44  6% John B. Matthews
  0 siblings, 0 replies; 114+ results
From: John B. Matthews @ 2010-08-11 14:44 UTC (permalink / raw)


Inspired by <http://sourceforge.net/projects/gnat-math-extn/> and as 
suggested by a correspondent, I've updated my experimental 
implementations of these two generic procedures:

AI95-0346: Ada.Numerics.Generic_Real_Arrays.Generic_Roots
AI95-0346: Ada.Numerics.Generic_Complex_Arrays.Generic_Roots 

<http://home.roadrunner.com/~jbmatthews/misc/groots.html>

The implementation is unchanged, but I've fixed a few style warnings and 
obviated the need to update the run-time library. I've tested it with 
GNAT 4.3.4 (Mac OS X 10.5) and GNAT 4.4 (Ubuntu 10.04). I'd welcome any 
reports of anomalies or regressions.

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



^ permalink raw reply	[relevance 6%]

* Re: Interfacing Ada with C
  @ 2010-08-05 20:25  6%                                     ` Simon Wright
  0 siblings, 0 replies; 114+ results
From: Simon Wright @ 2010-08-05 20:25 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 666 bytes --]

Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:

> On 08/05/2010 10:24 AM, Ada novice wrote:
>>
>> They are much more accurate and better results of course. I wonder why
>> Matlab tends to be give very "accurate" answers. Normally 15 digits of
>> precision is also used there.
>
> You requested 15 decimal digits; your results are zero to 15 decimal
> places. If you output in non-scientific notation you'd get zero;
> presumably that's what Matlab is doing.

The attached update uses fixed notation, looks rather better.

Note that the reason for the lack of precision in the Test16 results is
likely because the inputs are only specified to 6 digits.


[-- Attachment #2: New test program --]
[-- Type: text/plain, Size: 5011 bytes --]

--  This package is free software; you can redistribute it and/or
--  modify it under terms of the GNU General Public License as
--  published by the Free Software Foundation; either version 3, or
--  (at your option) any later version.  It is distributed in the
--  hope that it will be useful, but WITHOUT ANY WARRANTY; without
--  even the implied warranty of MERCHANTABILITY or FITNESS FOR A
--  PARTICULAR PURPOSE.
--
--  You should have received a copy of the GNU General Public License
--  along with this program; see the file COPYING3.  If not, see
--  <http://www.gnu.org/licenses/>.
--
--  Copyright Simon Wright <simon@pushface.org>

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Numerics.Generic_Real_Arrays;
with Ada.Numerics.Generic_Complex_Types;
with Ada.Numerics.Generic_Complex_Arrays.Extensions;

procedure Test_Extensions is

   subtype My_Float is Long_Float;
   package My_Float_IO is new Float_IO (My_Float);
   use My_Float_IO;

   package Real_Arrays
   is new Ada.Numerics.Generic_Real_Arrays (My_Float);
   package Complex_Types
   is new Ada.Numerics.Generic_Complex_Types (My_Float);
   package Complex_Arrays
   is new Ada.Numerics.Generic_Complex_Arrays (Real_Arrays, Complex_Types);
   package Extensions
   is new Complex_Arrays.Extensions;

   use Real_Arrays;
   use Complex_Types;
   use Complex_Arrays;

begin

   declare
   --  Values in yc's example
      Input : constant Complex_Matrix
        := (((8.0, 0.0), (-1.0, 0.0), (-5.0, 0.0)),
            ((-4.0, 0.0), (4.0, 0.0), (-2.0, 0.0)),
            ((18.0, 0.0), (-5.0, 0.0), (-7.0, 0.0)));
      Result : Complex_Vector (1 .. Input'Length (1));
   begin

      Put_Line ("Values from <143ef70b-7e74-426b-a621-a5fd157849be"
                  & "@x21g2000yqa.googlegroups.com>");

      Result := Extensions.Eigenvalues (Input);

      for J in Result'Range loop
         Put (Result (J).Re, Exp => 0);
         Put (" ");
         Put (Result (J).Im, Exp => 0);
         New_Line;
      end loop;

      New_Line;

   end;

   declare
   --  Values in Test 16 of
   --  http://people.sc.fsu.edu/~jburkardt/f_src/lapack/lapack_OSX_prb_output.txt
      Z : constant Complex := (0.0, 0.0);
      A : constant Complex := (2.44949, 0.0);
      B : constant Complex := (3.16228, 0.0);
      C : constant Complex := (3.46410, 0.0);
      Input : constant Complex_Matrix
        := (
            1 => (Z, A, Z, Z, Z, Z, Z),
            2 => (A, Z, B, Z, Z, Z, Z),
            3 => (Z, B, Z, C, Z, Z, Z),
            4 => (Z, Z, C, Z, C, Z, Z),
            5 => (Z, Z, Z, C, Z, B, Z),
            6 => (Z, Z, Z, Z, B, Z, A),
            7 => (Z, Z, Z, Z, Z, A, Z)
           );
   begin

      Put_Line ("Values in Test16 of "
                  & "http://people.sc.fsu.edu/~jburkardt/f_src/lapack"
                  & "/lapack_OSX_prb_output.txt");

      -- GNAT: Eigenvalues of symmetrix complex matrix are real
      Put_Line ("using Complex_Arrays.Eigenvalues");
      declare
         Result : constant Real_Vector := Complex_Arrays.Eigenvalues (Input);
      begin
         for J in Result'Range loop
            Put (Result (J), Exp => 0);
            New_Line;
         end loop;
      end;
      New_Line;

      --  Extension: Eigenvalues of general complex matrix are complex.
      Put_Line ("using Extensions.Eigenvalues");
      declare
         Result : constant Complex_Vector := Extensions.Eigenvalues (Input);
      begin
         for J in Result'Range loop
            Put (Result (J).Re, Exp => 0);
            Put (" ");
            Put (Result (J).Im, Exp => 0);
            New_Line;
         end loop;
      end;
      New_Line;

   end;

   declare
   --  Values from http://en.wikipedia.org/wiki/Skew-symmetric_matrix
      Input : constant Complex_Matrix
        := (((0.0, 0.0), (2.0, 0.0), (-1.0, 0.0)),
            ((-2.0, 0.0), (0.0, 0.0), (-4.0, 0.0)),
            ((1.0, 0.0), (4.0, 0.0), (0.0, 0.0)));
      Result : Complex_Vector (1 .. Input'Length (1));
   begin

      Put_Line
        ("Values from http://en.wikipedia.org/wiki/Skew-symmetric_matrix");

      Result := Extensions.Eigenvalues (Input);

      for J in Result'Range loop
         Put (Result (J).Re, Exp => 0);
         Put (" ");
         Put (Result (J).Im, Exp => 0);
         New_Line;
      end loop;
      New_Line;

   end;

   declare
   --  Values from http://en.wikipedia.org/wiki/Orthogonal_matrix
      Input : constant Complex_Matrix
        := (((0.0, 0.0), (-0.8, 0.0), (-0.6, 0.0)),
            ((0.8, 0.0), (-0.36, 0.0), (0.48, 0.0)),
            ((0.6, 0.0), (0.48, 0.0), (-0.64, 0.0)));
      Result : Complex_Vector (1 .. Input'Length (1));
   begin

      Put_Line
        ("Values from http://en.wikipedia.org/wiki/Orthogonal_matrix");

      Result := Extensions.Eigenvalues (Input);

      for J in Result'Range loop
         Put (Result (J).Re, Exp => 0);
         Put (" ");
         Put (Result (J).Im, Exp => 0);
         New_Line;
      end loop;
      New_Line;

   end;

end Test_Extensions;

^ permalink raw reply	[relevance 6%]

* Re: Interfacing Ada with C
  @ 2010-07-28 22:26  7%               ` Simon Wright
    0 siblings, 1 reply; 114+ results
From: Simon Wright @ 2010-07-28 22:26 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> Ada novice <posts@gmx.us> writes:
>> On Jul 26, 1:21 am, Simon Wright <si...@pushface.org> wrote:
>>
>>> I've encoded a general complex eigenvalues function, interfacing to the
>>> LAPACK procedure zgeev
>
>> Thank you very much for your commendable efforts. This is a very good
>> example to demonstrate how Ada can be binded with LAPACK.
>
> Well, it's a start!

I've taken the plunge and started a SourceForge project for this. It's
at http://sourceforge.net/projects/gnat-math-extn/ -- under "Ada 2005
Math Extensions", click on [Develop] then on [Code].

I've chosen to use Mercurial (Hg) as the VCS, mainly to get a real-world
feel for using a DVCS (Distributed Version Control System). To downoad
the code, you'll need to install Hg - http://mercurial.selenic.com/ -
because I haven't actually made a code release yet!

If anyone feels moved to join in, just say (of course you need a SF
account to update the SF repository, but with Hg it should be possible
to work via patchsets .. )

For interest, the test program now looks like

   with Ada.Text_IO; use Ada.Text_IO;
   with Ada.Numerics.Generic_Real_Arrays;
   with Ada.Numerics.Generic_Complex_Types;
   with Ada.Numerics.Generic_Complex_Arrays.Extensions;

   procedure Test_Extensions is

      package Real_Arrays
      is new Ada.Numerics.Generic_Real_Arrays (Long_Float);
      package Complex_Types
      is new Ada.Numerics.Generic_Complex_Types (Long_Float);
      package Complex_Arrays
      is new Ada.Numerics.Generic_Complex_Arrays (Real_Arrays,
                                                  Complex_Types);
      package Extensions
      is new Complex_Arrays.Extensions;

      use Complex_Arrays;

      Input : Complex_Matrix (1 .. 3, 1 .. 3);
      Result : Complex_Vector (1 .. Input'Length (1));

   begin

      --  Values in yc's example
      Input := (((8.0, 0.0), (-1.0, 0.0), (-5.0, 0.0)),
                ((-4.0, 0.0), (4.0, 0.0), (-2.0, 0.0)),
                ((18.0, 0.0), (-5.0, 0.0), (-7.0, 0.0)));

      Result := Extensions.Eigenvalues (Input);

      for J in Result'Range loop
         Put_Line (Long_Float'Image (Result (J).Re)
                     & " "
                     & Long_Float'Image (Result (J).Im));
      end loop;

   end Test_Extensions;

(results as before)



^ permalink raw reply	[relevance 7%]

* Re: Interfacing Ada with C
  @ 2010-07-24 16:38  5% ` Simon Wright
    0 siblings, 1 reply; 114+ results
From: Simon Wright @ 2010-07-24 16:38 UTC (permalink / raw)


Ada novice <posts@gmx.us> writes:

>     Having some background in C and in Ada, I would like to have some
> examples on how to interface codes between these two languages. I
> loved Ada but scientific computing libraries are not available. So I
> was thinking to use an available numeric library in C to do some
> mathematical operations such as calculations of eigenvalues and
> eigenvectors from data in an Ada program. Ada does provide some
> routines for eigenvalues and eigenvectors computations but they aren't
> suitable for a non-symmetric matrix.
>
> Information on interfacing Ada with C is scarce on the web and it
> would help much if I can get some simple examples here from which I
> can build up.

I think you have GNAT? Assuming that, you'll find their implementation
of Ada.Numerics.Generic_Real_Arrays in their Ada standard library;
you'll find this under the installation directory. On my Mac it's 
/opt/gnat-gpl-2010-x86_64/lib/gcc/x86_64-apple-darwin9.6.0/4.3.6/adainclude/a-ngrear.ad[sb]
but on a Windows machine it'll be something li
<install-dir>\<gnat-release>\lib\gcc\<architecture>\<gcc-release>\adainclude\a-ngrear.ad[sb]

This will lead you to System.Generic_Real_BLAS (s-gerebl.ad[sb]) and
System.Generic_Real_LAPACK (s-gerela.ad[sb]), which are interfaces to
the corresponding external libraries.


Not sure that these will fit your 'simple' criterion, though!

--S



^ permalink raw reply	[relevance 5%]

* Re: Does ada have a sscanf equivalent?
  @ 2010-02-23  2:11  4%     ` jpwoodruff
  0 siblings, 0 replies; 114+ results
From: jpwoodruff @ 2010-02-23  2:11 UTC (permalink / raw)


On Feb 22, 3:11 pm, Jerry <lancebo...@qwest.net> wrote:
> On Feb 22, 12:48 pm, jpwoodruff <jpwoodr...@gmail.com> wrote:
>
>
>
> > On Feb 22, 1:08 am, "J.s" <justin.squi...@gmail.com> wrote:
>
> > > I am trying to translate some C code that parses a string into numbers
> > > (both Integers and Floats) from an input file. Would it be easiest to
> > > just import the C function or is there an Ada equivalent?
>
> > Let me offer a product of my own devising.
>
> > "The packages Numeric_IO and Name_IO, together with their children and
> > support, assist a program to read a user’s input.  The packages are
> > intended to support numerical computation by providing Get and Put
> > procedures for floating numbers and for vectors and matrices of
> > floating numbers.
>
> > "The procedures ease an end-user’s burden in preparing inputs for
> > computational programs.  The rules for input of floating numbers are
> > relaxed so that program inputs need not conform to the strict Ada
> > syntax for floating numbers. Facilities allow input either from files
> > or interactively. Consistent policies throughout all the services
> > allow programs to address input errors, to prompt the end-user
> > interactively or to specify optional default values."
>
> > Dmitry has been kind enough to make it available.
>
> >http://www.dmitry-kazakov.de/ada/Numeric-Name-IO
>
> > --
> > John
>
> This looks pretty cool. But it doesn't seem to use the Ada 2005
> definitions for matrices and vectors. I haven't looked at the code but
> I wonder how hard it would be to create such a version. I would think
> it should be pretty easy.
>
> Jerry

There's a file in the distribution called "Guide-to-Examples" that
will shed some light on how to roll this forward to Ada 05 standards.

"As of November 2004 I am aware of six different publicly available
libraries that provide some operations on vectors and matrices.  In
the interest of offering the numeric_IO.matrix_IO services to users
who might be using one of these libraries, I have build small
demonstrations of the usage of the IO functions that conform with each
of them."

The same library worked for all cases.

One of the examples was called Ada0y as signed by Martin Dowie. I
can't claim what version that was, but if not too much has changed
since then, maybe this will still fly:


   type Real is digits 6 ;

   package Ada_Matrix is new Ada.Numerics.Generic_Real_Arrays (Real =>
Real) ;

   -- Numeric_IO services will read and write the same matrix
representation
   package Scalar_IO is new Numeric_IO (Real, Integer) ;

   package Matrix_IO is new Scalar_IO.Matrix_IO
     (Vector_Ix    => Integer,
      Vector_Type  => Ada_Matrix.Real_Vector,
      Matrix_Ix1   => Integer,
      Matrix_Ix2   => Integer,
      Matrix_Type  => Ada_Matrix.Real_Matrix) ;



I'm a retired software engineer who has decided not to follow the new
standard.  I decided that I don't need a new programming paradigm
(except maybe for prolog).  And some of my old favorites didn't work
with the '05 compiler I looked at.

This whole business dates to 1986, with an update to Ada95's generic
child packages.  Besides, I wrote in "A Family of Numeric ..." a
paragraph headed Anachronism Alert.  "... So don't read this package
for esthetics, but it seems to work OK"

John



^ permalink raw reply	[relevance 4%]

* Re: Randomness tests
  @ 2009-07-17 20:41  5%   ` Gautier write-only
  0 siblings, 0 replies; 114+ results
From: Gautier write-only @ 2009-07-17 20:41 UTC (permalink / raw)


Nicholas Paul Collin Gloucester:

> Please let us know your conclusions.

So - the mentioned package is indeed the "universal" random generator
from Dr. George Marsaglia, which seems to have appeared in the Ada
letters in 1988, which circulates under the name U_Rand.
According to the machine and compiler, I get a speedup from 5x to 6.8x
(net of overhead).
No more advanced tests yet...
There are a couple of others generators I've to try, e.g. the Mersenne
Twister:
http://adrianhoe.com/adrianhoe/projects/adamt19937/
or a very simple one from Peter:
http://groups.google.ch/group/comp.lang.ada/msg/cf300f84f8782702

I've just "repimped" U_Rand with generics, no more global variables
but a type Generator, and some Ada 95 A.N.Float_Random-style
"renames", which facilitates the switch between random packages, like
in this example:

  -- *** Choice of the floating-point type used for the whole
Portfolio Model:
  subtype Real is Long_Float;

  package Real_U_Rand is new U_Rand(Real);

  -- *** Choice of a random generator: A.N.F_R, or U_Rand (faster),
or...:
  package RRand renames
    -- Ada.Numerics.Float_Random;
    Real_U_Rand;

The funny thing is that RRand can be plugged in its turn into another
generic package

  package GRA is new Ada.Numerics.Generic_Real_Arrays(Real);

  package RCopulas is new Copulas(
    Real,
    RRand.Uniformly_Distributed, RRand.Generator, RRand.Random,
    GRA
  );

In case someone is interested, mail me.
Anytime soon I'll open a SourceForge project with various random
variable goodies.
_________________________________________________________
Gautier's Ada programming -- http://sf.net/users/gdemont/
NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[relevance 5%]

* Re: ANN: miscellaneous Math routines, GPL'd
  2009-05-13 11:52  7%     ` gautier_niouzes
@ 2009-05-13 13:43  0%       ` johnscpg
  0 siblings, 0 replies; 114+ results
From: johnscpg @ 2009-05-13 13:43 UTC (permalink / raw)


On May 13, 12:52 pm, gautier_niou...@hotmail.com wrote:
> On 13 Mai, 11:25, johns...@googlemail.com wrote:
>
>
>
> > Another irritation:  suppose user declares
>
> >   V : Vector (1..10);
> >   M : Matrix (0..9, 0..9);
> > or worse
> >   M : Matrix (0..9, 2..11);
> > or worse still
> >   M : Matrix (0..11, 2..11);
>
> > How do you handle it?
> > 1. shift indices during iteration inside loops in the lin alg program.
> > 2. slide arrays so indices coincide.
> > 3. Raise constraint_error;
> > 4. Assume they won't do it.
>
> > I do 3. (See for example procedure Choleski_Decompose at end of
> > Disorderly-Random-Deviates.adb  and near bottom of
> > Disorderly-Random-Deviates.ads.)   But I'm not sure what to do.
> > (I was going ask here on comp.lang.ada, but got lazy.)
> > Generics with constrained arrays work ok for me here.
>
> It's done here:http://www.cs.umbc.edu/~squire/adaclass/gnatmath95,
> generic_real_linear_equations.ads .
>
> For using with Ada 2005's matrices, all you need is to replace
> package Generic_Real_Arrays by Ada.Numerics.Generic_Real_Arrays
> :-)
> _________________________________________________________
> Gautier's Ada programming --http://sf.net/users/gdemont/
>
> NB: For a direct answer, e-mail address on the Web site!

Thanks Gautier!  After a quick inspection, I notice a lot
of method 1, (shifting indices inside loops), but sometimes the
author copies the entire input array over to a new local array
with the desired indices (usually 1..N).  Also
raises an exception if there's a length mismatch.

cheers,
jonathan




^ permalink raw reply	[relevance 0%]

* Re: ANN: miscellaneous Math routines, GPL'd
  @ 2009-05-13 11:52  7%     ` gautier_niouzes
  2009-05-13 13:43  0%       ` johnscpg
  0 siblings, 1 reply; 114+ results
From: gautier_niouzes @ 2009-05-13 11:52 UTC (permalink / raw)


On 13 Mai, 11:25, johns...@googlemail.com wrote:

> Another irritation:  suppose user declares
>
>   V : Vector (1..10);
>   M : Matrix (0..9, 0..9);
> or worse
>   M : Matrix (0..9, 2..11);
> or worse still
>   M : Matrix (0..11, 2..11);
>
> How do you handle it?
> 1. shift indices during iteration inside loops in the lin alg program.
> 2. slide arrays so indices coincide.
> 3. Raise constraint_error;
> 4. Assume they won't do it.
>
> I do 3. (See for example procedure Choleski_Decompose at end of
> Disorderly-Random-Deviates.adb  and near bottom of
> Disorderly-Random-Deviates.ads.)   But I'm not sure what to do.
> (I was going ask here on comp.lang.ada, but got lazy.)
> Generics with constrained arrays work ok for me here.

It's done here:
http://www.cs.umbc.edu/~squire/adaclass/gnatmath95 ,
generic_real_linear_equations.ads .

For using with Ada 2005's matrices, all you need is to replace
package Generic_Real_Arrays by Ada.Numerics.Generic_Real_Arrays
:-)
_________________________________________________________
Gautier's Ada programming -- http://sf.net/users/gdemont/

NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[relevance 7%]

* Re: Linking Error when using Ada.Numerics.Generic_Real_Arrays package
  2008-11-11 22:27  7% ` Jeffrey R. Carter
  2008-11-12  6:15  7%   ` christoph.grein
@ 2008-11-13 14:36  7%   ` Samuel Tardieu
  1 sibling, 0 replies; 114+ results
From: Samuel Tardieu @ 2008-11-13 14:36 UTC (permalink / raw)


>>>>> "Jeffrey" == Jeffrey R Carter <spam.jrcarter.not@spam.acm.org> writes:

Jeffrey> If you have GNAT Pro, you should have a support agreement
Jeffrey> with AdaCore. Why not ask them?

GNAT Pro may have been obtained originally from AdaCore, but can be
redistributed to others (who may not have a support contract).
Or isn't GNAT Pro GPL anymore?
 
 Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/



^ permalink raw reply	[relevance 7%]

* Re: Linking Error when using Ada.Numerics.Generic_Real_Arrays package
  2008-11-11 22:27  7% ` Jeffrey R. Carter
@ 2008-11-12  6:15  7%   ` christoph.grein
  2008-11-13 14:36  7%   ` Samuel Tardieu
  1 sibling, 0 replies; 114+ results
From: christoph.grein @ 2008-11-12  6:15 UTC (permalink / raw)


On 11 Nov., 23:27, "Jeffrey R. Carter"
<spam.jrcarter....@spam.acm.org> wrote:
> If you have GNAT Pro, you should have a support agreement with AdaCore. Why not
> ask them?

Right.

Just for the record: I also have GNAT Pro 6.0.1 - it's missing the
library libgnalasup.a which is not included by mistake. Just get it
from AdaCore and place it in the standard library directory (the
command "gnatls -v" shows this under the heading "Object Search
Path"); you also need the linker options "-lgnalasup -lm".

(GNAT Pro 6.1.1. has it.)



^ permalink raw reply	[relevance 7%]

* Re: Linking Error when using Ada.Numerics.Generic_Real_Arrays package
  2008-11-11 21:43 14% Linking Error when using Ada.Numerics.Generic_Real_Arrays package AAFellow
@ 2008-11-11 22:27  7% ` Jeffrey R. Carter
  2008-11-12  6:15  7%   ` christoph.grein
  2008-11-13 14:36  7%   ` Samuel Tardieu
  0 siblings, 2 replies; 114+ results
From: Jeffrey R. Carter @ 2008-11-11 22:27 UTC (permalink / raw)


AAFellow@hotmail.com wrote:
> 
> I am using GNAT Pro 6.0.1.  Does the compiler not support the use of
> the Ada.Numerics.Generic_Real_Arrays package?  Is there anything that
> can be done to make this work?

If you have GNAT Pro, you should have a support agreement with AdaCore. Why not 
ask them?

-- 
Jeff Carter
"We use a large, vibrating egg."
Annie Hall
44



^ permalink raw reply	[relevance 7%]

* Linking Error when using Ada.Numerics.Generic_Real_Arrays package
@ 2008-11-11 21:43 14% AAFellow
  2008-11-11 22:27  7% ` Jeffrey R. Carter
  0 siblings, 1 reply; 114+ results
From: AAFellow @ 2008-11-11 21:43 UTC (permalink / raw)


Hello,

I am writing a program that uses the Ada.Numerics.Generic_Real_Arrays
package.  I use the Real_Vector data type, as well as the *
(vector*vector as well as scalar*vector) , +,  and - functions.

Upon linking, I get errors in System.Generic_Real_BLAS and
System.Generic_Real_LAPACK packages.   In the first file, I am getting
undefined references to sdot_, sgemm_, sgemv_, and snrm2_.  In the
second file, I am getting errors for undefined references to sgetrf_,
sgetri_, sgetrs_, sorgtr_, ssteqr_, ssterf_, and ssytrd_.

I am using GNAT Pro 6.0.1.  Does the compiler not support the use of
the Ada.Numerics.Generic_Real_Arrays package?  Is there anything that
can be done to make this work?

Thanks!!

AAFellow



^ permalink raw reply	[relevance 14%]

* Re: Generic_Roots
  2008-11-01 17:47  7% Generic_Roots John B. Matthews
@ 2008-11-07  1:20  0% ` Randy Brukardt
  0 siblings, 0 replies; 114+ results
From: Randy Brukardt @ 2008-11-07  1:20 UTC (permalink / raw)


Umm, AI95-0356 is "Support for Preemption Level Locking Policy".

You mean AI95-0346 "Roots of polynomials".

You might want to pass this implementation past John Barnes, as he was the 
original proposer of that AI.

                           Randy.

"John B. Matthews" <nospam@nospam.invalid> wrote in message 
news:nospam-5E13A8.13471601112008@news.motzarella.org...
> Although they never became standard, I've written implementations of
>
> AI-356: Ada.Numerics.Generic_Real_Arrays.Generic_Roots
> AI-356: Ada.Numerics.Generic_Complex_Arrays.Generic_Roots
>
> The updated numerics packages and some test code are available here
>
> <http://home.roadrunner.com/~jbmatthews/misc/groots.html>
>
> The implementation uses the Durand-Kerner-Weierstrass method:
>
> <http://en.wikipedia.org/wiki/Durand-Kerner_method>
>
> I'd be grateful for any comments you might have.
>
> -- 
> John B. Matthews
> trashgod at gmail dot com
> http://home.roadrunner.com/~jbmatthews/ 





^ permalink raw reply	[relevance 0%]

* Generic_Roots
@ 2008-11-01 17:47  7% John B. Matthews
  2008-11-07  1:20  0% ` Generic_Roots Randy Brukardt
  0 siblings, 1 reply; 114+ results
From: John B. Matthews @ 2008-11-01 17:47 UTC (permalink / raw)


Although they never became standard, I've written implementations of

AI-356: Ada.Numerics.Generic_Real_Arrays.Generic_Roots
AI-356: Ada.Numerics.Generic_Complex_Arrays.Generic_Roots

The updated numerics packages and some test code are available here

<http://home.roadrunner.com/~jbmatthews/misc/groots.html>

The implementation uses the Durand-Kerner-Weierstrass method:

<http://en.wikipedia.org/wiki/Durand-Kerner_method>

I'd be grateful for any comments you might have.

-- 
John B. Matthews
trashgod at gmail dot com
http://home.roadrunner.com/~jbmatthews/



^ permalink raw reply	[relevance 7%]

* Re: Larger matrices
  2008-08-08 15:40  0%                             ` Georg Bauhaus
@ 2008-08-08 16:37  0%                               ` Dmitry A. Kazakov
  0 siblings, 0 replies; 114+ results
From: Dmitry A. Kazakov @ 2008-08-08 16:37 UTC (permalink / raw)


On Fri, 08 Aug 2008 17:40:16 +0200, Georg Bauhaus wrote:

> Dmitry A. Kazakov schrieb:
> 
>> They are not. Lisp is a list-oriented language, Prolog is a logical
>> inference language.
> 
> Lisp and Prolog with FFI(!) are not universal? Come on.

Of course they are not. Both are domain-specific languages.

>>> This notion of "purpose" is not very specific.
>>> Let me put is this way: Ada has to be especially good at
>>> systems programming, hence it has to be fairly low level.
>> 
>> Wrong. Where that follows from? Systems programming need not to be
>> low-level.
> 
> A systems programming language must provide for the low
> level.

Nope, it must provide systems programming domain abstractions. Ada does
this. This does not make it low-level.

It seems that you are confusing different concepts of abstraction. Level
depends on where is the ground, the underlying computational environment.
This is not necessarily the hardware, but it can be one.

1. Considering hardware as the environment. Ada running on an Ada-hardware
(if such existed) would make this implementation of Ada low-level. But it
would not make Ada low-level, because it also runs on the hardware
requiring much work to create an Ada compiler. Therefore Ada in general is
high level relatively to the hardware.

2. Considering programming paradigms as the environment, i.e. the terms in
which programs are thought an composed. Ada is again very high level, as it
supports up to 3rd set abstractions:

   value -> type (sets of) -> class / generic (sets of)

OO decomposition, concurrency etc.

> A language that does not provide for the low level
> is not a systems programming language.

A logical fallacy: A => B does not imply A = B.

> Ada has many features
> that provide for low level programming.  It lacks a numer of
> features used in higher level programming (E.g. function
> environments, unbounded numbers, ...).

Since when unbounded numbers became high level? Consider it used to
implement modular arithmetic or ASCII characters. How low-level!

> Systems programming
> is not the same as low level programming or high level programming;
> rather, the set of objects is typically not as abstract as
> some mathematical N-array of numbers.

I don't see how interrupt, task or I/O port are less abstract than array.

>>> What hardware?
>> 
>> Vector processors.
> 
> OK, I wasn't aware that the LA packages were made for vector
> processors only.

Take Intel x86 instead, if you don't like vector processor.

>>> Assume data flow hardware, and assume a way
>>> to put the function result in the input box of the next processing unit.
>>> What now?
>> 
>> Nothing, Ada.Numerics.Generic_Real_Arrays was not designed in order to
>> support this hardware.
> 
> Aha?   I see that GNAT delegates to Fortran libraries. Traditionally,
> Fortran is certainly an associate of non-PC hardware.

That was not the point, it was as it reads, the design did not target any
hardware and will be *relatively* inefficient on any existing hardware.
Relatively, because it most likely will beat both Lisp and Prolog.

>>> I don't see how prototyping a hypertext graph algorithm
>>> requires a maximally efficient implementation of matrix
>>> computations.
>> 
>> Because of the problem size. Incidence matrices grow as O(n**2), i.e.
>> extremely fast.
> 
> O(N**2) is not extremely fast; many non-extreme algorithms
> are in this class.  The case discussed hits some memory barrier
> at n = 5_000 and that's it. We get elaborate array indexing support
> in some array programming languages.  If chosing one of those
> PLs costs me a constant factor of 10, I get all the indexing
> stuff in return, it seems worth the cost during prototyping.

No chance. O(N**2) is only memory complexity. You should also consider the
number of operations required per element. Naive matrix multiplication is
O(N**3). Factor 10 means (N x 10)**3 thousand times slower! And this is
only the lower bound. But all this is in order learn that the fancy
language X is greatly slower than Ada and is totally unsuitable for
production code? I know it in advance!

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[relevance 0%]

* Re: Larger matrices
  2008-08-08 14:36  7%                           ` Dmitry A. Kazakov
@ 2008-08-08 15:40  0%                             ` Georg Bauhaus
  2008-08-08 16:37  0%                               ` Dmitry A. Kazakov
  0 siblings, 1 reply; 114+ results
From: Georg Bauhaus @ 2008-08-08 15:40 UTC (permalink / raw)


Dmitry A. Kazakov schrieb:

> They are not. Lisp is a list-oriented language, Prolog is a logical
> inference language.

Lisp and Prolog with FFI(!) are not universal? Come on.


>> This notion of "purpose" is not very specific.
>> Let me put is this way: Ada has to be especially good at
>> systems programming, hence it has to be fairly low level.
> 
> Wrong. Where that follows from? Systems programming need not to be
> low-level.

A systems programming language must provide for the low
level.  A language that does not provide for the low level
is not a systems programming language.  Ada has many features
that provide for low level programming.  It lacks a numer of
features used in higher level programming (E.g. function
environments, unbounded numbers, ...).  Systems programming
is not the same as low level programming or high level programming;
rather, the set of objects is typically not as abstract as
some mathematical N-array of numbers.  The set of objects in
a systems programming language is more like a real N-array
of numbers: storage cells of well defined meaning, with just
one layer of abstraction above the storage cells.

>> What hardware?
> 
> Vector processors.

OK, I wasn't aware that the LA packages were made for vector
processors only.


>> Assume data flow hardware, and assume a way
>> to put the function result in the input box of the next processing unit.
>> What now?
> 
> Nothing, Ada.Numerics.Generic_Real_Arrays was not designed in order to
> support this hardware.

Aha?   I see that GNAT delegates to Fortran libraries. Traditionally,
Fortran is certainly an associate of non-PC hardware.


> Which is the point. Ada is not low-level,

Ada is fairly low-level.


>> I don't see how prototyping a hypertext graph algorithm
>> requires a maximally efficient implementation of matrix
>> computations.
> 
> Because of the problem size. Incidence matrices grow as O(n**2), i.e.
> extremely fast.

O(N**2) is not extremely fast; many non-extreme algorithms
are in this class.  The case discussed hits some memory barrier
at n = 5_000 and that's it. We get elaborate array indexing support
in some array programming languages.  If chosing one of those
PLs costs me a constant factor of 10, I get all the indexing
stuff in return, it seems worth the cost during prototyping.



>> A production system may require increased
>> efficiency. At that stage you have to pay attention to
>> the tiny bits, possibly redesigning the algorithm.
> 
> Numerics is all about algorithms.

Numerics is about numbers (or about numeric control, depending).


> This BTW is exactly the problem OP has. He has "prototyped" the thing using
> Ada.Numerics.Generic_Real_Arrays. Now, he faces the problem that the
> prototype does not scale due to stack overflow. The consequence is a need
> in full redesign. Ergo, prototyping was time wasting.

Nice rhetoric logic error.


--
Georg Bauhaus
Y A Time Drain  http://www.9toX.de



^ permalink raw reply	[relevance 0%]

* Re: Larger matrices
  2008-08-08 14:11  0%                         ` Georg Bauhaus
@ 2008-08-08 14:36  7%                           ` Dmitry A. Kazakov
  2008-08-08 15:40  0%                             ` Georg Bauhaus
  0 siblings, 1 reply; 114+ results
From: Dmitry A. Kazakov @ 2008-08-08 14:36 UTC (permalink / raw)


On Fri, 08 Aug 2008 16:11:57 +0200, Georg Bauhaus wrote:

> Dmitry A. Kazakov schrieb:
>> On Fri, 08 Aug 2008 13:35:04 +0200, Georg Bauhaus wrote:
> 
>>> Ada is a systems programming language. 
> 
>> What?! Ada is a universal purpose language.
> 
> Assembly language is universal,

It is Turing complete.

> too, as are Lisp and Prolog with FFI,
> and so on.

They are not. Lisp is a list-oriented language, Prolog is a logical
inference language.

> This notion of "purpose" is not very specific.
> Let me put is this way: Ada has to be especially good at
> systems programming, hence it has to be fairly low level.

Wrong. Where that follows from? Systems programming need not to be
low-level. It has to have abstractions close to ones typical for "systems."
There is no obvious connection between these. For example, Ada offers the
notion of protected action in order represent a systems-domain specific
concept of interrupt. It is a fairly high-level abstraction.

>> But an efficient or hardware-close implementation was certainly not the
>> concern of the Ada.Numerics.Generic_Real_Arrays design. Otherwise it would
>> not use functions at all.
> 
> What hardware?

Vector processors.

> Assume data flow hardware, and assume a way
> to put the function result in the input box of the next processing unit.
> What now?

Nothing, Ada.Numerics.Generic_Real_Arrays was not designed in order to
support this hardware. Which is the point. Ada is not low-level, and its
design goals are not focused solely on efficiency, but on usability,
portability and maintainability.

> I don't see how prototyping a hypertext graph algorithm
> requires a maximally efficient implementation of matrix
> computations.

Because of the problem size. Incidence matrices grow as O(n**2), i.e.
extremely fast.

> A production system may require increased
> efficiency. At that stage you have to pay attention to
> the tiny bits, possibly redesigning the algorithm.

So, what was prototyped then? Numerics is all about algorithms. Changing
matrix representation has a huge impact on the implementation of the
operations. Technically it means that you have to re-write everything.

This BTW is exactly the problem OP has. He has "prototyped" the thing using
Ada.Numerics.Generic_Real_Arrays. Now, he faces the problem that the
prototype does not scale due to stack overflow. The consequence is a need
in full redesign. Ergo, prototyping was time wasting.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[relevance 7%]

* Re: Larger matrices
  2008-08-08 12:11  5%                       ` Dmitry A. Kazakov
@ 2008-08-08 14:11  0%                         ` Georg Bauhaus
  2008-08-08 14:36  7%                           ` Dmitry A. Kazakov
  0 siblings, 1 reply; 114+ results
From: Georg Bauhaus @ 2008-08-08 14:11 UTC (permalink / raw)


Dmitry A. Kazakov schrieb:
> On Fri, 08 Aug 2008 13:35:04 +0200, Georg Bauhaus wrote:


>> Ada is a systems programming language. 

> What?! Ada is a universal purpose language.

Assembly language is universal, too, as are Lisp and Prolog with FFI,
and so on.  This notion of "purpose" is not very specific.
Let me put is this way: Ada has to be especially good at
systems programming, hence it has to be fairly low level.



> But an efficient or hardware-close implementation was certainly not the
> concern of the Ada.Numerics.Generic_Real_Arrays design. Otherwise it would
> not use functions at all.

What hardware?  Assume data flow hardware, and assume a way
to put the function result in the input box of the next processing unit.
What now?


>>  I'd suggest that you seriously consider prototyping
>> your algorithms using one of the fine PLs that do have the
>> required mathematical stuff built in.
> 
> Really? 90% of numeric libraries and applications is written in FORTRAN.

Only a fraction of the tabular arrays of numbers
is input to procedures of challenging numeric libraries.
I'll even guess that a larger fraction of matrices in
lots of Ada programs are 3x3, maybe 4x4.


> Do
> you think they have prototyped them in 60's?
[The libraries, or the algorithms? The latter, yes; APL is about
that old.]

I don't see how prototyping a hypertext graph algorithm
requires a maximally efficient implementation of matrix
computations.  A production system may require increased
efficiency. At that stage you have to pay attention to
the tiny bits, possibly redesigning the algorithm.
(If I could have stopped at simple recursive
functions when writing the program below it would have been
a trivial exercise. :)

Georg Bauhaus
Y A Time Drain  http://www.9toX.de



^ permalink raw reply	[relevance 0%]

* Re: Larger matrices
  @ 2008-08-08 12:11  5%                       ` Dmitry A. Kazakov
  2008-08-08 14:11  0%                         ` Georg Bauhaus
  0 siblings, 1 reply; 114+ results
From: Dmitry A. Kazakov @ 2008-08-08 12:11 UTC (permalink / raw)


On Fri, 08 Aug 2008 13:35:04 +0200, Georg Bauhaus wrote:

> amado.alves@gmail.com schrieb:
>>>> And Ada got in the way: slicing restricted to one-dimensional arrays!
>>> Compared to other languages that have no slicing at all?
>> 
>> There are languages better than Ada at array indexing, including
>> slicing. If there aren't, there should be!
> 
> Ada is a systems programming language.  As such, it is
> targetting digital computers. In cases where Ada can be used
> for some mathematical tasks, it is still a systems programming
> language.

What?! Ada is a universal purpose language.

> Ada is about computers that have word/byte adressable
> storage cells that happen to be able to store
> bit combinations. Ada is not about cells of mathematical
> abstractions.  Overlap is accidental.

Submatrices can be handled efficiently [in-place] using interleaving
techniques.

But an efficient or hardware-close implementation was certainly not the
concern of the Ada.Numerics.Generic_Real_Arrays design. Otherwise it would
not use functions at all.

> If you do already have some theory for your graphs,
> and presuming you need a working program for large
> matrices, I'd suggest that you seriously consider prototyping
> your algorithms using one of the fine PLs that do have the
> required mathematical stuff built in.

Really? 90% of numeric libraries and applications is written in FORTRAN. Do
you think they have prototyped them in 60's? I guess that pencil and paper
is what they used. After all maths is best prototyped in math.

The major challenges numerical applications have is not math, but squeezing
most out of the hardware, in terms of memory, time, accuracy, problem size.
None of this can be "prototyped."

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[relevance 5%]

* Re: Symmetric matrices only!
  2008-04-18  4:30  0% ` Gautier
@ 2008-04-18  9:40  0%   ` Ken Thomas
  0 siblings, 0 replies; 114+ results
From: Ken Thomas @ 2008-04-18  9:40 UTC (permalink / raw)


On Apr 18, 5:30 am, Gautier <gaut...@fakeaddress.nil> wrote:
> amado.al...@gmail.com:
>
> > The eigenvector solvers in Ada.Numerics.Generic_Real_Arrays require
> > *symmetric* matrices! This is extremely silly. The world is full of
> > nonsymmetric matrices. I've got a bunch of them to solve. Some very
> > large, e.g. 1000x1000. Suggestions welcome. Thanks a lot.
>
> As other people answered, solving a symmetric matrix is another science than a
> asymmetric one. But also when the matrices get big, other storages (than array
> (Integer range <>, Integer range <>) of...) can be a better solution, like band
> or sparse matrices. In some areas a 10_000 x 10_000 matrix is a toy one, for
> testing small examples (e.g. solving a physics equation on a 100x100 grid)...
> ______________________________________________________________
> Gautier         --http://www.mysunrise.ch/users/gdm/index.htm
> Ada programming --http://www.mysunrise.ch/users/gdm/gsoft.htm
>
> NB: For a direct answer, e-mail address on the Web site!

What you can do is write an interface to the LAPACK routine _GEEV (or
similar); it means needing an installation of LAPACK and BLAS. But if
you are using Generic_Real_Arrays you will need to link up with these
libraries anyway.

Duncan Sands produced bindings to BLAS and I extended some to cover
the LAPACK material I needed. They are not complete  just created on
demand. I could send these if they would help.

Ada is very good in the way it can define interfaces to numerical
software.






^ permalink raw reply	[relevance 0%]

* Re: Symmetric matrices only!
  2008-04-17 13:16  6% Symmetric matrices only! amado.alves
  2008-04-17 15:25  0% ` Adam Beneschan
  2008-04-18  1:34  0% ` smsomething
@ 2008-04-18  4:30  0% ` Gautier
  2008-04-18  9:40  0%   ` Ken Thomas
  2 siblings, 1 reply; 114+ results
From: Gautier @ 2008-04-18  4:30 UTC (permalink / raw)


amado.alves@gmail.com:

> The eigenvector solvers in Ada.Numerics.Generic_Real_Arrays require
> *symmetric* matrices! This is extremely silly. The world is full of
> nonsymmetric matrices. I've got a bunch of them to solve. Some very
> large, e.g. 1000x1000. Suggestions welcome. Thanks a lot.

As other people answered, solving a symmetric matrix is another science than a 
asymmetric one. But also when the matrices get big, other storages (than array 
(Integer range <>, Integer range <>) of...) can be a better solution, like band 
or sparse matrices. In some areas a 10_000 x 10_000 matrix is a toy one, for 
testing small examples (e.g. solving a physics equation on a 100x100 grid)...
______________________________________________________________
Gautier         -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[relevance 0%]

* Re: Symmetric matrices only!
  2008-04-17 13:16  6% Symmetric matrices only! amado.alves
  2008-04-17 15:25  0% ` Adam Beneschan
@ 2008-04-18  1:34  0% ` smsomething
  2008-04-18  4:30  0% ` Gautier
  2 siblings, 0 replies; 114+ results
From: smsomething @ 2008-04-18  1:34 UTC (permalink / raw)


On Apr 18, 1:16 am, amado.al...@gmail.com wrote:
> The eigenvector solvers in Ada.Numerics.Generic_Real_Arrays require
> *symmetric* matrices! This is extremely silly. The world is full of
> nonsymmetric matrices. I've got a bunch of them to solve. Some very
> large, e.g. 1000x1000. Suggestions welcome. Thanks a lot.

Providing support for solving eigenvectors for general matrices
without restrictions would be a very complicated task, and I can
understand why the language designers provided the limited support
they have. Ada provides a rather basic set of solvers, useable in
straight-forward problems. This is not particularly silly at all -
it's a pragmatic approach to what is a very difficult general problem.
Having said that, I do use the Ada built-in solvers, and they're very
useful where I can't be bothered getting access to specialised
routines, or where there is no necessity to do so. When I need
something better, I use a routine that has been proven to work in the
specialised situation I am dealing with.

If you (potentially) need to find the eigenvalues of non-symmetric
matrices of 1000x1000, then your need is highly specialised, and you
need to seek out the highly-specialised solutions that have been
developed, and that are widely available. Some will be in C/C++, but
more likely they are in FORTRAN, but the interfacing issues with Ada
are (usually) not complicated.

You could start with GSL (www.gnu.org/software/gsl), which has a
variety of eigensystem solvers, including a set for real asymmetric
matrices. Also look at NETLIB (www.netlib.org). Once you've been
through these, you'll have a better idea what kind of problem you are
up against, and whether you need to seek straight-forward or
specialised routines.

Unfortunately, you havn't specified whether your asymmetric matrices
are real or complex, or whether the matrix itself has any other
construction properties, or whether it is sparse. Answers to these
questions could drastically alter the advice you would be given.

Overall, the answer to your problem for calculating (or, better,
"estimating") eigenvalues is out there somewhere, and the various
solutions can (in general) be accessed from Ada.

Good luck
SM



^ permalink raw reply	[relevance 0%]

* Re: Symmetric matrices only!
  2008-04-17 15:25  0% ` Adam Beneschan
@ 2008-04-17 16:55  0%   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 114+ results
From: Dmitry A. Kazakov @ 2008-04-17 16:55 UTC (permalink / raw)


On Thu, 17 Apr 2008 08:25:26 -0700 (PDT), Adam Beneschan wrote:

> On Apr 17, 6:16 am, amado.al...@gmail.com wrote:

>> The eigenvector solvers in Ada.Numerics.Generic_Real_Arrays require
>> *symmetric* matrices! This is extremely silly. The world is full of
>> nonsymmetric matrices. I've got a bunch of them to solve. Some very
>> large, e.g. 1000x1000. Suggestions welcome. Thanks a lot.

In my times it was "huge". (:-)) I"m afraid you should turn to special
literature and implement a suitable method by yourself.

> We're in an area where I have no mathematical knowledge.  However, I
> can quote something from AI95-296, which might explain why an
> "extremely silly" decision was made:

[...]

It is a long time since I dealt with numerical linear algebra, but I well
remember that eigenvalues and/or eigenvectors is a complex numerical
problem, which does not have just one, best solution method. There are many
special case matrices, sparse matrices etc.

It is strange that the package does not mandate neither the method, nor the
accuracy. I would expect a design with several child packages implementing
different methods for special matrix cases, as well as means for
checkpointing when dealing with large matrices.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[relevance 0%]

* Re: Symmetric matrices only!
  2008-04-17 13:16  6% Symmetric matrices only! amado.alves
@ 2008-04-17 15:25  0% ` Adam Beneschan
  2008-04-17 16:55  0%   ` Dmitry A. Kazakov
  2008-04-18  1:34  0% ` smsomething
  2008-04-18  4:30  0% ` Gautier
  2 siblings, 1 reply; 114+ results
From: Adam Beneschan @ 2008-04-17 15:25 UTC (permalink / raw)


On Apr 17, 6:16 am, amado.al...@gmail.com wrote:
> The eigenvector solvers in Ada.Numerics.Generic_Real_Arrays require
> *symmetric* matrices! This is extremely silly. The world is full of
> nonsymmetric matrices. I've got a bunch of them to solve. Some very
> large, e.g. 1000x1000. Suggestions welcome. Thanks a lot.

We're in an area where I have no mathematical knowledge.  However, I
can quote something from AI95-296, which might explain why an
"extremely silly" decision was made:

'We considered providing subprograms for the determination of
eigenvalues and
eigenvectors of general real and complex matrices. Such matrices can
have
complex eigenvalues and therefore provision for these would have to be
in the
complex package. However, there are mathematical difficulties with
these general
cases which are in strong contrast to the real symmetric and Hermitian
matrices.
Thus, Numerical Recipes by Press, Flannery, Teukolsky and Vetterling
says
regarding the real case:

"The algorithms for symmetric matrices ... are highly satisfactory in
practice.
By contrast, it is impossible to design equally satisfactory
algorithms for the
nonsymmetric case. There are two reasons for this. First, the
eigenvalues of a
nonsymmetric matrix can be very sensitive to small changes in the
matrix
elements. Second, the matrix itself can be defective so that there is
no
complete set of eigenvectors. We emphasize that these difficulties are
intrinsic
properties of certain nonsymmetric matrices, and no numerical
procedure can cure
them."'

In the discussion section of the AI there's this, from John Barnes:

"Moreover, the eigenvalues and vectors of
nonsymmetric, non-Hermitian matrices have been removed because of
potential
computational difficulties."

I have no idea what all this means, but it doesn't sound silly to me.

                                     -- Adam



^ permalink raw reply	[relevance 0%]

* Symmetric matrices only!
@ 2008-04-17 13:16  6% amado.alves
  2008-04-17 15:25  0% ` Adam Beneschan
                   ` (2 more replies)
  0 siblings, 3 replies; 114+ results
From: amado.alves @ 2008-04-17 13:16 UTC (permalink / raw)


The eigenvector solvers in Ada.Numerics.Generic_Real_Arrays require
*symmetric* matrices! This is extremely silly. The world is full of
nonsymmetric matrices. I've got a bunch of them to solve. Some very
large, e.g. 1000x1000. Suggestions welcome. Thanks a lot.



^ permalink raw reply	[relevance 6%]

* Re: Interested about number crunching in Ada
  2007-08-16 18:59  6%   ` Gautier
@ 2007-08-17  4:44  0%     ` anon
  0 siblings, 0 replies; 114+ results
From: anon @ 2007-08-17  4:44 UTC (permalink / raw)


As for F2A: 

Language converts are nice but in the GNU series they may add useless 
code because of the number of steps take to convert the code from the 
source to object code.

An example:

   GNU F77
   GNU F90  -- to --> C then using GCC -- to --> asm 
   GNU F95 
            asm then using GCC -- to --> object


   GNU F2C  -- to --> C then using GCC -- to --> asm 
            asm then using GCC -- to --> object

   GNAT  -- to --> C then using GCC -- to --> asm 
            asm then using GCC -- to --> object

   F2A -- to --> Ada then using GNAT -- to --> C
            C using GCC -- to --> asm 
            asm then using GCC -- to --> object


The asm package is internal data file unless you ask for a assembly 
listing by insert -S into the command line. The "-S" cause the "GCC" 
to format and write the data to the 'stdout'.

To truly optimize the code you need to stop and perform code 
optimization at each step and then repeat all previous steps. That's a 
lot of coding and testing just to optimize code that is already optimize 
in FORTRAN. And rewriting the code 2 .. x times to optimize the 
algorithm, is pure boring. Some programmers may take the full time 
alotted by the school for a Doctoral just to try to increase performance 
and optimize an algorithm. After the first couple of months re-writing 
the same algorithm they state they are truly bored with the whole 
process. 

To test this try re-writing an algorithm a couple of times a day for a 
month to try to increase the performance. You will get bored too.

Also, as many will tell you those little codes seams to turn into bigger 
ones in a blink of an eye. For school projects, that is fine, but in big 
business, time is money and that can mean someone job. So, the faster 
it works is not always the best policy, it faster you can get operational 
the best policy. And that's the reason why people use the pre-defined 
libraries.

Then there the compatibility, any library code written in FORTRAN 2, or 
IV can be compiled and be linked in FORTRAN 77, 90, 95 or beyond.  
I/O may need to be redirected but numerical code needs no rewriting.

But in Ada, like JAVA the packages have changed.  Such as 
'LOW_LEVEL_IO' package which as defined in Ada 83 but in not in Ada 
95, see RM Annex J for some other changes. This suggest that Ada 95 
compiler are not required to support Ada 83, and Ada 2005 compiles may 
not support Ada 83 or 95. Which means the built-in Ada packages that 
you use today may not be there tomorrow and that includes the numeric 
packages.

Gnat allows one to limit its code to Ada 83, Ada 95, and Ada 05, but 
will that be the case in the next Ada specification update. Of course, 
they still have GNAT obsolescent features that still work like the 
'pragma No_Run_Time'. So, only time will see!



Then, you forgot to say that HP is playing politics.

That is, there are three main groups that deal with FORTRAN.

First, is the part-time programmers.  Like Doctors who program uses 
the language because the FORTRAN routine libraries exist. That save 
time and lives. but it does increase cost that is pass on to the 
end-user for libraries fees.

The second group, loves FORTRAN and actively use FORTRAN and push 
for modifications/updates that will make it easier for them to use 
the language. They HATE the idea that they may have to rewrite the 
FORTRAN libraries so the function of the code can still be used. 
Plus, some do not want to give up the copyrights or licenses they 
own. So, more Software Patents.

Then there are the one that are trying to kill FORTRAN.  HP 
since the late 70's is one companies that is trying to retire 
FORTRAN.  They also voted against adopting FORTRAN 90 and 95, 
stating that FORTRAN is outdated and should stop with FORTRAN 
77. HP has it reasons, and one could be Ada.

Which brings us to Ada. Ada was developed for the military by DEC 
using DEC computer systems. So, DEC had at that time had the 
Software Licenses and Copyright to Ada. DEC was purchase by 
COMPAQ then both were purchase by HP. This means that HP owns 
the Software licenses and Copyright to Ada. Now, HP pays for 
the FORTRAN Software licenses to third parties for the FORTRAN 
libraries. If they sell that Ada out performs FORTRAN then they can 
start receiving more fees for Ada libraries license then what they are 
paying for FORTRAN. Since, licensing fees is a big business, HP 
wants a bigger piece of the pie. 

TI did something like this with their TI-990 series computers 
and PASCAL. They wrote all compilers, assemblers, and Operating 
Systems in PASCAL for their home-owned and mini-frame computer 
system. The PASCAL programs would be allowed to steal resources 
from other users environments or programs. Such as memory and would 
receive more time-slice from the operating system. In some cases
FORTRAN programs would require twice to triple the time just to 
equal the execution of a PASCAL program. After fine tuning the 
operating system for balancing executions, a numeric algorithm 
written in FORTRAN would out perform the same algorithm in 
PASCAL.


In <46c49e6e$1_6@news.bluewin.ch>, Gautier <gautier@fakeaddress.nil> writes:
>anon wrote: plenty of right things that explain the situation - first of all 
>the issue of Ada compilers i.r.o. performance for numerics (it exists: at 
>least, there is a performant one, HP Ada). Now, there are two missing aspects:
>
>- even if you intend to use Ada for number crunching, you don't need to 
>translate all the large building blocks that are presently in Fortran: Ada 
>provides the Import and Convention pragmata. If you look at GNAT's sources 
>behind the new Ada.Numerics.Generic_Real_Arrays, you will see that it cleverly 
>uses the famous and broadly-tested and possibly non-GNU-compiled BLAS and 
>LAPACK libraries.
>
>- for small and/or less tested pieces of code, it is relatively easy to 
>translate them with the f2a tool and the amount of bugs that pop during the 
>Ada-ptation is not boring at all!
>
>Maybe a kind of Sourceforge repository for Ada numerical code would be a good 
>idea - any volunteer ? At least, there would be several contributors...
>______________________________________________________________
>Gautier         -- http://www.mysunrise.ch/users/gdm/index.htm
>Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm
>
>NB: For a direct answer, e-mail address on the Web site!




^ permalink raw reply	[relevance 0%]

* Re: Interested about number crunching in Ada
  @ 2007-08-16 18:59  6%   ` Gautier
  2007-08-17  4:44  0%     ` anon
  0 siblings, 1 reply; 114+ results
From: Gautier @ 2007-08-16 18:59 UTC (permalink / raw)


anon wrote: plenty of right things that explain the situation - first of all 
the issue of Ada compilers i.r.o. performance for numerics (it exists: at 
least, there is a performant one, HP Ada). Now, there are two missing aspects:

- even if you intend to use Ada for number crunching, you don't need to 
translate all the large building blocks that are presently in Fortran: Ada 
provides the Import and Convention pragmata. If you look at GNAT's sources 
behind the new Ada.Numerics.Generic_Real_Arrays, you will see that it cleverly 
uses the famous and broadly-tested and possibly non-GNU-compiled BLAS and 
LAPACK libraries.

- for small and/or less tested pieces of code, it is relatively easy to 
translate them with the f2a tool and the amount of bugs that pop during the 
Ada-ptation is not boring at all!

Maybe a kind of Sourceforge repository for Ada numerical code would be a good 
idea - any volunteer ? At least, there would be several contributors...
______________________________________________________________
Gautier         -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[relevance 6%]

* Re: gnatmake, gnat2007. Linking to lapack and blas using with Ada.Numerics.Generic_Real_Arrays;
  2007-08-12  1:01  7% ` Jerry
@ 2007-08-12  9:53  6%   ` Marc Enzmann
  0 siblings, 0 replies; 114+ results
From: Marc Enzmann @ 2007-08-12  9:53 UTC (permalink / raw)


Hi Jerry!

The libraries for MacOS -on my MacBook with 10.4-  are libBLAS.dylib
and
libLAPACK.dylib, so no problem here, but:
I had to tinker with the Interfaces.Fortran.BLAS package, which is
used
to write Ada wrappers for the BLAS and LAPACK functions. The
"standard"
i-forbla.ads uses pragma import to access Fortran Routines, which are
not
available on standard Mac OS. I had to replace the Fortran Routines in
the
import with C Routines. Not a clean solution, really.

It works, but I am not sure, whether I mapped all routines correctly.
Not much time to check ...

Send me an e-mail, if you would like to try my workaround.

Best regards,

Marc

On 12 Aug., 03:01, Jerry <lancebo...@qwest.net> wrote:
> Has anyone done this on OS X? I believe that lapack and blas are pre-
> installed but might be called clapack and cblas.
>
> Jerry
>




^ permalink raw reply	[relevance 6%]

* Re: gnatmake, gnat2007. Linking to lapack and blas using with Ada.Numerics.Generic_Real_Arrays;
  2007-08-10 23:34 14% gnatmake, gnat2007. Linking to lapack and blas using with Ada.Numerics.Generic_Real_Arrays; Nasser Abbasi
@ 2007-08-12  1:01  7% ` Jerry
  2007-08-12  9:53  6%   ` Marc Enzmann
  0 siblings, 1 reply; 114+ results
From: Jerry @ 2007-08-12  1:01 UTC (permalink / raw)


Has anyone done this on OS X? I believe that lapack and blas are pre-
installed but might be called clapack and cblas.

Jerry

On Aug 10, 4:34 pm, Nasser Abbasi <n...@12000.org> wrote:
> These are the steps I did to link a small ada program with lapack and
> blas libraries which are needed if one uses some of the  the new
> packages such as  Ada.Numerics.Generic_Real_Arrays and its linear
> algebra functions.
>
> Here is the gnatmake command:
>
> $ gnatmake solve.adb -largs -L/usr/lib  -lgnala -llapack -lblas
> gcc -c solve.adb
> gnatbind -x solve.ali
> gnatlink solve.ali -L/usr/lib -lgnala -llapack -lblas
>
> On linux Ubuntu, I used adept_manger to install blas and lapack, then
> after that, added the following symbolic links (which the link above
> would fail otherwise):
>
> su -
> cd /usr/lib
> ln -s liblapack.so.3 liblapack.so
> ln -s libblas.so libblas.so.3
>
> This is the ada program (just to test with, no data in matric to do an
> actual solve)
>
> --------------- solve.adb--------------
> $ cat solve.adb
>  with Ada.Numerics.Generic_Real_Arrays;
>
> procedure solve is
>
>    package myReals is new Ada.Numerics.Generic_Real_Arrays(Float);
>    use myReals;
>
>    nElements: constant integer:=6;
>    A: Real_Matrix(1..nElements,1..nElements):=(others => (others =>
> 0.0));
>    b: Real_Vector(1..nElements):=(Others=>0.0);
>
>    begin
>        b:=solve(A,b);
>
> end solve;
> ------------- solve--------------------
>
> Nasser





^ permalink raw reply	[relevance 7%]

* gnatmake, gnat2007. Linking to lapack and blas using with Ada.Numerics.Generic_Real_Arrays;
@ 2007-08-10 23:34 14% Nasser Abbasi
  2007-08-12  1:01  7% ` Jerry
  0 siblings, 1 reply; 114+ results
From: Nasser Abbasi @ 2007-08-10 23:34 UTC (permalink / raw)


These are the steps I did to link a small ada program with lapack and
blas libraries which are needed if one uses some of the  the new
packages such as  Ada.Numerics.Generic_Real_Arrays and its linear
algebra functions.

Here is the gnatmake command:

$ gnatmake solve.adb -largs -L/usr/lib  -lgnala -llapack -lblas
gcc -c solve.adb
gnatbind -x solve.ali
gnatlink solve.ali -L/usr/lib -lgnala -llapack -lblas

On linux Ubuntu, I used adept_manger to install blas and lapack, then
after that, added the following symbolic links (which the link above
would fail otherwise):

su -
cd /usr/lib
ln -s liblapack.so.3 liblapack.so
ln -s libblas.so libblas.so.3

This is the ada program (just to test with, no data in matric to do an
actual solve)

--------------- solve.adb--------------
$ cat solve.adb
 with Ada.Numerics.Generic_Real_Arrays;

procedure solve is

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

   nElements: constant integer:=6;
   A: Real_Matrix(1..nElements,1..nElements):=(others => (others =>
0.0));
   b: Real_Vector(1..nElements):=(Others=>0.0);

   begin
       b:=solve(A,b);

end solve;
------------- solve--------------------

Nasser




^ permalink raw reply	[relevance 14%]

* Re: GNAT2007: Link error on windows when using Ada.Numerics.Generic_Real_Arrays, SOLVE.
  2007-08-10 10:27 13% GNAT2007: Link error on windows when using Ada.Numerics.Generic_Real_Arrays, SOLVE Nasser Abbasi
@ 2007-08-10 23:02  7% ` Nasser Abbasi
  0 siblings, 0 replies; 114+ results
From: Nasser Abbasi @ 2007-08-10 23:02 UTC (permalink / raw)



"Nasser Abbasi" <nma@12000.org> wrote in message 
news:V3Xui.85757$zz2.14818@newsfe12.phx...
> This in windows XP. I get this link error when gnatmake on this file: (ps. 
> I use cygwin bash shell to invoke commands, easier than DOS, but 
> otherwise, this is windows installation of GNAT2007.)
>
> GNATMAKE GPL 2007 (20070405-41)
> Copyright 1995-2007, Free Software Foundation, Inc.
>
> ----- error.adb---------
> with Ada.Numerics.Generic_Real_Arrays;
>
> procedure error is
>
>   package myReals is new Ada.Numerics.Generic_Real_Arrays(Float);
>   use myReals;
>
>   nElements: constant integer:=6;
>   A: Real_Matrix(1..nElements,1..nElements):=(others => (others => 0.0));
>   b: Real_Vector(1..nElements):=(Others=>0.0);
>
>   begin
>       b:=solve(A,b);
>
> end error;
> ------------------ end error.adb--------------
>
> $ which gnatmake
> /cygdrive/c/GNAT/2007/bin/gnatmake
>
> $ gnatmake error.adb
> gnatbind -x error.ali
> gnatlink error.ali
> .\error.o:error.adb:(.text+0x47c6): undefined reference to `sgetri_'
> .\error.o:error.adb:(.text+0x4dd5): undefined reference to `sgetrf_'
> .\error.o:error.adb:(.text+0x647b): undefined reference to `sgemv_'
> collect2: ld returned 1 exit status
> gnatlink: error when calling c:\GNAT\2007\bin\gcc.exe
> gnatmake: *** link failed.
>
> Nasser
>

Ok, I needed to link explicitly with blas and lapack.  Which I did, and the 
program linked ok.

But I have a question on the link using gnatmake, which I will ask in a new 
post.

Nasser 





^ permalink raw reply	[relevance 7%]

* GNAT2007: Link error on windows when using Ada.Numerics.Generic_Real_Arrays, SOLVE.
@ 2007-08-10 10:27 13% Nasser Abbasi
  2007-08-10 23:02  7% ` Nasser Abbasi
  0 siblings, 1 reply; 114+ results
From: Nasser Abbasi @ 2007-08-10 10:27 UTC (permalink / raw)


This in windows XP. I get this link error when gnatmake on this file: (ps. I 
use cygwin bash shell to invoke commands, easier than DOS, but otherwise, 
this is windows installation of GNAT2007.)

GNATMAKE GPL 2007 (20070405-41)
Copyright 1995-2007, Free Software Foundation, Inc.

----- error.adb---------
with Ada.Numerics.Generic_Real_Arrays;

procedure error is

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

   nElements: constant integer:=6;
   A: Real_Matrix(1..nElements,1..nElements):=(others => (others => 0.0));
   b: Real_Vector(1..nElements):=(Others=>0.0);

   begin
       b:=solve(A,b);

end error;
------------------ end error.adb--------------

$ which gnatmake
/cygdrive/c/GNAT/2007/bin/gnatmake

$ gnatmake error.adb
gnatbind -x error.ali
gnatlink error.ali
.\error.o:error.adb:(.text+0x47c6): undefined reference to `sgetri_'
.\error.o:error.adb:(.text+0x4dd5): undefined reference to `sgetrf_'
.\error.o:error.adb:(.text+0x647b): undefined reference to `sgemv_'
collect2: ld returned 1 exit status
gnatlink: error when calling c:\GNAT\2007\bin\gcc.exe
gnatmake: *** link failed.

Nasser 





^ permalink raw reply	[relevance 13%]

* Re: Ada.Numerics.Generic_Real_Arrays: Problem with Transpose
  2007-08-01  8:46  7%   ` Ken Thomas
  2007-08-01 12:14  7%     ` Jeffrey Creem
@ 2007-08-01 15:14  7%     ` Robert A Duff
  1 sibling, 0 replies; 114+ results
From: Robert A Duff @ 2007-08-01 15:14 UTC (permalink / raw)


Ken Thomas <kst@ecs.soton.ac.uk> writes:

> On Jul 27, 10:52 am, Colin Paul Gloster <Colin_Paul_Glos...@ACM.org>
> wrote:
>> On 2007-07-27, Ken Thomas <k...@ecs.soton.ac.uk> wrote:
>>
>> |----------------------------------------------------------------------|
>> |"[..]                                                                 |
>> |                                                                      |
>> |[..] I have reported it to Adacore.                                   |
>> |                                                                      |
>> |[..]"                                                                 |
>> |----------------------------------------------------------------------|
>>
>> Thanks. Has Ada Core Technologies acknowledged that it will fix it
>> soon? It has a reputation for not giving bug reports which are not
>> part of a paid support contract prompt conclusions.
>
> The GPL edition (2007) only gets limited support :-(
> Ken

Well, as it happens, the bug was fixed in AdaCore's internal
version a few days ago.

- Bob



^ permalink raw reply	[relevance 7%]

* Re: Ada.Numerics.Generic_Real_Arrays: Problem with Transpose
  2007-08-01  8:46  7%   ` Ken Thomas
@ 2007-08-01 12:14  7%     ` Jeffrey Creem
  2007-08-01 15:14  7%     ` Robert A Duff
  1 sibling, 0 replies; 114+ results
From: Jeffrey Creem @ 2007-08-01 12:14 UTC (permalink / raw)


Ken Thomas wrote:
> On Jul 27, 10:52 am, Colin Paul Gloster <Colin_Paul_Glos...@ACM.org>
> wrote:
>> On 2007-07-27, Ken Thomas <k...@ecs.soton.ac.uk> wrote:
>>
>> |----------------------------------------------------------------------|
>> |"[..]                                                                 |
>> |                                                                      |
>> |[..] I have reported it to Adacore.                                   |
>> |                                                                      |
>> |[..]"                                                                 |
>> |----------------------------------------------------------------------|
>>
>> Thanks. Has Ada Core Technologies acknowledged that it will fix it
>> soon? It has a reputation for not giving bug reports which are not
>> part of a paid support contract prompt conclusions.
> 
> The GPL edition (2007) only gets limited support :-(
> Ken
> 

Well, of course there are no wavefronts for the GPL edition to fix bug 
reports but big errors like this are almost always fixed in the next GPL 
release even if they are only submitted via non-supported users.

In general the problem (if there is one) is really just the lack of 
transparency for non-supported users..Not so much the lack of looking at 
the issues.



^ permalink raw reply	[relevance 7%]

* Re: Ada.Numerics.Generic_Real_Arrays: Problem with Transpose
  2007-07-27  9:52  7% ` Colin Paul Gloster
@ 2007-08-01  8:46  7%   ` Ken Thomas
  2007-08-01 12:14  7%     ` Jeffrey Creem
  2007-08-01 15:14  7%     ` Robert A Duff
  0 siblings, 2 replies; 114+ results
From: Ken Thomas @ 2007-08-01  8:46 UTC (permalink / raw)


On Jul 27, 10:52 am, Colin Paul Gloster <Colin_Paul_Glos...@ACM.org>
wrote:
> On 2007-07-27, Ken Thomas <k...@ecs.soton.ac.uk> wrote:
>
> |----------------------------------------------------------------------|
> |"[..]                                                                 |
> |                                                                      |
> |[..] I have reported it to Adacore.                                   |
> |                                                                      |
> |[..]"                                                                 |
> |----------------------------------------------------------------------|
>
> Thanks. Has Ada Core Technologies acknowledged that it will fix it
> soon? It has a reputation for not giving bug reports which are not
> part of a paid support contract prompt conclusions.

The GPL edition (2007) only gets limited support :-(
Ken




^ permalink raw reply	[relevance 7%]

* Re: Ada.Numerics.Generic_Real_Arrays: Problem with Transpose
  2007-07-27  8:59 13% Ada.Numerics.Generic_Real_Arrays: Problem with Transpose Ken Thomas
@ 2007-07-27  9:52  7% ` Colin Paul Gloster
  2007-08-01  8:46  7%   ` Ken Thomas
  0 siblings, 1 reply; 114+ results
From: Colin Paul Gloster @ 2007-07-27  9:52 UTC (permalink / raw)


On 2007-07-27, Ken Thomas <kst@ecs.soton.ac.uk> wrote:

|----------------------------------------------------------------------|
|"[..]                                                                 |
|                                                                      |
|[..] I have reported it to Adacore.                                   |
|                                                                      |
|[..]"                                                                 |
|----------------------------------------------------------------------|

Thanks. Has Ada Core Technologies acknowledged that it will fix it
soon? It has a reputation for not giving bug reports which are not
part of a paid support contract prompt conclusions.



^ permalink raw reply	[relevance 7%]

* Ada.Numerics.Generic_Real_Arrays: Problem with Transpose
@ 2007-07-27  8:59 13% Ken Thomas
  2007-07-27  9:52  7% ` Colin Paul Gloster
  0 siblings, 1 reply; 114+ results
From: Ken Thomas @ 2007-07-27  8:59 UTC (permalink / raw)


There is an error in the transpose function in the library
Ada.Numerics.Generic_Real_Arrays in the GNAT GPL 2007 edition; it
returns the matrix unchanged not the transpose. I am using the windows
version.

I discovered it after getting some strange results in my Finite
Element code, other users should check their code.

A workaround is trivial and I have reported it to Adacore.

In other respects, this library is a valuable contribution for those
involved in numerical computation.

Ken




^ permalink raw reply	[relevance 13%]

* Re: Gnat2007 and Ada.Numerics.Generic_Real_Arrays
  2007-05-25 17:12  6% Gnat2007 and Ada.Numerics.Generic_Real_Arrays Yves Bailly
  2007-05-25 18:47 13% ` Anh Vo
  2007-06-01  2:01 13% ` Anh Vo
@ 2007-06-06  8:19  7% ` Maxim Reznik
  2 siblings, 0 replies; 114+ results
From: Maxim Reznik @ 2007-06-06  8:19 UTC (permalink / raw)


On 25    , 20:12, Yves Bailly <kafka...@laposte.net> wrote:
> /home/yves/Programs/Ada/test_matrix.o: In function `_ada_test_matrix':
> test_matrix.adb:(.text+0x40): undefined reference to
> `ada__numerics__long_real_arrays__Omultiply'

Try to link with libgnala.a (included in gnat-gpl-2007) and lapack
+blas libraries like this:
gnatmake ... -largs -lgnala -llapack -lblas

I've managed to work with matrixes this way under Linux. I installed
lapack and blas from my linux distribution (Gentoo: emerge blas
lacpack). No idea where are this libraries for windows.

--
Maxim Reznik




^ permalink raw reply	[relevance 7%]

* Re: Gnat2007 and Ada.Numerics.Generic_Real_Arrays
  2007-05-29 10:47  7%             ` Yves Bailly
@ 2007-06-01  9:40  7%               ` Ken
  0 siblings, 0 replies; 114+ results
From: Ken @ 2007-06-01  9:40 UTC (permalink / raw)


On May 29, 11:47 am, Yves Bailly <kafka...@laposte.net> wrote:
> Ken wrote:
> > [...]
> > I have looked at the GNAT2007 and Ada.Generic_Real_Arrays. It needs a
> > link to a BLAS/LAPACK library. I have tested it with compiled BLAS/
> > LAPACK with the gnat FORTRAN compiler. Some timing on Windows XP
> > (Intel Core 2CPU): to multiply two matrices of size 500 produced a
> > rate of 1.17 GFlops/sec.
>
> Can you share the switches you used? I tried installing LAPACK using
> the GNU gfortran compiler, but I still get link errors...
>
> Thanks.
>
> YB

The library was built using the FORTRAN Compiler in the MinGW
installation. The compile options were -O4

>From gnatmake, the link options were:

-largs -LW:\d-drive\LAPACK -llapack_WindowsXP -lblas_WindowsXP  -LC:
\MinGW\lib -lg2c


The libraries refer to those created by G77 and we note the need for
some modules from g2c.

I have used both Float and Long_Float in instaniations.

Hope this helps.

Ken




^ permalink raw reply	[relevance 7%]

* Re: Gnat2007 and Ada.Numerics.Generic_Real_Arrays
  2007-05-25 17:12  6% Gnat2007 and Ada.Numerics.Generic_Real_Arrays Yves Bailly
  2007-05-25 18:47 13% ` Anh Vo
@ 2007-06-01  2:01 13% ` Anh Vo
  2007-06-06  8:19  7% ` Maxim Reznik
  2 siblings, 0 replies; 114+ results
From: Anh Vo @ 2007-06-01  2:01 UTC (permalink / raw)


On May 25, 10:12 am, Yves Bailly <kafka...@laposte.net> wrote:
> But when trying to create the executable, I get a link error:
> --8<-----8<-----8<-----8<-----8<-----8<-----8<---
> gnatlink /home/yves/Programs/Ada/test_matrix.ali -o /home/yves/Programs/Ada/test_matrix
> /home/yves/Programs/Ada/test_matrix.o: In function `_ada_test_matrix':
> test_matrix.adb:(.text+0x40): undefined reference to
> `ada__numerics__long_real_arrays__Omultiply'
> --8<-----8<-----8<-----8<-----8<-----8<-----8<---

I had similar problem, undefined reference to `sgetrf_', when using
inverse matrix operation under instantiation of
Ada.Numerics.Generic_Real_Arrays with Float. This problem had been
reported to AdaCore.

AV




^ permalink raw reply	[relevance 13%]

* Re: Gnat2007 and Ada.Numerics.Generic_Real_Arrays
  2007-05-29  8:56  6%           ` Ken
@ 2007-05-29 10:47  7%             ` Yves Bailly
  2007-06-01  9:40  7%               ` Ken
  0 siblings, 1 reply; 114+ results
From: Yves Bailly @ 2007-05-29 10:47 UTC (permalink / raw)


Ken wrote:
> [...]
> I have looked at the GNAT2007 and Ada.Generic_Real_Arrays. It needs a
> link to a BLAS/LAPACK library. I have tested it with compiled BLAS/
> LAPACK with the gnat FORTRAN compiler. Some timing on Windows XP
> (Intel Core 2CPU): to multiply two matrices of size 500 produced a
> rate of 1.17 GFlops/sec.

Can you share the switches you used? I tried installing LAPACK using
the GNU gfortran compiler, but I still get link errors...

Thanks.

YB




^ permalink raw reply	[relevance 7%]

* Re: Gnat2007 and Ada.Numerics.Generic_Real_Arrays
  2007-05-26 10:21  7%         ` Dmitry A. Kazakov
@ 2007-05-29  8:56  6%           ` Ken
  2007-05-29 10:47  7%             ` Yves Bailly
  0 siblings, 1 reply; 114+ results
From: Ken @ 2007-05-29  8:56 UTC (permalink / raw)


On May 26, 11:21 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On Sat, 26 May 2007 11:31:44 +0200, Georg Bauhaus wrote:
> > Dmitry A. Kazakov wrote:
> >> On Fri, 25 May 2007 20:59:58 +0200, Gautier wrote:
>
> >>> This seems to mean that the Lapack library needs to be bound with.
> >>> BTW, a very good thing that Lapack is being used by the new Ada.Numerics.* !
>
> >> BTW, where it is hosted now? The old link to Lapack Ada I once had, does
> >> not work anymore.
>
> > Here's one:
> >http://topo.math.u-psud.fr/~sands/Programs/BLAS/index.html
>
> Thanks
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de

I have looked at the GNAT2007 and Ada.Generic_Real_Arrays. It needs a
link to a BLAS/LAPACK library. I have tested it with compiled BLAS/
LAPACK with the gnat FORTRAN compiler. Some timing on Windows XP
(Intel Core 2CPU): to multiply two matrices of size 500 produced a
rate of 1.17 GFlops/sec.

Some questions
How do you use other blas/lapack for example Intel or atlas?
How do you increase the stack size (I would like to try 1000 by 1000
and I have 2GB of memory)?

Ken Thomas




^ permalink raw reply	[relevance 6%]

* Re: Gnat2007 and Ada.Numerics.Generic_Real_Arrays
  2007-05-26  9:31  7%       ` Georg Bauhaus
  2007-05-26 10:21  7%         ` Dmitry A. Kazakov
@ 2007-05-28 10:19  6%         ` Dirk Craeynest
  1 sibling, 0 replies; 114+ results
From: Dirk Craeynest @ 2007-05-28 10:19 UTC (permalink / raw)


In article <4657fde5$0$23140$9b4e6d93@newsspool1.arcor-online.net>,
Georg Bauhaus  <bauhaus.rm.tsoh@maps.futureapps.de> wrote:
[...]
>Has all public NYU Ada stuff been saved to Ada Belgium
>servers, BTW?

I'm not sure Georg got my e-mailed response, as I had to guess his
real address, hence this follow-up.

In a nutshell: yes, all "public NYU Ada stuff" that was in the
cs.nyu.edu:/pub/gnat directory is still available at
<ftp://ftp.cs.kuleuven.be/pub/Ada-Belgium/mirrors/gnu-ada>.

I refer to my older posting that describes the NYU Ada mirror on the
Ada-Belgium server:
<http://groups.google.be/group/comp.lang.ada/browse_thread/thread/281f51aa0dcc9033/48e99dafe9e3c8b0?hl=nl#48e99dafe9e3c8b0>.

HTH

Dirk
Dirk.Craeynest@cs.kuleuven.be (for Ada-Belgium/-Europe/SIGAda/WG9 mail)

+-------------/  Home: http://www.cs.kuleuven.be/~dirk/ada-belgium
|Ada-Belgium /    FTP: ftp://ftp.cs.kuleuven.be/pub/Ada-Belgium
|on Internet/  E-mail: ada-belgium-board@cs.kuleuven.be
+----------/ Maillist: ada-belgium-info-request@cs.kuleuven.be

*** 12th Intl.Conf.on Reliable Software Technologies - Ada-Europe'2007
*** June 25-29, 2007 * Geneva, Switzerland * http://www.ada-europe.org



^ permalink raw reply	[relevance 6%]

* Re: Gnat2007 and Ada.Numerics.Generic_Real_Arrays
  2007-05-26  9:31  7%       ` Georg Bauhaus
@ 2007-05-26 10:21  7%         ` Dmitry A. Kazakov
  2007-05-29  8:56  6%           ` Ken
  2007-05-28 10:19  6%         ` Dirk Craeynest
  1 sibling, 1 reply; 114+ results
From: Dmitry A. Kazakov @ 2007-05-26 10:21 UTC (permalink / raw)


On Sat, 26 May 2007 11:31:44 +0200, Georg Bauhaus wrote:

> Dmitry A. Kazakov wrote:
>> On Fri, 25 May 2007 20:59:58 +0200, Gautier wrote:
>> 
>>> This seems to mean that the Lapack library needs to be bound with.
>>> BTW, a very good thing that Lapack is being used by the new Ada.Numerics.* !
>> 
>> BTW, where it is hosted now? The old link to Lapack Ada I once had, does
>> not work anymore.
> 
> Here's one:
> http://topo.math.u-psud.fr/~sands/Programs/BLAS/index.html

Thanks

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[relevance 7%]

* Re: Gnat2007 and Ada.Numerics.Generic_Real_Arrays
  2007-05-26  7:53  7%     ` Dmitry A. Kazakov
@ 2007-05-26  9:31  7%       ` Georg Bauhaus
  2007-05-26 10:21  7%         ` Dmitry A. Kazakov
  2007-05-28 10:19  6%         ` Dirk Craeynest
  0 siblings, 2 replies; 114+ results
From: Georg Bauhaus @ 2007-05-26  9:31 UTC (permalink / raw)


Dmitry A. Kazakov wrote:
> On Fri, 25 May 2007 20:59:58 +0200, Gautier wrote:
> 
>> This seems to mean that the Lapack library needs to be bound with.
>> BTW, a very good thing that Lapack is being used by the new Ada.Numerics.* !
> 
> BTW, where it is hosted now? The old link to Lapack Ada I once had, does
> not work anymore.
> 

Here's one:
http://topo.math.u-psud.fr/~sands/Programs/BLAS/index.html

Has all public NYU Ada stuff been saved to Ada Belgium
servers, BTW?



^ permalink raw reply	[relevance 7%]

* Re: Gnat2007 and Ada.Numerics.Generic_Real_Arrays
  2007-05-25 18:59  7%   ` Gautier
@ 2007-05-26  7:53  7%     ` Dmitry A. Kazakov
  2007-05-26  9:31  7%       ` Georg Bauhaus
  0 siblings, 1 reply; 114+ results
From: Dmitry A. Kazakov @ 2007-05-26  7:53 UTC (permalink / raw)


On Fri, 25 May 2007 20:59:58 +0200, Gautier wrote:

> This seems to mean that the Lapack library needs to be bound with.
> BTW, a very good thing that Lapack is being used by the new Ada.Numerics.* !

BTW, where it is hosted now? The old link to Lapack Ada I once had, does
not work anymore.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[relevance 7%]

* Re: Gnat2007 and Ada.Numerics.Generic_Real_Arrays
  2007-05-25 18:47 13% ` Anh Vo
@ 2007-05-25 18:59  7%   ` Gautier
  2007-05-26  7:53  7%     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 114+ results
From: Gautier @ 2007-05-25 18:59 UTC (permalink / raw)


Anh Vo:

> I had similar problem, undefined reference to `sgetrf_', when using
> inverse matrix operation under instantiation of
> Ada.Numerics.Generic_Real_Arrays with Float. This problem had been
> reported to AdaCore.

This seems to mean that the Lapack library needs to be bound with.
BTW, a very good thing that Lapack is being used by the new Ada.Numerics.* !
______________________________________________________________
Gautier         -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[relevance 7%]

* Re: Gnat2007 and Ada.Numerics.Generic_Real_Arrays
  2007-05-25 17:12  6% Gnat2007 and Ada.Numerics.Generic_Real_Arrays Yves Bailly
@ 2007-05-25 18:47 13% ` Anh Vo
  2007-05-25 18:59  7%   ` Gautier
  2007-06-01  2:01 13% ` Anh Vo
  2007-06-06  8:19  7% ` Maxim Reznik
  2 siblings, 1 reply; 114+ results
From: Anh Vo @ 2007-05-25 18:47 UTC (permalink / raw)


On May 25, 10:12 am, Yves Bailly <kafka...@laposte.net> wrote:
> But when trying to create the executable, I get a link error:
> --8<-----8<-----8<-----8<-----8<-----8<-----8<---
> gnatlink /home/yves/Programs/Ada/test_matrix.ali -o /home/yves/Programs/Ada/test_matrix
> /home/yves/Programs/Ada/test_matrix.o: In function `_ada_test_matrix':
> test_matrix.adb:(.text+0x40): undefined reference to
> `ada__numerics__long_real_arrays__Omultiply'
> --8<-----8<-----8<-----8<-----8<-----8<-----8<---

I had similar problem, undefined reference to `sgetrf_', when using
inverse matrix operation under instantiation of
Ada.Numerics.Generic_Real_Arrays with Float. This problem had been
reported to AdaCore.

AV




^ permalink raw reply	[relevance 13%]

* Gnat2007 and Ada.Numerics.Generic_Real_Arrays
@ 2007-05-25 17:12  6% Yves Bailly
  2007-05-25 18:47 13% ` Anh Vo
                   ` (2 more replies)
  0 siblings, 3 replies; 114+ results
From: Yves Bailly @ 2007-05-25 17:12 UTC (permalink / raw)


Hello all,

I just downloaded Gnat2007, then tried this little program:
--8<-----8<-----8<-----8<-----8<-----8<-----8<---
with Ada.Numerics.Long_Real_Arrays;
use Ada.Numerics.Long_Real_Arrays;
procedure Test_Matrix is
   v: Real_Vector(1..3) := (1.0, 2.0, 3.0);
   d: Long_Float := v*v;
begin
   null;
end Test_Matrix;
--8<-----8<-----8<-----8<-----8<-----8<-----8<---

But when trying to create the executable, I get a link error:
--8<-----8<-----8<-----8<-----8<-----8<-----8<---
gnatlink /home/yves/Programs/Ada/test_matrix.ali -o /home/yves/Programs/Ada/test_matrix
/home/yves/Programs/Ada/test_matrix.o: In function `_ada_test_matrix':
test_matrix.adb:(.text+0x40): undefined reference to
`ada__numerics__long_real_arrays__Omultiply'
--8<-----8<-----8<-----8<-----8<-----8<-----8<---

Nothing about those packages in the provided doc... Too bad, I've
been waiting for those packages since they appeared in the RM.
Am I missing something?

Any hint would be much appreciated!

--   Yves Bailly




^ permalink raw reply	[relevance 6%]

* Re: Why does this work? (overloads)
  @ 2007-02-07 20:43  7%   ` Jerry
  0 siblings, 0 replies; 114+ results
From: Jerry @ 2007-02-07 20:43 UTC (permalink / raw)


Grein, Christoph wrote:
> In my vector code, I do not define cross, inner and outer products via
> operator "*" overloading exactly because of these ambiguities.

I thought about doing that, or _not_  implementing the element-by-
element versions. Interestingly, Ada 2005 implements inner and outer
products for you if you use Ada.Numerics.Generic_Real_Arrays or
Ada.Numerics.Generic_Complex_Arrays.




^ permalink raw reply	[relevance 7%]

* Re: How to use Annex G.3 Vectors and Matrices in bindings to C arrays
  2006-11-12  8:45  0% ` Yves Bailly
@ 2006-11-13 10:48  0%   ` Jerry
  0 siblings, 0 replies; 114+ results
From: Jerry @ 2006-11-13 10:48 UTC (permalink / raw)



Yves Bailly wrote:
> Jerry wrote:
> > with arrays which are (sub)typed from the Annex G.3 declarations. For
> > example, here is the declaration from the spec of
> > Ada.Numerics.Generic_Real_Arrays which is GNAT file a-ngrear.ads:
>
> Sorry for this off-topic quesiton, but which GNAT version are you using ?
> I just can't find this file in GNAT-GPL...
>
I should have anticipated this. As I understand it, AdaCore has not put
the source for the new vector-matrix packages out yet. (I am using a
4.2 that someone on the MacAda.org site has provided, and the sources
are not in there.) But I found a nearly-complete set of sources here:
    http://www.martin.dowie.btinternet.co.uk/

> Have you tried:
> type A is array(1..10) of Float;
> pragma Convention(C, A);
>
Please see my reply to the next poster. (However, in GNAT, all arrays
are C-compatible, so the use of this pragma is useful only for
compatibility. I _hope_ I've used it, however.)

> The "pragma Convention" might be enough, at least it was when I did
> some OpenGL programming in Ada, passing Ada vectors or matrices to GL
> functions. It worked like a charm.
>




^ permalink raw reply	[relevance 0%]

* Re: How to use Annex G.3 Vectors and Matrices in bindings to C arrays
  2006-11-12  3:45  4% How to use Annex G.3 Vectors and Matrices in bindings to C arrays Jerry
@ 2006-11-12  8:45  0% ` Yves Bailly
  2006-11-13 10:48  0%   ` Jerry
  0 siblings, 1 reply; 114+ results
From: Yves Bailly @ 2006-11-12  8:45 UTC (permalink / raw)


Jerry wrote:
> with arrays which are (sub)typed from the Annex G.3 declarations. For
> example, here is the declaration from the spec of
> Ada.Numerics.Generic_Real_Arrays which is GNAT file a-ngrear.ads:

Sorry for this off-topic quesiton, but which GNAT version are you using ?
I just can't find this file in GNAT-GPL...
 
>        type Real_Vector is array (Integer range <>) of Real'Base;
> (The Long_Float version, for example, is an instantiation of this
> generic and is named Ada.Numerics.Long_Real_Arrays.)
> 
> So--how do I get objects and subtypes based on the type Real_Vector to
> have aliased components or, how do I get a type that is type-compatible
> with Real_Vector but which has aliased components?
> 
> I wonder if I am incorrect in believing that the binding to C-arrays
> need aliased components. Like I said, the reason for that is a little
> fuzzy to me right now. But I do know that if I remove the aliased
> component requirement from Long_Float_Array_1D the binding will not
> compile.

Have you tried:
type A is array(1..10) of Float;
pragma Convention(C, A);

The "pragma Convention" might be enough, at least it was when I did
some OpenGL programming in Ada, passing Ada vectors or matrices to GL
functions. It worked like a charm.

> I also wonder if it is generally possible to rationalize other bindings
> which involve connecting to C arrays by using (sub)types of the Annex
> G.3 vector and matrix types. If not, that would seem to make the Annex
> G.3 features useless whenever C array bindings are needed.

I can't try (as said, I don't have those Annex G.3-related files), but
maybe this works:
type C_Real_Vector is new Real_Vector;
pragma Convention(C, C_Real_Vector);
Though I wonder how the constraint will be handled...
 
Regards,

-- 
(o< | Yves Bailly  : http://kafka-fr.net   | -o)
//\ | Linux Dijon  : http://www.coagul.org | //\
\_/ |                                      | \_/`



^ permalink raw reply	[relevance 0%]

* How to use Annex G.3 Vectors and Matrices in bindings to C arrays
@ 2006-11-12  3:45  4% Jerry
  2006-11-12  8:45  0% ` Yves Bailly
  0 siblings, 1 reply; 114+ results
From: Jerry @ 2006-11-12  3:45 UTC (permalink / raw)


A while back, I wrote a binding for a C program (PLplot) in which I
have a declaration thus:

    type Long_Float_Array_1D is array (Integer range <>) of aliased
Long_Float;

and similarly for a 2D array. As I understand it (I'm a little unclear
about this even though I did most of the work myself, help from this
list notwithstanding), the aliasing of the array components was
required in order to cause the pass-by-reference to the C code to work
correctly.

Now, I am working with the Annex G.3.1 and G.3.2 features which are new
to Ada 2005, "Vector and Matrix Manipulation." I have those features
working correctly on their own; however, it only makes sense to
rationalize all 1D and 2D numerical arrays against the Annex G.3
features. Thus, I am looking into getting my PLplot binding to work
with arrays which are (sub)typed from the Annex G.3 declarations. For
example, here is the declaration from the spec of
Ada.Numerics.Generic_Real_Arrays which is GNAT file a-ngrear.ads:

       type Real_Vector is array (Integer range <>) of Real'Base;

(The Long_Float version, for example, is an instantiation of this
generic and is named Ada.Numerics.Long_Real_Arrays.)

So--how do I get objects and subtypes based on the type Real_Vector to
have aliased components or, how do I get a type that is type-compatible
with Real_Vector but which has aliased components?

I wonder if I am incorrect in believing that the binding to C-arrays
need aliased components. Like I said, the reason for that is a little
fuzzy to me right now. But I do know that if I remove the aliased
component requirement from Long_Float_Array_1D the binding will not
compile.

I also wonder if it is generally possible to rationalize other bindings
which involve connecting to C arrays by using (sub)types of the Annex
G.3 vector and matrix types. If not, that would seem to make the Annex
G.3 features useless whenever C array bindings are needed.

I next want to look into binding to the GNU Scientific Library (GS) and
hope to be able to derive all the 1D and 2D arrays from those specified
in Annex G.3.

Thanks as always,
Jerry




^ permalink raw reply	[relevance 4%]

* Re: Two generic families: I'm confused by error msg
  2004-11-03  5:40  3% Two generic families: I'm confused by error msg John Woodruff
@ 2004-11-03  8:46  0% ` Dmitry A. Kazakov
  0 siblings, 0 replies; 114+ results
From: Dmitry A. Kazakov @ 2004-11-03  8:46 UTC (permalink / raw)


On 2 Nov 2004 21:40:29 -0800, John Woodruff wrote:

> I'm puzzled by an Ada error.  The error arises in the attached
> program, which uses two different (parent-child) pairs of generic
> packages.  And the error seems to indicate a hard-for-me-to-understand
> issue of visibility.
> 
> The first two packages (numeric_io and it's child *.matrix_io) do some
> IO on vectors and matrices of floating numbers.  Just about like the
> new Ada.Numerics.Generic_Real_Arrays.Generic_IO.
> 
> Two more packages (name_io and its child *.matrix_name_io) add
> services that parse name-directed input for object-oriented
> applications.  This pair uses instances of numeric_io, so that vectors
> are the same regardless of which services are invoked.
> 
> It all works fine, and I'm in the final stages of preparing this to
> share.  Maybe on adaworld or adapower if they'll have me....
> 
> BUT
> 
> Numeric_io defines a subtype "real" that is just the actual type given
> for its argument.  That's how the two children manage to work on the
> same types (they are children of different, unrelated, parents).
> 
> So along comes the client (I named it "Unreal" in this exhibit). It
> laces the two generic families together, and it works perfectly  IF and
> ONLY IF it *happens* to use the identifier "Real" somewhere.  This
> client does not need to declare any *usage* of the subtype "Real", nor
> use it in instantiating the generics.
> 
> Unfortunately, poor client has no way of knowing he needs to declare
> "real".  And I'm not sure what is the language-law that connects the
> type Scalar_IO.Real in the generic actual package with the subtype
> identifier Real in the client.
> 
> Can someone help me make sense of this?  Can someone suggest a way to
> rephrase these relationships so I don't require the client to "say the
> magic word"?
> 
> <<< gnatchop the stuff after this line to see the puzzle >>>
> 
> generic
>    type Floating_Type is digits <> ;
> package Numeric_Io is
>    subtype Real is Floating_Type ;
> end Numeric_Io ;
> 
> 
> generic
>    type Vector_Ix is  (<>) ;
>    type Vector is array (Vector_Ix range <>) of Real ;
> package Numeric_Io.Matrix_IO is
> end Numeric_Io.Matrix_IO ;
> 
> with Numeric_Io;
> generic
>    type Floating_Type is digits <> ;
>    with package Scalar_Io is new Numeric_Io (Floating_Type) ;
> package Name_Io is
> end Name_Io;
> 
> with Numeric_Io.Matrix_Io ;
> generic
>    type Vector_Ix is  (<>) ;
>    type Vector is array (Vector_Ix range <>) of Scalar_Io.Real ;
>    with package Matrix_Io is new Scalar_Io.Matrix_Io
>      (Vector_Ix, Vector) ;
> package Name_Io.Matrix_name_IO is
> end Name_Io.Matrix_name_IO ;

Why do not you do it as:

with Numeric_Io.Matrix_Io ;
generic
   with package Matrix_Io is new Scalar_Io.Matrix_Io (<>);
package Name_Io.Matrix_name_IO is

Here you can refer the actual types of Matrix_IO instantiation as
Matrix_IO.Vector_Ix and Matrix_IO.Vector. This would also make
instantiations easier.

> with Numeric_Io.Matrix_Io ;
> with Name_Io.Matrix_Name_Io ;
> 
> procedure Unreal is
>    type Unreal is digits 6 ;
>    
> --------------------------------------------------------------------------
> -- If this line "subtype Real is Unreal"  is ABSENT, then error at line 26:
> -- Component subtype of actual does not match that of formal "Vector" 
> --------------------------------------------------------------------------
>    subtype Real is Unreal;
>    
>    type Vector is array (Integer range <>) of Unreal ;
> 
>    package Scalar_IO is new Numeric_IO (Unreal) ;
> 
>    package Matrix_IO is new Scalar_IO.Matrix_IO
>      (Vector_Ix  => Integer,
>       Vector     => Vector);
> 
>    package Nio is new Name_Io (Floating_Type => Unreal,
>                                Scalar_Io     => Scalar_IO);
> 
>    package Mat_IO is new Nio.Matrix_Name_IO
>      (Vector_Ix  => Integer,
>       Vector     => Vector,   -- the error is here
>       Matrix_Io  => Matrix_IO) ;

Yes, I saw that problem too and many times. To me it looks like a compiler
bug, but wait what our language lawyers will say.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[relevance 0%]

* Two generic families: I'm confused by error msg
@ 2004-11-03  5:40  3% John Woodruff
  2004-11-03  8:46  0% ` Dmitry A. Kazakov
  0 siblings, 1 reply; 114+ results
From: John Woodruff @ 2004-11-03  5:40 UTC (permalink / raw)


I'm puzzled by an Ada error.  The error arises in the attached
program, which uses two different (parent-child) pairs of generic
packages.  And the error seems to indicate a hard-for-me-to-understand
issue of visibility.

The first two packages (numeric_io and it's child *.matrix_io) do some
IO on vectors and matrices of floating numbers.  Just about like the
new Ada.Numerics.Generic_Real_Arrays.Generic_IO.

Two more packages (name_io and its child *.matrix_name_io) add
services that parse name-directed input for object-oriented
applications.  This pair uses instances of numeric_io, so that vectors
are the same regardless of which services are invoked.

It all works fine, and I'm in the final stages of preparing this to
share.  Maybe on adaworld or adapower if they'll have me....

BUT

Numeric_io defines a subtype "real" that is just the actual type given
for its argument.  That's how the two children manage to work on the
same types (they are children of different, unrelated, parents).

So along comes the client (I named it "Unreal" in this exhibit). It
laces the two generic families together, and it works perfectly  IF and
ONLY IF it *happens* to use the identifier "Real" somewhere.  This
client does not need to declare any *usage* of the subtype "Real", nor
use it in instantiating the generics.

Unfortunately, poor client has no way of knowing he needs to declare
"real".  And I'm not sure what is the language-law that connects the
type Scalar_IO.Real in the generic actual package with the subtype
identifier Real in the client.

Can someone help me make sense of this?  Can someone suggest a way to
rephrase these relationships so I don't require the client to "say the
magic word"?

<<< gnatchop the stuff after this line to see the puzzle >>>

generic
   type Floating_Type is digits <> ;
package Numeric_Io is
   subtype Real is Floating_Type ;
end Numeric_Io ;


generic
   type Vector_Ix is  (<>) ;
   type Vector is array (Vector_Ix range <>) of Real ;
package Numeric_Io.Matrix_IO is
end Numeric_Io.Matrix_IO ;

with Numeric_Io;
generic
   type Floating_Type is digits <> ;
   with package Scalar_Io is new Numeric_Io (Floating_Type) ;
package Name_Io is
end Name_Io;

with Numeric_Io.Matrix_Io ;
generic
   type Vector_Ix is  (<>) ;
   type Vector is array (Vector_Ix range <>) of Scalar_Io.Real ;
   with package Matrix_Io is new Scalar_Io.Matrix_Io
     (Vector_Ix, Vector) ;
package Name_Io.Matrix_name_IO is
end Name_Io.Matrix_name_IO ;


with Numeric_Io.Matrix_Io ;
with Name_Io.Matrix_Name_Io ;

procedure Unreal is
   type Unreal is digits 6 ;
   
--------------------------------------------------------------------------
-- If this line "subtype Real is Unreal"  is ABSENT, then error at line 26:
-- Component subtype of actual does not match that of formal "Vector" 
--------------------------------------------------------------------------
   subtype Real is Unreal;
   
   type Vector is array (Integer range <>) of Unreal ;

   package Scalar_IO is new Numeric_IO (Unreal) ;

   package Matrix_IO is new Scalar_IO.Matrix_IO
     (Vector_Ix  => Integer,
      Vector     => Vector);

   package Nio is new Name_Io (Floating_Type => Unreal,
                               Scalar_Io     => Scalar_IO);

   package Mat_IO is new Nio.Matrix_Name_IO
     (Vector_Ix  => Integer,
      Vector     => Vector,   -- the error is here
      Matrix_Io  => Matrix_IO) ;

begin
   null ;
end Unreal ;



^ permalink raw reply	[relevance 3%]

* Re: Thank you Matthew Heaney!
  @ 2004-11-02 18:27  6%     ` Martin Dowie
  0 siblings, 0 replies; 114+ results
From: Martin Dowie @ 2004-11-02 18:27 UTC (permalink / raw)


"Marius Amado Alves" <amado.alves@netcabo.pt> wrote in message 
news:mailman.76.1099405387.10401.comp.lang.ada@ada-france.org...
> Matthew, if Ada.Numerics_Generic_Real_Arrays is based on Ada.Containers, 
> then by the unwritten laws of generic instantiation you are an author of 
> Ada.Numerics_Generic_Real_Arrays. Next, world domination :-)

Sorry - there are no containers in Ada.Numerics.Generic_Real_Arrays... :-) 





^ permalink raw reply	[relevance 6%]

* Re: First Ada0Y Package for GNAT
  @ 2004-04-21  8:12  5%   ` Martin Dowie
  0 siblings, 0 replies; 114+ results
From: Martin Dowie @ 2004-04-21  8:12 UTC (permalink / raw)


"Martin Dowie" <martin.dowie@btopenworld.com> wrote in message > <shameless_plug>
> Which is great if you have gcc 3.5 but if you are a mere mortal
> and living with 3.15p you can still get Ada.Directories @
> http://www.martin.dowie.btinternet.co.uk/
> </shameless_plug>

A quick follow up to those that want to use "Ada.Directories" and
not "Ada0Y.Directories" (as downloaded).

1. Edit each file and change each reference of "Ada0Y" to "Ada".

2. Copy the files to the predefined GNAT libraries area, probably:
C:\GNAT\lib\gcc-lib\pentium-mingw32msv\2.8.1\adainclude

3. Change the file names to:
a-direct.ads/.adb
a-dirinf.ads/.adb
a-dirite.ads/.adb
a-diwiin.ads/.adb

4. Compile the files using the "-a" option

5. Use "Ada.Directories" in your 3.15p code!

If I ever get a spare hour again, I'll .zip up a version like
this (this is actually how I use it myself and
Ada.Numerics.Generic_Real_Arrays [AI-296] actually ;-).

Cheers

-- Martin



^ permalink raw reply	[relevance 5%]

Results 1-114 of 114 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2004-04-18 17:57     First Ada0Y Package for GNAT Martin Krischik
2004-04-19 20:18     ` Martin Dowie
2004-04-21  8:12  5%   ` Martin Dowie
2004-10-30  2:07     Thank you Matthew Heaney! Steve
2004-10-30  4:31     ` Matthew Heaney
2004-11-02 11:55       ` Marius Amado Alves
2004-11-02 18:27  6%     ` Martin Dowie
2004-11-03  5:40  3% Two generic families: I'm confused by error msg John Woodruff
2004-11-03  8:46  0% ` Dmitry A. Kazakov
2006-11-12  3:45  4% How to use Annex G.3 Vectors and Matrices in bindings to C arrays Jerry
2006-11-12  8:45  0% ` Yves Bailly
2006-11-13 10:48  0%   ` Jerry
2007-02-07  7:07     Why does this work? (overloads) Jerry
2007-02-07  7:26     ` AW: " Grein, Christoph (Fa. ESG)
2007-02-07 20:43  7%   ` Jerry
2007-05-25 17:12  6% Gnat2007 and Ada.Numerics.Generic_Real_Arrays Yves Bailly
2007-05-25 18:47 13% ` Anh Vo
2007-05-25 18:59  7%   ` Gautier
2007-05-26  7:53  7%     ` Dmitry A. Kazakov
2007-05-26  9:31  7%       ` Georg Bauhaus
2007-05-26 10:21  7%         ` Dmitry A. Kazakov
2007-05-29  8:56  6%           ` Ken
2007-05-29 10:47  7%             ` Yves Bailly
2007-06-01  9:40  7%               ` Ken
2007-05-28 10:19  6%         ` Dirk Craeynest
2007-06-01  2:01 13% ` Anh Vo
2007-06-06  8:19  7% ` Maxim Reznik
2007-07-27  8:59 13% Ada.Numerics.Generic_Real_Arrays: Problem with Transpose Ken Thomas
2007-07-27  9:52  7% ` Colin Paul Gloster
2007-08-01  8:46  7%   ` Ken Thomas
2007-08-01 12:14  7%     ` Jeffrey Creem
2007-08-01 15:14  7%     ` Robert A Duff
2007-08-10 10:27 13% GNAT2007: Link error on windows when using Ada.Numerics.Generic_Real_Arrays, SOLVE Nasser Abbasi
2007-08-10 23:02  7% ` Nasser Abbasi
2007-08-10 23:34 14% gnatmake, gnat2007. Linking to lapack and blas using with Ada.Numerics.Generic_Real_Arrays; Nasser Abbasi
2007-08-12  1:01  7% ` Jerry
2007-08-12  9:53  6%   ` Marc Enzmann
2007-08-16  3:42     Interested about number crunching in Ada holst
2007-08-16 11:17     ` anon
2007-08-16 18:59  6%   ` Gautier
2007-08-17  4:44  0%     ` anon
2008-04-17 13:16  6% Symmetric matrices only! amado.alves
2008-04-17 15:25  0% ` Adam Beneschan
2008-04-17 16:55  0%   ` Dmitry A. Kazakov
2008-04-18  1:34  0% ` smsomething
2008-04-18  4:30  0% ` Gautier
2008-04-18  9:40  0%   ` Ken Thomas
2008-08-06 13:32     Larger matrices amado.alves
2008-08-06 14:29     ` Georg Bauhaus
2008-08-06 15:01       ` amado.alves
2008-08-06 17:29         ` amado.alves
2008-08-06 18:44           ` Jeffrey R. Carter
2008-08-06 19:12             ` amado.alves
2008-08-06 23:33               ` amado.alves
2008-08-07  6:30                 ` Georg Bauhaus
2008-08-07  8:01                   ` amado.alves
2008-08-07 19:13                     ` Jeffrey R. Carter
2008-08-08  9:59                       ` amado.alves
2008-08-08 11:35                         ` Georg Bauhaus
2008-08-08 12:11  5%                       ` Dmitry A. Kazakov
2008-08-08 14:11  0%                         ` Georg Bauhaus
2008-08-08 14:36  7%                           ` Dmitry A. Kazakov
2008-08-08 15:40  0%                             ` Georg Bauhaus
2008-08-08 16:37  0%                               ` Dmitry A. Kazakov
2008-11-01 17:47  7% Generic_Roots John B. Matthews
2008-11-07  1:20  0% ` Generic_Roots Randy Brukardt
2008-11-11 21:43 14% Linking Error when using Ada.Numerics.Generic_Real_Arrays package AAFellow
2008-11-11 22:27  7% ` Jeffrey R. Carter
2008-11-12  6:15  7%   ` christoph.grein
2008-11-13 14:36  7%   ` Samuel Tardieu
2009-05-12 16:38     ANN: miscellaneous Math routines, GPL'd johnscpg
2009-05-12 21:02     ` lanceboyle
2009-05-13  9:25       ` johnscpg
2009-05-13 11:52  7%     ` gautier_niouzes
2009-05-13 13:43  0%       ` johnscpg
2009-07-16 19:41     Randomness tests Gautier write-only
2009-07-17 10:58     ` Nicholas Paul Collin Gloucester
2009-07-17 20:41  5%   ` Gautier write-only
2010-02-22  9:08     Does ada have a sscanf equivalent? J.s
2010-02-22 19:48     ` jpwoodruff
2010-02-22 23:11       ` Jerry
2010-02-23  2:11  4%     ` jpwoodruff
2010-07-24 11:57     Interfacing Ada with C Ada novice
2010-07-24 16:38  5% ` Simon Wright
2010-07-24 17:58       ` Ada novice
2010-07-25  8:29         ` Simon Wright
2010-07-25 12:21           ` Ada novice
2010-07-25 23:21             ` Simon Wright
     [not found]               ` <da987804-3948-4871-ab52-4a8e95f06d44@k39g2000yqb.googlegroups.com>
2010-07-26 19:46                 ` Simon Wright
2010-07-28 22:26  7%               ` Simon Wright
2010-08-01 10:47                     ` John B. Matthews
2010-08-01 17:08                       ` Simon Wright
2010-08-02  1:08                         ` John B. Matthews
2010-08-02 16:36                           ` Simon Wright
2010-08-02 16:55                             ` Ada novice
2010-08-05  9:14                               ` Ada novice
2010-08-05 13:23                                 ` John B. Matthews
2010-08-05 13:57                                   ` sjw
2010-08-05 17:24                                     ` Ada novice
2010-08-05 17:59                                       ` Jeffrey Carter
2010-08-05 20:25  6%                                     ` Simon Wright
2010-08-10 21:38     ANN: Ada 2005 Math Extensions, 20100810 release Simon Wright
2010-08-11 21:38  9% ` Simon Wright
2010-08-12  5:57  0%   ` Dmitry A. Kazakov
2010-08-12 19:45  6%     ` Simon Wright
2010-08-13  6:27  0%       ` Dmitry A. Kazakov
2010-08-12 10:36  0%   ` Stephen Leake
2010-08-12 12:48  9%     ` sjw
2010-08-14  1:05  9%       ` Stephen Leake
2010-08-14 16:26  0%         ` Simon Wright
2010-08-11 14:44  6% Generic_Roots John B. Matthews
2010-08-29  8:50     heap size exceeded for large matrices John Raymond Dore
2010-08-29  9:51  5% ` Yannick Duchêne (Hibou57)
2010-08-29 10:42  0%   ` Simon Wright
2010-08-29 15:33  0%     ` John Raymond Dore
2010-12-04  6:32     Large arrays passed to arithmetic operators overflows GNAT stack Jerry
2010-12-04 14:17     ` Peter C. Chapin
2010-12-05  1:22  5%   ` Jerry
2010-12-06 21:03  9% How to include vector operators? tolkamp
2010-12-06 21:37  6% ` Adam Beneschan
2010-12-07 11:11  0%   ` tolkamp
2010-12-07  2:53  0% ` Gautier write-only
2011-02-21 18:43     Ann: Mathpaqs, release Feb. 2011 Gautier write-only
2011-02-21 23:59  6% ` Nasser M. Abbasi
2011-03-27  1:31     on using array index, vectorized operation Nasser M. Abbasi
2011-03-27 20:01     ` Cyrille
2011-03-27 20:44       ` Nasser M. Abbasi
2011-03-27 22:09         ` Phil Clayton
2011-03-27 22:23           ` Nasser M. Abbasi
2011-03-29  2:50  8%         ` Randy Brukardt
2011-03-29  4:55  0%           ` Nasser M. Abbasi
2011-05-27 20:50     Interfacing Ada multidimensional arrays with Fortran David Sauvage
2011-05-28  9:41  6% ` Simon Wright
2011-05-28 16:45       ` Simon Wright
2011-06-09  7:55  6%     ` David Sauvage
2011-07-18  8:47  8% Incorrect error? ldries46
2011-07-18  9:45  5% ` stefan-lucks
2011-07-18 10:40  0%   ` AdaMagica
2011-07-18 12:39  0%     ` Dmitry A. Kazakov
2011-07-18 12:45  0%     ` stefan-lucks
2011-07-18 10:39  8% ` Nicholas Collin Paul de Glouceſter
2011-07-18 15:58  0% ` Adam Beneschan
2011-07-25 17:36  7% Eigenvalues to find roots of polynomials marius63
2011-07-26  6:21     ` John B. Matthews
2011-07-26 15:40  7%   ` marius63
2012-06-30  2:40  7% Reason for elements of 'ada.numerics.generic_real_arrays' real_vector and real_matrix types not being aliased ? rodakay
2012-09-17 13:37  7% problem with Real_Matrix*Real_Matrix reinkor
2012-09-17 17:01  0% ` Niklas Holsti
2012-12-27 18:48  5% A thicker binding for Lapack jpwoodruff
2017-05-08 15:53     Question about sets and expression reinert
2017-05-08 19:00     ` Simon Wright
2017-05-09  3:58       ` reinert
2017-05-09  5:48  7%     ` reinert
2017-06-06 11:47     Arrays in Ada 2012 Anatoly Chernyshev
2017-06-18  2:14     ` Arrays in Ada 2020 Ivan Levashev
2017-06-18  3:00       ` Nasser M. Abbasi
2017-06-18 12:06  6%     ` Robert Eachus
2017-06-18 10:34     Help needed - "Storage_Error stack overflow or erroneous memory access" reinert
2017-06-18 10:41     ` Simon Clubley
2017-06-18 12:00       ` reinert
2017-06-18 12:24         ` Egil H H
2017-06-18 14:58           ` Simon Clubley
2017-06-18 15:44             ` reinert
2017-06-18 18:04               ` reinert
2017-06-19  4:53  6%             ` reinert
2017-11-24 11:42     How to access an array using two different indexing schemes Jerry
2017-11-24 17:37  7% ` A. Cervetti
2017-11-24 21:48  0%   ` Jerry
2017-11-28  1:25  0%   ` Randy Brukardt
2018-02-17 12:55     GNAT can't vectorize Real_Matrix multiplication from Ada.Numerics.Real_Arrays. What a surprise! Bojan Bozovic
2018-02-18  1:51     ` Bojan Bozovic
2018-02-18 10:35  7%   ` Jeffrey R. Carter
2018-02-18 12:05         ` Bojan Bozovic
2018-02-18 13:31  6%       ` Jeffrey R. Carter
2018-02-18 19:38  0%         ` Bojan Bozovic
2018-02-18 21:48               ` Nasser M. Abbasi
2018-02-18 22:50  5%             ` Bojan Bozovic
2018-02-25 12:30     64-bit unsigned integer? MM
2018-02-25 16:36     ` Anh Vo
2018-02-25 17:31       ` MM
2018-02-26 23:19         ` Randy Brukardt
2018-02-28 10:17           ` Paul Rubin
2018-02-28 23:20             ` Randy Brukardt
2018-03-01  5:47               ` Paul Rubin
2018-03-01  8:16                 ` Niklas Holsti
2018-03-01  8:35  6%               ` Simon Wright
2018-03-13 16:39     Mathpaqs release 13-Mar-2018 gautier_niouzes
2018-03-14 14:54     ` Vincent D.
2018-03-16 17:59  5%   ` gautier_niouzes
2018-04-06 13:22  7% Generic library design Marius Amado-Alves
2019-05-30 10:26  7% old problem Gilbert Gosseyn
2019-05-30 17:08  0% ` Anh Vo
2019-05-31  1:04  0% ` Keith Thompson
2019-05-31 12:37  8% ` Simon Wright
2019-07-22  4:38     The answer to "Can Ada replace FORTRAN for numerical computation? Nasser M. Abbasi
2019-07-23  1:35  6% ` Brad Moore
2020-06-05 14:35     generic with function procedure Gilbert Gosseyn
2020-06-05 14:52  7% ` gautier_niouzes
2020-06-05 15:45  0%   ` Gilbert Gosseyn
2023-01-22 21:34     Real_Arrays on heap with overloaded operators and clean syntax Jim Paloander
2023-01-22 21:56     ` Joakim Strandberg
2023-01-22 22:07       ` Jim Paloander
2023-01-22 22:42         ` Joakim Strandberg
2023-01-22 22:49           ` Jim Paloander
2023-01-22 23:14  7%         ` Gautier write-only address
2023-01-23  1:14  7%           ` Leo Brewin
2023-01-23  6:01  0%             ` Jim Paloander

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