CppADCodeGen  HEAD
A C++ Algorithmic Differentiation Package with Source Code Generation
CppAD::cg::LanguageMathML< Base > Class Template Reference
Inheritance diagram for CppAD::cg::LanguageMathML< Base >:
Inheritance graph
Collaboration diagram for CppAD::cg::LanguageMathML< Base >:
Collaboration graph

Public Types

using Node = OperationNode< Base >
 
using Arg = Argument< Base >
 

Public Member Functions

 LanguageMathML ()
 
const std::string & getAssignMarkup () const
 
void setAssignMarkup (const std::string &assign)
 
const std::string & getAddAssignMarkup () const
 
void setAddAssignMarkup (const std::string &assignAdd)
 
const std::string & getMultiplicationMarkup () const
 
void setMultiplicationMarkup (const std::string &multOpStr)
 
const std::string & getMultiplicationConstParMarkup () const
 
void setMultiplicationConstParMarkup (const std::string &multValOpStr)
 
bool isIgnoreZeroDepAssign () const
 
void setIgnoreZeroDepAssign (bool ignore)
 
void setFilename (const std::string &name)
 
void setStyle (const std::string &style)
 
const std::string & getStyle () const
 
void setJavascript (const std::string &javascript)
 
const std::string & getJavascript () const
 
void setHeadExtraMarkup (const std::string &headExtra)
 
const std::string & getHeadExtraMarkup () const
 
virtual void setEquationMarkup (const std::string &begin, const std::string &end)
 
virtual const std::string & getEquationStartMarkup () const
 
virtual const std::string & getEquationEndMarkup () const
 
virtual void setForMarkup (const std::string &begin, const std::string &end)
 
virtual const std::string & getForStartMarkup () const
 
virtual const std::string & getForEndMarkup () const
 
virtual void setIfMarkup (const std::string &begin, const std::string &end)
 
virtual const std::string & getIfStartMarkup () const
 
virtual const std::string & getIfEndMarkup () const
 
virtual void setElseIfMarkup (const std::string &begin, const std::string &end)
 
virtual const std::string & getElseIfStartMarkup () const
 
virtual const std::string & getElseIfEndMarkup () const
 
virtual void setElseMarkup (const std::string &begin, const std::string &end)
 
virtual const std::string & getElseStartMarkup () const
 
virtual const std::string & getElseEndMarkup () const
 
virtual size_t getParameterPrecision () const
 
virtual void setParameterPrecision (size_t p)
 
virtual void setAlwaysEnclosePowBase (bool enclose)
 
virtual bool isAlwaysEnclosePowBase () const
 
virtual void setMaxAssignmentsPerFunction (size_t maxAssignmentsPerFunction, std::map< std::string, std::string > *sources)
 
void setSaveVariableRelations (bool save)
 
bool requiresVariableDependencies () const override
 
void printStaticIndexArray (std::ostringstream &os, const std::string &name, const std::vector< size_t > &values)
 
void printStaticIndexMatrix (std::ostringstream &os, const std::string &name, const std::map< size_t, std::map< size_t, size_t > > &values)
 
void printRandomIndexPatternDeclaration (std::ostringstream &os, const std::string &identation, const std::set< RandomIndexPattern *> &randomPatterns)
 

Static Public Member Functions

static void printIndexCondExpr (std::ostringstream &out, const std::vector< size_t > &info, const std::string &index)
 
static void generateNames4RandomIndexPatterns (const std::set< RandomIndexPattern *> &randomPatterns)
 
static void indexPattern2String (std::ostream &os, const IndexPattern &ip, const Node &index)
 
static void indexPattern2String (std::ostream &os, const IndexPattern &ip, const std::vector< const Node *> &indexes)
 
static void linearIndexPattern2String (std::ostream &os, const LinearIndexPattern &lip, const Node &index)
 

Protected Member Functions

void generateSourceCode (std::ostream &out, std::unique_ptr< LanguageGenerationData< Base > > info) override
 
size_t getVariableID (const Node &node) const
 
virtual void printAlgorithmFileStart (std::ostream &out)
 
