Getting Blob data in caffe - c++

I am trying to plot layer out of caffe as follow.
int ncols = (int)(sqrt (blob.channels()));
int nrows;
if(blob.channels()%ncols!=0){
nrows = ncols+1;
}
int Rows = nrows*blob.height();
int Cols = ncols*blob.width();
cv::Mat image = cv::Mat::zeros(Rows+nrows, Cols+ncols, CV_32FC1);
///////Plotting output of individual layer
if(blob.height()>1 && blob.width()>1){
cv::Size ss(blob.width(), blob.height());
Dtype* data = blob.mutable_cpu_data();
int r=0; int c=0;
for(int k=0; k < blob.channels(); k++)
{
cv::Mat channel(ss, CV_32FC1, data);
channel.copyTo(image(cv::Rect(c*blob.width()+1, r*blob.height()+1, blob.width(), blob.height())));
c++;
if(c>0 &&c%ncols==0){
r++;
c=0;
}
channel.release();
data += ss.area();
}
}
For that I have error as
CXX src/caffe/net.cpp
src/caffe/net.cpp: In instantiation of ‘void caffe::Net<Dtype>::ForwardDebugInfo(int) [with Dtype = float]’:
src/caffe/net.cpp:1040:1: required from here
src/caffe/net.cpp:632:49: error: passing ‘const caffe::Blob<float>’ as ‘this’ argument discards qualifiers [-fpermissive]
Dtype* data = blob.mutable_cpu_data();
^
In file included from ./include/caffe/layer.hpp:8:0,
from src/caffe/net.cpp:11:
./include/caffe/blob.hpp:225:10: note: in call to ‘Dtype* caffe::Blob<Dtype>::mutable_cpu_data() [with Dtype = float]’
Dtype* mutable_cpu_data();
^
src/caffe/net.cpp: In instantiation of ‘void caffe::Net<Dtype>::ForwardDebugInfo(int) [with Dtype = double]’:
src/caffe/net.cpp:1040:1: required from here
src/caffe/net.cpp:632:49: error: passing ‘const caffe::Blob<double>’ as ‘this’ argument discards qualifiers [-fpermissive]
Dtype* data = blob.mutable_cpu_data();
^
In file included from ./include/caffe/layer.hpp:8:0,
from src/caffe/net.cpp:11:
./include/caffe/blob.hpp:225:10: note: in call to ‘Dtype* caffe::Blob<Dtype>::mutable_cpu_data() [with Dtype = double]’
Dtype* mutable_cpu_data();
^
Makefile:575: recipe for target '.build_debug/src/caffe/net.o' failed
make: *** [.build_debug/src/caffe/net.o] Error 1
What does that error means?
Earlier version of caffe, it was fine. I did it before.
Now what could be the error?

That error translates as "You pass a const object as this argument to a non-const method mutable_cpu_data"
const Dtype* cpu_data() const;
Dtype* mutable_cpu_data();
"Passing an object as this argument" suggests use of operators . or -> to access object's method and use of operator().
If you do that, you potentially can change const object, so it's an error, unless permissive mode engaged.

Related

How do you transpose a tensor in LibTorch?

I can't seem to figure out how to transpose a tensor in LibTorch, the (C++ version of PyTorch).
torch::Tensor one_T = torch::rand({6, 6});
int main() {
std::cout << one_T.transpose << "\n";
}
My error...
/home/iii/tor/m_gym/multiv_normal.cpp:53:24: note: mismatched types ‘const std::set<Types ...>’ and ‘at::Tensor (at::Tensor::*)(at::Dimname, at::Dimname) const’
53 | std::cout << one_T.transpose << "\n";
| ^~~~~~~~~
/home/iii/tor/m_gym/multiv_normal.cpp:53:24: note: mismatched types ‘const std::set<Types ...>’ and ‘at::Tensor (at::Tensor::*)(int64_t, int64_t) const’ {aka ‘at::Tensor (at::Tensor::*)(long int, long int) const’}
In file included from /home/iii/tor/m_gym/libtorch/include/c10/util/Logging.h:28,
from /home/iii/tor/m_gym/libtorch/include/c10/core/TensorImpl.h:17,
from /home/iii/tor/m_gym/libtorch/include/ATen/core/TensorBody.h:20,
from /home/iii/tor/m_gym/libtorch/include/ATen/core/Tensor.h:3,
from /home/iii/tor/m_gym/libtorch/include/ATen/Tensor.h:3,
from /home/iii/tor/m_gym/libtorch/include/torch/csrc/autograd/function_hook.h:3,
from /home/iii/tor/m_gym/libtorch/include/torch/csrc/autograd/cpp_hook.h:2,
from /home/iii/tor/m_gym/libtorch/include/torch/csrc/autograd/variable.h:6,
one_T.transpose(0, 1)
The 0, 1 is the type of default transpose used in PyTorch and Numpy without being specified.

I am using opencv 4.5.5 and I am getting this error but I don't know how to fix it

vector filtered_finger_points;
if (filtered_far_points.size() > 1) {
vector<Point> finger_points;
for (int i = 0; i < filtered_start_points.size(); i++) {
vector<Point> closest_points = findClosestOnX(filtered_far_points, filtered_start_points[i]);
if (isFinger(closest_points[0], filtered_start_points[i], closest_points[1], LIMIT_ANGLE_INF, LIMIT_ANGLE_SUP, center_bounding_rect, bounding_rectangle.height * BOUNDING_RECT_FINGER_SIZE_SCALING))
finger_points.push_back(filtered_start_points[i]);
}
i don't know how to fix it it says error at finger_points"."push_back;
this is the error:
no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=std::vector<cv::Point, std::allocator<cv::Point>>, _Alloc=std::allocator<std::vector<cv::Point, std::allocator<cv::Point>>>]" matches the argument list

exitprompt.cpp:268:22: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]

I'm trying to modify some C++ code but I and getting the following errors during build:
make[2]: Leaving directory '/home/runner/work/mythtv/mythtv/mythtv/programs/mythlcdserver'
cd mythshutdown/ && ( test -e Makefile || /usr/lib/x86_64-linux-gnu/qt5/bin/qmake -o Makefile /home/runner/work/mythtv/mythtv/mythtv/programs/mythshutdown/mythshutdown.pro QMAKE=/usr/lib/x86_64-linux-gnu/qt5/bin/qmake ) && make -f Makefile
exitprompt.cpp: In member function ‘void ExitPrompter::Confirm(MythPower::Feature) const’:
Makefile:4570: recipe for target 'obj/exitprompt.o' failed
exitprompt.cpp:268:22: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]
make[2]: Leaving directory '/home/runner/work/mythtv/mythtv/mythtv/programs/mythfrontend'
DoHalt(true);
Makefile:89: recipe for target 'sub-mythfrontend-make_first' failed
^
exitprompt.cpp:39:6: note: in call to ‘void ExitPrompter::DoHalt(bool)’
void ExitPrompter::DoHalt(const bool Confirmed)
^~~~~~~~~~~~
exitprompt.cpp:270:24: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]
DoReboot(true);
^
exitprompt.cpp:70:6: note: in call to ‘void ExitPrompter::DoReboot(bool)’
void ExitPrompter::DoReboot(const bool Confirmed)
^~~~~~~~~~~~
exitprompt.cpp:272:25: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]
DoSuspend(true);
^
exitprompt.cpp:100:6: note: in call to ‘void ExitPrompter::DoSuspend(bool)’
void ExitPrompter::DoSuspend(const bool Confirmed)
^~~~~~~~~~~~
make[2]: *** [obj/exitprompt.o] Error 1
make[1]: *** [sub-mythfrontend-make_first] Error 2
The code is as follows:
// Qt
#include <QCoreApplication>
// MythTV
#include "config.h"
#include "exitprompt.h"
#include "mythcontext.h"
#include "mythdialogbox.h"
#include "mythmainwindow.h"
#include "mythscreenstack.h"
#include "mythsystemlegacy.h"
#include "mythlogging.h"
#include "exitcodes.h"
ExitPrompter::ExitPrompter()
: m_power(MythPower::AcquireRelease(this, true)),
m_haltCommand(gCoreContext->GetSetting("HaltCommand", "")),
m_rebootCommand(gCoreContext->GetSetting("RebootCommand", "")),
m_suspendCommand(gCoreContext->GetSetting("SuspendCommand", ""))
{
}
ExitPrompter::~ExitPrompter()
{
if (m_power)
MythPower::AcquireRelease(this, false);
}
void ExitPrompter::DoQuit()
{
qApp->exit();
}
void ExitPrompter::ConfirmHalt() const
{
Confirm(MythPower::FeatureShutdown);
}
void ExitPrompter::DoHalt(const bool Confirmed)
{
if (!Confirmed)
return;
// Use user specified command if it exists
if (!m_haltCommand.isEmpty())
{
uint ret = myth_system(m_haltCommand);
if (ret == GENERIC_EXIT_OK)
return;
LOG(VB_GENERAL, LOG_ERR,
"User defined HaltCommand failed, falling back to "
"alternative methods.");
}
// Otherwise use MythPower
if (m_power && m_power->IsFeatureSupported(MythPower::FeatureShutdown))
if (m_power->RequestFeature(MythPower::FeatureShutdown))
return;
// halt of last resort
myth_system("sudo /sbin/halt -p");
}
void ExitPrompter::ConfirmReboot() const
{
Confirm(MythPower::FeatureRestart);
}
void ExitPrompter::DoReboot(const bool Confirmed)
{
if (!Confirmed)
return;
if (!m_rebootCommand.isEmpty())
{
uint ret = myth_system(m_rebootCommand);
if (ret == GENERIC_EXIT_OK)
return;
LOG(VB_GENERAL, LOG_ERR,
"User defined RebootCommand failed, falling back to "
"alternative methods.");
}
// Otherwise use MythPower
if (m_power && m_power->IsFeatureSupported(MythPower::FeatureRestart))
if (m_power->RequestFeature(MythPower::FeatureRestart))
return;
// reboot of last resort
myth_system("sudo /sbin/reboot");
}
void ExitPrompter::ConfirmSuspend(void) const
{
Confirm(MythPower::FeatureSuspend);
}
void ExitPrompter::DoSuspend(const bool Confirmed)
{
if (!Confirmed)
return;
// Use user specified command if it exists
if (!m_suspendCommand.isEmpty())
{
uint ret = myth_system(m_suspendCommand);
if (ret == GENERIC_EXIT_OK)
return;
LOG(VB_GENERAL, LOG_ERR,
"User defined SuspendCommand failed, falling back to "
"alternative methods.");
}
if (m_power && m_power->IsFeatureSupported(MythPower::FeatureSuspend))
m_power->RequestFeature(MythPower::FeatureSuspend);
}
void ExitPrompter::DoStandby()
{
GetMythMainWindow()->IdleTimeout();
}
void ExitPrompter::HandleExit()
{
// HACK IsFrontendOnly() triggers a popup if there is no BE connection.
// We really don't need that right now. This hack prevents it.
gContext->SetDisableEventPopup(true);
// first of all find out, if this is a frontend only host...
bool frontendOnly = gCoreContext->IsFrontendOnly();
// HACK Undo the hack, just in case we _don't_ quit:
gContext->SetDisableEventPopup(false);
// how do you want to quit today?
bool allowExit = false;
bool allowReboot = false;
bool allowShutdown = false;
bool allowStandby = false;
bool allowSuspend = false;
bool haveshutdown = !m_haltCommand.isEmpty();
bool havereboot = !m_rebootCommand.isEmpty();
bool havesuspend = !m_suspendCommand.isEmpty();
#ifdef Q_OS_ANDROID
haveshutdown = false;
havereboot = false;
havesuspend = false;
#endif
if (m_power)
{
havereboot |= m_power->IsFeatureSupported(MythPower::FeatureRestart);
haveshutdown |= m_power->IsFeatureSupported(MythPower::FeatureShutdown);
havesuspend |= m_power->IsFeatureSupported(MythPower::FeatureSuspend);
}
switch (gCoreContext->GetNumSetting("OverrideExitMenu", 0))
{
case 0:
allowExit = true;
if (frontendOnly)
allowShutdown = haveshutdown;
break;
case 1:
allowExit = true;
break;
case 2:
allowExit = true;
allowShutdown = haveshutdown;
break;
case 3:
allowExit = true;
allowReboot = havereboot;
allowShutdown = haveshutdown;
break;
case 4:
allowShutdown = haveshutdown;
break;
case 5:
allowReboot = havereboot;
break;
case 6:
allowReboot = havereboot;
allowShutdown = haveshutdown;
break;
case 7:
allowStandby = true;
break;
case 8:
allowSuspend = havesuspend;
break;
case 9:
allowExit = true;
allowSuspend = havesuspend;
break;
}
MythScreenStack *ss = GetMythMainWindow()->GetStack("popup stack");
auto *dlg = new MythDialogBox(tr("Do you really want to exit MythTV?"), ss,
"exit prompt");
if (!dlg->Create())
{
LOG(VB_GENERAL, LOG_ERR, "Can't create Exit Prompt dialog?");
delete dlg;
DoQuit();
return;
}
dlg->AddButton(QCoreApplication::translate("(Common)", "No"));
if (allowExit)
dlg->AddButton(tr("Yes, Exit now"), SLOT(DoQuit()));
if (allowReboot)
dlg->AddButton(tr("Yes, Exit and Reboot"), SLOT(ConfirmReboot()));
if (allowShutdown)
dlg->AddButton(tr("Yes, Exit and Shutdown"), SLOT(ConfirmHalt()));
if (allowStandby)
dlg->AddButton(tr("Yes, Enter Standby Mode"), SLOT(DoStandby()));
if (allowSuspend)
dlg->AddButton(tr("Yes, Suspend"), SLOT(ConfirmSuspend()));
// This is a hack so that the button clicks target the correct slot:
dlg->SetReturnEvent(this, QString());
ss->AddScreen(dlg);
}
void ExitPrompter::Confirm(MythPower::Feature Action) const
{
MythScreenStack *ss = GetMythMainWindow()->GetStack("popup stack");
QString msg;
gContext->SetDisableEventPopup(true);
if (!gCoreContext->IsFrontendOnly())
{
// this is the only case where a prompt should be shown
msg.prepend(tr("Mythbackend is running on this system. "));
auto *dlg = new MythConfirmationDialog(ss, msg);
if (!dlg->Create())
{
delete dlg;
DoQuit();
return;
}
if (Action == MythPower::FeatureShutdown)
connect(dlg, &MythConfirmationDialog::haveResult, this, &ExitPrompter::DoHalt);
else if (Action == MythPower::FeatureRestart)
connect(dlg, &MythConfirmationDialog::haveResult, this, &ExitPrompter::DoReboot);
else if (Action == MythPower::FeatureSuspend)
connect(dlg, &MythConfirmationDialog::haveResult, this, &ExitPrompter::DoSuspend);
ss->AddScreen(dlg);
}
else
{
// no prompts required, take a specific action required
// calling these exitprompter functions with (true) fails build
if (Action == MythPower::FeatureShutdown)
DoHalt(true);
else if (Action == MythPower::FeatureRestart)
DoReboot(true);
else if (Action == MythPower::FeatureSuspend)
DoSuspend(true);
}
gContext->SetDisableEventPopup(false);
}
I have already tried adding const to the end of the DoHalt (etc) functions like:
void ExitPrompter::DoHalt(const bool Confirmed) const
void ExitPrompter::DoReboot(const bool Confirmed) const
void ExitPrompter::DoSuspend(const bool Confirmed) const
But this just gives me a different error during build like:
cd mythshutdown/ && ( test -e Makefile || /usr/lib/x86_64-linux-gnu/qt5/bin/qmake -o Makefile /home/runner/work/mythtv/mythtv/mythtv/programs/mythshutdown/mythshutdown.pro QMAKE=/usr/lib/x86_64-linux-gnu/qt5/bin/qmake ) && make -f Makefile
exitprompt.cpp:39:6: error: prototype for ‘void ExitPrompter::DoHalt(bool) const’ does not match any in class ‘ExitPrompter’
void ExitPrompter::DoHalt(const bool Confirmed) const
^~~~~~~~~~~~
In file included from exitprompt.cpp:6:0:
exitprompt.h:14:10: error: candidate is: void ExitPrompter::DoHalt(bool)
Makefile:4570: recipe for target 'obj/exitprompt.o' failed
void DoHalt(bool Confirmed = true);
make[2]: Leaving directory '/home/runner/work/mythtv/mythtv/mythtv/programs/mythfrontend'
^~~~~~
Makefile:89: recipe for target 'sub-mythfrontend-make_first' failed
exitprompt.cpp:70:6: error: prototype for ‘void ExitPrompter::DoReboot(bool) const’ does not match any in class ‘ExitPrompter’
void ExitPrompter::DoReboot(const bool Confirmed) const
^~~~~~~~~~~~
In file included from exitprompt.cpp:6:0:
exitprompt.h:15:10: error: candidate is: void ExitPrompter::DoReboot(bool)
void DoReboot(bool Confirmed = true);
^~~~~~~~
exitprompt.cpp:100:6: error: prototype for ‘void ExitPrompter::DoSuspend(bool) const’ does not match any in class ‘ExitPrompter’
void ExitPrompter::DoSuspend(const bool Confirmed) const
^~~~~~~~~~~~
In file included from exitprompt.cpp:6:0:
exitprompt.h:17:10: error: candidate is: void ExitPrompter::DoSuspend(bool)
void DoSuspend(bool Confirmed = true);
^~~~~~~~~
exitprompt.cpp: In member function ‘void ExitPrompter::Confirm(MythPower::Feature) const’:
exitprompt.cpp:268:22: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]
DoHalt(true);
^
In file included from exitprompt.cpp:6:0:
exitprompt.h:14:10: note: in call to ‘void ExitPrompter::DoHalt(bool)’
void DoHalt(bool Confirmed = true);
^~~~~~
exitprompt.cpp:270:24: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]
DoReboot(true);
^
In file included from exitprompt.cpp:6:0:
exitprompt.h:15:10: note: in call to ‘void ExitPrompter::DoReboot(bool)’
void DoReboot(bool Confirmed = true);
^~~~~~~~
exitprompt.cpp:272:25: error: passing ‘const ExitPrompter’ as ‘this’ argument discards qualifiers [-fpermissive]
DoSuspend(true);
^
In file included from exitprompt.cpp:6:0:
exitprompt.h:17:10: note: in call to ‘void ExitPrompter::DoSuspend(bool)’
void DoSuspend(bool Confirmed = true);
^~~~~~~~~
make[2]: *** [obj/exitprompt.o] Error 1
make[1]: *** [sub-mythfrontend-make_first] Error 2
I don't know C++ (I though the change I was making was fairly simple!) very well at all so I need some precise help.
Thanks

