Skip to content
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

Error with list of vectors/matrices #352

Closed
pachadotdev opened this issue Jan 27, 2024 · 1 comment
Closed

Error with list of vectors/matrices #352

pachadotdev opened this issue Jan 27, 2024 · 1 comment

Comments

@pachadotdev
Copy link
Contributor

pachadotdev commented Jan 27, 2024

Problem

I am trying to create a list of two matrices, one for the real part and one for the imaginary part of an Armadillo matrix

Working code

I have this code that works

template <typename T>
inline doubles_matrix<> Mat_to_complex_matrix_(const Mat<T>& A) {
  static_assert(is_same<T, complex<double>>::value,
                "T must be complex<double>");
  Mat<double> A_real = real(A);
  Mat<double> A_imag = imag(A);

  int n = A_real.n_rows;
  int m = A_real.n_cols;

  writable::doubles_matrix<> B_real(n, m);
  writable::doubles_matrix<> B_imag(n, m);

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; j++) {
      B_real(i, j) = A_real(i, j);
      B_imag(i, j) = A_imag(i, j);
    }
  }

  return B_real;
}

inline doubles_matrix<> as_complex_matrix(const Mat<complex<double>>& A) {
  return Mat_to_complex_matrix_<complex<double>>(A);
}

Failing code

If I change the output to return writable::list({"real"_nm = B_real, "imag"_nm = B_imag}) as in this example, or I use push_back, it returns

[[1]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]]
[[1]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]]
NULL

[[1]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]]
[[1]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]]
NULL

[[1]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]]
[[1]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]]
NULL

[[1]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]]
[[1]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]]
NULL

[[1]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]]
[[1]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]][[2]]
NULL

Here is the failing code

template <typename T>
inline list Mat_to_complex_matrix_(const Mat<T>& A) {
  static_assert(is_same<T, complex<double>>::value,
                "T must be complex<double>");
  Mat<double> A_real = real(A);
  Mat<double> A_imag = imag(A);

  cout << A_real << endl;
  cout << A_imag << endl;

  int n = A_real.n_rows;
  int m = A_real.n_cols;

  writable::doubles_matrix<> B_real(n, m);
  writable::doubles_matrix<> B_imag(n, m);

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; j++) {
      B_real(i, j) = A_real(i, j);
      B_imag(i, j) = A_imag(i, j);
    }
  }

  // return B_real;

  writable::list B;
  B.push_back({"real"_nm = B_real});
  B.push_back({"imag"_nm = B_imag});

  return B;
}

inline list as_complex_matrix(const Mat<complex<double>>& A) {
  return Mat_to_complex_matrix_<complex<double>>(A);
}

Valgrind output

I run R in debug mode like this https://pacha.dev/capybara/#debugging and I get

cpp11armadillotest (main) $ r_valgrind dev/debug_list_output.r 
==39400== Memcheck, a memory error detector
==39400== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==39400== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==39400== Command: /usr/lib/R/bin/exec/R --vanilla -f dev/debug_list_output.r
==39400== 

R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 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.

> devtools::load_all()
ℹ Loading cpp11armadillotest
> 
> x <- cpp11armadillo::mtcars_mat$x
> y <- cpp11armadillo::mtcars_mat$y
> 
> x <- x[, c("wt", "cyl4", "cyl6", "cyl8")]
> 
> x <- cor(x)
> eigen_gen_mat(x)
   2.3758e+00
   2.6803e-01
   1.3562e+00
   1.2797e-16

        0
        0
        0
        0