virtual void printAlgorithmFileEnd (std::ostream &out)
 
unsigned printAssignment (Node &node)
 
unsigned printAssignment (Node &nodeName, const Arg &nodeRhs)
 
unsigned printAssignment (Node &nodeName, Node &nodeRhs)
 
virtual void printAssignmentStart (Node &op)
 
virtual void printAssignmentStart (Node &node, const std::string &varName, bool isDep)
 
virtual void printAssignmentEnd ()
 
virtual void printAssignmentEnd (Node &op)
 
virtual void saveLocalFunction (std::vector< std::string > &localFuncNames, bool zeroDependentArray)
 
bool createsNewVariable (const Node &var, size_t totalUseCount, size_t opCount) const override
 
virtual bool requiresVariableName (const Node &var) const
 
virtual bool directlyAssignsVariable (const Node &var) const
 
bool requiresVariableArgument (enum CGOpCode op, size_t argIndex) const override
 
const std::string & createVariableName (Node &var)
 
size_t getHtmlID (const Node &var) const
 
std::string createHtmlID (const Node *var)
 
virtual std::string createHtmlID (const Node &var)
 
virtual void printIndependentVariableName (Node &op)
 
virtual unsigned print (const Arg &arg)
 
virtual unsigned printExpression (Node &node)
 
virtual unsigned printExpressionNoVarCheck (Node &node)
 
virtual unsigned printAssignOp (Node &node)
 
virtual void printUnaryFunction (Node &op)
 
virtual void printPowFunction (Node &op)
 
virtual unsigned printOperationAlias (Node &op)
 
virtual void printOperationAdd (Node &op)
 
virtual void printOperationMinus (Node &op)
 
virtual void printOperationDiv (Node &op)
 
bool encloseInParenthesesMul (const Arg &arg) const
 
bool encloseInParenthesesMul (const Node *node) const
 
virtual void printOperationMul (Node &op)
 
virtual void printOperationUnaryMinus (Node &op)
 
virtual void printConditionalAssignment (Node &node)
 
bool isSameArgument (const Arg &newArg, const Arg *oldArg)
 
virtual void printArrayCreationOp (Node &op)
 
virtual void printSparseArrayCreationOp (Node &op)
 
void printArrayStructInit (const std::string &dataArrayName, size_t pos, const std::vector< Node *> &arrays, size_t k)
 
void printArrayStructInit (const std::string &dataArrayName, Node &array)
 
void markArrayChanged (Node &ty)
 
size_t printArrayCreationUsingLoop (size_t startPos, Node &array, size_t startj, std::vector< const Arg *> &tmpArrayValues)
 
std::string getTempArrayName (const Node &op)
 
virtual void printArrayElementOp (Node &op)
 
virtual void printAtomicForwardOp (Node &atomicFor)
 
virtual void printAtomicReverseOp (Node &atomicRev)
 
virtual unsigned printDependentMultiAssign (Node &node)
 
virtual void printLoopStart (Node &node)
 
virtual void printLoopEnd (Node &node)
 
virtual void printLoopIndexedDep (Node &node)
 
virtual void printLoopIndexedIndep (Node &node)
 
virtual void printLoopIndexedTmp (Node &node)
 
virtual void printTmpVar (Node &node)
 
virtual void printIndexAssign (Node &node)
 
virtual void printIndexCondExprOp (Node &node)
 
virtual void printStartIf (Node &node)
 
virtual void printElseIf (Node &node)
 
virtual void printElse (Node &node)
 
virtual void printEndIf (Node &node)
 
virtual void printCondResult (Node &node)
 
virtual void printUserCustom (Node &node)
 
bool isDependent (const Node &arg) const
 
virtual void printParameter (const Base &value)
 
virtual void getComparison (std::ostream &os, enum CGOpCode op) const
 

Static Protected Member Functions

static bool isFunction (enum CGOpCode op)
 
static bool isUnaryFunction (enum CGOpCode op)
 
static bool isCondAssign (enum CGOpCode op)
 

Protected Attributes

LanguageGenerationData< Base > * _info
 
size_t _indentationLevel
 
