Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
beginner question: passing std::vector by reference
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
peter aberline  
View profile  
 More options Oct 2 2012, 3:38 am
From: peter aberline <peter.aberl...@gmail.com>
Date: Tue, 2 Oct 2012 00:38:56 -0700 (PDT)
Local: Tues, Oct 2 2012 3:38 am
Subject: beginner question: passing std::vector by reference

Hi all,

I'm new to Cython, it looks to be an incredible technology -
congratulations to all the devs.

Please excuse my basic question. I'm trying to pass a reference to a
std::vector to a function and I'm getting a cpp compilaton error. Here's a
minimum example of what I'm doing:

test.py:

import sys

def vectortest(a, idx):
    print ('a[idx] is: ' + str(a[idx]))
    a[idx] += 1
    print ('a[idx] is: ' + str(a[idx]))
    return a

def run():
    lst = range(1, 5)
    lstNew = vectortest(lst, 1)

    print ('lstNew[1] is :' + str(lstNew[1]))

test.pxd
import cython
from libcpp.vector cimport vector

import sys

if sys.version_info < (3,):
    range = xrange

cpdef vector[int] vectortest(vector[int] a, int idx)  # <-- This works fine
('a' is pass by value?)

#cpdef vector[int] vectortest(vector[int]& a, int idx) #<-- This generates
an 'uninitialised reference' cpp compilation error ('a' is pass by
reference?')

@cython.locals(lst = vector[int])
cpdef run()

Compilation error:

$/test.cpp: In function ‘PyObject* __pyx_pw_4perf_1vectortest(PyObject*,
PyObject*, PyObject*)’:
$/test.cpp:640:21: error: ‘__pyx_v_a’ declared as reference but not
initialized

Can anyone suggest what I'm going wrong?

Many thanks
Peter.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Bradshaw  
View profile  
 More options Oct 3 2012, 12:56 am
From: Robert Bradshaw <rober...@gmail.com>
Date: Tue, 2 Oct 2012 21:55:31 -0700
Local: Wed, Oct 3 2012 12:55 am
Subject: Re: [cython-users] beginner question: passing std::vector by reference
On Tue, Oct 2, 2012 at 12:38 AM, peter aberline

Looks like this was a bug introduced In 0.17.1 and already fixed in master.

- Robert


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
peter aberline  
View profile  
 More options Oct 3 2012, 3:28 am
From: peter aberline <peter.aberl...@gmail.com>
Date: Wed, 3 Oct 2012 00:28:16 -0700 (PDT)
Local: Wed, Oct 3 2012 3:28 am
Subject: Re: [cython-users] beginner question: passing std::vector by reference

 Just got the latest source from git and that has indeed fixed it. Thanks
for your help.

Peter.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Behnel  
View profile  
 More options Oct 7 2012, 2:06 am
From: Stefan Behnel <stefan...@behnel.de>
Date: Sun, 07 Oct 2012 08:06:30 +0200
Local: Sun, Oct 7 2012 2:06 am
Subject: Re: [cython-users] beginner question: passing std::vector by reference
peter aberline, 02.10.2012 09:38:

> test.pxd
> import cython
> from libcpp.vector cimport vector

> import sys

> if sys.version_info < (3,):
>     range = xrange

Are you really using this in a .pxd file? I think it would be nice if
Cython gave you a compile error for this - it's dead code.

Stefan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »