Re: Improving dot product for standard multidimensional D arrays
it is difficult to write an efficient matrix matrix multiplication in any language. If you want a fair comparison, implement your naive method in python and compare those timings. Op di 3 mrt. 2020 om 04:20 schreef 9il via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com>: > On Sunday, 1 March 2020 at 20:58:42 UTC, p.shkadzko wrote: > > Hello again, > > > > Thanks to previous thread on multidimensional arrays, I managed > > to play around with pure D matrix representations and even > > benchmark a little against numpy: > > > > [...] > > Matrix multiplication is about cache-friendly blocking. > https://www.cs.utexas.edu/users/pingali/CS378/2008sp/papers/gotoPaper.pdf > > `mir-blas` package can be used for matrix operations for ndslice. > `cblas` - if you want to work with your own matrix type . >
Re: Please don't do a DConf 2018, consider alternatives
While I have never attended dconf itself, conferences itself usually aren't about the talks but about the people you meet and get to interact with. Op di 2 okt. 2018 om 10:15 schreef Joakim via Digitalmars-d < digitalmars-d@puremagic.com>: > On Tuesday, 2 October 2018 at 08:08:38 UTC, Gary Willoughby wrote: > > On Tuesday, 2 October 2018 at 07:32:58 UTC, Joakim wrote: > >> Thank you for making clear that the real reason you and some > >> others like the current format is because you want to have a > >> fun "vacation"- as I pointed out in that earlier thread- > >> rather than anything to do with D or advancing the ecosystem. > > > > Yes, please let's not have any fun at Dconf this year!!! /s > > Then why are you sitting around listening to boring tech talks on > your "super-fun" vacation? Get W and a bunch of other D devs > and go on a boat tour of the Greek islands! You'll have a lot > more fun!!! endSarcasm() >
Re: What do you want to see for a mature DLang?
>I'd like to see proper DLL (shared library) support and DIP45 implemented. I'm making a project that I hope in the future will be extendable with D plugins. Out of curiousity, what's wrong with the current dll support? 2017-12-29 11:36 GMT+01:00 angel via Digitalmars-d < digitalmars-d@puremagic.com>: > Built-in tuples: > > {val1, val2} = func(); > > > On Friday, 29 December 2017 at 07:53:51 UTC, IM wrote: > >> I will start: >> >>-- Better compiler errors, better compiler errors, better compiler >> errors. >> >> >> I really wish that the compiler errors could receive some refinement. >> Mostly it feels like some error text just being thrown at me. It needs to >> be better formatted, more helpful, with suggestions about how to fix (if >> possible). >> >> To illustrate my point: >> >> - See the compile errors I've just encountered with DMD: >> https://cdn.pbrd.co/images/H0q609l.png >> >> - Now compare that with an error produced by rustc: >> https://cdn.pbrd.co/images/H0q6bLi.png >> >> >> Simple things like these make a big difference. D Lang has been around >> for a long while now, and hence signs of its maturity has to show >> everywhere, especially in the compiler, as well as the package manager. >> > > >
Re: D is Multiplatform[DUVIDA]
It's a compiled language, it'll behave like c++. 2017-09-08 7:13 GMT+02:00 dark777 via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com>: > On Friday, 8 September 2017 at 03:56:25 UTC, rikki cattermole wrote: > >> On 08/09/2017 3:08 AM, dark777 wrote: >> >>> On Friday, 8 September 2017 at 00:09:08 UTC, solidstate1991 wrote: >>> On Thursday, 7 September 2017 at 23:58:05 UTC, dark777 wrote: > Good night, did you want to know this? Is the DE language > cross-platform or cross-compile like C ++? > GDC and LDC has multi-platform support, I'm currently working on an ARM backend for DMD. >>> >>> so does it mean that if I develop a program using the D language in BSD >>> creating generic resources for example and compiling on windows, linux and >>> darwin it would work fine? >>> >> >> Each platform has its own unique behavior and related code. >> Gotta try it to know for certain. >> >> But that is unrelated to D in the most part :) >> > > but in any case then the D language can be considered multiplatform? >
Re: very odd directx 11 error
zeroMemory(, scd.sizeof); void zeroMemory(void* ad,size_t size){ (cast(byte*)& ad)[0 .. size] = 0; } I was totally corrupting my stack and it's not even needed in D, the compiler zero's it out automatically. Mystery solved, thanks a lot irc (adam,wolfgang,...) 2017-08-24 17:26 GMT+02:00 maarten van damme <maartenvd1...@gmail.com>: > I should probably add that the error is a hresult, being 0 when it works > but -2005270527 when it fails. > > 2017-08-24 17:24 GMT+02:00 maarten van damme <maartenvd1...@gmail.com>: > >> Hi all. >> >> This works (dub --arch=x86_mscoff) http://dpaste.com/1XCJEX7 but this >> fails : http://dpaste.com/1C7WMB7 . >> >> Notice that all I've done is manually inlined init3d... >> >> You can compile this with the following dub.json >> >> http://dpaste.com/2QBQFSX >> >> Any help would be appreciated, it make absolutely no sense to me. >> > >
Re: very odd directx 11 error
I should probably add that the error is a hresult, being 0 when it works but -2005270527 when it fails. 2017-08-24 17:24 GMT+02:00 maarten van damme <maartenvd1...@gmail.com>: > Hi all. > > This works (dub --arch=x86_mscoff) http://dpaste.com/1XCJEX7 but this > fails : http://dpaste.com/1C7WMB7 . > > Notice that all I've done is manually inlined init3d... > > You can compile this with the following dub.json > > http://dpaste.com/2QBQFSX > > Any help would be appreciated, it make absolutely no sense to me. >
very odd directx 11 error
Hi all. This works (dub --arch=x86_mscoff) http://dpaste.com/1XCJEX7 but this fails : http://dpaste.com/1C7WMB7 . Notice that all I've done is manually inlined init3d... You can compile this with the following dub.json http://dpaste.com/2QBQFSX Any help would be appreciated, it make absolutely no sense to me.
Re: How to get uniq to return an array?
have you tried std.range's .array? 2017-07-04 13:00 GMT+02:00 PumpkinCake via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com>: > I'm trying to strip repeated values out of an int array using uniq. It's > returning a UniqResult which can't be accessed like an array... how can I > get it to return an array, or cast whatever it is returning to be an array? >
Re: Neural Networks / ML Libraries for D
There is mir https://github.com/libmir/mir which is geared towards machine learning, I don't know if it has anything about neural networks, I've yet to use it. If you're only interested in neural networks, I've used FANN (a C library) together with D and it worked very well. 2016-10-25 13:17 GMT+02:00 Saurabh Das via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com>: > Hello, > > Are there any good ML libraries for D? In particular, looking for a neural > network library currently. Any leads would be appreciated. > > Thanks, > Saurabh > >
Re: Females in the community.
> This very sexist and you are clearly either very young or a closet misogynist Great, so you answer a poorly thought out attempt to encourage women to join this community by bashing on younger people?
Re: D for project in computational chemistry
I'm not a programmer myself and used D for a project in computational electromagnetics. While I had to implement numerical integration and a bit of linear algebra which was annoying (would be really useful in phobos), it was a joy to work with and the resulting program was incredibly fast. Most others used matlab and the difference in speed was more than a factor 100. Not only that, prototyping went quicker in D. I've also written a simulation of the dual slit experiment which I'll drop somewhere on github once the code is presentable. So, if you don't mind having to implement a few algorithms that are already available in numpy, D will be pleasant and fast. 2015-08-04 11:48 GMT+02:00 Chris via Digitalmars-d digitalmars-d@puremagic.com: On Sunday, 2 August 2015 at 16:25:18 UTC, Yura wrote: Dear D coders/developers, I am just thinking on one project in computational chemistry, and it is sort of difficult for me to pick up the right language this project to be written. The project is going to deal with the generation of the molecular structures and will resemble to some extent some bio-informatic stuff. Personally I code in two languages - Python, and a little bit in C (just started to learn this language). While it is easy to code in Python there are two things I do not like: 1) Python is slow for nested loops (much slower comparing to C) 2) Python is not compiled. However, I want to work with a code which can be compiled and distributed as binaries (at least at the beginning). When it comes to C, it is very difficult to code (I am a chemist rather than computer scientist). The pointers, memory allocation, absence of the truly dynamically allocated arrays, etc, etc make the coding very long. C is too low level I believe. I just wander how D would be suitable for my purpose? Please, correct me if I am wrong, but in D the need of pointers is minimal, there is a garbage collector, the arrays can be dynamically allocated, the arrays can be sliced, ~=, etc which makes it similar to python at some extent. I tried to write a little code in D and it was very much intuitive and similar to what I did both in Python and C. Any hints/thoughts/advises? With kind regards, Yury I agree with bachmeier. You cannot go wrong. You mentioned nested loops. D allows you to concatenate (or pipe) loops. So instead of foreach { foreach { foreach { } } } you have something like int[] numbers = [-2, 1, 6, -3, 10]; foreach (ref n; numbers .map!(a = a * 5) // multiply each value by 5 .filter!(a = a 0)) // filter values that are 0 or less { // Do something } or just write auto result = numbers.map!(a = a * 5).filter!(a = a 0); // == result = [5, 30, 50] You'd probably want to have a look at: http://dlang.org/phobos/std_algorithm.html and ranges (a very important concept in D): http://ddili.org/ders/d.en/ranges.html http://wiki.dlang.org/Component_programming_with_ranges Excessive use of nested loops is not necessary in D nor is it very common. This makes the code easier to maintain and less buggy in the end.
Re: store template value
Oh, neat. This saves the day :) 2015-08-01 23:22 GMT+02:00 Ali Çehreli digitalmars-d-learn@puremagic.com: On 08/01/2015 08:37 AM, maarten van damme via Digitalmars-d-learn wrote: I have a class that creates a task in it's constructor. How do I store this created task as one of it's value members and later on call .yieldForce()? Tasks can be created with a function pointer 'function parameter' as well. (This has already been added to Programming in D but it is not available on the web site yet.) I learned the exact type by the help of pragma(msg) below and used it to create MyTask and myTasks: import std.parallelism; double foo(int i) { return i * 1.5; } double bar(int i) { return i * 2.5; } void main() { auto tasks = [ task(foo, 1), task(bar, 2) ];// ← compiles pragma(msg, typeof(tasks[0])); alias MyTask = Task!(run, double function(int), int)*; MyTask[] myTasks; myTasks ~= task(foo, 1); myTasks ~= task(bar, 2); } Ali
store template value
I have a class that creates a task in it's constructor. How do I store this created task as one of it's value members and later on call .yieldForce()?
Re: store template value
But it's std.parallelism's task... And how can I use get!T if I don't know the type of the task? 2015-08-01 19:02 GMT+02:00 Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn@puremagic.com: On Saturday, 1 August 2015 at 16:41:54 UTC, maarten van damme wrote: I was afraid I would have to do that. Templatizing the class on the value doesn't work as I later on want to create a hashmap of these classes. When I assign a task to a variant, how do I call .yieldForce later on? You can get a type from a Variant with the get!T method then call it. But actually, maybe Task should just be an interface with the yieldForce method then you create classes that implement it and pass them to the constructor. Then there's no need for templates or casting at all.
Re: store template value
I was afraid I would have to do that. Templatizing the class on the value doesn't work as I later on want to create a hashmap of these classes. When I assign a task to a variant, how do I call .yieldForce later on? 2015-08-01 18:28 GMT+02:00 Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn@puremagic.com: On Saturday, 1 August 2015 at 15:37:46 UTC, maarten van damme wrote: I have a class that creates a task in it's constructor. How do I store this created task as one of it's value members and later on call .yieldForce()? If the class itself isn't templated on the type, you'll want to use something like std.variant.Variant to store it.
Re: How to use core.thread.Thread
You can certainly use thread but in most use cases, concurrency or parallelism will accomplish the same in a much saner/safer way. (they're wrappers around core.thread anyway). Don't know of any tutorials about core.thread, about the other two you can find help here : http://ddili.org/ders/d.en/ 2015-07-16 11:24 GMT+02:00 aki via Digitalmars-d-learn digitalmars-d-learn@puremagic.com: On Thursday, 16 July 2015 at 08:21:26 UTC, maarten van damme wrote: Have you checked out std.parallelism and std.concurrency? I know std.concurrency to use spawn. If I cannot use Thread, I'll implement by spawn. But want to try Thread class because it seems similar to Java's Thread class. I don't know std.parallelism. It seems for the different case. Aki.
Re: How to use core.thread.Thread
Have you checked out std.parallelism and std.concurrency? 2015-07-16 9:57 GMT+02:00 aki via Digitalmars-d-learn digitalmars-d-learn@puremagic.com: I can't resolve the compile errors: import core.thread; class DerivedThread : Thread { int count = 0; this() { super(run); } private void run() { inc(); //testThread.d(8): Error: shared method testThread.DerivedThread.inc is not callable using a non-shared object } synchronized void inc() { ++count;//testThread.d(11): Deprecation: read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!+=(this.count, 1) instead. } } void main() { auto thr = new DerivedThread(); thr.start(); thr.inc(); //testThread.d(17): Error: shared method testThread.DerivedThread.inc is not callable using a non-shared object thr.join(); } 1. Should I declare thr as shared? But auto thr = new shared DerivedThread(); does not resolve it. 2. Why ++count cause an error? I think it is safe because it is marked as synchronized. If it is forced to use atomicOp all the time, it's painful. 3. Are there any tutorials about using Thread class? Aki.
Re: D looses in speed to Common Lisp
It may be a good idea to prealocate the whole array so you don't resize the dynamic arrays every execution of the loop. 2015-05-11 23:30 GMT+02:00 weaselcat via Digitalmars-d digitalmars-d@puremagic.com: On Monday, 11 May 2015 at 21:15:33 UTC, Dzhon Smit wrote: ... time sbcl --dynamic-space-size 4GB --script fib.lisp 0 1.16user 1.49system 0:02.67elapsed 99%CPU (0avgtext+0avgdata 1658860maxresident)k ldc -O5 -release -boundscheck=off fib.d $ time ./fib 0 1.33user 0.81system 0:02.15elapsed 99%CPU (0avgtext+0avgdata 1230712maxresident)k
Re: Beginner ?. Why does D suggest to learn java
While d can be complex, there's nothing preventing you from starting out simple and not using all features at first. I don't understand why it's not suitable for a beginner if you use this approach... 2014-10-17 6:51 GMT+02:00 via Digitalmars-d-learn digitalmars-d-learn@puremagic.com: On Friday, 17 October 2014 at 01:14:34 UTC, bearophile wrote: Python is probably a better first language than Java. D is a little too much complex as first language. The IDE support is probably a bit better with Java/C# and using a statically typed language as your first language has advantages, but all are good first languages: easy to find tutorials, easy to find educational example code, easy to find answers to typical beginner issues on Stackoverflow… I personally think Logo, Processing and Scheme would be more fun as learning tools, but they are throw-away languages. E.g. http://turtleacademy.com/programs/en http://www.processing.org/ and many more online programming sites.
Re: D with no druntime
There were 2 talks about bare metal D this year at the D conference. The first one is about someone able to use D on microcontrollers with a few k ram.: https://www.youtube.com/watch?v=o5m0m_ZG9e8 The second one is about someone trying to strip almost everything out and see what works: https://www.youtube.com/watch?v=qErXPomAWYI They both go through the process of striping down the runtime and showing what works. 2014-08-21 7:13 GMT+02:00 uri via Digitalmars-d-learn digitalmars-d-learn@puremagic.com: Hi All, I am playing with a small hack OS for fun and in 2066 there are these undefined refs (I have no druntime): _d_arraybounds (new to 2066) _d_assert (new to 2066) _d_unittest (new to 2066) _Dmodule_ref (also in 2065) _d_dso_registry (also in 2065) It is trivial to stub these out but it got me wondering... Is there any way to compile D that has no dependencies? Thanks, uri
Re: Command Line Application in D
I am a little bit confused as to what you want. There is a command line example at dlang.org, and there exists a program (rdmd) that compiles several D files and runs them. http://dlang.org/rdmd.html 2014-08-04 23:20 GMT+02:00 TJB via Digitalmars-d-learn digitalmars-d-learn@puremagic.com: I am trying to build some simple command line applications that I have written in python as a way to learn D. Can you give some examples for me? For instance, I think I remember once seeing somewhere in the documentation an example that took several D files and compiled them all by running some kind of system command. I much appreciate your help! TJB
Re: dlang website: remove that quick try editor
Honestly, if you look at other programming languages with some online editor, it's about the same speed. It would help though (don't know if it's already there) to include timestamps, so people see that the actuall time-waster is not in compilation/execution. 2014-06-09 23:21 GMT+02:00 Dejan Lekic via Digitalmars-d digitalmars-d@puremagic.com: John wrote: dlang.org website has a quick try editor with D code example. Please remove that feature (at least the buttons to run it) as it takes ages to run the example and leaves an impression that D is very slow!! This is only good if it can run quickly like the similar feature available on the golang website. If you love this feature and refuse to remove it, at least please move it to another page. You don't want to lose people within minutes of their first visit to D website with a total misunderstanding of the purpose and power of the D language. I hope you did not expect something on the web ba faster than a native application... :) -- http://dejan.lekic.org
std.algorithm range violation
an anyone explain me what I'm doing wrong here : [code] dstring[][dstring] providor_symbol_map; ... writeln(providor_symbol_map.keys.sort!((x,y)=providor_symbol_map[x].length=providor_symbol_map[y].length)); [/code] output: core.exception.RangeError@std.algorithm(9429): Range violation
Re: std.algorithm range violation
I'm trying to analyze the usage of certain words in a large number of spam emails, and I want for every interesting word a list of 'providors', that mentioned that word. with associative arrays I hoped to get it by using array[interestingworde]. And I have to refer outside from sort(x,y) as associative arrays have no order, I'll always have to sort a key-array according to values obtained through the associative array. It's supposed to be a delegate anyway, otherwise the least it could do is throw a compilation error. 2014-05-28 12:53 GMT+02:00 Wanderer via Digitalmars-d-learn digitalmars-d-learn@puremagic.com: On Wednesday, 28 May 2014 at 10:10:41 UTC, maarten van damme via Digitalmars-d-learn wrote: an anyone explain me what I'm doing wrong here : [code] dstring[][dstring] providor_symbol_map; ... writeln(providor_symbol_map.keys.sort!((x,y)=providor_ symbol_map[x].length=providor_symbol_map[y].length)); [/code] output: core.exception.RangeError@std.algorithm(9429): Range violation dstring[][dstring] declaration looks a bit obscure to me... what do you intent with it, array of maps or map of arrays? Also, it looks unnatural that inside sorting lambda, you refer outside from it (back to providor_symbol_map variable). Ideally, you should only use variables x and y. Does D support sorting by map entries instead of by keys only or by values only?
Re: std.algorithm range violation
wow. senpai, teach me what I did wrong... 2014-05-28 13:21 GMT+02:00 bearophile via Digitalmars-d-learn digitalmars-d-learn@puremagic.com: maarten van damme: writeln(providor_symbol_map.keys.sort!((x,y)=providor_ symbol_map[x].length=providor_symbol_map[y].length)); [/code] Try: ((x, y) = providor_symbol_map[x].length providor_symbol_map[y].length) Bye, bearophile
Re: [dox] What should we do with dsource?
At least something should happen with the huge amount of outdated projects. Maybe add an archive (assuming we're going to keep dsource alive). It's very frightening stumbling upon D to discover a huge list of abandoned projects and an empty forum :) 2013/10/22 Benjamin Thaut c...@benjamin-thaut.de Am 22.10.2013 21:46, schrieb Andrej Mitrovic: On 10/22/13, Wyatt wyatt@gmail.com wrote: So, as the topic asks: what should be done with it? Note that some people still use dsource, so well need their input as well. Specifically I know the WindowsAPI project is still being hosted there and being worked on. VisualD is also still hosted on dsource (at least the binaries and the documentation)
Re: Newbie questions. Which Compiler to start with? Real Time behaviour? Has anyone converted CImg yet?
1) afaik you can't cross compile to arm with dmd. I know it's possible with gdc. 2) There are people who successfully use d without gc. I think andrei posted a stub gc that throws an exception every time the garbage collector is tried to get used. You can't use whole phobos (yet) without gc. 2013/9/2 John Carter john.car...@taitradio.com So I'm a reasonably experienced C/C++/Ruby/... programmer and D is looking very Good to me... So, time to get serious and sit down and learn it. Ultimately it won't pay me to learn it unless I can ultimately take my colleagues along. Currently they are itching to move from C to C++, and I'm trying to convince them not to. We work in the embedded linux real time area, so here are a few newbie questions that I couldn't spot the answer to... 1) Which D compiler should we start with? We use gcc/g++ for everything else, is gcd a good choice or should we stick with Digital mars one? (We would be cross compiling to sparc or arm) 2) The traditional argument against garbage collected languages in real time environments is that they sporadically lock up while collecting resulting in missed real time deadlines. Certainly the state of the art in GC has moved beyond this, and also there are workarounds for the problem. Is it possible to do real time programming in D? 3) A good starter project for me would be to take a well known cpu-intensive C++ template rich project and convert it to D and then present that side-by-side to my colleagues. I like playing around with CImg, http://cimg.sourceforge.net/ CImg it is one huge template with chunks of macro magic to do image processing. Before I start, has anyone converted CImg to DImg yet? Thanks!
Re: A little of coordination for Rosettacode
the entry : http://rosettacode.org/wiki/File_IO is wrong because as stated by the asignment : In this task, the job is to create a file called output.txt, and place in it the contents of the file input.txt, *via an intermediate variable.*** * * there is no intermediate variable; I don't know if this is the right place to post but you seem to do a lot of work for rosetta... 2013/8/31 bearophile bearophileh...@lycos.com I have added a D entry for the Go Fish game: http://rosettacode.org/wiki/**Go_Fish#Dhttp://rosettacode.org/wiki/Go_Fish#D I don't know the Go Fish game, so I am not sure this code is correct. Is some of you able and willing to test its play a bit? (This D entry is very Python-style because it's a translation of the Python entry, so it's not very strongly typed. Generally in D I prefer stronger typing, but in this case I think it's acceptable). Bye, bearophile
Re: Replacing std.xml
and imagine someone forced to use xml who reads this answer from the community :p std.xml is a must, no doubt. 2013/8/29 Joakim joa...@airpost.net On Thursday, 29 August 2013 at 07:47:35 UTC, Jonathan M Davis wrote: There are several D XML libraries floating around, but no one has taken the time to get any of the prepared for the Phobos review queue, and I suspect that very few of them are range-based like the Phobos XML solution needs to be, but I don't know. I think it's great that there's no std.xml, as it implies that nobody using D would use a dumb tech like XML. Let's keep it that way. :)
Re: std.algorithm's remove
But remove doesn't truly remove from the source range because the length of the source range stays the same. It's return value is a modified copy of the source range. Filter doesn't really work right away because that would also remove duplicate elements while I only want to remove at a given index. It also makes for clunkier looking code and is counterintinuitive to come up with (I want to remove an element therefore I have to filter every element that isn't equal to that element from the source range...) And while I haven't worked in c++, even that appears to have remove_copy which is really what I want. I could use temporary variables and blow that neat line up in 3 lines which, while still readable, look redundant. I'm happy the d result is 3 times shorter then their haskell solution but not that the time spent was 5 minutes working and the rest of the time debugging. This as opposed to using racket where the time spent is 15 minutes but after that everything works great (while my racket experience is limited to playing around with it for 2 weeks now and then). 2013/8/25 Brad Anderson e...@gnuk.net On Sunday, 25 August 2013 at 02:24:30 UTC, maarten van damme wrote: hello, I'm a hobyist-programmer and around where I live there's a group of haskell fanatics. They posted solutions to a recent programming challenge which I find to be a bit ugly. For fun I wanted to implement it in d and a rough version (not correct yet, this was written/hacked in 5 minutes after reading the exercise) My rough version is posted here : http://dpaste.dzfl.pl/4b5a6578 if you look at the output, you'll see this particular line : omkom - komkom because of : kom momkom momkom - momkomm This is because of what remove from std.algorithm does. It not only returns a range with that element removed (as the name implies), it also modifies the original range. I assume this decision was made for efficiency purposes but that is one of the most ugliest things I have ever come across. At least c# forces the 'ref' in it's parameters so you know something's up. Is there any way I could've known this? (apart from reading the documentation on every single trivial function in the std library?) It was done that way intentionally because the purpose of remove is to remove from the source range. If you don't want to affect the source range use filter. I suspect you could trace remove's lineage back to C++ STL's remove which works similarly (but is significantly clunkier and harder to use).
Re: std.algorithm's remove
Correction, I could really use remove to begin with, only have to dup the range. Still convinced that the remove behaviour is counterintuitive but I assume good reasons exist... 2013/8/25 maarten van damme maartenvd1...@gmail.com But remove doesn't truly remove from the source range because the length of the source range stays the same. It's return value is a modified copy of the source range. Filter doesn't really work right away because that would also remove duplicate elements while I only want to remove at a given index. It also makes for clunkier looking code and is counterintinuitive to come up with (I want to remove an element therefore I have to filter every element that isn't equal to that element from the source range...) And while I haven't worked in c++, even that appears to have remove_copy which is really what I want. I could use temporary variables and blow that neat line up in 3 lines which, while still readable, look redundant. I'm happy the d result is 3 times shorter then their haskell solution but not that the time spent was 5 minutes working and the rest of the time debugging. This as opposed to using racket where the time spent is 15 minutes but after that everything works great (while my racket experience is limited to playing around with it for 2 weeks now and then). 2013/8/25 Brad Anderson e...@gnuk.net On Sunday, 25 August 2013 at 02:24:30 UTC, maarten van damme wrote: hello, I'm a hobyist-programmer and around where I live there's a group of haskell fanatics. They posted solutions to a recent programming challenge which I find to be a bit ugly. For fun I wanted to implement it in d and a rough version (not correct yet, this was written/hacked in 5 minutes after reading the exercise) My rough version is posted here : http://dpaste.dzfl.pl/4b5a6578 if you look at the output, you'll see this particular line : omkom - komkom because of : kom momkom momkom - momkomm This is because of what remove from std.algorithm does. It not only returns a range with that element removed (as the name implies), it also modifies the original range. I assume this decision was made for efficiency purposes but that is one of the most ugliest things I have ever come across. At least c# forces the 'ref' in it's parameters so you know something's up. Is there any way I could've known this? (apart from reading the documentation on every single trivial function in the std library?) It was done that way intentionally because the purpose of remove is to remove from the source range. If you don't want to affect the source range use filter. I suspect you could trace remove's lineage back to C++ STL's remove which works similarly (but is significantly clunkier and harder to use).
Re: std.algorithm's remove
I'm not sure if it really is my place to criticize design decisions of a language written by people that devoted their career to computer science while I have only read some books out of boredom :) 2013/8/25 bearophile bearophileh...@lycos.com maarten van damme: But remove doesn't truly remove from the source range because the length of the source range stays the same. It's return value is a modified copy of the source range. Filter doesn't really work right away because that would also remove duplicate elements while I only want to remove at a given index. It also makes for clunkier looking code and is counterintinuitive to come up with (I want to remove an element therefore I have to filter every element that isn't equal to that element from the source range...) And while I haven't worked in c++, even that appears to have remove_copy which is really what I want. I agree that the design of std.algorithm.remove is bug prone. The compiler doesn't verify that you are using its result! I have also filed several bugs regarding the implementation of std.algorithm.remove. In the end your complaints are real. You can't expect Phobos to be perfect, but people work to fix it. Fixing such problems future D users will not find your problem. So I suggest you to think well about what your problem is, what you don't like on this, and then write a enhancement request for Phobos. Even if std.algorithm.remove can't be fixed, people can add a new function with a safer/more handy behavour. Bye, bearophile
Re: randomShuffle
How about using std.random.randomSample? 2013/6/3 Yann skratc...@gmx.de Hey, I am trying to generate an array of 10 unique (!) random numbers from 1 to 1000 each (for example). The best I could come up with is: auto arr = iota(1, 1000).array; randomShuffle(arr); return arr.take(10).array.sort; This leaves me quite unhappy, because I would like the code a) to be one line b) not use array more than once Is there a better way to accomplish this? Naively, I would expect something like return iota(1, 1000).randomShuffle.take(10).**sort; Thanks, Yann
Re: how to avoid memory leaking
So now pgen.d works (without simpledisplay version an reusing trueimage). The simpledisplay version still has problems, but I'll try (manually (de)allocating)/(reusing) the data 2013/5/14 Adam D. Ruppe destructiona...@gmail.com On Monday, 13 May 2013 at 21:28:34 UTC, maarten van damme wrote: Adam checks this thread so he'll probably read the errors about simpledisplay. if not I'll copy paste and put in a bug report on github. I won't be on my linux box with free time until at least tomorrow afternoon but i'll check then. I've used simpledisplay on linux before, but never with a 64 bit app so i'll have to try it. So, do we actually know where the memory problems came from? is anyone actually running out of memory too or am I the only one? I didn't actually get that far since i'm on my slow computer, but my guess is one of those copies got pointed into. The image in your code is something like 8 MB of memory, and is generated pretty rapidly, as fast as teh cpu could do it in the other thread. The old function took that 8MB and made at least two copies of it, once in my function and once in std.zlib's function. If the usable address space is 2 GB, any random 32 bit number would have about a 1/128 chance of pointing into it. If you consider the gc was probably scanning at least one copy of that data for pointers - std.zlib's one was constructed as a void[], so even if allocator told the gc what type it was (idk if it does or not), void[] has to be scanned conservatively because it could be an array of pointers. And then add in random numbers on the stack, and the odds are pretty good the gc will get a false positive and then fail to free the memory block. Repeat as it loops through the images, and you've got a pretty big memory leak adding up. I'm not 100% sure that's what happened, but I think it is pretty likely. The reason the new function fixes it is because it manages the big copies manually, freeing them at the end of the function without worrying about false pointers.
Re: Disgusted
If you define intelligence as the ability to learn computer languages, I'd have to disagree with you. No reason to be disgusted, just curious. Why on earth would you spend your time doing that? 2013/5/13 D-Ratiseur some...@somewhere.com On Monday, 13 May 2013 at 00:21:06 UTC, John Colvin wrote: On Monday, 13 May 2013 at 00:18:34 UTC, D-Ratiseur wrote: I went back from a trip...basically I spent 6 monthes in Yukon... Then, came back to my activities, I was a lot in the library of the university linked to my geo. location...I've noticed a strange guy...He was always reading some books about computer programming languages. After a few monthes, I've realized that he was learning from A to Z all the languagues...I've just realized that he was probably smarter than me...And despite of being disgusted, I wonder If It's time to hide again in the Yukon state...'cause I'm basically disgusted, and the basic concept of being alive is stupid and pointless. There's always smarter people. Hell, most of my friends are smarter than me. You're probably smarter than me. But I know why I left my predilection language: I'm comming from Pascal/Delphi and everything is done while in D there is still a field for the basic stuff. Maybe Roquentin was also looking for that: a free field.
Re: how to avoid memory leaking
I'll check every uint occurance, thank you. I'm on windows so I won't get the maximum number of clients error you talk about. The loop I used inside main was : while(true){ curtrans=generateTransformationMatrix(); for(int y=0;yheight;y++) for(int x=0;xwidth;x++) i.data[(y*width+x)*4..y*width+x)*4+4]=colorify(applyTransformation(transformXY(x,y),curtrans)).dup[0..3] ~ 255; // and finally write the data to a png file png = pngFromImage(i); //std.file.write(images/~toHexString(md5Of(curtrans))~.png, writePng(png)); } This doesn't use simpledisplay anymore so this should work fine on linux too? Adam checks this thread so he'll probably read the errors about simpledisplay. if not I'll copy paste and put in a bug report on github. -- The new fixes from adam rupe for png and image.d actually get rid of all memory leakages in my reduced version (without simpledisplay). Now I can get to finetuning my functions for the best images :) I'll see if the simpledisplay version now works too (leave it running overnight). -- So, do we actually know where the memory problems came from? is anyone actually running out of memory too or am I the only one? (tested on both my pc and my laptop so should be reproducible) 2013/5/13 Maxim Fomin ma...@maxim-fomin.ru On Friday, 10 May 2013 at 23:18:31 UTC, maarten van damme wrote: I'm trying to generate images and after displaying them I want to save them to a png file. I use parallelism to generate them asynchronously with the gui-thread to avoid blocking (don't know if this is really relevant). If I add a single line in the method where I generate the image that creates a class which allocates a pretty big array, slowly but surely the memory starts to rise until it ends in a spectacular out of memory exception. I always thought the garbage collector would deal with it. I tried reducing it but failed. Maybe I should let dustmite bite in it a bit later. How can I manually fix this? Is this a known bug in the garbage collector? btw, this code also caused segfaults on my 64 bit laptop on linux. How can I avoid this? main class: https://dl.dropboxusercontent.**com/u/15024434/** picturegenerator/generalised.dhttps://dl.dropboxusercontent.com/u/15024434/picturegenerator/generalised.d zip file with everything ready to go to compile: https://dl.dropboxusercontent.**com/u/15024434/**picturegenerator/** picturegenerator.ziphttps://dl.dropboxusercontent.com/u/15024434/picturegenerator/picturegenerator.zip 1) your code is not compilable on 64x system due to erroneous treating of some platform-varying types as uint, use size_t. Luckily dmd has -m32 switch 2) I encounter not out of memory exception but enforcement failure in simpledisplay.d:1024 Maximum number of clients which looks like not a memory error but you running out of some X server limit. 3) Segfault occures in simpledisplay.d:1058 - in destructor you call XDestroyImage(handle) but do not check whether handle is null. However it happens after enforcement failure so it doesn't looks like root of problem. 4) What really consumes memory is kernel or something which forces it to consume it since my task manager reports two blocks of 280 MB and 126 MB inside kernel part of virtual memory.
Re: how to avoid memory leaking
This is ridiculous. Your solution appears to keep the memory somewhat constant around 20mb-28mb untill it suddenly runs out of memory. Literally out of nowhere. I have no idea what's causing everything, so I decided to get rid of the window altogether and to try saving the images instead of displaying + saving them. Now I run in Internal error: ..\ztc\cgcs.c 343... D is really dissapointing here. Maybe it's the gc having fun, maybe it's something else, no way to know for sure. Having to give up on displaying it altogether runs into internal error's.
Re: how to avoid memory leaking
aren't you guys all getting tons of internal error's as soon as you combine dynamic arrays with static arrays? It seems as if these things are completely seperate things, but their syntax sugests a more closely related connection. I really find it confusing... So, after reducing, I am very certain that at least one problem comes from generating a png, the code used is here available : https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/png.d seeing as this is pure d, am I right in assuming there should never be any memory leaks when using this? The reduced loop that only generates images is here : TrueColorImage i= new TrueColorImage(width,height); PNG* png; double[][4] curtrans; while(true){ curtrans=generateTransformationMatrix(); for(int y=0;yheight;y++) for(int x=0;xwidth;x++) i.data[(y*width+x)*4..y*width+x)*4+4]=colorify(applyTransformation(transformXY(x,y),curtrans)).dup[0..3] ~ 255; // and finally write the data to a png file png = pngFromImage(i); //std.file.write(images/~toHexString(md5Of(curtrans))~.png, writePng(png)); } if you comment out png = pngFromImage(i) the program appears to not blow up over time. I think the ice come from assiging a slice of a dynamic array to a slice of a static array (hence the .dup). (I'll try reducing it with dustmite) 2013/5/12 Benjamin Thaut c...@benjamin-thaut.de Am 12.05.2013 21:05, schrieb maarten van damme: This is ridiculous. Your solution appears to keep the memory somewhat constant around 20mb-28mb untill it suddenly runs out of memory. Literally out of nowhere. I have no idea what's causing everything, so I decided to get rid of the window altogether and to try saving the images instead of displaying + saving them. Now I run in Internal error: ..\ztc\cgcs.c 343... D is really dissapointing here. Maybe it's the gc having fun, maybe it's something else, no way to know for sure. Having to give up on displaying it altogether runs into internal error's. As D is a relative new lagnauge stuff like this can happen. It would be great if you could reduce the compiler crash to a minimal test case using dustmite: https://github.com/**CyberShadow/DustMitehttps://github.com/CyberShadow/DustMite A description how to use it is aviable in the wiki. If you successfully reduced the compiler error please fill in a bug report at http://d.puremagic.com/issues/ -- Kind Regards Benjamin Thaut
how to avoid memory leaking
I'm trying to generate images and after displaying them I want to save them to a png file. I use parallelism to generate them asynchronously with the gui-thread to avoid blocking (don't know if this is really relevant). If I add a single line in the method where I generate the image that creates a class which allocates a pretty big array, slowly but surely the memory starts to rise until it ends in a spectacular out of memory exception. I always thought the garbage collector would deal with it. I tried reducing it but failed. Maybe I should let dustmite bite in it a bit later. How can I manually fix this? Is this a known bug in the garbage collector? btw, this code also caused segfaults on my 64 bit laptop on linux. How can I avoid this? main class: https://dl.dropboxusercontent.com/u/15024434/picturegenerator/generalised.d zip file with everything ready to go to compile: https://dl.dropboxusercontent.com/u/15024434/picturegenerator/picturegenerator.zip
Re: Inline D in Javascript
Or, if you really want client side javascript, try mixing emscripten en ldc. If you want a great server-side library, take a look at adam rupe's work.
Re: variable x cannot be read at compile time (ctfe)
My only assumption is that -version=runtime doesn't utilize ctfe and the other does. The rest is simple timing on both linux and windows and ctfe is way slower... 2012/12/18 bearophile bearophileh...@lycos.com: maarten van damme: How can this be? Maybe there are some mistakes in your assumptions. Bye, bearophilwe
Re: variable x cannot be read at compile time (ctfe)
Thanks, I'm really happy it works now. it's odd that the resulting arraylist is slower to access at runtime then the arraylist generated at runtime... Is there a reason for this? Should I open bugreports for your testcases? 2012/12/17 bearophile bearophileh...@lycos.com: I think it's a problem of nested delegates at CT. But if this is the problem, dmd used to give a more clear error message. Two minimized programs that show the problems: - import std.algorithm: filter; import std.array: array; auto foo(in int x) { return [1, 2].filter!(i = x)(); } enum a = foo(3).array(); void main() {} temp.d(4): Error: variable x cannot be read at compile time - import std.array: array; enum a = [1, 2].array(); void main() {} ...\src\druntime\import\core\memory.d(251): Error: gc_malloc cannot be interpreted at compile time, because it has no available source code - Bye, bearophile
Re: variable x cannot be read at compile time (ctfe)
How do I make dmd output asm? I wrote a simple test and for a simple int[] array it was 2,5 times slower. 2012/12/17 bearophile bearophileh...@lycos.com: maarten van damme: it's odd that the resulting arraylist is slower to access at runtime then the arraylist generated at runtime... Is there a reason for this? In such cases, beside thinking some time about the topic, one solution is to take a look at the asm. Maybe it's the same problem as with enum arrays, they get copied like literals every time you use them.
Re: DLL Injection
Strangely, the main in my dll is getting executed multiple times and msvcr71.dll gets injected too. Is this normal? 2012/12/3 s0beit s0b...@myg0t.com: On Sunday, 2 December 2012 at 22:30:56 UTC, maarten van damme wrote: Thanks, interesting blog :) 2012/12/2 s0beit s0b...@myg0t.com: Alright, I was finally able to give it a try: http://s0beit.me/d/d-module-injector/ I released the source code as well as the binary here if anyone wants to try. It worked for me in a game I was playing with. Thanks! Please let me know the results if you end up trying it, I want to confirm it works depending on certain conditions.
Re: DLL Injection
Yes, that was the problem :p I have no idea about mcvr71, maybe because of std.process but that isn't that huge a concern
Re: telnet and D
vibe.d is very modular, just import what you need. I hate to push it, but it has very good documentation and examples. Its designed for web apps, but it makes a nice little web library as well. import vibe.vibe; void main() { auto client = new HttpClient; client.connect(www.google.com, 80); auto res = client.request((req){ req.url = /; }); logInfo(Response: %d, res.statusCode); foreach( k, v; res.headers ) logInfo(Header: %s: %s, k, v); (new NullOutputStream).write(res.bodyReader); client.disconnect(); } That does indeed look clean. Now I'm using a ubyte[1] buffer to try and read single bytes from my sockets. their tcp example looks pretty clean: import vibe.d; static this() { auto conn = connectTcp(time-b.timefreq.bldrdoc.gov, 13); logInfo(The time is: %s, cast(string)conn.readAll()); } let's see how it'll hold up when I try to deal with raw bytes :)
Re: telnet and D
Haven't looked at vibe.d yet because it looked more like a library for writing web apps and normal sockets should be enough. Didn't know about Tango, I'll try deciphering the original d1 module.
Re: telnet and D
IIRC, telnet is simple, so it shouldn't be too difficult.. Turns out it indeed was simple. My option negotiation had a bug :D my (primitive) telnet client works now :)
Re: getters and setters not an lvalue
Ok, looking forward to the fix :) Btw, I have a foreach loop and in that foreach loop I want to decide if the current element can stay and if not, I want to remove it. If removing it yields an empty range in the foreach loop, it crashes. What's the sane way to do this?
Re: getters and setters not an lvalue
Ok, makes sense now :) 2012/10/31 monarch_dodra monarchdo...@gmail.com: On Wednesday, 31 October 2012 at 12:46:12 UTC, maarten van damme wrote: In my current code I'd like to do something ala: void main(){ getsettest test=new getsettest(); test.value+=1; } class getsettest{ int myvalue; this(){ } @property{ int value(){ return myvalue; } void value(int value){ myvalue=value; } } } but this gives the following error: test.d(4): Error: test.value() is not an lvalue Is there a rationale behind this decision of not translating test.value+=1 to test.value= test.value +1 ? It's not that simple as test.value is not an LValue, so from the compiler's perspective test.value = test.value + 1 calls two different functions, that may or may not have anything to do with each other. The expansion ++ = +=1 = a = a + 1 works if there is only 1 lvalue the whole chain through. Can the compiler really assume it can do that? And is it a smart move to allow it to make that assumption. What you have there is basically an encapsulated field, that does not leak its address: You can take the filed, you can update it with a new value, but you can't modify it. If you allow test.value+=1, then where does it end? Is this legal? // void foo(int a) {...} foo(test.value); // Would you want the compiler to expand it into: // void foo(int a) {...} //scope for __temp { auto __temp = test.value; foo(temp); test.value = temp; } // IMO, if you take the time to write both functions, instead of just: // @property ref int front(){return myvalue;} // Then the compiler must assume you did it for a reason, and not mess with your code.
Re: Gathering info for D/Embedded presentation
I'm also curious if druntime can be made compatible with bionic because now I have to experiment with using a chrooted linux on my phone to test some D applications.
Re: bigger then size_t
Ok, that solves it. Thank you.
Re: bigger then size_t
Another quick question. When I know an array is going to have an length smaller then 255, can I use bytes as index or do I have to use size_t to make it portable across 64 bit platforms?
Re: Sudoku Py / C++11 / D?
The puzzle unflipped is extra hard as the solution to the first row is 987 654 321. Come to think of it, one could add a new function flip that mutates the sudoku according to well known rules and maybe something like unflip for when the sudoku was finnished. New techniques could certainly be added (like single candidate and naked pairs) without too much overhead so they might just pay off, certainly on the impossible puzzle. Maybe I could also pre-calculate all rows, collumns and squares and store them in int pointer arrays. This way things could become even faster. Would it be possible to do something like that in ctfe?
Re: Sudoku Py / C++11 / D?
Congratulations, you have found a compiler bug. I have found maybe one hundred of those. Please minimize the code and submit it to Bugzilla :-) Oh, but try playing around with static and dynamic arrays. You'll be able to find plenty more :p By changing both squareWidth and squareHeight to 5, we get an optlink crash (those are more rare, aren't they?) I've made one of my last modifications allowing M x N sudoku's. I think I'm going to place the result on github or something. It was a great experience :) One last thing would be to try and move generateBitsetCache to CTFE (if that's even possible). Anyway, code can be checked out at http://dpaste.dzfl.pl/879b0973 (along with the pretty compiler error at the end). I'm going to try dustmite out (always wanted to do that) and see if it can reduce my testcase (no previous experience).
Re: Sudoku Py / C++11 / D?
I've distiled what I understood from your source and the resulting executable managed to solve the impossible one in 27 seconds while your source takes 41 seconds. I've probably violated every D guideline concerning the use of static, pure, nothrow,... but it works perfectly :) It does fail to compile on dpaste, I have no idea why. It does compile on my machine though... http://dpaste.dzfl.pl/8a2aef5b 2012/8/21, Timon Gehr timon.g...@gmx.ch: On 08/21/2012 05:52 PM, maarten van damme wrote: On 08/20/2012 11:49 PM, Timon Gehr wrote: On 08/20/2012 10:43 PM, maarten van damme wrote: Still it comes nowhere near beating timons solution. Is the logic of that documented somewhere because I don't understand it. Try this: http://dpaste.dzfl.pl/23b1b6e2 Thank you very much, this makes everything more clearer. I'm not very familiar with binary operators so the comments help out a lot. Would you mind it if I shamelessly copy your solution of using shorts to store possibilities in? Not at all. I'm also a bit confused. How come the int's you change from a square passed from squ are stilled referenced to the original array? I thought it lost that reference as soon as you did any operations (like concenating) on it? The used ranges just express patterns of iteration. They replace manual for-loops. The data source has assignable elements, and the relevant range operations in Phobos all propagate this capability to their result.
Re: Sudoku Py / C++11 / D?
Thank you very much. I changed line 119 to an explicit cast to int and removed an unneeded cast at line 63. It now happily compiles with 64bit mode : http://dpaste.dzfl.pl/63666f07. It's kind off odd though that compiling with -inline seems to slow it a bit down. I'm unsure if searching for the field with the least possibilities was a smart move because now I have to carry that taken array through all my functions and optimize has to check the whole sudoku instead of a slice. (come to think of it, taken should've been named occupied) Still, I'm really pleased with the results. I should write a prettyPrint method that prints sudoku's in a prettier format and returns the solution instead of the shorts containing the solutions hidden in bitfields :)
Re: Sudoku Py / C++11 / D?
I'm unsure if searching for the field with the least possibilities was a smart move because now I have to carry that taken array through all my functions and optimize has to check the whole sudoku instead of a slice. (come to think of it, taken should've been named occupied) I take that back, having tried it out, it is more then 3 times slower...
Re: Sudoku Py / C++11 / D?
Some suggestions about the code: Thank you very much for your criticism, there are indeed a lot of points where I have to improve on. - Put a space before and after operators, after a commas and semicolon, around .., etc. - Compile with -wi -property; - Try to add pure/const/nothrow/immutable where possible; I realize the usefullness of keywords like these but having to type them over and over again tends to become rather annoying. There are functions where the implementation is shorter than it's declaration... Is there a special reason I should use them in little programs like these? - Minimize the need of cast(); - Sometimes it's useful to localize the imports (stdio e datetime are used just by the main); - Minimize the usage of magical constants like 0b10__, possibly define it only once. And often adding underscores inside long numbers is handy (here I have put them every 4 digits because it's binary); - Repeating things like short[81] in many function signatures is quite bad. Better to define a global type with alias (or someday better with std.typecons.Typedef when it will work), and then use it; - Generally it's better to use unsigned values for array indexes; - If you look for performance and your program is single thread, then it's better to annotate global variables with __gshared; I'm not all that familiar with __gshared, why does it increase performance? - This: ubyte[81] taken = false; is better than this: ubyte[81] taken; taken[] = false; I know and I think I can even leave false out because the default value of ubyte is 0 = false. I had a big in my code and it took me a long time to find it. That line is a leftover of a desperate attempt at finding it :) (as is line 101) I even tried using array!bool but even instantiating failed so I gave up. Would performance increase be noticeable? I guess not. This is your code modified, it's also a little faster: http://dpaste.dzfl.pl/06510dcd Thank you. I see you also used contracts, looks better now :) (using contracts is really something I should start doing...) I will try to replace the int[] of cachedBitsetToRange with something more static, to reduce indirection. Bye, bearophile I should also add a little check to see if every value I put is indeed numerical.
Re: Sudoku Py / C++11 / D?
and everythingPossible should also be changed to something ala 2 ^(side) -1
Re: Sudoku Py / C++11 / D?
2012/8/25 Timon Gehr timon.g...@gmx.ch: On 08/24/2012 09:32 PM, maarten van damme wrote: I've distiled what I understood from your source and the resulting executable managed to solve the impossible one in 27 seconds while your source takes 41 seconds. It is 10s vs 13s with GDC on my machine. I've only tried dmd but I'm installing gdc on this laptop too. When that's done I'm going to see how they both perform on this puzzle : http://en.wikipedia.org/wiki/File:Sudoku_puzzle_hard_for_brute_force.jpg
Re: Sudoku Py / C++11 / D?
2012/8/17, Chris Cain clc...@uncg.edu: Gonna chime in a bit here: There's a lot of factors at play when deciding to use shorts vs bytes vs native-sized ints. The best way to decide is to time all of them and see which works best overall. With caching on a larger problem, I'd guess that the smaller you go, the better. The reason is that you run the risk of your data getting large enough that it can't all fit in the L2 cache and waiting for information to come from memory takes forever (comparatively speaking). Also, I just looked at your solution (not Mr. Gehr's solution), but it looks like you could approach this much more efficiently. It seems like you're storing a lot of information in arrays of ints. At least some of that could be stored in a bitmap/bitset (http://en.wikipedia.org/wiki/Bit_array) and give you significantly better memory efficiency. Array!bool in std.container will actually do the correct thing and store things like a bitset, so you don't necessarily have to implement your own (however, I think that it stores it in an int when you could use a short to hold 1-9 ... but it's not enough to really worry about). I've been using my phone the last few days to check my emails and overlooked this message. I've never heard about std.container but this could indeed be a more efficient solution. I'm now storing a lot in bytes but that's still 8 times too much :) Try this: http://dpaste.dzfl.pl/23b1b6e2 Thank you very much, this makes everything more clearer. I'm not very familiar with binary operators so the comments help out a lot. Would you mind it if I shamelessly copy your solution of using shorts to store possibilities in? I'm also a bit confused. How come the int's you change from a square passed from squ are stilled referenced to the original array? I thought it lost that reference as soon as you did any operations (like concenating) on it? Was that sarcasm? My own code only uses copying when it's working in the next section of brute force, otherwise it's all referenced. No, that wasn't sarastic. If you look at my last code you see that I compose the squares using something like [] ~ [.] ~ [.] Using a foreach loop and copying the values was 10 times faster... I only use exceptions twice and both when it would be unable to find a solution; I suppose I can try putting nothrow on everything and return a bool if it had an error for solving, or when it had to, inside a structure. Mmmm... I'll give it a try. Yes but when your solver reaches a solution that is wrong, you get a whole branch of numbers falling of, all throwing a broken sudoku exception. It will rarely be called once. Not normal but it can be arranged. :p But I used it in my getRegion code where I do simple calculations on the contents of that array. It is slower there...
Re: Sudoku Py / C++11 / D?
Great, i tried to get rid of the dynamic array possibilities by representing it using a static array of bools. This approach made it 4 times faster :) When i have a solid wifi connection I'm going to install dmd 2.60 to compile timon's code. In the meantime I've started beautifying the source so i can follow the logic. I still have a few questions however: - era claims his code takes 12 seconds on the hardest supplied puzzle yet it enters an infinite loop when the puzzle isnt solvable. Is he talking about a different puzzle? -is it normal that const ref is slower then ref? - in an effort of trying to make the program reuse the same memory I've moved some temporary variables outside the function but the program became slower, how can this be? - in a few hours i'll upload my newest source. I cant find that much stupid design decisions anymore that cause slowdowns yet it keeps lagging behind by an enormous amount to timon's solver. What's that much more efficient in his solution?
Re: Sudoku Py / C++11 / D?
my code is located at http://dpaste.dzfl.pl/93cd5f45 2012/8/19, maarten van damme maartenvd1...@gmail.com: Great, i tried to get rid of the dynamic array possibilities by representing it using a static array of bools. This approach made it 4 times faster :) When i have a solid wifi connection I'm going to install dmd 2.60 to compile timon's code. In the meantime I've started beautifying the source so i can follow the logic. I still have a few questions however: - era claims his code takes 12 seconds on the hardest supplied puzzle yet it enters an infinite loop when the puzzle isnt solvable. Is he talking about a different puzzle? -is it normal that const ref is slower then ref? - in an effort of trying to make the program reuse the same memory I've moved some temporary variables outside the function but the program became slower, how can this be? - in a few hours i'll upload my newest source. I cant find that much stupid design decisions anymore that cause slowdowns yet it keeps lagging behind by an enormous amount to timon's solver. What's that much more efficient in his solution?
Re: Sudoku Py / C++11 / D?
The infinite loop was my mistake. I was looking at your outer while loop but because you use exceptions instead of return values it indeed throws an exception, my bad :) By replacing ref by const ref my program slowed down (looked over a period of 10_000 runs). Not considerably but noticeable. Compiled with -release -noboundscheck -O -inline. Anyone else experiencing the same? Is copying a static arrays cheaper then recalculating the lovation of collumns and squares btw?
Re: Sudoku Py / C++11 / D?
I'm using a static array. I'm hesitating though if I should store possibilities in a precalculated array or calculate them in-place. If i precalculate the possibilities i'd have to copy them over and over so i don't know if it's smart. Going even further I could even store a filled-in value as an array with one possibilities...
Re: Sudoku Py / C++11 / D?
Depends. Do you plan on doing more than brute force? Having it bulk copy them may not be that bad if it's all in one place, and if you do it like that you have all the combinations that carry forward to the next level and if you back out it undoes them all automatically. No, I think doing something else then brute-force would simply be a waste of time (except for finding singles in which case you don't need to use a brute force solver right?) These are of course speculations, I'm not sure. Going even further I could even store a filled-in value as an array with one possibilities... As long as you can tell it apart for it to work, that's up to you. yes, that is indeed going to be the problem ...
Re: Sudoku Py / C++11 / D?
I've now ran in something odd. Using a slight variant from my program on dpaste (can't upload modified version atm but changes are minimal) it takes 0.6 seconds to solve the hard puzzle the python version took 180 seconds for. Yet on the last puzzle, the impossible one, python takes 1800 seconds to figure out it's impossible yet mine takes over 3885 seconds. Where is this slowdown coming from?
Re: Sudoku Py / C++11 / D?
This is because your specific solution is slow. Mine takes 20ms on the 'hard' puzzle and ~13s on the impossible one. (~2.4 GHZ intel x86_64 machine, with gdmd -O -release -inline -noboundscheck.) There is a constant factor between those two solutions. I've compiled it using dmd on my latitude e5500 which is not that fast so I don't think it's that slow... Besides, lets say mine is five times slower, 3000 seconds is still waaay to much. When I'm back able to get my laptop to use my crapy data connection I'll compare. Do you have some optimization ideas by the way?
Re: Sudoku Py / C++11 / D?
great, going to play around with it tomorrow. Caching the possibilities is going to look really ugly but you're right, it's going to give quiet a boost in performance. I'm also going to format your source code a bit more and see if I can follow it's logic as it seems to be way more efficient. (although compilation is failing here, I'm running dmd 2.059 and it gives can't stride on chunks!(short)) would using short or bytes increase performance compared to integers? if so, why did you use shorts instead of bytes? 2012/8/17, Timon Gehr timon.g...@gmx.ch: On 08/16/2012 11:51 PM, maarten van damme wrote: This is because your specific solution is slow. Mine takes 20ms on the 'hard' puzzle and ~13s on the impossible one. (~2.4 GHZ intel x86_64 machine, with gdmd -O -release -inline -noboundscheck.) There is a constant factor between those two solutions. I've compiled it using dmd on my latitude e5500 which is not that fast so I don't think it's that slow... Compiled and run in the same environment, your solution takes 0.26s on the 'hard' one, whereas mine takes 0.0013s. Your solution takes ~1600s on the impossible one whereas mine takes ~13s. Besides, lets say mine is five times slower, Hard facts say that it is at around 100x-200x slower. 3000 seconds is still waaay to much. Sounds reasonable to me. When I'm back able to get my laptop to use my crapy data connection I'll compare. Do you have some optimization ideas by the way? First of all, getting rid of the dynamic allocations is low hanging fruit. Then you'll have to reduce the number of times you recompute the same information. Update/restore the possibilities array as you update/restore the solution attempts. Do this for the whole board at once and use a compact representation of possibilities.
Re: Sudoku Py / C++11 / D?
solving sudoku's well too : http://dpaste.dzfl.pl/903e34b5 I have one question though, how can you make it find all possible solutions? 2012/8/16, Era Scarecrow rtcv...@yahoo.com: On Thursday, 16 August 2012 at 01:05:20 UTC, Era Scarecrow wrote: So far having it running it's found over 23k+ combinations after about 3 minutes. Unless I introduced a bug... Now I'll have to speed it up to make sure and won't take an afternoon to calculate.
Re: sorting failed error
I now tried to bring it to the next level, using concurrency to bread a couple of populations and make the best solutions migrate between them. But, to use concurrency in D, one has to continually cast between immutable, cast immutable away, Not only that, casting away from immutable (or too, the error message is not informative at all) you get error's along the line of opEquals doesn't work with immutable arguments... Why is it that cumbersome? It seems like D took a good idea and ruined it with all that const-stuff. I have the feeling that I've completely missed the whole idea on how concurrency in D should work. Is it normal that you have to either mess with immutable or with the broken shared? Am I implementing everything wrong?
sorting failed error
For fun I started implementing a program that uses genetics algorithm's to solve the travelling salesman problem. I want to sort an array of chromosome structures according to their fitness. I now get the error: core.exception.AssertError@C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm. d(6714): Failed to sort range of type chromosome[]. Actual result is: [chromosom e([city(20, 0), city(25, 25), city(10, 65), city(50, 50), city(75, 30), city(0, 10)]), chromosome([city(10, 65), city(50, 50), city(25, 25), city(75, 30), city( ... I have no idea what is wrong with my code and the error is not very informative. Does anyone have any idea as to what the problem could be? (full code is at https://dl.dropbox.com/u/15024434/travelling_salesman.d , If it's not something obvious then I'm going to try to reduce it to something as small as possible) Maarten
Re: sorting failed error
My cmp is : bool fitnessCompare(chromosome first,chromosome second){ return fitness(first)fitness(second); } float fitness(chromosome victim){ city[] cities=victim.dna; //we need to start from home and return to home cities=city(0,0) ~ cities; cities~=city(0,0); float travelled=0f; for(int x=0;xcities.length-1;x++) travelled+=distance(cities[x],cities[x+1]); return 1/travelled; } I've posted my code too on pastebin : http://pastebin.com/7927Hpv2
Re: sorting failed error
it is guaranteed to never be 0 because it always contains all cities so it will always travel something unless there are no cities or when all cities are in the same place (in which case the task to solve is senseless). I'll create an array containing all finesses and try sorting using that. And bearophile, you're right. it was supposed to be a very quick program just for fun to see how powerful genetics can be. (read about them yesterday.Never looked at a complete implementation and I'm trying to see how far I'd get with some simple rules. My cross over function isn't really that good...) I really dislike contracts, they kind off blow your function up while adding not that much. I'll add some unit tests.
Re: sorting failed error
About float not beeing deterministic, would this behavior also exist when I use doubles? I've changed everything to use doubles now and the same error comes up. My sorting function used so I guess it can never return on (a,b) when (b,a) was true. But on the other hand, it can return false twice. Is it antisymmetric then? I have a struct that encapsulates an array. Shouldn't that struct get passed by value? Because right now the array inside that struct get's passed by reference. How can I circumvent this? I thought I had the problem at the line city[] cities=victim.dna I later on modified cities so it should've been victim.dna.dpu. This didn't solve the problem however...
Re: sorting failed error
2012/7/30 bearophile bearophileh...@lycos.com: maarten van damme: I really dislike contracts, they kind off blow your function up while adding not that much. I'll add some unit tests. They make your programs more robust. Contracts are used to spot bugs in your code and not to validate data coming from the outside world. As most other tools there are few ways to use them well, and many ways to use them badly. I suggest you to read about the meaning of Contract programming, so maybe you will learn to appreciate them. Bye, bearophile I certainly will. Andrei's chapter didn't convince me but maybe reading something more specialized to contract programming specifically will convince me :) About my pass-by-value problem, I am not used to working with structs, I usually work with classes. That's why I completely forgot about post-blit constructors... Still my sorting problem isn't sorted out.
Re: sorting failed error
Great, with that workaround everything works correctly now. I can finally start playing around with my salesman's dna :p There is one little problem left, the comparing problem. I can't really define an opcmp because a city isn't smaller or bigger than another city, it's simply another city. I tried defining opEquals but it still refuses to work (could be a problem on my end though). To clear things out: Comparing an array of structs with inside a dynamic array fails unless you add an opCmp (?or opEquals?) function to that struct. I thought comparing failed because the references to those dynamic arrays were different and that he was comparing references instead of values.
Re: sorting failed error
monarch_dodra, I'm not trying to order cities, I'm trying to filter out duplicate's in my dna chromosomes and == isn't working on structs that encapsulates dynamic arrays. And I can compare elements without defining opCmp. I've written a function that calculates the distance travelled when going to the cities according to that dna and sort using that. It looks like you didn't really get how or what I'm trying to do (I don't blame you, I'm terrible at explaining things). You should really look at the code, most things are more obvious there. Ellery, When I change it so it uses double
Re: sorting failed error
2012/7/31 Timon Gehr timon.g...@gmx.ch: I realize that the code is just for fun, but I have some comments: - don't .dup stuff just in order to index directly. it never has any effect other than performance degradation. (this could be a compiler warning) - crossOver and mutate mutate their parameters in-place. I assume this is by mistake. reproduce effectively inserts every element a couple times because of this -- this is why the bug manifests reliably. (const, immutable annotations?) - make use of $ int from=uniform(0,victim.dna.length); int to=uniform(0,victim.dna.length); swap(victim.dna[from],victim.dna[to]); = swap(victim.dna[uniform(0,$)], victim.dna[uniform(0,$)]); - sort is in-place workers=array(sort!(fitnessCompare)(workers)); = sort!fitnessCompare(workers) - mark local functions static if they do not need to access the enclosing context. - use size_t for array iteration variables (if necessary) for(int x=0;xcities.length-1;x++) travelled+=distance(cities[x],cities[x+1]); = for(size_t x=1;xcities.length;x++) travelled+=distance(cities[x-1],cities[x]); I also removed the subtraction from the array length. This would be correct in this case because cities.length=2 is guaranteed, but it is an error prone pattern. - another way to do it is to drop the loop completely and to use ranges instead: return zip(cities,cities.drop(1)) .map!(a=distance(a.expand)) .reduce!a+b; The benefit is that this is now obviously correct. You might also want to consider not building up the cities array and computing the terms at the boundary explicitly instead: return distance(city(0,0), victim.dna[0]) + distance(victim.dna[$-1], city(0,0)) + zip(victim.dna, victim.dna.drop(1)) .map!(a=distance(a.expand)) .reduce!a+b; The goal is to craft the shortest code possible that is still efficient and easy to follow. - type deduction? further comments whose application does not lead to immediate benefit: - in contracts are better specified in their dedicated section to push the requirements onto the caller. - consider for(;;) as a means for indefinite looping. - the convention is upper case for type names Thank you very much for this criticism, I'm relatively new to programming and these mistakes/points are the kind off things you can't learn from reading a book or two. I have one little question about one of the last points though why use for(;;)? As far as I can tell this simply reduces readability from while(true). Is there any reason for this?
an enum inside another enum
Hi, would the response to this question : http://stackoverflow.com/questions/757684/enum-inheritance be the same for D? I have these two enums: enum first : string{ a=a, b=b } enum second : string{ a=first.a, b=first.b, c=c } Is there a way to make this cleaner? I don't mind having something like second.firstchar.a with firstchar beeing a first enum. To do that I would need to tell the enum that it can also use the type first because in the end, that is a string too...
Re: an enum inside another enum
Such a shame that enums do not allow mixins to be made. This (mixin(EnumInh!First)) would've been an imho way cleaner solution then declaring your own kind off enum and doing template magic on that. I still have some problems with Simen's code (the first one, haven't yet experimented with enumeration.d) template ExtendEnum(T, string s) if (is(T == enum) is(typeof({mixin(enum a {~s~});}))){ mixin( enum ExtendEnum { ~ EnumDefAsString!T() ~ s ~ }); } The newly generated ExtendEnum will try to convert my old enum with string fields to integer fields. the mixin should generated ExtendEnum : string when passing in an enum with type string. Same problem apply's to the second line of this sniped. enum a doesn't have a type yet so it will try to convert everything to ints. As I seem to run into problems few others have, is my usage of enum's incorrect?
Re: getting to know dmd and druntime
Got some more information here : http://wiki.osdev.org/D_Bare_Bones Any way to do this with dmd? When compiling with -debuglib=none and -defaultlib=none I still get a 31 kb executable so druntime still gets linked in.
getting to know dmd and druntime
Right now I'm a bit confused. I assume that the garbage collector and some other parts from druntime need startup code. But what gets run first is my main method in the d file I compile. Does this mean that the first call to something in druntime calls that startup code? If not, what does get ran first? how can I intercept this and run something else? When compiling without druntime the program will crash when initializing an object. How can I implement my own limited druntime that provides it's own version of the new expression? Druntime contains it's own trimmed down garbage collector that is most likely not very efficient. How can I use that one instead of the other more advanced one? Is the garbage collector embedded in druntime or is it somehow linked at compile time from a c-source (I found gc.c in the dmd source). What else gets linked? What exactly does dmd do? Which parts of druntime does it rely on? I really want to get to know that part of D a bit better. Is this somewhere documented? Ideally I want to compile a d file without druntime (and thus with a very limited subset of D). Then, I want to start writing my own version of druntime (that is, providing the needed methods to get something more advanced working but stubbing everything out). I came accross this blog https://www.semitwist.com/articles/article/view/d-on-gba-nds-progress-thanks-to-oopman but the link to the documentation seems to not be working (and judging by the date it will most likely be about D1). To sum everything up : are the inner workings of dmd-druntime somewhere documented?
Re: getting to know dmd and druntime
Noticed I've sent this to digitalmars.D instead of digitalmars.D.learn. Sorry for that, going to resend this in D.learn.
getting to know dmd and druntime
Right now I'm a bit confused. I assume that the garbage collector and some other parts from druntime need startup code. But what gets run first is my main method in the d file I compile. Does this mean that the first call to something in druntime calls that startup code? If not, what does get ran first? how can I intercept this and run something else? When compiling without druntime the program will crash when initializing an object. How can I implement my own limited druntime that provides it's own version of the new expression? Druntime contains it's own trimmed down garbage collector that is most likely not very efficient. How can I use that one instead of the other more advanced one? Is the garbage collector embedded in druntime or is it somehow linked at compile time from a c-source (I found gc.c in the dmd source). What else gets linked? What exactly does dmd do? Which parts of druntime does it rely on? I really want to get to know that part of D a bit better. Is this somewhere documented? Ideally I want to compile a d file without druntime (and thus with a very limited subset of D). Then, I want to start writing my own version of druntime (that is, providing the needed methods to get something more advanced working but stubbing everything out). I came accross this blog https://www.semitwist.com/articles/article/view/d-on-gba-nds-progress-thanks-to-oopman but the link to the documentation seems to not be working (and judging by the date it will most likely be about D1). To sum everything up : are the inner workings of dmd-druntime somewhere documented?
Re: getting to know dmd and druntime
2012/7/22 Nick Sabalausky seewebsitetocontac...@semitwist.com: Actually, that's just a clever illusion. Your main() method isn't really the first thing called, the first thing called is a function in druntime called dmain (or Dmain or _dmain or something like that, I forget offhand). This function does all the initial stuff like calling all the static/module constructors, initializing druntime including the GC, some other stuff, and then actually calling *your* main(). IIRC, this dmain function is in object.d. I've looked and it appears to be in rt/dmain2.d . Great to know that my main() function isn't the first function called, this explains a lot for me. It looks like what I need is a function with the signature extern (C) int main(int argc, char** argv) which initializes the garbage collector etc. To compile it I would need a function with signature _Dmodule_ref What is this and where does it come from? (Got this information from http://www.mail-archive.com/digitalmars-d@puremagic.com/msg89241.html) I'm trying to compile my file with only extern (C) int main with -defaultlib=none and -debuglib=none but the resulting executable is 31 kb so I'm pretty sure druntime is still beeing mixed in.
Re: should a thread print exceptions?
I think spawnlinked will do the job for me, thank you.
how to consume less memory
I use a foreach with parallel where I download and process webpages. Needles to say, this can consume a lot of memory at peak times. I've noticed the D garbage collector doesn't return the memory when it isn't needed anymore. Is there any clever way to limit that usage? Currently it consumes 1 gig but I'm afraid it'll get even higher...
Re: dfmt - D source code formatter
2012/7/5 Jens Mueller jens.k.muel...@gmx.de: Walter Bright wrote: It would be nice to have a D source code formatter. But it needs a champion. Who's up for it? I'm using uncrustify (http://uncrustify.sourceforge.net/). It does most of the time what I want. Jens I'm using uncrustify too although it has the annoying habbit of rewriting = to = causing all functions using the new lambda syntax to break.
Re: Editable and runnable code sample on dlang.org by Damian Ziemba (nazriel)
2012/7/5 André nos...@spambog.com: Great tool! Just a small layout bug: On Firefox 3.6.4 (on Mac) the [your code here] tags is misplaced after clicking the Run button. It then overlaps the appearing output box. Cheers, André same bug with chrome
bad unary function
I have an array of structs and I've written a function that takes as argument a struct (and an array but this is besides the point) and returns a unique string. I wanted to use map to retrieve a string array of all unique strings from that array. I've used it this way: string [] added=map!(toName(a,parsedschema))(mod.added); But I get a compilation error: bad unary function : toName(a,parsedschema) for type randomStruct. Is my usage of map wrong? what's the compiler trying to explain?
Re: bad unary function
Ok, that made sense :) Now I get a variable with the Result type and this isn't castable or convertable to an array of strings, how can I extract the actual result now?
Re: bad unary function
Ok, everything works great now. thank you maarten
Re: Concurrency in D
yeah, I didn't knew std.parallelism was so easy to use. Speed up was really big for minimal effort.
Re: how to handle shared arrays?
Well, maybe idup is a bit better then assumeuniqe. I don't work anymore with that mutable array on the workerthread but using idup is in all cases allowed and cannot cause subtle bugs like me reusing a mutable array that I've casted to immutable and send over to another thread. It's a shame that shared doesn't (yet) work, It looks a bit dirty to convert to immutable and back to mutable simply to pass it over to another thread...
how to handle shared arrays?
I want to have two threads. One parses some content ever half hour and the other continuously parses commands passed from the first thread. When the second thread finished something it should send the results back to the first thread who'll present it to the user. The messages the second thread needs to send back is under the form of an array of a struct. Right now I'm trying something like this: shared (T[]) mods=cast(shared (T[]))modifications.dup; send(tid, mods); This gives me a rather odd-looking errormessage: C:\D\dmd2\windows\bin\..\..\src\phobos\std\variant.d(528): Error: function core. stdc.string.memcpy (void* s1, const(void*) s2, uint n) is not callable using arg ument types (ubyte[20u]*,shared(T[])*,uint) C:\D\dmd2\windows\bin\..\..\src\phobos\std\variant.d(528): Error: cannot implici tly convert expression ( rhs) of type shared(T[])* to const( void*) How should I handle arrays that I will need to send back to another thread? Excuse me for all those questions, I'm really having a hard time grasping the D threading model.
Re: how to handle shared arrays?
Oh thank god, this helps soo much. Now I can finally do away with all those ugly shared casts and variables in my other toy code involving threads. It works like a charm, great.
Re: sorting associative array's keys by values
Everything turned out to be problems with \r \n. The treading system worked perfectly (although I still don't understand how one can use immutable and receiveonly).
Re: sorting associative array's keys by values
and something I forgot to ask, is it a conscious decision to not print out fired asserts in treads? Normally when an assert fails my whole program crashes and I can see what went wrong. With treads however, it quietly dies.