Re: Reading and wiping notes also adding more notes
On Tuesday, 18 October 2022 at 05:48:27 UTC, Ali Çehreli wrote: On 10/17/22 22:40, Joel wrote: > I have two text fields. The one on the left has the whole text, new > stuff being added to the bottom. The one on the right has text I've been > wiping as I'm reading. I think this can be modelled as a string array and an index showing where the active part starts: import std; struct Notes { string[] whole; size_t activeIndex; void add(string line) { whole ~= line; } string[] activeText() { return whole[activeIndex..$]; } void wipeText() { ++activeIndex; } } void main() { auto input = [ "I went for a walk and fell down a hole.", "There was a D guy on the roof.", "That was a tricky problem!", ]; Notes notes; // add() to add() input.each!(line => notes.add(line)); // activeText() will show the active part // wipeText() will move forward } Ali I want to have two text files, for each notes I'm reading and wiping. Keep adding to one and reading wiping and updating the other one. I want my program to process them by updating the temporary notes.
Re: Reading and wiping notes also adding more notes
On Tuesday, 18 October 2022 at 05:48:27 UTC, Ali Çehreli wrote: On 10/17/22 22:40, Joel wrote: > I have two text fields. The one on the left has the whole text, new > stuff being added to the bottom. The one on the right has text I've been > wiping as I'm reading. I think this can be modelled as a string array and an index showing where the active part starts: import std; struct Notes { string[] whole; size_t activeIndex; void add(string line) { whole ~= line; } string[] activeText() { return whole[activeIndex..$]; } void wipeText() { ++activeIndex; } } void main() { auto input = [ "I went for a walk and fell down a hole.", "There was a D guy on the roof.", "That was a tricky problem!", ]; Notes notes; // add() to add() input.each!(line => notes.add(line)); // activeText() will show the active part // wipeText() will move forward } Ali void upNotes() { string left, right; left=_editBoxMain.text.to!string; right=_editBoxRight.text.to!string; // left is the whole doc // right is the read and wipe doc // Add the new stuff at the bottom of left and append it to the right size_t chunkSize=100; string chunkText, appendText; if (right.length<100) chunkSize=right.length; // mixin(tce("chunkSize left.length right.length right[$-chunkSize..$]".split)); chunkText=left[$-chunkSize..$]; size_t l=left.length-1, r=right.length-1; while(true) { if (right[r..$]!=left[l..$]) { r-=1; l-=1; } else break; } right=right~left[r..$]; //appendText; _editBoxRight.text=right.to!dstring; }
Re: parallel is slower than serial
On Tuesday, 18 October 2022 at 11:56:30 UTC, Yura wrote: ```D // Then for each Sphere, i.e. dot[i] // I need to do some arithmetics with itself and other dots // I have only parallelized the inner loop, i is fixed. It's usually a much better idea to parallelize the outer loop. Even OpenMP tutorials explain this: https://ppc.cs.aalto.fi/ch3/nested/ (check the "collapse it into one loop" suggestion from it). ```D for (auto j=0;j This way of appending to an array is very slow and `A ~= Ai[j];` is much faster. And even better would be `A ~= Ai;` instead of the whole loop.
Re: library to solve the system of linear equations
On Tuesday, 18 October 2022 at 09:56:09 UTC, Siarhei Siamashka wrote: On Monday, 17 October 2022 at 20:05:24 UTC, mw wrote: On Monday, 17 October 2022 at 19:54:12 UTC, Yura wrote: it is possible to install the most recent ldc and gdc compilers on Ubuntu 18.04? Yes, I used LDC on the same system. What's the recommended way to have up to date D compilers in Ubuntu? I just download the official prebuilt binary from the ldc github repo.
Re: parallel is slower than serial
On 10/18/22 06:24, Guillaume Piolat wrote: > To win something with OS threads, you must think of tasks that takes on > the order of milliseconds rather than less than 0.1ms. > Else you will just pay extra in synchronization costs. In other words, the OP can adjust work unit size. It is on the official documentation but I also mention it on slide 72 of the section that starts at the following point: https://youtu.be/dRORNQIB2wA?t=1327 Ali
parallel is slower than serial
Dear All, I am trying to make a simple code run in parallel. The parallel version works, and gives the same number as serial albeit slower. First, the parallel features I am using: import core.thread: Thread; import std.range; import std.parallelism:parallel; import std.parallelism:taskPool; import std.parallelism:totalCPUs; // Then, I have an array of structures shared Sphere [] dot; // Each Sphere is struct Sphere { string El; double x; double y; double z; double S; double Z; double V; } // Then for each Sphere, i.e. dot[i] // I need to do some arithmetics with itself and other dots // I have only parallelized the inner loop, i is fixed. // parallel loop auto I = std.range.iota(0,dot.length); shared double [] Ai; Ai.length = dot.length; foreach (j;parallel(I)) { Ai[j] = GETAij (i, j, dot[i], dot[j]); } for (auto j=0;jWhat I am doing wrong? Any advanced options for the ldc2 compiler? Many thanks in advance!
Re: parallel is slower than serial
On Tuesday, 18 October 2022 at 11:56:30 UTC, Yura wrote: What I am doing wrong? The size of your task are way too small. To win something with OS threads, you must think of tasks that takes on the order of milliseconds rather than less than 0.1ms. Else you will just pay extra in synchronization costs.
Re: library to solve the system of linear equations
On Monday, 17 October 2022 at 20:22:47 UTC, jmh530 wrote: If you have a problem with support for mir, submit a bug report. I don't think gdc is supported, but ldc should be. GDC12 has finally upgraded its D language frontend version to 2.100 and I have successfully compiled a simple lubeck example by it after applying this patch: https://github.com/libmir/mir-core/pull/72 (it's merged now and the next version of mir-core will probably have it included). But GDC isn't officially supported yet and isn't even getting tested by the current libmir's CI pipeline. Maybe GDC12 can be added to it now? There's an open issue about troubles with LDC 1.24.0 from Debian 11: https://github.com/libmir/mir-core/issues/64 Libmir developers seem to be very eager to try every new language feature and break compatibility with D compilers unless these compilers are always super fresh. That said, it's still possible to specify older versions of mir libraries in dub.sdl and compile the lubeck example by LDC 1.24.0 or DMD 2.091.1 with something like this: ```D /+dub.sdl: dependency "lubeck" version="==1.5.1" dependency "mir-core" version="==1.1.85" dependency "mir-algorithm" version="==3.11.7" +/ ```
Re: library to solve the system of linear equations
On Monday, 17 October 2022 at 20:05:24 UTC, mw wrote: On Monday, 17 October 2022 at 19:54:12 UTC, Yura wrote: it is possible to install the most recent ldc and gdc compilers on Ubuntu 18.04? Yes, I used LDC on the same system. What's the recommended way to have up to date D compilers in Ubuntu? I'm using Gentoo Linux and there's a 'dlang' overlay for various recent versions of DMD and LDC. I can also compile any version of GDC myself either via portage or just from a GCC sources tarball or git.
Re: parallel is slower than serial
Thank you, folks, for your hints and suggestions! Indeed, I re-wrote the code and got it substantially faster and well paralleled. Insted of making inner loop parallel, I made parallel both of them. For that I had to convert 2d index into 1d, and then back to 2d. Essentially I had to calculate each element Aij of the matrix, and then I put everything to 1d array. And yes, A = A ~ Aij was very slow, to avoid it I had to use 2d -> 1d mapping. I will check your solution as well as I like it too. The more I use the D Language, the more I like it. On Tuesday, 18 October 2022 at 16:07:22 UTC, Siarhei Siamashka wrote: On Tuesday, 18 October 2022 at 11:56:30 UTC, Yura wrote: ```D // Then for each Sphere, i.e. dot[i] // I need to do some arithmetics with itself and other dots // I have only parallelized the inner loop, i is fixed. It's usually a much better idea to parallelize the outer loop. Even OpenMP tutorials explain this: https://ppc.cs.aalto.fi/ch3/nested/ (check the "collapse it into one loop" suggestion from it). ```D for (auto j=0;j This way of appending to an array is very slow and `A ~= Ai[j];` is much faster. And even better would be `A ~= Ai;` instead of the whole loop.
Re: Find out what type my class is being converted to for comparisons
Well its not a type system issue. Making u = n, that'll returns true. So the problem almost certainly lies with IEEE-754. They are horrible to compare (float/double). Unfortunately you are stuck calling functions like isClose to compare. https://dlang.org/phobos/std_math_operations.html#.isClose Full code extracted from above: ```d import std; void main() { auto m = new Matrix!(2)(); m.data = [1.0, 0.0, 0.0, 1.0].dup; auto n = new Matrix!(2)(); n.data = [2.0, 3.0, 4.0, 5.0].dup; auto u = mult(m, n); writeln("u.data vs n.data:"); for (int i = 0; i < u.data.length; ++i) writeln(u.data[i], "\t", n.data[i]); // using opEquals() directly is working, but it doesn't seem to be being used //assert(opEquals(u,n),"\"opEquals(u, n)\" is failing."); // this works fine assert(u == n, "\"u == n\" is failing."); // this fails. Why? } class Matrix(size_t X, size_t Y = X) { const size_t x_length = X; const size_t y_length = Y; double[X * Y] data; /// both matrices have to have an identical shape to compare /// each element must be identical to match bool opEquals(size_t X, size_t Y)(const Matrix!(X, Y) m1, const Matrix!(X, Y) m2) { for (int i = 0; i < m1.data.length; ++i) if (m1.data[i] != m2.data[i]) return false; return true; } } ```
Re: warning LNK4255 - How to solve this warning
On 10/18/22 12:26, Hipreme wrote: > Is there any way to know which files produced this error or at least the > symbol names that are clashing? I'm totally helpless about this error. There is 'nm' on Posix systems that lists symbols in object files (including libraries and programs). Ali
Re: library to solve the system of linear equations
Yes, did the same and it worked. The amazing thing is that the system solver turned out to be natively parallel and runs smoothly! On Tuesday, 18 October 2022 at 15:22:02 UTC, mw wrote: On Tuesday, 18 October 2022 at 09:56:09 UTC, Siarhei Siamashka wrote: On Monday, 17 October 2022 at 20:05:24 UTC, mw wrote: On Monday, 17 October 2022 at 19:54:12 UTC, Yura wrote: it is possible to install the most recent ldc and gdc compilers on Ubuntu 18.04? Yes, I used LDC on the same system. What's the recommended way to have up to date D compilers in Ubuntu? I just download the official prebuilt binary from the ldc github repo.
Find out what type my class is being converted to for comparisons
I am in the process of building a matrix class (uni project, with my choice of programming language) and appear to have run into a problem that I'm not too sure how to fix. My class uses templates to define the shape of the matrix, although I'm not sure if that matters. As part of my class, I included a opEquals, but when I try to assert that a matrix created by multiplying with the identity matrix matches the output (I checked with liberal writeln()s to make sure they do) but my opEquals() function (I moved it out of the class as I kept getting errors saying it was supposed to be non-const, and couldn't figure out how to fix that either) just isn't called. --- Matrix code (the only bit of the class used by opEquals): ``` class Matrix(size_t X, size_t Y = X){ const size_t x_length = X; const size_t y_length = Y; double[X*Y] data; ... } ``` The entirety of opEquals: ``` /// both matrices have to have an identical shape to compare /// each element must be identical to match bool opEquals(size_t X, size_t Y)(const Matrix!(X,Y) m1, const Matrix!(X,Y) m2) { for (int i = 0; i < m1.data.length; ++i) if (m1.data[i] != m2.data[i]) return false; return true; } ``` and the code that excepts: ``` void main() { auto m = new Matrix!(2)(); m.data = [1.0,0.0,0.0,1.0].dup; auto n = new Matrix!(2)(); n.data = [2.0,3.0,4.0,5.0].dup; auto u = mult(m,n); writeln("u.data vs n.data:"); for (int i = 0; i < u.data.length; ++i) writeln(u.data[i], "\t", n.data[i]); // using opEquals() directly is working, but it doesn't seem to be being used //assert(opEquals(u,n),"\"opEquals(u, n)\" is failing."); // this works fine assert(u == n,"\"u == n\" is failing."); // this fails. Why? } ``` --- Any help would be very much appreciated. A way to figure out what the '==' is converting its arguments to would also be great, but I'm not sure it exists (beyond just sitting down and trying to work it out myself, of course)
Re: Find out what type my class is being converted to for comparisons
On Tuesday, 18 October 2022 at 18:59:37 UTC, rikki cattermole wrote: Well its not a type system issue. Making u = n, that'll returns true. So the problem almost certainly lies with IEEE-754. They are horrible to compare (float/double). Unfortunately you are stuck calling functions like isClose to compare. https://dlang.org/phobos/std_math_operations.html#.isClose Hi Rikki, thanks for the rapid reply. I'm not so sure it isn't a type issue, tbh. The only reason being that the opEquals() works whenever I call it directly (ignoring the comparison of proximity to a value for the moment) but doesn't work when I use "==" stripped down to just the two lines that are causing issues: ``` //assert(opEquals(u,n)); // this works fine assert(u == n); // this fails. Why? ``` I guess to put it more bluntly, I should ask "why is opEquals working when I call it directly, but when I try to use the equality check, which should be CALLING opEquals, it doesn't appear to do so?"
warning LNK4255 - How to solve this warning
I get the warning `warning LNK4255: library contain multiple objects of the same name; linking object as if no debug info` when dealing a project with multiple static libraries. Is there any way to know which files produced this error or at least the symbol names that are clashing? I'm totally helpless about this error.
Re: Find out what type my class is being converted to for comparisons
On Tuesday, 18 October 2022 at 18:53:41 UTC, Matthew Rushworth wrote: The entirety of opEquals: ``` /// both matrices have to have an identical shape to compare /// each element must be identical to match bool opEquals(size_t X, size_t Y)(const Matrix!(X,Y) m1, const Matrix!(X,Y) m2) { for (int i = 0; i < m1.data.length; ++i) if (m1.data[i] != m2.data[i]) return false; return true; } ``` A free-standing opEquals won't work. It needs to be a method of the class. So: ```d class Matrix(size_t X, size_t Y = X) { /* ... */ bool opEquals(const Matrix m2) { for (int i = 0; i < this.data.length; ++i) if (this.data[i] != m2.data[i]) return false; return true; } } ```
Re: Can someone tell me what the compiler thought I was trying to do?
On Wednesday, 19 October 2022 at 01:30:23 UTC, H. S. Teoh wrote: On Wed, Oct 19, 2022 at 01:15:37AM +, Adam D Ruppe via it only applies to types, not to functions. Wat... so what's the use of it then? So it's not possible to mark the return value of an int function @mustUse without making, in theory, *all* ints @mustUse? I must confess I'm baffled as to the purpose of this strange design. Same, can't believe it. Is there any (design) doc about this?
Re: warning LNK4255 - How to solve this warning
On Tuesday, 18 October 2022 at 19:38:39 UTC, Ali Çehreli wrote: On 10/18/22 12:26, Hipreme wrote: > Is there any way to know which files produced this error or at least the > symbol names that are clashing? I'm totally helpless about this error. There is 'nm' on Posix systems that lists symbols in object files (including libraries and programs). Ali I have added under lflags : "/VERBOSE" which activates the verbose mode and "/WX" which treats the warnings as errors (because there is just so many things on linking step) I found some functions but nothing of them feels out of the ordinary. Treating this module as sourceLibrary instead of staticLibrary doesn't cause this warning though
Re: Can someone tell me what the compiler thought I was trying to do?
On 19/10/2022 2:30 PM, H. S. Teoh wrote: On Wed, Oct 19, 2022 at 01:15:37AM +, Adam D Ruppe via Digitalmars-d-learn wrote: On Wednesday, 19 October 2022 at 00:57:31 UTC, H. S. Teoh wrote: Has it really been implemented? I tested the latest git master, the following code doesn't compile: it only applies to types, not to functions. Wat... so what's the use of it then? So it's not possible to mark the return value of an int function @mustUse without making, in theory, *all* ints @mustUse? I must confess I'm baffled as to the purpose of this strange design. Oh but it gets better: From C23 draft: The nodiscard attribute shall be applied to the identifier in a function declaration or to the definition of a structure, union, or enumeration type. If an attribute argument clause is present, it shall have the form: ( string-literal )
Re: Find out what type my class is being converted to for comparisons
On Tuesday, 18 October 2022 at 20:02:02 UTC, ag0aep6g wrote: On Tuesday, 18 October 2022 at 18:53:41 UTC, Matthew Rushworth wrote: The entirety of opEquals: ``` /// both matrices have to have an identical shape to compare /// each element must be identical to match bool opEquals(size_t X, size_t Y)(const Matrix!(X,Y) m1, const Matrix!(X,Y) m2) { for (int i = 0; i < m1.data.length; ++i) if (m1.data[i] != m2.data[i]) return false; return true; } ``` A free-standing opEquals won't work. It needs to be a method of the class. So: ```d class Matrix(size_t X, size_t Y = X) { /* ... */ bool opEquals(const Matrix m2) { for (int i = 0; i < this.data.length; ++i) if (this.data[i] != m2.data[i]) return false; return true; } } ``` Thank you, that worked perfectly, not sure exactly what I did wrong, I'm assuming I forgot to make the parameter a const variable
Re: Can someone tell me what the compiler thought I was trying to do?
https://github.com/dlang/dmd/blob/master/druntime/src/core/attribute.d#L292
Re: Can someone tell me what the compiler thought I was trying to do?
On Wednesday, 19 October 2022 at 00:57:31 UTC, H. S. Teoh wrote: Has it really been implemented? I tested the latest git master, the following code doesn't compile: it only applies to types, not to functions.
Re: Can someone tell me what the compiler thought I was trying to do?
On Wed, Oct 19, 2022 at 01:15:37AM +, Adam D Ruppe via Digitalmars-d-learn wrote: > On Wednesday, 19 October 2022 at 00:57:31 UTC, H. S. Teoh wrote: > > Has it really been implemented? I tested the latest git master, the > > following code doesn't compile: > > it only applies to types, not to functions. Wat... so what's the use of it then? So it's not possible to mark the return value of an int function @mustUse without making, in theory, *all* ints @mustUse? I must confess I'm baffled as to the purpose of this strange design. T -- Doubt is a self-fulfilling prophecy.
Re: Can someone tell me what the compiler thought I was trying to do?
On Sat, Oct 15, 2022 at 12:47:02AM +, Mike Parker via Digitalmars-d-learn wrote: > On Friday, 14 October 2022 at 22:17:52 UTC, H. S. Teoh wrote: > > > Given that this particular trap crops up regularly, perhaps some > > sort of warning ought to be added. Once the @nodiscard DIP is > > accepted & implemented this should be easy to do. > > > > Seems like you're behind the times! The DIP was accepted and implemented > with some changes: > > https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1038.md#final-review Has it really been implemented? I tested the latest git master, the following code doesn't compile: -- @mustUse int fun() { return 455; } void main() { fun(); } -- Compiler output: -- /tmp/test.d(1): Error: undefined identifier `mustUse` -- I tried @mustuse, @nodiscard, @noDiscard, no good. What am I missing? T -- This is not a sentence.
Re: Can someone tell me what the compiler thought I was trying to do?
On Wednesday, 19 October 2022 at 01:34:54 UTC, mw wrote: Is there any (design) doc about this? scroll up, click the link from this very thread. https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1038.md#design-goals-and-possible-alternatives
Re: Can someone tell me what the compiler thought I was trying to do?
On Wednesday, 19 October 2022 at 05:41:26 UTC, zjh wrote: Why can't do it `in one step`? Why always afraid to `add features`? C++ is `so complicated` ,but that people are not afraid to continue to `add features`. There is also `class level private`. I saw someone start it by himself, and he felt very happy. It completely conforms to the encapsulation, but it seems that the latest D has no switch about it. In my opinion, as long as `users` have reasonable needs, languages should added corresponding features, instead of becoming religions. `Some features` are very popular for users,I really don't know why they didn't add it.
Re: Can someone tell me what the compiler thought I was trying to do?
On Wednesday, 19 October 2022 at 01:49:26 UTC, mw wrote: On Wednesday, 19 October 2022 at 01:38:27 UTC, Adam D Ruppe wrote: On Wednesday, 19 October 2022 at 01:34:54 UTC, mw wrote: Is there any (design) doc about this? scroll up, click the link from this very thread. https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1038.md#design-goals-and-possible-alternatives """ Rather than make either sacrifice, this DIP proposes a design that allows both rigor and simplicity to be maintained, and reserves the possibility for a future DIP to allow @mustUse as a function attribute. """ Another future DIP? I think this DIP is flawed for not using "@mustUse as a function attribute" @mustuse as a function attribute was in the original version of the DIP. It was vetoed by Walter. Thus, only the type attribute remains in the accepted version. FWIW, this is the same path that #[must_use] took in Rust. It was added originally as a type attribute only, and later had its usage extended to functions.
Re: Can someone tell me what the compiler thought I was trying to do?
On Wednesday, 19 October 2022 at 01:34:54 UTC, mw wrote: On Wednesday, 19 October 2022 at 01:30:23 UTC, H. S. Teoh wrote: On Wed, Oct 19, 2022 at 01:15:37AM +, Adam D Ruppe via it only applies to types, not to functions. Wat... so what's the use of it then? So it's not possible to mark the return value of an int function @mustUse without making, in theory, *all* ints @mustUse? I must confess I'm baffled as to the purpose of this strange design. Same, can't believe it. Is there any (design) doc about this? It's right there in the summary of the Final Review of the DIP that I linked above: https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1038.md#final-review
Re: Can someone tell me what the compiler thought I was trying to do?
On Wednesday, 19 October 2022 at 01:38:27 UTC, Adam D Ruppe wrote: On Wednesday, 19 October 2022 at 01:34:54 UTC, mw wrote: Is there any (design) doc about this? scroll up, click the link from this very thread. https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1038.md#design-goals-and-possible-alternatives """ Rather than make either sacrifice, this DIP proposes a design that allows both rigor and simplicity to be maintained, and reserves the possibility for a future DIP to allow @mustUse as a function attribute. """ Another future DIP? I think this DIP is flawed for not using "@mustUse as a function attribute"
Re: Can someone tell me what the compiler thought I was trying to do?
On Wednesday, 19 October 2022 at 03:10:29 UTC, Mike Parker wrote: It's right there in the summary of the Final Review of the DIP that I linked above: https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1038.md#final-review I meant to say the summary of the formal assessment. One of the conditions of acceptance was this one: develop rules for handling covariance and contravariance when applied to functions. Paul opted instead to do just have it apply to types for now. A future enhancement can take on extending it to functions. As he noted above, that's the approach Rust took as well.
Re: Can someone tell me what the compiler thought I was trying to do?
@mustuse as a function attribute was in the original version of the DIP. It was vetoed by Walter. Thus, only the type attribute remains in the accepted version. Let's continue the discussion here: https://forum.dlang.org/thread/nmornkxaxddfziqmq...@forum.dlang.org in general, it's about: command query separation principle
Re: Can someone tell me what the compiler thought I was trying to do?
On Wednesday, 19 October 2022 at 04:59:40 UTC, mw wrote: ... Why can't do it `in one step`? Why always afraid to `add features`? C++ is `so complicated` ,but that people are not afraid to continue to `add features`.