Will Mayner | 28 Feb 01:03 2014
Picon

Best way to convert numpy array to C++ vector?

Hi,

What is the best way to convert a numpy array to a C++ std::vector?

I'm trying to wrap a C++ library for computing the Earth Mover's Distance in Cython so that it can be used to compute the EMD of two numpy arrays from normal Python code, and the library works with C++ vectors. From looking around here I've found that I can probably hack it together by
  • first converting the numpy array to a C-style array by passing the data pointer, as described here;
  • then converting that to a vector, as described here
But I was wondering if there is a better (easier to write, more efficient) way. Any ideas/comments would be greatly appreciated. Thanks!


— Will

--
 
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Czarek Tomczak | 27 Feb 14:36 2014
Picon

Static analysis of code that makes calls to python standard libraries?

Hello Cython enthusiasts,

When writing new functions and classes in Cython, typos like this will be detected by compiler:

cdef void Some():
    asd() # nonexistent function

But what about static checking when using methods/functions from python standard library? The code below compiles fine:

cdef void Some():
    os.asd()

What are my options to detect errors like this? In Python there are tools like pychecker/pylint that can help with that, but I don't think they are compatible with Cython (I've used google, correct me if I'm wrong).

I've found that mypy can do static checking when calling standard libraries, a quote from http://www.mypy-lang.org/:

Most commonly used libraries also have statically typed interface definitions that allow the type checker to check code that uses the libraries.

Could Cython somehow reuse mypy statically typed interface definitions? Any other ideas?

Best regards,
Czarek

--
 
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Anthony Scopatz | 27 Feb 01:24 2014
Picon

ANN: XDress v0.4

Hello All, 

I am extremely pleased to be able to announce the version 0.4 release of xdress.  This version contains much anticipated full support for Clang as a parser!  This is almost entirely due to the efforts of Geoffrey Irving.  Please thank him the next time you get a chance :)

This release also contains a lot of other goodies that you can read about in the release notes below.

Happy Generating!
Anthony

XDress 0.4 Release Notes

XDress is a numpy-aware automatic wrapper generator for C/C++ written in pure Python. Currently, xdress may generate Python bindings (via Cython) for C++ classes, functions, and certain variable types. It also contains idiomatic wrappers for C++ standard library containers (sets, vectors, maps). In the future, other tools and bindings will be supported.

The main enabling feature of xdress is a dynamic type system that was designed with the purpose of API generation in mind.

Release highlights:

  • Clang support! All kudos to Geoffrey Irving!
  • NumPy dtypes may be created independently of C++ STL vectors
  • A complete test suite refactor
  • Arbitrary source code locations
  • Global run control files
  • A plethora of useful bug fixes

This version of xdress is not 100% backwards compatible with previous versions of xdress. We apologize in the name of progress. It represents ans impressive 245 files changed, 44917 aggregate line insertions (+), and 7893 deletions (-).

Please visit the website for more information: http://xdress.org/

Ask questions on the mailing list: https://groups.google.com/forum/#!forum/xdress

Download the code from GitHub: http://github.com/xdress/xdress

XDress is free & open source (BSD 2-clause license) and requires Python 2.7+, NumPy 1.5+, Cython 0.19+, and optionally Clang, GCC-XML, pycparser, dOxygen, or lxml.

New Features

Clang Support

Through the herculean efforts of Geoffrey Irving xdress finally has full, first-class Clang/LLVM support! This is major advancement as it allows xdress to wrap more modern versions of C++ than GCC-XML can handle. Because of deficiencies in the existing libclang and Python bindings it was necessary for us to fork libclang for xdress in the short term. We hope to integrate these changes upstream. Clang versions 3.2 - 3.4 are supported.

Independent NumPy Dtypes

In previous versions of xdress, to create a dtype of type T the user needed to declare the desire for a wrapper of an STL vector of type T. These two desires have now been separated. It is now possible to create a dtype via the dtypes run control parameter. STL vectors are still wrapped via dtypes. See the dtypes module for more information.

Shiny New Test Suite

The xdress test suite has been completely revamped to include both unit and integration tests which are run for all available parsers. The integration tests are accomplished though two fake projects - cproj and cppproj - on which the xdress CLI is run. These tests are now fully platform independent, unlike the previous BASH-based test suite.

