shouldn't this throw ? iota(5).sliced(2,2)

Timothee Cour via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 8 16:15:10 PST 2016


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 at 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
>> instead of:
>> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20160108/1866615d/attachment-0001.html>


More information about the Digitalmars-d mailing list