Skip to content

Commit

Permalink
Merge branch 'mpd'
Browse files Browse the repository at this point in the history
  • Loading branch information
deseilligny committed Mar 15, 2024
2 parents 78d2032 + d75409a commit 82c3ca2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
24 changes: 20 additions & 4 deletions MMVII/include/MMVII_Ptxd.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,19 @@ template <class Type,const int Dim> class cPtxd

inline Type & x() {static_assert(Dim>=1,"bad dim in cPtxd initializer");return mCoords[0];}
inline const Type & x() const {static_assert(Dim>=1,"bad dim in cPtxd initializer");return mCoords[0];}
inline tBigNum BigX2() const {return Square(tBigNum(x()));}

inline Type & y() {static_assert(Dim>=2,"bad dim in cPtxd initializer");return mCoords[1];}
inline const Type & y() const {static_assert(Dim>=2,"bad dim in cPtxd initializer");return mCoords[1];}
inline tBigNum BigY2() const {return Square(tBigNum(y()));}

inline Type & z() {static_assert(Dim>=3,"bad dim in cPtxd initializer");return mCoords[2];}
inline const Type & z() const {static_assert(Dim>=3,"bad dim in cPtxd initializer");return mCoords[2];}
inline tBigNum BigZ2() const {return Square(tBigNum(z()));}

inline Type & t() {static_assert(Dim>=4,"bad dim in cPtxd initializer");return mCoords[3];}
inline const Type & t() const {static_assert(Dim>=4,"bad dim in cPtxd initializer");return mCoords[3];}
inline tBigNum BigT2() const {return Square(tBigNum(t()));}

