digitalmars.D.learn - Simple casting?
- Taylor R Hillegeist (15/15) Nov 25 2019 I'm attempting to do a segment group.
- Taylor R Hillegeist (14/31) Nov 25 2019 a simpler example:
- Alex (23/58) Nov 25 2019 What exactly is the problem, as this works for me if I understood
- Taylor R Hillegeist (5/30) Nov 26 2019 I like auto and all. But I wanted the return of the respective
- Timon Gehr (7/26) Nov 26 2019 import std;
- Taylor R Hillegeist (2/3) Nov 26 2019 how did you know to do that?
- =?UTF-8?Q?Ali_=c3=87ehreli?= (17/19) Nov 26 2019 Ranges don't have elements. They either generate elements according to
- Taylor R Hillegeist (15/28) Nov 26 2019 I suppose I'm asking here how did he know to use:
- Timon Gehr (4/10) Nov 26 2019 chunkBy with a binary predicate returns a range of ranges. So if I want
- ixid (5/11) Nov 27 2019 This stuff is a nightmare for less experienced users like myself,
- Timon Gehr (11/22) Nov 27 2019 import std;
- ixid (2/25) Nov 27 2019 Thank you, this is great but it should be in Phobos!
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?
Nov 25 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.
Nov 25 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: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'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.
Nov 25 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: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.[...]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.
Nov 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); }
Nov 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?
Nov 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: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 Aliint[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;how did you know to do that?
Nov 26 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: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?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 Aliint[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;how did you know to do that?
Nov 26 2019
On 26.11.19 23:08, Taylor R Hillegeist wrote:On Tuesday, 26 November 2019 at 16:33:06 UTC, Timon Gehr wrote: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.int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array;how did you know to do that?
Nov 26 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.
Nov 27 2019
On 27.11.19 11:43, ixid wrote:On Tuesday, 26 November 2019 at 16:33:06 UTC, Timon Gehr wrote:import std; auto eager(T)(T r){ static if(isInputRange!T) return r.map!eager.array; else return r; } void main(){ int[] x=[1,1,2,3,4,4]; int[][] y=x.chunkBy!((a,b)=>a==b).eager; writeln(y); }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.
Nov 27 2019
On Wednesday, 27 November 2019 at 14:40:56 UTC, Timon Gehr wrote:On 27.11.19 11:43, ixid wrote:Thank you, this is great but it should be in Phobos!On Tuesday, 26 November 2019 at 16:33:06 UTC, Timon Gehr wrote:import std; auto eager(T)(T r){ static if(isInputRange!T) return r.map!eager.array; else return r; } void main(){ int[] x=[1,1,2,3,4,4]; int[][] y=x.chunkBy!((a,b)=>a==b).eager; writeln(y); }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.
Nov 27 2019