<div dir="ltr">Hi,<div><br></div><div>Thanks Dirk for your suggestions. Let me try to clarify a few things below. Basically,</div><div><br></div><div>- zgels should not be needed (probably, and if I was doing things correctly)</div><div><br></div><div>- I believe the template mechanism is simply unaware of the square format of my matrix, and defaults to the nrow < ncol case for lack of better knowledge. I do not know how to specify that the matrix is square, it's passed on from another function, i.e.</div><div><br></div><div><a href="https://github.com/baptiste/cda/blob/master/src/cd.cpp#L49">https://github.com/baptiste/cda/blob/master/src/cd.cpp#L49</a> </div><div>is using A from</div><div><a href="https://github.com/baptiste/cda/blob/master/src/cda.cpp#L129">https://github.com/baptiste/cda/blob/master/src/cda.cpp#L129</a><br></div><div><br><div>The way I picture it, I need to give a hint of the square size, and armadillo will pick the right function/template/glue (I don't know the mechanism at play).</div><div><br></div></div><div class="gmail_extra"><div class="gmail_quote">On 1 June 2015 at 01:12, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
Hi Baptiste,<br>
<span class=""><br>
On 31 May 2015 at 20:47, Baptiste Auguie wrote:<br>
| Dear list,<br>
|<br>
| My cda package (<a href="https://github.com/baptiste/cda" target="_blank">https://github.com/baptiste/cda</a>) solves a linear system Ax=b<br>
| with Armadillo; win-builder and CRAN complain about a missing "zgels_" when<br>
| trying to build on windows or mac, as it's not part of the subset of LAPACK<br>
| provided by R libraries (I asked about this in 2011). I have included a copy of<br>
<br>
</span>Right. When no system lapack/blas is found, R uses its own. Which is a<br>
subset.  We were bitten that once and now check in configure for availability<br>
of zgesdd.  I suppose this case is similar.<br>
<br>
Look at the logic in<br>
<br>
  <a href="https://github.com/RcppCore/RcppArmadillo/blob/master/configure" target="_blank">https://github.com/RcppCore/RcppArmadillo/blob/master/configure</a><br>
<br>
You may need to do something similar for zgels.  So this part of the problem<br>
("do we have zgels ?") really may be part of "which type of R installation do<br>
we have".<br>
<br>
Worst case we need new branching / #ifdef logic --- but right now I think<br>
maybe more at the level of your package then at RcppArmadillo.<br>
<span class=""><br></span></blockquote><div><br></div><div>The easiest workaround, I find, is to include zgels.f, as I've been doing since 2011. Now, my premise here is that this function is not needed in my package.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">
| this file (zgels.f) from Netlib for the past few years just to make the problem<br>
| go away, but I've recently realised that zgels is not supposed to be called! It<br>
| builds fine on Linux, or any machine with a full LAPACK installed, but I'm now<br>
| wondering if solve() always calls zgels (that would be inefficient for my<br>
| use-case). <br>
<br>
</span>From the top-level, when I just use ag (a fantastic and much faster grep<br>
alternative; and mail will drop the ansi code for colour highlihting from the<br>
console)<br></blockquote><div><br></div><div>Yes, I've tried to look at where zgels is called in the original Armadillo; it's not crystal clear (for me) with the templates and glue etc.  </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
edd@max:~/git/rcpparmadillo(master)$ ag zgels<br>
inst/include/armadillo_bits/lapack_bones.hpp<br>
97:  #define arma_zgels  zgels<br>
205:  #define arma_zgels  ZGELS<br>
340:  void arma_fortran(arma_zgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, void*   a, blas_int* lda, void*   b, blas_int* ldb, void*   work, blas_int* lwork, blas_int* info);<br>
<br>
inst/include/armadillo_bits/lapack_wrapper.hpp<br>
689:      arma_fortran(arma_zgels)(trans, m, n, nrhs, (T*)a, lda, (T*)b, ldb, (T*)work, lwork, info);<br>
edd@max:~/git/rcpparmadillo(master)$<br>
<br>
I think you should discuss the merits of what gets called with Conrad.<br></blockquote><div><br></div><div>Looking at the code and docs, the intent for square matrices is probably not to use zgels. I believe my code is simply failing to give enough hints for the templates to work out which case is actually being required.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span class=""><br>
| The matrix A is square: the system is not under/overdetermined, and I believe<br>
| Armadillo should select LU factorisation rather than (slower) QR. Here's the<br>
<br>
</span>It is hard to answer this in full generality --- and even harder to change an<br>
existing API.<br>
<br>
If Armadillo has been using QR here for years, we cannot really change this<br>
now on the request of a single package. </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span class=""><br>
| error I get from win-builder when I remove zgels.f from my cda package,<br>
|<br>
| cd.o:cd.cpp:<br>
| (.text$_ZN4arma6auxlib8solve_udISt7complexIdENS_3MatIS3_EEEEbRNS4_IT_EES8_RKNS_4BaseIS6_T0_EE<br>
| [bool arma::auxlib::solve_ud<std::complex<double>, arma::Mat<std::complex<br>
| <double> > >(arma::Mat<std::complex<double> >&, arma::Mat<std::complex<double><br>
| >&, arma::Base<std::complex<double>, arma::Mat<std::complex<double> > > const<br>
| &)]+0x3a5): undefined reference to `zgels_'<br>
|<br>
| So it thinks it should call solve_ud, which is meant for under-determined<br>
| systems. Why would that be? <br>
| I tried to find the relevant piece in the template code, this looks relevant<br>
| but I don't understand it: <a href="https://github.com/RcppCore/RcppArmadillo/blob/" target="_blank">https://github.com/RcppCore/RcppArmadillo/blob/</a><br>
| master/inst/include/armadillo_bits/glue_solve_meat.hpp#L26<br>
<br>
</span>Well that seems to be the call in the 'rows < cols' case.<br></blockquote><div><br></div><div>I linked to the case which is returned in the win-builder log; the case of a square matrix would be a few lines earlier (note that the solve_ud case is the default, if previous conditions fail to apply).</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
But if there is a function solve_ud, can you not just call solve_ud<br>
from your package?<br></blockquote><div><br></div><div>That would be auxlib::solve(out, A, X, slow); Yes, it's probably an option, although if I were to bypass the high-level solve() interface, I'd probably feel more comfortable with an explicit call to lu() instead. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I haven't had coffee yet so I may not need the full picture. <br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Cheers, Dirk<br></blockquote><div> </div><div>Thanks!</div><div><br></div><div>baptiste </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
<br>
<br>
|<br>
| Best regards,<br>
|<br>
| baptiste<br>
| _______________________________________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<span class=""><font color="#888888"><br>
--<br>
<a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
</font></span></blockquote></div><br></div></div>