Be cautious of discriminating “Ctxt::multiplyBy()” and “Ctxt::*=”

In the past 2 Days, I was frustrated by an issue, which will cause program crashed at HElib‘s Ctxt::reLinearize() function:

assert(W.toKeyID>=0);       // verify that a switching matrix exists

After tough debugging, the root cause is found: I should use Ctxt::multiplyBy() instead of Ctxt::*=. From Ctxt::multiplyBy()‘s implementation:

void Ctxt::multiplyBy(const Ctxt& other)
{
  // Special case: if *this is empty then do nothing
  if (this->isEmpty()) return;

  *this *= other;  // perform the multiplication
  reLinearize();   // re-linearize
}

We can see besides it calls Ctxt::*=, it also invokesĀ reLinearize(), and that’s point!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.