1 /****************************************************************************
2  * Core Library Version 1.7, August 2004
3  * Copyright (c) 1995-2004 Exact Computation Project
4  * All rights reserved.
5  *
6  * This file is part of CGAL (www.cgal.org).
7  *
8  * $URL: https://github.com/CGAL/cgal/blob/v5.3/CGAL_Core/include/CGAL/CORE/linearAlgebra.h $
9  * $Id: linearAlgebra.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot
10  * SPDX-License-Identifier: LGPL-3.0-or-later
11  ***************************************************************************/
12 /******************************************************************
13  * Core Library Version 1.7, August 2004
14  * Copyright (c) 1995-2002 Exact Computation Project
15  *
16  * File: LinearAlgebra.h
17  * Synopsis:
18  *      Linear Algebra Extension of Core Library introducing
19  *              class Vector
20  *              class Matrix
21  *
22  * Written by
23  *       Shubin Zhao (shubinz@cs.nyu.edu) (2001)
24  *
25  * WWW URL: http://cs.nyu.edu/exact/
26  * Email: exact@cs.nyu.edu
27  *
28  * $Id: linearAlgebra.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot
29  *****************************************************************/
30 
31 #ifndef CORE_LINEAR_ALGEBRA_H
32 #define CORE_LINEAR_ALGEBRA_H
33 
34 #ifndef CORE_LEVEL
35 #  define CORE_LEVEL 3
36 #endif
37 
38 #include <cstdarg>
39 #include <CGAL/CORE/CORE.h>
40 
41 class Vector;
42 class Matrix;
43 
44 ////////////////////////////////////////////////////////////////////////
45 //  Class Vector
46 //     Generic vectors
47 //     Operations implemented:  addition, subtraction, dot product
48 ////////////////////////////////////////////////////////////////////////
49 
50 class Vector {
51 private:
52    int     dim;
53    double* _rep;
54 public:
55    class RangeException { };
56    class ArithmeticException { };
57 
58    explicit Vector(int);
59    Vector();
60    Vector(double, double);
61    Vector(double, double, double);
62    Vector(const Vector&);
63    Vector(int, double *);
64    ~Vector();
65 
66    const Vector& operator=(const Vector&);
67 
68    bool operator==(const Vector&);
69    bool operator!=(const Vector&);
70    const Vector& operator+=(const Vector&);
71    const Vector& operator-=(const Vector&);
72    const Vector& operator*=(double);
73 
74    const double& operator[](int) const;
75    double& operator[](int);
76 
77    double norm() const;
78    double maxnorm() const;
79    double infnorm() const;
dimension()80    double dimension() const {return dim;}
81    bool isZero() const;
82    Vector cross(const Vector &v) const;
83    static Vector crossProduct(int, ...);
84 
85    friend Vector operator+(const Vector&, const Vector&);
86    friend Vector operator-(const Vector&, const Vector&);
87    friend Vector operator-(const Vector&);
88    friend Vector operator*(const Vector&, double);
89    friend Vector operator*(double, const Vector&);
90    friend Vector operator*(const Matrix&, const Vector&);
91    friend Vector operator*(const Vector&, const Matrix&);
92    friend double dotProduct(const Vector&, const Vector&);
93 
94    friend std::istream& operator>>(std::istream&, Vector&);
95    friend std::ostream& operator<<(std::ostream&, const Vector&);
96 };
97 
98 ////////////////////////////////////////////////////////////////////////
99 //  Class Matrix
100 //     Generic matrices
101 //     Operations implemented:  addition, subtraction, multiplication
102 ////////////////////////////////////////////////////////////////////////
103 
104 class Matrix {
105 private:
106    int dim1, dim2;
107    double* _rep;
108 
109 public:
110    class RangeException { };
111    class ArithmeticException { };
112 
113    explicit Matrix(int);
114    Matrix(int, int);
115    Matrix(int, int, double *);
116    Matrix(double, double,
117           double, double);
118    Matrix(double, double, double,
119           double, double, double,
120           double, double, double);
121    Matrix(const Matrix&);
122    ~Matrix();
123 
124    Matrix& operator=(const Matrix&);
125 
126    bool operator==(const Matrix&);
127    bool operator!=(const Matrix&);
128 
129    const Matrix& operator+=(const Matrix&);
130    const Matrix& operator-=(const Matrix&);
131    const Matrix& operator*=(double);
132 
133    const double& operator()(int, int) const;
134    double& operator()(int, int);
135 
136    // added by chen li
137    //   const Vector& row(int i) const;
138    //   const Vector& col(int i) const;
139    Matrix matrixAlgebraRemainder(int, int) const;
140    double valueAlgebraRemainder(int, int) const;
141    const Matrix& transpose();
142 
143    double determinant() const;
144 
dimension_1()145    int dimension_1() const { return dim1; }
dimension_2()146    int dimension_2() const { return dim2; }
147 
148    friend Matrix operator+(const Matrix&, const Matrix&);
149    friend Matrix operator-(const Matrix&, const Matrix&);
150    friend Matrix operator*(const Matrix&, double);
151    friend Matrix operator*(double, const Matrix&);
152    friend Vector operator*(const Vector&, const Matrix&);
153    friend Vector operator*(const Matrix&, const Vector&);
154    friend Matrix operator*(const Matrix&, const Matrix&);
155    friend Matrix transpose(const Matrix&);
156 
157    friend double det(const double a, const double b,
158                 const double c, const double d);
159    friend double det(const Vector u, const Vector & v);  // u,v are 2d vectors
160 
161    friend std::istream& operator>>(std::istream&, Matrix&);
162    friend std::ostream& operator<<(std::ostream&, const Matrix&);
163 
164 }; //Matrix
165 
166 #endif
167