No, it's because your loop is over 1 rather than 1000.
Sharp eyes! :)
So, to summarize, with the improved Cython one should always use isinstance
as it will be optimized to be at least as fast. I guess we should remove the
PY_TYPE_CHECK macro from Sage altogether and replace every
On Tue, Dec 21, 2010 at 4:16 AM, Volker Braun vbraun.n...@gmail.com wrote:
No, it's because your loop is over 1 rather than 1000.
Sharp eyes! :)
So, to summarize, with the improved Cython one should always use isinstance
as it will be optimized to be at least as fast.
Yes, as long as the
On 12/21/10 11:36 AM, Robert Bradshaw wrote:
On Tue, Dec 21, 2010 at 4:16 AM, Volker Braunvbraun.n...@gmail.com wrote:
No, it's because your loop is over 1 rather than 1000.
Sharp eyes! :)
So, to summarize, with the improved Cython one should always use isinstance
as it will be optimized
On Tue, Dec 21, 2010 at 10:29 AM, Jason Grout
jason-s...@creativetrax.com wrote:
On 12/21/10 11:36 AM, Robert Bradshaw wrote:
On Tue, Dec 21, 2010 at 4:16 AM, Volker Braunvbraun.n...@gmail.com
wrote:
No, it's because your loop is over 1 rather than 1000.
Sharp eyes! :)
So, to
On 12/20/10 1:42 PM, Simon King wrote:
Dear sage-support,
at #10496, David Roe gave me the advice to use PY_TYPE_CHECK rather
than isinstance in Cython files. I did so.
But actually I didn't know PY_TYPE_CHECK at all, and so I have a two
questions:
1) Apparently there are several PY_...
PY_TYPE_CHECK is just a wrapper macro around PyObject_TypeCheck which
dereferences and compares the object type fields. So that part should be
insanely fast.
sage: cython('cpdef t(x):\n for i in range(0,1000):\n
PY_TYPE_CHECK(x,int)'); timeit(t(5000), repeat=100)
625 loops, best of 100:
Aha, with Jason's answer:
Calling isinstance(x,int) on a python x is cheating, because Cython replaces
it with PyInt_Check (no inheritance to check!).
Calling isinstance on a C variable x goes through IS_INSTANCE which builds
an unnecessary python boolean.
--
To post to this group, send
The PY_TYPE_CHECK macro exists primarily because Cython didn't used to
optimize isinstance.
On Mon, Dec 20, 2010 at 12:34 PM, Volker Braun vbraun.n...@gmail.com wrote:
PY_TYPE_CHECK is just a wrapper macro around PyObject_TypeCheck which
dereferences and compares the object type fields. So that
On Mon, Dec 20, 2010 at 12:27 PM, Jason Grout
jason-s...@creativetrax.com wrote:
On 12/20/10 1:42 PM, Simon King wrote:
Dear sage-support,
at #10496, David Roe gave me the advice to use PY_TYPE_CHECK rather
than isinstance in Cython files. I did so.
But actually I didn't know PY_TYPE_CHECK
Dear Volker, dear Jason,
thank you for your answers!
So, I chose the wrong example isinstance(x,int). With other types to
test, PY_TYPE_CHECK will be faster.
@Volker
But if you really write Cython code then you probably want to type the
argument so that the compiler knows what x is.
...
10 matches
Mail list logo