<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 11/6/13 6:57 PM, Douglas Bates
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAO7JsnQP6zaOP8g5L681Q-AHCCROBKb1OWM3PnGVGAbWZn2Wpg@mail.gmail.com"
      type="cite">
      <div dir="ltr">By default Eigen does not use BLAS, which can be
        good or bad, depending on the situation.  I notice that the
        second largest total time is spent in t.default which may mean
        that you are using an operation like
        <div>
          <br>
        </div>
        <div>t(X) %*% X</div>
        <div><br>
        </div>
        <div>If so, you can save yourself time by using the crossprod or
          tcrossprod functions.  For example, the expression above is
          more cleanly written as</div>
        <div><br>
        </div>
        <div>crossprod(X)</div>
        <div><br>
        </div>
        <div>or, for t(X) %*% Y,</div>
        <div><br>
        </div>
        <div>crossprod(X, Y)<br>
          <br>
          Eigen or Armadillo could help you avoid making unnecessary
          copied but if your calculation does end up being dominated by
          matrix multiplications you can't expect to gain much speed
          relative to R.  You may want to check the type of BLAS you are
          using.  For Intel processors MKL is generally the fastest (but
          proprietary) with OpenBLAS in second place.<br>
          <br>
          I see that I am, as often happens, giving you similar advice
          to Dirk's response.</div>
      </div>
    </blockquote>
    t(X) %*% Y is indeed a very frequent operation. Thanks for pointing
    out the crossprod function, I was unaware of its existence.<br>
    <br>
    <br>
    Xavier<br>
    <br>
    <blockquote
cite="mid:CAO7JsnQP6zaOP8g5L681Q-AHCCROBKb1OWM3PnGVGAbWZn2Wpg@mail.gmail.com"
      type="cite">
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">On Wed, Nov 6, 2013 at 11:35 AM, Xavier
          Robin <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:xavier@cbs.dtu.dk" target="_blank">xavier@cbs.dtu.dk</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
            <br>
            I have a pure-R code that spends most of the time performing
            vector and matrix operations, as shown by the summary of
            Rprof:<br>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
                                 self.time self.pct total.time total.pct<br>
              "%*%"                 903.24    77.67     903.24 77.67<br>
              "t.default"            76.26     6.56      76.26 6.56<br>
              "-"                    36.60     3.15      36.60 3.15<br>
              "+"                    24.44     2.10      24.44 2.10<br>
              "/"                    24.22     2.08      24.22 2.08<br>
              "exp"                  20.26     1.74      20.26 1.74<br>
              "predict.myClass"      17.68     1.52     503.82 43.32<br>
              "*"                    11.90     1.02      11.90 1.02<br>
              "t"                     9.38     0.81     811.94 69.82<br>
              "update.batch"          8.04     0.69     654.68     56.30<br>
              ...<br>
            </blockquote>
            So mostly matrix %*% matrix multiplications, transpositions,
            vector +-/* matrix operations and exponentiations,
            representing >95% of the computation time.<br>
            I have very few loops and if/else blocks.<br>
            <br>
            I want to speed up this code, and I am considering
            reimplementing it (or part of it) with RcppEigen or
            RcppArmadillo.<br>
            <br>
            However, I read that both Eigen and Amarillo use the
            underlying BLAS, like R.<br>
            My question is, can I expect any significant speed-up from
            an Rcpp re-implementation in this case, given it is already
            mostly matrix algebra (which are supposed to be pretty
            efficient in R)?<br>
            <br>
            Thanks,<br>
            Xavier<span class="HOEnZb"><font color="#888888"><br>
                <br>
                -- <br>
                Xavier Robin, PhD<br>
                Cellular Signal Integration Group (C-SIG) - <a
                  moz-do-not-send="true"
                  href="http://www.lindinglab.org" target="_blank">http://www.lindinglab.org</a><br>
                Center for Biological Sequence Analysis (CBS) - <a
                  moz-do-not-send="true" href="http://www.cbs.dtu.dk"
                  target="_blank">http://www.cbs.dtu.dk</a><br>
                Department of Systems Biology - Technical University of
                Denmark (DTU)<br>
                Anker Engelundsvej, Building 301, DK-2800 Lyngby,
                DENMARK.<br>
                <br>
                _______________________________________________<br>
                Rcpp-devel mailing list<br>
                <a moz-do-not-send="true"
                  href="mailto:Rcpp-devel@lists.r-forge.r-project.org"
                  target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
                <a moz-do-not-send="true"
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>
              </font></span></blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Xavier Robin, PhD
Cellular Signal Integration Group (C-SIG) - <a class="moz-txt-link-freetext" href="http://www.lindinglab.org">http://www.lindinglab.org</a>
Center for Biological Sequence Analysis (CBS) - <a class="moz-txt-link-freetext" href="http://www.cbs.dtu.dk">http://www.cbs.dtu.dk</a>
Department of Systems Biology - Technical University of Denmark (DTU)
Anker Engelundsvej, Building 301, DK-2800 Lyngby, DENMARK.</pre>
  </body>
</html>