Discussion:
[Rcpp-devel] A tough RcppArmadillo Error; address(nil) cause 'unknown' in R
井澤 毅
2017-07-01 18:06:15 UTC
Permalink
Dear rcpp-***@lists.r-forge.r-project.org,

Sorry for bothering you much, but do me a favor please. Please help me
some.

I am just a molecular biologist working on plants. Thus, I am still a
newcomer in this field.

Recently, I have been working with a script using RcppArmadillo, This
has helped me a lot. However, after updating the system in our
institute, the script gives me an error repeatedly. My former Postdoc
wrote this script. Thus, I did not know this inside much.

I have tried to fix it for more than a month, but now I have no idea how
to fix it. I would appreciate it very much if you could help and give me
your advice.

Please see an attached cpp file, termed ge-r.cpp. With this cpp file and
other ones, I have succeeded to install a skeleton R package into R
using your function Rcpp.package.skeleton.

In this ge-r.cpp, there is one R function called simulate_R() written.
In this R fucntion, there are two C++ functions, load() and simulate(),
both are described in other cpp files, called from C++ into R. With cout
function described in simulate_R(), I confirmed these two function work
in R thanks to RcppArmadillo, however, it suddenly stops with an error,
address(nil) cause 'unknown' in R. It has seemed to stop when it return
(out) at the last in ge-r.cpp. I do not know why it happens. Note that
the C++ script works normally after the update of the system. Only this
RcppArmadillo conversion from C++ function into a R function is deformed.

Please give me an advice, please. Of course, I can give you more
information on the C++ script in details if you need.

Best regards,

Takeshi



ge-r.cpp

#ifndef __R__

#define __R__
#endif

#ifndef USE_OMP
#define USE_OMP
#endif


#include <RcppArmadillo.h>


#include "ge-model.h"

using namespace arma;



// input:
// parameter matrix: row for particle, col for parameter
// filename of observation
// output:
// simulation for regular time points: row for particle, col for time, slice for term
// existing observation to corresponding regular time points

// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
Rcpp::List simulate_R(const arma::mat& param_r, const char* fobs, const int interval) {

try {
geModel Model;
Model.n_thread=omp_get_num_procs();
Model._param=param_r;
cout << "params set.\n";

cout << "filename of obs: "<< fobs << ".\n";

Model._obs.load(fobs);

cout << "obs loaded.\n";

Model.n_acc=Model._param.n_rows;
cout << "n_acc set to be " << Model.n_acc << ".\n";

Model._obs._out_interval = interval;
Model._obs._n_out_date = (Model._obs._n_date / Model._obs._out_interval) + 1;

Model.out_y=cube(Model.n_acc, Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);

cout << "output matrix initialized.\n";

//necessary for simulate_obs
Model._distance=vec(Model.n_acc);

Model.simulate(0,Model.n_acc-1,true);
cout << "simulation complete.\n";

fflush(stdout);

cout << size(Model.out_y)<<".\n"<< Model.out_y[0]<<".\n"<<Model.out_y[1]<<".\n"<<Model.out_y[2]<<".\n";

Rcpp::List out = Rcpp::List::create(
Rcpp::Named("out_y")=Model.out_y,
Rcpp::Named("out_res_1")=Model.out_res_1,
Rcpp::Named("out_res_2")=Model.out_res_2,
Rcpp::Named("out_res_clock")=Model.out_res_clock,
Rcpp::Named("out_res_dev")=Model.out_res_dev
);

cout << "List constructed.\n";

fflush(stdout);

return (out);
}

catch(char* e) {
cout << e << "\n";
exit(EXIT_FAILURE);
}
catch(...) {
cout << "Error\n";
exit(EXIT_FAILURE);
}
}
Qiang Kou
2017-07-03 20:40:13 UTC
Permalink
Hi, I am afraid the example you provided is not a reproducible example.

First, we don't know the content of ge-model.h. Second, we don't know which
input will trigger the fault.

Please provide a reproducible example if you really want to get help.

Best,