std::string _style
 
std::string _javascript
 
std::string _headExtra
 
std::string _startEq
 
std::string _endEq
 
std::string _forStart
 
std::string _forEnd
 
std::string _forBodyStart
 
std::string _forBodyEnd
 
std::string _ifStart
 
std::string _ifEnd
 
std::string _elseIfStart
 
std::string _elseIfEnd
 
std::string _elseStart
 
std::string _elseEnd
 
std::string _condBodyStart
 
std::string _condBodyEnd
 
std::string _assignStr
 
std::string _assignAddStr
 
std::string _multOpStr
 
std::string _multValOpStr
 
std::string _endline
 
std::ostringstream _code
 
VariableNameGenerator< Base > * _nameGen
 
std::ostringstream _ss
 
size_t _independentSize
 
size_t _minTemporaryVarID
 
std::map< size_t, size_t > _dependentIDs
 
const ArrayView< CG< Base > > * _dependent
 
bool _ignoreZeroDepAssign
 
std::string _filename
 
size_t _maxAssignmentsPerFile
 
std::map< std::string, std::string > * _sources
 
std::vector< const Arg * > _tmpArrayValues
 
std::vector< const Arg * > _tmpSparseArrayValues
 
std::vector< const LoopStartOperationNode< Base > * > _currentLoops
 
size_t _parameterPrecision
 
bool _powBaseEnclose
 
bool _saveVariableRelations
 

Static Protected Attributes

static const std::string _C_STATIC_INDEX_ARRAY = "index"
 
static const std::string _C_SPARSE_INDEX_ARRAY = "idx"
 
static const std::string _ATOMIC_TX = "atx"
 
static const std::string _ATOMIC_TY = "aty"
 
static const std::string _ATOMIC_PX = "apx"
 
static const std::string _ATOMIC_PY = "apy"
 

Detailed Description

template<class Base>
class CppAD::cg::LanguageMathML< Base >

Generates presentation markup using the html and MathML specification.

Author
Joao Leal

Definition at line 28 of file language_mathml.hpp.

Constructor & Destructor Documentation

◆ LanguageMathML()

template<class Base >
CppAD::cg::LanguageMathML< Base >::LanguageMathML ( )
inline

Creates a MathML language source code generator

Definition at line 117 of file language_mathml.hpp.

Member Function Documentation

◆ createHtmlID() [1/2]

template<class Base >
std::string CppAD::cg::LanguageMathML< Base >::createHtmlID ( const Node var)
inlineprotected

Creates an HTML ID for the usage of a variable in particular place in the HTML

Definition at line 1144 of file language_mathml.hpp.

Referenced by CppAD::cg::LanguageMathML< Base >::createHtmlID().

◆ createHtmlID() [2/2]

template<class Base >
virtual std::string CppAD::cg::LanguageMathML< Base >::createHtmlID ( const Node var)
inlineprotectedvirtual

Creates an HTML ID for the usage of a variable in particular place in the HTML

Definition at line 1151 of file language_mathml.hpp.

◆ createsNewVariable()

template<class Base >
bool CppAD::cg::LanguageMathML< Base >::createsNewVariable ( const Node op,
size_t  totalUseCount,
size_t  opCount 
) const
inlineoverrideprotectedvirtual

Whether or not a new variable is created as a result of this operation

Parameters
opOperation
totalUseCountthe number of times this node has been used as an argument in other operations
Returns
true if a new variable is created

Implements CppAD::cg::Language< Base >.

Definition at line 1005 of file language_mathml.hpp.

◆ directlyAssignsVariable()

template<class Base >
virtual bool CppAD::cg::LanguageMathML< Base >::directlyAssignsVariable ( const Node var) const
inlineprotectedvirtual

Whether or not this operation assign its expression to a variable by itself.

Parameters
varthe operation node
Returns

Definition at line 1055 of file language_mathml.hpp.

◆ generateSourceCode()

template<class Base >
void CppAD::cg::LanguageMathML< Base >::generateSourceCode ( std::ostream &  out,
std::unique_ptr< LanguageGenerationData< Base > >  info 
)
inlineoverrideprotectedvirtual

