Skip to content

Matrix sugar functions eye, ones, and zeros - part of #564 #566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 23, 2016

Conversation

nathan-russell
Copy link
Contributor

This PR adds non-member versions of eye, ones, and zeros.

@eddelbuettel
Copy link
Member

You're fast :) That looks rather good from a first glance.

@nathan-russell
Copy link
Contributor Author

FYI there was a strange error in one of the unit tests when it ran on Travis, but I did not get it on my machine, which is running a nightly build of R:

Locally

unit-test

On Travis

travis-test

At any rate, I think the behavior on my machine is "correct", but either way the Rcpp function was behaving consistently.

@eddelbuettel
Copy link
Member

Could be clang vs g++, or old g++ vs new g++. What is your OS and compiler again?

@nathan-russell
Copy link
Contributor Author

nathan-russell commented Oct 23, 2016

I'm on Debian 8.6, using GCC 4.9.2. I was thinking there may have been something that changed between whatever version of R is running on Travis and what I have which is causing diag(TRUE, 3, 3) to give different results. But either way, it's not an Rcpp issue as far as I can tell.

@eddelbuettel
Copy link
Member

You could fire up Docker to get a newer g++. I default to 5.4 on Ubuntu 16.04, but my uploads into Debian unstable all have g++-6.2 which is (I think) also the default in Ubuntu 16.10.

@eddelbuettel
Copy link
Member

eddelbuettel commented Oct 23, 2016

Maybe it is "simply" an R versus R-devel thing. On my box (R-release, g++-5.4.0, Ubuntu 16.04) it behaves like Travis:

R> library(Rcpp)
R> cppFunction("LogicalMatrix lgl_eye(int n) { return Rcpp::eye(n); }")
R> lgl_eye(3)
      [,1]  [,2]  [,3]
[1,]  TRUE FALSE FALSE
[2,] FALSE  TRUE FALSE
[3,] FALSE FALSE  TRUE
R> storage.mode(lgl_eye(3))
[1] "logical"
R> storage.mode(diag(TRUE, 3, 3))
[1] "double"
R> 

That is, after pulling your branch and installing, of course.

@nathan-russell
Copy link
Contributor Author

nathan-russell commented Oct 23, 2016

Hmm that is strange; I would expect the storage.mode == "double" to be the exception rather than the rule. I have Clang 4.0 built from source, so I may try rebuilding R devel with that overnight and seeing how that behaves, just out of curiosity.

@eddelbuettel
Copy link
Member

eddelbuettel commented Oct 23, 2016

I really think it is R 3.3.* vs R 3.4.0-to-be:

edd@max:~/git/rcpp(feature/pr566)$ RD

R Under development (unstable) (2016-10-14 r71522) -- "Unsuffered Consequences"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

R> storage.mode(diag(TRUE, 3, 3))
[1] "logical"
R> 

and continuing in the same R-devel session:

R> library(Rcpp)
R> cppFunction("LogicalMatrix lgl_eye(int n) { return Rcpp::eye(n); }")
R> lgl_eye(3)
      [,1]  [,2]  [,3]
[1,]  TRUE FALSE FALSE
[2,] FALSE  TRUE FALSE
[3,] FALSE FALSE  TRUE
R> storage.mode(lgl_eye(3))
[1] "logical"
R> 

@nathan-russell
Copy link
Contributor Author

Ah, yes -- from the upcoming release notes:

diag(x, nrow = n) now preserves typeof(x), also for logical, integer and raw x (and as previously for complex and numeric).

@eddelbuettel
Copy link
Member

So you added a unit test from the future. I am in awe 😁

@nathan-russell
Copy link
Contributor Author

While we are on the subject, running the full unit test suite did yield this both times:

Rcpp unit testing - 551 test functions, 0 errors, 1 failure
FAILURE in test.ExpressionVector: Error in checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (numeric)") : 
  Attributes: < target is NULL, current is list >
current is not list-like
RCPP_RETURN_VECTOR (numeric)

So that may or may not be another R 3.4 issue; but it is potentially something to keep an eye on for the future.

@eddelbuettel
Copy link
Member

This one from runit.dispatch.R?

    test.ExpressionVector <- function() {
        x <- parse(text = "rnrom; rnrom(10); mean(1:10)")
        checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (numeric)")
    }

I don't recall what the story is. An intentional misspelling of rnorm to catch an exception?

@nathan-russell
Copy link
Contributor Author

Yes that's that one; I hadn't stopped to look at it before, but for whatever reason it causes an error on my machine and not on Travis.

@eddelbuettel
Copy link
Member

When I run that here I get

Executing test function test.ExpressionVector  ... Timing stopped at: 0 0 0.001 
Error in checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (numeric)") : 
  Attributes: < target is NULL, current is list >
current is not list-like
RCPP_RETURN_VECTOR (numeric)
 done successfully.

so it passes with the usual noise from RUnit (which I should really turn off...)