KK
Post by 井澤 毅
Sorry for bothering you much, but do me a favor please. Please help me
some.
I am just a molecular biologist working on plants. Thus, I am still a
newcomer in this field.
Recently, I have been working with a script using RcppArmadillo, This has
helped me a lot. However, after updating the system in our institute, the
script gives me an error repeatedly. My former Postdoc wrote this script.
Thus, I did not know this inside much.
I have tried to fix it for more than a month, but now I have no idea how
to fix it. I would appreciate it very much if you could help and give me
your advice.
Please see an attached cpp file, termed ge-r.cpp. With this cpp file and
other ones, I have succeeded to install a skeleton R package into R using
your function Rcpp.package.skeleton.
In this ge-r.cpp, there is one R function called simulate_R() written. In
this R fucntion, there are two C++ functions, load() and simulate(), both
are described in other cpp files, called from C++ into R. With cout
function described in simulate_R(), I confirmed these two function work in
R thanks to RcppArmadillo, however, it suddenly stops with an error,
address(nil) cause 'unknown' in R. It has seemed to stop when it return
(out) at the last in ge-r.cpp. I do not know why it happens. Note that the
C++ script works normally after the update of the system. Only this
RcppArmadillo conversion from C++ function into a R function is deformed.
Please give me an advice, please. Of course, I can give you more
information on the C++ script in details if you need.
Best regards,
Takeshi
ge-r.cpp
#ifndef __R__
#define __R__
#endif
#ifndef USE_OMP
#define USE_OMP
#endif
#include <RcppArmadillo.h>
#include "ge-model.h"
using namespace arma;
// parameter matrix: row for particle, col for parameter
// filename of observation
// simulation for regular time points: row for particle, col for time, slice for term
// existing observation to corresponding regular time points
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
Rcpp::List simulate_R(const arma::mat& param_r, const char* fobs, const int interval) {
try {
geModel Model;
Model.n_thread=omp_get_num_procs();
Model._param=param_r;
cout << "params set.\n";
cout << "filename of obs: "<< fobs << ".\n";
Model._obs.load(fobs);
cout << "obs loaded.\n";
Model.n_acc=Model._param.n_rows;
cout << "n_acc set to be " << Model.n_acc << ".\n";
Model._obs._out_interval = interval;
Model._obs._n_out_date = (Model._obs._n_date / Model._obs._out_interval) + 1;
Model.out_y=cube(Model.n_acc, Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
cout << "output matrix initialized.\n";
//necessary for simulate_obs
Model._distance=vec(Model.n_acc);
Model.simulate(0,Model.n_acc-1,true);
cout << "simulation complete.\n";
fflush(stdout);
cout << size(Model.out_y)<<".\n"<< Model.out_y[0]<<".\n"<<Model.out_y[1]<<".\n"<<Model.out_y[2]<<".\n";
Rcpp::List out = Rcpp::List::create(
Rcpp::Named("out_y")=Model.out_y,
Rcpp::Named("out_res_1")=Model.out_res_1,
Rcpp::Named("out_res_2")=Model.out_res_2,
Rcpp::Named("out_res_clock")=Model.out_res_clock,
Rcpp::Named("out_res_dev")=Model.out_res_dev
);
cout << "List constructed.\n";
fflush(stdout);
return (out);
}
catch(char* e) {
cout << e << "\n";
exit(EXIT_FAILURE);
}
catch(...) {
cout << "Error\n";
exit(EXIT_FAILURE);
}
}
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Qiang Kou
***@umail.iu.edu
School of Informatics and Computing, Indiana University
Qiang Kou
2017-07-09 22:38:08 UTC
Permalink
Hi, professor,

I think the problem is in ge-r. cpp, you forgot to call *initialize*.

The error has nothing to do with Rcpp.

Best,

KK
Sorry, I forgot the attached file.
Dear KK,
Thanks for your kind reply.
I am afraid that one of the input file is very heavy, this time but I am
sending a ZIP file including all.
Please make v30 package using install.simulate_R_1.r and then
install.simulate_R_2.r. Then, try ge-r_test.r, please.
To make the v30 package, we need ge-r.cpp, ge-model.cpp, ge-model.h,
ge-obs.cpp, ge-obs.h, ge-range.h.
As the input file, we need var.mat.all matrix data in R and
obs.Os01g0182600_g1.nc file in the directry.
Then, you will see the error I have been suffering from for a month.
The obs.Os01g0182600_g1.nc file is a file containing environmental
fluctuation data.
Best,
Takeshi
Hi, I am afraid the example you provided is not a reproducible example.
First, we don't know the content of ge-model.h. Second, we don't know
which input will trigger the fault.
Please provide a reproducible example if you really want to get help.
Best,
KK
Post by 井澤 毅
Sorry for bothering you much, but do me a favor please. Please help me
some.
I am just a molecular biologist working on plants. Thus, I am still a
newcomer in this field.
Recently, I have been working with a script using RcppArmadillo, This has
helped me a lot. However, after updating the system in our institute, the
script gives me an error repeatedly. My former Postdoc wrote this script.
Thus, I did not know this inside much.
I have tried to fix it for more than a month, but now I have no idea how
to fix it. I would appreciate it very much if you could help and give me
your advice.
Please see an attached cpp file, termed ge-r.cpp. With this cpp file and
other ones, I have succeeded to install a skeleton R package into R using
your function Rcpp.package.skeleton.
In this ge-r.cpp, there is one R function called simulate_R() written. In
this R fucntion, there are two C++ functions, load() and simulate(), both
are described in other cpp files, called from C++ into R. With cout
function described in simulate_R(), I confirmed these two function work in
R thanks to RcppArmadillo, however, it suddenly stops with an error,
address(nil) cause 'unknown' in R. It has seemed to stop when it return
(out) at the last in ge-r.cpp. I do not know why it happens. Note that the
C++ script works normally after the update of the system. Only this
RcppArmadillo conversion from C++ function into a R function is deformed.
Please give me an advice, please. Of course, I can give you more
information on the C++ script in details if you need.
Best regards,
Takeshi
ge-r.cpp
#ifndef __R__
#define __R__
#endif
#ifndef USE_OMP
#define USE_OMP
#endif
#include <RcppArmadillo.h>
#include "ge-model.h"
using namespace arma;
// parameter matrix: row for particle, col for parameter
// filename of observation
// simulation for regular time points: row for particle, col for time, slice for term
// existing observation to corresponding regular time points
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
Rcpp::List simulate_R(const arma::mat& param_r, const char* fobs, const int interval) {
try {
geModel Model;
Model.n_thread=omp_get_num_procs();
Model._param=param_r;
cout << "params set.\n";
cout << "filename of obs: "<< fobs << ".\n";
Model._obs.load(fobs);
cout << "obs loaded.\n";
Model.n_acc=Model._param.n_rows;
cout << "n_acc set to be " << Model.n_acc << ".\n";
Model._obs._out_interval = interval;
Model._obs._n_out_date = (Model._obs._n_date / Model._obs._out_interval) + 1;
Model.out_y=cube(Model.n_acc, Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
cout << "output matrix initialized.\n";
//necessary for simulate_obs
Model._distance=vec(Model.n_acc);
Model.simulate(0,Model.n_acc-1,true);
cout << "simulation complete.\n";
fflush(stdout);
cout << size(Model.out_y)<<".\n"<< Model.out_y[0]<<".\n"<<Model.out_y[1]<<".\n"<<Model.out_y[2]<<".\n";
Rcpp::List out = Rcpp::List::create(
Rcpp::Named("out_y")=Model.out_y,
Rcpp::Named("out_res_1")=Model.out_res_1,
Rcpp::Named("out_res_2")=Model.out_res_2,
Rcpp::Named("out_res_clock")=Model.out_res_clock,
Rcpp::Named("out_res_dev")=Model.out_res_dev
);
cout << "List constructed.\n";
fflush(stdout);
return (out);
}
catch(char* e) {
cout << e << "\n";
exit(EXIT_FAILURE);
}
catch(...) {
cout << "Error\n";
exit(EXIT_FAILURE);
}
}
_______________________________________________ Rcpp-devel mailing list
t.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Qiang Kou
School of Informatics and Computing, Indiana University
--
Qiang Kou
***@umail.iu.edu
School of Informatics and Computing, Indiana University
井澤 毅
2017-07-10 04:03:16 UTC
Permalink
Dear KK,

Thanks for this explanation. Now I got it.

I did not think that ge-model.cpp is involved in this problem since it
works well as a C++ script even in our current system.

I still wonder why this ge-r.cpp works in the old system, but I will ask
this to the maintainer of our system.

I have learned a lot from your suggestion.

Thanks again!

Best,

Takeshi
In line 37 of ge-model.cpp, you try to free _rand. However, if you
don't call initialize in line 49 first, the array won't be initialized.
Best,
KK
Dear KK,
I owe you a lot! I will check it as soon as possible.
Since I am not familiar with this much, I would be very happy to
tell me some urls describing "initialize".
Best,
Takeshi
Post by Qiang Kou
Hi, professor,
I think the problem is in ge-r. cpp, you forgot to call *initialize*.
The error has nothing to do with Rcpp.
Best,
KK
On Tue, Jul 4, 2017 at 2:45 AM, 井柀 毅
Sorry, I forgot the attached file.
Dear KK,
Thanks for your kind reply.
I am afraid that one of the input file is very heavy, this
time but I am sending a ZIP file including all.
Please make v30 package using install.simulate_R_1.r and
then install.simulate_R_2.r. Then, try ge-r_test.r, please.
To make the v30 package, we need ge-r.cpp, ge-model.cpp,
ge-model.h, ge-obs.cpp, ge-obs.h, ge-range.h.
As the input file, we need var.mat.all matrix data in R and
obs.Os01g0182600_g1.nc <http://obs.Os01g0182600_g1.nc> file
in the directry.
Then, you will see the error I have been suffering from for a month.
The obs.Os01g0182600_g1.nc
<http://obs.Os01g0182600_g1.nc> file is a file containing
environmental fluctuation data.
Best,
Takeshi
Post by Qiang Kou
Hi, I am afraid the example you provided is not a
reproducible example.
First, we don't know the content of ge-model.h. Second, we
don't know which input will trigger the fault.
Please provide a reproducible example if you really want to get help.
Best,
KK
On Sat, Jul 1, 2017 at 11:06 AM, 井柀 毅
Sorry for bothering you much, but do me a favor please.
Please help me some.
I am just a molecular biologist working on plants.
Thus, I am still a newcomer in this field.
Recently, I have been working with a script using
RcppArmadillo, This has helped me a lot. However, after
updating the system in our institute, the script gives
me an error repeatedly. My former Postdoc wrote this
script. Thus, I did not know this inside much.
I have tried to fix it for more than a month, but now I
have no idea how to fix it. I would appreciate it very
much if you could help and give me your advice.
Please see an attached cpp file, termed ge-r.cpp. With
this cpp file and other ones, I have succeeded to
install a skeleton R package into R using your function
Rcpp.package.skeleton.
In this ge-r.cpp, there is one R function called
simulate_R() written. In this R fucntion, there are two
C++ functions, load() and simulate(), both are
described in other cpp files, called from C++ into R.
With cout function described in simulate_R(), I
confirmed these two function work in R thanks to
RcppArmadillo, however, it suddenly stops with an
error, address(nil) cause 'unknown' in R. It has
seemed to stop when it return (out) at the last in
ge-r.cpp. I do not know why it happens. Note that the
C++ script works normally after the update of the
system. Only this RcppArmadillo conversion from C++
function into a R function is deformed.
Please give me an advice, please. Of course, I can give
you more information on the C++ script in details if
you need.
Best regards,
Takeshi
ge-r.cpp
#ifndef __R__
#define __R__
#endif
#ifndef USE_OMP
#define USE_OMP
#endif
#include <RcppArmadillo.h>
#include "ge-model.h"
using namespace arma;
// parameter matrix: row for particle, col for parameter
// filename of observation
// simulation for regular time points: row for particle, col for time, slice for term
// existing observation to corresponding regular time points
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
Rcpp::List simulate_R(const arma::mat& param_r, const char* fobs, const int interval) {
try {
geModel Model;
Model.n_thread=omp_get_num_procs();
Model._param=param_r;
cout << "params set.\n";
cout << "filename of obs: "<< fobs << ".\n";
Model._obs.load(fobs);
cout << "obs loaded.\n";
Model.n_acc=Model._param.n_rows;
cout << "n_acc set to be " << Model.n_acc << ".\n";
Model._obs._out_interval = interval;
Model._obs._n_out_date = (Model._obs._n_date / Model._obs._out_interval) + 1;
Model.out_y=cube(Model.n_acc, Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
cout << "output matrix initialized.\n";
//necessary for simulate_obs
Model._distance=vec(Model.n_acc);
Model.simulate(0,Model.n_acc-1,true);
cout << "simulation complete.\n";
fflush(stdout);
cout << size(Model.out_y)<<".\n"<< Model.out_y[0]<<".\n"<<Model.out_y[1]<<".\n"<<Model.out_y[2]<<".\n";
Rcpp::List out = Rcpp::List::create(
Rcpp::Named("out_y")=Model.out_y,
Rcpp::Named("out_res_1")=Model.out_res_1,
Rcpp::Named("out_res_2")=Model.out_res_2,
Rcpp::Named("out_res_clock")=Model.out_res_clock,
Rcpp::Named("out_res_dev")=Model.out_res_dev
);
cout << "List constructed.\n";
fflush(stdout);
return (out);
}
catch(char* e) {
cout << e << "\n";
exit(EXIT_FAILURE);
}
catch(...) {
cout << "Error\n";
exit(EXIT_FAILURE);
}
}
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
<https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel>
--
Qiang Kou
School of Informatics and Computing, Indiana University
--
Qiang Kou
School of Informatics and Computing, Indiana University
--
Qiang Kou
School of Informatics and Computing, Indiana University
井澤 毅
2017-07-10 04:55:31 UTC
Permalink
Dear KK,

Sorry for bothering you again, I still have some problems.

According to your advice, in order to initialize the array in ge-r.cpp,

I put


Model.out_y=cube(Model.n_acc, Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);

instead of the old ones,

Model.out_y=cube(Model.n_acc, Model._obs._n_group,
Model._obs._n_out_date);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date);

However, I got the same error in R.

What should I do next ?

I am afraid that I do not know how rand generated in ge-model.cpp (line
37) is linked to the array in ge-r.cpp (line 49) yet. Should I use
fill:: randu instead of fill:: zeros?

Best,

Takeshi
Dear KK,
Thanks for this explanation. Now I got it.
I did not think that ge-model.cpp is involved in this problem since it
works well as a C++ script even in our current system.
I still wonder why this ge-r.cpp works in the old system, but I will
ask this to the maintainer of our system.
I have learned a lot from your suggestion.
Thanks again!
Best,
Takeshi
In line 37 of ge-model.cpp, you try to free _rand. However, if you
don't call initialize in line 49 first, the array won't be initialized.
Best,
KK
Dear KK,
I owe you a lot! I will check it as soon as possible.
Since I am not familiar with this much, I would be very happy to
tell me some urls describing "initialize".
Best,
Takeshi
Post by Qiang Kou
Hi, professor,
I think the problem is in ge-r. cpp, you forgot to call
*initialize*.
The error has nothing to do with Rcpp.
Best,
KK
On Tue, Jul 4, 2017 at 2:45 AM, 井柀 毅
Sorry, I forgot the attached file.
Dear KK,
Thanks for your kind reply.
I am afraid that one of the input file is very heavy, this
time but I am sending a ZIP file including all.
Please make v30 package using install.simulate_R_1.r and
then install.simulate_R_2.r. Then, try ge-r_test.r, please.
To make the v30 package, we need ge-r.cpp, ge-model.cpp,
ge-model.h, ge-obs.cpp, ge-obs.h, ge-range.h.
As the input file, we need var.mat.all matrix data in R and
obs.Os01g0182600_g1.nc <http://obs.Os01g0182600_g1.nc> file
in the directry.
Then, you will see the error I have been suffering from for a month.
The obs.Os01g0182600_g1.nc
<http://obs.Os01g0182600_g1.nc> file is a file containing
environmental fluctuation data.
Best,
Takeshi
Post by Qiang Kou
Hi, I am afraid the example you provided is not a
reproducible example.
First, we don't know the content of ge-model.h. Second, we
don't know which input will trigger the fault.
Please provide a reproducible example if you really want
to get help.
Best,
KK
On Sat, Jul 1, 2017 at 11:06 AM, 井柀 毅
Sorry for bothering you much, but do me a favor
please. Please help me some.
I am just a molecular biologist working on plants.
Thus, I am still a newcomer in this field.
Recently, I have been working with a script using
RcppArmadillo, This has helped me a lot. However,
after updating the system in our institute, the script
this script. Thus, I did not know this inside much.
I have tried to fix it for more than a month, but now
I have no idea how to fix it. I would appreciate it
very much if you could help and give me your advice.
Please see an attached cpp file, termed ge-r.cpp. With
this cpp file and other ones, I have succeeded to
install a skeleton R package into R using your
function Rcpp.package.skeleton.
In this ge-r.cpp, there is one R function called
simulate_R() written. In this R fucntion, there are
two C++ functions, load() and simulate(), both are
described in other cpp files, called from C++ into R.
With cout function described in simulate_R(), I
confirmed these two function work in R thanks to
RcppArmadillo, however, it suddenly stops with an
error, address(nil) cause 'unknown' in R. It has
seemed to stop when it return (out) at the last in
ge-r.cpp. I do not know why it happens. Note that the
C++ script works normally after the update of the
system. Only this RcppArmadillo conversion from C++
function into a R function is deformed.
Please give me an advice, please. Of course, I can
give you more information on the C++ script in details
if you need.
Best regards,
Takeshi
ge-r.cpp
#ifndef __R__
#define __R__
#endif
#ifndef USE_OMP
#define USE_OMP
#endif
#include <RcppArmadillo.h>
#include "ge-model.h"
using namespace arma;
// parameter matrix: row for particle, col for parameter
// filename of observation
// simulation for regular time points: row for particle, col for time, slice for term
// existing observation to corresponding regular time points
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
Rcpp::List simulate_R(const arma::mat& param_r, const char* fobs, const int interval) {
try {
geModel Model;
Model.n_thread=omp_get_num_procs();
Model._param=param_r;
cout << "params set.\n";
cout << "filename of obs: "<< fobs << ".\n";
Model._obs.load(fobs);
cout << "obs loaded.\n";
Model.n_acc=Model._param.n_rows;
cout << "n_acc set to be " << Model.n_acc << ".\n";
Model._obs._out_interval = interval;
Model._obs._n_out_date = (Model._obs._n_date / Model._obs._out_interval) + 1;
Model.out_y=cube(Model.n_acc, Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
cout << "output matrix initialized.\n";
//necessary for simulate_obs
Model._distance=vec(Model.n_acc);
Model.simulate(0,Model.n_acc-1,true);
cout << "simulation complete.\n";
fflush(stdout);
cout << size(Model.out_y)<<".\n"<< Model.out_y[0]<<".\n"<<Model.out_y[1]<<".\n"<<Model.out_y[2]<<".\n";
Rcpp::List out = Rcpp::List::create(
Rcpp::Named("out_y")=Model.out_y,
Rcpp::Named("out_res_1")=Model.out_res_1,
Rcpp::Named("out_res_2")=Model.out_res_2,
Rcpp::Named("out_res_clock")=Model.out_res_clock,
Rcpp::Named("out_res_dev")=Model.out_res_dev
);
cout << "List constructed.\n";
fflush(stdout);
return (out);
}
catch(char* e) {
cout << e << "\n";
exit(EXIT_FAILURE);
}
catch(...) {
cout << "Error\n";
exit(EXIT_FAILURE);
}
}
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
<https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel>
--
Qiang Kou
School of Informatics and Computing, Indiana University
--
Qiang Kou
School of Informatics and Computing, Indiana University
--
Qiang Kou
School of Informatics and Computing, Indiana University
Qiang Kou
2017-07-10 05:04:00 UTC
Permalink
I mean line 49 in ge-model.cpp. You have a function called "initialize"
there.

The "initialize" function will initialize the _rand array.

Best,

KK
Dear KK,
Sorry for bothering you again, I still have some problems.
According to your advice, in order to initialize the array in ge-r.cpp,
I put
Model.out_y=cube(Model.n_acc, Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
instead of the old ones,
Model.out_y=cube(Model.n_acc, Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date);
However, I got the same error in R.
What should I do next ?
I am afraid that I do not know how rand generated in ge-model.cpp (line
randu instead of fill:: zeros?
Best,
Takeshi
Dear KK,
Thanks for this explanation. Now I got it.
I did not think that ge-model.cpp is involved in this problem since it
works well as a C++ script even in our current system.
I still wonder why this ge-r.cpp works in the old system, but I will ask
this to the maintainer of our system.
I have learned a lot from your suggestion.
Thanks again!
Best,
Takeshi
In line 37 of ge-model.cpp, you try to free _rand. However, if you don't
call initialize in line 49 first, the array won't be initialized.
Best,
KK
Dear KK,
I owe you a lot! I will check it as soon as possible.
Since I am not familiar with this much, I would be very happy to tell me
some urls describing "initialize".
Best,
Takeshi
Hi, professor,
I think the problem is in ge-r. cpp, you forgot to call *initialize*.
The error has nothing to do with Rcpp.
Best,
KK
Sorry, I forgot the attached file.
Dear KK,
Thanks for your kind reply.
I am afraid that one of the input file is very heavy, this time but I am
sending a ZIP file including all.
Please make v30 package using install.simulate_R_1.r and then
install.simulate_R_2.r. Then, try ge-r_test.r, please.
To make the v30 package, we need ge-r.cpp, ge-model.cpp, ge-model.h,
ge-obs.cpp, ge-obs.h, ge-range.h.
As the input file, we need var.mat.all matrix data in R and
obs.Os01g0182600_g1.nc file in the directry.
Then, you will see the error I have been suffering from for a month.
The obs.Os01g0182600_g1.nc file is a file containing environmental
fluctuation data.
Best,
Takeshi
Hi, I am afraid the example you provided is not a reproducible example.
First, we don't know the content of ge-model.h. Second, we don't know
which input will trigger the fault.
Please provide a reproducible example if you really want to get help.
Best,
KK
Post by 井澤 毅
Sorry for bothering you much, but do me a favor please. Please help me
some.
I am just a molecular biologist working on plants. Thus, I am still a
newcomer in this field.
Recently, I have been working with a script using RcppArmadillo, This
has helped me a lot. However, after updating the system in our institute,
the script gives me an error repeatedly. My former Postdoc wrote this
script. Thus, I did not know this inside much.
I have tried to fix it for more than a month, but now I have no idea
how to fix it. I would appreciate it very much if you could help and give
me your advice.
Please see an attached cpp file, termed ge-r.cpp. With this cpp file
and other ones, I have succeeded to install a skeleton R package into R
using your function Rcpp.package.skeleton.
In this ge-r.cpp, there is one R function called simulate_R() written.
In this R fucntion, there are two C++ functions, load() and simulate(),
both are described in other cpp files, called from C++ into R. With cout
function described in simulate_R(), I confirmed these two function work in
R thanks to RcppArmadillo, however, it suddenly stops with an error,
address(nil) cause 'unknown' in R. It has seemed to stop when it return
(out) at the last in ge-r.cpp. I do not know why it happens. Note that the
C++ script works normally after the update of the system. Only this
RcppArmadillo conversion from C++ function into a R function is deformed.
Please give me an advice, please. Of course, I can give you more
information on the C++ script in details if you need.
Best regards,
Takeshi
ge-r.cpp
#ifndef __R__
#define __R__
#endif
#ifndef USE_OMP
#define USE_OMP
#endif
#include <RcppArmadillo.h>
#include "ge-model.h"
using namespace arma;
// parameter matrix: row for particle, col for parameter
// filename of observation
// simulation for regular time points: row for particle, col for time, slice for term
// existing observation to corresponding regular time points
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
Rcpp::List simulate_R(const arma::mat& param_r, const char* fobs, const int interval) {
try {
geModel Model;
Model.n_thread=omp_get_num_procs();
Model._param=param_r;
cout << "params set.\n";
cout << "filename of obs: "<< fobs << ".\n";
Model._obs.load(fobs);
cout << "obs loaded.\n";
Model.n_acc=Model._param.n_rows;
cout << "n_acc set to be " << Model.n_acc << ".\n";
Model._obs._out_interval = interval;
Model._obs._n_out_date = (Model._obs._n_date / Model._obs._out_interval) + 1;
Model.out_y=cube(Model.n_acc, Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
cout << "output matrix initialized.\n";
//necessary for simulate_obs
Model._distance=vec(Model.n_acc);
Model.simulate(0,Model.n_acc-1,true);
cout << "simulation complete.\n";
fflush(stdout);
cout << size(Model.out_y)<<".\n"<< Model.out_y[0]<<".\n"<<Model.out_y[1]<<".\n"<<Model.out_y[2]<<".\n";
Rcpp::List out = Rcpp::List::create(
Rcpp::Named("out_y")=Model.out_y,
Rcpp::Named("out_res_1")=Model.out_res_1,
Rcpp::Named("out_res_2")=Model.out_res_2,
Rcpp::Named("out_res_clock")=Model.out_res_clock,
Rcpp::Named("out_res_dev")=Model.out_res_dev
);
cout << "List constructed.\n";
fflush(stdout);
return (out);
}
catch(char* e) {
cout << e << "\n";
exit(EXIT_FAILURE);
}
catch(...) {
cout << "Error\n";
exit(EXIT_FAILURE);
}
}
_______________________________________________ Rcpp-devel mailing
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Qiang Kou
School of Informatics and Computing, Indiana University
--
Qiang Kou
School of Informatics and Computing, Indiana University
--
Qiang Kou
School of Informatics and Computing, Indiana University
--
Qiang Kou
***@umail.iu.edu
School of Informatics and Computing, Indiana University
井澤 毅
2017-07-10 05:36:22 UTC
Permalink
Dear KK,

Thanks for your advice. I am afraid that the "initialize" function would
make the initial parameters for our machine learning using an improved
ABC method.

After this learning, we got a thousand of selected parameter sets which
would mimic the updated parameter distributions, those are described in
var.mat.all in this case. Then, this time we use this like
simulate_R(var.mat.all, fobs="observed data", interval=6).

Thus, I am afraid that we do not need the initialize function for
simulation when we use the updated parameter sets. In fact, I confirmed
the simulation using simulate_R() works in R but did not give me the
"out" list as a result.

In this term, I am thinking the "out" list was not generated, due to
"the initialization of the array". But I have no idea how to generate
"out" list.

Best,

Takeshi
Post by Qiang Kou
I mean line 49 in ge-model.cpp. You have a function called
"initialize" there.
The "initialize" function will initialize the _rand array.
Best,
KK
Dear KK,
Sorry for bothering you again, I still have some problems.
According to your advice, in order to initialize the array in ge-r.cpp,
I put
Model.out_y=cube(Model.n_acc, Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date,fill::zeros);
instead of the old ones,
Model.out_y=cube(Model.n_acc, Model._obs._n_group,
Model._obs._n_out_date);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group,
Model._obs._n_out_date);
However, I got the same error in R.
What should I do next ?
I am afraid that I do not know how rand generated in ge-model.cpp
(line 37) is linked to the array in ge-r.cpp (line 49) yet. Should
I use fill:: randu instead of fill:: zeros?
Best,
Takeshi
Dear KK,
Thanks for this explanation. Now I got it.
I did not think that ge-model.cpp is involved in this problem
since it works well as a C++ script even in our current system.
I still wonder why this ge-r.cpp works in the old system, but I
will ask this to the maintainer of our system.
I have learned a lot from your suggestion.
Thanks again!
Best,
Takeshi
In line 37 of ge-model.cpp, you try to free _rand. However, if
you don't call initialize in line 49 first, the array won't be
initialized.
Best,
KK
On Sun, Jul 9, 2017 at 4:45 PM, 井柀 毅
Dear KK,
I owe you a lot! I will check it as soon as possible.
Since I am not familiar with this much, I would be very
happy to tell me some urls describing "initialize".
Best,
Takeshi
Post by Qiang Kou
Hi, professor,
I think the problem is in ge-r. cpp, you forgot to call *initialize*.
The error has nothing to do with Rcpp.
Best,
KK
On Tue, Jul 4, 2017 at 2:45 AM, 井柀 毅
Sorry, I forgot the attached file.
Dear KK,
Thanks for your kind reply.
I am afraid that one of the input file is very heavy,
this time but I am sending a ZIP file including all.
Please make v30 package using install.simulate_R_1.r
and then install.simulate_R_2.r. Then, try
ge-r_test.r, please.
To make the v30 package, we need ge-r.cpp,
ge-model.cpp, ge-model.h, ge-obs.cpp, ge-obs.h,
ge-range.h.
As the input file, we need var.mat.all matrix data in
R and obs.Os01g0182600_g1.nc
<http://obs.Os01g0182600_g1.nc> file in the directry.
Then, you will see the error I have been suffering
from for a month.
The obs.Os01g0182600_g1.nc
<http://obs.Os01g0182600_g1.nc> file is a file
containing environmental fluctuation data.
Best,
Takeshi
Post by Qiang Kou
Hi, I am afraid the example you provided is not a
reproducible example.
First, we don't know the content of ge-model.h.
Second, we don't know which input will trigger the fault.
Please provide a reproducible example if you really
want to get help.
Best,
KK
On Sat, Jul 1, 2017 at 11:06 AM, 井柀 毅
Sorry for bothering you much, but do me a favor
please. Please help me some.
I am just a molecular biologist working on
plants. Thus, I am still a newcomer in this field.
Recently, I have been working with a script using
RcppArmadillo, This has helped me a lot. However,
after updating the system in our institute, the
script gives me an error repeatedly. My former
Postdoc wrote this script. Thus, I did not know
this inside much.
I have tried to fix it for more than a month, but
now I have no idea how to fix it. I would
appreciate it very much if you could help and
give me your advice.
Please see an attached cpp file, termed ge-r.cpp.
With this cpp file and other ones, I have
succeeded to install a skeleton R package into R
using your function Rcpp.package.skeleton.
In this ge-r.cpp, there is one R function called
simulate_R() written. In this R fucntion, there
are two C++ functions, load() and simulate(),
both are described in other cpp files, called
from C++ into R. With cout function described in
simulate_R(), I confirmed these two function work
in R thanks to RcppArmadillo, however, it
suddenly stops with an error, address(nil) cause
'unknown' in R. It has seemed to stop when it
return (out) at the last in ge-r.cpp. I do not
know why it happens. Note that the C++ script
works normally after the update of the system.
Only this RcppArmadillo conversion from C++
function into a R function is deformed.
Please give me an advice, please. Of course, I
can give you more information on the C++ script
in details if you need.
Best regards,
Takeshi
ge-r.cpp
#ifndef __R__
#define __R__
#endif
#ifndef USE_OMP
#define USE_OMP
#endif
#include <RcppArmadillo.h>
#include "ge-model.h"
using namespace arma;
// parameter matrix: row for particle, col for parameter
// filename of observation
// simulation for regular time points: row for particle, col for time, slice for term
// existing observation to corresponding regular time points
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
Rcpp::List simulate_R(const arma::mat& param_r, const char* fobs, const int interval) {
try {
geModel Model;
Model.n_thread=omp_get_num_procs();
Model._param=param_r;
cout << "params set.\n";
cout << "filename of obs: "<< fobs << ".\n";
Model._obs.load(fobs);
cout << "obs loaded.\n";
Model.n_acc=Model._param.n_rows;
cout << "n_acc set to be " << Model.n_acc << ".\n";
Model._obs._out_interval = interval;
Model._obs._n_out_date = (Model._obs._n_date / Model._obs._out_interval) + 1;
Model.out_y=cube(Model.n_acc, Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_1=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_2=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_clock=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
Model.out_res_dev=cube(Model.n_acc,Model._obs._n_group, Model._obs._n_out_date);
cout << "output matrix initialized.\n";
//necessary for simulate_obs
Model._distance=vec(Model.n_acc);
Model.simulate(0,Model.n_acc-1,true);
cout << "simulation complete.\n";
fflush(stdout);
cout << size(Model.out_y)<<".\n"<< Model.out_y[0]<<".\n"<<Model.out_y[1]<<".\n"<<Model.out_y[2]<<".\n";
Rcpp::List out = Rcpp::List::create(
Rcpp::Named("out_y")=Model.out_y,
Rcpp::Named("out_res_1")=Model.out_res_1,
Rcpp::Named("out_res_2")=Model.out_res_2,
Rcpp::Named("out_res_clock")=Model.out_res_clock,
Rcpp::Named("out_res_dev")=Model.out_res_dev
);
cout << "List constructed.\n";
fflush(stdout);
return (out);
}
catch(char* e) {
cout << e << "\n";
exit(EXIT_FAILURE);
}
catch(...) {
cout << "Error\n";
exit(EXIT_FAILURE);
}
}
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
<https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel>
--
Qiang Kou
School of Informatics and Computing, Indiana University
--
Qiang Kou
School of Informatics and Computing, Indiana University
--
Qiang Kou
School of Informatics and Computing, Indiana University
--
Qiang Kou
School of Informatics and Computing, Indiana University
Qiang Kou
2017-07-10 06:22:56 UTC
Permalink
In the ge-model.cpp, from line 216 to line 225, the *_rand* will be
initialized there.

These lines of code are part of the "initialize" function.

If you don't call the "initialize", the array won't be initialized and
cause a memory error in deconstructor.

Can we discuss off the list?

This really has nothing to do with Rcpp.

Best,

KK

Loading...