#include <IpTaggedObject.hpp>
Often, certain calculations or operations are expensive, and it can be very inefficient to perform these calculations again if the input to the calculation has not changed since the result was last stored. This base class provides an efficient mechanism to update a tag, indicating that the object has changed. Users of a TaggedObject class, need their own Tag data member to keep track of the state of the TaggedObject, the last time they performed a calculation. A basic use case for users of a class inheriting off of TaggedObject follows like this:
Initialize your own Tag to zero in constructor.
Before an expensive calculation, check if the TaggedObject has changed, passing in your own Tag, indicating the last time you used the object for the calculation. If it has changed, perform the calculation again, and store the result. If it has not changed, simply return the stored result.
Here is a simple example:
if (vector.HasChanged(my_vector_tag_)) { my_vector_tag_ = vector.GetTag(); result = PerformExpensiveCalculation(vector); return result; } else { return result; }
Objects derived from TaggedObject: Objects derived from TaggedObject must indicate that they have changed to the base class using the protected member function ObjectChanged(). For example, a Vector class, inside its own set method, MUST call ObjectChanged() to update the internally stored tag for comparison.
Public Types | |
typedef unsigned int | Tag |
Type for the Tag values. | |
Public Member Functions | |
TaggedObject () | |
Constructor. | |
virtual | ~TaggedObject () |
Destructor. | |
Tag | GetTag () const |
Users of TaggedObjects call this to update their own internal tags every time they perform the expensive operation. | |
bool | HasChanged (const Tag comparison_tag) const |
Users of TaggedObjects call this to check if the object HasChanged since they last updated their own internal tag. | |
Protected Member Functions | |
void | ObjectChanged () |
Objects derived from TaggedObject MUST call this method every time their internal state changes to update the internal tag for comparison. |
typedef unsigned int Tag |
Type for the Tag values.
TaggedObject | ( | ) | [inline] |
virtual ~TaggedObject | ( | ) | [inline, virtual] |
Destructor.
Tag GetTag | ( | ) | const [inline] |
Users of TaggedObjects call this to update their own internal tags every time they perform the expensive operation.
Referenced by Vector::Amax(), Vector::Asum(), Vector::Copy(), OrigIpoptNLP::f(), Vector::HasValidNumbers(), Matrix::HasValidNumbers(), Vector::Max(), Vector::Min(), TSymLinearSolver::MultiSolve(), StdAugSystemSolver::MultiSolve(), Vector::Nrm2(), Vector::Scal(), LowRankAugSystemSolver::Solve(), Vector::Sum(), and Vector::SumLogs().
bool HasChanged | ( | const Tag | comparison_tag | ) | const [inline] |
Users of TaggedObjects call this to check if the object HasChanged since they last updated their own internal tag.
Referenced by TSymLinearSolver::MultiSolve().
void ObjectChanged | ( | ) | [inline, protected] |
Objects derived from TaggedObject MUST call this method every time their internal state changes to update the internal tag for comparison.
References DBG_ASSERT, DBG_START_METH, SimTK::max(), Subject::Notify(), and Observer::NT_Changed.
Referenced by DenseSymMatrix::AddMatrix(), DenseGenMatrix::AddMatrixProduct(), MultiVectorMatrix::AddOneMultiVectorMatrix(), MultiVectorMatrix::AddRightMultMatrix(), Vector::AddScalar(), Vector::AddTwoVectors(), Vector::AddVectorQuotient(), Vector::Axpy(), DenseGenMatrix::ComputeCholeskyFactor(), DenseGenMatrix::ComputeEigenVectors(), Vector::Copy(), DenseGenMatrix::Copy(), DenseVector::CopyFromPos(), DenseVector::CopyToPos(), Vector::ElementWiseAbs(), Vector::ElementWiseDivide(), Vector::ElementWiseMax(), Vector::ElementWiseMin(), Vector::ElementWiseMultiply(), Vector::ElementWiseReciprocal(), Vector::ElementWiseSgn(), Vector::ElementWiseSqrt(), DenseSymMatrix::FillIdentity(), DenseGenMatrix::FillIdentity(), MultiVectorMatrix::FillWithNewVectors(), CompoundVector::GetCompNonConst(), CompoundSymMatrix::GetCompNonConst(), CompoundMatrix::GetCompNonConst(), SymScaledMatrix::GetUnscaledMatrixNonConst(), ScaledMatrix::GetUnscaledMatrixNonConst(), MultiVectorMatrix::GetVectorNonConst(), DenseSymMatrix::HighRankUpdate(), DenseSymMatrix::HighRankUpdateTranspose(), DenseGenMatrix::HighRankUpdateTranspose(), Vector::Scal(), MultiVectorMatrix::ScaleColumns(), DenseGenMatrix::ScaleColumns(), MultiVectorMatrix::ScaleRows(), Vector::Set(), CompoundVector::SetComp(), CompoundSymMatrix::SetComp(), CompoundMatrix::SetComp(), CompoundVector::SetCompNonConst(), CompoundSymMatrix::SetCompNonConst(), CompoundMatrix::SetCompNonConst(), LowRankUpdateSymMatrix::SetDiag(), LowRankUpdateSymMatrix::SetU(), SymScaledMatrix::SetUnscaledMatrix(), ScaledMatrix::SetUnscaledMatrix(), SymScaledMatrix::SetUnscaledMatrixNonConst(), ScaledMatrix::SetUnscaledMatrixNonConst(), LowRankUpdateSymMatrix::SetV(), SymTMatrix::SetValues(), GenTMatrix::SetValues(), DenseVector::SetValues(), MultiVectorMatrix::SetVector(), MultiVectorMatrix::SetVectorNonConst(), DenseSymMatrix::SpecialAddForLMSR1(), TaggedObject::TaggedObject(), SymTMatrix::Values(), GenTMatrix::Values(), DenseVector::Values(), DenseSymMatrix::Values(), and DenseGenMatrix::Values().