Re: New variable type: matrix

2000-08-26 Thread Nathan Wiger

Buddha Buck wrote:
> 
> $matrix[$x,$y,$z] already has a reasonable meaning.  If we
> appropriate that syntax, how do you take slices of a matrix?

My point too, only someone else pointed out that this is actually
@matrix[$x,$y,$z].

STILL, the fact that I've been hacking Perl since 4 and missed this
worries me that many others will confuse the two also.

> I'm thinking I like using ; as an index separator, as in
> $matrix[$x;$y;$z].  This -shouldn't- be a massive problem for parsing;
> we are already using ; in "for(;;)" as something other than a statement
> separator.

Great minds think alike! Are you sure you didn't read my email? ;-)

http://www.mail-archive.com/perl6-language-data%40perl.org/msg00035.html

> This would also allow us to do slices like: @matrix[1,3,5;2,4,6;3] to
> get a 3x3x1 resulting matrix consisting of $matrix[1;2;3],$matrix[1;4;3]
> , etc.

Now THAT seems pretty damn cool. REALLY cool. I'll have to think some
more, but my initial reaction is YES!

Buddha, RFC this! The stuff you put below here is great. It's easily the
most flexible format proposal I've seen.

> How are literal multidimensional arrays written?  For this, I'm not
> sure...  My first thought was to separate the rows with ;, as in
> @matrix = ( 1,2;3,4).  But that doesn't scale well to more than 2d.
> Then I thought just using the standard list of list syntax:  @matrix =
> ( [1,2],[3,4] ).  But is that a list of array references, or a 2-d
> array?  Next, I thought of combining the two:
> 
> @matrix3x3x3 = ( [[ 1, 2, 3];
>   [ 4, 5, 6];
>   [ 7, 8, 9]];   # row 0;
>  [[10,11,12];
>   [13,14,15];
>   [16,17,18]];   # row 1;
>  [[19,20,21];
>   [22,23,24];
>   [25,26,27]] ); # row 2;
> 
> I think parenthesis might be better, using [] for reference
> constructors, but any way you look at it.
> 
> Should explicit bounds and declarations take place before use?  Is "my
> @matrix:bounds(3,3,3);" necessary?  I don't know about you, but
> autovivication of array elements and boundlessness is a feature I like
> about perl.  Why should "$array[1000] = $x" work without predeclaration
> but "$matrix[1000;1000;1000] = $x" shouldn't?
> 
> Just my thoughts?



Re: New variable type: matrix

2000-08-26 Thread Buddha Buck


> Not being a PDL'er myself, but interested in learning more about it and
> making sure Perl 6 doesn't suck, I'd love to see a bulleted list of what
> doesn't work right, even assuming that @arrays were made more flexible.
> For example, if you could do this:
> 
>@c = @a * @b;
>@c = @a + @b;
>@c = (@a - @b) * (@d / @e);
> 
> What other specific problems remain? TIA.

I'm not a PDL'er myself, either.  But I haven't noticed a syntax 
suggested for multidimensional arrays that looks good to me yet.

How are they indexed?  $matrix[$x][$y][$z] is (too me) too C'ish, and 
implies that @matrix is implemented as an array of arrays of arrays, 
instead of some more efficient, compact structure.  $matrix[$x,$y,$z] 
already has a reasonable meaning.  If we appropriate that syntax, how 
do you take slices of a matrix?

I'm thinking I like using ; as an index separator, as in 
$matrix[$x;$y;$z].  This -shouldn't- be a massive problem for parsing; 
we are already using ; in "for(;;)" as something other than a statement 
separator.

This would also allow us to do slices like: @matrix[1,3,5;2,4,6;3] to 
get a 3x3x1 resulting matrix consisting of $matrix[1;2;3],$matrix[1;4;3]
, etc.

