<commit_before>// @(#)root/matrix:$Name:  $:$Id: TVectorF.h,v 1.5 2004/03/21 10:52:27 brun Exp $
// Authors: <NAME>, <NAME>   Nov 2003

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TVectorF
#define ROOT_TVectorF

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TVectorF                                                             //
//                                                                      //
// Vectors in the linear algebra package                                //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TMatrixF
#include "TMatrixF.h"
#endif
#ifndef ROOT_TMatrixFSym
#include "TMatrixFSym.h"
#endif

class TVectorF : public TObject {

protected:
  Int_t     fNrows;                // number of rows
  Int_t     fRowLwb;               // lower bound of the row index
  Float_t  *fElements;             //[fNrows] elements themselves

  enum {kSizeMax = 5};             // size data container on stack, see New_m(),Delete_m()
  Float_t   fDataStack[kSizeMax];  //! data container
  Bool_t    fIsOwner;              //!default kTRUE, when Use array kFALSE

  Float_t*  New_m   (Int_t size);
  void      Delete_m(Int_t size,Float_t*&);
  Int_t     Memcpy_m(Float_t *newp,const Float_t *oldp,Int_t copySize,
                     Int_t newSize,Int_t oldSize);

  void Allocate  (Int_t nrows,Int_t row_lwb = 0,Int_t init = 0);

public:
  TVectorF() { fIsOwner = kTRUE; fElements = 0; fNrows = 0; fRowLwb = 0; }
  explicit TVectorF(Int_t n);
  TVectorF(Int_t lwb,Int_t upb);
  TVectorF(Int_t n,const Float_t *elements);
  TVectorF(Int_t lwb,Int_t upb,const Float_t *elements);
  TVectorF(const TVectorF             &another);
  TVectorF(const TMatrixFRow_const    &mr);
  TVectorF(const TMatrixFColumn_const &mc);
  TVectorF(const TMatrixFDiag_const   &md);
#ifndef __CINT__
  TVectorF(Int_t lwb,Int_t upb,Float_t iv1, ...);
#endif
  virtual ~TVectorF() { Clear(); }

  inline          Int_t     GetLwb       () const { return fRowLwb; }
  inline          Int_t     GetUpb       () const { return fNrows+fRowLwb-1; }
  inline          Int_t     GetNrows     () const { return fNrows; }
  inline          Int_t     GetNoElements() const { return fNrows; }

  inline          Float_t  *GetMatrixArray  ()       { return fElements; }
  inline const    Float_t  *GetMatrixArray  () const { return fElements; }

  inline void     Invalidate () { fNrows = -1; }
  inline Bool_t   IsValid    () const { if (fNrows == -1) return kFALSE; return kTRUE; }
  inline Bool_t   IsOwner    () const { return fIsOwner; }
  inline void     SetElements(const Float_t *elements) { Assert(IsValid());
                                                          memcpy(fElements,elements,fNrows*sizeof(Float_t)); }
         void     ResizeTo   (Int_t lwb,Int_t upb);
  inline void     ResizeTo   (Int_t n)       { ResizeTo(0,n-1); }
  inline void     ResizeTo   (const TVectorF &v) { ResizeTo(v.GetLwb(),v.GetUpb()); }

         void     Use        (Int_t n,Float_t *data);
         void     Use        (Int_t lwb,Int_t upb,Float_t *data);
         TVectorF GetSub     (Int_t row_lwb,Int_t row_upb,Option_t *option="S") const;
         void     SetSub     (Int_t row_lwb,const TVectorF &source);

  TVectorF &Zero();
  TVectorF &Abs ();
  TVectorF &Sqr ();
  TVectorF &Sqrt();
  TVectorF &Invert();
  TVectorF &SelectNonZeros(const TVectorF &select);

  Float_t Norm1   () const;
  Float_t Norm2Sqr() const;
  Float_t NormInf () const;
  Int_t   NonZeros() const;
  Float_t Sum     () const;
  Float_t Min     () const;
  Float_t Max     () const;

  inline const Float_t &operator()(Int_t index) const;
  inline       Float_t &operator()(Int_t index)       { return (Float_t&)((*(const TVectorF *)this)(index)); }
  inline const Float_t &operator[](Int_t index) const { return (Float_t&)((*(const TVectorF *)this)(index)); }
  inline       Float_t &operator[](Int_t index)       { return (Float_t&)((*(const TVectorF *)this)(index)); }

  TVectorF &operator= (const TVectorF             &source);
  TVectorF &operator= (const TMatrixFRow_const    &mr);
  TVectorF &operator= (const TMatrixFColumn_const &mc);
  TVectorF &operator= (const TMatrixFDiag_const   &md);
  TVectorF &operator= (Float_t val);
  TVectorF &operator+=(Float_t val);
  TVectorF &operator-=(Float_t val);
  TVectorF &operator*=(Float_t val);

  TVectorF &operator+=(const TVectorF    &source);
  TVectorF &operator-=(const TVectorF    &source);
  TVectorF &operator*=(const TMatrixF    &a);
  TVectorF &operator*=(const TMatrixFSym &a);

  Bool_t operator==(Float_t val) const;
  Bool_t operator!=(Float_t val) const;
  Bool_t operator< (Float_t val) const;
  Bool_t operator<=(Float_t val) const;
  Bool_t operator> (Float_t val) const;
  Bool_t operator>=(Float_t val) const;
  Bool_t MatchesNonZeroPattern(const TVectorF &select);
  Bool_t SomePositive         (const TVectorF &select);
  void   AddSomeConstant      (Float_t val,const TVectorF &select);

  TVectorF &Apply(const TElementActionF    &action);
  TVectorF &Apply(const TElementPosActionF &action);

  void Clear(Option_t * /*option*/ ="") { if (fIsOwner) Delete_m(fNrows,fElements); fNrows = 0; }
  void Draw (Option_t *option=""); // *MENU*
  void Print(Option_t *option="") const;  // *MENU*

  friend Bool_t    operator== (const TVectorF    &v1,     const TVectorF &v2);
  friend Float_t   operator*  (const TVectorF    &v1,     const TVectorF &v2);
  friend TVectorF  operator+  (const TVectorF    &source1,const TVectorF &source2);
  friend TVectorF  operator-  (const TVectorF    &source1,const TVectorF &source2);
  friend TVectorF  operator*  (const TMatrixF    &a,      const TVectorF &source);
  friend TVectorF  operator*  (const TMatrixFSym &a,      const TVectorF &source);
  friend TVectorF  operator*  (      Float_t      val,    const TVectorF &source);

  friend TVectorF &Add        (TVectorF &target,Float_t scalar,const TVectorF &source);
  friend TVectorF &AddElemMult(TVectorF &target,Float_t scalar,
                               const TVectorF &source1,const TVectorF &source2);
  friend TVectorF &AddElemMult(TVectorF &target,Float_t scalar,
                               const TVectorF &source1,const TVectorF &source2,const TVectorF &select);
  friend TVectorF &AddElemDiv (TVectorF &target,Float_t scalar,
                               const TVectorF &source1,const TVectorF &source2);
  friend TVectorF &AddElemDiv (TVectorF &target,Float_t scalar,
                               const TVectorF &source1,const TVectorF &source2,const TVectorF &select);
  friend TVectorF &ElementMult(TVectorF &target,const TVectorF &source);
  friend TVectorF &ElementMult(TVectorF &target,const TVectorF &source,const TVectorF &select);
  friend TVectorF &ElementDiv (TVectorF &target,const TVectorF &source);
  friend TVectorF &ElementDiv (TVectorF &target,const TVectorF &source,const TVectorF &select);

  friend Bool_t AreCompatible(const TVectorF &v1,const TVectorF &v2,Int_t verbose);
  friend void   Compare      (const TVectorF &v1,const TVectorF &v2);

  ClassDef(TVectorF,2)  // Vector class with single precision
};

class TVector : public TVectorF {
public :
  TVector() {}
  explicit TVector(Int_t n)                            : TVectorF(n) {}
  TVector(Int_t lwb,Int_t upb)                         : TVectorF(lwb,upb) {}
  TVector(Int_t n,const Float_t *elements)             : TVectorF(n,elements) {}
  TVector(Int_t lwb,Int_t upb,const Float_t *elements) : TVectorF(lwb,upb,elements) {}
  TVector(const TVectorF             &another)         : TVectorF(another) {}
  TVector(const TMatrixFRow_const    &mr)              : TVectorF(mr) {}
  TVector(const TMatrixFColumn_const &mc)              : TVectorF(mc) {}
  TVector(const TMatrixFDiag_const   &md)              : TVectorF(md) {}

  virtual ~TVector() {}
  ClassDef(TVector,2)  // Vector class with single precision
};

