Mitesh Patel | 13 Nov 01:34 2010
Picon

Re: Re: Function next_prime using with cython

On 11/12/2010 03:17 PM, Robert Bradshaw wrote:
> On Fri, Nov 12, 2010 at 7:56 AM, karneades <apo <at> pdauf.de> wrote:
>> On 12 Nov., 15:50, Mitesh Patel <qed... <at> gmail.com> wrote:
>>> On 11/12/2010 08:35 AM, karneades wrote:
>>> What happens if you prepend
>>>
>>> from sage.rings.arith import next_prime
>>> from sage.misc.misc import cputime
>>>
>> Thank you Mitesh Patel,
>>
>> this works.
>>
>> Any hints, where i can find more information for this necessery
>> imports?
> 
> You get a NameError telling you what functions you need to import.

To find the module paths of the missing functions, I used introspection,
e.g.,

next_prime?<TAB>

and checked the "File:" field.

But William's and Robert's suggestions seem much more convenient.

> (Either that or a typo.) Now that cython has import *, perhaps we
> should do a "from sage.all import *" at the top. Even better would be
> to use http://wiki.cython.org/enhancements/inline which automatically
(Continue reading)

karneades | 13 Nov 13:09 2010
Picon

Re: Function next_prime using with cython

On 13 Nov., 01:34, Mitesh Patel <qed... <at> gmail.com> wrote:
> On 11/12/2010 03:17 PM, Robert Bradshaw wrote:
>
> But William's and Robert's suggestions seem much more convenient.
>
Thank You very much just as to William and Robert.
The Help in this user-group is great!

And so it comes, the next questions:

1. Is there in the web an example showing how i can "cythonize" only
    a little part of a Pythonprogram (i.e. a inner loop)
    The reason is, i'm often using "inner lamdas" and generators.

2. Is there a way, to make unbound ints (like ZZ) static in the way
   to a c-function?

Why want i do more?:

This first try (Fermat-factorization)  with cython, was a little
disappointing.
The cython version needs about 295 secs,
the native python version 210 secs
for factoring next_prime(1234567890)*next_prime(9876543210)
on a AMD 6000 cpu with ubuntu 10.10.

k.

Vineet Jain | 13 Nov 15:24 2010
Picon

small test program works in python but raises exception through cython

#######test.py and testcython.pyx

import os
import h5py
import numpy

os.popen("rm myfile.hdf5")
f = h5py.File('myfile.hdf5')
dset = f.create_dataset("MyDataset", (10, 10), 'i')
dset[...] = 42

indexDest = f["MyDataset"]
index = numpy.zeros(dtype=indexDest.dtype, shape=indexDest.shape)
index = indexDest[:]
f.close()
print index

Output from python module and cython module

>>> import testcython
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "testcython.pyx", line 13, in init
modules.pytrade.db.h5py.testcython
(modules/pytrade/db/h5py/testcython.c:725)
    index = indexDest[:]
  File "/usr/lib/python2.6/dist-packages/h5py/highlevel.py", line
1200, in __getitem__
    selection = sel.select(self.shape, args, dsid=self.id)
  File "/usr/lib/python2.6/dist-packages/h5py/selections.py", line 94, in select
(Continue reading)

Robert Bradshaw | 13 Nov 19:10 2010

Re: Re: Function next_prime using with cython

On Sat, Nov 13, 2010 at 4:09 AM, karneades <apo <at> pdauf.de> wrote:
> On 13 Nov., 01:34, Mitesh Patel <qed... <at> gmail.com> wrote:
>> On 11/12/2010 03:17 PM, Robert Bradshaw wrote:
>>
>> But William's and Robert's suggestions seem much more convenient.
>>
> Thank You very much just as to William and Robert.
> The Help in this user-group is great!
>
> And so it comes, the next questions:
>
> 1. Is there in the web an example showing how i can "cythonize" only
>    a little part of a Pythonprogram (i.e. a inner loop)
>    The reason is, i'm often using "inner lamdas" and generators.

Closures (inner lambdas) work as of the latest release, bug generators
are still not supported yet.

> 2. Is there a way, to make unbound ints (like ZZ) static in the way
>   to a c-function?

Not sure what you want to do here.

> Why want i do more?:
>
> This first try (Fermat-factorization)  with cython, was a little
> disappointing.
> The cython version needs about 295 secs,
> the native python version 210 secs
> for factoring next_prime(1234567890)*next_prime(9876543210)
(Continue reading)

Stefan Behnel | 13 Nov 19:19 2010
Picon

Re: Re: Function next_prime using with cython

Robert Bradshaw, 13.11.2010 19:10:
> bug generators are still not supported yet.

Doesn't sound like an important feature to me. ;)

Stefan


Gmane