Jump to page: 1 2
Thread overview
Simple casting?
Nov 26, 2019
Alex
Nov 26, 2019
Timon Gehr
Nov 26, 2019
Ali Çehreli
Nov 27, 2019
Timon Gehr
Nov 27, 2019
ixid
Nov 27, 2019
Timon Gehr
Nov 27, 2019
ixid
November 26, 2019
I'm attempting to do a segment group.

details:
alias ProbePoint[3]=triple;
triple[] irqSortedSet = UniqueTriples.keys
				.sort!("a[1].irqid < b[1].irqid",SwapStrategy.stable)
				.array;		
83:triple[][] irqSortedSets = irqSortedSet.chunkBy!((a,b) => a[1].irqid == b[1].irqid);	


GetAllTriplesExtractFileIrqSplit.d(83): Error: cannot implicitly convert expression `chunkBy(irqSortedSet)` of type `ChunkByImpl!(__lambda4, ProbePoint[3][])` to `ProbePoint[3][][]`

I have something that looks like a triple[][] but I can't seem to get that type out.
when I add .array it converts to a Group which doesn't make sense to me because I'm not using a unary comparison. Any thought?
November 26, 2019
On Tuesday, 26 November 2019 at 05:05:48 UTC, Taylor R Hillegeist wrote:
> I'm attempting to do a segment group.
>
> details:
> alias ProbePoint[3]=triple;
> triple[] irqSortedSet = UniqueTriples.keys
> 				.sort!("a[1].irqid < b[1].irqid",SwapStrategy.stable)
> 				.array;		
> 83:triple[][] irqSortedSets = irqSortedSet.chunkBy!((a,b) => a[1].irqid == b[1].irqid);	
>
>
> GetAllTriplesExtractFileIrqSplit.d(83): Error: cannot implicitly convert expression `chunkBy(irqSortedSet)` of type `ChunkByImpl!(__lambda4, ProbePoint[3][])` to `ProbePoint[3][][]`
>
> I have something that looks like a triple[][] but I can't seem to get that type out.
> when I add .array it converts to a Group which doesn't make sense to me because I'm not using a unary comparison. Any thought?

a simpler example:

import std.algorithm.comparison : equal;
import std.array;
// Grouping by particular attribute of each element:
uint[3][] data = [
    [1, 1,0],
    [1, 2,0],
    [2, 2,0],
    [2, 3,0]
];

uint[3][][] r1 = data.chunkBy!((a,b) => a[0] == b[0]);

fails in the same way.
November 26, 2019
On Tuesday, 26 November 2019 at 05:17:54 UTC, Taylor R Hillegeist wrote:
> On Tuesday, 26 November 2019 at 05:05:48 UTC, Taylor R Hillegeist wrote:
>> I'm attempting to do a segment group.
>>
>> details:
>> alias ProbePoint[3]=triple;
>> triple[] irqSortedSet = UniqueTriples.keys
>> 				.sort!("a[1].irqid < b[1].irqid",SwapStrategy.stable)
>> 				.array;		
>> 83:triple[][] irqSortedSets = irqSortedSet.chunkBy!((a,b) => a[1].irqid == b[1].irqid);	
>>
>>
>> GetAllTriplesExtractFileIrqSplit.d(83): Error: cannot implicitly convert expression `chunkBy(irqSortedSet)` of type `ChunkByImpl!(__lambda4, ProbePoint[3][])` to `ProbePoint[3][][]`
>>
>> I have something that looks like a triple[][] but I can't seem to get that type out.
>> when I add .array it converts to a Group which doesn't make sense to me because I'm not using a unary comparison. Any thought?
>
> a simpler example:
>
> import std.algorithm.comparison : equal;
> import std.array;
> // Grouping by particular attribute of each element:
> uint[3][] data = [
>     [1, 1,0],
>     [1, 2,0],
>     [2, 2,0],
>     [2, 3,0]
> ];
>
> uint[3][][] r1 = data.chunkBy!((a,b) => a[0] == b[0]);
>
> fails in the same way.

What exactly is the problem, as this works for me if I understood your goal correctly:

´´´
void main()
{
    import std.algorithm.comparison : equal;
    import std.array;
    import std;
    // Grouping by particular attribute of each element:
    uint[3][] data = [
        [1, 1,0],
        [1, 2,0],
        [2, 2,0],
        [2, 3,0]
    ];

    auto r1 = data.chunkBy!((a,b) => a[0] == b[0]);
}
´´´

If it is the type of the return value --> the return value of chunkBy has a different one compared to the input. Instead, you get an abstracted range whereas the input data serves as a source.
November 26, 2019
On Tuesday, 26 November 2019 at 06:45:19 UTC, Alex wrote:
> On Tuesday, 26 November 2019 at 05:17:54 UTC, Taylor R Hillegeist wrote:
>> [...]
>
> What exactly is the problem, as this works for me if I understood your goal correctly:
>
> ´´´
> void main()
> {
>     import std.algorithm.comparison : equal;
>     import std.array;
>     import std;
>     // Grouping by particular attribute of each element:
>     uint[3][] data = [
>         [1, 1,0],
>         [1, 2,0],
>         [2, 2,0],
>         [2, 3,0]
>     ];
>
>     auto r1 = data.chunkBy!((a,b) => a[0] == b[0]);
> }
> ´´´
>
> If it is the type of the return value --> the return value of chunkBy has a different one compared to the input. Instead, you get an abstracted range whereas the input data serves as a source.

I like auto and all. But I wanted the return of the respective type. I can't figure out how to get the type uint[3][][]; that is the type my function takes but I can't figure out how to get it converted.
November 26, 2019
On 26.11.19 06:05, Taylor R Hillegeist wrote:
> I'm attempting to do a segment group.
> 
> details:
> alias ProbePoint[3]=triple;
> triple[] irqSortedSet = UniqueTriples.keys
>                  .sort!("a[1].irqid < b[1].irqid",SwapStrategy.stable)
>                  .array;
> 83:triple[][] irqSortedSets = irqSortedSet.chunkBy!((a,b) => a[1].irqid == b[1].irqid);
> 
> 
> GetAllTriplesExtractFileIrqSplit.d(83): Error: cannot implicitly convert expression `chunkBy(irqSortedSet)` of type `ChunkByImpl!(__lambda4, ProbePoint[3][])` to `ProbePoint[3][][]`
> 
> I have something that looks like a triple[][] but I can't seem to get that type out.
> when I add .array it converts to a Group which doesn't make sense to me because I'm not using a unary comparison. Any thought?

import std;
void main(){
    int[] x=[1,1,2,3,4,4];
    int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;
    writeln(y);
}
November 26, 2019
On Tuesday, 26 November 2019 at 16:33:06 UTC, Timon Gehr wrote:
>     int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;


how did you know to do that?

November 26, 2019
On 11/26/19 2:08 PM, Taylor R Hillegeist wrote:> On Tuesday, 26 November 2019 at 16:33:06 UTC, Timon Gehr wrote:
>>     int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;
>
>
> how did you know to do that?

Ranges don't have elements. They either generate elements according to an algorithm, provide access to elements (or copies of elements) that belong to other containers.

In this case, chunkBy() is like an engine that knows how to present the input range in chunks but does not start working automatically. This is a great feature because you can start accessing chunks, deciding it's enough, and stop; potentially avoiding a lot of eager work (potentially infinite).

std.array.array pulls all elemenst of a range and places them inside an array. That is eager but sometimes necessary work. For example, std.algorithm.sort cannot sort just any range because it needs the elements to be layed out as array elements:

  someAlgorithmRange.sort;      <-- Does not work
  someAlgorithmRange.array.sort <-- Works

Ali

November 27, 2019
On Tuesday, 26 November 2019 at 23:29:12 UTC, Ali Çehreli wrote:
> On 11/26/19 2:08 PM, Taylor R Hillegeist wrote:> On Tuesday, 26 November 2019 at 16:33:06 UTC, Timon Gehr wrote:
> >>     int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;
> >
> >
> > how did you know to do that?
> std.array.array pulls all elemenst of a range and places them inside an array. That is eager but sometimes necessary work. For example, std.algorithm.sort cannot sort just any range because it needs the elements to be layed out as array elements:
>
>   someAlgorithmRange.sort;      <-- Does not work
>   someAlgorithmRange.array.sort <-- Works
>
> Ali

I suppose I'm asking here how did he know to use:
.map!array.array

I in my mind I thought that
.array
would have been enough, it seems like it when looking at the original error:

GetAllTriplesExtractFileIrqSplit.d(83):

Error: cannot implicitly convert expression `chunkBy(irqSortedSet)` of type

`ChunkByImpl!(__lambda4, ProbePoint[3][])`  <<Its almost to the final form
to
`ProbePoint[3][][]`

does this have to do with the collection depth?




November 27, 2019
On 26.11.19 23:08, Taylor R Hillegeist wrote:
> On Tuesday, 26 November 2019 at 16:33:06 UTC, Timon Gehr wrote:
>>     int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;
> 
> 
> how did you know to do that?
> 

chunkBy with a binary predicate returns a range of ranges. So if I want an array of arrays I have to convert both the inner ranges and the outer range.
November 27, 2019
On Tuesday, 26 November 2019 at 16:33:06 UTC, Timon Gehr wrote:
> import std;
> void main(){
>     int[] x=[1,1,2,3,4,4];
>     int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;
>     writeln(y);
> }

This stuff is a nightmare for less experienced users like myself, I wish there were a single function that would make any data obkect eager, no matter how convoluted its arrays of arrays of arrays.
« First   ‹ Prev
1 2