[PYTHON MATRIX-SIG] bug: assignment from string

James Hugunin jjh@mama-bear.lcs.mit.edu
Mon, 18 Dec 95 15:56:36 -0500


> (Core dump data ommitted)

As a small point, these detailed listings of the results of a core dump are  
probably not at all useful to any member of this list except myself (to  
whom the are EXTREMELY helpful) so it might be a better idea to just send  
them directly to me and I'll fix them ASAP.  However, I don't want to say  
anything that will discourage people from sending in bug reports.

The other comments are great for the list.

> The problem is with the string in the rhs: m2[1,1] = 'e'
> (m1[1,1] = 66 works).
>
> I suppose the bug is in matrix_ass_sub(), but I can't figure where.

There's actually something rather strange going on here, and while it  
shouldn't dump core, my current interpretation of strings says that this  
should raise an exception.

Here's what's going on:

'hello' gets converted to a 5-length vector ['h', 'e', 'l', 'l', 'o']
'e' gets converted to a 1-length vector ['e']
66 is a 0-dimensional scalar

So, m[1,1] = 'e' is trying to assign a 1-length vector to a 0-dimensional  
scalar, which is an exception.

I can fix this by treating 1-length strings as 0-dimensional scalars if you  
think this is the appropriate choice.

Note: I NEVER use arrays of strings personally, so I'm depending on the  
other people on this list to tell me how you want them to behave.  I can't  
imagine a use for arrays of strings except for interfacing to existing  
libraries.

> Also, I wonder why can't we specify all the dimensions as arguments to
> fromString(), avoiding to call reshape() ?

This is a simple oversight on my part.  I'm not convinced that the current  
form of "fromString" is exactly the way it should finally be, and I'm  
reluctant to churn out C-code for an interface that might change.   
Nevertheless, I'll add a function to Matrix.py to fix this in the next  
release.

-Jim

=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================