Re: reshape() (was Re: Fw: Wrapup time)
Nathan Wiger wrote: > Jeremy Howard wrote: > > > > RFC 203 defines a :bounds attribute that defines the maximum index of each > > dimension of an array. RFC 206 provides the syntax @#array which returns > > these maximum indexes. For consistancy, the arguments to reshape() should be > > the maximum index of each dimension. A maximum index of '0' would mean that > > that dimension is 1 element wide. Therefore '0' can not be special in > > reshape(). Therefore we should use '-1'. > > I agree with Christian, if you're going to use bounds(), this should be > equal to the number of elements, NOT the number of the last element. So > you would say "3" for 3 elements, even though they're numbered 0..2. > This is the way other similar Perl ops work already: > >$size = @a;# 3 >$last = $#a; # 2 > OK, I'm convinced. I'll change :bounds. I agree with Christian that it should be renamed :shape in that case.
Re: reshape() (was Re: Fw: Wrapup time)
Jeremy Howard wrote: > > RFC 203 defines a :bounds attribute that defines the maximum index of each > dimension of an array. RFC 206 provides the syntax @#array which returns > these maximum indexes. For consistancy, the arguments to reshape() should be > the maximum index of each dimension. A maximum index of '0' would mean that > that dimension is 1 element wide. Therefore '0' can not be special in > reshape(). Therefore we should use '-1'. I agree with Christian, if you're going to use bounds(), this should be equal to the number of elements, NOT the number of the last element. So you would say "3" for 3 elements, even though they're numbered 0..2. This is the way other similar Perl ops work already: $size = @a;# 3 $last = $#a; # 2 Having "bounds" be the last index, instead of the max size, is very counterintuitive. Having "0" mean "1 element" doesn't make any sense. "0" should mean 0 elements, and -1 should mean the last element. -Nate
Re: reshape() (was Re: Fw: Wrapup time)
Jeremy Howard wrote: > the maximum index of each dimension. A maximum index of '0' would mean that > that dimension is 1 element wide. Therefore '0' can not be special in > reshape(). Therefore we should use '-1'. -1 is the maximum index for any size in the usual fashion of perl array indexing. However, do you really want to give the args to reshape in the @#array form? This in contrast to any other array language I know where the actual shape of the target array is used which is related to @#array via @shape = @#array+1; I see a great source of confusion here. Similarly I would change the bound(@#args) to shape(@shape) [or allow it as an alias] my @b : shape(3,3); # fixed shape -- corresponds to bounds(2,2) print @#b; 2 2 That's how NumPy, PDL, IDL, MatLab, Yorick treat things (and any other similar language I have come across). I hadn't noted this in the RFCs before. Breaking these conventions will *not* help acceptance. Christian
Re: reshape() (was Re: Fw: Wrapup time)
> > rather use a transpose() function for this that can transpose across a given > > axis. > > You'll be RFC'ing that, I suppose? ;-) (But seriously, it sounds like a > good idea) > Yes, I will. > > I don't think we need to define the ability to work on multiple lists as > > special behaviour. Perl knows how to flatten lists, so any syntax we define > > will allow multiple lists simply by letting Perl join and flatten them. > > Right, unless you make the list the first argument, like NumPy: > >@b = rehape @a, [1,2]; > > Then you're in trouble. > So we shouldn't make the list the first argument... > > Finally, I think the dimensions specified by reshape() should be the maximum > > index of the axis, not the number of elements, since this way it matches the > > :bounds semantics. In this case, the wildcard would clearly need to -1. > > This sounds reasonable, but maybe just clarify this a little? Feel free > to send me volumes of examples offline if need be. > RFC 203 defines a :bounds attribute that defines the maximum index of each dimension of an array. RFC 206 provides the syntax @#array which returns these maximum indexes. For consistancy, the arguments to reshape() should be the maximum index of each dimension. A maximum index of '0' would mean that that dimension is 1 element wide. Therefore '0' can not be special in reshape(). Therefore we should use '-1'. Let me know off-list if you'd like more clarification.
Re: reshape() (was Re: Fw: Wrapup time)
Jeremy Howard wrote: > > That looks good, except that I'd remove the interleaving. Currently, it's > not clear how to reshape() to more than 2 dimensions, because the third > argument of the first list ref is the interleave flag. We should be able to > be able to reshape to any number of dimensions: You've convinced me, I'll take it out. > rather use a transpose() function for this that can transpose across a given > axis. You'll be RFC'ing that, I suppose? ;-) (But seriously, it sounds like a good idea) > I don't think we need to define the ability to work on multiple lists as > special behaviour. Perl knows how to flatten lists, so any syntax we define > will allow multiple lists simply by letting Perl join and flatten them. Right, unless you make the list the first argument, like NumPy: @b = rehape @a, [1,2]; Then you're in trouble. > Finally, I think the dimensions specified by reshape() should be the maximum > index of the axis, not the number of elements, since this way it matches the > :bounds semantics. In this case, the wildcard would clearly need to -1. This sounds reasonable, but maybe just clarify this a little? Feel free to send me volumes of examples offline if need be. -Nate
reshape() (was Re: Fw: Wrapup time)
Nathan Wiger wrote: > Jeremy Howard wrote: > > > > 148: Change to Numeric Python semantics of reshape(), or write counter-RFC > > specifying these semantics (preferably renaming this RFC's 'reshape' to > > something else) > > There are a couple things that the NumPy one lacks that RFC 148 > currently has: > >1. Arbitrary Interleaving > >2. A way to specify multiple @arrays, i.e. > > @new = reshape $x,$y,$i, @a, @b, @c;# RFC 148 > > Now, if we're looking for a new, more compact syntax, let's make arg one > an arrayref of dimensions: > > @new = reshape [$x,$y,$i], @a, @b, @c; > > That looks remarkably similar to NumPy's, plus it can take multiple > arrays, even defaulting to @_. And I can change the "wildcard" from 0 to > -1, just like NumPy's. > That looks good, except that I'd remove the interleaving. Currently, it's not clear how to reshape() to more than 2 dimensions, because the third argument of the first list ref is the interleave flag. We should be able to be able to reshape to any number of dimensions: @new = reshape [$w,$x,$y,$z], @a, @b, @c; Furthermore, it's not clear how interleaving would work on >2d arrays. I'd rather use a transpose() function for this that can transpose across a given axis. I don't think we need to define the ability to work on multiple lists as special behaviour. Perl knows how to flatten lists, so any syntax we define will allow multiple lists simply by letting Perl join and flatten them. Finally, I think the dimensions specified by reshape() should be the maximum index of the axis, not the number of elements, since this way it matches the :bounds semantics. In this case, the wildcard would clearly need to -1. Then I'd be happy. ;-)