Source Paths

Source file paths are now given by either their absolute or relative path. This allows source code to be located anywhere on the user’s file system and enable the wrapping of dependencies or externally supplied libraries as needed. The run control parametersourcedir has been deprecated.

Global Run Control Files

It is sometimes useful to be able to set system-wide run control parameters. XDress will now search the following files in order of increasing precedence.

  • $HOME/.xdressrc
  • $HOME/.xdressrc.py
  • $HOME/.config/xdressrc
  • $HOME/.config/xdressrc.py

$HOME is the user’s home directory. Settings in the project run control file take precedence over the values here.

Major Bug Fixes

  • Debug file now always written when in debug mode.
  • STL sets of custom types now allowed.
  • Template parameters now allowed to be enum values.
  • Allow classes with no default constructor.

Join in the Fun!

If you are interested in using xdress on your project (and need help), contributing back to xdress, starting up a development team, or writing your own code generation plugin tool, please let us know. Participation is very welcome!

Authors

  • Anthony Scopatz
  • Geoffrey Irving *
  • James Casbon *
  • Kevin Tew *
  • Spencer Lyon
  • John Wiggins
  • Matt McCormick
  • Brad Buran
  • Chris Harris *
  • Gerald Dalley *
  • Micky Latowicki *
  • Mike C. Fletcher *
  • Robert Schwarz *

An * indicates a first time contributor.

Links

  1. Homepage - http://xdress.org/
  2. Mailing List - https://groups.google.com/forum/#!forum/xdress
  3. GitHub Organization - https://github.com/xdress

--
 
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Jonathan Buck | 26 Feb 17:33 2014
Picon

Problem linking gomp and pthread for OpenMP

In my ongoing effort to get familiar with Cython, I'm trying to use Cython's OpenMP capabilities, but I'm having difficulty getting it to compile.

I've got a setup file as follows:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

setup(
    ext_modules = cythonize([Extension("cython_sum_p", ["cython_sum_p.pyx"],
    extra_compile_args=["-fopenmp"],
    extra_link_args=["-fopenmp"])])
)


Then I try to build the extension module:
python cython_sum_parallel_setup.py build_ext --inplace

And I get errors about pthread and gopenmp.


running build_ext
building 'cython_sum_p' extension
C:\Anaconda\Scripts\gcc.bat -DMS_WIN64 -mdll -O -Wall -IC:\Anaconda\include -IC:\Anaconda\PC -c cython_sum_p.c -o build\temp.win-amd64-2.7\Release\cython_sum_p.
o -fopenmp
cython_sum_p.c: In function '__Pyx_BufFmt_ProcessTypeChunk':
cython_sum_p.c:13707:26: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:13707:26: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:13707:26: warning: too many arguments for format [-Wformat-extra-args]
cython_sum_p.c:13759:20: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:13759:20: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:13759:20: warning: too many arguments for format [-Wformat-extra-args]
cython_sum_p.c: In function '__pyx_buffmt_parse_array':
cython_sum_p.c:13819:25: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:13819:25: warning: format '%d' expects argument of type 'int', but argument 3 has type 'size_t' [-Wformat]
cython_sum_p.c:13819:25: warning: too many arguments for format [-Wformat-extra-args]
cython_sum_p.c: In function '__Pyx_GetBufferAndValidate':
cython_sum_p.c:14000:7: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:14000:7: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'Py_ssize_t' [-Wformat]
cython_sum_p.c:14000:7: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:14000:7: warning: too many arguments for format [-Wformat-extra-args]
cython_sum_p.c: In function '__Pyx_RaiseArgtupleInvalid':
cython_sum_p.c:14172:18: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:14172:18: warning: format '%s' expects argument of type 'char *', but argument 5 has type 'Py_ssize_t' [-Wformat]
cython_sum_p.c:14172:18: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:14172:18: warning: too many arguments for format [-Wformat-extra-args]
cython_sum_p.c: In function '__Pyx_RaiseTooManyValuesError':
cython_sum_p.c:14707:18: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:14707:18: warning: too many arguments for format [-Wformat-extra-args]
cython_sum_p.c: In function '__Pyx_RaiseNeedMoreValuesError':
cython_sum_p.c:14713:18: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:14713:18: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'Py_ssize_t' [-Wformat]
cython_sum_p.c:14713:18: warning: too many arguments for format [-Wformat-extra-args]
cython_sum_p.c: In function '__Pyx_ValidateAndInit_memviewslice':
cython_sum_p.c:15213:22: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:15213:22: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'Py_ssize_t' [-Wformat]
cython_sum_p.c:15213:22: warning: unknown conversion type character 'z' in format [-Wformat]
cython_sum_p.c:15213:22: warning: too many arguments for format [-Wformat-extra-args]
writing build\temp.win-amd64-2.7\Release\cython_sum_p.def
C:\Anaconda\Scripts\gcc.bat -DMS_WIN64 -shared -s build\temp.win-amd64-2.7\Release\cython_sum_p.o build\temp.win-amd64-2.7\Release\cython_sum_p.def -LC:\Anacond
a\libs -LC:\Anaconda\PCbuild\amd64 -lpython27 -lmsvcr90 -o H:\training\Python\2014Seminar\Demos\cython_sum_p.pyd -fopenmp
c:/anaconda/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgomp
c:/anaconda/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

