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
Some questions, maybe naive ones
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
  13 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
 
JBT  
View profile  
 More options Sep 28 2012, 12:39 am
From: JBT <jianbao....@gmail.com>
Date: Thu, 27 Sep 2012 21:39:29 -0700 (PDT)
Local: Fri, Sep 28 2012 12:39 am
Subject: Some questions, maybe naive ones

Hi,

I am new to cython. I am currently trying to make a python wrapper to use
NASA CDF library. This is currently for practicing purposes, but hopefully
it will eventually work out and turn into something useful.

Anyway, for now I am trying to translate the following c codes to cython
codes.
------------------------ below is from cdf.h
------------------------------------------------
typedef void *CDFid;
typedef long CDFstatus;

static double *TT2000NULL = 0;

#define HOST_ENCODING           8L
#define ROW_MAJOR       1L
#define SINGLE_FILE     1L

----------------------------- below is from an example, say, example.c
-----------------------
CDFid       test_id;                    /* CDF identifier (handle). */
CDFstatus   status;                     /* Status returned from CDF
library. */
static char CDFname[] = {"test1"};      /* File name of the CDF. */
long        numDims = 2;                /* Number of dimensions. */
static long dimSizes[2] = {100,200};    /* Dimension sizes. */
long        encoding = HOST_ENCODING;   /* Data encoding. */
long        majority = ROW_MAJOR;       /* Variable data majority. */
long        form = SINGLE_FILE;         /* Format of CDF. */

Below is my translation.
------------------------------ below is from nasacdf.pxd
----------------------------
cdef extern from "cdf34_1-dist/include/cdf.h":
    ctypedef void *CDFid;
    ctypedef long CDFstatus;
    static double *TT2000NULL = 0;
    enum:
        HOST_ENCODING = 8;
        ROW_MAJOR     = 1;
        SINGLE_FILE   = 1;

-------------------------------below is from test.pyx
------------------------------
cimport nasacdf

def hello():
    cdef CDFid       test_id
    cdef CDFstatus   status
 #  cdef char        CDFname[] = {"test1"}
    cdef char        *CDFname = "test1"
    cdef long        numDims = 2
 #  cdef static long dimSizes[2] = {100,200}
    cdef long        encoding = HOST_ENCODING
    cdef long        majority = ROW_MAJOR
    cdef long        form = SINGLE_FILE

    print CDFname

----------------------------- below is my setup.py ---------------------
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

cdfdist = 'cdf34_1-dist/'
modules = Extension("cdf",
    sources = ['test.pyx'],
    libraries = [cdfdist + 'lib/libcdf.a'],
    extra_compile_args = ['-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE64_SOURCE',
                         '-D_LARGEFILE_SOURCE'])

setup(name = 'pyNASACDF',
      version = '0.1.0',
      cmdclass = {'build_ext':build_ext},
      ext_modules = [modules]
     )

---------------------------------------- end of code
--------------------------------------
 I modified the CDFname declaration and commented out dimSizes declaration
because the compiler issued errors on them. After I run:
python setup.py build_ext --inplace
I got errors. I attached the error message below. Can anyone tell me what
is wrong with my translation, please? Thank you very much.

>$ python setup.py build_ext --inplace

running build_ext
cythoning test.pyx to test.c

Error compiling Cython file:
------------------------------------------------------------
...
# File: nasacdf.pxd

cdef extern from "cdf34_1-dist/include/cdf.h":
    ctypedef void *CDFid;
                       ^
------------------------------------------------------------

nasacdf.pxd:4:24: Syntax error in ctypedef statement

Error compiling Cython file:
------------------------------------------------------------
...
# File test.pyx

cimport nasacdf

def hello():
    cdef CDFid       test_id
        ^
------------------------------------------------------------

test.pyx:6:9: 'CDFid' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...

cimport nasacdf

def hello():
    cdef CDFid       test_id
    cdef CDFstatus   status
        ^
------------------------------------------------------------

test.pyx:7:9: 'CDFstatus' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
    cdef CDFstatus   status
 #  cdef char        CDFname[] = {"test1"}
    cdef char        *CDFname = "test1"
    cdef long        numDims = 2
 #  cdef static long dimSizes[2] = {100,200}
    cdef long        encoding = HOST_ENCODING
                                            ^
------------------------------------------------------------

test.pyx:12:45: undeclared name not builtin: HOST_ENCODING

Error compiling Cython file:
------------------------------------------------------------
...
 #  cdef char        CDFname[] = {"test1"}
    cdef char        *CDFname = "test1"
    cdef long        numDims = 2
 #  cdef static long dimSizes[2] = {100,200}
    cdef long        encoding = HOST_ENCODING
    cdef long        majority = ROW_MAJOR
                                        ^
------------------------------------------------------------

test.pyx:13:41: undeclared name not builtin: ROW_MAJOR

Error compiling Cython file:
------------------------------------------------------------
...
    cdef char        *CDFname = "test1"
    cdef long        numDims = 2
 #  cdef static long dimSizes[2] = {100,200}
    cdef long        encoding = HOST_ENCODING
    cdef long        majority = ROW_MAJOR
    cdef long        form = SINGLE_FILE
                                      ^