@eddelbuettel
Copy link
Member

eddelbuettel commented Oct 23, 2016

My runit.sh is a simple

edd@max:~/git/rcpp/inst/unitTests(feature/pr566)$ cat ~/bin/runit.sh 
#!/bin/sh

set -u 
set -e

progname=`basename $0`
options='p:ah?'

usage_and_exit()
{
    echo ""
    echo "Usage: $progname [-p package[,package2,..]] [-?|-h]"
    echo "  Run unit test script for R package"
    echo ""
    echo "Options:"
    echo "  -p package[,package2,..]]  load additional package(s)"
    echo "  -h                         show this help"
    echo "  -a                         run with 'export RunAllRcppTests=yes'"
    echo ""
    echo "The RUnit and inline packages are automatically loaded."
    echo ""
    exit 0
}

while getopts "$options" i 
do 
    case "$i" in
        p)
            pkg=",$OPTARG"
            shift 
            shift
            ;;
        a)
            export RunAllRcppTests="yes"
            shift
            ;;
        h|?)
            usage_and_exit
            ;;
    esac
done

if [ ! -f $1 ]; then
    echo "Error: No file '$1' found"
    exit 1
fi

file=`pwd`/$1

#r -i -t -linline,RUnit${pkg} -e"cppfunction <- function(...) cxxfunction(..., plugin=\"Rcpp\"); runTestFile(\"$file\")"
r -i -t -lRUnit${pkg} -e"runTestFile(\"$file\")"
edd@max:~/git/rcpp/inst/unitTests(feature/pr566)$ 

and I just executed

edd@max:~/git/rcpp/inst/unitTests(feature/pr566)$ runit.sh -p Rcpp -a runit.dispatch.R 

The -a is important to turn the (otherwise opt-in) tests on.

@nathan-russell
Copy link
Contributor Author

Hmm I don't get any errors when running your script; I guess it must have something to do with RStudio.

@kevinushey
Copy link
Contributor

I get a bunch of warnings when compiling sugar.cpp:

In file included from sugar.cpp:22:
In file included from /Users/kevin/Library/R/3.3/library/Rcpp/include/Rcpp.h:70:
In file included from /Users/kevin/Library/R/3.3/library/Rcpp/include/Rcpp/sugar/sugar.h:32:
In file included from /Users/kevin/Library/R/3.3/library/Rcpp/include/Rcpp/sugar/matrix/matrix_functions.h:32:
/Users/kevin/Library/R/3.3/library/Rcpp/include/Rcpp/sugar/matrix/eye.h:146:43: warning: unused variable 'allowed_matrix_type' [-Wunused-variable]
        traits::static_assertion<enabled> allowed_matrix_type;
                                          ^
sugar.cpp:1177:12: note: in instantiation of function template specialization 'Rcpp::zeros::operator Matrix<15>' requested here
    return Rcpp::zeros(n);
           ^

Any chance that warning could be suppressed / disabled somehow? Maybe an RCPP_STATIC_ASSERT macro with appropriate attributes?

@kevinushey
Copy link
Contributor

kevinushey commented Oct 23, 2016

As an aside, I can replicate the ExpressionVector failure when running the unit tests interactively. It looks like it's because the R-level subset includes srcrefs, so the comparison fails:

> .Internal(inspect(first_el(x)))
@102ce93f8 20 EXPRSXP g0c1 [] (len=1, tl=0)
  @10367d558 01 SYMSXP g0c0 [NAM(2)] "rnrom"
> .Internal(inspect(x[1]))
@102ce92a8 20 EXPRSXP g0c1 [NAM(2),ATT] (len=1, tl=0)
  @10367d558 01 SYMSXP g0c0 [NAM(2)] "rnrom"