cDenseVect<Type> ToVect() const; ///< conversion
std::vector<Type> ToStdVector() const; ///< conversion
Expand Down Expand Up @@ -395,10 +399,22 @@ template <class T> inline T NormInf(const cPtxd<T,2> & aP) {return std::max(std:
// template <class T> inline T SqN2(const cPtxd<T,1> & aP) {return Square(aP.x());}
*/
/// Currently, the L2 norm is used for comparaison, no need to extract square root
template <class T> inline typename tNumTrait<T>::tBig SqN2(const cPtxd<T,1> & aP) {return Square(aP.x());}
template <class T> inline typename tNumTrait<T>::tBig SqN2(const cPtxd<T,2> & aP) {return Square(aP.x())+Square(aP.y());}
template <class T> inline typename tNumTrait<T>::tBig SqN2(const cPtxd<T,3> & aP) {return Square(aP.x())+Square(aP.y())+Square(aP.z());}
template <class T> inline typename tNumTrait<T>::tBig SqN2(const cPtxd<T,4> & aP) {return Square(aP.x())+Square(aP.y())+Square(aP.z()) + Square(aP.t()) ;}
template <class T> inline typename tNumTrait<T>::tBig SqN2(const cPtxd<T,1> & aP)
{
return aP.BigX2();
}
template <class T> inline typename tNumTrait<T>::tBig SqN2(const cPtxd<T,2> & aP)
{
return aP.BigX2() + aP.BigY2();
}
template <class T> inline typename tNumTrait<T>::tBig SqN2(const cPtxd<T,3> & aP)
{
return aP.BigX2() + aP.BigY2() + aP.BigZ2();
}
template <class T> inline typename tNumTrait<T>::tBig SqN2(const cPtxd<T,4> & aP)
{
return aP.BigX2() + aP.BigY2() + aP.BigZ2() + aP.BigT2() ;
}
/// Sort vector by norm, typically dont need to compute square root
template <class Type,const int Dim> bool CmpN2(const cPtxd<Type,Dim> &aP1,const cPtxd<Type,Dim> & aP2)
{
Expand Down
2 changes: 2 additions & 0 deletions MMVII/include/SymbDer/SymbDer_BinaryOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ template <class TypeElem> class cBinaryF : public cImplemF<TypeElem>
InternalError("No operation defined",aV1->CoordF()->Name());
return aV1;
}

std::string Name4Print() const override {return this->NameOperator();}
protected :
void AssocSortedVect(std::vector<tFormula> & aV);
void EmpileAssoc (const cFormula <TypeElem>& aF, std::vector<tFormula > & aV);
Expand Down
1 change: 1 addition & 0 deletions MMVII/include/SymbDer/SymbDer_UnaryOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ template <class TypeElem> class cUnaryF : public cImplemF<TypeElem>
{
return this->NameOperator() + " "+ mF->InfixPPrint() + PostName() ;
}
std::string Name4Print() const override {return this->NameOperator();}

protected :
virtual std::string GenCodeExpr() const override
Expand Down
39 changes: 37 additions & 2 deletions MMVII/include/SymbDer/SymbolicDerivatives.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ template <class TypeElem> class cImplemF : public SYMBDER_cMemCheck

/// Access at global level is 4 reducing, also it is used 4 implemant in Unary & Binary
virtual const std::string & NameOperator() const = 0;
/// Name for pretty print
virtual std::string Name4Print() const = 0;


// -------------------- Destructor / Constructor --------------------------
Expand Down Expand Up @@ -655,7 +657,8 @@ template <class TypeElem> class cAtomicF : public cImplemF<TypeElem>
typedef typename tCoordF::tFormula tFormula;

/// Should work always
std::string InfixPPrint() const override {return tImplemF::Name();}
// std::string InfixPPrint() const override {return tImplemF::Name();}
std::string InfixPPrint() const override {return this->Name4Print();}
/// Rule deriv=0 , work by default (constant and observations)
tFormula Derivate(int aK) const override {return tImplemF::mCoordF->Cste0();}

Expand All @@ -682,8 +685,9 @@ template <class TypeElem> class cUnknownF : public cAtomicF<TypeElem>
typedef typename tCoordF::tFormula tFormula;

const std::string & NameOperator() const override {static std::string s("UK"); return s;}
std::string Name4Print() const override {return tImplemF::Name() +"_UK";}

std::string InfixPPrint() const override {return tImplemF::Name();}
// std::string InfixPPrint() const override {return tImplemF::Name();} All ready overided
/// rule : dXi/dXj = delta(i,j)
tFormula Derivate(int aK) const override
{
Expand Down Expand Up @@ -712,6 +716,8 @@ template <class TypeElem> class cObservationF : public cAtomicF<TypeElem>
friend tCoordF;

const std::string & NameOperator() const override {static std::string s("Obs"); return s;}
std::string Name4Print() const override {return tImplemF::Name() +"_Obs";}
// const std::string & NameOperator() const override {return tImplemF::Name() +"-Obs";}
private :
inline cObservationF(tCoordF * aCoordF,const std::string & aName,int aNum) :
tAtom (aCoordF,aName),
Expand All @@ -735,6 +741,7 @@ template <class TypeElem> class cConstantF : public cAtomicF<TypeElem>
bool IsCste(const TypeElem &K) const override {return mVal==K;} ///< Here we know if we are a constant of value K
const TypeElem * ValCste() const override {return &mVal;}
const std::string & NameOperator() const override {static std::string s("Cste"); return s;}
std::string Name4Print() const override {return std::to_string(mVal) +"_Cste";}
protected :
inline cConstantF(tCoordF * aCoordF,const std::string & aName,int aNum,const TypeElem& aVal) :
tAtom (aCoordF,aName),
Expand Down Expand Up @@ -1271,6 +1278,34 @@ inline const cFormula<TypeElem> SymbCommentDer(const cFormula<TypeElem> & aF, in
}



template <class TypeElem> void StdShowTreeFormulaRec(const cFormula<TypeElem>& aF,int aMaxPerL,int aLevel)
{

// StdOut() << aF->GenCodeFormName() << std::endl;
// StdOut() << aF->GenCodeExpr() << std::endl;
for (int aK=0 ; aK < aLevel ; aK++)
{
std::cout << " ";
}
if (aF->RecursiveRec() < aMaxPerL)
{
std::cout << aF->InfixPPrint() << std::endl;
}
else
{
std::cout << aF->Name4Print() << std::endl;
for (auto aChild : aF->Ref())
StdShowTreeFormulaRec(aChild,aMaxPerL,aLevel+1);
}
}
template <class TypeElem> void StdShowTreeFormula(const cFormula<TypeElem>& aF,int aMaxPerL=7)
{
StdShowTreeFormulaRec(aF,aMaxPerL,0);
}



} // namespace NS_SymbolicDerivative


Expand Down

0 comments on commit 82c3ca2

Please sign in to comment.