| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT RUN-TIME COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- ADA.NUMERICS.GENERIC_REAL_ARRAYS -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2009-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- This specification is derived from the Ada Reference Manual for use with -- |
| 12 |
-- GNAT. The copyright notice above, and the license provisions that follow -- |
| 13 |
-- apply solely to the contents of the part following the private keyword. -- |
| 14 |
-- -- |
| 15 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 16 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 17 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 18 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 19 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 20 |
-- or FITNESS FOR A PARTICULAR PURPOSE. -- |
| 21 |
-- -- |
| 22 |
-- As a special exception under Section 7 of GPL version 3, you are granted -- |
| 23 |
-- additional permissions described in the GCC Runtime Library Exception, -- |
| 24 |
-- version 3.1, as published by the Free Software Foundation. -- |
| 25 |
-- -- |
| 26 |
-- You should have received a copy of the GNU General Public License and -- |
| 27 |
-- a copy of the GCC Runtime Library Exception along with this program; -- |
| 28 |
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- |
| 29 |
-- <http://www.gnu.org/licenses/>. -- |
| 30 |
-- -- |
| 31 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 32 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 33 |
-- -- |
| 34 |
------------------------------------------------------------------------------ |
| 35 |
|
| 36 |
generic |
| 37 |
type Real is digits <>; |
| 38 |
package Ada.Numerics.Generic_Real_Arrays is |
| 39 |
pragma Pure (Generic_Real_Arrays); |
| 40 |
|
| 41 |
-- Types |
| 42 |
|
| 43 |
type Real_Vector is array (Integer range <>) of Real'Base; |
| 44 |
type Real_Matrix is array (Integer range <>, Integer range <>) of Real'Base; |
| 45 |
|
| 46 |
-- Subprograms for Real_Vector types |
| 47 |
|
| 48 |
-- Real_Vector arithmetic operations |
| 49 |
|
| 50 |
function "+" (Right : Real_Vector) return Real_Vector; |
| 51 |
function "-" (Right : Real_Vector) return Real_Vector; |
| 52 |
function "abs" (Right : Real_Vector) return Real_Vector; |
| 53 |
|
| 54 |
function "+" (Left, Right : Real_Vector) return Real_Vector; |
| 55 |
function "-" (Left, Right : Real_Vector) return Real_Vector; |
| 56 |
|
| 57 |
function "*" (Left, Right : Real_Vector) return Real'Base; |
| 58 |
|
| 59 |
function "abs" (Right : Real_Vector) return Real'Base; |
| 60 |
|
| 61 |
-- Real_Vector scaling operations |
| 62 |
|
| 63 |
function "*" (Left : Real'Base; Right : Real_Vector) return Real_Vector; |
| 64 |
function "*" (Left : Real_Vector; Right : Real'Base) return Real_Vector; |
| 65 |
function "/" (Left : Real_Vector; Right : Real'Base) return Real_Vector; |
| 66 |
|
| 67 |
-- Other Real_Vector operations |
| 68 |
|
| 69 |
function Unit_Vector |
| 70 |
(Index : Integer; |
| 71 |
Order : Positive; |
| 72 |
First : Integer := 1) return Real_Vector; |
| 73 |
|
| 74 |
-- Subprograms for Real_Matrix types |
| 75 |
|
| 76 |
-- Real_Matrix arithmetic operations |
| 77 |
|
| 78 |
function "+" (Right : Real_Matrix) return Real_Matrix; |
| 79 |
function "-" (Right : Real_Matrix) return Real_Matrix; |
| 80 |
function "abs" (Right : Real_Matrix) return Real_Matrix; |
| 81 |
function Transpose (X : Real_Matrix) return Real_Matrix; |
| 82 |
|
| 83 |
function "+" (Left, Right : Real_Matrix) return Real_Matrix; |
| 84 |
function "-" (Left, Right : Real_Matrix) return Real_Matrix; |
| 85 |
function "*" (Left, Right : Real_Matrix) return Real_Matrix; |
| 86 |
|
| 87 |
function "*" (Left, Right : Real_Vector) return Real_Matrix; |
| 88 |
|
| 89 |
function "*" (Left : Real_Vector; Right : Real_Matrix) return Real_Vector; |
| 90 |
function "*" (Left : Real_Matrix; Right : Real_Vector) return Real_Vector; |
| 91 |
|
| 92 |
-- Real_Matrix scaling operations |
| 93 |
|
| 94 |
function "*" (Left : Real'Base; Right : Real_Matrix) return Real_Matrix; |
| 95 |
function "*" (Left : Real_Matrix; Right : Real'Base) return Real_Matrix; |
| 96 |
function "/" (Left : Real_Matrix; Right : Real'Base) return Real_Matrix; |
| 97 |
|
| 98 |
-- Real_Matrix inversion and related operations |
| 99 |
|
| 100 |
function Solve (A : Real_Matrix; X : Real_Vector) return Real_Vector; |
| 101 |
function Solve (A, X : Real_Matrix) return Real_Matrix; |
| 102 |
function Inverse (A : Real_Matrix) return Real_Matrix; |
| 103 |
function Determinant (A : Real_Matrix) return Real'Base; |
| 104 |
|
| 105 |
-- Eigenvalues and vectors of a real symmetric matrix |
| 106 |
|
| 107 |
function Eigenvalues (A : Real_Matrix) return Real_Vector; |
| 108 |
|
| 109 |
procedure Eigensystem |
| 110 |
(A : Real_Matrix; |
| 111 |
Values : out Real_Vector; |
| 112 |
Vectors : out Real_Matrix); |
| 113 |
|
| 114 |
-- Other Real_Matrix operations |
| 115 |
|
| 116 |
function Unit_Matrix |
| 117 |
(Order : Positive; |
| 118 |
First_1 : Integer := 1; |
| 119 |
First_2 : Integer := 1) return Real_Matrix; |
| 120 |
|
| 121 |
private |
| 122 |
-- The following operations are either relatively simple compared to the |
| 123 |
-- expense of returning unconstrained arrays, or are just function wrappers |
| 124 |
-- calling procedures implementing the actual operation. By having the |
| 125 |
-- front end inline these, the expense of the unconstrained returns |
| 126 |
-- can be avoided. |
| 127 |
|
| 128 |
-- Note: We use an extended return statement in their implementation to |
| 129 |
-- allow the frontend to inline these functions. |
| 130 |
|
| 131 |
pragma Inline ("+"); |
| 132 |
pragma Inline ("-"); |
| 133 |
pragma Inline ("*"); |
| 134 |
pragma Inline ("/"); |
| 135 |
pragma Inline ("abs"); |
| 136 |
pragma Inline (Eigenvalues); |
| 137 |
pragma Inline (Inverse); |
| 138 |
pragma Inline (Solve); |
| 139 |
pragma Inline (Transpose); |
| 140 |
pragma Inline (Unit_Matrix); |
| 141 |
pragma Inline (Unit_Vector); |
| 142 |
end Ada.Numerics.Generic_Real_Arrays; |