Lyrics Türkiye | 10 Dec 20:13 2014
Picon

Struct pointer declaring

Hello guys,

I started Cython new. Documention say to me (url)

cdef struct Grail:
   
int age
   
float volume

For this is use;

cdef Grail *gp

and after we know, I guess so like,

gp.age = 19

My sample is;

cdef struct kimlik:
    int tc
   
cdef kimlik k
k
.tc = 12345678911

print
"TC:",k.tc

result by to -539222977 If it isn't shot to me I must using pointer.

cdef kimlik * k

Compile is true but doesn't work it. (python.exe stopped by windows)

How is show to result value 12345678911?

Thank you for interest.
Best regards..

--

---
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.
larsmans | 10 Dec 20:19 2014
Picon

run a small part of the test suite with runtests.py

Hi all,

Quick question: if I've altered a test in the Cython source code, how do I run only that test (or maybe the file it's in) and not the entire test suite with runtests.py? I couldn't find it in the --help output.

TIA,
Lars

--

---
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.
Hai Nguyen | 10 Dec 17:50 2014
Picon

Cython syntax for CUDA programming?

Hi there,

As far as I know, supporting GPU for Python is still limited and the
most popular library is pycuda/pyopencl. In order to use it we still
need to write extension in C/C++ syntax
(http://documen.tician.de/pycuda/)

I am interested in writing CUDA code in clean Cython/Python syntax. Is
there any quick way to get this code below workable?
( I know that we can write very clean syntax with numbapro but
numbapro is not really free).

Thanks.

(This is very simple hello world example for running in GPU from this website
https://www.pdc.kth.se/resources/computers/zorn/how-to/how-to-compile-and-run-a-simple-cuda-hello-world)

hello.pyx
======
# pseudocode
from libcuda cimport *

DEF N = 7
DEF blocksize = 7

# dummy cuda decorator to let Cython know that it will be used with CUDA
cdef cuda(func, message):
    pass

 <at> cuda('global')
cdef void hello (char* a, int *b, cudablockcode=args):
    # C language: void __global__ hello(...)
    # cudablockcode will be translated to something like <<<dimGrid, dimBlock>>>
    # hello<<dimGrid, dimBlock>>>(ad, bd)
    a[threadIdx.x] += b[threadIdx.x]

cdef main():
    cdef char[N] a = "Hello "
    cdef int[N] b = [15, 10, 6, 0, -11, 1, 0]
    cdef:
        char* ad
        int* db
        int csize = N * sizeof(char)
        int isize = N * sizeof(int)
        int i=1
        dim3 dimBlock(blocksize, i)
        dim3 dimGrid(i, i)

    print a
    # alloc and copy to device
    cudaMalloc(<void**≥&ad, csize)
    cudaMalloc(<void**≥&bd, isize)
    cudaMemcpy(ad, a, csize, cudaMemcpyHostToDevice)
    cudaMemcpy(bd, b, isize, cudaMemcpyHostToDevice)

    # hello<<<dimGrid, dimBlock>>>(ad, bd)
    # call function in device
    hello(ad, bd, cudablockcode=(dimGrid, dimBlock))

    # copy to host
    cudaMemcpy(a, ad, csize, cudaMemcpyDeviceToHost)

    # free mem
    cudaFree(ad)

libcuda.pxd
========
# delaration for CUDA
cdef extern from "driver_types.h":
    ctypedef enum cudaError:
        pass
    ctypedef enum cudaMemcpyKind:
        cudaMemcpyHostToHost
        cudaMemcpyHostToDevice
        cudaMemcpyDeviceToHost
        cudaMemcpyDeviceToDevice
        cudaMemcpyDefault

cdef extern from "vector_types.h":
    ctypedef struct uint3:
        unsigned int x, y, z
    ctypedef struct dim3:
        pass

cdef extern from "cuda.h":
    uint3 threadIdx
    uint3 threadIdy
    uint3 threadIdz

cdef extern from "device_functions.h":
    void __syncthreads(void)

ctypedef cudaError cudaError_t
cdef extern from "cuda_device_runtime_api.h":
    cudaError_t cudaMalloc(void **p, size_t s)
    cudaError_t cudaMemcpy()

cdef extern from "cuda_runtime_api.h":
    cudaError_t CUDARTAPI cudaMemcpy(void *dst, const void *src, size_t count,
                                     enum cudaMemcpyKind kind)

cheer
Hai

--

-- 

--- 
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.

Jeroen Demeyer | 10 Dec 17:35 2014
Picon

Exporting C (not Cython) functions

Hello,

Is there a mechanism in Cython to __Pyx_ExportFunction() a function 
which is defined in a C library (which is not a Cython function)?

I want a mylib.pxd file with

cdef int myfunc()       # Note: not extern!

but without defining myfunc() in the .pyx file: the function myfunc() is 
actually implemented in C code which is linked with mylib.pyx.

Is this by any chance possible in Cython?

--

-- 

--- 
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.

Robert McGibbon | 9 Dec 08:40 2014
Picon

Creating an array or typed memoryview without holding the GIL?

Is it possible to allocate a typed memoryview without holding the GIL? I was hoping, for example, to use code like what is shown below, but the cast seems to require the gil.

```
from libc.stdlib cimport malloc, free

cdef double* p
cdef double[::1] X
cdef size_t N

with nogil:
        p = <double* >malloc(N*sizeof(double))
        X = <double[:N]> p
        [...]
        free(p)
```

--

---
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.
Pedro Camargo | 9 Dec 00:25 2014
Picon

Memory Views and parallel computation

Hi there group.

                   I have not kept up too much with Cython since 0.16, but I am trying to keep up with it now as I try to implement a parallel version of the shortest path algorithms Jake Vanderplas created for SciPy (I'm running shortest path from all to all thousands of times for a really large network, so it NEEDS to be done in parallel, and I have 16 physical cores plus hyper threading).

          Back in early 2013, Sturla mentioned that I could use memory views, but I never got into doing it.
          Since each call of a Dijkstra algorithm will update a single row of the distance matrix, I imagine I can use a memory view of the network (the same for all the paths to be calculated) and a memory view for the corresponding line in the shortest path distance only to be updated in each call and use the cpdef *** nogil: structure found here: http://docs.cython.org/src/userguide/memoryviews.html

Am I missing anything?


Thanks,

Pedro

--

---
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.
Ivan Smirnov | 8 Dec 15:52 2014
Picon

New-style type annotations with gdb_debug=True cause compiler crash

Type annotations of the form "variable: type" will cause compiler to crash if gdb_debug is enabled:


Error compiling Cython file:
------------------------------------------------------------
...
    cdef
void reraise_exc(self, e: Exception) except *:
                                           
^
------------------------------------------------------------


test
/file.pyx:195:44: Compiler crash in DebugTransform


ModuleNode.body = StatListNode(file.pyx:6:0)
StatListNode.stats[6] = StatListNode(file.pyx:26:5)
StatListNode.stats[0] = CClassDefNode(file.pyx:26:5,
    as_name
= u'File',
    class_name
= u'File',
    doc
= u'',
    module_name
= u'',
    visibility
= u'private')
CClassDefNode.body = StatListNode(file.pyx:27:4)
StatListNode.stats[2] = CFuncDefNode(file.pyx:195:9,
    args
= [...]/2,
    is_c_class_method
= 1,
    modifiers
= [...]/0,
    visibility
= u'private')
CFuncDefNode.declarator = CFuncDeclaratorNode(file.pyx:195:25,
    calling_convention
= '',
    exception_check
= 1)
CFuncDeclaratorNode.args[1] = CArgDeclNode(file.pyx:195:32,
    cf_is_null
= True,
    cf_maybe_null
= True,
    cf_state
= [...]/0,
    cname
= u'__pyx_v_e',
    is_generic
= 1,
    name
= u'e')
CArgDeclNode.annotation = NameNode(file.pyx:195:44,
    cf_maybe_null
= True,
    is_name
= True,
    name
= u'Exception',
    result_is_used
= True,
    use_managed_ref
= True)


Compiler crash traceback from this point on:
 
File "Cython/Compiler/Visitor.py", line 173, in Cython.Compiler.Visitor.TreeVisitor._visit (-------src-dir-------/Cython-0.21/Cython/Compiler/Visitor.c:4456)
 
File ".../site-packages/Cython/Compiler/ParseTreeTransforms.py", line 2937, in visit_NameNode
    node
.type.is_cfunction and
AttributeError: 'NoneType' object has no attribute 'is_cfunction'
Traceback (most recent call last):
 
File ".../site-packages/Cython/Build/Dependencies.py", line 962, in cythonize_one_helper
   
return cythonize_one(*m[1:])
 
File ".../site-packages/Cython/Build/Dependencies.py", line 944, in cythonize_one
   
raise CompileError(None, pyx_file)
CompileError: test/file.pyx
Traceback (most recent call last):
 
File "setup.py", line 218, in <module>
    setup
(**setup_args())
 
File ".../distutils/core.py", line 151, in setup
    dist
.run_commands()
 
File ".../distutils/dist.py", line 953, in run_commands
   
self.run_command(cmd)
 
File ".../distutils/dist.py", line 971, in run_command
    cmd_obj
.ensure_finalized()
 
File ".../distutils/cmd.py", line 109, in ensure_finalized
   
self.finalize_options()
 
File ".../site-packages/setuptools/command/build_ext.py", line 108, in finalize_options
    _build_ext
.finalize_options(self)
 
File ".../distutils/command/build_ext.py", line 140, in finalize_options
   
('plat_name', 'plat_name'),
 
File ".../distutils/cmd.py", line 298, in set_undefined_options
    src_cmd_obj
.ensure_finalized()
 
File ".../distutils/cmd.py", line 109, in ensure_finalized
   
self.finalize_options()
 
File ".../distutils/command/build.py", line 103, in finalize_options
   
if self.distribution.ext_modules:
 
File "setup.py", line 175, in __len__
   
return len(self.cythonized)
 
File "setup.py", line 154, in cythonized
   
self._cythonized = self._build_and_cythonize()
 
File "setup.py", line 169, in _build_and_cythonize
    gdb_debug
=True, output_dir=os.path.join(pkg_root(), '..'))
 
File ".../site-packages/Cython/Build/Dependencies.py", line 816, in cythonize
    result
.get(99999)  # seconds
 
File ".../multiprocessing/pool.py", line 558, in get
   
raise self._value
Cython.Compiler.Errors.CompileError: test/file.pyx


asd

--

---
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.
vaxmogel | 8 Dec 11:45 2014
Picon

Weird bug in compiler flags when compiling an extension module

Hi folks,

recently, a bug during the installation of networkit through pip has been discovered for which we aren't able to find an explanation nor a solution.
When compiling the extension source code generated by Cython, it fails to compile, here's the line in question:

  g++-4.8 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -I/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m -c networkit/_NetworKit.cpp -o build/temp.macosx-10.6-intel-3.4/networkit/_NetworKit.o -fopenmp -std=c++11 -O3 -DNOGTEST

It seems that the compiler proceeds as usual, printing out warnings and such. Then, however, more than 100k lines complaining about bad register names in the assembler appear and g++ fails. This suggests, that the highlighted flags specifying the platform are responsible for this behaviour. I guess that most of the flags are generated by Cython's distutils(?), I thought that you maybe have an idea how these flags are gathered/determined.

Please note that this happened on a machine with Mac OSX 10.6 when installing the package through pip. The same happened when trying to build the extensions from a clone of the repository. Manually calling the line without -arch i386 does work, but is not really a solution for the automated installation through pip.

Since I'm not familiar with Mac OS and many installations on other Mac machines worked, the problem's origin is probably OS related and only appears when using Cython, however any help or hints to narrow it down are appreciated.

Thanks in advance,
Max

--

---
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.
Philips | 7 Dec 21:25 2014
Picon

Broadcasting and Memory Views

Is it correct that I should not expect broadcasting to work with memory views? That is what the following suggests. Aside: Is that compiler crash a bug?

def test():
    cdef np
.float64_t[:, :] test = np.ones(10, dtype=np.float64).reshape(5, 2)
   
   
# Compiler crash: Cython/Compiler/UtilNodes.py", AssertionError in line 143, in __init__: assert self.pos is not None
    test
[0] *= 3

    # Invalid operand types for '*' (float64_t[:, :]; long)
   
#test *= 3
   
    # Invalid operand types for '*' (float64_t[:, :]; long)
   
#test = test * 3
   
    # Invalid operand types for '*' (float64_t[:]; long)
   
#test[0] = test[0] * 3


In general, what will be the fastest way do to this? Should I do a manual loop? Or would it be better to do something like:

def test():
   test_
= np.ones(10, dtype=np.float64).reshape(5, 2)
   cdef np
.float64_t[:, :] test = test_
   
...
   test
[0] *= 3



--

---
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.
Marius Gedminas | 7 Dec 16:10 2014

pip install Cython fails randomly on Python 3.2

I submitted a pull request to lxml and was surprised by a Travis CI build failure while it was attempting to pip install Cython:

cythoning /home/travis/virtualenv/python3.2.5/build/Cython/Cython/Runtime/refnanny.pyx to /home/travis/virtualenv/python3.2.5/build/Cython/Cython/Runtime/refnanny.c
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/travis/virtualenv/python3.2.5/build/Cython/setup.py", line 337, in <module>
    **setup_args
  File "/opt/python/3.2.5/lib/python3.2/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/opt/python/3.2.5/lib/python3.2/distutils/dist.py", line 917, in run_commands
    self.run_command(cmd)
  File "/opt/python/3.2.5/lib/python3.2/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/home/travis/virtualenv/python3.2.5/lib/python3.2/site-packages/setuptools/command/install.py", line 54, in run
    return _install.run(self)
  File "/opt/python/3.2.5/lib/python3.2/distutils/command/install.py", line 569, in run
    self.run_command('build')
  File "/opt/python/3.2.5/lib/python3.2/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/opt/python/3.2.5/lib/python3.2/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/opt/python/3.2.5/lib/python3.2/distutils/command/build.py", line 126, in run
    self.run_command(cmd_name)
  File "/opt/python/3.2.5/lib/python3.2/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/opt/python/3.2.5/lib/python3.2/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "Cython/Distutils/build_ext.py", line 163, in run
    _build_ext.build_ext.run(self)
  File "/opt/python/3.2.5/lib/python3.2/distutils/command/build_ext.py", line 344, in run
    self.build_extensions()
  File "/home/travis/virtualenv/python3.2.5/build/Cython/setup.py", line 169, in build_extensions
    build_ext_orig.build_extensions(self)
  File "Cython/Distutils/build_ext.py", line 170, in build_extensions
    ext.sources = self.cython_sources(ext.sources, ext)
  File "Cython/Distutils/build_ext.py", line 319, in cython_sources
    full_module_name=module_name)
  File "/home/travis/virtualenv/python3.2.5/build/Cython/build/lib.linux-x86_64-3.2/Cython/Compiler/Main.py", line 627, in compile
    return compile_single(source, options, full_module_name)
  File "/home/travis/virtualenv/python3.2.5/build/Cython/build/lib.linux-x86_64-3.2/Cython/Compiler/Main.py", line 580, in compile_single
    return run_pipeline(source, options, full_module_name)
  File "/home/travis/virtualenv/python3.2.5/build/Cython/build/lib.linux-x86_64-3.2/Cython/Compiler/Main.py", line 406, in run_pipeline
    context = options.create_context()
  File "/home/travis/virtualenv/python3.2.5/build/Cython/build/lib.linux-x86_64-3.2/Cython/Compiler/Main.py", line 527, in create_context
    self.cplus, self.language_level, options=self)
  File "/home/travis/virtualenv/python3.2.5/build/Cython/build/lib.linux-x86_64-3.2/Cython/Compiler/Main.py", line 69, in __init__
    from . import Builtin, CythonScope
  File "/home/travis/virtualenv/python3.2.5/build/Cython/build/lib.linux-x86_64-3.2/Cython/Compiler/CythonScope.py", line 5, in <module>
    from .UtilityCode import CythonUtilityCode
  File "/home/travis/virtualenv/python3.2.5/build/Cython/build/lib.linux-x86_64-3.2/Cython/Compiler/UtilityCode.py", line 3, in <module>
    from .TreeFragment import parse_from_strings, StringParseContext
  File "/home/travis/virtualenv/python3.2.5/build/Cython/build/lib.linux-x86_64-3.2/Cython/Compiler/TreeFragment.py", line 20, in <module>
    from . import Parsing
  File "Cython/Plex/Actions.pxd", line 2, in init Cython.Compiler.Parsing (/home/travis/virtualenv/python3.2.5/build/Cython/Cython/Compiler/Parsing.c:55686)
    cdef class Action:
