From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.5 required=3.0 tests=BAYES_05,FREEMAIL_FROM, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Received: by 2002:ac8:7206:0:b0:3b6:8c54:129e with SMTP id a6-20020ac87206000000b003b68c54129emr1025810qtp.147.1674589634355; Tue, 24 Jan 2023 11:47:14 -0800 (PST) X-Received: by 2002:a9d:6f05:0:b0:686:4b6f:78a8 with SMTP id n5-20020a9d6f05000000b006864b6f78a8mr1401039otq.291.1674589634080; Tue, 24 Jan 2023 11:47:14 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!border-1.nntp.ord.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: Tue, 24 Jan 2023 11:47:13 -0800 (PST) In-Reply-To: <9c7cccd9-733f-49a8-b482-087ccb14b58dn@googlegroups.com> Injection-Info: google-groups.googlegroups.com; posting-host=2a02:1210:2824:7200:e16e:d103:5ddc:cf2a; posting-account=gRqrnQkAAAAC_02ynnhqGk1VRQlve6ZG NNTP-Posting-Host: 2a02:1210:2824:7200:e16e:d103:5ddc:cf2a References: <9c7cccd9-733f-49a8-b482-087ccb14b58dn@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <62954fe7-8f83-40ad-823f-ef628c43c544n@googlegroups.com> Subject: Re: Real_Arrays on heap with overloaded operators and clean syntax From: Gautier write-only address Injection-Date: Tue, 24 Jan 2023 19:47:14 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:64875 List-Id: There are plenty of legitimate complaints and good ideas in this thread. - need for a package for large matrices (issue with stack allocation) - should support approximations (at least, floating-point) real and complex numbers (and perhaps others) - should support various matrix storages: sparse storages, band storages, ... Fortunately Ada (not "ADA" = "American Dentist Association" and some others...) is powerful enough to have such components written in Ada itself (with GNAT, it is done exactly like this). So _we_ don't need to wait that _they_ do anything about it :-) So, if I summarize the ideas discussed and combine with stuff grabbed from a toolbox of mine ( https://github.com/zertovitch/mathpaqs ), I obtain the following specification. The choice between different kind of matrix storages would be trivial. Comments are welcome! ---8<--------8<--------8<--------8<--------8<--------8<----- -- Draft of a specification for an universal matrix package. -- The elements of the vectors and matrices can be of any algebraic ring -- and their implementation, eventually approximate: -- -- - integers (stored as Integer, Integer_n or Big_Integer) -- - modular integers -- - real numbers (approximated as floating-point, fixed-point or Big_Real) -- - complex numbers -- - rational numbers -- - polynomials (of real, complex, rational, ...) -- - other matrices -- - ... with Ada.Containers.Vectors; generic type Ring_Element is private; -- Element of an algebraic ring zero, one : Ring_Element; -- 0 and 1 elements with function "-" (a : Ring_Element) return Ring_Element; -- Unary operators with function "+" (a, b : Ring_Element) return Ring_Element; -- Binary operators with function "-" (a, b : Ring_Element) return Ring_Element; with function "*" (a, b : Ring_Element) return Ring_Element; package Universal_Matrices is package UM_Vectors is new Ada.Containers.Vectors (Positive, Ring_Element); subtype Vector is UM_Vectors.Vector; ------------------------- -- Vector operations -- ------------------------- function "*" (v : Vector; factor : Ring_Element) return Vector; function "*" (factor : Ring_Element; v : Vector) return Vector; -- v := factor * v : procedure Scale_Left (v : in out Vector; factor : Ring_Element); function "-" (v : Vector) return Vector; function "+" (v, w : Vector) return Vector; -- v := v + w : procedure Add (v : in out Vector; w : Vector); -- v := v + factor * w : procedure Add_Left_Scaled (v : in out Vector; factor : Ring_Element; w : Vector); function "-" (v, w : Vector) return Vector; -- v := v - w : procedure Subtract (v : in out Vector; w : Vector); function "*" (v, w : Vector) return Ring_Element; -- Euclidean norm and distance: function Square_L2_Norm (v : Vector) return Ring_Element; function Square_L2_Distance (v, w : Vector) return Ring_Element; ------------------------------------------------------------------- -- Root matrix type. -- -- Possible derivations: dense, sparse, band storage matrices. -- ------------------------------------------------------------------- type Matrix is interface; ------------------------- -- Matrix operations -- ------------------------- function Transpose (A : Matrix) return Matrix is abstract; function Identity (order : Positive) return Matrix is abstract; function "*" (factor : Ring_Element; A : Matrix) return Matrix is abstract; function "*" (A : Matrix; factor : Ring_Element) return Matrix is abstract; function "*" (A, B : Matrix) return Matrix is abstract; function "+" (A, B : Matrix) return Matrix is abstract; function "-" (A, B : Matrix) return Matrix is abstract; -- Matrix-Vector operations function "*" (A : Matrix; x : Vector) return Vector is abstract; end Universal_Matrices;