## digitalmars.D - shouldn't this throw ? iota(5).sliced(2,2)

Timothee Cour via Digitalmars-d <digitalmars-d puremagic.com> writes:
what's the rationale for:
Range length must be greater than or equal to the sum of shift and the
product of lengths
Range length must be equal to the sum of shift and the product of lengths
?

It seems more lax and bug-prone.
Jan 06 2016
Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
On Thursday, 7 January 2016 at 04:47:16 UTC, Timothee Cour wrote:
what's the rationale for:
Range length must be greater than or equal to the sum of shift
and the
product of lengths
Range length must be equal to the sum of shift and the product
of lengths
?

It seems more lax and bug-prone.
std.ndslice will contain a module or few for allocations, script like code, and concatenations. User defined range may not have slicing, but must be able to be used with `sliced` multiple times with different lengths. -- Ilya
Jan 06 2016
Timothee Cour via Digitalmars-d <digitalmars-d puremagic.com> writes:
I'm not sure I understand your argument.
My problem is that iota(5) has 5 elements which is more than 2*2, so I
would expect
iota(5).sliced(2,2)
or
iota(7).sliced(2,3).sliced(1,2)
to throw, as in pretty much any other tensor library:

*matlab:*
reshape(0:4, 2,2)
Error using reshape
To RESHAPE the number of elements must not change.

python with numpy:
import numpy as np
np.arange(5).reshape((2, 2))
ValueError: total size of new array must be unchanged

eigen:
http://eigen.tuxfamily.org/dox-devel/unsupported/TensorMorphing_8h_source.html
eigen_assert(internal::array_prod(m_impl.dimensions()) ==
internal::array_prod(op.dimensions()));

This behavior will 100% cause hard to find bugs.
Why not instead allow this behavior only when a template argument is given:
ReshapeAllowsDownsize.yes

On Wed, Jan 6, 2016 at 10:39 PM, Ilya Yaroshenko via Digitalmars-d <
digitalmars-d puremagic.com> wrote:

On Thursday, 7 January 2016 at 04:47:16 UTC, Timothee Cour wrote:

what's the rationale for:
Range length must be greater than or equal to the sum of shift and the
product of lengths
Range length must be equal to the sum of shift and the product of lengths
?

It seems more lax and bug-prone.
std.ndslice will contain a module or few for allocations, script like code, and concatenations. User defined range may not have slicing, but must be able to be used with `sliced` multiple times with different lengths. -- Ilya
Jan 08 2016
Ilya <ilyayaroshenko gmail.com> writes:
On Saturday, 9 January 2016 at 00:15:10 UTC, Timothee Cour wrote:
I'm not sure I understand your argument.
My problem is that iota(5) has 5 elements which is more than
2*2, so I
would expect
iota(5).sliced(2,2)
or
iota(7).sliced(2,3).sliced(1,2)
to throw, as in pretty much any other tensor library:

[...]
auto a = iota(5).sliced(5); auto b = a.reshape(2, 2); // throws ReshapeException --ilya
Jan 08 2016
Timothee Cour via Digitalmars-d <digitalmars-d puremagic.com> writes:
ok good, 'reshape' behaves as it should; but what's the rationale for not
throwing on 'iota(5).sliced(2,2) ' ?

in light of what i wrote above, it's surprising behavior and will cause
bugs. What are the advantages of allowing it to not throw?

On Fri, Jan 8, 2016 at 6:09 PM, Ilya via Digitalmars-d <
digitalmars-d puremagic.com> wrote:

On Saturday, 9 January 2016 at 00:15:10 UTC, Timothee Cour wrote:

I'm not sure I understand your argument.
My problem is that iota(5) has 5 elements which is more than 2*2, so I
would expect
iota(5).sliced(2,2)
or
iota(7).sliced(2,3).sliced(1,2)
to throw, as in pretty much any other tensor library:

[...]
auto a = iota(5).sliced(5); auto b = a.reshape(2, 2); // throws ReshapeException --ilya
Jan 08 2016
Ilya <ilyayaroshenko gmail.com> writes:
On Saturday, 9 January 2016 at 04:15:08 UTC, Timothee Cour wrote:
ok good, 'reshape' behaves as it should; but what's the
rationale for not
throwing on 'iota(5).sliced(2,2) ' ?

in light of what i wrote above, it's surprising behavior and
will cause bugs. What are the advantages of allowing it to not
throw?

On Fri, Jan 8, 2016 at 6:09 PM, Ilya via Digitalmars-d <
digitalmars-d puremagic.com> wrote:

On Saturday, 9 January 2016 at 00:15:10 UTC, Timothee Cour
wrote:

I'm not sure I understand your argument.
My problem is that iota(5) has 5 elements which is more than
2*2, so I
would expect
iota(5).sliced(2,2)
or
iota(7).sliced(2,3).sliced(1,2)
to throw, as in pretty much any other tensor library:

[...]
auto a = iota(5).sliced(5); auto b = a.reshape(2, 2); // throws ReshapeException --ilya
Agreed. I will add optional exception (by default sliced will trow). --Ilya
Jan 08 2016
Timothee Cour via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Fri, Jan 8, 2016 at 10:07 PM, Ilya via Digitalmars-d <
digitalmars-d puremagic.com> wrote:

On Saturday, 9 January 2016 at 04:15:08 UTC, Timothee Cour wrote:

ok good, 'reshape' behaves as it should; but what's the rationale for not
throwing on 'iota(5).sliced(2,2) ' ?

in light of what i wrote above, it's surprising behavior and will cause
bugs. What are the advantages of allowing it to not throw?

On Fri, Jan 8, 2016 at 6:09 PM, Ilya via Digitalmars-d <
digitalmars-d puremagic.com> wrote:

On Saturday, 9 January 2016 at 00:15:10 UTC, Timothee Cour wrote:
I'm not sure I understand your argument.
My problem is that iota(5) has 5 elements which is more than 2*2, so I
would expect
iota(5).sliced(2,2)
or
iota(7).sliced(2,3).sliced(1,2)
to throw, as in pretty much any other tensor library:

[...]
auto a = iota(5).sliced(5); auto b = a.reshape(2, 2); // throws ReshapeException --ilya
Agreed. I will add optional exception (by default sliced will trow). --Ilya
thanks!! glad we could agree on this!
Jan 08 2016