Message from discussion
Python to Cython conversion
Received: by 10.213.113.196 with SMTP id b4mr671248ebq.0.1328562154898;
Mon, 06 Feb 2012 13:02:34 -0800 (PST)
X-BeenThere: cython-users@googlegroups.com
Received: by 10.14.124.198 with SMTP id x46ls978229eeh.2.canary; Mon, 06 Feb
2012 13:02:33 -0800 (PST)
Received: by 10.180.92.196 with SMTP id co4mr1227589wib.2.1328562153644;
Mon, 06 Feb 2012 13:02:33 -0800 (PST)
Received: by 10.180.92.196 with SMTP id co4mr1227588wib.2.1328562153635;
Mon, 06 Feb 2012 13:02:33 -0800 (PST)
Return-Path: <markflorisso...@gmail.com>
Received: from mail-ww0-f42.google.com (mail-ww0-f42.google.com [74.125.82.42])
by gmr-mx.google.com with ESMTPS id m2si9811585wiy.2.2012.02.06.13.02.33
(version=TLSv1/SSLv3 cipher=OTHER);
Mon, 06 Feb 2012 13:02:33 -0800 (PST)
Received-SPF: pass (google.com: domain of markflorisso...@gmail.com designates 74.125.82.42 as permitted sender) client-ip=74.125.82.42;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of markflorisso...@gmail.com designates 74.125.82.42 as permitted sender) smtp.mail=markflorisso...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-ww0-f42.google.com with SMTP id gn7so3611821wgb.5
for <cython-users@googlegroups.com>; Mon, 06 Feb 2012 13:02:33 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=mime-version:in-reply-to:references:date:message-id:subject:from:to
:content-type;
bh=EIRygpIxVHsM65Jah7d6umhadh0+rbQmkwfwnKnWSes=;
b=G4KQROvzOjWgj5BKRS2ov+Wj1kksCutTJQwOduq2H9/TN4eFwbaT0S5w3fvbO0WhEK
pEuZcqdviBzodUls8/XDK7JApT3FqiIYUuNl8MAe4CwMY4APQU72qJtdjTSQRfK6BeKn
x6MLSwNukG3YdHZHYYw5wmHVsbuL/wbfvDlEw=
MIME-Version: 1.0
Received: by 10.180.24.166 with SMTP id v6mr15560964wif.10.1328562153566; Mon,
06 Feb 2012 13:02:33 -0800 (PST)
Received: by 10.180.103.134 with HTTP; Mon, 6 Feb 2012 13:02:33 -0800 (PST)
In-Reply-To: <CAObL9LYmfxnUH9BTEoyQaf7PhSc90RXY8pucK363DsNp-Fhp9A@mail.gmail.com>
References: <CAObL9LYmfxnUH9BTEoyQaf7PhSc90RXY8pucK363DsNp-Fh...@mail.gmail.com>
Date: Mon, 6 Feb 2012 21:02:33 +0000
Message-ID: <CANg26EXE-iKCgkyG=2ykKjYSnRU0HFz7hVz9K8Gjq=0UPdg...@mail.gmail.com>
Subject: Re: [cython-users] Python to Cython conversion
From: mark florisson <markflorisso...@gmail.com>
To: cython-users@googlegroups.com
Content-Type: text/plain; charset=UTF-8
On 5 February 2012 23:19, Waqas Muhi <waqas.m...@gmail.com> wrote:
> Hello,
>
> I'm currently working on a project for my Master's which involves optimizing
> a fairly big simulation system originally written in Python. I've read about
> and researched Cython and I think it would give me the best performance
> improvements. My software system basically is a bunch of Python .py files
> and the top-level module makes use of functions defined in them as
> appropriate.
>
> Based on some profiling, I've been able to identify a few of the .py files
> which are good candidates for the conversion. In particular, there are a few
> functions in one particular file - let's say xyz.py - which I'm looking to
> convert. My questions are:
>
> 1) Is it possible to convert a few of the functions to Cython and leave the
> rest with the original Python code?
Sure.
> 2) Would I have to rename the file to use the .pyx extension if the above is
> possible?
Yes, I believe that if you use the .py extension Cython expects a
pure-mode Python file (possibly annotated with Cython types etc).
That's probably not what you want.
> 3) If 1) is not possible, would file xyz.py still work properly with the
> other .py files in the software system if I do a full conversion to Cython?
> In other words, would anything change from the other files' perspective?
You can keep xyz.py and have it import performance-critical functions
from _xyz.pyx.
> Any feedback would be highly appreciated. Thanks a lot!
Just give the Cython tutorials a go and it will be a lot clearer to you :)
> Waqas