How are literal multidimensional arrays written?  For this, I'm not 
sure...  My first thought was to separate the rows with ;, as in 
@matrix = ( 1,2;3,4).  But that doesn't scale well to more than 2d.  
Then I thought just using the standard list of list syntax:  @matrix = 
( [1,2],[3,4] ).  But is that a list of array references, or a 2-d 
array?  Next, I thought of combining the two:

@matrix3x3x3 = ( [[ 1, 2, 3];
  [ 4, 5, 6];
  [ 7, 8, 9]];   # row 0;
 [[10,11,12];  
  [13,14,15];
  [16,17,18]];   # row 1;
 [[19,20,21];
  [22,23,24];
  [25,26,27]] ); # row 2;

I think parenthesis might be better, using [] for reference 
constructors, but any way you look at it.

Should explicit bounds and declarations take place before use?  Is "my 
@matrix:bounds(3,3,3);" necessary?  I don't know about you, but 
autovivication of array elements and boundlessness is a feature I like 
about perl.  Why should "$array[1000] = $x" work without predeclaration 
but "$matrix[1000;1000;1000] = $x" shouldn't?

Just my thoughts?


 
> 
> -Nate

-- 
 Buddha Buck [EMAIL PROTECTED]
"Just as the strength of the Internet is chaos, so the strength of our
liberty depends upon the chaos and cacophony of the unfettered speech
the First Amendment protects."  -- A.L.A. v. U.S. Dept. of Justice





Re: New variable type: matrix

2000-08-26 Thread Nathan Wiger

Baris wrote:
> 
> Suppose I am a newcomer to perl and my aim is to multiply two matrices
> and I don't really care about regex's or references in perl. Currently
> I have to learn a lot about perl language to begin working with matrix
> multiplication. This seems to me aginst the perl culture. I know pdl is
> very easy to use, but how about somebody who doesn't know anything about
> perl? He will have to first buy an introductory book for perl.

I'm not really against a matrix variable type, but I must say I don't
think this is an argument for one. A person will always have to learn
about any language to harness its powerful features, whether they be
regexes, objects, pdl, or something else. So I don't think the "dumbing
down" argument is a good one.

Not being a PDL'er myself, but interested in learning more about it and
making sure Perl 6 doesn't suck, I'd love to see a bulleted list of what
doesn't work right, even assuming that @arrays were made more flexible.
For example, if you could do this:

   @c = @a * @b;
   @c = @a + @b;
   @c = (@a - @b) * (@d / @e);

What other specific problems remain? TIA.

-Nate



Re: RFC 148 (v1) Add reshape() for multi-dimensional array reshaping

2000-08-26 Thread Daniel Chetlin

On Fri, Aug 25, 2000 at 07:35:24PM -0700, Nathan Wiger wrote:
> > > > $a[$i][$j][$k] or $a[$i,$j,$k]
>
> > The second one has no useful meeting, "," is just an operator which
> > does nothing much useful in this context.
> 
> Not true, at least not in the Perl I know. :-) Here's a description of
> what these do in Perl just to clarify:
> 
>$a[0][1][2];  # get a single multidimensional element
>$a[0,1,2];# get elements 0, 1, and 2 of @a

perl -le'@a=(1..5);$,=" .. ",print @a[1,2,3];print $a[1,2,3]'
2 .. 3 .. 4
4

perl -wle'@a=(1..5);$,=" .. ",print @a[1,2,3];print $a[1,2,3]'
Multidimensional syntax $a[1,2,3] not supported at -e line 1.
Useless use of a constant in void context at -e line 1.
2 .. 3 .. 4
4

-dlc




Re: New variable type: matrix

2000-08-26 Thread Baris

