Re: Introduction to programming with compile time sequences in D

2020-08-25 Thread data pulverizer via Digitalmars-d-announce
On Tuesday, 25 August 2020 at 15:58:46 UTC, Petar Kirov [ZombineDev] wrote: On Tuesday, 25 August 2020 at 15:30:17 UTC, data pulverizer wrote: I think your article is quite valuable is it covers many aspects of template programming in D, while being quite approachable as well. May I suggest

Re: Introduction to programming with compile time sequences in D

2020-08-25 Thread data pulverizer via Digitalmars-d-announce
On Tuesday, 25 August 2020 at 14:02:33 UTC, Petar Kirov [ZombineDev] wrote: Nice article! I haven't had the chance to read it fully, so far [snip] I though of writing at the beginning that it was long and that readers could dip in and out of the article as they wished but decided that people

Re: Introduction to programming with compile time sequences in D

2020-08-25 Thread data pulverizer via Digitalmars-d-announce
On Tuesday, 25 August 2020 at 14:02:33 UTC, Petar Kirov [ZombineDev] wrote: Nice article! I haven't had the chance to read it fully, so far now I have just one quick suggestion regarding removing items from sequences [0]. I think it would be much simpler (and likely more efficient) to avoid

Introduction to programming with compile time sequences in D

2020-08-24 Thread data pulverizer via Digitalmars-d-announce
I have a draft new blog article "Introduction to programming with compile time sequences in D", it's on Github and I would appreciate feedback before it goes live https://gist.github.com/dataPulverizer/67193772c52e7bd0a16414cb01ae4250 Comment welcome. Many thanks

Re: opIndex for type list

2020-08-24 Thread data pulverizer via Digitalmars-d-learn
On Monday, 24 August 2020 at 14:36:22 UTC, Adam D. Ruppe wrote: On Monday, 24 August 2020 at 14:19:14 UTC, data pulverizer wrote: I am trying to implement `opIndex` (e.g. T[i]) for types in a struct. So for I have `length`: Can't really do that, the operator overloads work on instances

Re: opIndex for type list

2020-08-24 Thread data pulverizer via Digitalmars-d-learn
On Monday, 24 August 2020 at 14:19:14 UTC, data pulverizer wrote: I am trying to implement `opIndex` (e.g. T[i]) for types in a struct. p.s. I know I could just write a separate `get` template, but `AliasSeq` has opIndex and opSlice operators, so I wonder whether it is possible to get those

opIndex for type list

2020-08-24 Thread data pulverizer via Digitalmars-d-learn
Hi all, I am trying to implement `opIndex` (e.g. T[i]) for types in a struct. So for I have `length`: ```d struct TList(T...) { enum long length = T.length; } ``` and have tried including ```d alias opIndex(long i) = T[i]; ``` or ```d alias opIndex(alias i) = T[i]; ``` called with

Re: String mixin from within a template

2020-08-23 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 23 August 2020 at 21:13:51 UTC, ag0aep6g wrote: On Sunday, 23 August 2020 at 20:54:22 UTC, data pulverizer wrote: compiled string 1: alias x0 = Remove(indicies[i] - i, Args); Error: found - when expecting ) Error: semicolon expected to close alias declaration Error: no identifier for

Re: String mixin from within a template

2020-08-23 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 23 August 2020 at 20:12:12 UTC, ag0aep6g wrote: On Sunday, 23 August 2020 at 19:42:47 UTC, data pulverizer wrote: `alias x` ~ i ~ ` = Remove(indexes[i] - i, x`~ (i - 1) ~ `);` [...] ```d Error: no identifier for declarator x ``` Indicating that the concatenation `~` is not

String mixin from within a template

2020-08-23 Thread data pulverizer via Digitalmars-d-learn
Hi all, I am trying to dynamically create compile time variables by using string and template mixins. I have tried both approaches and they have failed. The central thing I am trying to create is a line like this: ```d `alias x` ~ i ~ ` = Remove(indexes[i] - i, Args);` ``` where a compile

Re: Creating a pointer array

2020-08-22 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 22:21:21 UTC, data pulverizer wrote: On Wednesday, 19 August 2020 at 21:10:00 UTC, data pulverizer wrote: alias is one of those awesome chameleons in D. The template equivalent is ``` template P(T) = T*; ``` Correction ... ``` template P(T){ alias P = T*;

Re: AliasSeq!() deletes item in type list

2020-08-22 Thread data pulverizer via Digitalmars-d-learn
On Saturday, 22 August 2020 at 21:52:53 UTC, Paul Backus wrote: On Saturday, 22 August 2020 at 21:45:35 UTC, data pulverizer wrote: AliasSeq's don't nest and automatically expand when you use them, so when you write MyTemplate!(Nothing, types) it gets expanded to MyTemplate!(bool,

AliasSeq!() deletes item in type list

2020-08-22 Thread data pulverizer via Digitalmars-d-learn
Hi all, just wandering if this is a bug, I certainly didn't expect the output: ```d alias AliasSeq(T...) = T; alias Nothing = AliasSeq!(); template MyTemplate(S, Args...) { pragma(msg, "Args: ", Args); } void main() { alias types = AliasSeq!(bool, string, ubyte, short, ushort); alias

Re: Reading IDX Files in D, an introduction to compile time programming

2020-08-21 Thread data pulverizer via Digitalmars-d-announce
On Friday, 21 August 2020 at 15:54:14 UTC, H. S. Teoh wrote: CSS leakage into text in 2nd bullet point under "Introduction": "uspadding: 0.5em;s" should be "uses". Thanks, just fixed it.

Reading IDX Files in D, an introduction to compile time programming

2020-08-21 Thread data pulverizer via Digitalmars-d-announce
I have written an article targeted at people new to D on compile-time programming: https://www.active-analytics.com/blog/reading-idx-files-in-d/ and tweeted it here: https://twitter.com/chibisi/status/1296824381088440320?s=20 Comments welcome. Thanks in advance.

Re: Disjoint slices of an array as reference

2020-08-20 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 20 August 2020 at 08:26:59 UTC, Ali Çehreli wrote: On 8/19/20 9:11 PM, data pulverizer wrote: Thanks. I might go for a design like this: ``` struct View(T){   T* data;   long[2][] ranges; } ``` [...] I implemented the same idea recently; it's a fun exercise. :) I didn't

Re: Disjoint slices of an array as reference

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 20 August 2020 at 03:47:15 UTC, Paul Backus wrote: double[][] y; y ~= x[0..5]; Thanks. I might go for a design like this: ``` struct View(T){ T* data; long[2][] ranges; } ``` The ranges are were the slices are stored and T* (maybe even immutable(T*)) is a pointer is to the

Re: Disjoint slices of an array as reference

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 20 August 2020 at 02:38:33 UTC, data pulverizer wrote: I've been thinking about this some more and I don't think it is possible. An array in D is effectively two pointers either side of a memory block. When you create a slice you are creating another array two pointers somewhere

Re: Disjoint slices of an array as reference

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 20 August 2020 at 02:21:15 UTC, data pulverizer wrote: However I would like to have disjoint slices, something like this: ``` auto y = x[0..5, 9..14]; ``` I've been thinking about this some more and I don't think it is possible. An array in D is effectively two pointers either

Disjoint slices of an array as reference

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
I have been trying to create a new array from an existing array that is effectively a view on the original array. This can be done with slices in D: ``` auto x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; auto y = [0..5]; ``` y a subset of the x array. If I

Location of core.internal.traits : CoreUnqual in Dlang GitHub repo

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
Hi all, I've been looking for where `CoreUnqual` is defined in the Dlang repos. I've tried searching in dmd and phobos but only found the reference usage in std.traits: import core.internal.traits : CoreUnqual; I'd like to know where it is defined so I can (attempt to!) study the code.

Re: Creating a pointer array

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 21:10:00 UTC, data pulverizer wrote: alias is one of those awesome chameleons in D. The template equivalent is ``` template P(T) = T*; ``` Correction ... ``` template P(T){ alias P = T*; } ```

Re: Creating a pointer array

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 20:09:31 UTC, bachmeier wrote: On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer wrote: Maybe I'm the only one, but I think double*[] is hideous, and I'd sure hate for someone not used to D to see it. Alias is your friend. I think this is much nicer:

Re: Creating a pointer array

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 13:12:21 UTC, data pulverizer wrote: On Wednesday, 19 August 2020 at 13:08:37 UTC, Adam D. Ruppe wrote: On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer wrote: How do you create an array of pointers in D? I tried something like ``` double* []y;

Re: Creating a pointer array

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 13:08:37 UTC, Adam D. Ruppe wrote: On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer wrote: How do you create an array of pointers in D? I tried something like ``` double* []y; ``` I'd write it double*[] y; but yeah that's it. Error: only one

Creating a pointer array

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
Hi all, How do you create an array of pointers in D? I tried something like ``` double* []y; ``` Or ``` (double*) []y; ``` But I get the error: ``` Error: only one index allowed to index double[] ``` Thanks in advance.

Re: Mixin and imports

2020-06-08 Thread data pulverizer via Digitalmars-d-learn
On Monday, 8 June 2020 at 16:02:02 UTC, Steven Schveighoffer wrote: On 6/8/20 11:11 AM, jmh530 wrote: On Monday, 8 June 2020 at 14:27:26 UTC, data pulverizer wrote: [snip] Out of curiosity what does the "." in front of `foo` mean? [snip] ag0aep6g provided the link to it [snip] The dot

Re: Mixin and imports

2020-06-08 Thread data pulverizer via Digitalmars-d-learn
On Monday, 8 June 2020 at 02:55:25 UTC, jmh530 wrote: ``` ... template foo(string f) { mixin("alias foo = .foo!(" ~ f ~ ");"); } ... ``` Out of curiosity what does the "." in front of `foo` mean? I've seen that in some D code on the compiler in GitHub and have no idea what it does. I

Re: What is the equivalent of -version=Flag for conditional compilation in the ldc2 compiler?

2020-06-05 Thread data pulverizer via Digitalmars-d-learn
On Friday, 5 June 2020 at 22:39:23 UTC, Steven Schveighoffer wrote: It's in there, I had to do grep to find it: --d-version= - Compile in version code >= or identified by -Steve Thanks, I tried that but didn't realise I still had the old version flag in the command line

What is the equivalent of -version=Flag for conditional compilation in the ldc2 compiler?

2020-06-05 Thread data pulverizer via Digitalmars-d-learn
Hi, I was switching from dmd to ldc2 and would like to know the equivalent command line for conditional compilation -version=Flag I was using in dmd. I checked the ldc2 --help but didn't see anything relevant. Version there refers to compiler version or some other unrelated things. Thanks

Re: On the D Blog: A Looat at Chapel, D, and Julia Using Kernel Matrix Calculations

2020-06-03 Thread data pulverizer via Digitalmars-d-announce
On Wednesday, 3 June 2020 at 16:15:41 UTC, jmh530 wrote: Also, I'm curious if you know how the Julia functions (like pow/log) are implemented, i.e. are they also calling C/Fortran functions or are they natively implemented in Julia? It's not 100% clear but Julia does appear to implement a

Re: On the D Blog: A Looat at Chapel, D, and Julia Using Kernel Matrix Calculations

2020-06-03 Thread data pulverizer via Digitalmars-d-announce
On Wednesday, 3 June 2020 at 14:34:02 UTC, Mike Parker wrote: Some of you may have seen a draft of this post from user "data pulverizer" elsewhere on the forums. The final draft is now on the D Blog under his real name and ready for your perusal. The blog:

Re: Mir Slice Column or Row Major

2020-05-26 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 01:31:23 UTC, data pulverizer wrote: Hi, I have started running Kernel benchmarks calculations using Mir NDSlice, and I'm getting times that are much slower than expected. I've swapped the calculation to row major and it's running as expected.

Re: How to target ldc compiler only in dub

2020-05-26 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 02:09:48 UTC, Mike Parker wrote: Thanks. Is there anyway to verify that the flags I am passing to the compiler are being used? dub -v It shows you the full compiler command line. Ah, I forgot to force the rebuild. Thanks.

Re: How to target ldc compiler only in dub

2020-05-26 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 01:06:48 UTC, mw wrote: And you can use option dub -v to verify it's calling the correct compiler cmd. Thanks. Is there anyway to verify that the flags I am passing to the compiler are being used?

Mir Slice Column or Row Major

2020-05-26 Thread data pulverizer via Digitalmars-d-learn
Hi, I have started running Kernel benchmarks calculations using Mir NDSlice, and I'm getting times that are much slower than expected. To check that I'm not making an obvious mistake, below are samples of the code I am using. The way the selection happens is that the `calculateKernelMatrix`

Re: How to target ldc compiler only in dub

2020-05-26 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 00:52:55 UTC, mw wrote: On Tuesday, 26 May 2020 at 22:28:14 UTC, data pulverizer wrote: I am trying to build a package to target LDC compiler only. I set env: LDC= DUB = $(LDC)/bin/dub then, run this new dub: $(DUB) build Thanks. Building with `dub run

How to target ldc compiler only in dub

2020-05-26 Thread data pulverizer via Digitalmars-d-learn
Hi, I am trying to build a package to target LDC compiler only. I have both dmd and ldc2 (1.18.0) installed on my system. The dub file is: ``` { "authors": [ "Me" ], "copyright": "Copyright © 2020, Me", "dependencies": {

Re: Variable "i" can not be read at compile time

2020-05-24 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 24 May 2020 at 16:57:54 UTC, ag0aep6g wrote: On 24.05.20 18:34, data pulverizer wrote: Since `kernel` is a `Tuple`, you can only access it with compile-time constant indices. But your loop variable `i` is not a compile-time constant, it's being calculated at run time. What's more,

Variable "i" can not be read at compile time

2020-05-24 Thread data pulverizer via Digitalmars-d-learn
Hi all, I'm getting the error: ``` Error: variable i cannot be read at compile time Error: template instance script.runKernelBenchmarks!(Tuple!(DotProduct!float, Gaussian!float, Polynomial!float, Exponential!float, Log!float, Cauchy!float, Power!float, Wave!float, Sigmoid!float)) error

Re: Error running concurrent process and storing results in array

2020-05-21 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 21 May 2020 at 07:38:45 UTC, data pulverizer wrote: Started uploading the code and writing the article for this. The code for each language can be run, see the script.x files in each folder for details and timings. https://github.com/dataPulverizer/KernelMatrixBenchmark Thanks

Re: Template type deduction question

2020-05-21 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 21 May 2020 at 07:16:11 UTC, Basile B. wrote: The problem is that "K" is a template type parameter [1]. When the compiler deduces the parameter that ends up with a symbol, i.e not a type. To permit a symbol to be deduced you can use a template alias parameter[2] instead: ---

Re: Error running concurrent process and storing results in array

2020-05-21 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 17:31:39 UTC, Jacob Carlborg wrote: On 2020-05-06 12:23, data pulverizer wrote: Yes, I'll do a blog or something on GitHub and link it. It would be nice if you could get it published on the Dlang blog [1]. One usually get paid for that. Contact Mike Parker. [1]

Template type deduction question

2020-05-20 Thread data pulverizer via Digitalmars-d-learn
I'd like to pass kernel functions using: ``` auto calculateKernelMatrix(K, T)(K!(T) Kernel, Matrix!(T) data) { ... } ``` and call it using `calculateKernelMatrix(myKernel, myData);` but I get a type deduction error and have to call it using `calculateKernelMatrix!(typeof(myKernel),

How to allocate/free memory under @nogc

2020-05-20 Thread data pulverizer via Digitalmars-d-learn
I'm a bit puzzled about the whole `@nogc` thing. At first I thought it just switched off the garbage collector and that you had to allocate and free memory manually using `import core.memory: GC;` I tried this and it failed because @nogc means that the function can not allocate/free memory

Re: Is it possible to implement operators as ordinary functions?

2020-05-18 Thread data pulverizer via Digitalmars-d-learn
On Tuesday, 19 May 2020 at 02:42:22 UTC, Adam D. Ruppe wrote: On Tuesday, 19 May 2020 at 02:36:24 UTC, data pulverizer wrote: I was wandering if it possible to implement operators as ordinary functions instead of as member functions of a class or struct for example something like this: nope,

Is it possible to implement operators as ordinary functions?

2020-05-18 Thread data pulverizer via Digitalmars-d-learn
I was wandering if it possible to implement operators as ordinary functions instead of as member functions of a class or struct for example something like this: ``` import std.stdio: writeln; struct Int{ int data = 0; } Int opBinary(string op)(Int x1, Int x2) { static if((op == "+") ||

Re: Error running concurrent process and storing results in array

2020-05-14 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 13 May 2020 at 15:13:50 UTC, wjoe wrote: On Friday, 8 May 2020 at 13:43:40 UTC, data pulverizer wrote: [...] I also chose kernel matrix calculations, you can't always call a library, sometimes you just need to write performant code. Aren't kernel function calls suffering a

Re: Error running concurrent process and storing results in array

2020-05-08 Thread data pulverizer via Digitalmars-d-learn
On Friday, 8 May 2020 at 13:36:22 UTC, data pulverizer wrote: ...I've disallowed calling BLAS because I'm looking at the performance of the programming language implementations rather than it's ability to call other libraries. Also BLAS is of limited use for most of all the kernel functions,

Re: Error running concurrent process and storing results in array

2020-05-08 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 7 May 2020 at 14:49:43 UTC, data pulverizer wrote: After running the Julia code by the Julia community they made some changes (using views rather than passing copies of the array) and their time has come down to ~ 2.5 seconds. The plot thickens. I've run the Chapel code past the

Re: Error running concurrent process and storing results in array

2020-05-07 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 7 May 2020 at 15:41:12 UTC, drug wrote: 07.05.2020 17:49, data pulverizer пишет: On Thursday, 7 May 2020 at 02:06:32 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 10:23:17 UTC, data pulverizer wrote: D:  ~ 1.5 seconds After running the Julia code by the Julia

Re: Error running concurrent process and storing results in array

2020-05-07 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 7 May 2020 at 02:06:32 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 10:23:17 UTC, data pulverizer wrote: D: ~ 1.5 seconds This is going to sound absurd but can we do even better? If none of the optimizations we have so far is using simd maybe we can get even

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 10:23:17 UTC, data pulverizer wrote: D: ~ 1.5 seconds This is going to sound absurd but can we do even better? If none of the optimizations we have so far is using simd maybe we can get even better performance by using it. I think I need to go and read a

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 23:10:05 UTC, data pulverizer wrote: The -O3 -O5 optimization on the ldc compiler is instrumental in bringing the times down, going with -02 based optimization even with the other flags gives us ~ 13 seconds for the 10,000 dataset rather than the very nice 1.5

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 17:31:39 UTC, Jacob Carlborg wrote: On 2020-05-06 12:23, data pulverizer wrote: Yes, I'll do a blog or something on GitHub and link it. It would be nice if you could get it published on the Dlang blog [1]. One usually get paid for that. Contact Mike Parker. [1]

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 08:28:41 UTC, drug wrote: What is current D time? ... Current Times: D: ~ 1.5 seconds Chapel: ~ 9 seconds Julia: ~ 35 seconds That would be really nice if you make the resume of your research. Yes, I'll do a blog or something on GitHub and link it.

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 07:57:46 UTC, WebFreak001 wrote: On Wednesday, 6 May 2020 at 07:42:44 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 07:27:19 UTC, data pulverizer wrote: Just tried removing the boundscheck and got 1.5 seconds in D! Cool! But before getting too excited I

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 07:47:59 UTC, drug wrote: 06.05.2020 10:42, data pulverizer пишет: On Wednesday, 6 May 2020 at 07:27:19 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 06:54:07 UTC, drug wrote: Thing are really interesting. So there is a space to improve performance in 2.5

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 07:27:19 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 06:54:07 UTC, drug wrote: Thing are really interesting. So there is a space to improve performance in 2.5 times :-) Yes, `array` is smart enough and if you call it on another array it is no op. What

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 07:27:19 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 06:54:07 UTC, drug wrote: Thing are really interesting. So there is a space to improve performance in 2.5 times :-) Yes, `array` is smart enough and if you call it on another array it is no op. What

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 06:49:13 UTC, drug wrote: ... Then you can pass the arguments in ctor of the derived class like: ``` foreach(long i; 0..n) new DerivedThread(double)(i), cast(double)(i + 1), i, z).start(); thread_joinAll(); ``` not tested example of derived thread ``` class

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 06:54:07 UTC, drug wrote: Thing are really interesting. So there is a space to improve performance in 2.5 times :-) Yes, `array` is smart enough and if you call it on another array it is no op. What means `--fast` in Chapel? Do you try `--fast-math` in ldc? Don't

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 05:50:23 UTC, drug wrote: General advice - try to avoid using `array` and `new` in hot code. Memory allocating is slow in general, except if you use carefully crafted custom memory allocators. And that can easily be the reason of 40% cpu usage because the cores are

Re: Error running concurrent process and storing results in array

2020-05-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 05:44:47 UTC, drug wrote: proc is already a delegate, so is a pointer to the delegate, just pass a `proc` itself Thanks done that but getting a range violation on z which was not there before. ``` core.exception.RangeError@onlineapp.d(3): Range violation

Re: Error running concurrent process and storing results in array

2020-05-05 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 04:52:30 UTC, data pulverizer wrote: myData is referencing elements [5..10] of data and not creating a new array with elements data[5..10] copied? Just checked this and can confirm that the data is not being copied so that is not the source of cpu idling:

Re: Error running concurrent process and storing results in array

2020-05-05 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 04:04:14 UTC, Mathias LANG wrote: On Wednesday, 6 May 2020 at 03:41:11 UTC, data pulverizer wrote: Yes, that's exactly what I want the actual computation I'm running is much more expensive and much larger. It shouldn't matter if I have like 100_000_000 threads

Re: Error running concurrent process and storing results in array

2020-05-05 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 03:56:04 UTC, Ali Çehreli wrote: On 5/5/20 8:41 PM, data pulverizer wrote:> On Wednesday, 6 May 2020 at 03:33:12 UTC, Mathias LANG wrote: >> On Wednesday, 6 May 2020 at 03:25:41 UTC, data pulverizer wrote: > Is there something I need to do to wait for each thread to

Re: Error running concurrent process and storing results in array

2020-05-05 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 03:33:12 UTC, Mathias LANG wrote: On Wednesday, 6 May 2020 at 03:25:41 UTC, data pulverizer wrote: [...] The problem here is that `process` is a delegate, not a function. The compiler *should* know it's a function, but for some reason it does not. Making the

Error running concurrent process and storing results in array

2020-05-05 Thread data pulverizer via Digitalmars-d-learn
I have been using std.parallelism and that has worked quite nicely but it is not fully utilising all the cpu resources in my computation so I though it could be good to run it concurrently to see if I can get better performance. However I am very new to std.concurrency and the baby version of

Re: Help, what is the code mean?

2020-04-27 Thread data pulverizer via Digitalmars-d-learn
On Monday, 27 April 2020 at 13:36:25 UTC, Adam D. Ruppe wrote: On Monday, 27 April 2020 at 13:29:08 UTC, lilijreey wrote: Hi: In dlang core.thread.osthread has below code, the 654 line code i can understand why write () first, and {m_fn = fn;}() do what? The stdlib uses that pattern

Re: How to do HEAD request in std.net.curl

2020-04-26 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 26 April 2020 at 22:03:33 UTC, data pulverizer wrote: Hi all, I am using std.net.curl and would like to run a HEAD request to find out if a web page exists - I've looked at the documentation and have tried various things that haven't worked. Thanks Never mind, I've got it, the

How to do HEAD request in std.net.curl

2020-04-26 Thread data pulverizer via Digitalmars-d-learn
Hi all, I am using std.net.curl and would like to run a HEAD request to find out if a web page exists - I've looked at the documentation and have tried various things that haven't worked. Thanks

Re: @safe function with __gshared as default parameter value

2020-04-08 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 8 April 2020 at 19:29:17 UTC, Anonymouse wrote: ``` __gshared int gshared = 42; void foo(ref int i = gshared) @safe { ++i; } void main() { assert(gshared == 42); foo(); assert(gshared == 43); } ``` Dude, you just broke `@safe`! Lol!

Re: @safe function with __gshared as default parameter value

2020-04-08 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 8 April 2020 at 16:53:05 UTC, Anonymouse wrote: ``` import std.stdio; @safe: __gshared int gshared = 42; void foo(int i = gshared) { writeln(i); } void main() { foo(); } ``` This currently works; `foo` is `@safe` and prints the value of `gshared`. Changing the call in

Re: Array fill performance differences between for, foreach, slice

2020-04-08 Thread data pulverizer via Digitalmars-d-learn
In all honesty till now I haven't really thought deeply about memory allocation, I just assumed that malloc, free, and so on where low level operating system functions and that was that. I've heard people in the D community talk about garbage collection, and memory allocation but I didn't

Re: Array fill performance differences between for, foreach, slice

2020-04-01 Thread data pulverizer via Digitalmars-d-learn
Thanks for all the suggestions made so far. I am still interested in looking at the implementation details of the slice assign `arr[] = x` which I can't seem to find. Before I made my initial post, I tried doing a `memcpy` and `memmove` under a `for` loop but it did not change the performance

Re: Dynamic twodimensial array

2020-03-31 Thread data pulverizer via Digitalmars-d-learn
On Tuesday, 31 March 2020 at 21:39:30 UTC, Quantium wrote: I know that to create a dynamic array: int[] m = new int[a]; where a is a variable. And if I need a twodimensial array, code int[][] m = new int[a][b]; where a and b are variables doesn't work. I used dmd compiler, it says: "Cannot read

Array fill performance differences between for, foreach, slice

2020-03-31 Thread data pulverizer via Digitalmars-d-learn
I've observed large differences in timing performance while filling arrays using different methods (for vs foreach vs arr[] = x) and don't know why. I've looked at array.d (https://github.com/dlang/dmd/blob/9792735c82ac997d11d7fe6c3d6c604389b3f5bd/src/dmd/root/array.d) but I'm still none the

Re: OT: Photo of a single atom by David Nadlinger wins top prize

2018-02-14 Thread data pulverizer via Digitalmars-d
On Tuesday, 13 February 2018 at 23:09:07 UTC, Ali Çehreli wrote: David (aka klickverbot) is a longtime D contributor. https://www.epsrc.ac.uk/newsevents/news/single-trapped-atom-captures-science-photography-competitions-top-prize/ Ali Well done David. I saw this news on my twitter feed and

Re: Quora: Why hasn't D started to replace C++?

2018-02-07 Thread data pulverizer via Digitalmars-d
On Tuesday, 30 January 2018 at 20:45:44 UTC, Andrei Alexandrescu wrote: https://www.quora.com/Why-hasnt-D-started-to-replace-C++ Andrei The Betamax Problem When you introduce something new, how do you know that it is going to be compelling enough for people to move from whatever it is they

Re: LDC 1.6.0

2017-12-04 Thread data pulverizer via Digitalmars-d-announce
On Sunday, 3 December 2017 at 12:50:26 UTC, kinke wrote: Hi everyone, on behalf of the LDC team, I'm glad to announce LDC 1.6. The highlights of this version in a nutshell: * Based on D 2.076.1. * Experimental support for dynamic codegen at runtime ('manual JIT'). * Many std.math functions

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-30 Thread data pulverizer via Digitalmars-d-announce
On Wednesday, 30 August 2017 at 22:49:54 UTC, jmh530 wrote: On Wednesday, 30 August 2017 at 22:30:12 UTC, data pulverizer wrote: On Wednesday, 30 August 2017 at 22:10:38 UTC, Jean-Louis Leroy wrote: On Wednesday, 30 August 2017 at 21:30:29 UTC, data pulverizer wrote: In the light of this I

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-30 Thread data pulverizer via Digitalmars-d-announce
On Wednesday, 30 August 2017 at 22:10:38 UTC, Jean-Louis Leroy wrote: On Wednesday, 30 August 2017 at 21:30:29 UTC, data pulverizer wrote: In the light of this I think your package just became more interesting to me. I think that your work and mine are complementary :-) Here is one strange

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-30 Thread data pulverizer via Digitalmars-d-announce
On Wednesday, 30 August 2017 at 22:10:38 UTC, Jean-Louis Leroy wrote: On Wednesday, 30 August 2017 at 21:30:29 UTC, data pulverizer wrote: In the light of this I think your package just became more interesting to me. I think that your work and mine are complementary :-) Yes, one of the

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-30 Thread data pulverizer via Digitalmars-d-announce
On Wednesday, 30 August 2017 at 21:30:29 UTC, data pulverizer wrote: On Wednesday, 30 August 2017 at 20:40:38 UTC, Jean-Louis Leroy wrote: After mulling over this example, I don't see how this proves that Julia does *not* support run time polymorphism. On the contrary. In that case you are

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-30 Thread data pulverizer via Digitalmars-d-announce
On Wednesday, 30 August 2017 at 20:40:38 UTC, Jean-Louis Leroy wrote: After mulling over this example, I don't see how this proves that Julia does *not* support run time polymorphism. On the contrary. If you translate this to D you get the same result by the way: import std.stdio; class

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-30 Thread data pulverizer via Digitalmars-d-announce
On Wednesday, 30 August 2017 at 18:48:58 UTC, data pulverizer wrote: I suspect the reason you can't have parametric typed array containers in statically typed compiled languages is that underneath, they are doubly/linked lists, and there is no way of resolving the types at the end of the

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-30 Thread data pulverizer via Digitalmars-d-announce
On Wednesday, 30 August 2017 at 17:57:49 UTC, data pulverizer wrote: The reason I have never really been comfortable with sub-typing is that the polymorphic types are a black-box, my preference is certainly for parametric type polymorphism. The main disadvantage with parametric polymorphism in

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-30 Thread data pulverizer via Digitalmars-d-announce
On Wednesday, 30 August 2017 at 17:29:42 UTC, Jean-Louis Leroy wrote: On Wednesday, 30 August 2017 at 17:16:59 UTC, data pulverizer wrote: p.p.s typeof(x[1]) # returns Cat so it isn't really polymorphism - the object is never converted to the "parent" type! Lol ... sorry for the confusion!

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-30 Thread data pulverizer via Digitalmars-d-announce
On Wednesday, 30 August 2017 at 17:14:37 UTC, data pulverizer wrote: On Wednesday, 30 August 2017 at 16:45:19 UTC, data pulverizer wrote: You mentioned Julia in your article, however for clarity I would point out that Julia doesn't have OOP-type polymorphism. There is no notion of being able

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-30 Thread data pulverizer via Digitalmars-d-announce
On Wednesday, 30 August 2017 at 16:45:19 UTC, data pulverizer wrote: You mentioned Julia in your article, however for clarity I would point out that Julia doesn't have OOP-type polymorphism. There is no notion of being able to do something like: Animal snoopy = new Dog(); p.s. my bad, I was

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-30 Thread data pulverizer via Digitalmars-d-announce
On Monday, 28 August 2017 at 13:19:19 UTC, Jean-Louis Leroy wrote: On Thursday, 24 August 2017 at 23:50:21 UTC, data pulverizer wrote: I find OOP-polymorphic types ultimately unsatisfying, but I don't know of anyway to write, compile and load a D script with new types and methods on the fly

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-25 Thread data pulverizer via Digitalmars-d-announce
On Friday, 25 August 2017 at 20:54:05 UTC, jmh530 wrote: See below. I haven't implemented the random variables yet, but otherwise it seems to be working well. There is some trickiness with deprecated stuff that I had to hard code, but other than that it's pretty generic. Also, I think it is

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-25 Thread data pulverizer via Digitalmars-d-announce
On Friday, 25 August 2017 at 14:30:03 UTC, jmh530 wrote: On Friday, 25 August 2017 at 01:04:31 UTC, data pulverizer wrote: [snip] With respect to your point about immutability, you might be interested in the parameterize function in dstats.distrib. I hadn't noticed that was there, but I

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-24 Thread data pulverizer via Digitalmars-d-announce
On Friday, 25 August 2017 at 00:35:24 UTC, jmh530 wrote: What you seem concerned about here is how to produce a meaningful error message for distribution that you do not have implementations for. A slightly more elegant solution would be to pack the structs into an AliasSeq and then use

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-24 Thread data pulverizer via Digitalmars-d-announce
On Thursday, 24 August 2017 at 21:13:10 UTC, jmh530 wrote: On UDAs, at least in the current implementation, I think that the actual issue you are trying to address is to force the type in the distribution to be convertible to double in the continuous case and convertible to long in the

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-24 Thread data pulverizer via Digitalmars-d-announce
On Thursday, 24 August 2017 at 18:16:21 UTC, jmh530 wrote: I think at one point I had actually suggested that dstats or something be re-written in a Julia-like way (before I realized how much work that would be!). It looks very pretty. Thanks. I think most of that is down to D's nice syntax

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-24 Thread data pulverizer via Digitalmars-d-announce
On Thursday, 24 August 2017 at 17:01:38 UTC, Ali Çehreli wrote: This works only with compile-time dispatch, right? Yes ... Does Julia support dynamic multiple dispatch? Okay Julia is my second favourite language next to D and one of it's cool features is that even though it is a dynamic

Re: Article: Writing Julia style multiple dispatch code in D

2017-08-24 Thread data pulverizer via Digitalmars-d-announce
On Thursday, 24 August 2017 at 16:41:54 UTC, David Gileadi wrote: Very interesting! Thank you I have a couple suggestions: for newbies like me, it would be nice to include a short explanation of multiple dispatch, and maybe a link to a longer description. Wikipedia's description of

Article: Writing Julia style multiple dispatch code in D

2017-08-24 Thread data pulverizer via Digitalmars-d-announce
Hi all, I have written an article about writing Julia style multiple dispatch code in D (https://github.com/dataPulverizer/dispatch-it-like-julia). I am hoping that it is appropriate for the D blog. Reviews please. Many Thanks!

<    1   2   3   4   >