ATTRIB:
  @102bdd778 02 LISTSXP g0c0 [] 
    TAG: @103022f90 01 SYMSXP g1c0 [MARK,LCK,gp=0x4000] "srcref" (has value)
    @102ce9278 19 VECSXP g0c1 [] (len=1, tl=0)
      @11104a758 13 INTSXP g0c3 [OBJ,NAM(2),ATT] (len=8, tl=0) 1,1,1,5,1,...
      ATTRIB:
    @102b11750 02 LISTSXP g0c0 [] 
      TAG: @103023000 01 SYMSXP g1c0 [MARK,NAM(2),LCK,gp=0x4000] "srcfile" (has value)
      @102b0e4e8 04 ENVSXP g0c0 [OBJ,NAM(2),ATT] <0x102b0e4e8>
      ENCLOS:
        @103052ed8 04 ENVSXP g1c0 [MARK,NAM(2)] <R_EmptyEnv>
      HASHTAB:
        @10bf99a00 19 VECSXP g0c7 [] (len=29, tl=8)
          @103002378 00 NILSXP g1c0 [MARK,NAM(2)] 
          @103002378 00 NILSXP g1c0 [MARK,NAM(2)] 
          @103002378 00 NILSXP g1c0 [MARK,NAM(2)] 
          @102b0ece8 02 LISTSXP g0c0 [] 
        TAG: @1029a5a70 01 SYMSXP g1c0 [MARK] "wd"
        @102c4ce38 16 STRSXP g0c1 [NAM(1)] (len=1, tl=0)
          @10c686808 09 CHARSXP g1c4 [MARK,gp=0x60] [ASCII] [cached] "/Users/kevin/git/Rcpp/inst/unitTests"
          @103002378 00 NILSXP g1c0 [MARK,NAM(2)] 
          ...
      ATTRIB:
        @102b11ad0 02 LISTSXP g0c0 [] 
          TAG: @103002148 01 SYMSXP g1c0 [MARK,NAM(2),LCK,gp=0x4000] "class" (has value)
          @10328e028 16 STRSXP g1c2 [MARK,NAM(2)] (len=2, tl=0)
        @1030ab350 09 CHARSXP g1c2 [MARK,gp=0x61] [ASCII] [cached] "srcfilecopy"
        @103002678 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "srcfile"
      TAG: @103002148 01 SYMSXP g1c0 [MARK,NAM(2),LCK,gp=0x4000] "class" (has value)
      @102c4cb98 16 STRSXP g0c1 [NAM(2)] (len=1, tl=0)
        @103002648 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "srcref"

This was with R 3.3.1 patched (r71015), so may well be an R-devel change?

@eddelbuettel
Copy link
Member

@nathan-russell :

I guess it must have something to do with RStudio.

It's a command-line script. RStudio never enters that picture.

@nathan-russell
Copy link
Contributor Author

@kevinushey I changed the offending lines to use (void)sizeof(traits::allowed_matrix_type<enabled>); and that silenced the warning on my machine.

@eddelbuettel
Copy link
Member

I am not sure if we can salvage that (templated) ExpressionVector unit test mentioned above. Seems like comparison do not work (illustrating what @kevinushey dug up)

R> parse(text="rnorm; rnorm(10); mean(1:10);")[1]
expression(rnorm)
R> parse(text="rnorm; rnorm(10); mean(1:10);")[2]
expression(rnorm(10))
R> parse(text="rnorm; rnorm(10); mean(1:10);")[3]
expression(mean(1:10))
R> eval(parse(text="rnorm; rnorm(10); mean(1:10);")[3])
[1] 5.5
R> library(Rcpp)
R> cppFunction("ExpressionVector foo(ExpressionVector x) { ExpressionVector res(1); res[0] = x[0]; return res;}" )
R> foo(parse(text="rnorm; rnorm(10); mean(1:10);"))
expression(rnorm)

So far so good but neither == nor the RUnit::checkEquals comparison work.

R> foo(parse(text="rnorm; rnorm(10); mean(1:10);")) == parse(text="rnorm; rnorm(10); mean(1:10);")[1]
Error in foo(parse(text = "rnorm; rnorm(10); mean(1:10);")) == parse(text = "rnorm; rnorm(10); mean(1:10);")[1] : 
  comparison is not allowed for expressions
