Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 773085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:54:32+00:00 2026-05-14T18:54:32+00:00

I am trying to pass data around the numpy and boost::ublas layers. I have

  • 0

I am trying to pass data around the numpy and boost::ublas layers. I
have written an ultra thin wrapper because swig cannot parse ublas’
header correctly. The code is shown below

#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/lexical_cast.hpp>
#include <algorithm>
#include <sstream>
#include <string>

using std::copy;
using namespace boost;

typedef boost::numeric::ublas::matrix<double> dm;
typedef boost::numeric::ublas::vector<double> dv;

class dvector : public dv{
 public:
 dvector(const int rhs):dv(rhs){;};
 dvector();
 dvector(const int size, double* ptr):dv(size){
   copy(ptr, ptr+sizeof(double)*size, &(dv::data()[0]));
 }
 ~dvector(){}
};

with the SWIG interface that looks something like

%apply(int DIM1, double* INPLACE_ARRAY1) {(const int size, double* ptr)}
class dvector{
 public:
 dvector(const int rhs);
 dvector();
 dvector(const int size, double* ptr);
       %newobject toString;
 char* toString();
       ~dvector();
};

I have compiled them successfully via gcc 4.3 and vc++9.0. However
when I simply run

a = dvector(array([1.,2.,3.]))

it gives me a segfault. This is the first time I use swigh with numpy
and not have fully understanding between the data conversion and
memory buffer passing. Does anyone see something obvious I have
missed? I have tried to trace through with a debugger but it crashed within the assmeblys of python.exe. I have no clue if this is a swig problem or of my simple wrapper. Anything is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:54:33+00:00Added an answer on May 14, 2026 at 6:54 pm

    You may want to replace

    copy(ptr, ptr+sizeof(double)*size, &(dv::data()[0]));

    by

    copy(ptr, ptr+size, &(dv::data()[0]));

    Remember that in C/C++ adding or subtracting from a pointer moves it by a multiple of the size of the datatype it points to.

    Best,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass data around objects using singleton pattern. Here is my code
I'm trying to use redirects and sessions in Sinatra to pass some data around
I am trying to pass some data into my Controller, but I'm getting a
I am trying to pass in mutliple data into AJAX .post(). This is what
I am trying to make an app that will pass data between two servers
I'm trying to make simple script using jquery $post function to pass data to
I'm trying to write my own protocol so that multiple servers can pass data
I'm trying to pass a form's data to my controller method using JQuery Ajax,
I'm trying to use __doPostBack to pass some data from client to server side.
I have a web app with a form that I am trying to pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.