Commit a4935dea by Geert Bosch Committed by Arnaud Charlet

a-ngrear.adb ("abs"): Adjust for modified L2_Norm generic

2011-10-13  Geert Bosch  <bosch@adacore.com>

	* a-ngrear.adb ("abs"): Adjust for modified L2_Norm generic
	* s-gearop.ads (L2_Norm): Change profile to be suitable for
	Complex_Vector
	* s-gearop.adb (L2_Norm): Reimplement using direct definition,
	not inner product

From-SVN: r179908
parent 3e7302c3
2011-10-13 Geert Bosch <bosch@adacore.com>
* a-ngrear.adb ("abs"): Adjust for modified L2_Norm generic
* s-gearop.ads (L2_Norm): Change profile to be suitable for
Complex_Vector
* s-gearop.adb (L2_Norm): Reimplement using direct definition,
not inner product
2011-10-13 Robert Dewar <dewar@adacore.com> 2011-10-13 Robert Dewar <dewar@adacore.com>
* exp_ch5.adb, sem_ch3.adb, impunit.adb, impunit.ads, sem_type.adb, * exp_ch5.adb, sem_ch3.adb, impunit.adb, impunit.ads, sem_type.adb,
......
...@@ -356,10 +356,14 @@ package body Ada.Numerics.Generic_Real_Arrays is ...@@ -356,10 +356,14 @@ package body Ada.Numerics.Generic_Real_Arrays is
function "abs" is new function "abs" is new
L2_Norm L2_Norm
(Scalar => Real'Base, (X_Scalar => Real'Base,
Vector => Real_Vector, Result_Real => Real'Base,
Inner_Product => "*", X_Vector => Real_Vector,
Sqrt => Sqrt); "abs" => "+");
-- While the L2_Norm by definition uses the absolute values of the
-- elements of X_Vector, for real values the subsequent squaring
-- makes this unnecessary, so we substitute the "+" identity function
-- instead.
function "abs" is new function "abs" is new
Vector_Elementwise_Operation Vector_Elementwise_Operation
......
...@@ -336,9 +336,14 @@ package body System.Generic_Array_Operations is ...@@ -336,9 +336,14 @@ package body System.Generic_Array_Operations is
-- L2_Norm -- -- L2_Norm --
------------- -------------
function L2_Norm (X : Vector) return Scalar is function L2_Norm (X : X_Vector) return Result_Real'Base is
Sum : Result_Real'Base := 0.0;
begin begin
return Sqrt (Inner_Product (X, X)); for J in X'Range loop
Sum := Sum + Result_Real'Base (abs X (J))**2;
end loop;
return Sqrt (Sum);
end L2_Norm; end L2_Norm;
---------------------------------- ----------------------------------
......
...@@ -291,11 +291,12 @@ pragma Pure (Generic_Array_Operations); ...@@ -291,11 +291,12 @@ pragma Pure (Generic_Array_Operations);
------------- -------------
generic generic
type Scalar is private; type X_Scalar is private;
type Vector is array (Integer range <>) of Scalar; type Result_Real is digits <>;
with function Inner_Product (Left, Right : Vector) return Scalar is <>; type X_Vector is array (Integer range <>) of X_Scalar;
with function Sqrt (X : Scalar) return Scalar is <>; with function "abs" (Right : X_Scalar) return Result_Real is <>;
function L2_Norm (X : Vector) return Scalar; with function Sqrt (X : Result_Real'Base) return Result_Real'Base is <>;
function L2_Norm (X : X_Vector) return Result_Real'Base;
------------------- -------------------
-- Outer_Product -- -- Outer_Product --
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment