Re: Issue with small floating point numbers
On Thursday, 13 May 2021 at 03:03:37 UTC, Tim wrote: Hello all, I have this piece of code ```D /** Rotate a 2D array (Vector) by phi radians Params: vec = 2D Vector to rotate phi = Degree with which to rotate the Vector in radians Returns: Rotated 2D array (Vector) Example: */ pragma(inline, true) Point2 rotate2D(in Point2 vec, in float phi) pure nothrow { double x = (vec[0]*cos(phi)) - (vec[1]*sin(phi)); double y = (vec[0]*sin(phi)) + (vec[1]*cos(phi)); return [x, y]; } unittest{ auto p = rotate2D([0.0, 10.0], PI_2); assert(p == [-10.0, 0.0]); } ``` When I run the unittest, I get ```[-10, -4.37114e-07]``` back, which is obviously wrong. Any idea as to why it's not making the y-axis zero? Is it a rounding issue with the types I'm using? Thanks in advance You should try to use isClose to compare for floats equality : https://dlang.org/phobos/std_math.html#.isClose Float arithmetic isn't exact, and could give unexpected results like 0.1f + 0.2f != 0.3f
Re: It's DUB's "optional": true broken ?
On Sunday, 28 March 2021 at 15:52:43 UTC, Zardoz wrote: So, we get this dub.json : { "name": "example", "configurations": [ { "name": "example", "targetType": "library" }, { "name": "unittest", "targetType": "library", "importPaths": ["source", "tests"], "sourcePaths": ["source", "tests"], "dependencies": { "silly": "~>1.0.2", "dshould": "~>1.4.3" } } ] } Where "dshould have a dependency to unit-threaded marked as "optional", and not have any "default" set to true. DUB documentation says that the proyect not must pick the optional dependency if I not edit manualy dub.selections.json to pick unit-threaded. Well.. DUB ignores and picks unit-threaded as I can show here : $ dub build Performing "debug" build using /usr/bin/dmd for x86_64. sybok ~master: building configuration "sybok"... $ dub test Generating test runner configuration 'sybok-test-unittest' for 'unittest' (library). Performing "unittest" build using /usr/bin/dmd for x86_64. prettyprint 1.0.7: building configuration "library"... unit-threaded:from 1.0.14: building configuration "library"... unit-threaded:exception 1.0.14: building configuration "library"... unit-threaded:assertions 1.0.14: building configuration "library"... unit-threaded:integration 1.0.14: building configuration "library"... unit-threaded:mocks 1.0.14: building configuration "library"... unit-threaded:property 1.0.14: building configuration "default"... unit-threaded:runner 1.0.14: building configuration "library"... unit-threaded 1.0.14: building configuration "library"... dshould 1.4.3: building configuration "library"... sybok ~master: building configuration "sybok-test-unittest"... Linking... To force a rebuild of up-to-date targets, run again with --force. Running ./sybok-test-unittest ✓ sybok_spec Sybock test Summary: 1 passed, 0 failed in 0 ms And dub.selections.json show this : { "fileVersion": 1, "versions": { "dshould": "1.4.3", "prettyprint": "1.0.7", "silly": "1.0.2", "unit-threaded": "1.0.14" } } Plus, If edit dub.selections.json to remove unit-threaded , every time that I launch dub test, overwrites dub.selections.json and picks again unit-threaded. From my point of view, or documentation it's wrong, or there it's something really broken about this functionality. I think that I can self-answer me. Looks that this related to this : https://github.com/dlang/dub/issues/1706 DUB it's downloading unit-threaded, but not linking against it or using it for run the unit tests. It's more evident if I invert the situation : If I have this dub.json { "name": "example", "configurations": [ { "name": "example", "targetType": "library" }, { "name": "unittest", "targetType": "executable", - "preBuildCommands": ["$DUB run --compiler=$$DC unit-threaded -c gen_ut_main -- -f bin/ut.d -d $DUB"], - "mainSourceFile": "bin/ut.d", "importPaths": ["source", "tests"], "sourcePaths": ["source", "tests"], "dependencies": { "unit-threaded": "~>1.0.14", "pijamas": "~develop" } } ] } Uses unit-threaded runner, as is expected. If I use this dub.json : { "name": "example", "configurations": [ { "name": "v", "targetType": "library" }, { "name": "unittest", "importPaths": ["source", "tests"], "sourcePaths": ["source", "tests"], "dependencies": { "unit-threaded": "~>1.0.14", "pijamas": "~develop" } } ] } Uses the default unit tests runner and not Silly runner that it's leaked from pijamas (Pijamas uses Silly on a "unittest" config, but DUB downloads Silly, even when this project it's using it. This behavior should be on DUB's documentation. It's pretty confusing seeing that DUB it's downloading libraries that would never use, and gives the false impression that it's using it.
Re: How to update terminal output?
On Sunday, 28 March 2021 at 16:45:29 UTC, dog2002 wrote: I mean, I want to write a string without a new line. For example, some command line applications have progress bars. For a single line string I use \r. But it doesn't work for a multiple line string - the application is just adding new lines. You must use ANSI control codes to repositionate the cursor or use a library like ncurses that handle this kind of stuff. https://code.dlang.org/search?q=ncurses In particular , nice-curses have a class to generate a TUI progress bar
It's DUB's "optional": true broken ?
So, we get this dub.json : { "name": "example", "configurations": [ { "name": "example", "targetType": "library" }, { "name": "unittest", "targetType": "library", "importPaths": ["source", "tests"], "sourcePaths": ["source", "tests"], "dependencies": { "silly": "~>1.0.2", "dshould": "~>1.4.3" } } ] } Where "dshould have a dependency to unit-threaded marked as "optional", and not have any "default" set to true. DUB documentation says that the proyect not must pick the optional dependency if I not edit manualy dub.selections.json to pick unit-threaded. Well.. DUB ignores and picks unit-threaded as I can show here : $ dub build Performing "debug" build using /usr/bin/dmd for x86_64. sybok ~master: building configuration "sybok"... $ dub test Generating test runner configuration 'sybok-test-unittest' for 'unittest' (library). Performing "unittest" build using /usr/bin/dmd for x86_64. prettyprint 1.0.7: building configuration "library"... unit-threaded:from 1.0.14: building configuration "library"... unit-threaded:exception 1.0.14: building configuration "library"... unit-threaded:assertions 1.0.14: building configuration "library"... unit-threaded:integration 1.0.14: building configuration "library"... unit-threaded:mocks 1.0.14: building configuration "library"... unit-threaded:property 1.0.14: building configuration "default"... unit-threaded:runner 1.0.14: building configuration "library"... unit-threaded 1.0.14: building configuration "library"... dshould 1.4.3: building configuration "library"... sybok ~master: building configuration "sybok-test-unittest"... Linking... To force a rebuild of up-to-date targets, run again with --force. Running ./sybok-test-unittest ✓ sybok_spec Sybock test Summary: 1 passed, 0 failed in 0 ms And dub.selections.json show this : { "fileVersion": 1, "versions": { "dshould": "1.4.3", "prettyprint": "1.0.7", "silly": "1.0.2", "unit-threaded": "1.0.14" } } Plus, If edit dub.selections.json to remove unit-threaded , every time that I launch dub test, overwrites dub.selections.json and picks again unit-threaded. From my point of view, or documentation it's wrong, or there it's something really broken about this functionality.
Re: Does GtkD work well on Windows?
On Thursday, 24 March 2016 at 21:00:36 UTC, Web Biz Owner wrote: Hi group, I'm interested in developing some GUI programs in D on Windows. Looked into the various D GUI toolkit options a bit, on the D sites and by googling a bit. Thinking of using GtkD. So would like to know whether people think it is a good option for GUI app dev on Windows. Note: I have not ruled out other toolkits. If anyone has any thoughts on their use, please do comment. Thanks, W.B.O. Short answer : Yes, but you need to install (or package with) Gtk dlls. Long answer : Install following this instructions : https://github.com/gtkd-developers/GtkD/wiki/Installing-on-Windows If you would use Dub and you need to be cross-platform, the dub.sdl/json would be a bit more tricky, but works. You would need something like this : libs "gtkd" platform="windows" configuration "nogtk" { platforms "windows" targetType "executable" } configuration "gtk" { platforms "posix" dependency "gtk-d:gtkd" version="~>3.2.0" targetType "executable" }
Re: Using tango or other static lib in static lib
On Sunday, 13 March 2016 at 01:08:29 UTC, Mike Parker wrote: On Sunday, 13 March 2016 at 01:06:33 UTC, Mike Parker wrote: it. Assuming both files live in the same directory, they can be compiled with this command: Somehow I deleted that line: dmd main.d something.d Not would be more easy to simply add a dependency to tango on dub.SDL ? I ask...
Re: How to better organize dub project to get 3 exe from same codebase?
On Saturday, 27 February 2016 at 13:56:21 UTC, Suliman wrote: What I am doing wrong? http://img.ctrlv.in/img/16/02/27/56d1aae37b77a.png Try : dub build code1:App1 dub build code1:App2
Re: How to better organize dub project to get 3 exe from same codebase?
On Thursday, 25 February 2016 at 18:57:08 UTC, Suliman wrote: I have got 3 small projects that have shared code base. At compile time they use few same classes. On runtime they use same config file. How to better to organize work with dub? Try with subpacjages like I did : name "dedcpu" authors "Luis Panadero Guardeño" targetType "none" license "BSD 3-clause" description "DCPU-16 tools" subPackage { name "lem1802" description "Visual LEM1802 font editor" excludedSourceFiles "src/bconv.d" excludedSourceFiles "src/ddis.d" targetType "executable" targetName "lem1802" libs "gtkd" platform="windows" configuration "nogtk" { platforms "windows" } configuration "gtk" { platforms "posix" dependency "gtk-d:gtkd" version="~>3.2.0" } } subPackage { name "bconv" description "Binary file conversor. Converts between different data files for DCPU-16 emulators" targetType "executable" targetName "bconv" excludedSourceFiles "src/lem1802_fontview.d" excludedSourceFiles "src/ddis.d" excludedSourceFiles "src/ui/*" } subPackage { name "ddis" description "Dis-assembler for DCPU-16. Generates a DCPU-16 assembly dump from a binary file." targetType "executable" targetName "ddis" excludedSourceFiles "src/lem1802_fontview.d" excludedSourceFiles "src/bconv.d" excludedSourceFiles "src/ui/*" } https://github.com/Zardoz89/DEDCPU-16/blob/master/dub.sdl
Re: Running task once a day in vibe.d
On Tuesday, 16 February 2016 at 18:30:43 UTC, Nick wrote: Hey folks I'm making a vibe.d application. Once a day it needs to download some data. How do i get the program to perform this task once a day? Regards, Nick Why you not use cron to launch your program at desire time every day ?
Re: How to Generate Entities from an Existing Database in D language ORM?
On Monday, 15 February 2016 at 14:33:24 UTC, Eliatto wrote: Hello! I've found the following C++/Qt project: http://www.treefrogframework.org/ It contains ORM. Treefrog can generate model stubs from the existing database. Is it possible to do the same in any D language ORM library? BTW, similar situation was discussed here: http://programmers.stackexchange.com/questions/299715/using-orms-in-two-separate-programs-which-share-a-db Perhaps you can use liquidbase to generate an XML or json representation and use it to generate hibernated entities. I don't know yet enough about ddbc to say anything Bout his capacity to read the database structure. jDBC can do this, so I expect that DDBC have the same capacity.
Re: DUB, Platform specifications and dependencies
On Monday, 30 November 2015 at 16:54:43 UTC, Sönke Ludwig wrote: Am 24.11.2015 um 19:51 schrieb Zardoz: Actually I'm trying to setup dub to not grab a dependency on Windows ( https://github.com/Zardoz89/DEDCPU-16/blob/master/dub.sdl ) : name "dedcpu" authors "Luis Panadero Guardeño" targetType "none" license "BSD 3-clause" description "DCPU-16 tools" subPackage { name "lem1802" description "Visual LEM1802 font editor" targetType "executable" targetName "lem1802" excludedSourceFiles "src/bconv.d" excludedSourceFiles "src/ddis.d" dependency "gtk-d:gtkd" version="~>3.2.0" platform="posix" libs "gtkd" platform="windows" } ... How ever, running dub on Windows (tested on two different machines), ignores platform specification for gtk-d dependency . What I'm doing wrong ? Platform specifications are currently not supported for dependencies due to the way the dependency resolver works. However, it is possible to use platform specific configurations for this purpose: name "dedcpu" authors "Luis Panadero Guardeño" targetType "none" license "BSD 3-clause" description "DCPU-16 tools" subPackage { name "lem1802" description "Visual LEM1802 font editor" targetType "executable" targetName "lem1802" excludedSourceFiles "src/bconv.d" excludedSourceFiles "src/ddis.d" libs "gtkd" platform="windows" configuration "nogtk" { platforms "windows" } configuration "gtk" { platforms "posix" dependency "gtk-d:gtkd" version="~>3.2.0" } } Thanks!! I ended doing some minor change to get it working : subPackage { name "lem1802" description "Visual LEM1802 font editor" excludedSourceFiles "src/bconv.d" excludedSourceFiles "src/ddis.d" configuration "nogtk" { targetType "executable" targetName "lem1802" platform "windows" libs "gtkd" } configuration "gtk" { targetType "executable" targetName "lem1802" platform "posix" dependency "gtk-d:gtkd" version="~>3.2.0" } }
DUB, Platform specifications and dependencies
Actually I'm trying to setup dub to not grab a dependency on Windows ( https://github.com/Zardoz89/DEDCPU-16/blob/master/dub.sdl ) : name "dedcpu" authors "Luis Panadero Guardeño" targetType "none" license "BSD 3-clause" description "DCPU-16 tools" subPackage { name "lem1802" description "Visual LEM1802 font editor" targetType "executable" targetName "lem1802" excludedSourceFiles "src/bconv.d" excludedSourceFiles "src/ddis.d" dependency "gtk-d:gtkd" version="~>3.2.0" platform="posix" libs "gtkd" platform="windows" } ... How ever, running dub on Windows (tested on two different machines), ignores platform specification for gtk-d dependency . What I'm doing wrong ?
Re: Parallelism Map and Reduce
On Tuesday, 11 December 2012 at 17:50:31 UTC, Ali Çehreli wrote: On 12/11/2012 08:12 AM, Zardoz wrote: Could you please move MapIntegrator() to module-level. Then it should work. Ali I try it and now even with normal Map function give me errors with dmd ! public Entity MapIntegrator ( Entity me) { me.Integrador3Orden (); return me; } void main() { Entity[] objects; ... objects = array( map!MapIntegrator(objects) ); ... } With this error : dmd -w -wi -version=SReduction simulator.d entity.d vector.d -ofreduceSim simulator.d(194): Error: template std.algorithm.map!(MapIntegrator).map does not match any function template declaration /usr/include/dmd/phobos/std/algorithm.d(369): Error: template std.algorithm.map!(MapIntegrator).map(Range) if (isInputRange!(Unqual!(Range))) cannot deduce template function from argument types !()(Entity[])
Static compiling with dmd
How I can compile with static linking with dmd ? I try with dmd -L-static but i get this error : /usr/bin/ld: cannot find -lgcc_s I used before gdc with -static options and owrked well on it, but I need to use now dmd.
Re: Parallelism Map and Reduce
On Tuesday, 11 December 2012 at 15:22:49 UTC, Ali Çehreli wrote: That used to work a couple of dmd versions ago. I think it was a bug that it worked, so it stopped working after bug fixes. If I'm not mistaken this is actually related to a compiler implementation issue: Lambda's have a single pointer to store the context that they have been started in. When a lambda is a free-standing function (aka module function or global function) then there is only the context to deal with. When the template is a member function (taskPool.map is) then there is also the object that the function is started on. The single pointer of the lambda is not sufficient to store both without big changes in the compiler. (I may be off with that description above. e.g. there may be two pointers when three are actually needed, etc.) I had to change following chapter after dmd's behavior had changed: http://ddili.org/ders/d.en/parallelism.html --- Quoting --- import std.parallelism; // ... double averageGrade(Student student) { return student.averageGrade; } // ... auto results = taskPool.map!averageGrade(students, 3); Note: The free-standing averageGrade() function above is needed due to a limitation that involves using local delegates with member function templates like TaskPool.map: auto results = taskPool.map!(a = a.averageGrade)(students, 3); // ← compilation ERROR -- As you see above, the solution is to use a function with taskPool.map, not a lambda. Ali I try to use a function instead of a lambda function I'm keep getting compiler errors. Code : Entity MapIntegrator (ref Entity me) { me.Integrador3Orden (iDeltaT); return me; } objects = array( taskPool.map!MapIntegrator(objects) ); With taskPool.Map I get this errors : simulator.d(196): Error: template instance map!(MapIntegrator) cannot use local 'MapIntegrator' as parameter to non-global template map(functions...) /usr/include/dmd/phobos/std/parallelism.d(1969): Error: function std.parallelism.TaskPool.map!(MapIntegrator).map!(Entity[]).map.Map.fillBuf cannot access frame of function D main /usr/include/dmd/phobos/std/parallelism.d(1974): Error: template instance amap!(MapIntegrator) cannot use local 'MapIntegrator' as parameter to non-global template amap(functions...) /usr/include/dmd/phobos/std/parallelism.d(1675): Error: function std.parallelism.TaskPool.amap!(MapIntegrator).amap!(Entity[],ulong,Entity[]).amap cannot access frame of function D main /usr/include/dmd/phobos/std/parallelism.d(1706): Error: function std.parallelism.TaskPool.amap!(MapIntegrator).amap!(Entity[],ulong,Entity[]).amap.doIt cannot access frame of function D main /usr/include/dmd/phobos/std/parallelism.d(1974): Error: template instance std.parallelism.TaskPool.amap!(MapIntegrator).amap!(Entity[],ulong,Entity[]) error instantiating simulator.d(196):instantiated from here: map!(Entity[]) simulator.d(196): Error: template instance std.parallelism.TaskPool.map!(MapIntegrator).map!(Entity[]) error instantiating make: *** [predSim] Error 1 But again, with std.algorthim Map it don give any error and works fine.
std.algorithm Map using a external variable
I'm trying to use Map with a code like this : ... immutable int m = 10; int[] caca = [1,2,3,4]; auto caca2 = map!( (a) {return a * m;})(caca); writeln(caca2); ... I get a Segmentation fault some times: The most interesting point it's that depends of the code around of it ins the same program. for example If a use getopt at the begin of my program, then seg fault, etc... Looks that there some weird error in gdc 4.6.3 PD: Later I will put the whole code so any can see if I doing some weird thing that make map crazy
Re: std.algorithm Map using a external variable
Well. I just try it again and I noticed this things : -Changind the lambda function from : auto caca2 = map!((a) {return a * iDeltaT;})(caca); to : auto caca2 = map!((a) {return a + iDeltaT;})(caca); Avoid the segmentation fault -Using dmd 2.60 avoid the segmentation fault. The source code is in http://dl.dropbox.com/u/2716434/CodeThatCrash.tgz The makefile only builds againts gdc, so to test it with dmd, I manually compiled the faulty code of serie2Sim.d with : dmd serie2Sim.d entity.d vector.d -ofserie2Sim And I launch it with ./serie2Sim --rand 10 --seed 123 With dmd works, but with gdc not. On Monday, 10 December 2012 at 18:59:31 UTC, H. S. Teoh wrote: On Mon, Dec 10, 2012 at 07:21:47PM +0100, Zardoz wrote: I'm trying to use Map with a code like this : ... immutable int m = 10; int[] caca = [1,2,3,4]; auto caca2 = map!( (a) {return a * m;})(caca); writeln(caca2); ... I get a Segmentation fault some times: The most interesting point it's that depends of the code around of it ins the same program. for example If a use getopt at the begin of my program, then seg fault, etc... [...] Do you have a compilable sample (possibly reduced from your full sources) that exhibits this error? It would help track down the problem. There are some known bugs related to map in older releases of D that may be affecting you. T
How works internally ParallelForEach
How works internally ParallelFor ? I read that lauchn multiple tasks. Each task procces a chunk of the range, but each task it's syncronized , ahve some kind of comunication between or are using shared memory or what ?? In this example code : import std.stdio; import std.parallelism; import std.math; void main() { auto logs = new double[10_000_000]; double total = 0; foreach(i, ref elem; taskPool.parallel(logs, 100)) { elem = log(i + 1.0); total += elem; } writeln(total); } I understand that are launched N task, doing a chunk of 100 elements from logs array. But what happen with total. There is only a total and D is using memory barriers / atomic operations to write in it ? Or each Task have his own total and later joint each private total in the outside total.
Re: How works internally ParallelForEach
On Saturday, 1 December 2012 at 10:58:55 UTC, thedeemon wrote: taskPool.parallel is a library function, it doesn't make compiler smarter and doesn't get much help from the compiler. It means your total variable will not get any special treatment, it's still a local variable referenced from the loop body which is turned into a function by foreach. This function is run by .parallel in several threads, so you'll get a race condition and most probably an incorrect total value. You should avoid changing the same memory in paralel foreach. Processing different elements of one array (even local) is ok. Writing to one variable not ok. Humm... So ParallelForeach only launch N tasks doing a work over a slice from the range and nothing more. The prevois code should work better if i set total to be sahred and hope that D shared vars have nnow the internal barries working ,or I need to manually use semaphores ? import std.stdio; import std.parallelism; import std.math; void main() { auto logs = new double[10_000_000]; shared double total = 0; foreach(i, ref elem; taskPool.parallel(logs, 100)) { elem = log(i + 1.0); total += elem; } writeln(total); } PD: I know that I can use reduction to do the same thing much better...
rdmd and -I args in Windows
I'm trying to compile a small project with rdmd with this line: rdmd --build-only -JC:\Users\luis\Documents\GitHub\DEDCPU-16\src -Isrc -IGtkD\src -Ibuild -ofC:\Users\luis\Documents\GitHub\DEDCPU-16\build\lem1802.exe src\lem1802_fontview.d And I get this error : std.file.FileException@std\file.d(699): src\Config.d: El sistema no puede encontrar el archivo especificado. (Aka System can't find the file) Why this is happening ? I try with absolute and relative paths and nothing it's working. main source code file (lem1802_fontview.d) have this initial lines : module lem1802_fontview; import Config; import ... Config.d is placed in C:\Users\luis\Documents\GitHub\DEDCPU-16\build\src , being generated by CMake and contains : module Config; enum VERSION_MAJOR = ... Directory tree : Main - C:\Users\luis\Documents\GitHub\DEDCPU-16 \---src - Here is lem1802_fontview.d \---dcpu \---ui \---build- Here is generated Config.d
Re: Build / Package system
On Wednesday, 30 May 2012 at 19:12:06 UTC, Jacob Carlborg wrote: On 2012-05-30 20:53, Sputnik wrote: rdmd lloks to work well, escept for two things: 1) I only can compile with dmd. What happend if I like to use gdc to compile ? rdmd --compiler=compiler Wops! 2) I need to put the same flags for linking and includes for gtkd that I use in the makefile. I like to have something more OS agnostic of say to the compiler/builder to include gtkd. That would be nice to have. I managed to doing something similar using git submodules
Re: shared status
El Sun, 15 Apr 2012 23:05:55 +0200, Kapps escribió: On Saturday, 14 April 2012 at 10:48:16 UTC, Luis Panadero Guardeño wrote: What is the status of shared types ? I try it with gdmd v4.6.3 And I not get any warring/error when I do anything over a shared variable without using atomicOp. It's normal ? shared ushort ram[ram_size]; ram[i] = cast(ushort) (bytes[0] | bytes[1] 8); Shared is at the moment (in my opinion anyways) not useable. Very little in Phobos is shared friendly. Most benefits of shared aren't implemented yet. I personally avoid it. So, if I need to share a array of 0x1 elements between 3 or more threads, how should do it ?
Re: RPC module for D ?
I will try it. I only need to make a remote hello world , do a short description , and compare with other RPCs in other 3 languages (university homework...) . On Mon, 30 Jan 2012 17:30:59 +0100, David Nadlinger wrote: On 1/30/12 5:27 PM, luis wrote: There are any RPC module for D ?? I implemented support for Apache Thrift during last summer's GSoC, it's currently under review for inclusion into Thrift trunk: http://klickverbot.at/code/gsoc/thrift/ David -- Yep, I'm afraid that I have a blog : zardoz.es
Re: RPC module for D ?
On Mon, 30 Jan 2012 17:30:59 +0100, David Nadlinger wrote: On 1/30/12 5:27 PM, luis wrote: There are any RPC module for D ?? I implemented support for Apache Thrift during last summer's GSoC, it's currently under review for inclusion into Thrift trunk: http://klickverbot.at/code/gsoc/thrift/ David I try to build it and when i did make check to see it all works I get two fails : thrift.transport.base.TTransportException@src/thrift/transport/socket.d(255): Failed to connect to 127.0.0.1:11122. ./unittest/debug/thrift/server/transport/socket(void thrift.server.transport.socket.__unittest3()+0x1ba) [0x45e2ea] ./unittest/debug/thrift/server/transport/socket(void thrift.server.transport.socket.__modtest()+0x9) [0x46529d] ./unittest/debug/thrift/server/transport/socket(extern (C) bool core.runtime.runModuleUnitTests().int __foreachbody272(ref object.ModuleInfo*)+0x30) [0x47f228] ./unittest/debug/thrift/server/transport/socket(int object.ModuleInfo.opApply(scope int delegate(ref object.ModuleInfo*))+0x55) [0x4712d9] ./unittest/debug/thrift/server/transport/socket(runModuleUnitTests+0xa7) [0x47f0f7] ./unittest/debug/thrift/server/transport/socket(extern (C) int rt.dmain2.main(int, char**).void runAll() +0x27) [0x47583f] ./unittest/debug/thrift/server/transport/socket(extern (C) int rt.dmain2.main(int, char**).void tryExec (scope void delegate())+0x2a) [0x4753ae] ./unittest/debug/thrift/server/transport/socket(main+0xd3) [0x47533f] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x2b67f2bc730d] FAIL: unittest/debug/thrift/server/transport/socket thrift.transport.base.TTransportException@src/thrift/transport/socket.d(255): Failed to connect to 127.0.0.1:11122. ./unittest/release/thrift/server/transport/socket(void thrift.server.transport.socket.__unittest3()+0x19f) [0x45e0a7] ./unittest/release/thrift/server/transport/socket(void thrift.server.transport.socket.__modtest()+0x9) [0x46372d] ./unittest/release/thrift/server/transport/socket(extern (C) bool core.runtime.runModuleUnitTests().int __foreachbody272(ref object.ModuleInfo*)+0x30) [0x47d32c] ./unittest/release/thrift/server/transport/socket(int object.ModuleInfo.opApply(scope int delegate(ref object.ModuleInfo*))+0x55) [0x46f749] ./unittest/release/thrift/server/transport/socket(runModuleUnitTests+0xa7) [0x47d1fb] ./unittest/release/thrift/server/transport/socket(extern (C) int rt.dmain2.main(int, char**).void runAll() +0x27) [0x473caf] ./unittest/release/thrift/server/transport/socket(extern (C) int rt.dmain2.main(int, char**).void tryExec (scope void delegate())+0x2a) [0x47381e] ./unittest/release/thrift/server/transport/socket(main+0xd3) [0x4737af] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x2b6f742c530d] FAIL: unittest/release/thrift/server/transport/socket -- Yep, I'm afraid that I have a blog : zardoz.es
Re: RPC module for D ?
On Tue, 31 Jan 2012 00:17:18 +0100, David Nadlinger wrote: On 1/30/12 11:35 PM, Zardoz wrote: I try to build it and when i did make check to see it all works I get two fails : […] Oh, I'm afraid you caught me in a bad moment – because the version for upstream integration is frozen at Thrift's JIRA, I've been a bit more careless with multi-platform testing when pushing to my GitHub master (resp. d-gsoc) branch than normal – was an artifact of IPv6 support being rolled out, should be fixed now. Also, please note that the »all green« status on the project page applies to commit 73e7e5e (the one submitted for upstream integration), I didn't have time to check whether the IPv6 stuff works on Windows yet. David At least I can say that the Tutorial client server works (async_client not compile) :) . For me it's enough . -- Yep, I'm afraid that I have a blog : zardoz.es
Re: About to!int
On Mon, 30 Jan 2012 21:01:38 -0500, bearophile wrote: In D to!int( 12\n) gives a run-time error. So time ago I have weakly asked Andrei to change to!int, to let it ignore leading and trailing whitespace, but he has ignored my request. A leading newline comes often from input stdin.readln() and other sources. So in D you need to add a strip(): int n = to!int(stdin.readln().strip()); Bye, bearophile Try parse!int( 12\n); http://www.d-programming-language.org/phobos/std_conv.html#parse -- Yep, I'm afraid that I have a blog : zardoz.es
How convice people that D it's wonderfull in a hour ?
Recently I've been asked if I could give a speech about D in my university. It will be of one hour of long. I not respond yet, but I think that I will do it. Actually I have the problem that I don't know well how explain well too many features and things of D that I like. I think that only talking about D's arrays and type system I will need around half-hour. Any recommendation of how I should focus it ?
Pre and Post contracts and signature constraints
How is the correct way of mix Pre and Post contracts and signature constraints ? I try this that looks logic way and not compile : T foo (T) (T a) if ( is(T : real)) { in { assert (a 0); } body { return a*2; } } I get this errors : Declaration expected, not 'if' unrecognized declaration And this with same result : T foo (T) (T a) in { assert (a 0); } if ( is(T : real)) { body { return a*2; } } I'm using dmd 2.053. -- Yep, I'm afraid that I have a blog : zardoz.es
Re: Pre and Post contracts and signature constraints
On Mon, 04 Jul 2011 19:52:10 +0200, simendsjo wrote: On 04.07.2011 19:42, simendsjo wrote: The in should be in a block of it's own: T foo(T)(T a) if(...) // notice no { here in { } body { } I of course mean that if should not create a new block. Thanks ! I thought that the if () needs to make a block. :P -- Yep, I'm afraid that I have a blog : zardoz.es
Re: Passing a generic struct as parameter
Well, the problem is that I must do the cast always, see : // alias Matrix!(real,4) Mat4r; // alias Vector!(float, 3) Vec3f; // alias Vector!(real, 4) Vec4r; // In Mat4r, VCol it's aliased to Vector!(real, 4) auto tcol = Mat4r.IDENTITY; auto v = cast(tcol.VCol) Vec3f(1, 2 ,3 ); auto v2 = Vec4r(-1, -2 ,-3 ,-4); tcol[1] = v2; // Do a compiler error tcol[2] = v; I get this error : Error: function zmath.matrix.Matrix!(real,4).Matrix.opIndexAssign (real c, ulong row, ulong cl) is not callable using argument types (Vector! (real,4),int) Error: cannot implicitly convert expression (v2) of type Vector!(real,4) to Vector!(real,dim) If I do cast(tcol.Vcol) to v2, this works. Plus if I do a typeid(v1), typeid(v2) to see his types, I get this : zmath.vector.Vector!(real,4).Vector zmath.vector.Vector!(real,dim).Vector On Fri, 01 Jul 2011 02:29:58 +0200, Simen Kjaeraas wrote: On Fri, 01 Jul 2011 01:39:53 +0200, Zardoz luis.panad...@gmail.com wrote: I have a parametrized struct (Vector!(T, dim)) that takes two parameters (Type and a number). And made some Alias with defaults parameters. In other struct (Matrix!(T, dim)), that uses these struct to represent a matrix in column-major order. I have a internall alias for Vector using internally (alias Vector!(T,dim_) VCol;) . The problem that I have it's when I try to use opIndexAssign to assign to a column a Vector. I try this : void opIndexAssign(Vector v, size_t j) { if ( code that see if VCol if same type that v ) { col[j] = v; } else { col[j] = cast (VCol) v; } } But not compile... I get this error : Error: struct zmath.vector.Vector(T,ulong dim_) if (__traits (isFloating,T)) is used as a type Error: template instance zmath.matrix.Matrix!(float,2) error instantiating So finally I try this : /** * Assigns a new column vector */ void opIndexAssign(VCol v, size_t j) { col[j] = v; } But now I must do cast outside, even knowing that are same type. Plus now I must keep VCol alias public. How should fix this, or What is the correct way of doing this ? Private symbols in D are visible outside the defining module (and private symbols are accessible inside the same module), so having the alias private is no problem. In other words, the latter solution is good, and should not require any casting or public alias. Or have I perhaps misunderstood? Is there some other reason you need to cast? Also, the error message you get (Vector(...) is used as a type) is indicative of your referring to the Vector template rather than an instantiation. Struct templates in D behave as if defined thusly: template Foo( T ) { struct Foo { } } for a struct Foo( T ). Note : I have a opCast for Vector that cast between Vectors with different parameters and it's checked that works. Second Question : I'm thinking publish this small Vector/Quaternion/ Matrix lib that I made learning D2.. where I should put and how ? (and I use Git) GitHub, then? Or dsource.org. -- Yep, I'm afraid that I have a blog : zardoz.es
Re: Passing a generic struct as parameter
Thanks. I imagined something similar, that Vector alone not is type. How I can templatize opIndexAssign function ? I tried this : void opIndexAssign(U)(U v, size_t j) { col[j] = v; } And I get a error : Error: template zmath.matrix.Matrix!(float,2).Matrix.opIndexAssign(U) conflicts with function zmath.matrix.Matrix!(float,2).Matrix.opIndexAssign at src/matrix.d(261) That I interpret that this opIndexAssign clash with other opIndexAssign that I have to direct access to matrix cells void opIndexAssign(T c, size_t row, size_t cl) { col[cl][row] = c; } I said before that I made a opCast for Vector ? On Fri, 01 Jul 2011 00:12:43 +, Jonathan M Davis wrote: On 2011-06-30 16:39, Zardoz wrote: I have a parametrized struct (Vector!(T, dim)) that takes two parameters (Type and a number). And made some Alias with defaults parameters. In other struct (Matrix!(T, dim)), that uses these struct to represent a matrix in column-major order. I have a internall alias for Vector using internally (alias Vector!(T,dim_) VCol;) . The problem that I have it's when I try to use opIndexAssign to assign to a column a Vector. I try this : void opIndexAssign(Vector v, size_t j) { if ( code that see if VCol if same type that v ) { col[j] = v; } else { col[j] = cast (VCol) v; } } But not compile... I get this error : Error: struct zmath.vector.Vector(T,ulong dim_) if (__traits (isFloating,T)) is used as a type Error: template instance zmath.matrix.Matrix!(float,2) error instantiating So finally I try this : /** * Assigns a new column vector */ void opIndexAssign(VCol v, size_t j) { col[j] = v; } But now I must do cast outside, even knowing that are same type. Plus now I must keep VCol alias public. How should fix this, or What is the correct way of doing this ? Note : I have a opCast for Vector that cast between Vectors with different parameters and it's checked that works. Second Question : I'm thinking publish this small Vector/Quaternion/ Matrix lib that I made learning D2.. where I should put and how ? (and I use Git) The first thing that you need to understand is that Vector is not a type. It does not exist. Vector!(int, 4) is a type. Vector!(float, 3) is a type. Vector is not. Vector is a template for a type. When you use a template, you instantiate it for a particular set of arguments, and that creates a new type. An instantiation of a templated type such as Vector is a type, and every instantiation is its own, separate type which has no connection with any other instantion of that template. So, it makes no sense for a function to take a Vector (though within the Vector template that works, because Vector stands for that particular instantiation inside of the Vector template). If you want a function to take multiple instantiations of a template, then you need to templatize the function. If you want it to take a particular instantiation of a template, then you give its parameter that exact template instantiation. Now, if you want two separate instantions (such as Vector!(int, 3) and Vector! (float, 3)) to interact, you're going to need to either write opCasts to cast between them or have templated functions which are templated on both of their types (e.g. func(V1, V2)(V1 vector1, V2 vector2) {...}). They are two completed different types, just like if you created IntVector and FloatVector, so you have to write code which allows them to interact. They aren't going to just work together because they came from the same template. - Jonathan M Davis -- Yep, I'm afraid that I have a blog : zardoz.es
Re: Passing a generic struct as parameter
Finally I try this small test code : struct A(T, int U) { T x; static enum foo = U; Tout opCast( Tout ) () if (isA!Tout) { Tout nt; nt.x = x; return nt; } string toString() { return to!string(x); } } struct B(T, int I) { enum foo2 = I; alias A!(T, foo2) Internal; Internal[foo2 * 2] y; void opIndexAssign(K) (K v, size_t j) if (isA!(K) K.foo == Internal.foo is(typeof(K.x) == typeof(y[0].x)) ) { y[j] = v; } void opIndexAssign(K) (K v, size_t j) if (isA!(K) (K.foo != Internal.foo || !is(typeof(K.x) == typeof(y[0].x))) ) { y[j] = Internal(v.x); } } template isA(T) { immutable bool isA = __traits(compiles, (){ T t; auto x = t.x; auto u = t.foo; } ); } auto bla = A!(int, 2) (10); auto bla2 =A!(int, 5) (5) B!(int, 3) bleh; bleh[1] = bla; bleh[3] = bla2; writeln(bleh.y); And write : [0, 10, 0, 5, 0, 0] So this works. Only I need to discover why when I try it over Vector and Matrix class, I get errors... Finally, I upload to github : git://github.com/Zardoz89/zmath.git I hope that I not write some barbaric thing in my code I do all self-learning D On Fri, 01 Jul 2011 17:19:36 +0200, Simen Kjaeraas wrote: On Fri, 01 Jul 2011 08:58:32 +0200, Zardoz luis.panad...@gmail.com wrote: Well, the problem is that I must do the cast always, see : // alias Matrix!(real,4) Mat4r; // alias Vector!(float, 3) Vec3f; // alias Vector!(real, 4) Vec4r; // In Mat4r, VCol it's aliased to Vector!(real, 4) auto tcol = Mat4r.IDENTITY; auto v = cast(tcol.VCol) Vec3f(1, 2 ,3 ); auto v2 = Vec4r(-1, -2 ,-3 ,-4); tcol[1] = v2; // Do a compiler error tcol[2] = v; So more likely, this is what you want: void opIndexAssign(U)(Vector!(U,dim) v, size_t j) { static if (is(U == T)) { col[j] = v; } else { col[j] = cast(VCol)v; } } -- Yep, I'm afraid that I have a blog : zardoz.es
Re: Passing a generic struct as parameter
Ok, I fixed it. I just need to put (K) type parameter to the other opIndexAssign D not allow overload operators/methods with different type parameters. They must share same type parameters : void opIndexAssign(K)(K c, size_t row, size_t cl) {... } void opIndexAssign(K) (K v, size_t j) { ... } On Fri, 01 Jul 2011 21:46:56 +, Zardoz wrote: Finally I try this small test code : struct A(T, int U) { T x; static enum foo = U; Tout opCast( Tout ) () if (isA!Tout) { Tout nt; nt.x = x; return nt; } string toString() { return to!string(x); } } struct B(T, int I) { enum foo2 = I; alias A!(T, foo2) Internal; Internal[foo2 * 2] y; void opIndexAssign(K) (K v, size_t j) if (isA!(K) K.foo == Internal.foo is(typeof(K.x) == typeof(y[0].x)) ) { y[j] = v; } void opIndexAssign(K) (K v, size_t j) if (isA!(K) (K.foo != Internal.foo || !is(typeof(K.x) == typeof(y[0].x))) ) { y[j] = Internal(v.x); } } template isA(T) { immutable bool isA = __traits(compiles, (){ T t; auto x = t.x; auto u = t.foo; } ); } auto bla = A!(int, 2) (10); auto bla2 =A!(int, 5) (5) B!(int, 3) bleh; bleh[1] = bla; bleh[3] = bla2; writeln(bleh.y); And write : [0, 10, 0, 5, 0, 0] So this works. Only I need to discover why when I try it over Vector and Matrix class, I get errors... Finally, I upload to github : git://github.com/Zardoz89/zmath.git I hope that I not write some barbaric thing in my code I do all self-learning D On Fri, 01 Jul 2011 17:19:36 +0200, Simen Kjaeraas wrote: On Fri, 01 Jul 2011 08:58:32 +0200, Zardoz luis.panad...@gmail.com wrote: Well, the problem is that I must do the cast always, see : // alias Matrix!(real,4) Mat4r; // alias Vector!(float, 3) Vec3f; // alias Vector!(real, 4) Vec4r; // In Mat4r, VCol it's aliased to Vector!(real, 4) auto tcol = Mat4r.IDENTITY; auto v = cast(tcol.VCol) Vec3f(1, 2 ,3 ); auto v2 = Vec4r(-1, -2 ,-3 ,-4); tcol[1] = v2; // Do a compiler error tcol[2] = v; So more likely, this is what you want: void opIndexAssign(U)(Vector!(U,dim) v, size_t j) { static if (is(U == T)) { col[j] = v; } else { col[j] = cast(VCol)v; } } -- Yep, I'm afraid that I have a blog : zardoz.es
Passing a generic struct as parameter
I have a parametrized struct (Vector!(T, dim)) that takes two parameters (Type and a number). And made some Alias with defaults parameters. In other struct (Matrix!(T, dim)), that uses these struct to represent a matrix in column-major order. I have a internall alias for Vector using internally (alias Vector!(T,dim_) VCol;) . The problem that I have it's when I try to use opIndexAssign to assign to a column a Vector. I try this : void opIndexAssign(Vector v, size_t j) { if ( code that see if VCol if same type that v ) { col[j] = v; } else { col[j] = cast (VCol) v; } } But not compile... I get this error : Error: struct zmath.vector.Vector(T,ulong dim_) if (__traits (isFloating,T)) is used as a type Error: template instance zmath.matrix.Matrix!(float,2) error instantiating So finally I try this : /** * Assigns a new column vector */ void opIndexAssign(VCol v, size_t j) { col[j] = v; } But now I must do cast outside, even knowing that are same type. Plus now I must keep VCol alias public. How should fix this, or What is the correct way of doing this ? Note : I have a opCast for Vector that cast between Vectors with different parameters and it's checked that works. Second Question : I'm thinking publish this small Vector/Quaternion/ Matrix lib that I made learning D2.. where I should put and how ? (and I use Git) -- Yep, I'm afraid that I have a blog : zardoz.es
Re: WTF! Parallel foreach more slower that normal foreach in multicore CPU ?
Thanks, now I'm using pan to read and post directly :D -- Yep, I'm afraid that I have a blog : zardoz.es
Re: WTF! Parallel foreach more slower that normal foreach in multicore CPU ?
Thanks !!! Now I'm getting a more logical result. I get 1407ms normal vs 759ms in parallel foreach with logs[20_000_000] It's strange that clock() do weird things with threading, not ? PD: It's me, or http version of the forum do strange things, like not getting correct javascript action for the buttons if you hover from one to other ??
WTF! Parallel foreach more slower that normal foreach in multicore CPU ?
I'm trying std.parallelism, and I made this code (based over foreach parallel example) : import std.stdio; import std.parallelism; import std.math; import std.c.time; void main () { auto logs = new double[20_000_000]; const num = 10; clock_t clk; double norm; double par; writeln(CPUs : ,totalCPUs ); clk = clock(); foreach (t; 0..num) { foreach(i, ref elem; logs) { elem = log(i + 1.0); } } norm = clock() -clk; clk = clock(); foreach (t; 0..num) { foreach(i, ref elem; taskPool.parallel(logs, 100)) { elem = log(i + 1.0); } } par = clock() -clk; norm = norm / num; par = par / num; writeln(Normal : , norm / CLOCKS_PER_SEC, Parallel : , par / CLOCKS_PER_SEC); } I get this result : CPUs : 2 Normal : 1.325 Parallel : 1.646 And the result changes, every time that I run it, around +-100ms (I think that depends of how are CPUs busy in these moment) I played changin workUnitSize from 1 to 1000 without any apreciable change My computer it's a AMD Athlon 64 X2 Dual Core Processor 6000+ running over a kUbuntu 11.04 64bits with 2 GiB of ram. I compiled it with dmd 2.053 htop shows that when test program are running parallel foreach, both cores are at ~98% of load and with normal foreach, only one core gets at ~99% of load.
Re: WTF! Parallel foreach more slower that normal foreach in multicore CPU ?
Ok, so why in std.parallelism examples are this : // Same thing, but use the default work unit size. // // Timings on an Athlon 64 X2 dual core machine: // // Parallel foreach: 388 milliseconds // Regular foreach: 619 milliseconds foreach(i, ref elem; taskPool.parallel(logs)) { elem = log(i + 1.0); } Plus, a change my code to make that for same elem, calc log 10 times in each loop, and now I get parallel foreach get a bit shorter time that normal foreach Change code : auto logs = new double[200]; const num = 2; clock_t clk; double norm; double par; writeln(CPUs : ,totalCPUs ); foreach (t; 0..num) { foreach(i, ref elem; logs) { foreach(p; 0..100_000) elem = log(i + 1.0); } } norm = clock() -clk; clk = clock(); foreach (t; 0..num) { foreach(i, ref elem; taskPool.parallel(logs, 100)) { foreach(p; 0..100_000) elem = log(i + 1.0); } } New times : Normal : 12.725 Parallel : 12.499
Re: WTF! Parallel foreach more slower that normal foreach in multicore CPU ?
Code : auto logs = new double[200]; const num = 2; clock_t clk; double norm; double par; writeln(CPUs : ,totalCPUs ); clk = clock(); foreach(i, ref elem; logs) { elem = log(i + 1.0); } norm = clock() -clk; clk = clock(); foreach(i, ref elem; taskPool.parallel(logs, 100)) { elem = log(i + 1.0); } I get same problem. Parallel foreach, is more slower that normal foreach. And it's same code that hace lib example that claims that parallel foreach do it in aprox. half time in Athlon X2
It's dsss live ?
I'm learning D2, and puxxled when I see that something usefull like dsss, looks that not have any updte for too long time. In his SVN, show that not have any update in years!!! (or I'm blind). It's dsss dead ??