inline const Float_t &TVectorF::operator()(Int_t ind) const
{
  // Access a vector element.<commit_msg>Change class version from 2 to 3<commit_after>// @(#)root/matrix:$Name:  $:$Id: TVectorF.h,v 1.6 2004/03/22 10:50:44 brun Exp $
// Authors: <NAME>, <NAME>   Nov 2003

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TVectorF
#define ROOT_TVectorF

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TVectorF                                                             //
//                                                                      //
// Vectors in the linear algebra package                                //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TMatrixF
#include "TMatrixF.h"
#endif
#ifndef ROOT_TMatrixFSym
#include "TMatrixFSym.h"
#endif

class TVectorF : public TObject {

protected:
  Int_t     fNrows;                // number of rows
  Int_t     fRowLwb;               // lower bound of the row index
  Float_t  *fElements;             //[fNrows] elements themselves

  enum {kSizeMax = 5};             // size data container on stack, see New_m(),Delete_m()
  Float_t   fDataStack[kSizeMax];  //! data container
  Bool_t    fIsOwner;              //!default kTRUE, when Use array kFALSE

  Float_t*  New_m   (Int_t size);
  void      Delete_m(Int_t size,Float_t*&);
  Int_t     Memcpy_m(Float_t *newp,const Float_t *oldp,Int_t copySize,
                     Int_t newSize,Int_t oldSize);

  void Allocate  (Int_t nrows,Int_t row_lwb = 0,Int_t init = 0);

public:
  TVectorF() { fIsOwner = kTRUE; fElements = 0; fNrows = 0; fRowLwb = 0; }
  explicit TVectorF(Int_t n);
  TVectorF(Int_t lwb,Int_t upb);
  TVectorF(Int_t n,const Float_t *elements);
  TVectorF(Int_t lwb,Int_t upb,const Float_t *elements);
  TVectorF(const TVectorF             &another);
  TVectorF(const TMatrixFRow_const    &mr);
  TVectorF(const TMatrixFColumn_const &mc);
  TVectorF(const TMatrixFDiag_const   &md);
#ifndef __CINT__
  TVectorF(Int_t lwb,Int_t upb,Float_t iv1, ...);
#endif
  virtual ~TVectorF() { Clear(); }

  inline          Int_t     GetLwb       () const { return fRowLwb; }
  inline          Int_t     GetUpb       () const { return fNrows+fRowLwb-1; }
  inline          Int_t     GetNrows     () const { return fNrows; }
  inline          Int_t     GetNoElements() const { return fNrows; }

  inline          Float_t  *GetMatrixArray  ()       { return fElements; }
  inline const    Float_t  *GetMatrixArray  () const { return fElements; }

  inline void     Invalidate () { fNrows = -1; }
  inline Bool_t   IsValid    () const { if (fNrows == -1) return kFALSE; return kTRUE; }
  inline Bool_t   IsOwner    () const { return fIsOwner; }
  inline void     SetElements(const Float_t *elements) { Assert(IsValid());
                                                          memcpy(fElements,elements,fNrows*sizeof(Float_t)); }
         void     ResizeTo   (Int_t lwb,Int_t upb);
  inline void     ResizeTo   (Int_t n)       { ResizeTo(0,n-1); }
  inline void     ResizeTo   (const TVectorF &v) { ResizeTo(v.GetLwb(),v.GetUpb()); }

         void     Use        (Int_t n,Float_t *data);
         void     Use        (Int_t lwb,Int_t upb,Float_t *data);
         TVectorF GetSub     (Int_t row_lwb,Int_t row_upb,Option_t *option="S") const;
         void     SetSub     (Int_t row_lwb,const TVectorF &source);

  TVectorF &Zero();
  TVectorF &Abs ();
  TVectorF &Sqr ();
  TVectorF &Sqrt();
  TVectorF &Invert();
  TVectorF &SelectNonZeros(const TVectorF &select);

  Float_t Norm1   () const;
  Float_t Norm2Sqr() const;
  Float_t NormInf () const;
  Int_t   NonZeros() const;
  Float_t Sum     () const;
  Float_t Min     () const;
  Float_t Max     () const;

  inline const Float_t &operator()(Int_t index) const;
  inline       Float_t &operator()(Int_t index)       { return (Float_t&)((*(const TVectorF *)this)(index)); }
  inline const Float_t &operator[](Int_t index) const { return (Float_t&)((*(const TVectorF *)this)(index)); }
  inline       Float_t &operator[](Int_t index)       { return (Float_t&)((*(const TVectorF *)this)(index)); }

  TVectorF &operator= (const TVectorF             &source);
  TVectorF &operator= (const TMatrixFRow_const    &mr);
  TVectorF &operator= (const TMatrixFColumn_const &mc);
  TVectorF &operator= (const TMatrixFDiag_const   &md);
  TVectorF &operator= (Float_t val);
  TVectorF &operator+=(Float_t val);
  TVectorF &operator-=(Float_t val);
  TVectorF &operator*=(Float_t val);

  TVectorF &operator+=(const TVectorF    &source);
  TVectorF &operator-=(const TVectorF    &source);
  TVectorF &operator*=(const TMatrixF    &a);
  TVectorF &operator*=(const TMatrixFSym &a);

  Bool_t operator==(Float_t val) const;
  Bool_t operator!=(Float_t val) const;
  Bool_t operator< (Float_t val) const;
  Bool_t operator<=(Float_t val) const;
  Bool_t operator> (Float_t val) const;
  Bool_t operator>=(Float_t val) const;
  Bool_t MatchesNonZeroPattern(const TVectorF &select);
  Bool_t SomePositive         (const TVectorF &select);
  void   AddSomeConstant      (Float_t val,const TVectorF &select);

  TVectorF &Apply(const TElementActionF    &action);
  TVectorF &Apply(const TElementPosActionF &action);

  void Clear(Option_t * /*option*/ ="") { if (fIsOwner) Delete_m(fNrows,fElements); fNrows = 0; }
  void Draw (Option_t *option=""); // *MENU*
  void Print(Option_t *option="") const;  // *MENU*

  friend Bool_t    operator== (const TVectorF    &v1,     const TVectorF &v2);
  friend Float_t   operator*  (const TVectorF    &v1,     const TVectorF &v2);
  friend TVectorF  operator+  (const TVectorF    &source1,const TVectorF &source2);
  friend TVectorF  operator-  (const TVectorF    &source1,const TVectorF &source2);
  friend TVectorF  operator*  (const TMatrixF    &a,      const TVectorF &source);
  friend TVectorF  operator*  (const TMatrixFSym &a,      const TVectorF &source);
  friend TVectorF  operator*  (      Float_t      val,    const TVectorF &source);

  friend TVectorF &Add        (TVectorF &target,Float_t scalar,const TVectorF &source);
  friend TVectorF &AddElemMult(TVectorF &target,Float_t scalar,
                               const TVectorF &source1,const TVectorF &source2);
  friend TVectorF &AddElemMult(TVectorF &target,Float_t scalar,
                               const TVectorF &source1,const TVectorF &source2,const TVectorF &select);
  friend TVectorF &AddElemDiv (TVectorF &target,Float_t scalar,
                               const TVectorF &source1,const TVectorF &source2);
  friend TVectorF &AddElemDiv (TVectorF &target,Float_t scalar,
                               const TVectorF &source1,const TVectorF &source2,const TVectorF &select);
  friend TVectorF &ElementMult(TVectorF &target,const TVectorF &source);
  friend TVectorF &ElementMult(TVectorF &target,const TVectorF &source,const TVectorF &select);
  friend TVectorF &ElementDiv (TVectorF &target,const TVectorF &source);
  friend TVectorF &ElementDiv (TVectorF &target,const TVectorF &source,const TVectorF &select);

  friend Bool_t AreCompatible(const TVectorF &v1,const TVectorF &v2,Int_t verbose);
  friend void   Compare      (const TVectorF &v1,const TVectorF &v2);

  ClassDef(TVectorF,2)  // Vector class with single precision
};

class TVector : public TVectorF {
public :
  TVector() {}
  explicit TVector(Int_t n)                            : TVectorF(n) {}
  TVector(Int_t lwb,Int_t upb)                         : TVectorF(lwb,upb) {}
  TVector(Int_t n,const Float_t *elements)             : TVectorF(n,elements) {}
  TVector(Int_t lwb,Int_t upb,const Float_t *elements) : TVectorF(lwb,upb,elements) {}
  TVector(const TVectorF             &another)         : TVectorF(another) {}
  TVector(const TMatrixFRow_const    &mr)              : TVectorF(mr) {}
  TVector(const TMatrixFColumn_const &mc)              : TVectorF(mc) {}
  TVector(const TMatrixFDiag_const   &md)              : TVectorF(md) {}

  virtual ~TVector() {}
  ClassDef(TVector,3)  // Vector class with single precision
};

inline const Float_t &TVectorF::operator()(Int_t ind) const
{
  // Access a vector element.
{'fraction_non_alphanumeric': 0.13674423976439337, 'fraction_numerical': 0.007622567419298955, 'mean_word_length': 2.360760721909567, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3355084', 'n_tokens_mistral': 5626, 'n_tokens_neox': 5455, 'n_words': 1381}