Robert Bradshaw wrote:
> Currently the way to do numerics in Sage is to import scipy and numpy  
> (because they really have created a good stack), and turn off  
> preparsing (because those type issues get really annoying). At this  
> point, it may become unclear why one is using Sage instead of the  
> SciPy stack itself. The fact that most Sage examples and discussion  
> revolves around "esoteric" things like Rings and Categories and  
> Modular Forms just promotes this view.
> 
> Dag, if you put together a list of why Sage isn't good enough for  
> you, that would be very interesting. I wonder if many things on that  
> list would be desirable for non-numerical use as well.

It's dangerous to ask this of me -- it's roughly in order of priority so 
feel free to stop when you got what you wanted :- )

(Any of this might have been changed recently, I haven't upgraded for a 
while to be honest).

The minimum to make me start using Sage:

1) I must be able to use NumPy together with the preparser (it's just 
too much hassle to turn it on and off, and it kind of defeats the 
purpose.). That is, with the preparser on, I should be able to run most 
NumPy-using code without changes. (I don't think is a difficult to 
achieve, but certainly didn't look at it in detail.)

One example is:

sage: np.arange(4)
array([0, 1, 2, 3], dtype=object)

This is not what I want, and I can never remember to pass in 
dtype=np.int64. I don't think it makes sense either -- passing in 
np.arange(int(4)) gives the desired behaviour, and a Python int and a 
Sage Integer are equally far from an np.int64 anyway.


I think that's all, actually -- this would stop Sage from getting in my 
way. But this is on my strongly wanted-list too:

2) sin, sqrt etc. should understand, act on, and return NumPy arrays 
(probably by calling corresponding functions in numpy)

3) It would be nice with better plotting support for NumPy arrays, so 
that I don't have to use pylab directly, but haven't given any thought 
to what I want here.

4) Not sure if this can be done in a reasonable way, but: I'd like to 
not have to use Python ints/floats at all, it's just nicer to know that 
I have a Sage element. So ideally

sage: a=np.arange(5, dtype=np.uint8)
sage: a[2]/a[4]
1/2

5) #4571 (cimport numpy in notebook), obviously.

6) One of the things drawing me towards using Sage is the "attach" 
feature. However, it is too limited for my use (and so makes me 
frustrated, so that it is better not to use it at all). Something being 
a combination for an "attach" and a pure Python "import" is what I want; 
that is, "import" with automatically calling "reload" on change. (The 
recent work in pyximport may come into play here; if the sources are in 
Cython.)

7) Make NumPy dtypes for all Sage rings. I think that NumPy is quite 
extensible in this respect and that it shouldn't be too difficult to 
have arrays over Sage rings.

sage: a = np.arange(10, dtype=ZZ.numpy()) # or dtype=ZZ if possible

8) For syntax consistency etc., a simple function to create SIMD arrays.

sage: x = array(RDF, 20, 20, 20) # 20x20x20 array

Whether a wrapper is returned or a raw NumPy array, it is important to 
have elementwise operators and allow slices. Whether a slice should be a 
view, a copy, or sometimes a view and sometimes a copy (like in NumPy 
:-( ) seems to be debatable here though.

9) Long-term, linear algebra in a data processing context Done Right 
(According To Myself). I.e.:

sage: parent(img)
Array of shape (100, 100, 3) over uint8
sage: parent(weights)
Array of shape (100, 100, 3) over Real Double Field

Now, componentwise multiply the two the proper way; treating img as a 
vector and the reweighting as an operator matrix:

sage: op = diagonal_matrix(weights); parent(op)
Diagonal MatrixSpace of (100, 100, 3) by (100, 100, 3) matrices
over Real Double Field

Access as six-dimensional array; first three indices is the row, the 
next three indices the column:

sage: op[1,2,3,4,5,6]
0.5

sage: result = op * vector(img)
sage: result
Vector space of dimension (100, 100, 3) over uint8

(Here, * is the linear algebra *, while result contains the elementwise 
product of weights and img).

-- 
Dag Sverre

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to