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
namedtuples in Cython?
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
 
Chris Barker  
View profile  
 More options Sep 20 2012, 12:56 pm
From: Chris Barker <chris.bar...@noaa.gov>
Date: Thu, 20 Sep 2012 09:55:58 -0700
Local: Thurs, Sep 20 2012 12:55 pm
Subject: namedtuples in Cython?
I'm thinking of using namedtuples in Cython -- it seems a reasonable
way to wrap a c struct, and, at least in pure python, lighter weight
than a class.

If I'm going to do that, is seems I might as well use the C-API when
constructing, rather than doing it all with the Python API. But it
appears the namedtuple is written in pure python, as a subclass of
tuple.

Which I suppose means I need to create a nametuple class with the
Python call, but then I should be able to actually set the fields with
the C-API for a tuple.

But is there any point in this anyway -- is, in fact, a cdef class
just as lightweight (or maybe more lightweight) anyway?

-Chris

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Bar...@noaa.gov


 
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 Sep 20 2012, 1:32 pm
From: Robert Bradshaw <rober...@gmail.com>
Date: Thu, 20 Sep 2012 10:32:01 -0700
Local: Thurs, Sep 20 2012 1:32 pm
Subject: Re: [cython-users] namedtuples in Cython?

A cdef class is more lightweight, but requires an explicit class for
every set of names you want. (It also has the advantage of storing
members as C values, if you intend to use them a lot from your Cython
code.)

- 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.
Chris Barker  
View profile  
 More options Sep 20 2012, 4:06 pm
From: Chris Barker <chris.bar...@noaa.gov>
Date: Thu, 20 Sep 2012 13:05:46 -0700
Local: Thurs, Sep 20 2012 4:05 pm
Subject: Re: [cython-users] namedtuples in Cython?

On Thu, Sep 20, 2012 at 10:32 AM, Robert Bradshaw <rober...@gmail.com> wrote:
> A cdef class is more lightweight,

Then that's the way to go, unless there is real reason for it to be a
tuple, too.

> but requires an explicit class for
> every set of names you want.

which namedtuple requires as well, you'd still create a specific
namedtuple class for each struct you wanted to wrap.

> (It also has the advantage of storing
> members as C values, if you intend to use them a lot from your Cython
> code.)

makes sense -- and it's mutable, which more closely follows the
use-cases of C structs.

namedtuples area also sequences, but I suppose you could add that to
your cdef class if you wanted to.

Thanks -- I see now why this hasn't been done -- really no point.

-Chris

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Bar...@noaa.gov


 
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.
Gunnlaugur Þór Briem  
View profile  
 More options Sep 21 2012, 5:47 am
From: Gunnlaugur Þór Briem <gunnlau...@gmail.com>
Date: Fri, 21 Sep 2012 02:47:11 -0700 (PDT)
Local: Fri, Sep 21 2012 5:47 am
Subject: Re: [cython-users] namedtuples in Cython?

On Thursday, 20 September 2012 20:06:29 UTC, Chris Barker wrote:
> > but requires an explicit class for
> > every set of names you want.

> which namedtuple requires as well, you'd still create a specific
> namedtuple class for each struct you wanted to wrap.

The difference is that a namedtuple class can be created at runtime for any
set of names, whereas cdef classes can only be created for specific sets of
names known at compile time. (There are probably ways around that, like
generating code and cythonizing it at runtime ... but that's probably more
trouble than it's worth, unless one reeeally needs dynamic cdef namedtuples)

Gulli


 
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 »