SourceForge logo
SourceForge logo
Menu

matplotlib-devel — matplotlib developers

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
(1)
Nov
(33)
Dec
(20)
2004 Jan
(7)
Feb
(44)
Mar
(51)
Apr
(43)
May
(43)
Jun
(36)
Jul
(61)
Aug
(44)
Sep
(25)
Oct
(82)
Nov
(97)
Dec
(47)
2005 Jan
(77)
Feb
(143)
Mar
(42)
Apr
(31)
May
(93)
Jun
(93)
Jul
(35)
Aug
(78)
Sep
(56)
Oct
(44)
Nov
(72)
Dec
(75)
2006 Jan
(116)
Feb
(99)
Mar
(181)
Apr
(171)
May
(112)
Jun
(86)
Jul
(91)
Aug
(111)
Sep
(77)
Oct
(72)
Nov
(57)
Dec
(51)
2007 Jan
(64)
Feb
(116)
Mar
(70)
Apr
(74)
May
(53)
Jun
(40)
Jul
(519)
Aug
(151)
Sep
(132)
Oct
(74)
Nov
(282)
Dec
(190)
2008 Jan
(141)
Feb
(67)
Mar
(69)
Apr
(96)
May
(227)
Jun
(404)
Jul
(399)
Aug
(96)
Sep
(120)
Oct
(205)
Nov
(126)
Dec
(261)
2009 Jan
(136)
Feb
(136)
Mar
(119)
Apr
(124)
May
(155)
Jun
(98)
Jul
(136)
Aug
(292)
Sep
(174)
Oct
(126)
Nov
(126)
Dec
(79)
2010 Jan
(109)
Feb
(83)
Mar
(139)
Apr
(91)
May
(79)
Jun
(164)
Jul
(184)
Aug
(146)
Sep
(163)
Oct
(128)
Nov
(70)
Dec
(73)
2011 Jan
(235)
Feb
(165)
Mar
(147)
Apr
(86)
May
(74)
Jun
(118)
Jul
(65)
Aug
(75)
Sep
(162)
Oct
(94)
Nov
(48)
Dec
(44)
2012 Jan
(49)
Feb
(40)
Mar
(88)
Apr
(35)
May
(52)
Jun
(69)
Jul
(90)
Aug
(123)
Sep
(112)
Oct
(120)
Nov
(105)
Dec
(116)
2013 Jan
(76)
Feb
(26)
Mar
(78)
Apr
(43)
May
(61)
Jun
(53)
Jul
(147)
Aug
(85)
Sep
(83)
Oct
(122)
Nov
(18)
Dec
(27)
2014 Jan
(58)
Feb
(25)
Mar
(49)
Apr
(17)
May
(29)
Jun
(39)
Jul
(53)
Aug
(52)
Sep
(35)
Oct
(47)
Nov
(110)
Dec
(27)
2015 Jan
(50)
Feb
(93)
Mar
(96)
Apr
(30)
May
(55)
Jun
(83)
Jul
(44)
Aug
(8)
Sep
(5)
Oct
Nov
(1)
Dec
(1)
2016 Jan
Feb
Mar
(1)
Apr
May
Jun
(2)
Jul
Aug
(3)
Sep
(1)
Oct
(3)
Nov
Dec
2017 Jan
Feb
(5)
Mar
Apr
May
Jun
Jul
(3)
Aug
Sep
(7)
Oct
Nov
Dec
2018 Jan
Feb
Mar
Apr
May
Jun
Jul
(2)
Aug
Sep
Oct
Nov
Dec
S M T W T F S






1
(13)
2
(2)
3
(9)
4
(16)
5
(3)
6
(4)
7
(2)
8
(1)
9
10
(7)
11
(8)
12
(9)
13
14
(4)
15
(5)
16
(7)
17
(12)
18
19
(1)
20
21
22
(3)
23
(2)
24
(2)
25
26
27
(2)
28
29
(4)
30
31





Showing 16 results of 16

