Re: Threading Questions
On Friday, 25 September 2015 at 15:19:27 UTC, bitwise wrote: I know that all global variables are TLS unless explicitly marked as 'shared', but someone once told me something about 'shared' affecting member variables in that accessing them from a separate thread would return T.init instead of the actual value... or something like that. This seems to be wrong(thankfully). T.init is returned for TLS variable when accessed from a thread for which it wasn't initialized.
Re: Mac IDE with Intellisense
Am Sat, 26 Sep 2015 10:38:25 + schrieb Gary Willoughby: > Auto-complete in D is tricky because of this feature and no-one > has invested any time to figure out a nice way to provide > auto-complete for this. Mono-D does have UFCS auto-complete. The plugin is going to bit-rot though, since its only developer is done studying. -- Marco
Re: WTF does "Enforcement failed" actually mean?
Am Thu, 01 Oct 2015 08:52:43 + schrieb John Colvin: > On Thursday, 1 October 2015 at 07:08:00 UTC, Russel Winder wrote: > > On Wed, 2015-09-30 at 23:35 -0700, Ali Çehreli via > > Digitalmars-d-learn wrote: > >> On 09/30/2015 10:46 PM, Russel Winder via Digitalmars-d-learn > >> wrote: > >> > [...] > >> > >> It's coming from the following no-message enforce(): > >> > >> enforce(!r.empty); > >> > >> > >> https://github.com/D-Programming-Language/phobos/blob/master/std/algo > >> rithm/iteration.d#L2481 > >> > >> You are using the no-seed version of reduce(), which uses the > >> first element as seed, which means that the range cannot be > >> empty. > > > > Well that explanation (*) makes it abundantly clear that the > > error reporting from this part of Phobos is distinctly > > substandard, let alone below par. > > > > > > (*) Which is clear and informative! > > Bug report? Then it'll get fixed. The problem is that in out minds addition has an implicit seed value of 0 and multiplication has 1, so a potentially empty range doesn't immediately raise a red flag. The correct thing to use, following this train of thought, is http://dlang.org/phobos/std_algorithm_iteration.html#.sum (Additionally it provides better accuracy when summing up floating-point values.) -- Marco
Re: Which GDC to download?
On Thursday, 1 October 2015 at 12:04:40 UTC, NX wrote: 1) Why there is a download targeting arm-linux-gnueabi(hf) and what exactly it means? Is this a cross-compiler which will produce obj files containing ARM instructions or what? If so, will linking just work? and how? Yes, that's a cross compiler. You run it on Windows to produce programs for an ARM device running Linux (for example, you do your development on Windows but want the program to run on a Raspberry Pi) 3) Which one to choose if I just want to write & compile windows programs? The x86_64-w64-mingw32 one. That means Intel processor, Windows 64 bit. mingw32 is the library used by gcc to make Windows programs. You could also use the 32 bit one below, i686-w64-mingw32, both should work on Windows. 4) x86_64-w64-mingw32 is commented as "Unsupported alpha build. SEH"? is that means windows-targeting version of the compiler is highly unstable/not ready yet? What's "SEH"? SEH is Windows' "Structured Exception Handling". The open source compilers (not just D, basically all of them) historically haven't done a great job implementing that but have recently been fixing their problems. You'll probably be fine using it though.
Re: Interval Arithmetic
Am Tue, 29 Sep 2015 21:04:00 + schrieb Wulfrick: > Is there an interval arithmetic library in D? I couldn’t find one. > > In case I had to write my own, I understand that the IEEE > standard floating point arithmetic provides operations for > rounding up or down certain operations like summing, subtracting, > etc. (thus overriding the default behavior of rounding to nearest > representable). > > How do I access this functionality in D? At first I thought that > std.math.nextDown and nextUp is what I needed, but not so. > Apparently these functions return the previous or next > representable *after* the calculation has been done. > > For example, I would like the value of x+y rounded in the > arithmetic towards -\infty, which may or may not be nextDown(x+y). > > Any luck? > Thanks for reading! Yes, Phobos provides you with this thing: http://dlang.org/phobos/std_math.html#.FloatingPointControl Read the help carefully. End of the scope generally means "}". You can also use the C standard library from D and use: http://www.cplusplus.com/reference/cfenv/fesetround/ import core.stdc.fenv; fesetround( FE_DOWNWARD ); auto z = x + y; And if all that still isn't enough you can write it in inline assembler using the `fldcw` mnemonic. Note that the FP control word is per thread and any external code you call or even buggy interrupt handlers could change or reset it to defaults. Known cases include a faulty printer driver and Delphi's runtime, which enables FP exceptions to throw exceptions on division by 0. Just saying this so if it ever happens you have it in the back of your mind. Against interrupt handlers you probably cannot protect, but when calling other people's code it would be best not depend on what the FP control word is set to on return. `FloatingPointControl` is nice here, because you can temporarily set the rounding mode directly for a block of FP instructions where no external libraries are involved. -- Marco
Which GDC to download?
Windows X86 64bit (x86_64-w64-mingw32) Standard builds Target DMDFE Runtime GCC GDC revisionBuild Date arm-linux-gnueabi 2.066.1 yes 5.2.0 dadb5a3784 2015-08-30 arm-linux-gnueabihf 2.066.1 yes 5.2.0 dadb5a3784 2015-08-30 x86_64-w64-mingw32 2.066.1 yes 5.2.0 dadb5a3784 2015-08-30 I'm totally confused about what does these mean: 1) Why there is a download targeting arm-linux-gnueabi(hf) and what exactly it means? Is this a cross-compiler which will produce obj files containing ARM instructions or what? If so, will linking just work? and how? 2) Is what I understand from "cross-compiler" correct? (a compiler that can target different architectures than the host architecture it's compiled for) 3) Which one to choose if I just want to write & compile windows programs? 4) x86_64-w64-mingw32 is commented as "Unsupported alpha build. SEH"? is that means windows-targeting version of the compiler is highly unstable/not ready yet? What's "SEH"?
Re: Interval Arithmetic
On Thursday, 1 October 2015 at 11:40:28 UTC, Marco Leise wrote: Note that the FP control word is per thread and any external code you call or even buggy interrupt handlers could change or reset it to defaults. Known cases include a faulty printer driver and Delphi's runtime, which enables FP exceptions to throw exceptions on division by 0. Just saying this so if it ever happens you have it in the back of your mind. Against interrupt handlers you probably cannot protect, but when calling other people's code it would be best not depend on what the FP control word is set to on return. `FloatingPointControl` is nice here, because you can temporarily set the rounding mode directly for a block of FP instructions where no external libraries are involved. I have a RAII struct to save/restore the FP control word. It also handle the SSE control word which unfortunately exist. https://github.com/p0nce/dplug/blob/master/plugin/dplug/plugin/fpcontrol.d
Re: Which GDC to download?
Am Thu, 01 Oct 2015 12:04:38 + schrieb NX: > Windows X86 64bit (x86_64-w64-mingw32) > > Standard builds > TargetDMDFE Runtime > GCC GDC revisionBuild Date arm-linux-gnueabi > 2.066.1 yes 5.2.0 dadb5a3784 > 2015-08-30 arm-linux-gnueabihf2.066.1 yes > 5.2.0 dadb5a3784 2015-08-30 > x86_64-w64-mingw322.066.1 yes > 5.2.0 dadb5a3784 2015-08-30 > > I'm totally confused about what does these mean: > > 1) Why there is a download targeting arm-linux-gnueabi(hf) and > what exactly it means? Is this a cross-compiler which will > produce obj files containing ARM instructions or what? If so, > will linking just work? and how? Linking only works for libraries which are included with the cross compiler. That usually means only the C/C++/D standard libraries will be available. You can link to other libraries with a cross-compiler, but you need to provides these libraries in some way: http://wiki.dlang.org/GDC/Cross_Compiler http://wiki.dlang.org/GDC/Cross_Compiler/Existing_Sysroot http://wiki.dlang.org/GDC/Cross_Compiler/Existing_Sysroot#Using_a_compiler_from_gdcproject.org.2Fdownloads For more information: http://build-gdc.readthedocs.org/en/latest/Cross-Compiler%20Basics/ > > 2) Is what I understand from "cross-compiler" correct? (a > compiler that can target different architectures than the host > architecture it's compiled for) > > 3) Which one to choose if I just want to write & compile windows > programs? > Adding to Adams answer I guess we (the GDC team) have to somehow present 'native compilers' more prominently. > 4) x86_64-w64-mingw32 is commented as "Unsupported alpha build. > SEH"? is that means windows-targeting version of the compiler is > highly unstable/not ready yet? What's "SEH"? Unfortunately Windows GDC builds are very unstable right now. I'd recommend using DMD or LDC for Windows.
Re: Regex start/end position of match?
On Thursday, 1 October 2015 at 03:29:29 UTC, Gerald wrote: I'm stuck though on how to get the start/end index of a match? I couldn't find one either so I did the pre/post/hit things broken up. Take a look at this little program I wrote: http://arsdnet.net/dcode/replacer/ All the files it needs are there, so you can browse by http or download them somewhere and compile+run to give it a try. Lines 73-78 show the pre/hit/post thing, with me changing the colors of the output so they match. Afterward, I replace one instance and draw it again to show what the new line would look like. (The point of my program is to interactively request confirmation of every individual change you are going to make.) Something similar will probably work for you too.
Re: How to use std.experimental.logger?
Ah, I tried to format a custom struct that has a non-pure toString, because std.conv.to isn't pure either, sigh :(
Re: Which GDC to download?
Thanks both to you for answers... On Thursday, 1 October 2015 at 14:07:02 UTC, Johannes Pfau wrote: Unfortunately Windows GDC builds are very unstable right now. I'd recommend using DMD or LDC for Windows. Well... To me it's surprising GDC is not usable on windows but I doubt LDC is more stable. Sad... *Cries in Turkish*
Re: Regex start/end position of match?
Thanks Adam, that was the hint I needed. For a given RegexMatch the pre().length() is essentially equivalent to the start position and taking pre().length + hit.length() gives the end position so I think this should be OK for my needs.
Re: an example of parallel calculation of metrics
On Thursday, 1 October 2015 at 07:03:40 UTC, Ali Çehreli wrote: Looks like a bug. Workaround: Get rid of member names Thanks. My particular use case, working with metric expressions, is easier to understand if I use the names. I converted the use of Tuple to struct to see if I could get an easier error msg. Turns out the use of struct also results in much cleaner writeln text. Still has the compile error, though. import std.algorithm, std.parallelism, std.range; import std.stdio; import std.datetime; import std.typecons; import std.meta; // define some input measurement sample tuples and output metric tuples struct TR {double per_sec; double per_cycle; long raw;} struct TI {long proc_cyc; long DATA_RD; long DATA_WR; long INST_FETCH; long L1I_MISS; long L1I_HIT; long L1D_HIT; long L1D_MISS;} struct TO { TR L1_MISS; TR L1_HIT; TR DATA_ACC; TR ALL_ACC;} const double CYC_PER_SEC = 1_600_000_000; // various metric definitions // using Tuples with defined names for each member, and use the names here in the metrics. TR met_l1_miss ( ref TI m){ TR rv; with(rv) with(m) { raw = L1I_MISS+L1D_MISS; per_cycle = cast(double)raw/proc_cyc; per_sec = per_cycle*CYC_PER_SEC;} return rv; } TR met_l1_hit ( ref TI m){ TR rv; with(rv) with(m) { raw = L1I_HIT+L1D_HIT; per_cycle = cast(double)raw/proc_cyc; per_sec = per_cycle*CYC_PER_SEC;} return rv; } TR met_data_acc ( ref TI m){ TR rv; with(rv) with(m) { raw = DATA_RD+DATA_WR; per_cycle = cast(double)raw/proc_cyc; per_sec = per_cycle*CYC_PER_SEC;} return rv; } TR met_all_acc( ref TI m){ TR rv; with(rv) with(m) { raw = DATA_RD+DATA_WR+INST_FETCH; per_cycle = cast(double)raw/proc_cyc; per_sec = per_cycle*CYC_PER_SEC;} return rv; } // a convenience to use all the metrics above as a list alias Metrics = AliasSeq!(met_l1_miss,met_l1_hit,met_data_acc,met_all_acc); void main(string[] argv) { auto samples = iota(1_00); auto meas = new TI[samples.length]; auto results = new TO[samples.length]; // Initialize some values for the measured samples foreach(i, ref m; meas){ with(m){ proc_cyc = 1_000_000+i*2; DATA_RD = 1000+i; DATA_WR= 2000+i; INST_FETCH=proc_cyc/2; L1I_HIT= INST_FETCH-100; L1I_MISS=100; L1D_HIT= DATA_RD+DATA_WR - 200; L1D_MISS=200;} } std.datetime.StopWatch sw; sw.start(); ref TI getTerm(int i) { return meas[i]; } // compute the metric results for the above measured sample values in parallel taskPool.amap!(Metrics)(std.algorithm.map!getTerm(samples),results); TR rv1 = met_l1_miss( meas[0]); TR rv2 = met_l1_hit( meas[0]); TR rv3 = met_data_acc( meas[0]); TR rv4 = met_all_acc( meas[0]); // how long did this take long exec_ms = sw.peek().msecs; writeln("measurements:", meas[0]); writeln("rv1:", rv1); writeln("rv2:", rv2); writeln("rv3:", rv3); writeln("rv4:", rv4); writeln("results:", results[1]); writeln("time:", exec_ms); }
Re: an example of parallel calculation of metrics
On Thursday, 1 October 2015 at 18:08:31 UTC, Ali Çehreli wrote: Makes sense. Please open a bug at least for investigation why tuples with named members don't work with amap. ok, thanks. I opened the issue. https://issues.dlang.org/show_bug.cgi?id=15134
help me learn to read documentation
Hi. I like to learn programming by examples but I need help learning how to read documentation. I have some idea of how it works in some aspects but in others i get completely stuck because there are no examples or code snippets. I am using dgame (dgame-dev.de) and im reading the documentation for changing the background text of my font in my program. I have the basic code for font creation but i need to make changes to the colors. import std.stdio; import std.system; import Dgame.System; import Dgame.Window; import Dgame.Graphic; import Dgame.Audio; import Dgame.Math; void main() { Font dejavu = Font("resources/dejavu.ttf", 12); Text CurrentFps = new Text(dejavu); ..window loop } The documentation here (http://dgame-dev.de/index.php?controller=learn=package=graphic=Text=0.6)... gives me the Text() class but i dont know how to use "foreground, background, and Font mode" or at least turn it into usable syntax.
Re: an example of parallel calculation of metrics
On Thursday, 1 October 2015 at 18:08:31 UTC, Ali Çehreli wrote: However, if you prove to yourself that the result tuple and your struct have the same memory layout, you can cast the tuple slice to struct slice after calling amap: After re-reading your explanation, I see that the problem is only that the results needs to be a Tuple. It works with named tuple members in this example as the result and array of struct as the input. I'll re-check if the multi-member result also works with named members. I'll update the issue report. import std.meta; import std.stdio; // define some input measurement sample tuples and output metric tuples struct TI {long L1I_MISS; long L1D_MISS; } alias TO = Tuple!(long, "raw"); // various metric definitions // using Tuples with defined names for each member, and use the names here in the metrics. TO met_l1_miss ( ref TI m){ TO rv; rv.raw = m.L1I_MISS+m.L1D_MISS; return rv; } // a convenience to use all the metrics above as a list alias Metrics = AliasSeq!(met_l1_miss); void main(string[] argv) { auto samples = iota(100); auto meas = new TI[samples.length]; auto results = new TO[samples.length]; // Initialize some values for the measured samples foreach(i, ref m; meas){ m.L1D_MISS= 100+i; m.L1I_MISS=100-i; } ref TI getTerm(int i) { return meas[i]; } // compute the metric results for the above measured sample values in parallel taskPool.amap!(Metrics)(std.algorithm.map!getTerm(samples),results); TO rv1 = met_l1_miss( meas[1]); writeln("measurements:", meas[1]); writeln("rv1:", rv1); writeln("results:", results[1]); }
Re: WTF does "Enforcement failed" actually mean?
On Thu, 2015-10-01 at 08:52 +, John Colvin via Digitalmars-d-learn wrote: > […] > > Bug report? Then it'll get fixed. https://issues.dlang.org/show_bug.cgi?id=15133 Timer running… ;-) -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: an example of parallel calculation of metrics
On 10/01/2015 08:56 AM, Jay Norwood wrote: > Thanks. My particular use case, working with metric expressions, is > easier to understand if I use the names. Makes sense. Please open a bug at least for investigation why tuples with named members don't work with amap. > I converted the use of Tuple > to struct to see if I could get an easier error msg. Turns out the use > of struct also results in much cleaner writeln text. > > Still has the compile error, though. We have to live with the fact that amap and friends produce a Tuple result if there are multiple functions. A struct won't work. However, if you prove to yourself that the result tuple and your struct have the same memory layout, you can cast the tuple slice to struct slice after calling amap: alias TO_for_amap_result = Tuple!(TR, TR, TR, TR); struct TO { TR L1_MISS; TR L1_HIT; TR DATA_ACC; TR ALL_ACC;} // ... auto results_for_amap = new TO_for_amap_result[samples.length]; // ... taskPool.amap!(Metrics)(std.algorithm.map!getTerm(samples),results_for_amap); auto results = cast(TO[])results_for_amap; // Use 'results' from this point on... Ali
Re: Interval Arithmetic
Am Thu, 01 Oct 2015 12:03:10 + schrieb ponce: > I have a RAII struct to save/restore the FP control word. > It also handle the SSE control word which unfortunately exist. > > https://github.com/p0nce/dplug/blob/master/plugin/dplug/plugin/fpcontrol.d Nice to have in Phobos. I assume you have to set the correct control word depending on whether you perform math on the FPU or via SSE (as is standard for x86_64)? And I assume further that DMD always uses FPU math and other compilers provide flags to switch between FPU and SSE? -- Marco
Re: an example of parallel calculation of metrics
So, this is a condensed version of the original problem. It looks like the problem is that the return value for taskPool.amap can't be a tuple of tuples or a tuple of struct. Either way, it fails with the Wrong buffer type error message if I uncomment the taskPool line import std.algorithm, std.parallelism, std.range; import std.typecons; import std.meta; import std.stdio; // define some input measurement sample tuples and output metric tuples struct TR { long raw; double per_cyc;} //alias TR = Tuple!(long, "raw", double, "per_cyc"); alias TI = Tuple!(long, "L1I_MISS",long, "L1D_MISS", long, "L1D_READ", long, "L1D_WRITE", long, "cycles" ); alias TO = Tuple!(TR, "L1_MISS", TR, "L1D_ACCESS"); // various metric definitions // using Tuples with defined names for each member, and use the names here in the metrics. TR met_l1_miss ( ref TI m){ TR rv; rv.raw = m.L1I_MISS+m.L1D_MISS; rv.per_cyc = cast(double)rv.raw/m.cycles; return rv; } TR met_l1_access ( ref TI m){ TR rv; rv.raw = m.L1D_READ+m.L1D_WRITE; rv.per_cyc = cast(double)rv.raw/m.cycles; return rv; } // a convenience to use all the metrics above as a list alias Metrics = AliasSeq!(met_l1_miss, met_l1_access); void main(string[] argv) { auto samples = iota(100); auto meas = new TI[samples.length]; auto results = new TO[samples.length]; // Initialize some values for the measured samples foreach(i, ref m; meas){ m.L1D_MISS= 100+i; m.L1I_MISS=100-i; m.L1D_READ= 200+i; m.L1D_WRITE=200-i; m.cycles= 10+i; } ref TI getTerm(int i) { return meas[i]; } // compute the metric results for the above measured sample values in parallel //taskPool.amap!(Metrics)(std.algorithm.map!getTerm(samples),results); TR rv1 = met_l1_miss( meas[1]); TR rv2 = met_l1_access( meas[1]); writeln("measurements:", meas[1]); writeln("rv1:", rv1); writeln("rv2:", rv2); writeln("results:", results[1]); }
Re: an example of parallel calculation of metrics
I re-submitted this as: https://issues.dlang.org/show_bug.cgi?id=15135
Re: Checking that a template parameter is an enum
On Thursday, 1 October 2015 at 02:06:48 UTC, Fusxfaranto wrote: /** Returns: true iff all values $(D V) are the same. */ template allSame(V...) // TODO restrict to values only { static if (V.length <= 1) enum bool allSame = true; else enum bool allSame = V[0] == V[1] && allSame!(V[1..$]); } std.traits to the rescue! http://dlang.org/phobos/std_traits.html#isExpressions Using isExpressions!V as a template constraint looks like the behavior you're looking for. Thanks! BTW: Is there some way to turn the recursive definition of `allSame` template allSame(V...) if (isExpressions!(V)) { static if (V.length <= 1) enum allSame = true; else enum allSame = V[0] == V[1] && allSame!(V[1..$]); } into an iterative definition?
Re: Checking that a template parameter is an enum
On Thursday, 1 October 2015 at 02:06:48 UTC, Fusxfaranto wrote: /** Returns: true iff all values $(D V) are the same. */ template allSame(V...) // TODO restrict to values only { static if (V.length <= 1) enum bool allSame = true; else enum bool allSame = V[0] == V[1] && allSame!(V[1..$]); } std.traits to the rescue! http://dlang.org/phobos/std_traits.html#isExpressions Using isExpressions!V as a template constraint looks like the behavior you're looking for. Thanks! BTW: Is there some way to turn the recursive definition of `allSame` into an iterative definition?
Re: Checking that a template parameter is an enum
On 10/01/2015 03:26 PM, Nordlöw wrote: On Thursday, 1 October 2015 at 02:06:48 UTC, Fusxfaranto wrote: /** Returns: true iff all values $(D V) are the same. */ template allSame(V...) // TODO restrict to values only { static if (V.length <= 1) enum bool allSame = true; else enum bool allSame = V[0] == V[1] && allSame!(V[1..$]); } std.traits to the rescue! http://dlang.org/phobos/std_traits.html#isExpressions Using isExpressions!V as a template constraint looks like the behavior you're looking for. Thanks! BTW: Is there some way to turn the recursive definition of `allSame` template allSame(V...) if (isExpressions!(V)) { static if (V.length <= 1) enum allSame = true; else enum allSame = V[0] == V[1] && allSame!(V[1..$]); } into an iterative definition? Very quickly: import std.traits; template allSame(V...) if (isExpressions!(V)) { bool impl_(V...)() { static if (V.length > 1) { foreach (i, _; V[0 .. $ - 1]) { if (V[i] != V[i + 1]) { return false; } } return true; } else { return true; } } enum allSame = impl_!V(); } unittest { static assert( allSame!()); static assert( allSame!(42)); static assert( allSame!(42, 42, 42)); static assert(!allSame!(42, 43, 42)); } Ali
Re: an example of parallel calculation of metrics
This is another attempt with the metric parallel processing. This uses the results only to return an int value, which could be used later as an error return value. The metric value locations are now allocated as a part of the input measurement values tuple. The Tuple vs struct definitions seem to have a big difference in default output formatting. import std.algorithm, std.parallelism, std.range; import std.typecons; import std.meta; import std.stdio; // define some input measurement sample tuples and output metric tuples alias TR = Tuple!(long,"raw",double, "per_cycle"); //struct TR {long raw; double per_cycle;} alias TO = Tuple!(TR, "l1_miss", TR, "l1_access" ); //struct TO {TR l1_miss; TR l1_access; }; alias TI = Tuple!(long, "L1I_MISS",long, "L1D_MISS", long, "L1D_READ", long, "L1D_WRITE", long, "cycles", TO, "res"); // various metric definitions // using Tuples with defined names for each member, and use the names here in the metrics. long met_l1_miss ( ref TI m){ return m.L1I_MISS + m.L1D_MISS; } long met_l1_access ( ref TI m){ return m.L1D_READ + m.L1D_WRITE; } int met_all (ref TI m) { with (m.res){ l1_miss.raw = met_l1_miss(m); l1_access.raw = met_l1_access(m); l1_miss.per_cycle = (m.cycles == 0)? double.nan : l1_miss.raw / cast(double)m.cycles; l1_access.per_cycle = (m.cycles == 0)? double.nan : l1_access.raw / cast(double)m.cycles; } return 0; } // a convenience to use all the metrics above as a list alias Metrics = AliasSeq!(met_all); void main(string[] argv) { auto samples = iota(100); auto meas = new TI[samples.length]; auto results = new int[samples.length]; // Initialize some values for the measured samples foreach(i, ref m; meas){ m.L1D_MISS= 100+i; m.L1I_MISS=100-i; m.L1D_READ= 200+i; m.L1D_WRITE=200-i; m.cycles= 10+i; } ref TI getTerm(int i) { return meas[i]; } // compute the metric results for the above measured sample values in parallel taskPool.amap!(Metrics)(std.algorithm.map!getTerm(samples),results); writeln("measurements:", meas[1]); foreach(ref m; meas){ writeln(m.res); } }
Re: Checking that a template parameter is an enum
On Thursday, 1 October 2015 at 22:37:57 UTC, Ali Çehreli wrote: Very quickly: import std.traits; template allSame(V...) if (isExpressions!(V)) { bool impl_(V...)() { static if (V.length > 1) { foreach (i, _; V[0 .. $ - 1]) { if (V[i] != V[i + 1]) { return false; } } return true; } else { return true; } } enum allSame = impl_!V(); } Will this spare memory in DMD? If so there are a few traits that should be update accordingly, for instance `allSatisfy` and `anySatisfy`. Thanks!
Re: WTF does "Enforcement failed" actually mean?
On 09/30/2015 10:46 PM, Russel Winder via Digitalmars-d-learn wrote: I have the code: reduce!"a+b"(x) where x is a int[] and I get an exception "Enforcement failed" at run time. This gives me enough information to say ¿que? It's coming from the following no-message enforce(): enforce(!r.empty); https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm/iteration.d#L2481 You are using the no-seed version of reduce(), which uses the first element as seed, which means that the range cannot be empty. Ali
Re: an example of parallel calculation of metrics
On 09/30/2015 09:15 PM, Jay Norwood wrote: > alias TO = Tuple!(TR,"L1_MISS", TR, "L1_HIT", TR,"DATA_ACC", TR,"ALL_ACC"); Looks like a bug. Workaround: Get rid of member names there: alias TO = Tuple!(TR, TR, TR, TR); > //taskPool.amap!(Metrics)(std.algorithm.map!getTerm(samples),results); For some reason, having member names prevents 'results' passing one of amap's requirements. The following check in std.parallelism thinks that 'results' does not have random assignable elements if it is a Tuple with member names. else static if(randAssignable!(Args[$ - 1]) && Args.length > 1) { static assert(0, "Wrong buffer type."); } Ali
Re: address of overloaded function
On 2015-10-01 00:48, Freddy wrote: How do you take the address of a specific overloaded function. This won't compile --- import std.range; void main() { ForwardAssignable!int range; int delegate() @property get = void delegate(int) @property set = } --- Not sure why that doesn't work. This works: int foo () { return 0; } void foo (int) {} void main() { int function () a = void function (int) b = } -- /Jacob Carlborg
Re: WTF does "Enforcement failed" actually mean?
On Wed, 2015-09-30 at 23:35 -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 09/30/2015 10:46 PM, Russel Winder via Digitalmars-d-learn wrote: > > I have the code: > > > > reduce!"a+b"(x) > > > > where x is a int[] and I get an exception "Enforcement failed" at > > run > > time. This gives me enough information to say ¿que? > > > > It's coming from the following no-message enforce(): > > enforce(!r.empty); > > > https://github.com/D-Programming-Language/phobos/blob/master/std/algo > rithm/iteration.d#L2481 > > You are using the no-seed version of reduce(), which uses the first > element as seed, which means that the range cannot be empty. Well that explanation (*) makes it abundantly clear that the error reporting from this part of Phobos is distinctly substandard, let alone below par. (*) Which is clear and informative! -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: help me learn to read documentation
On Thursday, 1 October 2015 at 19:15:39 UTC, Robin wrote: The documentation here (http://dgame-dev.de/index.php?controller=learn=package=graphic=Text=0.6)... gives me the Text() class but i dont know how to use "foreground, background, and Font mode" or at least turn it into usable syntax. Those describe simple class members, so you can set them through assignment: Text CurrentFps = new Text(dejavu); // change to white on black CurrentFps.foreground = Color4b.White; CurrentFps.background = Color4b.Black; // change mode CurrentFps.mode = Font.Mode.Shaded; I haven't actually used this library, but since the doc describes it with variable syntax (`Color4b foreground;`) that means you should be able to just assign to them like ordinary object member variables.
Re: Checking that a template parameter is an enum
On Thursday, 1 October 2015 at 22:41:21 UTC, Nordlöw wrote: Will this spare memory in DMD? If so there are a few traits that should be update accordingly, for instance `allSatisfy` and `anySatisfy`. Thanks! Highly doubtful as CTFE already allocates like there's no tomorrow.
Re: help me learn to read documentation
On Friday, 2 October 2015 at 01:20:50 UTC, Adam D. Ruppe wrote: On Thursday, 1 October 2015 at 19:15:39 UTC, Robin wrote: [...] Those describe simple class members, so you can set them through assignment: Text CurrentFps = new Text(dejavu); // change to white on black CurrentFps.foreground = Color4b.White; CurrentFps.background = Color4b.Black; // change mode CurrentFps.mode = Font.Mode.Shaded; I haven't actually used this library, but since the doc describes it with variable syntax (`Color4b foreground;`) that means you should be able to just assign to them like ordinary object member variables. Wow, thank you so much. I have never seen code like that before but the documentation there made me scratch my head. Thank you.
How to break gdb on D exception ?
Currently it works fine when throwing with core.exception functions 'on', like explained in the wiki, for example: --- break onFinalizeError --- But I can't manage to break when a new Exception instance is thrown in the code: --- throw new Exception("ouch"); --- none of the following GB commands work: --- catch catch catch throw catch signal all catch signal --- It looks like there are some tricks, like put a break on the vtbl of the base throwable class (no quite sure about this to be honest...) Does anyone manage this ?
Re: How to break gdb on D exception ?
On Friday, 2 October 2015 at 04:24:11 UTC, Adam D. Ruppe wrote: On Friday, 2 October 2015 at 03:58:45 UTC, BBasile wrote: none of the following GB commands work: give break d_throw or maybe `break d_throwc` a try unfortunately it doesn't work, i get --- (gdb) Function "d_throw"/"d_throwc" not defined.
Re: How to break gdb on D exception ?
On Friday, 2 October 2015 at 04:46:51 UTC, BBasile wrote: On Friday, 2 October 2015 at 04:24:11 UTC, Adam D. Ruppe wrote: On Friday, 2 October 2015 at 03:58:45 UTC, BBasile wrote: none of the following GB commands work: give break d_throw or maybe `break d_throwc` a try unfortunately it doesn't work, i get --- (gdb) Function "d_throw"/"d_throwc" not defined. it was almost that actually, 'break _d_throwc
Re: How to break gdb on D exception ?
On Friday, 2 October 2015 at 03:58:45 UTC, BBasile wrote: Does anyone manage this ? I meant: Does anyone master this ?
Re: How to break gdb on D exception ?
On Friday, 2 October 2015 at 03:58:45 UTC, BBasile wrote: none of the following GB commands work: give break d_throw or maybe `break d_throwc` a try
How to use std.experimental.logger?
I tried it on Windows today using the latest DMD installer, all default logger and settings. I get: safe function [...].logImplf cannot call system function 'std.format.formattedWrite!(MsgRange, char, Result!()).formattedWrite' How do I make formatted logging work?
Re: How to use std.experimental.logger?
On Thursday, 1 October 2015 at 08:21:35 UTC, Panke wrote: I tried it on Windows today using the latest DMD installer, all default logger and settings. I get: safe function [...].logImplf cannot call system function 'std.format.formattedWrite!(MsgRange, char, Result!()).formattedWrite' How do I make formatted logging work? Would be easier to diagnose your problem if you pasted your code and uncut complaint from the compiler. Anyway, the following works, so it may give you a hint: $ cat log.d import std.experimental.logger; void main() { logf("just log %s and %d", "this", 1337); } $ dmd log.d $ ./log 2015-10-01T11:23:57.291:log.d:main:5 just log this and 1337
Re: WTF does "Enforcement failed" actually mean?
On Thursday, 1 October 2015 at 07:08:00 UTC, Russel Winder wrote: On Wed, 2015-09-30 at 23:35 -0700, Ali Çehreli via Digitalmars-d-learn wrote: On 09/30/2015 10:46 PM, Russel Winder via Digitalmars-d-learn wrote: > [...] It's coming from the following no-message enforce(): enforce(!r.empty); https://github.com/D-Programming-Language/phobos/blob/master/std/algo rithm/iteration.d#L2481 You are using the no-seed version of reduce(), which uses the first element as seed, which means that the range cannot be empty. Well that explanation (*) makes it abundantly clear that the error reporting from this part of Phobos is distinctly substandard, let alone below par. (*) Which is clear and informative! Bug report? Then it'll get fixed.
Re: Range of variables
On Wednesday, 30 September 2015 at 20:11:56 UTC, Freddy wrote: Is there a way to make a range of a variables lazily? --- int var1; int var2; void func() { int var3; auto range = /*range of var1,var2,var3*/ ; } --- std.range.iota Atila