generate index array names (might be used for variable names)

generate variable names

function variable declaration

Determine the dependent variables that result from the same operations

non-constant variables

Source code generation magic!

Create the master html file which inputs the other files

encapsulate the code in a function

Implements CppAD::cg::Language< Base >.

Definition at line 535 of file language_mathml.hpp.

◆ getElseEndMarkup()

template<class Base >
virtual const std::string& CppAD::cg::LanguageMathML< Base >::getElseEndMarkup ( ) const
inlinevirtual

Provides the markup after each else.

Definition at line 401 of file language_mathml.hpp.

◆ getElseIfEndMarkup()

template<class Base >
virtual const std::string& CppAD::cg::LanguageMathML< Base >::getElseIfEndMarkup ( ) const
inlinevirtual

Provides the markup after each else if.

Definition at line 375 of file language_mathml.hpp.

◆ getElseIfStartMarkup()

template<class Base >
virtual const std::string& CppAD::cg::LanguageMathML< Base >::getElseIfStartMarkup ( ) const
inlinevirtual

Provides the markup preceding each else if.

Definition at line 368 of file language_mathml.hpp.

◆ getElseStartMarkup()

template<class Base >
virtual const std::string& CppAD::cg::LanguageMathML< Base >::getElseStartMarkup ( ) const
inlinevirtual

Provides the markup preceding each else.

Definition at line 394 of file language_mathml.hpp.

◆ getEquationEndMarkup()

template<class Base >
virtual const std::string& CppAD::cg::LanguageMathML< Base >::getEquationEndMarkup ( ) const
inlinevirtual

Provides the markup after each equation.

Definition at line 297 of file language_mathml.hpp.

◆ getEquationStartMarkup()

template<class Base >
virtual const std::string& CppAD::cg::LanguageMathML< Base >::getEquationStartMarkup ( ) const
inlinevirtual

Provides the markup preceding each equation.

Definition at line 290 of file language_mathml.hpp.

◆ getForEndMarkup()

template<class Base >
virtual const std::string& CppAD::cg::LanguageMathML< Base >::getForEndMarkup ( ) const
inlinevirtual

Provides the markup after each loop.

Definition at line 323 of file language_mathml.hpp.

◆ getForStartMarkup()

template<class Base >
virtual const std::string& CppAD::cg::LanguageMathML< Base >::getForStartMarkup ( ) const
inlinevirtual

Provides the markup preceding each loop.

Definition at line 316 of file language_mathml.hpp.

◆ getHtmlID()

template<class Base >
size_t CppAD::cg::LanguageMathML< Base >::getHtmlID ( const Node var) const
inlineprotected

The base HTML ID for a node

Definition at line 1137 of file language_mathml.hpp.

Referenced by CppAD::cg::LanguageMathML< Base >::createHtmlID().

◆ getIfEndMarkup()

template<class Base >
virtual const std::string& CppAD::cg::LanguageMathML< Base >::getIfEndMarkup ( ) const
inlinevirtual

Provides the markup after each If.

Definition at line 349 of file language_mathml.hpp.

◆ getIfStartMarkup()

template<class Base >
virtual const std::string& CppAD::cg::LanguageMathML< Base >::getIfStartMarkup ( ) const
inlinevirtual

Provides the markup preceding each If.

Definition at line 342 of file language_mathml.hpp.

◆ getMultiplicationConstParMarkup()

template<class Base >
const std::string& CppAD::cg::LanguageMathML< Base >::getMultiplicationConstParMarkup ( ) const
inline

Provides the mathml markup used for multiplications of constant parameters. The default is <mo>×</mo>.

Definition at line 208 of file language_mathml.hpp.

◆ getMultiplicationMarkup()

template<class Base >
const std::string& CppAD::cg::LanguageMathML< Base >::getMultiplicationMarkup ( ) const
inline

Provides the mathml markup used to define multiplications. The default is <mo></mo>.

Note
Multiplications of constant parameters use a different multiplication markup string

Definition at line 187 of file language_mathml.hpp.

◆ getParameterPrecision()

template<class Base >
virtual size_t CppAD::cg::LanguageMathML< Base >::getParameterPrecision ( ) const
inlinevirtual

Provides the maximum precision used to print constant values in the generated source code

Returns
the maximum number of digits

Definition at line 411 of file language_mathml.hpp.

◆ isAlwaysEnclosePowBase()

template<class Base >
virtual bool CppAD::cg::LanguageMathML< Base >::isAlwaysEnclosePowBase ( ) const
inlinevirtual

Whether or not to always enclose the base of a power within parenthesis.

Returns
true if the base is always enclosed within parenthesis

Definition at line 443 of file language_mathml.hpp.

◆ printArrayCreationUsingLoop()

template<class Base >
size_t CppAD::cg::LanguageMathML< Base >::printArrayCreationUsingLoop ( size_t  startPos,
Node array,
size_t  startj,
std::vector< const Arg *> &  tmpArrayValues 
)
inlineprotected

from independents array

from independents array in a loop

constant value?

print the loop

update values in the global temporary array

Definition at line 139 of file language_mathml_arrays.hpp.

◆ printArrayStructInit()

template<class Base >
void CppAD::cg::LanguageMathML< Base >::printArrayStructInit ( const std::string &  dataArrayName,
Node array 
)
inlineprotected

TODO: finish this

Definition at line 322 of file language_mathml_arrays.hpp.

◆ printAtomicForwardOp()

template<class Base >
virtual void CppAD::cg::LanguageMathML< Base >::printAtomicForwardOp ( Node atomicFor)
inlineprotectedvirtual

the values of ty are now changed

Definition at line 1719 of file language_mathml.hpp.

◆ printAtomicReverseOp()

template<class Base >
virtual void CppAD::cg::LanguageMathML< Base >::printAtomicReverseOp ( Node atomicRev)
inlineprotectedvirtual

the values of px are now changed

Definition at line 1762 of file language_mathml.hpp.

◆ printElse()

template<class Base >
virtual void CppAD::cg::LanguageMathML< Base >::printElse ( Node node)
inlineprotectedvirtual

the first argument is the if start node, the following arguments are assignments in the previous if branch

Definition at line 1984 of file language_mathml.hpp.

◆ printElseIf()

template<class Base >
virtual void CppAD::cg::LanguageMathML< Base >::printElseIf ( Node node)
inlineprotectedvirtual

the first argument is the condition, the second argument is the if start node, the following arguments are assignments in the previous if branch

Definition at line 1952 of file language_mathml.hpp.

◆ printRandomIndexPatternDeclaration()

template<class Base >
void CppAD::cg::LanguageMathML< Base >::printRandomIndexPatternDeclaration ( std::ostringstream &  os,
const std::string &  identation,
const std::set< RandomIndexPattern *> &  randomPatterns 
)
inline

◆ printStartIf()

template<class Base >
virtual void CppAD::cg::LanguageMathML< Base >::printStartIf ( Node node)
inlineprotectedvirtual

the first argument is the condition, following arguments are just extra dependencies that must be defined outside the if

Definition at line 1934 of file language_mathml.hpp.

◆ printStaticIndexMatrix()

template<class Base >
void CppAD::cg::LanguageMathML< Base >::printStaticIndexMatrix ( std::ostringstream &  os,
const std::string &  name,
const std::map< size_t, std::map< size_t, size_t > > &  values 
)
inline

◆ requiresVariableDependencies()

template<class Base >
bool CppAD::cg::LanguageMathML< Base >::requiresVariableDependencies ( ) const
inlineoverridevirtual

Whether or not this language can use information regarding the dependencies between different equations/variables.

Implements CppAD::cg::Language< Base >.

Definition at line 457 of file language_mathml.hpp.

◆ setAlwaysEnclosePowBase()

template<class Base >
virtual void CppAD::cg::LanguageMathML< Base >::setAlwaysEnclosePowBase ( bool  enclose)
inlinevirtual

Defines whether or not to always enclose the base of a power within parenthesis. By default the base is only enclosed in parenthesis if it contains of a mathematical expression.

Parameters
enclosetrue to always enclose the base in parenthesis

Definition at line 433 of file language_mathml.hpp.

◆ setElseIfMarkup()

template<class Base >
virtual void CppAD::cg::LanguageMathML< Base >::setElseIfMarkup ( const std::string &  begin,
const std::string &  end 
)
inlinevirtual

Defines the surrounding markup for each else if.

Parameters
beginthe opening html markup
endthe closing html markup

Definition at line 359 of file language_mathml.hpp.

◆ setElseMarkup()

template<class Base >
virtual void CppAD::cg::LanguageMathML< Base >::setElseMarkup ( const std::string &  begin,
const std::string &  end 
)
inlinevirtual

Defines the surrounding markup for each else.

Parameters
beginthe opening html markup
endthe closing html markup

Definition at line 385 of file language_mathml.hpp.

◆ setEquationMarkup()

template<class Base >
virtual void CppAD::cg::LanguageMathML< Base >::setEquationMarkup ( const std::string &  begin,
const std::string &  end 
)
inlinevirtual

Defines the surrounding markup for each equation.

Parameters
beginthe opening html markup
endthe closing html markup

Definition at line 281 of file language_mathml.hpp.

◆ setForMarkup()

template<class Base >
virtual void CppAD::cg::LanguageMathML< Base >::setForMarkup ( const std::string &  begin,
const std::string &  end 
)
inlinevirtual

Defines the surrounding markup for each for loop.

Parameters
beginthe opening html markup
endthe closing html markup

Definition at line 307 of file language_mathml.hpp.

◆ setHeadExtraMarkup()

template<class Base >
void CppAD::cg::LanguageMathML< Base >::setHeadExtraMarkup ( const std::string &  headExtra)
inline

Defines additional markup to be added to head section of the html document.

Parameters
headExtrahtml markup to be added to the head section

Definition at line 267 of file language_mathml.hpp.

◆ setIfMarkup()

template<class Base >
virtual void CppAD::cg::LanguageMathML< Base >::setIfMarkup ( const std::string &  begin,
const std::string &  end 
)
inlinevirtual

Defines the surrounding markup for each If.

Parameters
beginthe opening html markup
endthe closing html markup

Definition at line 333 of file language_mathml.hpp.

◆ setJavascript()

template<class Base >
void CppAD::cg::LanguageMathML< Base >::setJavascript ( const std::string &  javascript)
inline

Defines Javascript source code to be added to head section of the html document.

Parameters
javascriptthe Javascript source code

Definition at line 254 of file language_mathml.hpp.

◆ setMultiplicationConstParMarkup()

template<class Base >
void CppAD::cg::LanguageMathML< Base >::setMultiplicationConstParMarkup ( const std::string &  multValOpStr)
inline

Defines the mathml markup used for multiplications of constant parameters. The default is <mo>×</mo>. Another common alternative is "<mo>&sdot;</mo>". Please take into account that numbers too close together are difficult to distinguish.

Definition at line 220 of file language_mathml.hpp.

◆ setMultiplicationMarkup()

template<class Base >
void CppAD::cg::LanguageMathML< Base >::setMultiplicationMarkup ( const std::string &  multOpStr)
inline

Defines the mathml markup used for multiplications. The default is <mo></mo>. Other common alternatives are "<mo>&sdot;</mo>" and "<mo>&times;</mo>".

Note
Multiplications of constant parameters use a different multiplication markup string

Definition at line 199 of file language_mathml.hpp.

◆ setParameterPrecision()

template<class Base >
virtual void CppAD::cg::LanguageMathML< Base >::setParameterPrecision ( size_t  p)
inlinevirtual

Defines the maximum precision used to print constant values in the generated source code

Parameters
pthe maximum number of digits

Definition at line 421 of file language_mathml.hpp.

◆ setStyle()

template<class Base >
void CppAD::cg::LanguageMathML< Base >::setStyle ( const std::string &  style)
inline

Defines the CSS style to be added to head section of the html document.

Parameters
stylethe content of the CSS

Definition at line 241 of file language_mathml.hpp.


The documentation for this class was generated from the following files: