-- CC70A01.A
|
-- CC70A01.A
|
--
|
--
|
-- Grant of Unlimited Rights
|
-- Grant of Unlimited Rights
|
--
|
--
|
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
|
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
|
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
|
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
|
-- unlimited rights in the software and documentation contained herein.
|
-- unlimited rights in the software and documentation contained herein.
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
-- this public release, the Government intends to confer upon all
|
-- this public release, the Government intends to confer upon all
|
-- recipients unlimited rights equal to those held by the Government.
|
-- recipients unlimited rights equal to those held by the Government.
|
-- These rights include rights to use, duplicate, release or disclose the
|
-- These rights include rights to use, duplicate, release or disclose the
|
-- released technical data and computer software in whole or in part, in
|
-- released technical data and computer software in whole or in part, in
|
-- any manner and for any purpose whatsoever, and to have or permit others
|
-- any manner and for any purpose whatsoever, and to have or permit others
|
-- to do so.
|
-- to do so.
|
--
|
--
|
-- DISCLAIMER
|
-- DISCLAIMER
|
--
|
--
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
--*
|
--*
|
--
|
--
|
-- OBJECTIVE:
|
-- OBJECTIVE:
|
-- Check that the visible part of a generic formal package includes the
|
-- Check that the visible part of a generic formal package includes the
|
-- first list of basic declarative items of the package specification.
|
-- first list of basic declarative items of the package specification.
|
-- Check for a generic package which declares a formal package with (<>)
|
-- Check for a generic package which declares a formal package with (<>)
|
-- as its actual part.
|
-- as its actual part.
|
--
|
--
|
-- TEST DESCRIPTION:
|
-- TEST DESCRIPTION:
|
-- The "first list of basic declarative items" of a package specification
|
-- The "first list of basic declarative items" of a package specification
|
-- is the visible part of the package. Thus, the declarations in the
|
-- is the visible part of the package. Thus, the declarations in the
|
-- visible part of the actual instance corresponding to a formal
|
-- visible part of the actual instance corresponding to a formal
|
-- package are available in the generic which declares the formal package.
|
-- package are available in the generic which declares the formal package.
|
--
|
--
|
-- Declare a generic package which simulates a complex integer abstraction
|
-- Declare a generic package which simulates a complex integer abstraction
|
-- (foundation code).
|
-- (foundation code).
|
--
|
--
|
-- Declare a second, library-level generic package which utilizes the
|
-- Declare a second, library-level generic package which utilizes the
|
-- first generic package as a generic formal package (with a (<>)
|
-- first generic package as a generic formal package (with a (<>)
|
-- actual_part). In the second generic package, declare objects, types,
|
-- actual_part). In the second generic package, declare objects, types,
|
-- and operations in terms of the objects, types, and operations declared
|
-- and operations in terms of the objects, types, and operations declared
|
-- in the first generic package.
|
-- in the first generic package.
|
--
|
--
|
-- In the main program, instantiate the first generic package, then
|
-- In the main program, instantiate the first generic package, then
|
-- instantiate the second generic package and pass the first instance
|
-- instantiate the second generic package and pass the first instance
|
-- to it as a generic actual parameter. Check that the operations in
|
-- to it as a generic actual parameter. Check that the operations in
|
-- the second instance perform as expected.
|
-- the second instance perform as expected.
|
--
|
--
|
--
|
--
|
-- CHANGE HISTORY:
|
-- CHANGE HISTORY:
|
-- 06 Dec 94 SAIC ACVC 2.0
|
-- 06 Dec 94 SAIC ACVC 2.0
|
--
|
--
|
--!
|
--!
|
|
|
with FC70A00; -- Generic complex integer operations.
|
with FC70A00; -- Generic complex integer operations.
|
|
|
generic -- Generic complex matrix operations.
|
generic -- Generic complex matrix operations.
|
with package Complex_Package is new FC70A00 (<>);
|
with package Complex_Package is new FC70A00 (<>);
|
package CC70A01_0 is
|
package CC70A01_0 is
|
|
|
type Complex_Matrix_Type is -- 1st index is matrix
|
type Complex_Matrix_Type is -- 1st index is matrix
|
array (Positive range <>, Positive range <>) -- row, 2nd is column.
|
array (Positive range <>, Positive range <>) -- row, 2nd is column.
|
of Complex_Package.Complex_Type;
|
of Complex_Package.Complex_Type;
|
Dimension_Mismatch : exception;
|
Dimension_Mismatch : exception;
|
|
|
|
|
function Identity_Matrix (Size : Positive) -- Create identity matrix
|
function Identity_Matrix (Size : Positive) -- Create identity matrix
|
return Complex_Matrix_Type; -- of specified size.
|
return Complex_Matrix_Type; -- of specified size.
|
|
|
function "*" (Left : Complex_Matrix_Type; -- Multiply two complex
|
function "*" (Left : Complex_Matrix_Type; -- Multiply two complex
|
Right : Complex_Matrix_Type) -- matrices.
|
Right : Complex_Matrix_Type) -- matrices.
|
return Complex_Matrix_Type;
|
return Complex_Matrix_Type;
|
|
|
end CC70A01_0;
|
end CC70A01_0;
|
|
|
|
|
--==================================================================--
|
--==================================================================--
|
|
|
|
|
package body CC70A01_0 is -- Generic complex matrix operations.
|
package body CC70A01_0 is -- Generic complex matrix operations.
|
|
|
use Complex_Package;
|
use Complex_Package;
|
|
|
--==============================================--
|
--==============================================--
|
|
|
function Inner_Product (Left, Right : Complex_Matrix_Type;
|
function Inner_Product (Left, Right : Complex_Matrix_Type;
|
Row, Column : Positive) -- Compute inner product
|
Row, Column : Positive) -- Compute inner product
|
return Complex_Package.Complex_Type is -- for matrix-multiply.
|
return Complex_Package.Complex_Type is -- for matrix-multiply.
|
|
|
Result : Complex_Type := Zero;
|
Result : Complex_Type := Zero;
|
subtype Vector_Size is Positive range Left'Range(2);
|
subtype Vector_Size is Positive range Left'Range(2);
|
|
|
begin -- Inner_Product.
|
begin -- Inner_Product.
|
for I in Vector_Size loop
|
for I in Vector_Size loop
|
Result := Result + -- Complex_Package."+".
|
Result := Result + -- Complex_Package."+".
|
(Left(Row, I) * Right(I, Column)); -- Complex_Package."*".
|
(Left(Row, I) * Right(I, Column)); -- Complex_Package."*".
|
end loop;
|
end loop;
|
return (Result);
|
return (Result);
|
end Inner_Product;
|
end Inner_Product;
|
|
|
--==============================================--
|
--==============================================--
|
|
|
function Identity_Matrix (Size : Positive) return Complex_Matrix_Type is
|
function Identity_Matrix (Size : Positive) return Complex_Matrix_Type is
|
Result : Complex_Matrix_Type (1 .. Size, 1 .. Size) :=
|
Result : Complex_Matrix_Type (1 .. Size, 1 .. Size) :=
|
(others => (others => Zero)); -- Zeroes everywhere...
|
(others => (others => Zero)); -- Zeroes everywhere...
|
begin
|
begin
|
for I in 1 .. Size loop
|
for I in 1 .. Size loop
|
Result (I, I) := One; -- Ones on the diagonal.
|
Result (I, I) := One; -- Ones on the diagonal.
|
end loop;
|
end loop;
|
return (Result);
|
return (Result);
|
end Identity_Matrix;
|
end Identity_Matrix;
|
|
|
--==============================================--
|
--==============================================--
|
|
|
function "*" (Left : Complex_Matrix_Type; Right : Complex_Matrix_Type)
|
function "*" (Left : Complex_Matrix_Type; Right : Complex_Matrix_Type)
|
return Complex_Matrix_Type is
|
return Complex_Matrix_Type is
|
|
|
subtype Rows is Positive range Left'Range(1);
|
subtype Rows is Positive range Left'Range(1);
|
subtype Columns is Positive range Right'Range(2);
|
subtype Columns is Positive range Right'Range(2);
|
|
|
Result : Complex_Matrix_Type(Rows, Columns);
|
Result : Complex_Matrix_Type(Rows, Columns);
|
begin
|
begin
|
if Left'Length(2) /= Right'Length(1) then -- # columns of Left must
|
if Left'Length(2) /= Right'Length(1) then -- # columns of Left must
|
-- match # rows of Right.
|
-- match # rows of Right.
|
raise Dimension_Mismatch;
|
raise Dimension_Mismatch;
|
else
|
else
|
for I in Rows loop
|
for I in Rows loop
|
for J in Columns loop
|
for J in Columns loop
|
Result(I, J) := Inner_Product (Left, Right, I, J);
|
Result(I, J) := Inner_Product (Left, Right, I, J);
|
end loop;
|
end loop;
|
end loop;
|
end loop;
|
return (Result);
|
return (Result);
|
end if;
|
end if;
|
end "*";
|
end "*";
|
|
|
end CC70A01_0;
|
end CC70A01_0;
|
|
|
|
|
--==================================================================--
|
--==================================================================--
|
|
|
|
|
with Report;
|
with Report;
|
|
|
with FC70A00; -- Generic complex integer operations.
|
with FC70A00; -- Generic complex integer operations.
|
with CC70A01_0; -- Generic complex matrix operations.
|
with CC70A01_0; -- Generic complex matrix operations.
|
|
|
procedure CC70A01 is
|
procedure CC70A01 is
|
|
|
type My_Integer is range -100 .. 100;
|
type My_Integer is range -100 .. 100;
|
|
|
package My_Complex_Package is new FC70A00 (My_Integer);
|
package My_Complex_Package is new FC70A00 (My_Integer);
|
package My_Matrix_Package is new CC70A01_0 (My_Complex_Package);
|
package My_Matrix_Package is new CC70A01_0 (My_Complex_Package);
|
|
|
use My_Complex_Package, -- All user-defined
|
use My_Complex_Package, -- All user-defined
|
My_Matrix_Package; -- operators directly
|
My_Matrix_Package; -- operators directly
|
-- visible.
|
-- visible.
|
|
|
subtype Matrix_2x2 is Complex_Matrix_Type (1 .. 2, 1 .. 2);
|
subtype Matrix_2x2 is Complex_Matrix_Type (1 .. 2, 1 .. 2);
|
subtype Matrix_2x3 is Complex_Matrix_Type (1 .. 2, 1 .. 3);
|
subtype Matrix_2x3 is Complex_Matrix_Type (1 .. 2, 1 .. 3);
|
|
|
function C (Real, Imag : My_Integer) return Complex_Type renames Complex;
|
function C (Real, Imag : My_Integer) return Complex_Type renames Complex;
|
|
|
begin -- Main program.
|
begin -- Main program.
|
|
|
Report.Test ("CC70A01", "Check that the visible part of a generic " &
|
Report.Test ("CC70A01", "Check that the visible part of a generic " &
|
"formal package includes the first list of basic " &
|
"formal package includes the first list of basic " &
|
"declarative items of the package specification. Check " &
|
"declarative items of the package specification. Check " &
|
"for a generic package where formal package has (<>) " &
|
"for a generic package where formal package has (<>) " &
|
"actual part");
|
"actual part");
|
|
|
declare
|
declare
|
Identity_2x2 : Matrix_2x2 := Identity_Matrix (Size => 2);
|
Identity_2x2 : Matrix_2x2 := Identity_Matrix (Size => 2);
|
Operand_2x3 : Matrix_2x3 := ( ( C(1, 2), C(3, 6), C(5, 1) ),
|
Operand_2x3 : Matrix_2x3 := ( ( C(1, 2), C(3, 6), C(5, 1) ),
|
( C(0, 3), C(7, 9), C(3, 4) ) );
|
( C(0, 3), C(7, 9), C(3, 4) ) );
|
Result_2x3 : Matrix_2x3 := ( others => ( others => Zero ) );
|
Result_2x3 : Matrix_2x3 := ( others => ( others => Zero ) );
|
begin
|
begin
|
|
|
begin -- Block #1.
|
begin -- Block #1.
|
Result_2x3 := Identity_2x2 * Operand_2x3; -- Should return
|
Result_2x3 := Identity_2x2 * Operand_2x3; -- Should return
|
-- Operand_2x3.
|
-- Operand_2x3.
|
if (Result_2x3 /= Operand_2x3) then
|
if (Result_2x3 /= Operand_2x3) then
|
Report.Failed ("Incorrect results from matrix multiplication");
|
Report.Failed ("Incorrect results from matrix multiplication");
|
end if;
|
end if;
|
exception
|
exception
|
when others =>
|
when others =>
|
Report.Failed ("Unexpected exception raised - Block #1");
|
Report.Failed ("Unexpected exception raised - Block #1");
|
end; -- Block #1.
|
end; -- Block #1.
|
|
|
|
|
begin -- Block #2.
|
begin -- Block #2.
|
Result_2x3 := Operand_2x3 * Identity_2x2; -- Can't multiply 2x3
|
Result_2x3 := Operand_2x3 * Identity_2x2; -- Can't multiply 2x3
|
-- by 2x2.
|
-- by 2x2.
|
Report.Failed ("Exception Dimension_Mismatch not raised");
|
Report.Failed ("Exception Dimension_Mismatch not raised");
|
exception
|
exception
|
when Dimension_Mismatch =>
|
when Dimension_Mismatch =>
|
null;
|
null;
|
when others =>
|
when others =>
|
Report.Failed ("Unexpected exception raised - Block #2");
|
Report.Failed ("Unexpected exception raised - Block #2");
|
end; -- Block #2.
|
end; -- Block #2.
|
|
|
end;
|
end;
|
|
|
Report.Result;
|
Report.Result;
|
|
|
end CC70A01;
|
end CC70A01;
|
|
|