==39400== Use of uninitialised value of size 8
==39400==    at 0x49D75F4: CAR (in /usr/lib/R/lib/libR.so)
==39400==    by 0x1389D8CF: cpp11::._anon_147::release(SEXPREC*) (protect.hpp:295)
==39400==    by 0x138A0921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==39400==    by 0x138B4E97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==39400==    by 0x138B46DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==39400==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==39400==  Uninitialised value was created by a stack allocation
==39400==    at 0x138B4623: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:24)
==39400== 
==39400== Use of uninitialised value of size 8
==39400==    at 0x49D75FB: CAR (in /usr/lib/R/lib/libR.so)
==39400==    by 0x1389D8CF: cpp11::._anon_147::release(SEXPREC*) (protect.hpp:295)
==39400==    by 0x138A0921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==39400==    by 0x138B4E97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==39400==    by 0x138B46DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==39400==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==39400==  Uninitialised value was created by a stack allocation
==39400==    at 0x138B4623: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:24)
==39400== 
==39400== Use of uninitialised value of size 8
==39400==    at 0x49E9484: CDR (in /usr/lib/R/lib/libR.so)
==39400==    by 0x1389D8DF: cpp11::._anon_147::release(SEXPREC*) (protect.hpp:296)
==39400==    by 0x138A0921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==39400==    by 0x138B4E97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==39400==    by 0x138B46DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==39400==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==39400==  Uninitialised value was created by a stack allocation
==39400==    at 0x138B4623: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:24)
==39400== 
==39400== Invalid read of size 2
==39400==    at 0x49E97D4: SETCAR (in /usr/lib/R/lib/libR.so)
==39400==    by 0x1389D909: cpp11::._anon_147::release(SEXPREC*) (protect.hpp:302)
==39400==    by 0x138A0921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==39400==    by 0x138B4E97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==39400==    by 0x138B46DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==39400==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==39400==  Address 0x5 is not stack'd, malloc'd or (recently) free'd
==39400== 

 *** caught segfault ***
address 0x5, cause 'memory not mapped'

Traceback:
 1: .Call(`_cpp11armadillotest_eigen_gen_mat`, x)
 2: eigen_gen_mat(x)
An irrecoverable exception occurred. R is aborting now ...
==39400== 
==39400== Process terminating with default action of signal 11 (SIGSEGV)
==39400==    at 0x4D559FC: __pthread_kill_implementation (pthread_kill.c:44)
==39400==    by 0x4D559FC: __pthread_kill_internal (pthread_kill.c:78)
==39400==    by 0x4D559FC: pthread_kill@@GLIBC_2.34 (pthread_kill.c:89)
==39400==    by 0x4D01475: raise (raise.c:26)
==39400==    by 0x4D0151F: ??? (in /usr/lib/x86_64-linux-gnu/libc.so.6)
==39400==    by 0x49E97D3: SETCAR (in /usr/lib/R/lib/libR.so)
==39400== 
==39400== HEAP SUMMARY:
==39400==     in use at exit: 85,757,313 bytes in 19,212 blocks
==39400==   total heap usage: 120,325 allocs, 101,113 frees, 204,680,823 bytes allocated
==39400== 
==39400== LEAK SUMMARY:
==39400==    definitely lost: 0 bytes in 0 blocks
==39400==    indirectly lost: 0 bytes in 0 blocks
==39400==      possibly lost: 5,469 bytes in 25 blocks
==39400==    still reachable: 85,751,844 bytes in 19,187 blocks
==39400==                       of which reachable via heuristic:
==39400==                         newarray           : 4,264 bytes in 1 blocks
==39400==         suppressed: 0 bytes in 0 blocks
==39400== Rerun with --leak-check=full to see details of leaked memory
==39400== 
==39400== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
==39400== 
==39400== 1 errors in context 1 of 4:
==39400== Invalid read of size 2
==39400==    at 0x49E97D4: SETCAR (in /usr/lib/R/lib/libR.so)
==39400==    by 0x1389D909: cpp11::._anon_147::release(SEXPREC*) (protect.hpp:302)
==39400==    by 0x138A0921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==39400==    by 0x138B4E97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==39400==    by 0x138B46DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==39400==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==39400==  Address 0x5 is not stack'd, malloc'd or (recently) free'd
==39400== 
==39400== 
==39400== 1 errors in context 2 of 4:
==39400== Use of uninitialised value of size 8
==39400==    at 0x49E9484: CDR (in /usr/lib/R/lib/libR.so)
==39400==    by 0x1389D8DF: cpp11::._anon_147::release(SEXPREC*) (protect.hpp:296)
==39400==    by 0x138A0921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==39400==    by 0x138B4E97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==39400==    by 0x138B46DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==39400==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==39400==  Uninitialised value was created by a stack allocation
==39400==    at 0x138B4623: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:24)
==39400== 
==39400== 
==39400== 1 errors in context 3 of 4:
==39400== Use of uninitialised value of size 8
==39400==    at 0x49D75FB: CAR (in /usr/lib/R/lib/libR.so)
==39400==    by 0x1389D8CF: cpp11::._anon_147::release(SEXPREC*) (protect.hpp:295)
==39400==    by 0x138A0921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==39400==    by 0x138B4E97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==39400==    by 0x138B46DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==39400==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==39400==  Uninitialised value was created by a stack allocation
==39400==    at 0x138B4623: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:24)
==39400== 
==39400== 
==39400== 1 errors in context 4 of 4:
==39400== Use of uninitialised value of size 8
==39400==    at 0x49D75F4: CAR (in /usr/lib/R/lib/libR.so)
==39400==    by 0x1389D8CF: cpp11::._anon_147::release(SEXPREC*) (protect.hpp:295)
==39400==    by 0x138A0921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==39400==    by 0x138B4E97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==39400==    by 0x138B46DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==39400==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==39400==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==39400==  Uninitialised value was created by a stack allocation
==39400==    at 0x138B4623: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:24)
==39400== 
==39400== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)

Data types affected

  • doubles_matrix<>
  • vectors (i.e., writable::doubles and std::vector<double>
@pachadotdev
Copy link
Contributor Author

here is valgrind output after using debug symbols

==40431== Memcheck, a memory error detector
==40431== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==40431== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==40431== Command: /usr/lib/R/bin/exec/R --vanilla -f dev/debug_list_output.r
==40431== 

R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 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.

> devtools::load_all()
ℹ Loading cpp11armadillotest
ℹ 5 functions decorated with [[cpp11::register]]
✔ generated file 'cpp11.R'
✔ generated file 'cpp11.cpp'
ℹ Re-compiling cpp11armadillotest (debug build)
── R CMD INSTALL ───────────────────────────────────────────────────────────────
* installing *source* package ‘cpp11armadillotest’ ...
** using staged installation
** libs
using C++ compiler: ‘g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -UDEBUG -g -I'/usr/lib/R/site-library/cpp11/include' -I'/home/pacha/R/x86_64-pc-linux-gnu-library/4.3/cpp11armadillo/include'    -Wall -O0 -pedantic -fpic  -g -O2 -ffile-prefix-map=/build/r-base-H0vbME/r-base-4.3.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -UNDEBUG -Wall -pedantic -g -O0 -c 00_main.cpp -o 00_main.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -UDEBUG -g -I'/usr/lib/R/site-library/cpp11/include' -I'/home/pacha/R/x86_64-pc-linux-gnu-library/4.3/cpp11armadillo/include'    -Wall -O0 -pedantic -fpic  -g -O2 -ffile-prefix-map=/build/r-base-H0vbME/r-base-4.3.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -UNDEBUG -Wall -pedantic -g -O0 -c 02_eigen.cpp -o 02_eigen.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -UDEBUG -g -I'/usr/lib/R/site-library/cpp11/include' -I'/home/pacha/R/x86_64-pc-linux-gnu-library/4.3/cpp11armadillo/include'    -Wall -O0 -pedantic -fpic  -g -O2 -ffile-prefix-map=/build/r-base-H0vbME/r-base-4.3.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -UNDEBUG -Wall -pedantic -g -O0 -c 03_ols.cpp -o 03_ols.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -UDEBUG -g -I'/usr/lib/R/site-library/cpp11/include' -I'/home/pacha/R/x86_64-pc-linux-gnu-library/4.3/cpp11armadillo/include'    -Wall -O0 -pedantic -fpic  -g -O2 -ffile-prefix-map=/build/r-base-H0vbME/r-base-4.3.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -UNDEBUG -Wall -pedantic -g -O0 -c cpp11.cpp -o cpp11.o
g++ -std=gnu++17 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -o cpp11armadillotest.so 00_main.o 02_eigen.o 03_ols.o cpp11.o -fopenmp -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR
installing to /tmp/RtmpH5kdd4/devtools_install_9def12d224ca/00LOCK-cpp11armadillotest/00new/cpp11armadillotest/libs
** checking absolute paths in shared objects and dynamic libraries
* DONE (cpp11armadillotest)
> 
> x <- cpp11armadillo::mtcars_mat$x
> y <- cpp11armadillo::mtcars_mat$y
> 
> x <- x[, c("wt", "cyl4", "cyl6", "cyl8")]
> 
> x <- cor(x)
> eigen_gen_mat(x)
   2.3758e+00
   2.6803e-01
   1.3562e+00
   1.2797e-16

        0
        0
        0
        0

==40431== Use of uninitialised value of size 8
==40431==    at 0x49D75F4: CAR (in /usr/lib/R/lib/libR.so)
==40431==    by 0x15D458CF: cpp11::._anon_145::release(SEXPREC*) (protect.hpp:295)
==40431==    by 0x15D48921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==40431==    by 0x15D5CE97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==40431==    by 0x15D5C6DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==40431==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==40431==  Uninitialised value was created by a stack allocation
==40431==    at 0x15D5C623: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:24)
==40431== 
==40431== Use of uninitialised value of size 8
==40431==    at 0x49D75FB: CAR (in /usr/lib/R/lib/libR.so)
==40431==    by 0x15D458CF: cpp11::._anon_145::release(SEXPREC*) (protect.hpp:295)
==40431==    by 0x15D48921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==40431==    by 0x15D5CE97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==40431==    by 0x15D5C6DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==40431==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==40431==  Uninitialised value was created by a stack allocation
==40431==    at 0x15D5C623: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:24)
==40431== 
==40431== Use of uninitialised value of size 8
==40431==    at 0x49E9484: CDR (in /usr/lib/R/lib/libR.so)
==40431==    by 0x15D458DF: cpp11::._anon_145::release(SEXPREC*) (protect.hpp:296)
==40431==    by 0x15D48921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==40431==    by 0x15D5CE97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==40431==    by 0x15D5C6DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==40431==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==40431==  Uninitialised value was created by a stack allocation
==40431==    at 0x15D5C623: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:24)
==40431== 
==40431== Invalid read of size 1
==40431==    at 0x49E9A40: SETCDR (in /usr/lib/R/lib/libR.so)
==40431==    by 0x15D458F6: cpp11::._anon_145::release(SEXPREC*) (protect.hpp:301)
==40431==    by 0x15D48921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==40431==    by 0x15D5CE97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==40431==    by 0x15D5C6DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==40431==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==40431==  Address 0x111000002 is not stack'd, malloc'd or (recently) free'd
==40431== 

 *** caught segfault ***