Hi Karl,
Thanks for your comments.
I still think it would be a good idea to have a new type for both functional and 
promotional purposes. I know that Nathan Torkington answered that perl6 will support 
the requirements of PDL but I am hoping that having a new type for multidimentional 
arrays lets PDL developpers freely create whichever syntax they want without worrying 
that if a syntax has any other meaning in another context. Also this will increase 
readibility of code. (Why do we have a new type for hashes?). And wouldn't it be 
faster since clases/objects/etc. are slower than regular perl. The whole issue looks 
like the regex support of perl. It needed a dedicated built in engine to have the 
flexibility and speed. People say that perl character manipulation is faster than C... 
And speed is much more crucial in linear algebra problems.

I think the question at this point will be that "Does perl want to target a new 
audience?". Having a new type will force new books from Oreilly ("Learning Perl6") to 
teach the new type in the second chapter (might be good or bad). Suppose I am a 
newcomer to perl and my aim is to multiply two matrices and I don't really care about 
regex's or references in perl. Currently I have to learn a lot about perl language to 
begin working with matrix multiplication. This seems to me aginst the perl culture. I 
know pdl is very easy to use, but how about somebody who doesn't know anything about 
perl? He will have to first buy an introductory book for perl.

Even if you can solve all problems with syntax, performance, flexibility (I am not 
saying these are problems, just guessing), in terms of promotion of perl in this area, 
having a new type will make a difference. I know this because saying that hashes are 
built in types for perl made a difference.

Thanks,
Baris.

*** REPLY SEPARATOR  ***

On 25.08.2000 at 12:28 Karl Glazebrook wrote:

>Hi Baris,
>
>I agree with your sentiments. Most people in PDL DO come from the
>number crunching/scientific background.
>
>I would say that a matrix is just a special case of a general
>N-dimensional compact array which obeys various rules. PDL
>supplies a matrix-mult operator ("x") and other matrix ops.
>Note it is useful to have BOTH "x" and "*".
>
>Our goal is to get true multi-dim arrays like PDL, as you say,
>into the core. Then one would have matrices too.
>
>What the prefix should be is of course as interesting question,
>currently PDL uses $, @ could be used if overloading became possible.
>Is there a real case for a special prefix?
>
>Karl
>
>Baris Sumengen wrote:
>>
>> I am little bit confused and probably very ignorant but one thing seems to
>> me very useful. Why doesn't perl support a new data type matrix. If perl
>> wants to become a real "programming language" not just a scripting language
>> it should support number crunching internally in a more intuitive way. I
>> don't know if this is suggested before but until now the messages I read
>> mentioned only making perl arrays consistant with pdl arrays.
>etc.







   1stUp.com - Free the Web
   Get your free Internet access at http://www.1stUp.com



Re: RFC 148 (v1) Add reshape() for multi-dimensional array reshaping

2000-08-26 Thread Ariel Scolnicov

Nathan Wiger <[EMAIL PROTECTED]> writes:

> > > > $a[$i][$j][$k] or $a[$i,$j,$k]
> 
> > The second one has no useful meeting, "," is just an operator which
> > does nothing much useful in this context.
> 
> Not true, at least not in the Perl I know. :-) Here's a description of
> what these do in Perl just to clarify:
> 
>$a[0][1][2];  # get a single multidimensional element
>$a[0,1,2];# get elements 0, 1, and 2 of @a

Ahem.  We've been arguing about getting rid of $@%, but haven't yet!
$a[0,1,2] returns exactly $a[2], since it is a $calar context.
Perhaps you were thinking of @a[0,1,2]?

In any case, having good multi-dimensional syntax for scalar access but 
not for list access is not very orthogonal.

Also, C<,> inside (scalar) square brackets is B useless!
Consider e.g.

print $line[do_something_for_side_effect, $a+$b]

[...]

-- 
Ariel Scolnicov|"GCAAGAATTGAACTGTAG"| [EMAIL PROTECTED]
Compugen Ltd.  |Tel: +972-2-6795059 (Jerusalem) \ We recycle all our Hz
72 Pinhas Rosen St.|Tel: +972-3-7658514 (Main office)`-
Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555http://3w.compugen.co.il/~ariels