Re: [Tutor] BLAS Implementation on Python

2011-03-25 Thread Mahesh Narayanamurthi
Thank you all for your replies. I wonder why I din't get any updates from the
mailing list. Now I feel I have more reasons to proceed with the implementation.
Only that I don't know where to start :)

Thanks,
Mahesh Narayanamurthi

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BLAS Implementation on Python

2011-03-08 Thread Alan Gauld

Knacktus knack...@googlemail.com wrote

He doesn't have to write it, as it is very obvious, that no Python 
code on earth (even written by Guido himself ;-)) stands a chance 
compared to Fortran or C. Look at this:


There is one big proviso. The C or Fortran needs to be well written
in the first place. It's quite possible to write code in Python that
outperforms badly written C. And it is quite easy to write bad C!

This is similar to the arguments in the 1960's/70's when languages
like C first appeared. The assembler programmers all said you'd
never replace assembler with C because assembler was an
order of magnitude faster (and smaller because size mattered then!).
But that was only true of well optimised assembler. Nowadays
speed is hardly ever used as a reason for using assembler.

Now the case between interpreted and compiled languages is
slightly different, but as python compilers emerge the gap will
continue to narrow. Will Python ever challenge C/assembler?
Probably not in the low level domain but where we are talking
about implementing complex algorithms it may well do.
But its a long way off just now and if you need speed
selectively rewriting in C is still the best bet. The skill is
in selecting the bits to optimise.  But a pure Python
implementation will benefit from any improvements
that are made going forward without significant rework.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BLAS Implementation on Python

2011-03-08 Thread Stefan Behnel

Alan Gauld, 08.03.2011 09:51:

Knacktus wrote


He doesn't have to write it, as it is very obvious, that no Python code
on earth (even written by Guido himself ;-)) stands a chance compared to
Fortran or C. Look at this:


There is one big proviso. The C or Fortran needs to be well written
in the first place. It's quite possible to write code in Python that
outperforms badly written C. And it is quite easy to write bad C!


It's seriously hard to write computational Python code that is faster than 
C code, though. It shifts a bit if you can take advantage of Python's 
dynamic container types, especially dicts, but that's rarely the case for 
mathematic computation code, which would usually deploy NumPy etc. in 
Python. Writing that in pure Python is bound to be incredibly slow, and 
likely still several hundred times slower than even a simple approach in C. 
There's a reason people use NumPy, C, Fortran and Cython for these things.


Remember that the OP's topic was a BLAS implementation. The BLAS libraries 
are incredibly well optimised for all sorts of platforms, including GPUs. 
They are building blocks that C programmers can basically just plug into 
their code to run hugely fast computations. There is no way Python code 
will ever be able to get any close to that.


Stefan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BLAS Implementation on Python

2011-03-08 Thread Alan Gauld


Stefan Behnel stefan...@behnel.de wrote
He doesn't have to write it, as it is very obvious, that no Python 
code
on earth (even written by Guido himself ;-)) stands a chance 
compared to

Fortran or C. Look at this:


There is one big proviso. The C or Fortran needs to be well written


It's seriously hard to write computational Python code that is 
faster than C code, though.


Agreed, it was the assertion that no Python code on earth...stands
a chance... that I was objecting to.

There are many areas where the C code would have to be pathologically
bad to be beaten by Python, but there are plenty of places where only
slightly inefficient C code can be competitive relatie to Python.

Alan G. 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BLAS Implementation on Python

2011-03-08 Thread Knacktus

Am 08.03.2011 20:00, schrieb Alan Gauld:


Stefan Behnel stefan...@behnel.de wrote

He doesn't have to write it, as it is very obvious, that no Python code
on earth (even written by Guido himself ;-)) stands a chance
compared to
Fortran or C. Look at this:


There is one big proviso. The C or Fortran needs to be well written


It's seriously hard to write computational Python code that is faster
than C code, though.


Agreed, it was the assertion that no Python code on earth...stands
a chance... that I was objecting to.

There are many areas where the C code would have to be pathologically
bad to be beaten by Python, but there are plenty of places where only
slightly inefficient C code can be competitive relatie to Python.