From: Eric F. <ef...@ha...> - 2012年12月04日 22:32:46
On 2012年12月04日 12:07 PM, Damon McDougall wrote:
> On Mon, Dec 3, 2012 at 12:12 PM, Chris Barker - NOAA Federal
> <chr...@no...> wrote:
>> generated code is ugly and hard to maintain, it is not designed to be
>> human-readable, and we wouldn't get the advantages of bug-fixes
>> further development in Cython.
>
> As far as I'm concerned, this is an argument against Cython.
Nonsense. It is an argument against the idea of maintaining the 
generated code directly, rather than maintaining the cython source code 
and regenerating the C code as needed. That idea never made any sense 
in the first place. I doubt that anyone follows it. Chris already 
pointed this out. Would you maintain the assembly code generated by 
your C++ compiler? Do you consider the fact that this is unreadable and 
unmaintainable a reason to avoid using that compiler, and instead to 
code directly in assembly?
>
> I've had to touch the C/C++/ObjC codebase. It was not automatically
> generated by Cython and it's not that hard to read. There's almost
> certainly a C/C++/ObjC expert around to help out. There's almost
> certainly Cython experts to help out, too. There is almost certainly
> *not* an expert in Cython-generated C code that is hard to read.
>
There doesn't need to be.
> I vote raw Python/C API. Managing reference counters is not the
> mundane task pythonistas make it out to be, in my opinion. If you know
> ObjC, you've had to do your own reference counting. If you know C,
> you've had to do your own memory management. If you know C++, you've
> had to do your own new/delete (or destructor) management. I agree not
> having to worry about reference counting is nice positive, but I don't
> think it outweighs the negatives.
You have completely misrepresented the negatives.
>
> It seems to me that Cython is a 'middle-man' tool, with the added
> downside of hard-to-maintain under-code.
>
Please, if you don't use Cython yourself, and therefore don't know it 
well, refrain from these sorts of criticisms. In normal cython use, one 
*never* modifies the code it generates. In developing with cython, one 
*might* read this code to find out what is going on, and especially to 
find out whether one inadvertently triggered a call to the python API by 
forgetting to declare a variable, for example. This is pretty easy, 
because the comments in the generated code show exactly which source 
line has generated each chunk of generated code. Context is included. 
It is very nicely done.
Eric
From: Ryan M. <rm...@gm...> - 2012年12月04日 22:20:26
On Tue, Dec 4, 2012 at 4:07 PM, Damon McDougall
<dam...@gm...>wrote:
> On Mon, Dec 3, 2012 at 12:12 PM, Chris Barker - NOAA Federal
> <chr...@no...> wrote:
> > generated code is ugly and hard to maintain, it is not designed to be
> > human-readable, and we wouldn't get the advantages of bug-fixes
> > further development in Cython.
>
> As far as I'm concerned, this is an argument against Cython.
>
> I've had to touch the C/C++/ObjC codebase. It was not automatically
> generated by Cython and it's not that hard to read. There's almost
> certainly a C/C++/ObjC expert around to help out. There's almost
> certainly Cython experts to help out, too. There is almost certainly
> *not* an expert in Cython-generated C code that is hard to read.
>
You've had to touch the C/C++/ObjC because that's the only source that
exists; in this case that's the C *is* the implementation of the wrapper.
 If we go Cython, the cython source is all that is maintained. It may be
