digitalmars.D.learn - updated mir interface
- Alex (25/25) Nov 07 2018 I'm referring to the example
- 9il (2/5) Nov 07 2018 This is a regression. It is fixed in mir-random v2.1.2.
I'm referring to the example Could somebody tell me, why ´´´ import mir.random.algorithm; import std.range; //import mir.range; void main() { // line 5 size_t[] arr; arr.length = 42; arr = arr.length.iota.array; auto res = rne.sample(arr, 1); } // line 10 ´´´ refuses to compile? The error message is /Users/alex/.dub/packages/mir-random-2.1.1/mir-random/source/mir/random/ lgorithm.d(551,23): Error: no property popFrontExactly for type ulong[] /Users/alex/.dub/packages/mir-random-2.1.1/mir-random/source/mir/random/ lgorithm.d(558,13): Error: template instance `mir.random.algorithm.RandomSample!(MersenneTwisterEngine!(ulong, 64LU, 312LU, 156LU, 31LU, 13043109905998158313LU, 29LU, 6148914691236517205LU, 17LU, 8202884508482404352LU, 37LU, 18444473444759240704LU, 43LU, 6364136223846793005LU), ulong[]).RandomSample.__ctor!()` error instantiating /Users/alex/.dub/packages/mir-random-2.1.1/mir-random/source/mir/random/ lgorithm.d(448,35): instantiated from here: __ctor!() source/app.d(9,23): instantiated from here: sample!(MersenneTwisterEngine!(ulong, 64LU, 312LU, 156LU, 31LU, 13043109905998158313LU, 29LU, 6148914691236517205LU, 17LU, 8202884508482404352LU, 37LU, 18444473444759240704LU, 43LU, 6364136223846793005LU), ulong[]) dmd failed with exit code 1.
Nov 07 2018
On Wednesday, 7 November 2018 at 09:33:32 UTC, Alex wrote:I'm referring to the example [...]This is a regression. It is fixed in mir-random v2.1.2.
Nov 07 2018
On Wednesday, 7 November 2018 at 14:07:32 UTC, 9il wrote:This is a regression. It is fixed in mir-random v2.1.2.Thanks. But I have another one: ´´´ import mir.random.algorithm; import std.experimental.all; void main() { S[] arr; arr.length = 42; arr.each!((i, ref el) => el.i = i); auto res = rne.sample(arr.map!((ref el) => el.i), 1); } struct S { size_t i; } ´´´ Does not depend, on whether I use (ref el) or just el... And should not depend on that ;)
Nov 07 2018
On Wednesday, 7 November 2018 at 14:46:17 UTC, Alex wrote:On Wednesday, 7 November 2018 at 14:07:32 UTC, 9il wrote:I have updated template constraints. The problem that looks like Phobos map does not define all required primitives like popFrontExactly. I suggest using Mir instead of Phobos if possible: https://run.dlang.io/is/NBTfwF /+dub.sdl: dependency "mir-algorithm" version="~>3.0.3" dependency "mir-random" version="~>2.1.1" +/ import mir.random.algorithm; import mir.algorithm.iteration; import mir.ndslice: sliced, iota, map, member; void main() { S[] arr; arr.length = 42; // using each arr.length.iota.each!((i, ref el) => el.i = i)(arr); // or using each and member arr.length.iota.each!"b = a"(arr.member!"i"); // or using assign arr.member!"i"[] = arr.length.iota; auto res0 = rne.sample(arr.map!((ref el) => el.i), 1); // or using member auto res1 = rne.sample(arr.member!"i", 1); } struct S { size_t i; }This is a regression. It is fixed in mir-random v2.1.2.Thanks. But I have another one: ´´´ import mir.random.algorithm; import std.experimental.all; void main() { S[] arr; arr.length = 42; arr.each!((i, ref el) => el.i = i); auto res = rne.sample(arr.map!((ref el) => el.i), 1); } struct S { size_t i; } ´´´ Does not depend, on whether I use (ref el) or just el... And should not depend on that ;)
Nov 07 2018
On Wednesday, 7 November 2018 at 17:05:31 UTC, 9il wrote:I have updated template constraints. The problem that looks like Phobos map does not define all required primitives like popFrontExactly.Ok... didn't have this on my radar.I suggest using Mir instead of Phobos if possible: https://run.dlang.io/is/NBTfwF /+dub.sdl: dependency "mir-algorithm" version="~>3.0.3" dependency "mir-random" version="~>2.1.1" +/ import mir.random.algorithm; import mir.algorithm.iteration; import mir.ndslice: sliced, iota, map, member; void main() { S[] arr; arr.length = 42; // using each arr.length.iota.each!((i, ref el) => el.i = i)(arr); // or using each and member arr.length.iota.each!"b = a"(arr.member!"i"); // or using assign arr.member!"i"[] = arr.length.iota; auto res0 = rne.sample(arr.map!((ref el) => el.i), 1); // or using member auto res1 = rne.sample(arr.member!"i", 1); } struct S { size_t i; }I will try to adopt this... Thanks a lot!
Nov 07 2018
Ok... sorry for being penetrant, but there is still something strange. Having dependencies as you had, ´´´ import mir.random.algorithm; import mir.algorithm.iteration; import mir.ndslice; import mir.random; void fun(size_t s){} void main() { size_t[] arr; arr.length = 42; rne.sample(arr, 1).each!(el => fun(el)); foreach(i; rne.sample(arr, 1)) { i.fun; } } ´´´ I get /Users/alex/.dub/packages/mir-random-2.1.2/mir-random/source/mir/random/ lgorithm.d(573,48): Error: no property front for type ulong[] /Users/alex/.dub/packages/mir-algorithm-3.0.3/mir-algorithm/source/mir/algorithm/iteration d-mixin-922(922,5): Error: template instance `mir.random.algorithm.RandomSample!(MersenneTwisterEngine!(ulong, 64LU, 312LU, 156LU, 31LU, 13043109905998158313LU, 29LU, 6148914691236517205LU, 17LU, 8202884508482404352LU, 37LU, 18444473444759240704LU, 43LU, 6364136223846793005LU), ulong[]).RandomSample.front!()` error instantiating /Users/alex/.dub/packages/mir-algorithm-3.0.3/mir-algorithm/source/mir/algorithm/ teration.d(966,25): instantiated from here: eachImpl!(__lambda1, RandomSample!(MersenneTwisterEngine!(ulong, 64LU, 312LU, 156LU, 31LU, 13043109905998158313LU, 29LU, 6148914691236517205LU, 17LU, 8202884508482404352LU, 37LU,18444473444759240704LU, 43LU, 6364136223846793005LU), ulong[])) source/app.d(13,20): instantiated from here: each!(RandomSample!(MersenneTwisterEngine!(ulong, 64LU, 312LU, 156LU, 31LU, 13043109905998158313LU, 29LU, 6148914691236517205LU, 17LU, 8202884508482404352LU, 37LU, 18444473444759240704LU, 43LU, 6364136223846793005LU), ulong[])) dmd failed with exit code 1. If I import in mir.random.algorithm.d (2.1.2) in line 534 std.range, the error goes away. But I assume, that's not the way it should be solved, is it?
Nov 07 2018
On 07.11.2018 22:09, Alex wrote:Ok... sorry for being penetrant, but there is still something strange. Having dependencies as you had, ´´´ import mir.random.algorithm; import mir.algorithm.iteration; import mir.ndslice; import mir.random; void fun(size_t s){} void main() { size_t[] arr; arr.length = 42; rne.sample(arr, 1).each!(el => fun(el)); foreach(i; rne.sample(arr, 1)) { i.fun; } } ´´´ I get /Users/alex/.dub/packages/mir-random-2.1.2/mir-random/source/mir/random/ lgorithm.d(573,48): Error: no property front for type ulong[] /Users/alex/.dub/packages/mir-algorithm-3.0.3/mir-algorithm/source/mir/algorithm/iteration d-mixin-922(922,5): Error: template instance `mir.random.algorithm.RandomSample!(MersenneTwisterEngine!(ulong, 64LU, 312LU, 156LU, 31LU, 13043109905998158313LU, 29LU, 6148914691236517205LU, 17LU, 8202884508482404352LU, 37LU, 18444473444759240704LU, 43LU, 6364136223846793005LU), ulong[]).RandomSample.front!()` error instantiating /Users/alex/.dub/packages/mir-algorithm-3.0.3/mir-algorithm/source/mir/algorithm/ teration.d(966,25): instantiated from here: eachImpl!(__lambda1, RandomSample!(MersenneTwisterEngine!(ulong, 64LU, 312LU, 156LU, 31LU, 13043109905998158313LU, 29LU, 6148914691236517205LU, 17LU, 8202884508482404352LU, 37LU,18444473444759240704LU, 43LU, 6364136223846793005LU), ulong[])) source/app.d(13,20): instantiated from here: each!(RandomSample!(MersenneTwisterEngine!(ulong, 64LU, 312LU, 156LU, 31LU, 13043109905998158313LU, 29LU, 6148914691236517205LU, 17LU, 8202884508482404352LU, 37LU, 18444473444759240704LU, 43LU, 6364136223846793005LU), ulong[])) dmd failed with exit code 1. If I import in mir.random.algorithm.d (2.1.2) in line 534 std.range, the error goes away. But I assume, that's not the way it should be solved, is it?It's not a full answer, but try to add `import std.array;` or its analog in mir if exists
Nov 07 2018
On Wednesday, 7 November 2018 at 19:09:50 UTC, Alex wrote:Ok... sorry for being penetrant, but there is still something strange. Having dependencies as you had, [...]Well, fixed in v2.1.3
Nov 07 2018
On Wednesday, 7 November 2018 at 19:40:57 UTC, 9il wrote:On Wednesday, 7 November 2018 at 19:09:50 UTC, Alex wrote:Thanks again! Works for now.Ok... sorry for being penetrant, but there is still something strange. Having dependencies as you had, [...]Well, fixed in v2.1.3
Nov 07 2018