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
[no subject]
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
  2 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
 
Ian Bell  
View profile  
 More options Nov 9 2012, 6:57 am
From: Ian Bell <ian.h.b...@gmail.com>
Date: Fri, 9 Nov 2012 12:56:22 +0100
Local: Fri, Nov 9 2012 6:56 am
Subject:

I posted this to sourceforge as well, any ideas?

I have written a function in cython that will search a STL vector of
strings for a given string and return true if it is found, false otherwise.
Performance is very important here! I would ideally like to have a
templated function to do the same thing for vectors of integers or double
values so I don't have to write a function for each data type. I am sure
this is possible but I don't know the cython syntax for templated
functions. (I know how to do it in c++)

from libcpp cimport boolfrom libcpp.string cimport stringfrom
libcpp.vector cimport vectorfrom cython.operator cimport dereference
as deref, preincrement as inc

cpdef bool is_in_vector(string a, vector[string] v):
    cdef vector[string].iterator it = v.begin()
    while it != v.end():
        if deref(it) == a:
            return True
        #Increment iterator
        inc(it)
    return False

Thanks,
Ian


 
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.
Discussion subject changed to "[cython-users]" by Robert Bradshaw
Robert Bradshaw  
View profile  
 More options Nov 9 2012, 11:58 am
From: Robert Bradshaw <rober...@gmail.com>
Date: Fri, 9 Nov 2012 08:57:35 -0800
Local: Fri, Nov 9 2012 11:57 am
Subject: Re: [cython-users]

Check out http://docs.cython.org/src/userguide/fusedtypes.html

Note that vector[bool] is a very different specialization C++ than all
the other vector types.

- 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.
End of messages
« Back to Discussions Older topic »