useful to glance at generated code, but no-one should be tweaking it by
hand--the Cython source, and only the Cython source, represents the
implementation of the wrapper.
Ryan
-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
From: Damon M. <dam...@gm...> - 2012年12月04日 22:07:58
On Mon, Dec 3, 2012 at 12:12 PM, Chris Barker - NOAA Federal
<chr...@no...> wrote:
> generated code is ugly and hard to maintain, it is not designed to be
> human-readable, and we wouldn't get the advantages of bug-fixes
> further development in Cython.
As far as I'm concerned, this is an argument against Cython.
I've had to touch the C/C++/ObjC codebase. It was not automatically
generated by Cython and it's not that hard to read. There's almost
certainly a C/C++/ObjC expert around to help out. There's almost
certainly Cython experts to help out, too. There is almost certainly
*not* an expert in Cython-generated C code that is hard to read.
I vote raw Python/C API. Managing reference counters is not the
mundane task pythonistas make it out to be, in my opinion. If you know
ObjC, you've had to do your own reference counting. If you know C,
you've had to do your own memory management. If you know C++, you've
had to do your own new/delete (or destructor) management. I agree not
having to worry about reference counting is nice positive, but I don't
think it outweighs the negatives.
It seems to me that Cython is a 'middle-man' tool, with the added
downside of hard-to-maintain under-code.
-- 
Damon McDougall
http://www.damon-is-a-geek.com
Institute for Computational Engineering Sciences
201 E. 24th St.
Stop C0200
The University of Texas at Austin
Austin, TX 78712-1229
From: Benjamin R. <ben...@ou...> - 2012年12月04日 18:21:01
On Tue, Dec 4, 2012 at 1:10 PM, Michael Droettboom <md...@st...> wrote:
> I think I see what's happened. I accidentally committed a #define in
> there when I was experimenting last week with removing deprecated Numpy
> APIs. It didn't cause things to break for me, but it looks like it could
> break things for more recent Numpy's. I've just gone ahead and reverted my
> change. Let me know if that fixes things for you when you get a chance.
>
> Cheers,
> Mike
>
>
Looks like that was the problem. The build is now successful.
Thanks!
Ben Root
From: Michael D. <md...@st...> - 2012年12月04日 18:10:33
I think I see what's happened. I accidentally committed a #define in 
there when I was experimenting last week with removing deprecated Numpy 
APIs. It didn't cause things to break for me, but it looks like it 
could break things for more recent Numpy's. I've just gone ahead and 
reverted my change. Let me know if that fixes things for you when you 
get a chance.
Cheers,
Mike
On 12/04/2012 10:50 AM, Benjamin Root wrote:
>
>
> On Tue, Dec 4, 2012 at 10:43 AM, Michael Droettboom <md...@st... 
> <mailto:md...@st...>> wrote:
>
> It looks like we're using the "old" Numpy API there. Did you
> recently update Numpy by any chance? I hadn't realised these APIs
> had been turned off yet, but maybe they are in git master. In any
> event, we should update these to the new APIs (NPY_UBYTE instead
> of PyArray_UBYTE etc.).
>
> Cheers,
> Mike
>
>
> Not since Nov. 5th (which was a fix for a bug I reported in numpy 
> master. So, I was using numpy 1.8.0 dev branch.
>
> Cheers!
> Ben Root
>
From: Benjamin R. <ben...@ou...> - 2012年12月04日 15:51:12
On Tue, Dec 4, 2012 at 10:43 AM, Michael Droettboom <md...@st...> wrote:
> It looks like we're using the "old" Numpy API there. Did you recently
> update Numpy by any chance? I hadn't realised these APIs had been turned
> off yet, but maybe they are in git master. In any event, we should update
> these to the new APIs (NPY_UBYTE instead of PyArray_UBYTE etc.).
>
> Cheers,
> Mike
>
>
Not since Nov. 5th (which was a fix for a bug I reported in numpy master.
So, I was using numpy 1.8.0 dev branch.
Cheers!
Ben Root
From: Michael D. <md...@st...> - 2012年12月04日 15:43:53
It looks like we're using the "old" Numpy API there. Did you recently 
update Numpy by any chance? I hadn't realised these APIs had been 
turned off yet, but maybe they are in git master. In any event, we 
should update these to the new APIs (NPY_UBYTE instead of PyArray_UBYTE 
etc.).
Cheers,
Mike
On 12/04/2012 09:46 AM, Benjamin Root wrote:
> I can't seem to build v1.2.x branch right now on CentOS6. This has 
> not been a problem before. I get the following error message while 
> trying to build the freetype2 stuff:
>
> creating build/temp.linux-x86_64-2.7/CXX
> gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall 
> -fPIC -DPY_ARRAY_UNIQUE_SYMBOL=MPL_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 
> -I/usr/local/include -I/usr/include 
> -I/nas/home/broot/centos6/lib/python2.7/site-packages/numpy/core/include 
> -I/usr/include/freetype2 -I/usr/local/include -I/usr/include -I. 
> -I/home/broot/.local_centos6/include/python2.7 -c src/ft2font.cpp -o 
> build/temp.linux-x86_64-2.7/src/ft2font.o
> src/ft2font.cpp: In member function 'Py::Object 
> FT2Image::py_as_array(const Py::Tuple&)':
> src/ft2font.cpp:388: error: 'PyArray_UBYTE' was not declared in this scope
> src/ft2font.cpp: In member function 'Py::Object FT2Font::get_path()':
> src/ft2font.cpp:626: error: 'PyArray_DOUBLE' was not declared in this 
> scope
> src/ft2font.cpp:632: error: 'PyArray_UINT8' was not declared in this scope
> error: command 'gcc' failed with exit status 1
>
>
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
>
>
> _______________________________________________
> Matplotlib-devel mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
From: Benjamin R. <ben...@ou...> - 2012年12月04日 14:47:19
I can't seem to build v1.2.x branch right now on CentOS6. This has not
been a problem before. I get the following error message while trying to
build the freetype2 stuff:
creating build/temp.linux-x86_64-2.7/CXX
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall
-fPIC -DPY_ARRAY_UNIQUE_SYMBOL=MPL_ARRAY_API -DPYCXX_ISO_CPP_LIB=1
-I/usr/local/include -I/usr/include
-I/nas/home/broot/centos6/lib/python2.7/site-packages/numpy/core/include
-I/usr/include/freetype2 -I/usr/local/include -I/usr/include -I.
-I/home/broot/.local_centos6/include/python2.7 -c src/ft2font.cpp -o
build/temp.linux-x86_64-2.7/src/ft2font.o
src/ft2font.cpp: In member function ‘Py::Object FT2Image::py_as_array(const
Py::Tuple&)’:
src/ft2font.cpp:388: error: ‘PyArray_UBYTE’ was not declared in this scope
src/ft2font.cpp: In member function ‘Py::Object FT2Font::get_path()’:
src/ft2font.cpp:626: error: ‘PyArray_DOUBLE’ was not declared in this scope
src/ft2font.cpp:632: error: ‘PyArray_UINT8’ was not declared in this scope
error: command 'gcc' failed with exit status 1
From: Michael D. <md...@st...> - 2012年12月04日 13:52:47
Also -- this feedback is really helpful when writing some comments in 
the wrappers as to why certain things are the way they are... I'll make 
sure to include rationales for raw file fast path and the need to open 
the files on the Python side.
Mike
On 12/04/2012 08:45 AM, Michael Droettboom wrote:
> On 12/03/2012 08:01 PM, Chris Barker - NOAA Federal wrote:
>> On Mon, Dec 3, 2012 at 4:16 PM, Nathaniel Smith <nj...@po...> wrote:
>>
>>> Yeah, this is a general problem with the Python file API, trying to
>>> hook it up to stdio is not at all an easy thing. A better version of
>>> this code would skip that altogether like:
>>>
>>> cdef void write_to_pyfile(png_structp s, png_bytep data, png_size_t count):
>>> fobj = <object>png_get_io_ptr(s)
>>> pydata = PyString_FromStringAndSize(data, count)
>>> fobj.write(pydata)
>> Good point -- not at all Cython-specific, but do you need libpng (or
>> whatever) to write to the file? can you just get a buffer with the
>> encoded data and write it on the Python side? Particularly if the user
>> wants to pass in an open file object. This might be a better API for
>> folks that might want stream an image right through a web app, too.
> You need to support both: raw C FILE objects for speed, and writing to a
> Python file-like object for flexibility. The code in master already
> does this (albeit with PyCXX), and the code on my "No CXX" branch does
> this as well with Cython.
>> As a lot of Python APIs take either a file name or a file-like object,
>> perhaps it would make sense to push that distinction down to the
>> Cython level:
>> -- if it's a filename, open it with raw C
> Unfortunately, as stated in detail in my last e-mail, that doesn't work
> with Unicode paths.
>
>> -- if it's a file-like object, have libpng write to a buffer (bytes
>> object) , and pass that to the file-like object in Python
> libpng does one better and allows us to stream directly to a callback
> which can then write to a Python object. This prevents double
> allocation of memory.
>
>> anyway, not really a Cython issue, but that second object sure would
>> be easy on Cython....
>>
> Yeah -- once I figured out how to make a real C callback function from
> Cython, the contents of the callback function itself is pretty easy to
> write.
>
> Mike
>
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> _______________________________________________
> Matplotlib-devel mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
From: Michael D. <md...@st...> - 2012年12月04日 13:46:02
On 12/03/2012 08:01 PM, Chris Barker - NOAA Federal wrote:
> On Mon, Dec 3, 2012 at 4:16 PM, Nathaniel Smith <nj...@po...> wrote:
>
>> Yeah, this is a general problem with the Python file API, trying to
>> hook it up to stdio is not at all an easy thing. A better version of
>> this code would skip that altogether like:
>>
>> cdef void write_to_pyfile(png_structp s, png_bytep data, png_size_t count):
>> fobj = <object>png_get_io_ptr(s)
>> pydata = PyString_FromStringAndSize(data, count)
>> fobj.write(pydata)
> Good point -- not at all Cython-specific, but do you need libpng (or
> whatever) to write to the file? can you just get a buffer with the
> encoded data and write it on the Python side? Particularly if the user
> wants to pass in an open file object. This might be a better API for
> folks that might want stream an image right through a web app, too.
You need to support both: raw C FILE objects for speed, and writing to a 
Python file-like object for flexibility. The code in master already 
does this (albeit with PyCXX), and the code on my "No CXX" branch does 
this as well with Cython.
>
> As a lot of Python APIs take either a file name or a file-like object,
> perhaps it would make sense to push that distinction down to the
> Cython level:
> -- if it's a filename, open it with raw C
Unfortunately, as stated in detail in my last e-mail, that doesn't work 
with Unicode paths.
> -- if it's a file-like object, have libpng write to a buffer (bytes
> object) , and pass that to the file-like object in Python
libpng does one better and allows us to stream directly to a callback 
which can then write to a Python object. This prevents double 
allocation of memory.
>
> anyway, not really a Cython issue, but that second object sure would
> be easy on Cython....
>
Yeah -- once I figured out how to make a real C callback function from 
Cython, the contents of the callback function itself is pretty easy to 
write.
Mike
From: Michael D. <md...@st...> - 2012年12月04日 13:43:58
On 12/03/2012 07:16 PM, Nathaniel Smith wrote:
> On Mon, Dec 3, 2012 at 11:50 PM, Chris Barker - NOAA Federal
> <chr...@no...> wrote:
>> On Mon, Dec 3, 2012 at 2:21 PM, Nathaniel Smith <nj...@po...> wrote:
>>> For the file handle, I would just write
>>>
>>> cdef FILE *fp = fdopen(file_obj.fileno(), "w")
>>>
>>> and be done with it. This will work with any version of Python etc.
>> yeah, that makes sense -- though what if you want to be able to
>> read_to/write_from a file that is already open, and in the middle of
>> the file somewhere -- would that work?
>>
>> I just posted a question to the Cython list, and indeed, it looks like
>> there is no easy answer to the file issue.
> Yeah, this is a general problem with the Python file API, trying to
> hook it up to stdio is not at all an easy thing. A better version of
> this code would skip that altogether like:
>
> cdef void write_to_pyfile(png_structp s, png_bytep data, png_size_t count):
> fobj = <object>png_get_io_ptr(s)
> pydata = PyString_FromStringAndSize(data, count)
> fobj.write(pydata)
>
> cdef void flush_pyfile(png_structp s):
> # Not sure if this is even needed
> fobj = <object>png_get_io_ptr(s)
> fobj.flush()
>
> # in write_png:
> write_png_c(<png_byte*>pix_buffer, width, height,
> NULL, <void*>file_obj, write_to_pyfile, flush_pyfile, dpi)
This is what my original version already does in the event that the 
file_obj is not a "real" file. In practice, you need to support both 
methods -- the callback approach is many times slower than writing 
directly to a regular old FILE object, because there is overhead both at 
the libpng and Python level, and there's no way to select a good buffer 
size.
>
> But this is a separate issue :-) (and needs further fiddling to make
> exception handling work).
>
> Or if you're only going to work on real OS-level file objects anyway,
> you might as well just accept a filename as a string and fopen() it
> locally. Having Python do the fopen just makes your life harder for no
> reason.
There's actually a very good reason. It is difficult to deal with 
Unicode in file paths from C in a portable way. On Windows, for 
example, if the user's name contains non-ascii characters, you can't 
write to the home directory using fopen, etc. It's doable with some 
care by using platform-specific C APIs etc., but CPython has already 
done all of the hard work for us, so it's easiest just to leverage that 
by opening the file from Python.
Mike
From: Michael D. <md...@st...> - 2012年12月04日 13:37:32
On 12/03/2012 07:00 PM, Chris Barker - NOAA Federal wrote:
> On Mon, Dec 3, 2012 at 12:24 PM, Chris Barker - NOAA Federal
> <chr...@no...> wrote:
>
>>>>> but some of that complexity could be reduced by using Numpy arrays in place
>>> It would at least make this a more fair comparison to have the Cython
>>> code as Cythonic as possible. However, I couldn't find any ways around
>>> using these particular APIs -- other than the Numpy stuff which probably
>>> does have a more elegant solution in the form of Cython arrays and
>>> memory views.
> OK -- so I poked at it, and this is my (very untested) version of
> write_png (I left out the py3 stuff, though it does look like it may
> be required for file handling...
>
> Letting Cython unpack the numpy array is the real win. Maybe having it
> this simple won't work for MPL, but this is what my code tends to look
> like.
>
>
> def write_png(cnp.ndarray[cnp.uint32, ndim=2, mode="c" ] buff not None,
> file_obj,
> double dpi=0.0):
>
> cdef png_uint_32 width = buff.size[0]
> cdef png_uint_32 height = buff.size[1]
>
> if PyFile_CheckExact(file_obj):
> cdef FILE *fp = fdopen(file_obj.fileno(), "w")
> fp = PyFile_AsFile(file_obj)
> write_png_c(buff[0,0], width, height, fp,
> NULL, NULL, NULL, dpi)
> return
> else:
> raise TypeError("write_png only works with real PyFileObject")
>
>
> NOTE: that could be:
>
> cnp.ndarray[cnp.uint8, ndim=3, mode="c" ]
>
> I'm not sure how MPL stores image buffers.
>
> or you could accept any object, then call:
>
> np.view()
The buffer comes in both ways, so the latter solution seems like the 
thing to do.
Thanks for working this through. This sort of thing is very helpful.
We can also, of course, maintain the existing code that allows writing 
to an arbitrary file-like object, but this fast path (where it is a 
"real" file) is very important. It's significantly faster than calling 
methods on Python objects.
Mike
From: Eric F. <ef...@ha...> - 2012年12月04日 03:41:52
On 2012年12月03日 4:54 AM, Michael Droettboom wrote:
> I think Cython is well suited to writing new algorithmic code to speed
> up hot spots in Python code. I don't think it's as well suited as glue
> between C and Python -- that was not a main goal of the original Pyrex
> project, IIRC. It feels kind of tacked on and not a very good fit to
> the problem.
Not entirely relevant to the PyCXX discussion, but to avoid misleading 
others reading this discussion, I must strongly disagree with your 
assertion about Cython's usefulness for wrapping C libraries or small 
chunks of C. I think this has always been a primary function of Cython 
and Pyrex, as far back as I have been aware of them. I wrote the raw 
interface to our contouring code, and I have written cython interfaces 
to various chunks of C outside of mpl; and cython makes it much easier 
for a non-professional programmer such as myself. So I am not arguing 
that Cython should be the choice for removing PyCXX, but for 
non-wizards, it can work very well as glue. It is much more 
approachable than any alternative of which I am aware. For Fortran, of 
course, f2py plays this glue code generation role.
Eric
From: Chris B. - N. F. <chr...@no...> - 2012年12月04日 01:02:28
On Mon, Dec 3, 2012 at 4:16 PM, Nathaniel Smith <nj...@po...> wrote:
> Yeah, this is a general problem with the Python file API, trying to
> hook it up to stdio is not at all an easy thing. A better version of
> this code would skip that altogether like:
>
> cdef void write_to_pyfile(png_structp s, png_bytep data, png_size_t count):
> fobj = <object>png_get_io_ptr(s)
> pydata = PyString_FromStringAndSize(data, count)
> fobj.write(pydata)
Good point -- not at all Cython-specific, but do you need libpng (or
whatever) to write to the file? can you just get a buffer with the
encoded data and write it on the Python side? Particularly if the user
wants to pass in an open file object. This might be a better API for
folks that might want stream an image right through a web app, too.
As a lot of Python APIs take either a file name or a file-like object,
perhaps it would make sense to push that distinction down to the
Cython level:
 -- if it's a filename, open it with raw C
 -- if it's a file-like object, have libpng write to a buffer (bytes
object) , and pass that to the file-like object in Python
anyway, not really a Cython issue, but that second object sure would
be easy on Cython....
-Chris
-- 
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chr...@no...
From: Nathaniel S. <nj...@po...> - 2012年12月04日 00:16:39
On Mon, Dec 3, 2012 at 11:50 PM, Chris Barker - NOAA Federal
<chr...@no...> wrote:
> On Mon, Dec 3, 2012 at 2:21 PM, Nathaniel Smith <nj...@po...> wrote:
>> For the file handle, I would just write
>>
>> cdef FILE *fp = fdopen(file_obj.fileno(), "w")
>>
>> and be done with it. This will work with any version of Python etc.
>
> yeah, that makes sense -- though what if you want to be able to
> read_to/write_from a file that is already open, and in the middle of
> the file somewhere -- would that work?
>
> I just posted a question to the Cython list, and indeed, it looks like
> there is no easy answer to the file issue.
Yeah, this is a general problem with the Python file API, trying to
hook it up to stdio is not at all an easy thing. A better version of
this code would skip that altogether like:
cdef void write_to_pyfile(png_structp s, png_bytep data, png_size_t count):
 fobj = <object>png_get_io_ptr(s)
 pydata = PyString_FromStringAndSize(data, count)
 fobj.write(pydata)
cdef void flush_pyfile(png_structp s):
 # Not sure if this is even needed
 fobj = <object>png_get_io_ptr(s)
 fobj.flush()
# in write_png:
write_png_c(<png_byte*>pix_buffer, width, height,
 NULL, <void*>file_obj, write_to_pyfile, flush_pyfile, dpi)
But this is a separate issue :-) (and needs further fiddling to make
exception handling work).
Or if you're only going to work on real OS-level file objects anyway,
you might as well just accept a filename as a string and fopen() it
locally. Having Python do the fopen just makes your life harder for no
reason.
-n
From: Chris B. - N. F. <chr...@no...> - 2012年12月04日 00:01:34
On Mon, Dec 3, 2012 at 12:24 PM, Chris Barker - NOAA Federal
<chr...@no...> wrote:
>>>> but some of that complexity could be reduced by using Numpy arrays in place
>> It would at least make this a more fair comparison to have the Cython
>> code as Cythonic as possible. However, I couldn't find any ways around
>> using these particular APIs -- other than the Numpy stuff which probably
>> does have a more elegant solution in the form of Cython arrays and
>> memory views.
OK -- so I poked at it, and this is my (very untested) version of
write_png (I left out the py3 stuff, though it does look like it may
be required for file handling...
Letting Cython unpack the numpy array is the real win. Maybe having it
this simple won't work for MPL, but this is what my code tends to look
like.
def write_png(cnp.ndarray[cnp.uint32, ndim=2, mode="c" ] buff not None,
 file_obj,
 double dpi=0.0):
 cdef png_uint_32 width = buff.size[0]
 cdef png_uint_32 height = buff.size[1]
 if PyFile_CheckExact(file_obj):
 cdef FILE *fp = fdopen(file_obj.fileno(), "w")
 fp = PyFile_AsFile(file_obj)
 write_png_c(buff[0,0], width, height, fp,
 NULL, NULL, NULL, dpi)
 return
 else:
 raise TypeError("write_png only works with real PyFileObject")
NOTE: that could be:
cnp.ndarray[cnp.uint8, ndim=3, mode="c" ]
I'm not sure how MPL stores image buffers.
or you could accept any object, then call:
np.view()
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chr...@no...

Showing 16 results of 16

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /