Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Numpy and shedskin
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mark Dewing  
View profile   Translate to Translated (View Original)
 More options May 31 2012, 2:40 am
From: Mark Dewing <markdew...@gmail.com>
Date: Thu, 31 May 2012 01:40:44 -0500
Local: Thurs, May 31 2012 2:40 am
Subject: Numpy and shedskin

I've been looking at using shedskin to translate some code using numpy.  In
this particular example, there is set of particles (in a 2d array) and a
simple computation related to the distance between particles.

There seem to be two issues with infering the type correctly:
 - the 'numpy.array' constructor can be used to create 1d or 2d arrays (or
higher dimensions, but not in this example).  Shedskin can't determine the
correct array type (even though it should have the type information it
needs).
 - slices of 2d arrays can either be a 1d array (single index - a[1]) or a
scalar (index is a tuple - a[1,2])

More generally, it seems there should be some way of conveying this
decision information to shedskin (the stub files don't necessarily work for
the case where the output type of a function requires a decision based on
the input type (?)).

Or have I done something wrong with the numpy stub file?  Both the example
and the numpy stub file are attached.

Mark

  ex1.py
< 1K Download

  numpy.py
1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
srepmub  
View profile  
 More options Jun 2 2012, 7:41 am
From: srepmub <mark.duf...@gmail.com>
Date: Sat, 2 Jun 2012 04:41:57 -0700 (PDT)
Local: Sat, Jun 2 2012 7:41 am
Subject: Re: Numpy and shedskin

hi mark,

indexing and slicing indeed seem the most difficult to support, as the
result in fact depends on both array rank and length of the index tuple..

I'm afraid 'isinstance' and 'len' don't work as expected during the type
inference that shedskin performs, so they can't be used to model this
behaviour.. :P shedskin currently doesn't track the length of things in any
way, which in general even seems impossible (comparable to the halting
problem), and 'isinstance' is in fact not supported at all anymore.
needless to say type inference is very nasty business.

but I guess the 'rank' of the data that goes into array() can be usually
known by shedskin. but we'd have to track things when combining arrays
further probably.. the index tuple forms an even more fundamental problem
perhaps, since we can't know its length beforehand in all cases.
restricting tuples to always be specified by its elements would make the
problem easier, as it would allow shedskin to insert the correct types
during analysis.

I'm sure we'd find other similar problems when trying to add direct support
for numpy. in short, I don't think we want to try and support it directly.
it's quite big and dynamic (in a way that guido himself dislikes - types
being dependent on non-type data essentially). we obviously can't support
every library out there, so perhaps it makes limit ourselves to the python
standard library. other libraries can also often be combined with a
shedskin-compiled extension module (as happens with for example pygame and
pygtk in shedskin/examples).

an alternative approach to integrate with numpy without the performance
loss of having to convert things, and that would probably also be useful in
other areas (the regular 'array' module would be one example) would be to
figure out a simple way to share memory between cpython and shedskin. I've
thought about this a few times, but have not come upon a satisfactory
solution yet..

thanks in any case for having me read through the numpy tutorial.. ;-)
mark.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »