From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:ac8:a45:: with SMTP id f5mr25680969qti.116.1591638157489; Mon, 08 Jun 2020 10:42:37 -0700 (PDT) X-Received: by 2002:a05:6830:2303:: with SMTP id u3mr16869236ote.147.1591638157242; Mon, 08 Jun 2020 10:42:37 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 8 Jun 2020 10:42:36 -0700 (PDT) In-Reply-To: <6c2c0e35-af07-4169-8be5-464ec7fd0fd5@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=146.5.2.231; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 146.5.2.231 References: <6c2c0e35-af07-4169-8be5-464ec7fd0fd5@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: GNAT vs Matlab - operation on multidimensional complex matrices From: Shark8 Injection-Date: Mon, 08 Jun 2020 17:42:37 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:59014 Date: 2020-06-08T10:42:36-07:00 List-Id: Cleaning out my computer, I found this working-file; it might be of interesti to you -- it shows "going all-in" with Generics: -------------------------------------------------------------- With Ada.Real_Time, Ada.Containers.Indefinite_Holders, Ada.Numerics.Long_Complex_Types, Ada.Exceptions, Ada.Text_IO.Complex_IO; Procedure Demo is package TIO renames Ada.Text_IO; package CTIO is new TIO.Complex_IO(Ada.Numerics.Long_Complex_Types); subtype mReal is Long_Float; subtype Complex is Ada.Numerics.Long_Complex_Types.Complex; NumIteration : constant := 1_000; NumChannels : constant := 64; NumRanges : constant := 400; NumAngles : constant := 30; Type Channel is range 1..NumChannels; Type Angle is range 1..NumAngles; Type Range_T is range 1..NumRanges; type tCubeReal is array (Channel, Angle, Range_T) of mReal; type tCubeComplex is array (Channel, Angle, Range_T) of Complex; Generic Type T is private; Type IndexA is (<>); Type IndexB is (<>); Type IndexC is (<>); Type Cubic is Array(IndexA, IndexB, indexC) of T; Zero : in T; with Function "+"(Left, Right: T) return T is <>; Function Summation( Input : Cubic ) return T with Inline; Function Summation( Input : Cubic ) return T is Begin Return Result : T := Zero do For A in IndexA loop For B in IndexB loop For C in IndexC loop Result:= Result + Input(A, B, C); End loop; End loop; End loop; End return; End Summation; Generic Type Element is private; Type Cubic is array (Channel, Angle, Range_T) of Element; Zero : In Element; with Function "+"(Left, Right: Element) return Element is <>; Procedure Timing_Harness(Mtx : in Cubic; S: out Element; Iterations : in Positive:= 1); Procedure Timing_Harness(Mtx : in Cubic; S: out Element; Iterations : in Positive:= 1) is Function Sum is new Summation(Element, Channel, Angle, Range_T, Cubic, Zero); Use Ada.Real_Time; Start : Time renames Clock; Begin For Count in 1..Iterations Loop S := Sum( Mtx ); End loop; METRICS: Declare Execution_Time : Constant Time_Span:= Clock - Start; Execution_Image : Constant String:= Duration'Image(To_Duration(Execution_Time)); T : Constant mReal := mReal(To_Duration(Execution_Time))/mReal(NumIteration); Begin TIO.New_Line; TIO.Put_Line("Computation time:" & Execution_Image ); TIO.Put_Line("Computation time per iteration:" & mReal'Image(T)); End METRICS; End Timing_Harness; Function Image( Input : mReal ) return string renames mReal'Image; Function Image( Input : Complex ) return string is ('(' & mReal'Image(Input.Re) & ", " & mReal'Image(Input.Im) & ')'); Generic Type T is private; Type IndexA is (<>); Type IndexB is (<>); Type IndexC is (<>); Type Cubic is Array(IndexA, IndexB, indexC) of T; Default : in T; Package Test_Data is Type Access_Cubic is not null access all Cubic; Access_Data : Constant Access_Cubic := new Cubic'(others => (others => (others => Default))); Data : Cubic renames Access_Data.all; End Test_Data; Generic Type Element is private; Type Cube_Array is array (Channel, Angle, Range_T) of Element; Default, Zero : in Element; Test_Name : in String; with Function "+"(Left, Right: Element) return Element is <>; with Function Image( Input : Element ) return string is <>; Procedure TEST; Procedure TEST is Package Test_Set is new Test_Data( T => Element, IndexA => Channel, IndexB => Angle, IndexC => Range_T, Cubic => Cube_Array, Default => Default ); procedure SpeedSum is new Timing_Harness( Element => Element, Cubic => Cube_Array, Zero => Zero, "+" => TEST."+" ); Cube : Cube_Array renames Test_Set.Data; Result : Element; Begin TIO.Put_Line(Test_Name & " cube"); TIO.Put_Line(Test_Name & " type size is:" & Integer'Image(Element'Size)); SpeedSum( Mtx => Cube, S => Result, Iterations => NumIteration ); TIO.Put_Line("Sum is:" & Image(Result)); End TEST; Begin REAL_CUBE_TEST: Declare Procedure Do_Test is new Test( Element => mReal, Cube_Array => tCubeReal, Default => 1.0, Zero => 0.0, Test_Name => "Real" ); Begin Do_Test; End REAL_CUBE_TEST; TIO.Put_Line( (1..20 => '-') ); -- Separator. COMPLEX_CUBE_TEST: Declare Procedure Do_Test is new Test( "+" => Ada.Numerics.Long_Complex_Types."+", Element => Complex, Cube_Array => tCubeComplex, Default => (Re => 1.0, Im => 1.0), Zero => (Re => 0.0, Im => 0.0), Test_Name => "Complex" ); Begin Do_Test; End COMPLEX_CUBE_TEST; TIO.Put_Line( (1..20 => '-') ); -- Separator. Ada.Text_IO.Put_Line( "Done." ); End Demo;