# Bayesian-Optimization / nlopt2 / stogo / linalg.h

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87``` ```/* Temporary implementation of vector and matrix classes This is more or less borrowed from Serguei's program */ #ifndef LINALG_H #define LINALG_H #include using namespace std; #include // for sqrt() #include typedef const class RVector CRVector; typedef CRVector& RCRVector; typedef const class RMatrix CRMatrix ; typedef CRMatrix& RCRMatrix; double eps() ; #define max(A,B) ((A) > (B) ? (A):(B)) #define min(A,B) ((A) < (B) ? (A):(B)) /********************* Class RVector *********************/ class RVector{ protected: public: int len; // size of array double* elements; // array of values RVector() ; RVector(int); // Constructor RVector(RCRVector); // copy constructor ~RVector() { delete[] elements; elements=0 ; len=0; } RCRVector operator=(double) ; RCRVector operator=(RCRVector); double & operator () (int i) const {return elements[i] ; } double nrm2() ; // Euclidian norm double *raw_data() { return elements; } const double *raw_data_const() const { return elements; } friend ostream & operator << (ostream &, const RVector &); friend double norm2(RCRVector) ; friend double normInf(RCRVector) ; friend double dot(RCRVector, RCRVector) ; friend void scal(double, RCRVector) ; friend void copy(RCRVector, RCRVector) ; friend void axpy(double, RCRVector, RCRVector) ; friend void gemv(char,double, RCRMatrix, RCRVector, double, RCRVector); friend void ger(double alpha, RCRVector, RCRVector, RCRMatrix); int GetLength() const { return len; }; // get vector size }; /******************* Class RMatrix *************************/ class RMatrix { protected: double* Vals; // array of values int Dim; // dimension public: RMatrix() ; RMatrix(int); // dimension ~RMatrix() { delete[] Vals; Vals=0 ; Dim=0; } RMatrix(RCRMatrix); // copy constructor RCRMatrix operator=(double num) ; RCRMatrix operator=(RCRMatrix) ; // (needed for template stuff) double& operator()(int vidx,int hidx) ; friend ostream & operator << (ostream &, const RMatrix &); friend void gemv(char,double, RCRMatrix, RCRVector, double, RCRVector); friend void ger(double alpha,RCRVector,RCRVector,RCRMatrix); int GetDim() { return Dim; }; // get dimension }; #endif ```