Re: ndslice help

2016-02-18 Thread Zz via Digitalmars-d-learn

On Thursday, 18 February 2016 at 02:24:20 UTC, ZombineDev wrote:

On Thursday, 18 February 2016 at 00:25:09 UTC, Zz wrote:

Hi,

I'm trying to generate the following sequences with ndslice.

0 0 0
1 1 1

1 1 1
0 0 0

0 1 2
0 1 2

2 1 0
2 1 0

It's okay with loops but was checking to see if it's possible 
with ndslice.


Zz


Here's my solution:
http://dpaste.dzfl.pl/29676608fd88

The best part about ndslice is that you can use the ordinary 
slice operations with it like:

http://dlang.org/spec/arrays.html#array-copying,
http://dlang.org/spec/arrays.html#array-setting,
http://dlang.org/spec/arrays.html#array-operations, etc.

and also leverage the existing ranges, range transformations 
and algorithms from

http://dlang.org/phobos/std_range and
http://dlang.org/phobos/std_algorithm.

In addition, I used nested array formatting with
http://dlang.org/phobos/std_format.


Thanks

Zz


Re: ndslice help

2016-02-17 Thread ZombineDev via Digitalmars-d-learn

On Thursday, 18 February 2016 at 00:25:09 UTC, Zz wrote:

Hi,

I'm trying to generate the following sequences with ndslice.

0 0 0
1 1 1

1 1 1
0 0 0

0 1 2
0 1 2

2 1 0
2 1 0

It's okay with loops but was checking to see if it's possible 
with ndslice.


Zz


Here's my solution:
http://dpaste.dzfl.pl/29676608fd88

The best part about ndslice is that you can use the ordinary 
slice operations with it like:

http://dlang.org/spec/arrays.html#array-copying,
http://dlang.org/spec/arrays.html#array-setting,
http://dlang.org/spec/arrays.html#array-operations, etc.

and also leverage the existing ranges, range transformations and 
algorithms from

http://dlang.org/phobos/std_range and
http://dlang.org/phobos/std_algorithm.

In addition, I used nested array formatting with
http://dlang.org/phobos/std_format.



ndslice help

2016-02-17 Thread Zz via Digitalmars-d-learn

Hi,

I'm trying to generate the following sequences with ndslice.

0 0 0
1 1 1

1 1 1
0 0 0

0 1 2
0 1 2

2 1 0
2 1 0

It's okay with loops but was checking to see if it's possible 
with ndslice.


Zz


Re: ndslice help.

2015-12-30 Thread Zz via Digitalmars-d-learn
On Wednesday, 30 December 2015 at 20:43:21 UTC, Ilya Yaroshenko 
wrote:

On Wednesday, 30 December 2015 at 18:53:15 UTC, Zz wrote:

Hi,

Just playing with ndslice and I couldn't figure how to get the 
following transformations.


given.

auto slicea = sliced(iota(6), 2, 3, 1);
foreach (item; slicea)
{
   writeln(item);
}

which gives.

[[0][1][2]]
[[3][4][5]]

what transformation should i do to get the following from 
slicea.


[[0][2][4]]
[[1][3][5]]

[[4][2][0]]
[[5][3][1]]

Zz


Hi,

void main()
{
auto slicea = sliced(iota(6), 2, 3, 1);
auto sliceb = slicea.reshape(3, 2, 1).transposed!1;
auto slicec = sliceb.reversed!1;

writefln("%(%(%(%s%)\n%)\n\n%)", [slicea, sliceb, slicec]);
}

Output:
[0][1][2]
[3][4][5]

[0][2][4]
[1][3][5]

[4][2][0]
[5][3][1]

Ilya


Thanks


Re: ndslice help.

2015-12-30 Thread Ilya Yaroshenko via Digitalmars-d-learn

On Wednesday, 30 December 2015 at 18:53:15 UTC, Zz wrote:

Hi,

Just playing with ndslice and I couldn't figure how to get the 
following transformations.


given.

auto slicea = sliced(iota(6), 2, 3, 1);
foreach (item; slicea)
{
   writeln(item);
}

which gives.

[[0][1][2]]
[[3][4][5]]

what transformation should i do to get the following from 
slicea.


[[0][2][4]]
[[1][3][5]]

[[4][2][0]]
[[5][3][1]]

Zz


Hi,

void main()
{
auto slicea = sliced(iota(6), 2, 3, 1);
auto sliceb = slicea.reshape(3, 2, 1).transposed!1;
auto slicec = sliceb.reversed!1;

writefln("%(%(%(%s%)\n%)\n\n%)", [slicea, sliceb, slicec]);
}

Output:
[0][1][2]
[3][4][5]

[0][2][4]
[1][3][5]

[4][2][0]
[5][3][1]

Ilya


ndslice help.

2015-12-30 Thread Zz via Digitalmars-d-learn

Hi,

Just playing with ndslice and I couldn't figure how to get the 
following transformations.


given.

auto slicea = sliced(iota(6), 2, 3, 1);
foreach (item; slicea)
{
   writeln(item);
}

which gives.

[[0][1][2]]
[[3][4][5]]

what transformation should i do to get the following from slicea.

[[0][2][4]]
[[1][3][5]]

[[4][2][0]]
[[5][3][1]]

Zz