Re: Specify dmd or ldc compiler and version in a json dub file?

2017-08-08 Thread data pulverizer via Digitalmars-d-learn
On Tuesday, 8 August 2017 at 09:21:54 UTC, Moritz Maxeiner wrote: On Tuesday, 8 August 2017 at 09:17:02 UTC, data pulverizer wrote: Hi, I would like to know how to specify dmd or ldc compiler and version in a json dub file. Thanks in advance. You can't [1]. You can specify the compiler to

Re: Specify dmd or ldc compiler and version in a json dub file?

2017-08-08 Thread data pulverizer via Digitalmars-d-learn
On Tuesday, 8 August 2017 at 09:51:40 UTC, Moritz Maxeiner wrote: If your code depends on capabilities of a specific D compiler, I wouldn't depend on build tools for that, I'd make it clear in the source code via conditional compilation [1]: --- version (DigitalMars) { } else version (LDC) {

Issue with template constraints in numeric types

2017-08-03 Thread data pulverizer via Digitalmars-d-learn
Dear all, I am writing template constraints for different numeric types: ``` import std.stdio: writeln; import std.traits: isIntegral, isNumeric; T test(T)(T x, T y) if(is(T: double) && isNumeric!T) { return x*y; } auto test(T)(T x, T y) if(!is(T: double) && isNumeric!T) {

Re: Issue with template constraints in numeric types

2017-08-03 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 3 August 2017 at 12:24:02 UTC, data pulverizer wrote: The same issue occurs when I try using template specializations instead. ... That is T test(T: double)(T x, T y){...} and T test(T)(T x, T y){...} Thanks

Re: Issue with template constraints in numeric types

2017-08-03 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 3 August 2017 at 12:35:08 UTC, data pulverizer wrote: What about this case: ``` T test(T: double)(T x, T y) { return x*y; } auto test(T)(T x, T y) { return 5*test!double(x, y); } ``` which also gives: ``` int test: 4 double test: 4 ``` Hmm ... it looks as the

Re: D outperformed by C++, what am I doing wrong?

2017-08-17 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 13 August 2017 at 06:09:39 UTC, amfvcg wrote: Hi all, I'm solving below task: given container T and value R return sum of R-ranges over T. An example: input : T=[1,1,1] R=2 output : [2, 1] input : T=[1,2,3] R=1 output : [1,2,3] (see dlang unittests for more examples) Below c++

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: 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: @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: 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: 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: 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: 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 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 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 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-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-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 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

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 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

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: 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: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: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 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 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-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

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: 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,

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-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-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-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

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

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),

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]

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

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: 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

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: 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,

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 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 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: 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

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

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

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: 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

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: 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

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: 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: 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: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 18:37:45 UTC, wjoe wrote: I have some similar functions: void register(C: IFoo)() { _insert!C(); } void register(C)() if (behavesLikeFoo!C) { _insert!C(); } There are more overloads with parameters so I want to merge them void register(C, ARGS...)(ARGS

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 18:56:33 UTC, wjoe wrote: It doesn't occur to me that the compiler doesn't know at compile time that interface IFoo{} class Foo: IFoo {} class Foo implements interface IFoo. Didn't think that the compiler didn't know but wasn't aware that you could use

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 20:19:04 UTC, data pulverizer wrote: This has prompted me to write a data structure that I thought would be impossible until now False alarm: ``` writeln("typeof(x.next): ", typeof(x.next).stringof); ``` gives: ``` typeof(x.next): const(Node) ``` Oh

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 19:27:13 UTC, wjoe wrote: Appologies if you took offense. Your replies are very much appreciated. No offense taken.

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 20:19:04 UTC, data pulverizer wrote: This has prompted me to write a data structure that I thought would be impossible until now. [...SNIP...] Here is the function with the correct template constraint: ``` auto makeChain(Args...)(Args args) if(Args.length >

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 19:16:13 UTC, H. S. Teoh wrote: Of course the compiler knows. And of course it can use this information for static dispatch. That's why D is so awesome at metaprogramming. ;-) What the compiler *doesn't* know is whether a variable of some supertype of Foo

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-24 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 20:19:04 UTC, data pulverizer wrote: Thinking more about it this ... class Middle: Node { Node prev; Node next; } won't work because the I've told the compiler that the static type is "Node", my original design was something like this: ``` struct

Type inference for constructors

2020-09-17 Thread data pulverizer via Digitalmars-d-learn
I’d like to know if constructors of classes and structs can have type inference. So far, I am using a separate function for this purpose, for example: ``` import std.stdio: writeln; struct Pair(T, U) { T first; U second; this(T first, U second) { this.first = first;

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: 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,

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: 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

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 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?

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: Type inference for constructors

2020-09-18 Thread data pulverizer via Digitalmars-d-learn
On Friday, 18 September 2020 at 06:43:12 UTC, Simen Kjærås wrote: On Friday, 18 September 2020 at 05:43:56 UTC, data pulverizer That's issue 1997: https://issues.dlang.org/show_bug.cgi?id=1997 D's templates are turing complete, and there may be arbitrary amounts of logic obscuring the mapping

Can we do compile time reading part of a file using import?

2020-10-23 Thread data pulverizer via Digitalmars-d-learn
Hi all, the `import` function allows a file to be read at compile time, which opens up great opportunities for (mostly binary) file IO, where data types can be coded into files - the user doesn't need to know data types ahead of time. As specified in my old blog article:

Re: Can we do compile time reading part of a file using import?

2020-10-25 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 25 October 2020 at 12:16:36 UTC, Jacob Carlborg wrote: On 2020-10-23 18:42, data pulverizer wrote: You could always have the build tool split up the file in multiple smaller files and read one of the smaller files with the import expression. Thanks. My current solution is to have

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: 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: 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

Issue with opening files on VSCode "D Language utility extension pack"

2020-11-15 Thread data pulverizer via Digitalmars-d-learn
Hi All, On VS Code "D Language utility extension pack", I notice that if I open a random D file, on the bottom left of the IDE, a message says "D: workspace/(0.0%): starting up...". It stays at 0.0% and doesn't go away and gives the impression that it is broken. Opening a file through a

Re: Issue with opening files on VSCode "D Language utility extension pack"

2020-11-16 Thread data pulverizer via Digitalmars-d-learn
On Monday, 16 November 2020 at 08:16:44 UTC, WebFreak001 wrote: On Monday, 16 November 2020 at 01:38:10 UTC, data pulverizer wrote: Hi All, On VS Code "D Language utility extension pack", I notice that if I open a random D file, on the bottom left of the IDE, a message says "D:

Re: Issue with opening files on VSCode "D Language utility extension pack"

2020-11-16 Thread data pulverizer via Digitalmars-d-learn
On Monday, 16 November 2020 at 08:04:24 UTC, frame wrote: On Monday, 16 November 2020 at 01:38:10 UTC, data pulverizer wrote: Hi All, On VS Code "D Language utility extension pack", I notice that if I open a random D file, on the bottom left of the IDE, a message says "D: workspace/(0.0%):

How to construct a tree data structure with differently static nodes types

2020-11-22 Thread data pulverizer via Digitalmars-d-learn
Hi all, I am trying to construct a tree data structure composed of differently (statically) typed nodes. The basic case is a binary tree. So you have a node like: ``` struct Node(T) { T value; Node* next; Node* prev; } void main() { auto x = Node!(int)(2); auto y =

Re: How to construct a tree data structure with differently static nodes types

2020-11-22 Thread data pulverizer via Digitalmars-d-learn
On Monday, 23 November 2020 at 01:24:54 UTC, Max Haughton wrote: If you want to keep things simple, use OOP (classes). If you need to use structs, the "sumtype" may be just what you need (it's a bit more lightweight than std.algebraic in the standard library). If you want to implement this

Re: How to construct a tree data structure with differently static nodes types

2020-11-22 Thread data pulverizer via Digitalmars-d-learn
On Monday, 23 November 2020 at 01:20:04 UTC, data pulverizer wrote: Hi all, I am trying to construct a tree data structure composed of differently (statically) typed nodes. The basic case is a binary tree. So you have a node like: ``` struct Node(T) { T value; Node* next; Node* prev;

Passing lots of C flas to the D compilers and DUB

2021-05-25 Thread data pulverizer via Digitalmars-d-learn
Hi, A [previous post](https://forum.dlang.org/post/hxlhyalzqmzzzihdj...@forum.dlang.org) shows how to link individual C flags with `-L`, but is there a convenient way of linking lots of C flags? I've tried variations of ``` dmd `pkg-config --libs libR` `pkg-config --cflags libR` main.d dmd

How to compile Phobos with other D code to create a shared library?

2021-05-31 Thread data pulverizer via Digitalmars-d-learn
Hi, I am trying to compile D code to a shared library to be called by another language (in this case Julia). I can get a basic call to work but I can't call functions that use Phobos (I have no idea how to compile against it). I have found some documentation

Re: Passing lots of C flas to the D compilers and DUB

2021-05-31 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 27 May 2021 at 01:55:15 UTC, Witold Baryluk wrote: try: ```bash dmd "-L$(pkg-config --libs libR)" main.d ``` if that doesn't work there are some other tricks (with `sed` for example), but I think the above should work. Thanks

Re: How to compile Phobos with other D code to create a shared library?

2021-05-31 Thread data pulverizer via Digitalmars-d-learn
On Monday, 31 May 2021 at 21:26:15 UTC, Steven Schveighoffer wrote: You need to call it wherever you think it might not have been called yet. It's reentrant, so if you call it more than once, it will only initialize once, and count how many times you have to call `Runtime.terminate`.

Re: How to compile Phobos with other D code to create a shared library?

2021-05-31 Thread data pulverizer via Digitalmars-d-learn
On Monday, 31 May 2021 at 20:32:11 UTC, kinke wrote: On Monday, 31 May 2021 at 19:21:52 UTC, data pulverizer wrote: ldc2 jbasic.d -O3 -link-defaultlib-shared --betterC --boundscheck=off -nogc -shared -of=jbasic.so The problem is almost certainly `-betterC`, which disables linking against

Re: How to compile Phobos with other D code to create a shared library?

2021-05-31 Thread data pulverizer via Digitalmars-d-learn
On Monday, 31 May 2021 at 21:01:19 UTC, Steven Schveighoffer wrote: ticksPerSecond is initialized in the runtime just before static constructors are run. See https://github.com/dlang/druntime/blob/2d8b28da39e8bc3bc3172c69bb96c35d77f40d2a/src/rt/dmain2.d#L130 Are you calling

Re: Naming issue importing different function overloads

2021-05-31 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 30 May 2021 at 18:50:25 UTC, Adam D. Ruppe wrote: On Sunday, 30 May 2021 at 18:42:34 UTC, data pulverizer wrote: I wonder if it is a purposeful design It is by design: https://dlang.org/articles/hijack.html Basically the idea behind it is to make sure that a change in a lib you

<    1   2   3   >