DiSMEC++
|
An Eigen vector with versioning information, to implement simple caching of results. More...
#include <hash_vector.h>
Public Member Functions | |
HashVector (DenseRealVector data) | |
Creates a new hash vector from the given DenseRealVector. More... | |
const DenseRealVector & | get () const |
Gets a constant reference to the data of this vector. More... | |
const DenseRealVector * | operator-> () const |
constant access to vector data. More... | |
VectorHash | hash () const |
Gets the unique id of this vector. More... | |
template<class Derived > | |
HashVector & | operator= (const Eigen::EigenBase< Derived > &expr) |
Update the contents of this vector. More... | |
DenseRealVector & | modify () |
Gets non-const access to the underlying data. More... | |
Private Member Functions | |
void | update_id () |
Private Attributes | |
std::size_t | m_UniqueID |
DenseRealVector | m_Data |
An Eigen vector with versioning information, to implement simple caching of results.
This class wraps an Eigen::Vector and adds an additional data field m_UniqueID
. This field contains a unique number for each new HashVector created, and is updated whenever a potentially modifying operation is performed on the vector.
The unique id can be queried using the hash() function, which returns a VectorHash() object. The only purpose of this is to enable checks of whether a function is called with a vector argument that is the same as a previous call, without having to store and compare the contents of the vector. This works as follows (if cached
doesn't need to be re-entrant):
The default-initialized VectorHash compares unequal to all other hash values.
Definition at line 43 of file hash_vector.h.
|
explicit |
Creates a new hash vector from the given DenseRealVector.
This moves the content from data
into the newly created HashVector
and generates a new unique id.
Definition at line 36 of file hash_vector.cpp.
|
inline |
Gets a constant reference to the data of this vector.
This is a non-modifying operation, so the id remains unchanged.
Definition at line 57 of file hash_vector.h.
References m_Data.
Referenced by dismec::objective::DenseAndSparseLinearBase::diag_preconditioner_unchecked(), dismec::objective::DenseAndSparseLinearBase::gradient_and_pre_conditioner_unchecked(), dismec::objective::DenseAndSparseLinearBase::gradient_unchecked(), dismec::objective::DenseAndSparseLinearBase::hessian_times_direction_unchecked(), dismec::operator*(), dismec::operator*=(), dismec::operator+(), dismec::operator+=(), dismec::objective::DenseAndSparseLinearBase::project_linear_to_line(), dismec::objective::PointWiseRegularizer< CRTP >::project_to_line_unchecked(), dismec::solvers::NewtonWithLineSearch::record_iteration(), dismec::solvers::NewtonWithLineSearch::run(), TEST_CASE(), dismec::CacheHelper::update(), dismec::objective::DenseAndSparseLinearBase::value_unchecked(), and dismec::objective::DenseAndSparseLinearBase::x_times_w().
VectorHash HashVector::hash | ( | ) | const |
Gets the unique id of this vector.
This gets a unique id that is different from those of all other HashVector objects. This function returns the same value until a modifying operation is performed with the vector. Thus, for a given HashVector vec
:
Definition at line 45 of file hash_vector.cpp.
References m_UniqueID.
Referenced by dismec::objective::Regularized_SquaredHingeSVC::margin_error(), TEST_CASE(), dismec::CacheHelper::update(), dismec::objective::DenseAndSparseLinearBase::update_xtw_cache(), dismec::objective::LinearClassifierBase::update_xtw_cache(), dismec::objective::DenseAndSparseLinearBase::x_times_w(), and dismec::objective::LinearClassifierBase::x_times_w().
|
inline |
Gets non-const access to the underlying data.
Since this can change the contents of the underlying vector, this updates this vectors unqiue id. However, note that you can store the returned reference, and modify the contents of the vector later on. Such changes cannot be detected, and will result in invalid unique ids.
Definition at line 98 of file hash_vector.h.
References m_Data, and update_id().
|
inline |
|
inline |
Update the contents of this vector.
Derived | The actual type of the Eigen expression.By accepting this in a templated version, we make sure that there are no unnecessary temporaries involved. |
expr | An eigen expression. |
Definition at line 86 of file hash_vector.h.
References m_Data, and update_id().
|
private |
Definition at line 41 of file hash_vector.cpp.
References anonymous_namespace{hash_vector.cpp}::get_next_id(), and m_UniqueID.
Referenced by modify(), and operator=().
|
private |
Definition at line 106 of file hash_vector.h.
Referenced by get(), modify(), operator->(), and operator=().
|
private |
Definition at line 105 of file hash_vector.h.
Referenced by hash(), and update_id().