[Libreoffice] Help concerning code style and documentation

Thorsten Behrens thb at documentfoundation.org
Mon Nov 1 17:33:11 PDT 2010


Regina Henschel wrote:
> There is no mathematical problem, but I'm uncertain about coding
> style. The algorithms work on matrices. They have a lot of parts
> which are nearly identical but the matrices are transposed. How to
> handle that?
> 
Hi Regina,

I'd suggest using templates to achieve that - this way, you'll get
the same runtime performance, but avoid all the (semantically)
duplicated code.

There are multiple ways to tackle that, to avoid changing your code
too much, I'd suggest passing a permutating type as template
parameter to each of the methods in need of variation, e.g.:

template< class Selector >
bool calculateQRdecomposition(
   ScMatrixRef pMatA,
   ::std::vector< double>& pVecR, 
   SCSIZE nK,
   SCSIZE nN,
   Selector const& rSelector )
{
   for (SCSIZE major = 0; major < rSelector.getMajor(nK,nN); major+)
   ...
      for (SCSIZE minor = major; minor < rSelector.getMinor(nK,nN); minor++)
         pMatA->PutDouble( pMatA->GetDouble(
                               rSelector.getCol(major,minor),
                               rSelector.getRow(major,minor))/fScale,
                           rSelector.getCol(major,minor),
                           rSelector.getRow(major,minor));

etc - the Selector class then has simple inline 
double blah(a,b) { return a; } permutation methods - if you like, we
could have a look at that during the HackFest next weekend.

Otherwise - lovely code!

Cheers,

-- Thorsten
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20101102/420a8478/attachment.pgp>


More information about the LibreOffice mailing list