If it's relevant, I'm on a Windows 7 x86-64 system. I'm running the latest build of Python 2.7.6 from Anaconda v1.9.0. Is this just a simple matter of including additional directories in my setup file?

Thanks,
Jonathan

--
 
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
yarden.katz | 26 Feb 05:47 2014
Picon

Problem calling clapack from Cython

Hi all,

I'm trying to simply call a C-LAPACK function (in this case, matrix multiplication) from Cython.  I don't want to dynamically link to an existing C-LAPACK installation, so I've packaged the necessary headers/*.c files for that function with my code.  I compile it using setup.py and then try to call it from a Cython (*.pyx) file.

I made a self-contained example here:

https://github.com/yarden/learn_cython

The README.txt explains how to compile and "run.py" is the test script. The key code from that example is below. I basically include the *.c / *.h files in the src/ and include/ directories and then define the external function as:

cdef extern from "f2c.h":
   ctypedef int integer
   ctypedef double doublereal


# Import lapack functions.
cdef extern from "clapack.h":
   cdef extern from "f2c.h":
       pass
   integer c_dgemm "dgemm_"(char *transa, char *transb, integer *m, integer *
                             n, integer *k, doublereal *alpha, doublereal *a, integer *lda,
                             doublereal *b, integer *ldb, doublereal *beta, doublereal *c__,
                             integer *ldc)


I then call the function as follows:

cdef int main():
    # Form of matrix
    cdef char transa_val = 'N'
    cdef char *transa = &transa_val

    cdef char transb_val = 'N'
    cdef char *transb = &transb_val

    # Number of rows of matrix A
    cdef int m = 3
    cdef int n = 3
    cdef int k = 3

    cdef double alpha = 1.0
    cdef np.ndarray[double, ndim=2, mode="c"] a = \
      np.array([[1, 2, 3],
                [4, 5, 6],
                [7, 8, 9]], dtype=float)

    cdef np.ndarray[double, ndim=2, mode="c"] b = \
      np.array([[1, 0, 0],
                [0, 0, 0],
                [1, 1, 1]], dtype=float)

    # result is a double pointer
    cdef np.ndarray[double, ndim=2, mode="c"] c = \
      np.empty([3, 3], dtype=float)


    cdef int lda = m
    cdef int ldb = n

    cdef double beta = 1.0

    cdef int ldc = 1

    print "Multipling: "
    print a
    print " times "
    print b

    c_dgemm(transa, transb, &m, &n, &k, &alpha, &a[0,0], &lda, &b[0,0], &ldb, &beta, &c[0,0], &ldc)

    return 0

main()

Then I compile and run this as follows:

$ python setup.py sdist
$ python setup.py build_ext
$ python run.py

This always yields the error:

ImportError: undefined symbol: dgemm_

Even though though the function body and header is included. What did I do wrong here?

Thanks very much in advance for your help.

--
 
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Antoine Martin | 23 Feb 12:51 2014
Picon

easiest way to access nested structs

Hi,