ValueError: Cython.Plex.Actions.Action has the wrong size, try recompiling

You can find the full build log at https://s3.amazonaws.com/archive.travis-ci.org/jobs/43259438/log.txt

The other pull request I submitted soon after this one succeeded without errors.  The first differing log line was:

    skipping '/home/travis/virtualenv/python3.2.5/build/Cython/Cython/Runtime/refnanny.c' Cython extension (up-to-date)

The full build log is at https://s3.amazonaws.com/archive.travis-ci.org/jobs/43260192/log.txt

You can see that both Travis builds were attempting to pip install Cython 0.21.1 on Python 3.2.5.

The only theory I have is that extracting the Cython tarball sometimes results in refnanny.pyx and refnanny.c having the same timestamp, and sometimes the timestamp differs.  When the timestamps match (which is the usual case), there's no cythoning and no error.  And yet sometimes you win a race and the two files end up with differing timestamps, in which case, uh, I don't know what happens.  The Cython install ends up trying to rebuild its own extensions using an older system-wide Cython installation that fails?  You tell me.

All I know is that apparently 'pip install Cython' can randomly fail and break CI builds of unrelated projects.

--

---
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.
Francisco Paisana | 7 Dec 13:52 2014
Picon
Picon

Comparison to boost.python

What are in your opinion the main strengths of cython C++ wrapping compared to the boost.python lib. I have only encountered the views of boost.python users on other forums so I would like to hear the opinion of some programmers of this group.

In my opinion, cython has a way better syntax than the ugly C++ boost lib, and it is way easier to understand the tutorials. The main thing I would change is describe more clearly how the conversion of stl containers is handled. I have also heard that boost.python is slow at compiling. Is it true?

Any way, I would like to hear your views.

Thanks.

Regards,
Francisco

--

---
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.

Gmane