Maybe there're those areas, but the top posters question is about 
reimplementing BLAS, which is a highly optimized package for linear 
algebra. And in this area no pure Python code on earth on any currently 
available Python implementation stands a chance performance wise to one 
of the C or Fortran implementations.




Alan G.

___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BLAS Implementation on Python

2011-03-07 Thread Stefan Behnel

Mahesh Narayanamurthi, 07.03.2011 01:50:

I am thinking of implementing a BLAS package in pure python. I am wondering
if this is a good idea. My design goals are:

[1] Efficient manipulation of Matrices and
 Vectors using pure python objects and
 python code.
[2] Targetted to run on Python3
[3] Extensive use of defensive programming
 style
[4] To serve as a reference design for
 future High Performance Code in Python
[5] To serve as a reference material in
 classroom courses on numerical computing
 or for hobbyist programmers


First question that comes to my mind: who would use this? The available 
packages are commonly not written in Python, but they are fast, which is 
why they are being used by Python programs. A quick web search brought up 
Tokyo, for example, which wraps BLAS in Cython:


https://github.com/tokyo/tokyo

I can see that it would be easier to teach the concepts based on code 
written in Python than based on the existing implementations. Even if there 
likely won't be a real use case, it may still be nice to have a pure Python 
implementation available, if it could serve as a drop-in replacement for 
faster implementations. I.e., you could present the inner workings based on 
the Python code, and then switch to a 'real' implementation for the actual 
computations.


However, even if you say efficient above (and the algorithms may well be 
efficient), don't expect it to be fast. Python is great for orchestrating 
high performance computations. It's less great for doing them in plain 
Python code.


Stefan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BLAS Implementation on Python

2011-03-07 Thread Knacktus

Am 07.03.2011 01:50, schrieb Mahesh Narayanamurthi:

Hello,

I am thinking of implementing a BLAS package in pure python. I am
wondering if this is a good idea.


I don't think so. Usually people write extensions to the CPython 
implementation (when talking about performance, we need to talk about 
Python implementations like CPython, Jython or PyPy) in C to do high 
performance stuff. Pure CPython is (depeneding on the problem) 
magnitudes slower than C.


Also, there's NumPy SciPy. Check those out.

More comments below ...

My design goals are:



[1] Efficient manipulation of Matrices and
 Vectors using pure python objects and
 python code.

No, not efficient in terms of performance.

[2] Targetted to run on Python3

Good idea. NumPy and SciPy will be (are already?) ported.

[3] Extensive use of defensive programming
 style
[4] To serve as a reference design for
 future High Performance Code in Python

The future of High Performance Python is probably PyPy.

[5] To serve as a reference material in
 classroom courses on numerical computing
 or for hobbyist programmers

Good idea, as Python is clear and nice to read.


Thanks,
Mahesh Narayanamurthi



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BLAS Implementation on Python

2011-03-07 Thread Stefan Behnel

Knacktus, 07.03.2011 14:28:

Am 07.03.2011 01:50, schrieb Mahesh Narayanamurthi:

Hello,

I am thinking of implementing a BLAS package in pure python. I am
wondering if this is a good idea.


My design goals are:


[2] Targetted to run on Python3

Good idea. NumPy and SciPy will be (are already?) ported.


Yes, NumPy has been ported as of version 1.5. Not sure about the overall 
status of SciPy, their FAQ isn't up to date.




[4] To serve as a reference design for
future High Performance Code in Python

The future of High Performance Python is probably PyPy.


PyPy has been the future ever since they started ;-). They have gotten 
faster, but it's is still far from being suitable for any kind of numerical 
high performance computing. That will continue to be the domain of C, 
Fortran and Cython for a while, and potentially including LuaJIT2 for 
certain use cases (usable from Python through Lupa, BTW).


Stefan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BLAS Implementation on Python

2011-03-07 Thread Steven D'Aprano
On Tue, 8 Mar 2011 12:28:56 am Knacktus wrote:
 Am 07.03.2011 01:50, schrieb Mahesh Narayanamurthi:
  Hello,
 
  I am thinking of implementing a BLAS package in pure python. I am
  wondering if this is a good idea.

Sure, why not? Even if nobody uses it, it looks good on a resume and you 
will hopefully learn a lot.


 I don't think so. Usually people write extensions to the CPython
 implementation (when talking about performance, we need to talk about
 Python implementations like CPython, Jython or PyPy) in C to do high
 performance stuff. Pure CPython is (depeneding on the problem)
 magnitudes slower than C.

Typical pure Python code is between 10 and 100 times slower than C, but 
talking about implementations, it is the aim of the PyPy project to use 
Just In Time compilation and clever optimizations to meet *and exceed* 
the speed of static C compilers. In just a few years, with a handful of 
people working on it, and a tiny grant from the EU, they have already 
doubled the speed of CPython. If PyPy could get *half* the love and 
attention that CPython gets, who knows what they could accomplish?

(If only Google had thrown some work into PyPy, instead of wasting time 
with Unladen Swallow that never went anywhere useful...)

But the beauty of Python is that if a piece of code is too slow, you can 
rip it out into an extension written in C or Fortran while keeping the 
rest of the library in Python. See, for example, the re module, which 
has a front end written in Python and the regex engine in C.

The itertools module is another good example. Using a few primitives 
written in C, itertools allows Python code to run efficiently and 
quickly.


 Also, there's NumPy SciPy. Check those out.

 More comments below ...

 My design goals are:
  [1] Efficient manipulation of Matrices and
   Vectors using pure python objects and
   python code.

 No, not efficient in terms of performance.

How do you know how efficient his code will be before he's even written 
it?

[...]
 The future of High Performance Python is probably PyPy.

Exactly why a pure-Python library *may* be useful. Today it will be 
slow, running under CPython, but in five (unlikely) or ten years 
(possibly), it may be fast, running under PyPy.

Or not. Who can tell what the future will bring?


-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BLAS Implementation on Python

2011-03-07 Thread Knacktus

Am 07.03.2011 22:44, schrieb Steven D'Aprano:

On Tue, 8 Mar 2011 12:28:56 am Knacktus wrote:

Am 07.03.2011 01:50, schrieb Mahesh Narayanamurthi:

Hello,

I am thinking of implementing a BLAS package in pure python. I am
wondering if this is a good idea.


Sure, why not? Even if nobody uses it, it looks good on a resume and you
will hopefully learn a lot.



I don't think so. Usually people write extensions to the CPython
implementation (when talking about performance, we need to talk about
Python implementations like CPython, Jython or PyPy) in C to do high
performance stuff. Pure CPython is (depeneding on the problem)
magnitudes slower than C.


Typical pure Python code is between 10 and 100 times slower than C, but
talking about implementations, it is the aim of the PyPy project to use
Just In Time compilation and clever optimizations to meet *and exceed*
the speed of static C compilers. In just a few years, with a handful of
people working on it, and a tiny grant from the EU, they have already
doubled the speed of CPython. If PyPy could get *half* the love and
attention that CPython gets, who knows what they could accomplish?

(If only Google had thrown some work into PyPy, instead of wasting time
with Unladen Swallow that never went anywhere useful...)

But the beauty of Python is that if a piece of code is too slow, you can
rip it out into an extension written in C or Fortran while keeping the
rest of the library in Python. See, for example, the re module, which
has a front end written in Python and the regex engine in C.

The itertools module is another good example. Using a few primitives
written in C, itertools allows Python code to run efficiently and
quickly.



Also, there's NumPy SciPy. Check those out.

More comments below ...

My design goals are:

[1] Efficient manipulation of Matrices and
  Vectors using pure python objects and
  python code.


No, not efficient in terms of performance.


How do you know how efficient his code will be before he's even written
it?


He doesn't have to write it, as it is very obvious, that no Python code 
on earth (even written by Guido himself ;-)) stands a chance compared to 
Fortran or C. Look at this:


http://shootout.alioth.debian.org/u32/performance.php?test=spectralnorm

CPython implementation runs 12 mins compared to 8 secs of a Fortran 
implementation. PyPy is about 100 secs, which is remarkable but still 
far off.




[...]

The future of High Performance Python is probably PyPy.


Exactly why a pure-Python library *may* be useful. Today it will be
slow, running under CPython, but in five (unlikely) or ten years
(possibly), it may be fast, running under PyPy.

Or not. Who can tell what the future will bring?




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor