Re: auto vectorization notes
On Monday, 23 March 2020 at 18:52:16 UTC, Bruce Carneal wrote: When speeds are equivalent, or very close, I usually prefer auto vectorized code to explicit SIMD/__vector code as it's easier to read. (on the downside you have to guard against compiler code-gen performance regressions) One oddity I've noticed is that I sometimes need to use pragma(inline, *false*) in order to get ldc to "do the right thing". Apparently the compiler sees the costs/benefits differently in the standalone context. More widely known techniques that have gotten people over the serial/SIMD hump include: 1) simplified indexing relationships 2) known count inner loops (chunkify) 3) static foreach blocks (manual inlining that the compiler "gathers") I'd be interested to hear from others regarding their auto vectorization and __vector experiences. What has worked and what hasn't worked in your performance sensitive dlang code? auto vectorization is bad because you never know if your code will get vectorized next time you make some change to it and recompile. Just use : https://ispc.github.io/
Re: How to create an array with custom length?
On Friday, 27 March 2020 at 19:30:39 UTC, Quantium wrote: Code int n=0; readf(" %d", &n); int[n] m; generated an error (DMD compiler): Cannot read n at compile time. How to create an array with custom length? The tour has a page for this: https://tour.dlang.org/tour/en/basics/arrays int n=0; readf(" %d", &n); int[] m = new int[n];
How to create an array with custom length?
Code int n=0; readf(" %d", &n); int[n] m; generated an error (DMD compiler): Cannot read n at compile time. How to create an array with custom length?
A question about C++ interop
Hi, I have a C++ header file which looks like class A { public: static A *create(); virtual int f() const = 0; }; And there is a C++ library file which provides the implementation, so that if I write a C++ program and call auto *p = A::create(); std::cout << p->f() << '\n'; It will work. Now I want to interface to this C++ library through D, and I wrote module test; import std.stdio; extern(C++) { class A { static A *create(); abstract int f() const; } } void main() { auto p = A.create(); writeln(p.f()); } This program will compile and link, but it core dumps at the call to f(). If I wrap up the C++ interface into a C interface (using a void *), and interface to the wrapped-up C library through D, it will work fine. So what am I doing wrong here? Thanks!
Re: Blog post about multidimensional arrays in D
On Friday, 27 March 2020 at 13:10:00 UTC, jmh530 wrote: On Friday, 27 March 2020 at 10:57:10 UTC, p.shkadzko wrote: I decided to write a small blog post about multidimensional arrays in D on what I learnt so far. It should serve as a brief introduction to Mir slices and how to do basic manipulations with them. It started with a small file with snippets for personal use but then kind of escalated into an idea of a blog post. However, given the limited about of time I spent in Mir docs and their conciseness, it would be great if anyone had a second look and tell me what is wrong or missing because I have a feeling a lot of things might. It would be a great opportunity for me to learn and also improve it or rewrite some parts. All is here: https://github.com/tastyminerals/tasty-blog/blob/master/_posts/2020-03-22-multidimensional_arrays_in_d.md Thanks for doing this. A small typo on this line a.byDim1; I think there would be a lot of value in doing another blogpost to cover some more advanced topics. For instance, mir supports three different SliceKinds and the documentation explaining the difference has never been very clear. I don't really feel like I've ever had a clear understanding of the low-level differences between them. The pack/ipack/unpack functions are also pretty hard to understand from the documentation. I agree. I was planning to do several follow-ups after this first brief overview. For example, looks like just one "byDim" requires a separate post. The goal was just to show ppl who know nothing or a little about D and Mir that Mir exists and is usable. Because what I am lacking is not the API docs but introductory examples how to do mundane tasks like creating matrices and reshaping. Treat the first post as such and if you have suggestions on what is redundant or good to have I shall update it accordingly.
Re: Blog post about multidimensional arrays in D
On Friday, 27 March 2020 at 11:19:06 UTC, WebFreak001 wrote: On Friday, 27 March 2020 at 10:57:10 UTC, p.shkadzko wrote: [...] I don't really know mir myself, but for the start of the content: [...] Ok, looks like I need to reread the slices topic. It always confused me especially when it comes to function parameters but I just swallowed it and continued on. Thank you.
Re: Blog post about multidimensional arrays in D
On Friday, 27 March 2020 at 10:57:10 UTC, p.shkadzko wrote: I decided to write a small blog post about multidimensional arrays in D on what I learnt so far. It should serve as a brief introduction to Mir slices and how to do basic manipulations with them. It started with a small file with snippets for personal use but then kind of escalated into an idea of a blog post. However, given the limited about of time I spent in Mir docs and their conciseness, it would be great if anyone had a second look and tell me what is wrong or missing because I have a feeling a lot of things might. It would be a great opportunity for me to learn and also improve it or rewrite some parts. All is here: https://github.com/tastyminerals/tasty-blog/blob/master/_posts/2020-03-22-multidimensional_arrays_in_d.md Thanks for doing this. A small typo on this line a.byDim1; I think there would be a lot of value in doing another blogpost to cover some more advanced topics. For instance, mir supports three different SliceKinds and the documentation explaining the difference has never been very clear. I don't really feel like I've ever had a clear understanding of the low-level differences between them. The pack/ipack/unpack functions are also pretty hard to understand from the documentation.
Re: Blog post about multidimensional arrays in D
On Friday, 27 March 2020 at 10:57:10 UTC, p.shkadzko wrote: I decided to write a small blog post about multidimensional arrays in D on what I learnt so far. It should serve as a brief introduction to Mir slices and how to do basic manipulations with them. It started with a small file with snippets for personal use but then kind of escalated into an idea of a blog post. However, given the limited about of time I spent in Mir docs and their conciseness, it would be great if anyone had a second look and tell me what is wrong or missing because I have a feeling a lot of things might. It would be a great opportunity for me to learn and also improve it or rewrite some parts. All is here: https://github.com/tastyminerals/tasty-blog/blob/master/_posts/2020-03-22-multidimensional_arrays_in_d.md I don't really know mir myself, but for the start of the content: Both array types represent a structure with a length and ptr (a pointer to the first element) properties A static array doesn't really fall under this imo, because it doesn't have any length field at runtime and is literally just the elements repeated N times. Dynamic arrays are also called slices in D meh, all dynamic arrays are also slices, but not all slices are dynamic arrays. You can take a slice from a static array or from a pointer and once you try to append to it or resize it, it will duplicate the data using the GC and create a new dynamic array. This is true every time you take a slice of any array or memory and then try to resize it. If the slice was originally from a dynamic array (checked using runtime magic) and you use assumeSafeAppend, it will actually try to resize the existing array in-place.
Blog post about multidimensional arrays in D
I decided to write a small blog post about multidimensional arrays in D on what I learnt so far. It should serve as a brief introduction to Mir slices and how to do basic manipulations with them. It started with a small file with snippets for personal use but then kind of escalated into an idea of a blog post. However, given the limited about of time I spent in Mir docs and their conciseness, it would be great if anyone had a second look and tell me what is wrong or missing because I have a feeling a lot of things might. It would be a great opportunity for me to learn and also improve it or rewrite some parts. All is here: https://github.com/tastyminerals/tasty-blog/blob/master/_posts/2020-03-22-multidimensional_arrays_in_d.md
Re: How package Dlang in a standalone portable executable?
On Thursday, 26 March 2020 at 23:19:20 UTC, Marcone wrote: I need package Dlang in a standalone portable executable. I need packcages all dependencies, dlls, files, etc in one executable file. by default if you use dub it will statically link phobos and druntime into the executable, so you have no external dependencies other than libc / msvc++ runtime redist. This might not be the case depending on your installation though like for example in LDC the config might default to using a shared ldc phobos runtime as this is the case for example on ArchLinux. If you use any shared libraries (derelict/bindbc) you will want to switch them to statically link. Otherwise libraries on dub are statically linked by default. If you want to compile in your files into the executable, you can use `import("filename.txt")` in your code instead of reading from a file. The compiler will read the file and embed the contents in your code at that point. This is very different from e.g. C# where it appends the resources to the executable and inside has code to read from it at runtime. If you want to be able to change it after compiling, on linux you would probably want to use something like AppImages or flatpaks and on OSX I think they have application bundles for this. The system dependencies (libc / msvc++ runtime and win32 api) you will still want the user to install them. This ensures compatibility with the OS, especially on Windows. For the msvc++ runtime you probably want to include their installer in your installer. You will have to read up on how that works though. But with D you can basically just take your executable file and distribute it in a lot of default cases. Best to try it out on PCs which have freshly installed operating systems though.
Re: How to code Z-Function of string?
On Thursday, 26 March 2020 at 20:08:39 UTC, Dennis wrote: On Thursday, 26 March 2020 at 19:34:08 UTC, Quantium wrote: 1. How can I make string ONLY char[] (Not immutable) You can use .dup to make a mutable copy of an array. ``` char[] a = "abc".dup; ``` extending on this: if you want to work on single unicode codepoints instead of utf 8 encoded bytes, you can use: char[] a = "abc".to!(char[]); // utf8 encoded bytes - single bytes may at most cover basic ASCII characters wchar[] a = "abc".to!(wchar[]); // utf16 encoded bytes - each element is ushort size, covers all characters of the Basic Multilingual Plane, and otherwise uses surrogate pairs which you might want to check for. Emoji span 2 code units for example dchar[] a = "abc".to!(dchar[]); // utf32 - each element is uint, covers all possible code points however note that code points may not cover all characters in all languages. Characters might be composed of multiple code points, even relatively innocent looking characters like รค may be composited of an umlaut code point and the character 'a' Basically before doing any operations on your text, I would specify and check for rules to restrict what your input can be. For example if you only want characters from certain ranges such as latin characters, restrict the user from entering anything else. std.uni can help you greatly with working with these ranges and std.utf can help you decode utf8/utf16/utf32 if you choose not to convert to char[], wchar[] or dchar[] before.