Re: [pygame] surfarray on 64-bit machines
Marius Gedminas wrote: Try pygame.surfarray.user_arraytype('numpy') at the start. NumPy became the default only recently with 1.9. Unfortunately, this gives me AttributeError: 'module' object has no attribute 'user_arraytype' I've got pygame 1.8.1 here (Ubuntu's 1.8.1release-0ubuntu1 to be precise) Marius Gedminas A typo. It should be user_arraytype. Lenard -- Lenard Lindstrom le...@telus.net
Re: [pygame] surfarray on 64-bit machines
hehe, double typo... 'use_arraytype' http://www.pygame.org/docs/ref/surfarray.html#pygame.surfarray.use_arraytype On Mon, Mar 2, 2009 at 1:43 PM, Lenard Lindstrom le...@telus.net wrote: A typo. It should be user_arraytype.
Re: [pygame] surfarray on 64-bit machines
On Mon, Mar 02, 2009 at 02:06:35PM +1100, René Dudfield wrote: hehe, double typo... 'use_arraytype' http://www.pygame.org/docs/ref/surfarray.html#pygame.surfarray.use_arraytype That works better, thanks! I've refactored PySpaceWar's fading title code into three classes now, one that uses plain PyGame, one that uses Numeric, and one that uses NumPy. The last one will be preferred if available. Marius Gedminas -- main(k){float i,j,r,x,y=-16;while(puts(),y++15)for(x =0;x++84;putchar( .:-;!/)|IH%*#[k15]))for(i=k=r=0; j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i11k++111;r=j);} /* Mandelbrot in ASCII. */ signature.asc Description: Digital signature
Re: [pygame] surfarray on 64-bit machines
It's the computer, honest. It keeps changing user to user. Oh no, not again. René Dudfield wrote: hehe, double typo... 'use_arraytype' http://www.pygame.org/docs/ref/surfarray.html#pygame.surfarray.use_arraytype On Mon, Mar 2, 2009 at 1:43 PM, Lenard Lindstrom le...@telus.net wrote: A typo. It should be user_arraytype. -- Lenard Lindstrom le...@telus.net
Re: [pygame] surfarray on 64-bit machines
On Fri, Feb 27, 2009 at 08:04:30PM -0800, Lenard Lindstrom wrote: Marius Gedminas wrote: Since I'm really clueless about Numeric/numarray/numpy, please tell me if this code has any obvious shortcomings: # initialization, done once import pygame import numpy image = pygame.image.load('title.png') # has an alpha channel mask = pygame.surfarray.array_alpha(image) # this is done once every frame array = pygame.surfarray.pixels_alpha(image) alpha = 42.5 # a float varying between 1 and 255 array[...] = (mask * alpha / 255).astype('b') Well, alpha and 255 are both scalars, so (mask * (alpha / 255)) saves one intermediate array. Also the preferred NumPy convention is to use dtypes (data-types) rather than type characters: .astype(numpy.uint8). I was using Numeric.UnsignedInt8 before, and couldn't find the NumPy version of that in a hurry. dir(array) showed me a typecode() method which returned things like 'b', and so I tried those. But arithmetic operations have ufunc equivalents which take an optional output array. This means the astype(), along with its intermediate array, can be removed. It probably also means the intermediate array float array goes away as well. So it is likely this alternative uses no intermediate arrays. ## array = pygame.surfarray.pixels_alpha(image) alpha = 42.5 ## array[...] = (mask * alpha / 255).astype('b') numpy.multiply(mask, alpha / 255, pygame.surfarray.pixels_alpha(image)) Unfortunately this gives me a TypeError: return arrays must be of ArrayType Marius Gedminas -- ... Another nationwide organization's computer system crashed twice in less than a year. The cause of each crash was a computer virus -- Paul Mungo, Bryan Glough _Approaching_Zero_ (in 1986 computer crashes were something out of the ordinary. Win95 anyone?) signature.asc Description: Digital signature
Re: [pygame] surfarray on 64-bit machines
Marius Gedminas wrote: On Fri, Feb 27, 2009 at 08:04:30PM -0800, Lenard Lindstrom wrote: Marius Gedminas wrote: Since I'm really clueless about Numeric/numarray/numpy, please tell me if this code has any obvious shortcomings: # initialization, done once import pygame import numpy image = pygame.image.load('title.png') # has an alpha channel mask = pygame.surfarray.array_alpha(image) # this is done once every frame array = pygame.surfarray.pixels_alpha(image) alpha = 42.5 # a float varying between 1 and 255 array[...] = (mask * alpha / 255).astype('b') Well, alpha and 255 are both scalars, so (mask * (alpha / 255)) saves one intermediate array. Also the preferred NumPy convention is to use dtypes (data-types) rather than type characters: .astype(numpy.uint8). I was using Numeric.UnsignedInt8 before, and couldn't find the NumPy version of that in a hurry. dir(array) showed me a typecode() method which returned things like 'b', and so I tried those. But arithmetic operations have ufunc equivalents which take an optional output array. This means the astype(), along with its intermediate array, can be removed. It probably also means the intermediate array float array goes away as well. So it is likely this alternative uses no intermediate arrays. ## array = pygame.surfarray.pixels_alpha(image) alpha = 42.5 ## array[...] = (mask * alpha / 255).astype('b') numpy.multiply(mask, alpha / 255, pygame.surfarray.pixels_alpha(image)) Unfortunately this gives me a TypeError: return arrays must be of ArrayType I'm guessing you have both Numeric and NumPy installed. Try pygame.surfarray.user_arraytype('numpy') at the start. NumPy became the default only recently with 1.9. Lenard -- Lenard Lindstrom le...@telus.net
Re: [pygame] surfarray on 64-bit machines
Marius Gedminas wrote: On Fri, Feb 27, 2009 at 11:16:28AM +1100, René Dudfield wrote: hey, is it possible to use numpy instead of Numeric? Numeric really is dying now... even we are going to stop trying to keep it working. I suppose I should. Since I'm really clueless about Numeric/numarray/numpy, please tell me if this code has any obvious shortcomings: # initialization, done once import pygame import numpy image = pygame.image.load('title.png') # has an alpha channel mask = pygame.surfarray.array_alpha(image) # this is done once every frame array = pygame.surfarray.pixels_alpha(image) alpha = 42.5 # a float varying between 1 and 255 array[...] = (mask * alpha / 255).astype('b') Cheers! Marius Gedminas Well, alpha and 255 are both scalars, so (mask * (alpha / 255)) saves one intermediate array. Also the preferred NumPy convention is to use dtypes (data-types) rather than type characters: .astype(numpy.uint8). But arithmetic operations have ufunc equivalents which take an optional output array. This means the astype(), along with its intermediate array, can be removed. It probably also means the intermediate array float array goes away as well. So it is likely this alternative uses no intermediate arrays. ## array = pygame.surfarray.pixels_alpha(image) alpha = 42.5 ## array[...] = (mask * alpha / 255).astype('b') numpy.multiply(mask, alpha / 255, pygame.surfarray.pixels_alpha(image)) Lenard -- Lenard Lindstrom le...@telus.net
Re: [pygame] surfarray on 64-bit machines
This was a long time ago (shame on me for not finding the time to investigate this further): On Wed, Oct 22, 2008 at 7:23 PM, Marius Gedminas mar...@gedmin.as wrote: A user reported that PySpaceWar fails on 64-bit Linux machines if I try to scale the alpha channel. Here's the code (simplified): import pygame import Numeric image = pygame.image.load('title.png') # has an alpha channel mask = pygame.surfarray.array_alpha(image).astype(Numeric.Int) array = pygame.surfarray.pixels_alpha(self.image) alpha = 42.5 # a float between 1 and 255 array[:] = (mask * alpha / 255).astype(Numeric.UnsignedInt8) The error happens on the last line, and it says ValueError: matrices are not aligned for copy Any ideas? The code works fine on 32-bit systems. On Wed, Oct 22, 2008 at 09:28:46PM -0500, Charlie Nolan wrote: I may be having this same error. I've got a bug report with that same error message at one point (and on a 64-bit machine), even though it works fine on my (32-bit) machine. Could you try printing out array[:].shape? In my case, I do a sensible slice and somehow end up with a 0x600 array. On a 32-bit machine: array[:].shape == array.shape == (333, 83) On a 64-bit machine: array[:].shape == (0, 83) On Wed, Oct 22, 2008 at 07:46:53PM -0700, Lenard Lindstrom wrote: I am curious, but what happens if array[:] is replaced with array[...]. The code starts working! Thank you! It is a two dimension array, so I am surprised the single index slice [:] even works. (on 32-bit only, for some reason). The alternate form [..] is indifferent to array dimension. It's a thinko on my part. I want an in-place assignment, I tend to write container[:] = new_value, without considering dimensionality at all. Cheers! Marius Gedminas -- A programmer started to cuss Because getting to sleep was a fuss As he lay there in bed Looping 'round in his head was: while(!asleep()) sheep++; signature.asc Description: Digital signature
Re: [pygame] surfarray on 64-bit machines
hey, is it possible to use numpy instead of Numeric? Numeric really is dying now... even we are going to stop trying to keep it working. cheers, On Fri, Feb 27, 2009 at 10:49 AM, Marius Gedminas mar...@gedmin.as wrote: This was a long time ago (shame on me for not finding the time to investigate this further): On Wed, Oct 22, 2008 at 7:23 PM, Marius Gedminas mar...@gedmin.as wrote: A user reported that PySpaceWar fails on 64-bit Linux machines if I try to scale the alpha channel. Here's the code (simplified): import pygame import Numeric image = pygame.image.load('title.png') # has an alpha channel mask = pygame.surfarray.array_alpha(image).astype(Numeric.Int) array = pygame.surfarray.pixels_alpha(self.image) alpha = 42.5 # a float between 1 and 255 array[:] = (mask * alpha / 255).astype(Numeric.UnsignedInt8) The error happens on the last line, and it says ValueError: matrices are not aligned for copy Any ideas? The code works fine on 32-bit systems. On Wed, Oct 22, 2008 at 09:28:46PM -0500, Charlie Nolan wrote: I may be having this same error. I've got a bug report with that same error message at one point (and on a 64-bit machine), even though it works fine on my (32-bit) machine. Could you try printing out array[:].shape? In my case, I do a sensible slice and somehow end up with a 0x600 array. On a 32-bit machine: array[:].shape == array.shape == (333, 83) On a 64-bit machine: array[:].shape == (0, 83) On Wed, Oct 22, 2008 at 07:46:53PM -0700, Lenard Lindstrom wrote: I am curious, but what happens if array[:] is replaced with array[...]. The code starts working! Thank you! It is a two dimension array, so I am surprised the single index slice [:] even works. (on 32-bit only, for some reason). The alternate form [..] is indifferent to array dimension. It's a thinko on my part. I want an in-place assignment, I tend to write container[:] = new_value, without considering dimensionality at all. Cheers! Marius Gedminas -- A programmer started to cuss Because getting to sleep was a fuss As he lay there in bed Looping 'round in his head was: while(!asleep()) sheep++; -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iD8DBQFJpyqMkVdEXeem148RAt0uAKCKWetlrgaEJwE9Y39Ue2Ms8UNgaQCfX/U/ TaEkGWual9RhcREfRIr3D7k= =IslQ -END PGP SIGNATURE-
Re: [pygame] surfarray on 64-bit machines
On Fri, Feb 27, 2009 at 11:16:28AM +1100, René Dudfield wrote: hey, is it possible to use numpy instead of Numeric? Numeric really is dying now... even we are going to stop trying to keep it working. I suppose I should. Since I'm really clueless about Numeric/numarray/numpy, please tell me if this code has any obvious shortcomings: # initialization, done once import pygame import numpy image = pygame.image.load('title.png') # has an alpha channel mask = pygame.surfarray.array_alpha(image) # this is done once every frame array = pygame.surfarray.pixels_alpha(image) alpha = 42.5 # a float varying between 1 and 255 array[...] = (mask * alpha / 255).astype('b') Cheers! Marius Gedminas -- Never trust a computer you can't repair yourself. signature.asc Description: Digital signature
[pygame] surfarray on 64-bit machines
A user reported that PySpaceWar fails on 64-bit Linux machines if I try to scale the alpha channel. Here's the code (simplified): import pygame import Numeric image = pygame.image.load('title.png') # has an alpha channel mask = pygame.surfarray.array_alpha(image).astype(Numeric.Int) array = pygame.surfarray.pixels_alpha(self.image) alpha = 42.5 # a float between 1 and 255 array[:] = (mask * alpha / 255).astype(Numeric.UnsignedInt8) The error happens on the last line, and it says ValueError: matrices are not aligned for copy Any ideas? The code works fine on 32-bit systems. Marius Gedminas -- If C gives you enough rope to hang yourself, C++ gives you enough rope to bind and gag your neighborhood, rig the sails on a small ship, and still have enough rope left over to hang yourself from the yardarm. signature.asc Description: Digital signature
Re: [pygame] surfarray on 64-bit machines
I may be having this same error. I've got a bug report with that same error message at one point (and on a 64-bit machine), even though it works fine on my (32-bit) machine. Could you try printing out array[:].shape? In my case, I do a sensible slice and somehow end up with a 0x600 array. -FM On Wed, Oct 22, 2008 at 7:23 PM, Marius Gedminas [EMAIL PROTECTED] wrote: A user reported that PySpaceWar fails on 64-bit Linux machines if I try to scale the alpha channel. Here's the code (simplified): import pygame import Numeric image = pygame.image.load('title.png') # has an alpha channel mask = pygame.surfarray.array_alpha(image).astype(Numeric.Int) array = pygame.surfarray.pixels_alpha(self.image) alpha = 42.5 # a float between 1 and 255 array[:] = (mask * alpha / 255).astype(Numeric.UnsignedInt8) The error happens on the last line, and it says ValueError: matrices are not aligned for copy Any ideas? The code works fine on 32-bit systems. Marius Gedminas -- If C gives you enough rope to hang yourself, C++ gives you enough rope to bind and gag your neighborhood, rig the sails on a small ship, and still have enough rope left over to hang yourself from the yardarm. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFI/8PxkVdEXeem148RAkA6AJwMJ03rjyOqAh6NWRtif4Hf㋀⟞恍 o4PpuubhJjENjPrqIg0CZXQ= =2e46 -END PGP SIGNATURE-
Re: [pygame] surfarray on 64-bit machines
Lenard Lindstrom wrote: It is a two dimension array, so I am surprised the single index slice [:] even works. Well, a 2d array can be thought of as a 1d array of 1d arrays, so you're getting an array of all of those 1d arrays, making another 2d array. Seems to work that way in Numeric at least -- you get back a view covering the whole of the original array. -- Greg