<commit_before>// @(#)root/smatrix:$Name:  $:$Id: Expression.h,v 1.5 2006/02/08 16:52:38 moneta Exp $
// Authors: <NAME>, <NAME>    2005  

#ifndef ROOT_Math_Expression
#define ROOT_Math_Expression
// ********************************************************************
//
// source:
//
// type:      source code
//
// created:   19. Mar 2001
//
// author:    <NAME>
//            HERA-B Collaboration
//            Max-Planck-Institut fuer Kernphysik
//            Saupfercheckweg 1
//            69117 Heidelberg
//            Germany
//            E-mail: <EMAIL>
//
// Description: Expression Template Elements for SVector
//
// changes:
// 19 Mar 2001 (TG) creation
// 20 Mar 2001 (TG) added rows(), cols() to Expr
// 21 Mar 2001 (TG) added Expr::value_type
// 11 Apr 2001 (TG) rows(), cols() replaced by rows, cols
// 10 Okt 2001 (TG) added print() and operator<<() for Expr class
//
// ********************************************************************

/** Expr.
    An Expression wrapper class.

    @memo Expr.
    @author <NAME>
*/
//==============================================================================
// Expr: class representing SVector expressions
//=============================================================================

// originally references where used as data members of operation wrappers
// problem appear on Windows because original ref goes out of scope use then by value by default (like in tvmet)
//#define SMATRIX_USE_REFERENCES   


#include <iomanip>

namespace ROOT { 

  namespace Math { 




    //    template <class T, unsigned int D, unsigned int D2> class MatRepStd;

    template <class ExprType, class T, unsigned int D >
    class VecExpr {
public:
  typedef T  value_type;

  ///
  VecExpr(const ExprType& rhs) :
    rhs_(rhs) {}

  ///
  ~VecExpr() {}

  ///
  inline T apply(unsigned int i) const {
    return rhs_.apply(i);
  }


#ifdef OLD_IMPL
  ///
  static const unsigned int rows = D;
  ///
  ///static const unsigned int cols = D2;
#else
  // use enumerations
  enum { 

    kRows = D 

  };
#endif

  /// used by operator<<()
  std::ostream& print(std::ostream& os) const {
    os.setf(std::ios::right,std::ios::adjustfield);
    unsigned int i=0;
    os << "[ ";
    for(; i<D-1; ++i) {
      os << apply(i) << ", ";
    }
    os << apply(i);
    os << " ]";
    
    return os;
  }

private:
  ExprType rhs_; // cannot be a reference!
};



    template <class T, unsigned int D, unsigned int D2> class MatRepStd;

    template <class ExprType, class T, unsigned int D, unsigned int D2 = 1,
	      class R1=MatRepStd<T,D,D2> >
    class Expr {
public:
  typedef T  value_type;

  ///
  Expr(const ExprType& rhs) :
    rhs_(rhs) {}

  ///
  ~Expr() {}

  ///
  inline T apply(unsigned int i) const {
    return rhs_.apply(i);
  }
  inline T apply(unsigned int i, unsigned j) const {
    return rhs_.apply(i,j);
  }


#ifdef OLD_IMPL
  ///
  static const unsigned int rows = D;
  ///
  static const unsigned int cols = D2;
#else
  // use enumerations
  enum { 
    ///
    kRows = D, 
  ///
    kCols = D2
  };
#endif

  /// used by operator<<()
  std::ostream& print(std::ostream& os) const {
    os.setf(std::ios::right,std::ios::adjustfield);
    if(D2 == 1 || D2 ==0 ) {
      unsigned int i=0;
      for(; i<D-1; ++i) {
        os << apply(i) << ", ";
      }
      os << apply(i);
    } else {
      os << "[ ";
      for (unsigned int i=0; i < D; ++i) {
        unsigned int d2 = D2; // to avoid some annoying warnings in case of vectors (D2 = 0)
        for (unsigned int j=0; j < D2; ++j) {
          os << std::setw(12) << apply(i*D2+j);
          if ((!((j+1)%12)) && (j < d2-1))
            os << std::endl << "         ...";
        }
        if (i != D - 1)
          os << std::endl  << "  ";
      }
      os << " ]";
    } // if D2==0

    return os;
  }

private:
  ExprType rhs_; // cannot be a reference!
};

//==============================================================================
// operator<<
//==============================================================================
template <class A, class T, unsigned int D>
inline std::ostream& operator<<(std::ostream& os, const VecExpr<A,T,D>& rhs) {
  return rhs.print(os);
}

template <class A, class T, unsigned int D1, unsigned int D2, class R1>
inline std::ostream& operator<<(std::ostream& os, const Expr<A,T,D1,D2,R1>& rhs) {
  return rhs.print(os);
}

/** BinaryOp.
    A class representing binary operators in the parse tree.

    @memo BinaryOp
    @author <NAME>
*/
//==============================================================================
// BinaryOp
//==============================================================================
template <class Operator, class LHS, class RHS, class T>
class BinaryOp {
public:
  ///
  BinaryOp( Operator /* op */, const LHS& lhs, const RHS& rhs) :
    lhs_(lhs), rhs_(rhs) {}

  ///
  ~BinaryOp() {}

  ///
  inline T apply(unsigned int i) const {
    return Operator::apply(lhs_.apply(i), rhs_.apply(i));
  }
  inline T apply(unsigned int i, unsigned int j) const {
    return Operator::apply(lhs_.apply(i,j), rhs_.apply(i,j));
  }

protected:

#ifdef SMATRIX_USE_REFERENCES
  const LHS& lhs_;
  const RHS& rhs_;
#else
  const LHS lhs_;
  const RHS rhs_;
#endif

};


/** UnaryOp.
    A class representing unary operators in the parse tree.

    @memo UnaryOp
    @author <NAME>
*/
//==============================================================================
// UnaryOp
//==============================================================================
template <class Operator, class RHS, class T>
class UnaryOp {
public:
  ///
  UnaryOp( Operator /* op */ , const RHS& rhs) :
    rhs_(rhs) {}

  ///
  ~UnaryOp() {}
  
  ///
  inline T apply(unsigned int i) const {
    return Operator::apply(rhs_.apply(i));
  }
  inline T apply(unsigned int i, unsigned int j) const {
    return Operator::apply(rhs_.apply(i,j));
  }

protected:

#ifdef SMATRIX_USE_REFERENCES
  const RHS& rhs_;
#else
  const RHS rhs_;
#endif

};


/** Constant.
    A class representing constant expressions (literals) in the parse tree.

    @memo Constant
    @author <NAME>
*/
//==============================================================================
// Constant
//==============================================================================
template <class T>
class Constant {
public:
  ///
  Constant( const T& rhs ) :
    rhs_(rhs) {}

  ///
  ~Constant() {}

  ///
  inline T apply(unsigned int /*i */ ) const { return rhs_; }

  inline T apply(unsigned int /*i */, unsigned int /*j */ ) const { return rhs_; }

protected:

#ifdef SMATRIX_USE_REFERENCES
  const T& rhs_;
#else
  const T rhs_;
#endif

};



  }  // namespace Math

}  // namespace ROOT
          


#endif  /* ROOT_Math_Expression */
<commit_msg>change also print method to use expression.apply(i,j). Expression.apply(i) gives in same case a compilaiton error on Windows<commit_after>// @(#)root/smatrix:$Name:  $:$Id: Expression.h,v 1.6 2006/03/08 15:11:06 moneta Exp $
// Authors: <NAME>, <NAME>    2005  

#ifndef ROOT_Math_Expression
#define ROOT_Math_Expression
// ********************************************************************
//
// source:
//
// type:      source code
//
// created:   19. Mar 2001
//
// author:    <NAME>
//            HERA-B Collaboration
//            Max-Planck-Institut fuer Kernphysik
//            Saupfercheckweg 1
//            69117 Heidelberg
//            Germany
//            E-mail: <EMAIL>
//
// Description: Expression Template Elements for SVector
//
// changes:
// 19 Mar 2001 (TG) creation
// 20 Mar 2001 (TG) added rows(), cols() to Expr
// 21 Mar 2001 (TG) added Expr::value_type
// 11 Apr 2001 (TG) rows(), cols() replaced by rows, cols
// 10 Okt 2001 (TG) added print() and operator<<() for Expr class
//
// ********************************************************************

/** Expr.
    An Expression wrapper class.

    @memo Expr.
    @author <NAME>
*/
//==============================================================================
// Expr: class representing SVector expressions
//=============================================================================

// originally references where used as data members of operation wrappers
// problem appear on Windows because original ref goes out of scope use then by value by default (like in tvmet)
//#define SMATRIX_USE_REFERENCES   


#include <iomanip>

namespace ROOT { 

  namespace Math { 




    //    template <class T, unsigned int D, unsigned int D2> class MatRepStd;

    template <class ExprType, class T, unsigned int D >
    class VecExpr {
public:
  typedef T  value_type;

  ///
  VecExpr(const ExprType& rhs) :
    rhs_(rhs) {}

  ///
  ~VecExpr() {}

  ///
  inline T apply(unsigned int i) const {
    return rhs_.apply(i);
  }


#ifdef OLD_IMPL
  ///
  static const unsigned int rows = D;
  ///
  ///static const unsigned int cols = D2;
#else
  // use enumerations
  enum { 

    kRows = D 

  };
#endif

  /// used by operator<<()
  std::ostream& print(std::ostream& os) const {
    os.setf(std::ios::right,std::ios::adjustfield);
    unsigned int i=0;
    os << "[ ";
    for(; i<D-1; ++i) {
      os << apply(i) << ", ";
    }
    os << apply(i);
    os << " ]";
    
    return os;
  }

private:
  ExprType rhs_; // cannot be a reference!
};



    template <class T, unsigned int D, unsigned int D2> class MatRepStd;

    template <class ExprType, class T, unsigned int D, unsigned int D2 = 1,
	      class R1=MatRepStd<T,D,D2> >
    class Expr {
public:
  typedef T  value_type;

  ///
  Expr(const ExprType& rhs) :
    rhs_(rhs) {}

  ///
  ~Expr() {}

  ///
  inline T apply(unsigned int i) const {
    return rhs_.apply(i);
  }
  inline T apply(unsigned int i, unsigned j) const {
    return rhs_.apply(i,j);
  }


#ifdef OLD_IMPL
  ///
  static const unsigned int rows = D;
  ///
  static const unsigned int cols = D2;
#else
  // use enumerations
  enum { 
    ///
    kRows = D, 
  ///
    kCols = D2
  };
#endif

  /// used by operator<<()
  /// simplify to use apply(i,j) 
  std::ostream& print(std::ostream& os) const {
    os.setf(std::ios::right,std::ios::adjustfield);
      os << "[ ";
      for (unsigned int i=0; i < D; ++i) {
	unsigned int d2 = D2; // to avoid some annoying warnings in case of vectors (D2 = 0)
        for (unsigned int j=0; j < D2; ++j) {
          os << std::setw(12) << apply(i,j);
          if ((!((j+1)%12)) && (j < d2-1))
            os << std::endl << "         ...";
        }
        if (i != D - 1)
          os << std::endl  << "  ";
      }
      os << " ]";

    return os;
  }

private:
  ExprType rhs_; // cannot be a reference!
};

//==============================================================================
// operator<<
//==============================================================================
template <class A, class T, unsigned int D>
inline std::ostream& operator<<(std::ostream& os, const VecExpr<A,T,D>& rhs) {
  return rhs.print(os);
}

template <class A, class T, unsigned int D1, unsigned int D2, class R1>
inline std::ostream& operator<<(std::ostream& os, const Expr<A,T,D1,D2,R1>& rhs) {
  return rhs.print(os);
}

/** BinaryOp.
    A class representing binary operators in the parse tree.

    @memo BinaryOp
    @author <NAME>
*/
//==============================================================================
// BinaryOp
//==============================================================================
template <class Operator, class LHS, class RHS, class T>
class BinaryOp {
public:
  ///
  BinaryOp( Operator /* op */, const LHS& lhs, const RHS& rhs) :
    lhs_(lhs), rhs_(rhs) {}

  ///
  ~BinaryOp() {}

  ///
  inline T apply(unsigned int i) const {
    return Operator::apply(lhs_.apply(i), rhs_.apply(i));
  }
  inline T apply(unsigned int i, unsigned int j) const {
    return Operator::apply(lhs_.apply(i,j), rhs_.apply(i,j));
  }

protected:

#ifdef SMATRIX_USE_REFERENCES
  const LHS& lhs_;
  const RHS& rhs_;
#else
  const LHS lhs_;
  const RHS rhs_;
#endif

};


/** UnaryOp.
    A class representing unary operators in the parse tree.

    @memo UnaryOp
    @author <NAME>
*/
//==============================================================================
// UnaryOp
//==============================================================================
template <class Operator, class RHS, class T>
class UnaryOp {
public:
  ///
  UnaryOp( Operator /* op */ , const RHS& rhs) :
    rhs_(rhs) {}

  ///
  ~UnaryOp() {}
  
  ///
  inline T apply(unsigned int i) const {
    return Operator::apply(rhs_.apply(i));
  }
  inline T apply(unsigned int i, unsigned int j) const {
    return Operator::apply(rhs_.apply(i,j));
  }

protected:

#ifdef SMATRIX_USE_REFERENCES
  const RHS& rhs_;
#else
  const RHS rhs_;
#endif

};


/** Constant.
    A class representing constant expressions (literals) in the parse tree.

    @memo Constant
    @author <NAME>
*/
//==============================================================================
// Constant
//==============================================================================
template <class T>
class Constant {
public:
  ///
  Constant( const T& rhs ) :
    rhs_(rhs) {}

  ///
  ~Constant() {}

  ///
  inline T apply(unsigned int /*i */ ) const { return rhs_; }

  inline T apply(unsigned int /*i */, unsigned int /*j */ ) const { return rhs_; }

protected:

#ifdef SMATRIX_USE_REFERENCES
  const T& rhs_;
#else
  const T rhs_;
#endif

};



  }  // namespace Math

}  // namespace ROOT
          


#endif  /* ROOT_Math_Expression */

{'fraction_non_alphanumeric': 0.26685331172180066, 'fraction_numerical': 0.014514108892654535, 'mean_word_length': 2.8882841592666857, 'pattern_counts': {'":': 0, '<': 136, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6485999', 'n_tokens_mistral': 4492, 'n_tokens_neox': 4152, 'n_words': 1263}