I am trying to interface with some C code that uses a structure like this one:

typedef struct param
{
    int a
    struct
    {
        int b
        int c
    } sub;
} param;

I have my "param" object in Cython and all I really want to do is the equivalent of:
param.sub.b = 1

Nothing that I've tried even compiles (ie: sticking the "sub" struct in its own typedef fails with error: unknown type name ‘sub’)

What is the easiest way of doing this without adding a C file to access all the "sub" fields? (which is tedious)

Thanks
Antoine

--
 
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Florent Hivert | 22 Feb 22:25 2014
Picon

Template function with different signatures

      Hi there,

I recently learn that Cython now support template functions. This is Great !
However I think there is a bug when using several template function with the
same name. The problem was raised on the following questionon StackOverflow
and I'm 100% sure of my answer.

<http://stackoverflow.com/questions/21960077/how-to-extern-from-algorithm-in-cython/21960531>

The following code works like a charm:

    from libcpp.vector cimport vector

    cdef extern from "<algorithm>" namespace "std":
        void partial_sort[RandomAccessIterator](RandomAccessIterator first, RandomAccessIterator
middle, RandomAccessIterator last)
        # void partial_sort[RandomAccessIterator, Compare](RandomAccessIterator first,
RandomAccessIterator middle, RandomAccessIterator last, Compare comp)

    cpdef bla():
        cdef vector[int] v
        cdef int i = 0
        cdef list res = []
        v.push_back(4)
        v.push_back(6)
        v.push_back(2)
        v.push_back(5)
        partial_sort_1[vector[int].iterator](v.begin(), v.end(), v.end())
        for i in v:
            res.append(i)
        return res

However uncommenting the line leads to a

    bla.pyx:15:16: Wrong number of template arguments: expected 2, got 1

Is this a bug ? a known bug ? Should I report it ?

I also suggested the following workaround:

    cdef extern from "<algorithm>" namespace "std":
        void partial_sort_1 "std::partial_sort"[RandomAccessIterator](RandomAccessIterator first,
RandomAccessIterator middle, RandomAccessIterator last)
        void partial_sort_2 "std::partial_sort"[RandomAccessIterator, Compare](RandomAccessIterator
first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp)

And then you use the correct one as in:

    partial_sort_1[vector[int].iterator](v.begin(), v.end(), v.end())

Any comment ?

Cheers,

Florent

--

-- 

--- 
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jonathan Buck | 22 Feb 00:33 2014
Picon

Help Wrapping Super Simple C Library

I'm trying to get an understanding of interfacing Cython with C, and I'm having some trouble wrapping a super simple C library. This is a really basic example, but I'd really appreciate some help with this. I've got a C header file with the function template, then the C source, a Cython source file, and then a Python setup file. When I run "python cython_c_sum_setup build_ext --inplace" I get the following error: "cython_c_sum.pyx:7:16: Cannot convert Python object to 'int *' ".

Can you please steer me in the right direction? Thank you!

----
c_sum.h

int _c_sum(int *y, int N);
----
c_sum.c

#include <stdio.h>
#include <c_sum.h>
int _c_sum(int *y, int N) {
    int i;
    int x = y[0];
    for (i=1; i<N; i++)
    {
        x += y[i];
    }
    return x;
}
----
cython_c_sum.pyx

cdef extern from "c_sum.h":
    int _c_sum(int *y, int N)
   
def cython_c_sum(x):
    return _c_sum(x, len(x))
----
cython_c_sum_setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("cython_c_sum", ["cython_c_sum.pyx"])]
)

--
 
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
aphro777 | 21 Feb 09:52 2014
Picon

problem with Cython v 0.20.1 when installing h5py with mpi on ubuntu 12.04

Hello everyone,

I have been trying to install h5py with parallel HDF5 support into my Ubuntu 12.04 machine. I have mpich2, and hdf5 with the --enable-parallel and --enable-shared options activated as well as mpi4py and Cython v0.20.1 pre-installed. However I get an error message (detail is further down).

I've contacted the people from h5py and they told me that this could be due to my current Cython installation, and that I should try to contact you to see if you have seen this type of behavior in the past.

As far as my understanding goes i see that there is a problem coming from either the mpicc compiler or the Cython installation in my machine. I would greatly appreciate it if anyone could help me understand what the problem might be. thanks in advance to anyone and have a nice day!

PS: here's the output i get:

~/Téléchargements/h5py-2.2.1$ export CC=/usr/bin/mpicc
~/Téléchargements/h5py-2.2.1$ python setup.py build --mpi
Autodetected HDF5 version 1.8.12
running build
running build_py
running build_ext
cythoning h5py/defs.pyx to h5py/defs.c

Error compiling Cython file:
------------------------------
------------------------------
...
# === Standard C library types and functions ==================================

include 'config.pxi'

IF MPI:
    from mpi4py.MPI cimport MPI_Comm, MPI_Info, Comm, Info
   ^
------------------------------------------------------------

h5py/api_types_ext.pxd:15:4: Compiler crash in AnalyseDeclarationsTransform

File 'ModuleNode.py', line 101, in analyse_declarations: ModuleNode(api_types_ext.pxd:1:0,
    full_module_name = u'api_types_ext',
    is_pxd = True)
File 'Nodes.py', line 383, in analyse_declarations: StatListNode(api_types_ext.pxd:12:0)
File 'Nodes.py', line 6826, in analyse_declarations: FromCImportStatNode(api_types_ext.pxd:15:4,
    imported_names = [...]/4,
    module_name = u'mpi4py.MPI')

Compiler crash traceback from this point on:
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Compiler/Nodes.py", line 6826, in analyse_declarations
    module_scope = env.find_module(self.module_name, self.pos)
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Compiler/Symtab.py", line 1089, in find_module
    module_name, relative_to = self.parent_module, pos = pos)
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Compiler/Main.py", line 150, in find_module
    pxd_pathname = self.find_pxd_file(module_name, pos)
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Compiler/Main.py", line 184, in find_pxd_file
    pxd = self.search_include_directories(qualified_name, ".pxd", pos, sys_path=True)
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Compiler/Main.py", line 225, in search_include_directories
    tuple(self.include_directories), qualified_name, suffix, pos, include, sys_path)
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Utils.py", line 16, in wrapper
    res = cache[args] = f(*args)
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Utils.py", line 101, in search_include_directories
    path = os.path.join(dir, dotted_filename)
  File "/usr/lib/python2.7/posixpath.py", line 71, in join
    path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 18: ordinal not in range(128)

Error compiling Cython file:
------------------------------------------------------------
...
  ctypedef struct H5G_stat_t:
    unsigned long fileno[2]
    unsigned long objno[2]
    unsigned int nlink
    H5G_obj_t type              # new in HDF5 1.6
    time_t mtime
   ^
------------------------------------------------------------

h5py/api_types_hdf5.pxd:189:4: 'time_t' is not a type identifier

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

  ctypedef struct H5G_info_t:
      H5G_storage_type_t     storage_type
      hsize_t     nlinks
      int64_t     max_corder
     ^
------------------------------------------------------------

h5py/api_types_hdf5.pxd:204:6: 'int64_t' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
    size_t val_size   #  Size of a soft link or UD link value

  ctypedef struct H5L_info_t:
    H5L_type_t  type            #  Type of link
    hbool_t     corder_valid    #  Indicate if creation order is valid
    int64_t     corder          #  Creation order
   ^
------------------------------------------------------------

h5py/api_types_hdf5.pxd:255:4: 'int64_t' is not a type identifier

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

  #  Prototype for H5Literate/H5Literate_by_name() operator
  ctypedef herr_t (*H5L_iterate_t) (hid_t group, char *name, H5L_info_t *info,
                    void *op_data) except 2

  ctypedef uint32_t H5O_msg_crt_idx_t
          ^
------------------------------------------------------------

h5py/api_types_hdf5.pxd:263:11: 'uint32_t' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
  ctypedef struct H5O_info_t:
    unsigned long   fileno      #  File number that object is located in
    haddr_t         addr        #  Object address in file
    H5O_type_t      type        #  Basic object type (group, dataset, etc.)
    unsigned        rc          #  Reference count of object
    time_t          atime       #  Access time
   ^
------------------------------------------------------------

h5py/api_types_hdf5.pxd:313:4: 'time_t' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
    unsigned long   fileno      #  File number that object is located in
    haddr_t         addr        #  Object address in file
    H5O_type_t      type        #  Basic object type (group, dataset, etc.)
    unsigned        rc          #  Reference count of object
    time_t          atime       #  Access time
    time_t          mtime       #  Modification time
   ^
------------------------------------------------------------

h5py/api_types_hdf5.pxd:314:4: 'time_t' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
    haddr_t         addr        #  Object address in file
    H5O_type_t      type        #  Basic object type (group, dataset, etc.)
    unsigned        rc          #  Reference count of object
    time_t          atime       #  Access time
    time_t          mtime       #  Modification time
    time_t          ctime       #  Change time
   ^
------------------------------------------------------------

h5py/api_types_hdf5.pxd:315:4: 'time_t' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
    H5O_type_t      type        #  Basic object type (group, dataset, etc.)
    unsigned        rc          #  Reference count of object
    time_t          atime       #  Access time
    time_t          mtime       #  Modification time
    time_t          ctime       #  Change time
    time_t          btime       #  Birth time
   ^
------------------------------------------------------------

h5py/api_types_hdf5.pxd:316:4: 'time_t' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
cdef herr_t H5Aget_info_by_name(hid_t loc_id, char *obj_name, char *attr_name, H5A_info_t *ainfo, hid_t lapl_id) except *
cdef herr_t H5Aget_info_by_idx(hid_t loc_id, char *obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, H5A_info_t *ainfo, hid_t lapl_id) except *
cdef herr_t H5Aiterate2(hid_t obj_id, H5_index_t idx_type, H5_iter_order_t order, hsize_t *n, H5A_operator2_t op, void *op_data) except *
cdef hsize_t H5Aget_storage_size(hid_t attr_id) except *
IF MPI:
    cdef herr_t H5Pset_fapl_mpio(hid_t fapl_id, MPI_Comm comm, MPI_Info info) except *
                                               ^
------------------------------------------------------------

h5py/defs.pxd:320:48: 'MPI_Comm' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
cdef herr_t H5Aget_info_by_name(hid_t loc_id, char *obj_name, char *attr_name, H5A_info_t *ainfo, hid_t lapl_id) except *
cdef herr_t H5Aget_info_by_idx(hid_t loc_id, char *obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, H5A_info_t *ainfo, hid_t lapl_id) except *
cdef herr_t H5Aiterate2(hid_t obj_id, H5_index_t idx_type, H5_iter_order_t order, hsize_t *n, H5A_operator2_t op, void *op_data) except *
cdef hsize_t H5Aget_storage_size(hid_t attr_id) except *
IF MPI:
    cdef herr_t H5Pset_fapl_mpio(hid_t fapl_id, MPI_Comm comm, MPI_Info info) except *
                                                              ^
------------------------------------------------------------

h5py/defs.pxd:320:63: 'MPI_Info' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
cdef herr_t H5Aiterate2(hid_t obj_id, H5_index_t idx_type, H5_iter_order_t order, hsize_t *n, H5A_operator2_t op, void *op_data) except *
cdef hsize_t H5Aget_storage_size(hid_t attr_id) except *
IF MPI:
    cdef herr_t H5Pset_fapl_mpio(hid_t fapl_id, MPI_Comm comm, MPI_Info info) except *
IF MPI:
    cdef herr_t H5Pset_fapl_mpiposix(hid_t fapl_id, MPI_Comm comm, hbool_t hints) except *
                                                   ^
------------------------------------------------------------

h5py/defs.pxd:322:52: 'MPI_Comm' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
  herr_t H5Aget_info_by_name(hid_t loc_id, char *obj_name, char *attr_name, H5A_info_t *ainfo, hid_t lapl_id) except *
  herr_t H5Aget_info_by_idx(hid_t loc_id, char *obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, H5A_info_t *ainfo, hid_t lapl_id) except *
  herr_t H5Aiterate2(hid_t obj_id, H5_index_t idx_type, H5_iter_order_t order, hsize_t *n, H5A_operator2_t op, void *op_data) except *
  hsize_t H5Aget_storage_size(hid_t attr_id) except *
  IF MPI:
    herr_t H5Pset_fapl_mpio(hid_t fapl_id, MPI_Comm comm, MPI_Info info) except *
                                          ^
------------------------------------------------------------

h5py/_hdf5.pxd:320:43: 'MPI_Comm' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
  herr_t H5Aget_info_by_name(hid_t loc_id, char *obj_name, char *attr_name, H5A_info_t *ainfo, hid_t lapl_id) except *
  herr_t H5Aget_info_by_idx(hid_t loc_id, char *obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, H5A_info_t *ainfo, hid_t lapl_id) except *
  herr_t H5Aiterate2(hid_t obj_id, H5_index_t idx_type, H5_iter_order_t order, hsize_t *n, H5A_operator2_t op, void *op_data) except *
  hsize_t H5Aget_storage_size(hid_t attr_id) except *
  IF MPI:
    herr_t H5Pset_fapl_mpio(hid_t fapl_id, MPI_Comm comm, MPI_Info info) except *
                                                         ^
------------------------------------------------------------

h5py/_hdf5.pxd:320:58: 'MPI_Info' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
  herr_t H5Aiterate2(hid_t obj_id, H5_index_t idx_type, H5_iter_order_t order, hsize_t *n, H5A_operator2_t op, void *op_data) except *
  hsize_t H5Aget_storage_size(hid_t attr_id) except *
  IF MPI:
    herr_t H5Pset_fapl_mpio(hid_t fapl_id, MPI_Comm comm, MPI_Info info) except *
  IF MPI:
    herr_t H5Pset_fapl_mpiposix(hid_t fapl_id, MPI_Comm comm, hbool_t hints) except *
                                              ^
------------------------------------------------------------

h5py/_hdf5.pxd:322:47: 'MPI_Comm' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
## {{{ http://code.activestate.com/recipes/577336/ (r3)
from cpython cimport pythread
^
------------------------------------------------------------

h5py/_locks.pxi:2:0: Compiler crash in AnalyseDeclarationsTransform

File 'ModuleNode.py', line 101, in analyse_declarations: ModuleNode(defs.pyx:1:0,
    full_module_name = 'h5py.defs')
File 'Nodes.py', line 383, in analyse_declarations: StatListNode(defs.pyx:1:0)
File 'Nodes.py', line 383, in analyse_declarations: StatListNode(_locks.pxi:2:0)
File 'Nodes.py', line 6826, in analyse_declarations: FromCImportStatNode(_locks.pxi:2:0,
    imported_names = [...]/1,
    module_name = u'cpython')

Compiler crash traceback from this point on:
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Compiler/Nodes.py", line 6826, in analyse_declarations
    module_scope = env.find_module(self.module_name, self.pos)
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Compiler/Symtab.py", line 1089, in find_module
    module_name, relative_to = self.parent_module, pos = pos)
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Compiler/Main.py", line 132, in find_module
    pxd_pathname = self.find_pxd_file(qualified_name, pos)
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Compiler/Main.py", line 184, in find_pxd_file
    pxd = self.search_include_directories(qualified_name, ".pxd", pos, sys_path=True)
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Compiler/Main.py", line 225, in search_include_directories
    tuple(self.include_directories), qualified_name, suffix, pos, include, sys_path)
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Utils.py", line 16, in wrapper
    res = cache[args] = f(*args)
  File "/usr/local/lib/python2.7/dist-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/Cython/Utils.py", line 101, in search_include_directories
    path = os.path.join(dir, dotted_filename)
  File "/usr/lib/python2.7/posixpath.py", line 71, in join
    path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 18: ordinal not in range(128)
building 'h5py.defs' extension
/usr/bin/mpicc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DH5_USE_16_API -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/home/jnunezrami/Téléchargements/h5py-2.2.1/lzf -I/usr/local/lib/python2.7/dist-packages/mpi4py/include -I/usr/include/python2.7 -c h5py/defs.c -o build/temp.linux-x86_64-2.7/h5py/defs.o
h5py/defs.c:1:2: erreur: #error Do not use this file, it is the result of a failed Cython compilation.
error: command '/usr/bin/mpicc' failed with exit status 1

--
 
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Matt | 19 Feb 15:00 2014
Picon

Constructing tuple with generator expression in cdef function