address 0x111000002, cause 'memory not mapped'

Traceback:
 1: .Call(`_cpp11armadillotest_eigen_gen_mat`, x)
 2: eigen_gen_mat(x)
An irrecoverable exception occurred. R is aborting now ...
==40431== 
==40431== Process terminating with default action of signal 11 (SIGSEGV)
==40431==    at 0x4D559FC: __pthread_kill_implementation (pthread_kill.c:44)
==40431==    by 0x4D559FC: __pthread_kill_internal (pthread_kill.c:78)
==40431==    by 0x4D559FC: pthread_kill@@GLIBC_2.34 (pthread_kill.c:89)
==40431==    by 0x4D01475: raise (raise.c:26)
==40431==    by 0x4D0151F: ??? (in /usr/lib/x86_64-linux-gnu/libc.so.6)
==40431==    by 0x49E9A3F: SETCDR (in /usr/lib/R/lib/libR.so)
==40431== 
==40431== HEAP SUMMARY:
==40431==     in use at exit: 105,761,591 bytes in 21,349 blocks
==40431==   total heap usage: 166,991 allocs, 145,642 frees, 267,961,699 bytes allocated
==40431== 
==40431== LEAK SUMMARY:
==40431==    definitely lost: 0 bytes in 0 blocks
==40431==    indirectly lost: 0 bytes in 0 blocks
==40431==      possibly lost: 7,151 bytes in 85 blocks
==40431==    still reachable: 105,754,440 bytes in 21,264 blocks
==40431==                       of which reachable via heuristic:
==40431==                         newarray           : 4,264 bytes in 1 blocks
==40431==         suppressed: 0 bytes in 0 blocks
==40431== Rerun with --leak-check=full to see details of leaked memory
==40431== 
==40431== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
==40431== 
==40431== 1 errors in context 1 of 4:
==40431== Invalid read of size 1
==40431==    at 0x49E9A40: SETCDR (in /usr/lib/R/lib/libR.so)
==40431==    by 0x15D458F6: cpp11::._anon_145::release(SEXPREC*) (protect.hpp:301)
==40431==    by 0x15D48921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==40431==    by 0x15D5CE97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==40431==    by 0x15D5C6DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==40431==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==40431==  Address 0x111000002 is not stack'd, malloc'd or (recently) free'd
==40431== 
==40431== 
==40431== 1 errors in context 2 of 4:
==40431== Use of uninitialised value of size 8
==40431==    at 0x49E9484: CDR (in /usr/lib/R/lib/libR.so)
==40431==    by 0x15D458DF: cpp11::._anon_145::release(SEXPREC*) (protect.hpp:296)
==40431==    by 0x15D48921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==40431==    by 0x15D5CE97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==40431==    by 0x15D5C6DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==40431==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==40431==  Uninitialised value was created by a stack allocation
==40431==    at 0x15D5C623: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:24)
==40431== 
==40431== 
==40431== 1 errors in context 3 of 4:
==40431== Use of uninitialised value of size 8
==40431==    at 0x49D75FB: CAR (in /usr/lib/R/lib/libR.so)
==40431==    by 0x15D458CF: cpp11::._anon_145::release(SEXPREC*) (protect.hpp:295)
==40431==    by 0x15D48921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==40431==    by 0x15D5CE97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==40431==    by 0x15D5C6DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==40431==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==40431==  Uninitialised value was created by a stack allocation
==40431==    at 0x15D5C623: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:24)
==40431== 
==40431== 
==40431== 1 errors in context 4 of 4:
==40431== Use of uninitialised value of size 8
==40431==    at 0x49D75F4: CAR (in /usr/lib/R/lib/libR.so)
==40431==    by 0x15D458CF: cpp11::._anon_145::release(SEXPREC*) (protect.hpp:295)
==40431==    by 0x15D48921: cpp11::r_vector<double>::~r_vector() (r_vector.hpp:192)
==40431==    by 0x15D5CE97: cpp11::matrix<cpp11::r_vector<double>, double, cpp11::by_column>::~matrix() (matrix.hpp:77)
==40431==    by 0x15D5C6DD: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:26)
==40431==    by 0x49562DD: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x495685C: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE34F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B1387: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AE10F: Rf_eval (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49AFD95: ??? (in /usr/lib/R/lib/libR.so)
==40431==    by 0x49B0BC4: Rf_applyClosure (in /usr/lib/R/lib/libR.so)
==40431==  Uninitialised value was created by a stack allocation
==40431==    at 0x15D5C623: _cpp11armadillotest_eigen_gen_mat (cpp11.cpp:24)
==40431== 
==40431== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)

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

No branches or pull requests

1 participant