Factor: improve factor multiplication
Pass the argument as reference-to-const and also allow chaining of multiplications.
This commit is contained in:
parent
6da2580c8f
commit
a2e54a235a
@ -91,14 +91,16 @@ Factor::sumOutAllExceptIndex (size_t idx)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Factor::multiply (Factor& g)
|
||||
|
||||
Factor&
|
||||
Factor::multiply (const Factor& g)
|
||||
{
|
||||
if (args_.empty()) {
|
||||
*this = g;
|
||||
operator= (g);
|
||||
} else {
|
||||
GenericFactor<VarId>::multiply (g);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ class Factor : public GenericFactor<VarId> {
|
||||
|
||||
void sumOutAllExceptIndex (size_t idx);
|
||||
|
||||
void multiply (Factor&);
|
||||
Factor& multiply (const Factor&);
|
||||
|
||||
std::string getLabel() const;
|
||||
|
||||
|
@ -82,15 +82,15 @@ GenericFactor<T>::operator[] (size_t idx)
|
||||
|
||||
|
||||
|
||||
template <typename T> void
|
||||
GenericFactor<T>::multiply (GenericFactor<T>& g)
|
||||
template <typename T> GenericFactor<T>&
|
||||
GenericFactor<T>::multiply (const GenericFactor<T>& g)
|
||||
{
|
||||
if (args_ == g.arguments()) {
|
||||
// optimization
|
||||
Globals::logDomain
|
||||
? params_ += g.params()
|
||||
: params_ *= g.params();
|
||||
return;
|
||||
return *this;
|
||||
}
|
||||
unsigned range_prod = 1;
|
||||
bool share_arguments = false;
|
||||
@ -124,6 +124,7 @@ GenericFactor<T>::multiply (GenericFactor<T>& g)
|
||||
}
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
@ -49,7 +49,7 @@ class GenericFactor {
|
||||
|
||||
double& operator[] (size_t idx);
|
||||
|
||||
void multiply (GenericFactor<T>& g);
|
||||
GenericFactor<T>& multiply (const GenericFactor<T>& g);
|
||||
|
||||
void sumOutIndex (size_t idx);
|
||||
|
||||
|
Reference in New Issue
Block a user