------------------------------------------------------------

test.pyx:14:39: undeclared name not builtin: SINGLE_FILE
building 'cdf' extension
clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common
-fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX
-DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall
-Wstrict-prototypes -DENABLE_DTRACE -pipe -arch i386 -arch x86_64
-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2. 7
-c test.c -o build/temp.macosx-10.8-intel-2.7/test.o -D_FILE_OFFSET_BITS=64
-D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE
clang: warning: argument unused during compilation: '-mno-fused-madd'
test.c:1:2: error: Do not use this file, it is the result of a failed
Cython compilation.
#error Do not use this file, it is the result of a failed Cython
compilation.
 ^
1 error generated.
error: command 'clang' failed with exit status 1


 
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.
Yichao Yu  
View profile  
 More options Sep 28 2012, 2:27 am
From: Yichao Yu <yyc1...@gmail.com>
Date: Fri, 28 Sep 2012 02:17:37 -0400
Local: Fri, Sep 28 2012 2:17 am
Subject: Re: [cython-users] Some questions, maybe naive ones

remove all your semicolon


 
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 Sep 28 2012, 9:47 am
From: Stefan Behnel <stefan...@behnel.de>
Date: Fri, 28 Sep 2012 15:47:16 +0200
Local: Fri, Sep 28 2012 9:47 am
Subject: Re: [cython-users] Some questions, maybe naive ones
JBT, 28.09.2012 06:39:

As normal in Python, you have to either prefix the names you use with the
module that you imported, or import the names that the module defines
directly into your code. I.e. either use

    cimport nasacdf

    cdef nasacdf.CDFid test_id

or

    from nasacdf cimport CDFid

    cdef CDFid test_id

or any mix of the two as you see fit. Cython is a lot closer to Python than
to C. It actually has namespaces.

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.
JBT  
View profile  
 More options Sep 28 2012, 12:32 pm
From: JBT <jianbao....@gmail.com>
Date: Fri, 28 Sep 2012 09:32:58 -0700 (PDT)
Local: Fri, Sep 28 2012 12:32 pm
Subject: Re: [cython-users] Some questions, maybe naive ones

Hi Stefan,

Thank you. That helps a lot.

So, after changing nasacdf.pxd to cdf.pxd, I modified the cimport statement
to:
from cdc cimport *

Then I got this error:
Error compiling Cython file:
------------------------------------------------------------
...
# File: cdf.pxd

cdef extern from "cdf34_1-dist/include/cdf.h":
    ctypedef void *CDFid
    ctypedef long CDFstatus
    static double *TT2000NULL = 0
                 ^
------------------------------------------------------------

cdf.pxd:6:18: Syntax error in C variable declaration

As you can see, the *static double* statement is copied from cdf.h, so I
don't understand why cython sees that as an error. Any ideas? Thank you so
much.

BTW, Yichao, I removed all the semicolons per your suggestion. :-)

JBT


 
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.
Yichao Yu  
View profile  
 More options Sep 28 2012, 12:50 pm
From: Yichao Yu <yyc1...@gmail.com>
Date: Fri, 28 Sep 2012 12:45:31 -0400
Local: Fri, Sep 28 2012 12:45 pm
Subject: Re: [cython-users] Some questions, maybe naive ones

don't think cython understand static (or I'm wrong?)
and u need a cdef here

cdef double *.... = NULL

works fine for me

>                  ^
> ------------------------------------------------------------

> cdf.pxd:6:18: Syntax error in C variable declaration

> As you can see, the *static double* statement is copied from cdf.h, so I
> don't understand why cython sees that as an error. Any ideas? Thank you so
> much.

> BTW, Yichao, I removed all the semicolons per your suggestion. :-)

That is where the original syntax error coming from. afaik


 
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 Sep 28 2012, 12:53 pm
From: Stefan Behnel <stefan...@behnel.de>
Date: Fri, 28 Sep 2012 18:53:10 +0200
Local: Fri, Sep 28 2012 12:53 pm
Subject: Re: [cython-users] Some questions, maybe naive ones
Yichao Yu, 28.09.2012 18:45:

The "cdef" isn't needed when you're inside of a "cdef extern" block anyway.

>> BTW, Yichao, I removed all the semicolons per your suggestion. :-)
> That is where the original syntax error coming from. afaik

No, semicolons work the same way as in Python.

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.
Yichao Yu  
View profile  
 More options Sep 28 2012, 1:14 pm
From: Yichao Yu <yyc1...@gmail.com>
Date: Fri, 28 Sep 2012 13:03:26 -0400
Local: Fri, Sep 28 2012 1:03 pm
Subject: Re: [cython-users] Some questions, maybe naive ones

true....

>>> BTW, Yichao, I removed all the semicolons per your suggestion. :-)
>> That is where the original syntax error coming from. afaik

> No, semicolons work the same way as in Python.