R> RUnit::checkEquals(foo(parse(text="rnorm; rnorm(10); mean(1:10);")), parse(text="rnorm; rnorm(10); mean(1:10);")[1])
Error in RUnit::checkEquals(foo(parse(text = "rnorm; rnorm(10); mean(1:10);")),  : 
  Attributes: < target is NULL, current is list >
current is not list-like
R> 

We could just compare to ExpressionVector.

@nathan-russell
Copy link
Contributor Author

nathan-russell commented Oct 23, 2016

After looking at this a little bit more, I feel like it was incorrect for that unit test to be using parse in the first place. While parse happens to return an expression object, it also has a bunch of extra srcref attributes, which is what checkEquals is breaking on, IIUC. It seems like the correct way to write this test would be

test.ExpressionVector <- function() {
    x <- expression(rnorm, rnorm(10), mean(1:10))
    checkEquals(first_el(x), x[1], msg = "RCPP_RETURN_VECTOR (numeric)")
}

Running the code interactively,

x <- parse(text = "rnrom; rnorm(10); mean(1:10)")
x2 <- expression(rnorm, rnorm(10), mean(1:10))
checkEquals(first_el(x), x[1])
# Error in checkEquals(first_el(x), x[1]) : 
#   Attributes: < target is NULL, current is list >
# current is not list-like
checkEquals(first_el(x2), x2[1])
# [1] TRUE

@eddelbuettel
Copy link
Member

I like that a lot better. Note that we may as well change the msg there.

Do you mind if I just punch that in?

@nathan-russell
Copy link
Contributor Author

Not at all, and yes I agree, the original (re: current version) also has a typo ("rnrom" instead of "rnorm"), which is probably also worth correcting.

eddelbuettel added a commit that referenced this pull request Oct 23, 2016
as discussed in #566, with thanks to Nathan Russell
@eddelbuettel
Copy link
Member

Just pushed it into a fresh baby branch. Take a look and if you nod, and if Travis agrees, I'll merge it in (probably even as squashing merge which is a nice and new-ish GH feature).

@eddelbuettel
Copy link
Member

Actually we could also have just piled it on to your open PR. Oh well. Six of one, half a dozen of the other.

@eddelbuettel
Copy link
Member

Dang. Now your PR now longer merges cleanly and we had hoped that having .gitattributes would avoid that. Guess not.

@eddelbuettel
Copy link
Member

eddelbuettel commented Oct 23, 2016

Actually, good news. Doing it 'by hand' in a (local) branch which had pull your master:

git merge --ff --no-commit master

gets me:

edd@max:~/git/rcpp(feature/pr566)$ git merge --ff --no-commit master          
Auto-merging inst/NEWS.Rd
Auto-merging ChangeLog
Automatic merge went well; stopped before committing as requested
edd@max:~/git/rcpp(feature/pr566)$ git st
On branch feature/pr566
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:

        modified:   ChangeLog
        modified:   inst/NEWS.Rd
        modified:   inst/unitTests/runit.dispatch.R

edd@max:~/git/rcpp(feature/pr566)$ 

so if you did the equivalent update of our master (in your branch corresponding to the Rcpp master)

... and dang before I was done typing this you already pushed. Well done.

@nathan-russell
Copy link
Contributor Author

nathan-russell commented Oct 23, 2016

I think maybe the GitHub client just isn't clever enough to apply the .gitattributes logic; it seems to have worked as advertised though (I think):

nathan@nathan-deb:~/gitrepos/Rcpp$ git merge upstream/master
Auto-merging inst/NEWS.Rd
Auto-merging ChangeLog
Merge made by the 'recursive' strategy.
 ChangeLog                       | 2 ++
 inst/NEWS.Rd                    | 4 ++++
 inst/unitTests/runit.dispatch.R | 7 ++++---
 3 files changed, 10 insertions(+), 3 deletions(-)

Edit: Didn't see you comment until after I that typed up.

@eddelbuettel
Copy link
Member

Agreed -- maybe the web client is dumber. The real git client handled it for you and me. Will merge once this Travis run is done. All good!

@eddelbuettel eddelbuettel merged commit 4e14955 into RcppCore:master Oct 23, 2016
@eddelbuettel
Copy link
Member

😢

Just started a reverse-dependency check, and it almost immediately barked when AdaptiveSparsity failed because with RcppArmadillo and Rcpp namespaces we now have an ambiguity over zeros():

* installing *source* package ‘AdaptiveSparsity’ ...
** package ‘AdaptiveSparsity’ successfully unpacked and MD5 sums checked
** libs
ccache g++ -I/usr/share/R/include -DNDEBUG   -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include"   -fpic  -g -O3 -Wall -pipe -Wno-unused -pedantic -c CSL.cpp -o CSL.o
CSL.cpp: In function ‘arma::mat armaOLSestim(arma::mat)’:
CSL.cpp:14:13: error: reference to ‘zeros’ is ambiguous
  mat LHat = zeros<mat>(n,n);
             ^
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/armadillo:429:0,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadilloForward.h:46,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:31,
                 from CSL.h:4,
                 from CSL.cpp:1:
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:192:1: note: candidates are: template<class sp_obj_type> sp_obj_type arma::zeros(const arma::SizeMat&, const typename arma::arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result*)
 zeros(const SizeMat& s, const typename arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:168:1: note:                 template<class sp_obj_type> sp_obj_type arma::zeros(arma::uword, arma::uword, const typename arma::arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result*)
 zeros(const uword n_rows, const uword n_cols, const typename arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:154:1: note:                 template<class cube_type> const arma::GenCube<typename cube_type::elem_type, arma::gen_zeros> arma::zeros(const arma::SizeCube&, const typename arma::arma_Cube_only<cube_type>::result*)
 zeros(const SizeCube& s, const typename arma_Cube_only<cube_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:140:1: note:                 template<class cube_type> const arma::GenCube<typename cube_type::elem_type, arma::gen_zeros> arma::zeros(arma::uword, arma::uword, arma::uword, const typename arma::arma_Cube_only<cube_type>::result*)
 zeros(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only<cube_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:127:1: note:                 const arma::GenCube<double, arma::gen_zeros> arma::zeros(const arma::SizeCube&)
 zeros(const SizeCube& s)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:115:1: note:                 const arma::GenCube<double, arma::gen_zeros> arma::zeros(arma::uword, arma::uword, arma::uword)
 zeros(const uword n_rows, const uword n_cols, const uword n_slices)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:102:1: note:                 template<class obj_type> const arma::Gen<obj_type, arma::gen_zeros> arma::zeros(const arma::SizeMat&, const typename arma::arma_Mat_Col_Row_only<obj_type>::result*)
 zeros(const SizeMat& s, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:78:1: note:                 template<class obj_type> const arma::Gen<obj_type, arma::gen_zeros> arma::zeros(arma::uword, arma::uword, const typename arma::arma_Mat_Col_Row_only<obj_type>::result*)
 zeros(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:65:1: note:                 const arma::Gen<arma::Mat<double>, arma::gen_zeros> arma::zeros(const arma::SizeMat&)
 zeros(const SizeMat& s)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:53:1: note:                 const arma::Gen<arma::Mat<double>, arma::gen_zeros> arma::zeros(arma::uword, arma::uword)
 zeros(const uword n_rows, const uword n_cols)
 ^
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/armadillo:429:0,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadilloForward.h:46,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:31,
                 from CSL.h:4,
                 from CSL.cpp:1:
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:32:1: note:                 template<class obj_type> const arma::Gen<obj_type, arma::gen_zeros> arma::zeros(arma::uword, arma::arma_empty_class, const typename arma::arma_Mat_Col_Row_only<obj_type>::result*)
 zeros(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only<obj_type>::result* junk2 = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:19:1: note:                 const arma::Gen<arma::Col<double>, arma::gen_zeros> arma::zeros(arma::uword)
 zeros(const uword n_elem)
 ^
In file included from /usr/local/lib/R/site-library/Rcpp/include/Rcpp/sugar/matrix/matrix_functions.h:32:0,
                 from /usr/local/lib/R/site-library/Rcpp/include/Rcpp/sugar/sugar.h:32,
                 from /usr/local/lib/R/site-library/Rcpp/include/Rcpp.h:71,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:34,
                 from CSL.h:4,
                 from CSL.cpp:1:
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/sugar/matrix/eye.h:129:7: note:                 class Rcpp::zeros
 class zeros {
       ^
CSL.cpp:14:22: error: expected primary-expression before ‘>’ token
  mat LHat = zeros<mat>(n,n);
                      ^
CSL.cpp: In function ‘arma::mat LtoBeta(arma::mat, arma::mat)’:
CSL.cpp:39:22: error: reference to ‘zeros’ is ambiguous
     mat betaMatrix = zeros(kNodes,kNodes);
                      ^
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/armadillo:429:0,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadilloForward.h:46,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:31,
                 from CSL.h:4,
                 from CSL.cpp:1:
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:192:1: note: candidates are: template<class sp_obj_type> sp_obj_type arma::zeros(const arma::SizeMat&, const typename arma::arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result*)
 zeros(const SizeMat& s, const typename arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:168:1: note:                 template<class sp_obj_type> sp_obj_type arma::zeros(arma::uword, arma::uword, const typename arma::arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result*)
 zeros(const uword n_rows, const uword n_cols, const typename arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:154:1: note:                 template<class cube_type> const arma::GenCube<typename cube_type::elem_type, arma::gen_zeros> arma::zeros(const arma::SizeCube&, const typename arma::arma_Cube_only<cube_type>::result*)
 zeros(const SizeCube& s, const typename arma_Cube_only<cube_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:140:1: note:                 template<class cube_type> const arma::GenCube<typename cube_type::elem_type, arma::gen_zeros> arma::zeros(arma::uword, arma::uword, arma::uword, const typename arma::arma_Cube_only<cube_type>::result*)
 zeros(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only<cube_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:127:1: note:                 const arma::GenCube<double, arma::gen_zeros> arma::zeros(const arma::SizeCube&)
 zeros(const SizeCube& s)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:115:1: note:                 const arma::GenCube<double, arma::gen_zeros> arma::zeros(arma::uword, arma::uword, arma::uword)
 zeros(const uword n_rows, const uword n_cols, const uword n_slices)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:102:1: note:                 template<class obj_type> const arma::Gen<obj_type, arma::gen_zeros> arma::zeros(const arma::SizeMat&, const typename arma::arma_Mat_Col_Row_only<obj_type>::result*)
 zeros(const SizeMat& s, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:78:1: note:                 template<class obj_type> const arma::Gen<obj_type, arma::gen_zeros> arma::zeros(arma::uword, arma::uword, const typename arma::arma_Mat_Col_Row_only<obj_type>::result*)
 zeros(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:65:1: note:                 const arma::Gen<arma::Mat<double>, arma::gen_zeros> arma::zeros(const arma::SizeMat&)
 zeros(const SizeMat& s)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:53:1: note:                 const arma::Gen<arma::Mat<double>, arma::gen_zeros> arma::zeros(arma::uword, arma::uword)
 zeros(const uword n_rows, const uword n_cols)
 ^
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/armadillo:429:0,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadilloForward.h:46,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:31,
                 from CSL.h:4,
                 from CSL.cpp:1:
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:32:1: note:                 template<class obj_type> const arma::Gen<obj_type, arma::gen_zeros> arma::zeros(arma::uword, arma::arma_empty_class, const typename arma::arma_Mat_Col_Row_only<obj_type>::result*)
 zeros(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only<obj_type>::result* junk2 = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:19:1: note:                 const arma::Gen<arma::Col<double>, arma::gen_zeros> arma::zeros(arma::uword)
 zeros(const uword n_elem)
 ^
In file included from /usr/local/lib/R/site-library/Rcpp/include/Rcpp/sugar/matrix/matrix_functions.h:32:0,
                 from /usr/local/lib/R/site-library/Rcpp/include/Rcpp/sugar/sugar.h:32,
                 from /usr/local/lib/R/site-library/Rcpp/include/Rcpp.h:71,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:34,
                 from CSL.h:4,
                 from CSL.cpp:1:
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/sugar/matrix/eye.h:129:7: note:                 class Rcpp::zeros
 class zeros {
       ^
CSL.cpp: In function ‘arma::mat betatoL(arma::mat, arma::mat)’:
CSL.cpp:51:14: error: reference to ‘zeros’ is ambiguous
  mat LTemp = zeros(kNodes, kNodes);
              ^
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/armadillo:429:0,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadilloForward.h:46,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:31,
                 from CSL.h:4,
                 from CSL.cpp:1:
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:192:1: note: candidates are: template<class sp_obj_type> sp_obj_type arma::zeros(const arma::SizeMat&, const typename arma::arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result*)
 zeros(const SizeMat& s, const typename arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:168:1: note:                 template<class sp_obj_type> sp_obj_type arma::zeros(arma::uword, arma::uword, const typename arma::arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result*)
 zeros(const uword n_rows, const uword n_cols, const typename arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:154:1: note:                 template<class cube_type> const arma::GenCube<typename cube_type::elem_type, arma::gen_zeros> arma::zeros(const arma::SizeCube&, const typename arma::arma_Cube_only<cube_type>::result*)
 zeros(const SizeCube& s, const typename arma_Cube_only<cube_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:140:1: note:                 template<class cube_type> const arma::GenCube<typename cube_type::elem_type, arma::gen_zeros> arma::zeros(arma::uword, arma::uword, arma::uword, const typename arma::arma_Cube_only<cube_type>::result*)
 zeros(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only<cube_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:127:1: note:                 const arma::GenCube<double, arma::gen_zeros> arma::zeros(const arma::SizeCube&)
 zeros(const SizeCube& s)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:115:1: note:                 const arma::GenCube<double, arma::gen_zeros> arma::zeros(arma::uword, arma::uword, arma::uword)
 zeros(const uword n_rows, const uword n_cols, const uword n_slices)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:102:1: note:                 template<class obj_type> const arma::Gen<obj_type, arma::gen_zeros> arma::zeros(const arma::SizeMat&, const typename arma::arma_Mat_Col_Row_only<obj_type>::result*)
 zeros(const SizeMat& s, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:78:1: note:                 template<class obj_type> const arma::Gen<obj_type, arma::gen_zeros> arma::zeros(arma::uword, arma::uword, const typename arma::arma_Mat_Col_Row_only<obj_type>::result*)
 zeros(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:65:1: note:                 const arma::Gen<arma::Mat<double>, arma::gen_zeros> arma::zeros(const arma::SizeMat&)
 zeros(const SizeMat& s)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:53:1: note:                 const arma::Gen<arma::Mat<double>, arma::gen_zeros> arma::zeros(arma::uword, arma::uword)
 zeros(const uword n_rows, const uword n_cols)
 ^
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/armadillo:429:0,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadilloForward.h:46,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:31,
                 from CSL.h:4,
                 from CSL.cpp:1:
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:32:1: note:                 template<class obj_type> const arma::Gen<obj_type, arma::gen_zeros> arma::zeros(arma::uword, arma::arma_empty_class, const typename arma::arma_Mat_Col_Row_only<obj_type>::result*)
 zeros(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only<obj_type>::result* junk2 = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:19:1: note:                 const arma::Gen<arma::Col<double>, arma::gen_zeros> arma::zeros(arma::uword)
 zeros(const uword n_elem)
 ^
In file included from /usr/local/lib/R/site-library/Rcpp/include/Rcpp/sugar/matrix/matrix_functions.h:32:0,
                 from /usr/local/lib/R/site-library/Rcpp/include/Rcpp/sugar/sugar.h:32,
                 from /usr/local/lib/R/site-library/Rcpp/include/Rcpp.h:71,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:34,
                 from CSL.h:4,
                 from CSL.cpp:1:
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/sugar/matrix/eye.h:129:7: note:                 class Rcpp::zeros
 class zeros {
       ^
CSL.cpp: In function ‘arma::mat wEstim(int, int, arma::mat, arma::mat, arma::mat, double, arma::mat)’:
CSL.cpp:129:17: error: reference to ‘zeros’ is ambiguous
     mat wtemp = zeros(1, kNodes);
                 ^
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/armadillo:429:0,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadilloForward.h:46,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:31,
                 from CSL.h:4,
                 from CSL.cpp:1:
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:192:1: note: candidates are: template<class sp_obj_type> sp_obj_type arma::zeros(const arma::SizeMat&, const typename arma::arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result*)
 zeros(const SizeMat& s, const typename arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:168:1: note:                 template<class sp_obj_type> sp_obj_type arma::zeros(arma::uword, arma::uword, const typename arma::arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result*)
 zeros(const uword n_rows, const uword n_cols, const typename arma_SpMat_SpCol_SpRow_only<sp_obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:154:1: note:                 template<class cube_type> const arma::GenCube<typename cube_type::elem_type, arma::gen_zeros> arma::zeros(const arma::SizeCube&, const typename arma::arma_Cube_only<cube_type>::result*)
 zeros(const SizeCube& s, const typename arma_Cube_only<cube_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:140:1: note:                 template<class cube_type> const arma::GenCube<typename cube_type::elem_type, arma::gen_zeros> arma::zeros(arma::uword, arma::uword, arma::uword, const typename arma::arma_Cube_only<cube_type>::result*)
 zeros(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only<cube_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:127:1: note:                 const arma::GenCube<double, arma::gen_zeros> arma::zeros(const arma::SizeCube&)
 zeros(const SizeCube& s)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:115:1: note:                 const arma::GenCube<double, arma::gen_zeros> arma::zeros(arma::uword, arma::uword, arma::uword)
 zeros(const uword n_rows, const uword n_cols, const uword n_slices)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:102:1: note:                 template<class obj_type> const arma::Gen<obj_type, arma::gen_zeros> arma::zeros(const arma::SizeMat&, const typename arma::arma_Mat_Col_Row_only<obj_type>::result*)
 zeros(const SizeMat& s, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:78:1: note:                 template<class obj_type> const arma::Gen<obj_type, arma::gen_zeros> arma::zeros(arma::uword, arma::uword, const typename arma::arma_Mat_Col_Row_only<obj_type>::result*)
 zeros(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:65:1: note:                 const arma::Gen<arma::Mat<double>, arma::gen_zeros> arma::zeros(const arma::SizeMat&)
 zeros(const SizeMat& s)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:53:1: note:                 const arma::Gen<arma::Mat<double>, arma::gen_zeros> arma::zeros(arma::uword, arma::uword)
 zeros(const uword n_rows, const uword n_cols)
 ^
In file included from /usr/local/lib/R/site-library/RcppArmadillo/include/armadillo:429:0,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadilloForward.h:46,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:31,
                 from CSL.h:4,
                 from CSL.cpp:1:
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:32:1: note:                 template<class obj_type> const arma::Gen<obj_type, arma::gen_zeros> arma::zeros(arma::uword, arma::arma_empty_class, const typename arma::arma_Mat_Col_Row_only<obj_type>::result*)
 zeros(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only<obj_type>::result* junk2 = 0)
 ^
/usr/local/lib/R/site-library/RcppArmadillo/include/armadillo_bits/fn_zeros.hpp:19:1: note:                 const arma::Gen<arma::Col<double>, arma::gen_zeros> arma::zeros(arma::uword)
 zeros(const uword n_elem)
 ^
In file included from /usr/local/lib/R/site-library/Rcpp/include/Rcpp/sugar/matrix/matrix_functions.h:32:0,
                 from /usr/local/lib/R/site-library/Rcpp/include/Rcpp/sugar/sugar.h:32,
                 from /usr/local/lib/R/site-library/Rcpp/include/Rcpp.h:71,
                 from /usr/local/lib/R/site-library/RcppArmadillo/include/RcppArmadillo.h:34,
                 from CSL.h:4,
                 from CSL.cpp:1:
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/sugar/matrix/eye.h:129:7: note:                 class Rcpp::zeros
 class zeros {
       ^
/usr/lib/R/etc/Makeconf:141: recipe for target 'CSL.o' failed
make: *** [CSL.o] Error 1
ERROR: compilation failed for package ‘AdaptiveSparsity’
* removing ‘/tmp/RcppDepends/AdaptiveSparsity.Rcheck/AdaptiveSparsity’

Now, that is arguably an error in that package. We'll see how many other bubble up. So far 19 good, 1 bad with a lot more to go.

@nathan-russell
Copy link
Contributor Author

nathan-russell commented Oct 24, 2016

I'm guessing the author is doing something like

using namespace Rcpp;
using namespace arma;

And unfortunately, they probably aren't the only person doing this...

Edit: Yep

nrussell@nrussell ~/tmp/AdaptiveSparsity/src
$ cat CSL.cpp | head
#include "CSL.h"

using namespace Rcpp;
using namespace std;
using namespace arma;

////////////////////// OLS Estimation //////////////////////
// [[Rcpp::export]]
mat armaOLSestim (mat x) {
    int m = x.n_rows;

@eddelbuettel
Copy link
Member

Yes and yes and why I wrote

We'll see how many other bubble up.

Just got three more failures. Current score 34 good, 4 bad.

@eddelbuettel
Copy link
Member

So ... here is what we can do:

  • protect the new functions by a #define which we say we'll flip in a year
  • 'hide' the new functions in yet another namespace, say, Rcpp::mat::

I like the #define better so far.

@nathan-russell
Copy link
Contributor Author

Yes the #define approach sounds good to me; I'll try to put something together.

@coatless
Copy link
Contributor

Why not something a bit simpler such as renaming the functions to fill_zeros, fill_ones, ...?

@nathan-russell
Copy link
Contributor Author

That could work also; I'm open to either. What do you want to do Dirk?

@eddelbuettel
Copy link
Member

eddelbuettel commented Oct 24, 2016

I hate underscores and find fillFoo a little weird. Sugar functions are generally named the same as the corresponding R functions.

Also, we have one advantage: we do also control RcppArmadillo AND we already control the include order. We could re-define the protective #define over there if needed. Or too complex?

@nathan-russell
Copy link
Contributor Author

nathan-russell commented Oct 24, 2016

I think that no matter what the macro guard would have to be inside of Rcpp.h though, right? E.g., in RcppArmadillo.h, it is pulling in everything at once with #include <Rcpp.h>, so it would be too late to do something like

#ifdef RCPP_USE_ADDITIONAL_SUGAR_FUNCTIONS 
#include <Rcpp/sugar/matrix/eye.h>
#endif 

Wouldn't that ^^ have to live in Rcpp/sugar/matrix/matrix_functions.h? Or did you have something else in mind?

@eddelbuettel
Copy link
Member

eddelbuettel commented Oct 24, 2016

See this one which happens before Rcpp.h is included. We could correct here -- and even, say, always turn the Rcpp ones off!

@nathan-russell
Copy link
Contributor Author

nathan-russell commented Oct 24, 2016

Oh I see, so maybe even just adding a simple

#define Rcpp__sugar__eye_h

before the #include <Rcpp.h> line would be sufficient, as it would trigger the include guard in eye.h.

@eddelbuettel
Copy link
Member

eddelbuettel commented Oct 24, 2016

Right! Now up to us to decide if we want to permanently hide them or not.

Maybe say we will flip such a #define in a year, leaving the user a (permanent) override by defining, say, #define RcppArmadillo_Really_Hide_Rcpp_Sugar_Functions_Eye_Zeros_Ones or something.

Thoughts?

@eddelbuettel
Copy link
Member

I guess we can just define that thing now, effectively hide, promised to remove it in a year -- and thereby leaves users an option to add it now or later if they prefer not change their code.

@nathan-russell
Copy link
Contributor Author

Yes that should work fine. All of the user code that is currently call eye, ones, or zeros is referring to the arma versions anyhow, so the Rcpp versions shouldn't be missed in those cases. Of course, this could all be avoided with proper namespace qualification, but what can you do...

@eddelbuettel
Copy link
Member

Exactly. All we can do is whine, and boy are we good at it ;-)

@kevinushey
Copy link
Contributor

kevinushey commented Oct 24, 2016

I'd rather just avoid breaking Rcpp client packages if possible (even if those packages are doing something they shouldn't be doing). Can we move these functions to an alternative place?

I'd advocate for placing them within the MatrixBase class, so users can call e.g. NumericMatrix::ones(10) or something similar.

@eddelbuettel
Copy link
Member

I like that option too.

@nathan-russell
Copy link
Contributor Author

@kevinushey Any reason to prefer putting them in MatrixBase rather than Matrix, as is the case with e.g. Matrix::diag?

@kevinushey
Copy link
Contributor

I initially thought MatrixBase would be a good fit to help reduce code bloat, but I'm fine either way + not sure if that actually helps here. (Thinking of e.g. the thin template idiom)

@nathan-russell
Copy link
Contributor Author

That's fine; I'll put it in MatrixBase. If there is some benefit, then that's great, and if not, we won't be any worse off for it.

As a side note, for the zeros function I had been constructing the return object to size, and then making a pass with

std::fill(
    res.begin(), res.end(), 
    traits::zero_type<stored_type>()
);

But as far as I can tell, Matrix::Matrix(int, int) will zero-initialize its data by default, meaning that the std::fill call is doing unnecessary work. Should this extra step be omitted here / can I rely on the values being zeroed properly by the constructor?

@eddelbuettel
Copy link
Member

eddelbuettel commented Oct 24, 2016

Yes, I think you can. This is the default behaviour here unless you call no_fill().

Edit: Don;t believe a word I am saying^Htyping. As @kevinushey wrote, no_init() it is.

@kevinushey
Copy link
Contributor

The other mechanism for generating vectors / matrices without initialized memory is with the no_init() static function. (They seem relatively unknown, but I find them useful)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants