GB | 11 Apr 20:18 2014
Picon

is Cython basic tutorial wrong?

I'm trying to follow this guidelines:
http://docs.cython.org/src/tutorial/cython_tutorial.html#the-basics-of-cython

but they don't work. I get this error:
 
C:\Users\Gabriele\Documents\università\TESI\code\test>python setup.py build_ext
--inplace
Compiling helloworld.pyx because it changed.
Cythonizing helloworld.pyx
C:\Anaconda\lib\site-packages\Cython\Utils.py:14: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  res = cache.get(args, uncomputed)
C:\Anaconda\lib\site-packages\Cython\Utils.py:16: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  res = cache[args] = f(*args)
running build_ext
building 'helloworld' extension
C:\Anaconda\Scripts\gcc.bat -DMS_WIN64 -mdll -O -Wall -IC:\Anaconda\include -IC:\Anaconda\PC -c helloworld.c -o build\temp.win-amd64-2.7\Release\helloworld.o
gcc.exe: error: helloworld.c: No such file or directory
gcc.exe: fatal error: no input files
compilation terminated.
error: command 'gcc' failed with exit status 1

What can I do?

thanks

Gabriele

--

---
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/d/optout.
GB | 11 Apr 19:51 2014
Picon

speed up with C extension

Hi,

I have a program in Python that is processing 3000000 data doing 200 operations on each one of them.

I would like to speed it up using a C routine.

In particular I'm using a scipy.interpolate function called interp1d.

How can I use Cython to write a routine like this?

Thanks

Gabriele

--

---
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/d/optout.
GB | 11 Apr 19:46 2014
Picon

speed up python routine writing C extension: can Cython be useful?

Hi,

I have a program that analyze 3000000 data and for each of them it makes 200 calculations (an interpolation with interp1d from scipy.interpolate).

I would like to speed up the process because now it takes near 12 hours...

I know that the bottleneck is this interp1d because I have profiled the program for different (small) numebers of data and this is the process that increase in time.

Do you think that using a C extension could speed up the process? How can I do that (it's the first time I try something like this)?

thanks

GB

--

---
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/d/optout.
sparrow2867 | 11 Apr 14:22 2014
Picon

Any progress on standalone dll's?

There has been a discussion about this on cython.devel on May 12th 2009, but 
apparently there are no examples on the web about how to use Cython to build 
dll's that can be loaded by, say, C++ code without embedding Python.
Stefan Behnel's reply at that time was "I never tried.".
The point I would like to make here that it would be a very appealing option 
if Cython could build dll's like C++ can, so callable without loading Python 
runtime.
My question is: has anyone tried, is there any example available?
I have been protoyping in Python/Cython, building modules to be contained
in a dll. 
Ultimately I had to translate everything to C++ since the application calling 
the dll did not have Python runtime and I could not persuade its owners to add 
Python runtime.

--

---
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/d/optout.
Christopher Jordan-Squire | 8 Apr 07:06 2014
Picon

recarray and typed memory views

I'm writing cython code to glue together some C code and python. The C code takes in many different struct types, such as

typdef struct{
char[16] name
int id
double value
} Container;

In total there are around 10 different types like that. So in the cython code I have many declarations like

ctypedef struct Container:
char[16] name
int id
double value

But I'd also like to create arrays of Container in python and pass those into the C code via Cython. Ideally without extension types that glom together Python objects to put into an array of strut at the cython level. The obvious thing to try was numpy record arrays. So in addition to the cython boilerplate I have numpy boiler plate for these types, e.g. 

container_t = np.dtype( '|S16,i4,f8', align=True). 

This works. But I'm repeating myself a lot. Not only do I create the cython type, but I also create a numpy dtype containing essentially the same information. Is there any way to get around this while keeping the same functionality? 

Thanks,
Chris

--

---
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/d/optout.
Dan Farmer | 7 Apr 20:03 2014
Picon

Serialization advice

Hello,

Here's the background: I have a C++ library (which could less charitably be called C with classes) that I've wrapped with Cython. This all works fine. But now I would like to be able to save things to disk. Under the hood the problematic structure is a singly linked list that is allocated by the C++ library when the constructor is called (TList). In my python code I have dictionaries that contain meta-data and the wrapped versions of the TLists e.g., {'experiment': 'foo', 'result': <TList>}. I'd like to be able to pickle this structure.

The Cython FAQ has an entry on this, but it just links to the python docs on the pickle protocol, which vaguely makes sense but it's still not clear to me how that interacts concretely with cython and cdef'd objects. So where I have cdef class ListWrapper I would def __reduce__(self) and this returns the constructor that would create an empty ListWrapper, and then... somehow I need to squirrel the data away and then reinsert the data. This is the part that has me confused.

I'd appreciate any tips or pointers to similar code that's out there.

Thanks,
Dan

--

---
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/d/optout.
chetan raga | 7 Apr 07:31 2014
Picon

error while creating cython wrapper class between c++ and python in linux

This is pyx:
def extern from "Rect.h":
    cdef cppclass Rectangle:
        Rectangle()
        int getLength()
 
cdef class PyRectangle:
    cdef Rectangle *thisptr
    def __cinit__(self):
        self.thisptr = new Rectangle()
    def __dealloc__(self):
        del self.thisptr
    def getLength(self):
        return self.thisptr.getLength()


this is .cpp file
#include "dijsdk.h"
#include <iostream>
#include <QString>
#include "arraysize.h"
#include "Rect.h"



Rectangle::Rectangle()
{
}
 
Rectangle::~Rectangle()
{
}
 
int Rectangle::getLength()
{
QString m_guids[16];
    DijSDK_CamGuid guids[ARRAYSIZE(m_guids)] = {0};
    unsigned int numGuids = ARRAYSIZE(guids);
    int result;
    int index;
    int res = DijSDK_Init();
    result = DijSDK_FindCameras(guids, &numGuids);
   
    std::cout<<"\nNumGuids = "<<numGuids;
   
    std::cout<<"\nresult = "<<result;
       
    if(result == 0)
        result1 = DijSDK_FindCameras(guids, &numGuids); //API call
       
    std::cout<<"\nNumguids = " <<numGuids;
    std::cout<<"\nResult = "<<result1;
    std::cout<<"\nGuids = "<<guids[0];
   
    return 0;
}

this is .h file
class Rectangle {
public:
  Rectangle();
  ~Rectangle();
  int getLength();

};
this is setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
 
setup(ext_modules=[Extension("rectangle", ["rect.pyx", "Rect.cpp"], language="c++",)],
include_dirs=["/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4"],
cmdclass = {'build_ext': build_ext})

after that iam using command in linux
user <at> emb-ubu-085:~/Desktop/reports$ sudo python setup.py build_ext --inplace  -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I.
running build_ext
cythoning rect.pyx to rect.cpp
building 'rectangle' extension
i686-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I. -I/usr/include/python2.7 -c rect.cpp -o build/temp.linux-i686-2.7/rect.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
i686-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I. -I/usr/include/python2.7 -c Rect.cpp -o build/temp.linux-i686-2.7/Rect.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
Rect.cpp:3:19: fatal error: QString: No such file or directory
compilation terminated.
error: command 'i686-linux-gnu-gcc' failed with exit status 1

let me know guys where iam doing mistake in the above case

--

---
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/d/optout.
Saullo Castro | 3 Apr 19:47 2014
Picon

Wrong signature error using function types in multiple modules

I have the following Cython modules:

compmech integrate integratev.pxd integratev.pyx conecyl main.pyx

In integratev.pxd I've declared:

ctypedef void (*f_type)(int npts, double *xs, double *ts, double *out, double *alphas, double *betas, void *args) nogil cdef int trapz2d(f_type f, int fdim, np.ndarray[cDOUBLE, ndim=1] final_out, double xmin, double xmax, int m, double ymin, double ymax, int n, void *args, int num_cores)

I call trapz2d from main.pyx, and the function passed to trapz2d is declared in main.pyx, e.g:

from compmech.integrate.integratev cimport trapz2d cdef void cfk0L(int npts, double *xs, double *ts, double *out, double *alphas, double *betas, void *args) nogil: ... trapz2d(cfk0L, fdim, k0Lv, xa, xb, nx, ta, tb, nt, &args, num_cores)

It compiles just fine, but when I run I get the error:

TypeError: C function compmech.integrate.integratev.trapz2d has wrong signature (expected int (__pyx_t_8compmech_9integrate_10integratev_f_type, int, PyArrayObject *, double, double, int, double, double, int, void *, int), got int (__pyx_t_10integratev_f_type, int, PyArrayObject *, double, double, int, double, double, int, void *, int))ddoes anybody known how to avoid this error?

--

---
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/d/optout.
Skipper Seabold | 2 Apr 16:26 2014
Picon

Re: Supporting Capsule and CObject?

On Wed, Apr 2, 2014 at 2:19 AM, Stefan Behnel <stefan_ml <at> behnel.de> wrote:
> Skipper Seabold, 01.04.2014 22:57:
>> I am trying to use the header file provided by numpy [1] so that our
>> code builds on both Python 2 and Python 3. I must be missing something
>> though. So far I can only get it to compile on Python 2. Python 3
>> results in the attached error log. Two questions.
>>
>> 1) why do I need to use object in the declaration rather than a
>> pointer to cython.object.PyObject to get it to compile on Python 2.
>> 2) Any idea why this isn't compiling on Python 3?
>
> What's the error you get in Py3?

For this minimum example, I get the following

https://gist.github.com/jseabold/9935135

Longer project build. Similar errors, but in numpy/npy_3kcompat.h

https://travis-ci.org/statsmodels/statsmodels/jobs/22067954

>
> Regarding the subject line, note that PyCObject is no longer available in
> Py3, so you have to use PyCapsule there (which is also available in Py2.7
> but not earlier).

Right. We need to support Python 2.6 - 3.4. It looks like that's what
the NpyCapsule_AsVoidPtr is for in numpy linked upthread.

>
>
>> cdef extern from "numpy/npy_3kcompat.h":
>>     void *NpyCapsule_AsVoidPtr(object ptr)
>
> Assuming this is what your question 1) is referring to, you need to use
> "object" here because you are passing a Python object.

I guess this is what's confusing me

[~/]
[3]: scipy.linalg.get_blas_funcs('gemm')._cpointer
[3]: <PyCObject at 0x5657648>

>
> Cython distinguishes between a (non-refcounted) pointer (which includes
> PyObject*) and a ref-counted Python object reference. The normal thing to
> use is "object", unless you know what you are doing.
>
> The only case where you have to be careful is when a function return value
> is a so-called "borrowed reference". In that case, you can't use "object",
> because that would make Cython think it owns the reference. In that case,
> declare it as "PyObject*" and use an explicit cast to <object>.
>

Thanks. That's helpful. I did read the faq on this, I guess I just
haven't fully absorbed it.

Skipper

> Stefan
>
> --
>
> ---
> 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/d/optout.

--

-- 

--- 
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/d/optout.

Stefan Behnel | 2 Apr 09:42 2014
Picon

Re: CYTHON_INLINE causing errors on MacOS with clang

Daniel Farrell, 02.04.2014 04:43:
> A follow up to this. In the end I removed the inline from the functions in,
> https://github.com/bmcage/odes/blob/master/scikits/odes/sundials/common_defs.pxd
>  
> 
> This allowed the compilation to complete without further errors, however 
> the end product is not valid. When running the tests that come with the 
> scikits.odes package produce an namespace error when loading the complied 
> code,
> 
> Expected in: flat namespace

What is expected there? The function symbol? Or something else? When
reporting errors, please always take care to provide the complete error
message, including any context that might help in understanding it (and/or
the actual problem).

The error message above generally hints at some kind of linking problem,
maybe a missing library.

Stefan

--

-- 

--- 
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/d/optout.

Skipper Seabold | 1 Apr 22:57 2014
Picon

Supporting Capsule and CObject?

Hi,

I am trying to use the header file provided by numpy [1] so that our
code builds on both Python 2 and Python 3. I must be missing something
though. So far I can only get it to compile on Python 2. Python 3
results in the attached error log. Two questions.

1) why do I need to use object in the declaration rather than a
pointer to cython.object.PyObject to get it to compile on Python 2.
2) Any idea why this isn't compiling on Python 3?

[1] https://github.com/numpy/numpy/blob/master/numpy/core/include/numpy/npy_3kcompat.h

Skipper

------

#mwe.pyx
cimport cython

import scipy.linalg
from numpy import float64
from numpy cimport float64_t, PyArray_EMPTY, ndarray
cimport numpy as cnp
cnp.import_array()

ctypedef float64_t DOUBLE

from blas cimport dgemm_t

cdef extern from "numpy/npy_3kcompat.h":
    void *NpyCapsule_AsVoidPtr(object ptr)

cdef dgemm_t *dgemm =
<dgemm_t*>NpyCapsule_AsVoidPtr(scipy.linalg.blas.get_blas_funcs('gemm',
dtype=float64)._cpointer)

 <at> cython.boundscheck(False)
 <at> cython.wraparound(False)
 <at> cython.cdivision(True)
def mydot(ndarray[DOUBLE, ndim=2] A, ndarray[DOUBLE, ndim=2] B):
    cdef:
        cnp.npy_intp outshape[2]
        int m = A.strides[1]/sizeof(DOUBLE)
        int FORTRAN = 1
    outshape[0] = <cnp.npy_intp> m
    outshape[1] = <cnp.npy_intp> m
    cdef:
        DOUBLE alpha = 1.0
        DOUBLE beta = 0.0
        ndarray[DOUBLE, ndim=2] out = PyArray_EMPTY(2, outshape,
                                                    cnp.NPY_DOUBLE,
                                                    FORTRAN)

    dgemm("N", "N", &m, &m, &m, &alpha, <DOUBLE*>A.data, &m,
          <DOUBLE*>B.data, &m, &beta, <DOUBLE*>out.data, &m)
    return out

-------------------

#blas.pxd
ctypedef int dgemm_t(
    # Compute C := alpha*A*B + beta*C
    char *transa,  # {'T','C'}: o(A)=A'; {'N'}: o(A)=A
    char *transb,  # {'T','C'}: o(B)=B'; {'N'}: o(B)=B
    int *m,        # Rows of o(A)    (and of C)
    int *n,        # Columns of o(B) (and of C)
    int *k,        # Columns of o(A) / Rows of o(B)
    double *alpha, # Scalar multiple
    double *a,     # Matrix A: mxk
    int *lda,      # The size of the first dimension of A (in memory)
    double *b,     # Matrix B: kxn
    int *ldb,      # The size of the first dimension of B (in memory)
    double *beta,  # Scalar multiple
    double *c,     # Matrix C: mxn
    int *ldc       # The size of the first dimension of C (in memory)
)

--

-- 

--- 
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/d/optout.
Attachment (mwe.pyx): application/octet-stream, 1531 bytes
Attachment (blas.pxd): application/octet-stream, 960 bytes
Attachment (build): application/octet-stream, 10 KiB

Gmane