Vectors in myclass. error: parenthesized initializer in array new [-fpermissive]

I'm new to C++
class BlenderMesh{
public:
std::vector<double[3]> vertex_vectors;
std::vector<double[3]> normal_vectors;
std::vector<double[2]> uv_vectors;
std::vector<std::string> texture_list;
std::vector<int[6]> face_indices;
std::vector<int[3]> normal_indices;
std::vector<int[3]> uv_indices;
BlenderMesh();
~BlenderMesh();};
Error in code: mesh->vertex_vectors.push_back(vertex);
BlenderMesh::BlenderMesh(){}
BlenderMesh::~BlenderMesh(){}
BlenderMesh* mesh = new BlenderMesh();
PyObject* vertexVectors = PyList_GetItem(blenderObject,2);
unsigned int size_vertex_vectors = PyObject_Size(vertexVectors);
for (unsigned int i = 0; i < size_vertex_vectors; i++){
double vertex[3];
PyObject* pyVertex = PyList_GetItem(vertexVectors,i);
PyObject* vertexX = PyTuple_GetItem(pyVertex,0);
vertex[0] = PyFloat_AsDouble(vertexX);
PyObject* vertexY = PyTuple_GetItem(pyVertex,1);
vertex[1] = PyFloat_AsDouble(vertexY);
PyObject* vertexZ = PyTuple_GetItem(pyVertex,2);
vertex[2] = PyFloat_AsDouble(vertexZ);
mesh->vertex_vectors.push_back(vertex);
}
Console:
/usr/include/c++/4.9.2/ext/new_allocator.h:120:4: error: parenthesized initializer in array new [-fpermissive]
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
/usr/include/c++/4.9.2/ext/new_allocator.h:124:29: error: request for member '~double [3]' in '* __p', which is of non-class type 'double [3]'
destroy(_Up* __p) { __p->~_Up(); }
Well it has been four years but hopefully this helps someone. For some reason you are not able to create a vector object containing a native list of objects (maybe someone could explain why?).
So, for example, when creating a 18x2 vector containing 1'ns for example:
std::vector<double[2]> my_vector(18, {1.0, 1.0});
So instead you should to the following:
std::vector<vector<double>> my_vector(18, vector<double>(2,{1.0, 1.0});
In C++11, a std::array can be used:
std::vector<std::array<double,2>> my_vector(18, std::array<double,2>{1.0, 1.0});

How to get integer rownames in Rcpp?

Working off of these two posts
1. Convert char to int in C and C++
2. http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2010-July/000932.html
I'm trying to get the rownames from an Rcpp Matrix (NumericMatrix, etc) as an IntegerVector.
In R, this would be:
as.integer(rownames(x)) # where x is a matrix
I've tried casting in two different ways and am getting different compilation errors:
attempt 1
cppFunction('IntegerVector rownames1(NumericMatrix x) {
List dimnames = x.attr("dimnames");
CharacterVector rownames = dimnames[0];
IntegerVector out(dimnames.size());
for (int i= 0; i < out.size(); i++) {
out[i] = (int) rownames[i]; // cast via (int)
}
return (IntegerVector) dimnames[0];}')
file1b9c6dec3c12.cpp: In function 'Rcpp::IntegerVector rownames1(Rcpp::NumericMatrix)':
file1b9c6dec3c12.cpp:11:40: error: invalid cast from type 'Rcpp::Vector<16>::Proxy {aka Rcpp::internal::string_proxy<16>}' to type 'int'
make: *** [file1b9c6dec3c12.o] Error 1
Warning message:
running command 'make -f "C:/PROGRA~1/R/R-32~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-32~1.2/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_23.dll" WIN=64 TCLBIN=64 OBJECTS="file1b9c6dec3c12.o"' had status 2
attempt 2
cppFunction('IntegerVector rownames1(NumericMatrix x) {
List dimnames = x.attr("dimnames");
CharacterVector rownames = dimnames[0];
IntegerVector out(dimnames.size());
for (int i= 0; i < out.size(); i++) {
out[i] = rownames[i] + "0"; // cast as suggested in SO post linked above
}
return (IntegerVector) dimnames[0];}')
file1b9c71d25b92.cpp: In function 'Rcpp::IntegerVector rownames1(Rcpp::NumericMatrix)':
file1b9c71d25b92.cpp:11:38: error: ambiguous overload for 'operator-' in 'Rcpp::Vector::operator [with int RTYPE = 16, StoragePolicy = Rcpp::PreserveStorage, Rcpp::Vector::Proxy = Rcpp::internal::string_proxy<16>, R_xlen_t = long long int](((long long int)i)) - "0"'
file1b9c71d25b92.cpp:11:38: note: candidates are:
file1b9c71d25b92.cpp:11:38: note: operator-(const char*, const char*)
file1b9c71d25b92.cpp:11:38: note: operator-(const char*, const char*)
file1b9c71d25b92.cpp:11:38: note: operator-(char*, char*)
make: *** [file1b9c71d25b92.o] Error 1
Warning message:
running command 'make -f "C:/PROGRA~1/R/R-32~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-32~1.2/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_21.dll" WIN=64 TCLBIN=64 OBJECTS="file1b9c71d25b92.o"' had status 2
Any help appreciated!
You can use the cstdlib function atoi to convert from const char* to int. For example,
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::IntegerVector rownames1(Rcpp::NumericMatrix x) {
Rcpp::List dimnames = x.attr("dimnames");
Rcpp::CharacterVector rownames = dimnames[0];
Rcpp::IntegerVector out(rownames.size());
std::transform(rownames.begin(), rownames.end(), out.begin(), std::atoi);
return out;
}
/*** R
M <- matrix(
1.5:16.5, nrow = 4,
dimnames = list(1:4, 1:4))
##
R> all.equal(rownames1(M), as.integer(row.names(M)))
#[1] TRUE
*/