well not for cdef, (as in Python def)

i.e. not here
cdef extern from "cdf34_1-dist/include/cdf.h":
    ctypedef void *CDFid;
                       ^
------------------------------------------------------------

nasacdf.pxd:4:24: Syntax error in ctypedef statement


 
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.
JBT  
View profile  
 More options Sep 28 2012, 1:32 pm
From: JBT <jianbao....@gmail.com>
Date: Fri, 28 Sep 2012 10:32:28 -0700 (PDT)
Local: Fri, Sep 28 2012 1:32 pm
Subject: Re: [cython-users] Some questions, maybe naive ones

Thanks, Yichao, Stefan.

So, here is another question. Cython won't compile these two statements:
    cdef static char        CDFname[] = {"test1"}
    cdef static long dimSizes[2] = {100,200}
because cython sees them with syntax error. I found the corresponding c
code (without the *cdef*) in the NASA CDF C reference manual, so I presume
the C counterpart is correct. So, why does cython think the two statements
are not correct?

JBT


 
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 28 2012, 3:37 pm
From: Chris Barker <chris.bar...@noaa.gov>
Date: Fri, 28 Sep 2012 12:36:41 -0700
Local: Fri, Sep 28 2012 3:36 pm
Subject: Re: [cython-users] Some questions, maybe naive ones

On Fri, Sep 28, 2012 at 10:32 AM, JBT <jianbao....@gmail.com> wrote:
> So, here is another question. Cython won't compile these two statements:
>     cdef static char        CDFname[] = {"test1"}
>     cdef static long dimSizes[2] = {100,200}
> because cython sees them with syntax error. I found the corresponding c code
> (without the *cdef*) in the NASA CDF C reference manual, so I presume the C
> counterpart is correct. So, why does cython think the two statements are not
> correct?

becaseu that is how you initialize arrays in C, not Python (or Cython)
-- remember that Cyton is closer to Python is syntax than C. For
instance, the {} are used to defien a dcitionaly literal.

try:

 cdef static char        CDFname = "test1"
 cdef static long dimSizes[2] = [100, 200]

(though you may need a char* there -- a char is one charactor.

(unteseted, and I'm no expert, but this is closer, for sure.)

-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.
Stefan Behnel  
View profile  
 More options Sep 28 2012, 3:43 pm
From: Stefan Behnel <stefan...@behnel.de>
Date: Fri, 28 Sep 2012 21:43:30 +0200
Local: Fri, Sep 28 2012 3:43 pm
Subject: Re: [cython-users] Some questions, maybe naive ones
Chris Barker, 28.09.2012 21:36:

Cython has no keyword "static" because all globally declared C names are
static anyway.

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.
JBT  
View profile  
 More options Sep 28 2012, 11:52 pm
From: JBT <jianbao....@gmail.com>
Date: Fri, 28 Sep 2012 20:52:50 -0700 (PDT)
Local: Fri, Sep 28 2012 11:52 pm
Subject: Re: [cython-users] Some questions, maybe naive ones

Hello, Stefan, Yichao, Chris,

I successfully used CDFlib to open and close a .cdf file, which is a big
milestone for my purposes. So, I'd like to say thank you to you guys for
helping me out along the way, especially to Stefan, for he, with others,
developed cython such a great tool/language. I don't think I would reach
this stage this fast if it weren't for cython. So, again, thank you very
much. :-)

In the meantime, have a very nice weekend. :-)

JBT


 
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.
Jianbao Tao  
View profile  
 More options Sep 28 2012, 5:42 pm
From: Jianbao Tao <jianbao....@gmail.com>
Date: Fri, 28 Sep 2012 14:42:56 -0700
Local: Fri, Sep 28 2012 5:42 pm
Subject: Re: [cython-users] Some questions, maybe naive ones

Thanks, Stefan, Chris.

So, now, the char statement can go through, but the dimSizes one still
can't. Here is my current version:
cdef long dimSizes[2] = [100, 200]

Cython still consider this with syntax error, which is quite confusing to
me. Any ideas?

JBT


 
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.
Yichao Yu  
View profile  
 More options Sep 28 2012, 1:38 pm
From: Yichao Yu <yyc1...@gmail.com>
Date: Fri, 28 Sep 2012 13:38:55 -0400
Local: Fri, Sep 28 2012 1:38 pm
Subject: Re: [cython-users] Some questions, maybe naive ones

On Fri, Sep 28, 2012 at 1:32 PM, JBT <jianbao....@gmail.com> wrote:
> Thanks, Yichao, Stefan.

> So, here is another question. Cython won't compile these two statements:
>     cdef static char        CDFname[] = {"test1"}
>     cdef static long dimSizes[2] = {100,200}
> because cython sees them with syntax error. I found the corresponding c code
> (without the *cdef*) in the NASA CDF C reference manual, so I presume the C
> counterpart is correct. So, why does cython think the two statements are not
> correct?

same with this one?
http://stackoverflow.com/questions/8320951/can-i-create-a-static-c-ar...


 
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 »