Jump to page: 1 26  
Page
Thread overview
Templates problem
Sep 06, 2016
Russel Winder
Sep 06, 2016
Lodovico Giaretta
Sep 06, 2016
ketmar
Sep 07, 2016
Russel Winder
Sep 07, 2016
ketmar
Sep 07, 2016
Russel Winder
Sep 07, 2016
ketmar
Sep 07, 2016
Russel Winder
Sep 07, 2016
Kagamin
Sep 07, 2016
Russel Winder
Sep 07, 2016
Lodovico Giaretta
Sep 07, 2016
Russel Winder
Sep 07, 2016
Lodovico Giaretta
Sep 07, 2016
jmh530
Sep 07, 2016
data pulverizer
Sep 07, 2016
deXtoRious
Sep 07, 2016
data pulverizer
Sep 07, 2016
deXtoRious
Sep 07, 2016
data pulverizer
Sep 07, 2016
data pulverizer
Sep 07, 2016
jmh530
Sep 08, 2016
Russel Winder
Sep 08, 2016
deXtoRious
Sep 10, 2016
Russel Winder
Sep 07, 2016
jmh530
Sep 07, 2016
data pulverizer
Sep 07, 2016
jmh530
Sep 07, 2016
data pulverizer
Sep 07, 2016
jmh530
Sep 07, 2016
data pulverizer
Sep 07, 2016
bachmeier
Sep 07, 2016
data pulverizer
Sep 07, 2016
data pulverizer
Sep 07, 2016
bachmeier
Sep 07, 2016
Kagamin
Sep 08, 2016
Russel Winder
Sep 09, 2016
Kagamin
Sep 10, 2016
Russel Winder
Sep 07, 2016
rikki cattermole
Sep 07, 2016
Russel Winder
Sep 07, 2016
pineapple
Sep 07, 2016
jmh530
Sep 07, 2016
pineapple
Sep 07, 2016
jmh530
Sep 07, 2016
pineapple
Sep 07, 2016
jmh530
Sep 08, 2016
Russel Winder
Sep 08, 2016
jmh530
Sep 09, 2016
Russel Winder
Sep 09, 2016
jmh530
Sep 10, 2016
Russel Winder
Sep 08, 2016
data pulverizer
Sep 09, 2016
Russel Winder
Sep 09, 2016
data pulverizer
Sep 09, 2016
deXtoRious
September 06, 2016
The code fragment:

	const results = benchmark!(run_mean, run_mode, run_stdDev)(1);
	const times = map!((TickDuration t) { return (to!Duration(t)).total!"seconds"; })(results);

seems entirely reasonable to me. However rdmd 20160627 begs to differ:

run_checks.d(20): Error: template std.algorithm.iteration.map!(function (TickDuration t) => to(t).total()).map cannot deduce function from argument types !()(const(TickDuration[3])), candidates are:
/usr/include/dmd/phobos/std/algorithm/iteration.d(450):        std.algorithm.iteration.map!(function (TickDuration t) => to(t).total()).map(Range)(Range r) if (isInputRange!(Unqual!Range))
Failed: ["dmd", "-v", "-o-", "run_checks.d", "-I."]

and I have no idea just now why it is complaining, nor what to do to fix it.


-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

September 06, 2016
On Tuesday, 6 September 2016 at 14:38:54 UTC, Russel Winder wrote:
> The code fragment:
>
> 	const results = benchmark!(run_mean, run_mode, run_stdDev)(1);
> 	const times = map!((TickDuration t) { return (to!Duration(t)).total!"seconds"; })(results);
>
> seems entirely reasonable to me. However rdmd 20160627 begs to differ:
>
> run_checks.d(20): Error: template std.algorithm.iteration.map!(function (TickDuration t) => to(t).total()).map cannot deduce function from argument types !()(const(TickDuration[3])), candidates are:
> /usr/include/dmd/phobos/std/algorithm/iteration.d(450):        std.algorithm.iteration.map!(function (TickDuration t) => to(t).total()).map(Range)(Range r) if (isInputRange!(Unqual!Range))
> Failed: ["dmd", "-v", "-o-", "run_checks.d", "-I."]
>
> and I have no idea just now why it is complaining, nor what to do to fix it.

From a quick look, it looks like `results` is a `const(TickDuration[3])`, that is a fixed-length array. And fixed-length arrays aren't ranges. If you explicitly slice them, they become dynamic arrays, which are ranges.