I tried this inside 0.20.1 but it crashes the compiler. (See below for the traceback).

cdef foo(int n):
    cdef int i
    return tuple(i*i for i in xrange(n))

This works, but uses an intermediate list in the generated code:

cdef foo(int n):
    cdef int i
    return tuple([i*i for i in xrange(n)])

Is there any way to get something roughly equivalent to the following CPython API calls?

PyObject* foo(int n) {
    PyObject* t = PyTuple_New(n);
    for(int i=0; i < n; ++i) {
        PyTuple_SET_ITEM(t, i, PyInt_FromLong(i*i));
    }
    return t;
}

Thanks

Matt


Error compiling Cython file:
------------------------------------------------------------
...
cdef foo(int n):
    ^
------------------------------------------------------------

test.pyx:1:5: closures inside cdef functions not yet supported

Error compiling Cython file:
------------------------------------------------------------
...
cdef foo(int n):
    cdef int i
    return tuple(i*i for i in xrange(n))
                 ^
------------------------------------------------------------

test.pyx:3:18: Compiler crash in CreateClosureClasses

ModuleNode.body = StatListNode(test.pyx:1:5)
StatListNode.stats[0] = CFuncDefNode(test.pyx:1:5,
    args = [...]/1,
    modifiers = [...]/0,
    needs_closure = True,
    visibility = u'private')
CFuncDefNode.body = StatListNode(test.pyx:2:4,
    is_terminator = True)
StatListNode.stats[0] = ReturnStatNode(test.pyx:3:4,
    is_terminator = True)
ReturnStatNode.value = SimpleCallNode(test.pyx:3:16,
    analysed = True,
    is_temp = 1,
    result_is_used = True,
    use_managed_ref = True)
SimpleCallNode.arg_tuple = TupleNode(test.pyx:3:16,
    is_sequence_constructor = 1,
    is_temp = 1,
    result_is_used = True,
    use_managed_ref = True)
TupleNode.args[0] = GeneratorExpressionNode(test.pyx:3:18,
    genexpr_name = u'genexpr1',
    is_temp = 1,
    name = u'genexpr',
    needs_closure = True,
    needs_self_code = True,
    pymethdef_cname = u'__pyx_mdef_2xi_4test_3foo_1genexpr',
    result_is_used = True,
    use_managed_ref = True)

Compiler crash traceback from this point on:
  File "Visitor.py", line 170, in Cython.Compiler.Visitor.TreeVisitor._visit (c:\temp\pip-build\cython\Cython\Compiler\Visitor.c:4284)
  File "C:\python27\lib\site-packages\Cython\Compiler\ParseTreeTransforms.py", line 2364, in visit_LambdaNode
    self.create_class_from_scope(node.def_node, self.module_scope, node)
  File "C:\python27\lib\site-packages\Cython\Compiler\ParseTreeTransforms.py", line 2342, in create_class_from_scope
    type=cscope.scope_class.type,
AttributeError: 'ClosureScope' object has no attribute 'scope_class'


--
 
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Gaël | 17 Feb 23:23 2014

Invalid C++ with Python and C++ iterators (not compiling in CLang)

Hi,

I'd like to enquire on the status of the problem raised last year:
https://mail.python.org/pipermail/cython-devel/2013-April/003629.html

To summarize, the following Cython leads to code that doesn't compile
with Clang and is probably invalid C++:

    from libcpp.vector cimport vector as libcpp_vector
    from cython.operator cimport dereference as deref, preincrement as inc

    cdef class TestClass:

        cdef libcpp_vector[float] inst

        def __iter__(self):
            it = self.inst.begin()
            while it != self.inst.end():
                yield deref(it)
                inc(it)

This create the following C++ code:

  p->__pyx_v_it.std::vector<float>::iterator::~iterator();

which is invalid, but happens to work on GCC and MSVC. However, Clang
support is starting to become very important, as it is the default
compiler on MacOSX.

The original reporter suggested a valid C++ code (see original email),
which wasn't very convenient as it required a typedef.

Any progress on the issue or suggestion to work around?

Cheers,

Gaël

PS: I tried sending this on the devel mail, but maybe I screwed up something. Anyhow, it seems that the email is not getting through.

--
 
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Gmane