So the solution is to call `map` with `results[]` instead of `results`.
September 06, 2016
On Tuesday, 6 September 2016 at 14:50:17 UTC, Lodovico Giaretta wrote:
> From a quick look, it looks like `results` is a `const(TickDuration[3])`, that is a fixed-length array. And fixed-length arrays aren't ranges. If you explicitly slice them, they become dynamic arrays, which are ranges.
>
> So the solution is to call `map` with `results[]` instead of `results`.

exactly. static arrays doesn't have `popFront`, hence `isInputRange` fails. yet there is no way to tell that to user, so one should just learn what those cryptic error messages really means.

or just get used to always slice arrays, it's cheap. ;-)
September 07, 2016
On Tue, 2016-09-06 at 14:50 +0000, Lodovico Giaretta via Digitalmars-d- learn wrote:
> 
[…]
>  From a quick look, it looks like `results` is a `const(TickDuration[3])`, that is a fixed-length array. And fixed-length arrays aren't ranges. If you explicitly slice them, they become dynamic arrays, which are ranges.
> 
> So the solution is to call `map` with `results[]` instead of `results`.

So trying with results[] leads to:

run_checks.d(21): Error: mutable method std.algorithm.iteration.MapResult!(function (TickDuration t) => to(t).total(), const(TickDuration)[]).MapResult.opIndex is not callable using a const object
run_checks.d(21): Error: mutable method std.algorithm.iteration.MapResult!(function (TickDuration t) => to(t).total(), const(TickDuration)[]).MapResult.opIndex is not callable using a const object
run_checks.d(21): Error: mutable method std.algorithm.iteration.MapResult!(function (TickDuration t) => to(t).total(), const(TickDuration)[]).MapResult.opIndex is not callable using a const object

yes, the message is repeated three times, for unknown reason. Possibly because the compiler is fairly certain I am not going to believe it.

So the upshot of this is that I can't work with const data, which is dreadful in these days of single assignment being the way of doing things.

So what is the way of constructing a range from a const array? If it involves copying then D is doomed.

And yes I am under stress as I am trying to pitch D to Python people next week.

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

September 07, 2016
On Tue, 2016-09-06 at 14:53 +0000, ketmar via Digitalmars-d-learn wrote:
> 
[…]
> exactly. static arrays doesn't have `popFront`, hence `isInputRange` fails. yet there is no way to tell that to user, so one should just learn what those cryptic error messages really means.

I shall assume a ;-) at the end of that. In trying to pitch D to Pythonistas, having to deal with error messages of this sort is the fastest route to "F@@@ that I'll just use Python", with D consigned to the dustbin.

Either that or it will make it very easy to pitch Chapel to Pythonistas. Which I shall also be trying to do as well – the idea is to wean Pythonistas off hacking Python to achieve computational speed, get them into a polyglot approach.

The issue here is having to compete against NumPy and Numba for performance computation, and Matplotlib for data visualisation. C, C++, Rust, Go will not cut it as competition in performance computation. D and Chapel (and X10 and Fortran but I am avoiding them) can. Sort of. The issue is that Python and Matplotlib should be seen as the partners rather than competition for D and Chapel. Arcane error messages from D compilers, are the fastest turn offs imaginable for people coming new to a language.

> or just get used to always slice arrays, it's cheap. ;-)

Except that it seems you cannot create a range from a const array by slicing. If the algorithms cannot operate on const arrays then the algorithms have a problem. If the algorithms have a problem, the language has a problem.

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

September 07, 2016
On 07/09/2016 2:38 AM, Russel Winder via Digitalmars-d-learn wrote:
> The code fragment:
>
> 	const results = benchmark!(run_mean, run_mode, run_stdDev)(1);
> 	const times = map!((TickDuration t) { return (to!Duration(t)).total!"seconds"; })(results);
>
> seems entirely reasonable to me. However rdmd 20160627 begs to differ:
>
> run_checks.d(20): Error: template std.algorithm.iteration.map!(function (TickDuration t) => to(t).total()).map cannot deduce function from argument types !()(const(TickDuration[3])), candidates are:
> /usr/include/dmd/phobos/std/algorithm/iteration.d(450):        std.algorithm.iteration.map!(function (TickDuration t) => to(t).total()).map(Range)(Range r) if (isInputRange!(Unqual!Range))
> Failed: ["dmd", "-v", "-o-", "run_checks.d", "-I."]
>
> and I have no idea just now why it is complaining, nor what to do to
> fix it.

Ok, I have it mostly compiling.

void run_mean() {}
void run_mode() {}
void run_stdDev() {}

void main() {
	import std.datetime;
	import std.algorithm : map;
	import std.conv;
	import std.array;
	
	const results = benchmark!(run_mean, run_mode, run_stdDev)(1);
	const times = map!((TickDuration t) { return (to!Duration(t)).total!"seconds"; })(results[]);
	
	import std.stdio;
	foreach(v; times) {
		writeln(v);	
	}
}

However times really can't be const. Since times is an input range which gets modified as part of the iterations.

So what exactly do you want times to be? If you want an array .array from std.algorithm it which can be const. Either way there is something I'm missing as to why const is so important here.
September 07, 2016
https://dpaste.dzfl.pl/0b436b240e3c
September 07, 2016
On Wednesday, 7 September 2016 at 08:30:51 UTC, Russel Winder wrote:
> On Tue, 2016-09-06 at 14:53 +0000, ketmar via Digitalmars-d-learn wrote:
>> 
> […]
>> exactly. static arrays doesn't have `popFront`, hence `isInputRange` fails. yet there is no way to tell that to user, so one should just learn what those cryptic error messages really means.
>
> I shall assume a ;-) at the end of that.

alas, no jokes here. within the current D sytnax there is simply no way to make that error less cryptic. :-(

even pointing at the failed constraint is fairly hard with current DMDFE code (that's why nobody did it yet), and show custom error for that is nearly impossible. we can't write "catch all" template with static assert, 'cause it catches everything, which is not desirable.

i myself didn't found even acceptable solution for this mess. sure, at least pointing to failed constraint is something we should have, but in your case it is of little help, actually.

probably adding `map` overload which accepts static arrays and does `static assert(0, "please use slice for static arrays");` may help in this case.
September 07, 2016
On Wednesday, 7 September 2016 at 08:19:39 UTC, Russel Winder wrote:
> On Tue, 2016-09-06 at 14:50 +0000, Lodovico Giaretta via Digitalmars-d- learn wrote:
>> 
> […]
>>  From a quick look, it looks like `results` is a `const(TickDuration[3])`, that is a fixed-length array. And fixed-length arrays aren't ranges. If you explicitly slice them, they become dynamic arrays, which are ranges.
>> 
>> So the solution is to call `map` with `results[]` instead of `results`.
>
> So trying with results[] leads to:
>
> run_checks.d(21): Error: mutable method std.algorithm.iteration.MapResult!(function (TickDuration t) => to(t).total(), const(TickDuration)[]).MapResult.opIndex is not callable using a const object
> run_checks.d(21): Error: mutable method std.algorithm.iteration.MapResult!(function (TickDuration t) => to(t).total(), const(TickDuration)[]).MapResult.opIndex is not callable using a const object
> run_checks.d(21): Error: mutable method std.algorithm.iteration.MapResult!(function (TickDuration t) => to(t).total(), const(TickDuration)[]).MapResult.opIndex is not callable using a const object
>
> yes, the message is repeated three times, for unknown reason. Possibly because the compiler is fairly certain I am not going to believe it.
>
> So the upshot of this is that I can't work with const data, which is dreadful in these days of single assignment being the way of doing things.
>
> So what is the way of constructing a range from a const array? If it involves copying then D is doomed.
>
> And yes I am under stress as I am trying to pitch D to Python people next week.

You have your const fixed-length array. You slice it and you obtain a const range to feed map. Now map will not return you an array. Because most of the time you don't need it. It will return you a range that lazily computes its elements on demand. No memory allocation at all. You can do a foreach on that range. If you need to access those elements more than once, instead of recomputing each of them every time it is accessed, you can store the results of the map. You simply have to use .array on the map result. This will allocate memory and give you an array with your results. Otherwise, no allocation at all. That result array can be const, if you want. If you need to access your elements only once, there's no need to have an array.

I really don't see what's not working in this.

And by the way, there's no need to put const on everything. An optimizing compiler is often able to infer things, especially for stack allocated local variables.
September 07, 2016
On Wed, 2016-09-07 at 08:42 +0000, Kagamin via Digitalmars-d-learn wrote:
> https://dpaste.dzfl.pl/0b436b240e3c

But now try adding the writeln function. Then you get the errors.

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

« First   ‹ Prev
1 2 3 4 5 6