On Friday, 1 October 2021 at 19:23:06 UTC, james.p.leblanc wrote:
D-ers,
Update from myself to myself (and any others who might use the
bash
command from my origin posting),
I try to compile the above using:
```bash
ldc2 -mattr=+avx2 myexample.d -H
~/ldc2/import/ldc/gccbuiltins_x86.di
On Friday, 1 October 2021 at 20:19:39 UTC, Imperatorn wrote:
Take a look at my post ;)
YES!
===
Thanks to both Imperatorn, and Max for their helpful and quick
responses.
The problem is SOLVED!
I didn't realize that the pragma had to be placed outside of the
main() ...
but it seems
On Friday, 1 October 2021 at 19:58:30 UTC, max haughton wrote:
On Friday, 1 October 2021 at 19:23:06 UTC, james.p.leblanc
Is it sqrt.32 or sqrt.f32? Try the latter, LLVM docs seem to
agree.
Hello Max,
Thanks for the correction... unfortunately, even after changing
the "32",
to "f32", **I
D-ers,
After experimenting with ldc's autovectorization of avx code, it
appears there may
be counter-intuitiveness to the autovectorization (especially for
complex numbers).
(My comment may be wrong, so any corrections are quite welcome).
Based on this, I wanted to investigate the use of
On Thursday, 30 September 2021 at 16:52:57 UTC, Johan wrote:
On Thursday, 30 September 2021 at 16:40:03 UTC, james.p.leblanc
Generally, for performance issues like this you need to study
assembly output (`--output-s`) or LLVM IR (`--output-ll`).
First thing I would look out for is function
D-Ers,
I have been getting counterintuitive results on avx/no-avx timing
experiments. Storyline to date (notes at end):
**Experiment #1)** Real float data type (i.e. non-complex
numbers),
speed comparison.
a) moving from non-avx --> avx shows non-realistic speed up of
15-25 X.
b)
On Tuesday, 28 September 2021 at 05:26:29 UTC, Ali Çehreli wrote:
On 9/27/21 10:38 AM, james.p.leblanc wrote:
In addition to what Mike Parker said, templates do complicate
matters here: Templates are instantiated (i.e. compiled for a
specific set of template arguments) by modules that
On Tuesday, 28 September 2021 at 02:05:43 UTC, Mike Parker wrote:
On Monday, 27 September 2021 at 17:38:29 UTC, james.p.leblanc
mpilations".
Does that help?
**Yes!...**
===
... this helped immensely!
This explanation gave me a much better understanding of how the
whole process works.
Dear D-ers,
I have trouble understanding "module imports" vs. "module
compilations".
For example, in the dlang.org/tour, we have:
**"The import statement makes all public functions and types from
the given module available."**
And from the dlang.org/spec we have:
**"Modules are always
On Sunday, 26 September 2021 at 19:00:54 UTC, kinke wrote:
On Sunday, 26 September 2021 at 18:08:46 UTC, james.p.leblanc
wrote:
or even moving the array declarations to before
the dot product function, and the avx instructions will
disappear!
That's because the `@fastmath` UDA applies to the
Dear D-ers,
I enjoyed reading some details of incorporating AVX into math code
from Johan Engelen's programming blog post:
http://johanengelen.github.io/ldc/2016/10/11/Math-performance-LDC.html
Basically, one can use the ldc compiler to insert avx code, nice!
In playing with some variants of
On Thursday, 23 September 2021 at 20:32:36 UTC, james.p.leblanc
wrote:
On Thursday, 23 September 2021 at 19:18:11 UTC, james.p.leblanc
wrote:
On Thursday, 23 September 2021 at 19:04:47 UTC, Steven
Schveighoffer wrote:
On 9/23/21 2:20 PM, james.p.leblanc wrote:
```
Produces:
typeid(jj):
On Thursday, 23 September 2021 at 19:18:11 UTC, james.p.leblanc
wrote:
On Thursday, 23 September 2021 at 19:04:47 UTC, Steven
Schveighoffer wrote:
On 9/23/21 2:20 PM, james.p.leblanc wrote:
Dear D-ers,
Here comes a minor update (small rearrangement in mapping/array
ordering)
for anyone who
On Thursday, 23 September 2021 at 19:04:47 UTC, Steven
Schveighoffer wrote:
On 9/23/21 2:20 PM, james.p.leblanc wrote:
Dear D-ers,
In attempting to cast JSONValues that hold arrays to "native"
How you really do this:
```d
import std.algorithm : map;
auto z5 = jj["ba"] // get the JSONValue
Dear D-ers,
In attempting to cast JSONValues that hold arrays to "native"
array types,
I have hit some issues. Example code:
```d
import std.stdio;
import std.json;
void main(){
JSONValue jj;
jj["d"] = [ 1.234 ]; // a "dummy" double value
jj["ba"] = [ true, false,
On Friday, 17 September 2021 at 00:36:42 UTC, ag0aep6g wrote:
On 16.09.21 22:53, jfondren wrote:
string joinstruct(A, B)(string name) {
struct JoinStruct(Structs ...)
{
static foreach (S; Structs)
{
static foreach (i, alias f; S.tupleof)
{
mixin("typeof(f)
Dear All,
I really thought that this would be a simple enough
small project in meta programming/reflection. Consisely,
merge two structures, which are coming from two different
elements of the code base. (One contains standard input
options for getopt, and the other is for user customization
On Thursday, 16 September 2021 at 03:26:46 UTC, Tejas wrote:
On Wednesday, 15 September 2021 at 19:59:43 UTC,
james.p.leblanc wrote:
s
Use the `mixin` compiler flag
`dmd -mixin= file.d`
Beware, this will also include **all** the mixin code from
standard library and runtime.
But it's
Dear All,
In attempting to learn and use code generation, it
would be useful to be able to view the source code
that gets generated.
However, with various combinations of templates, UDAs, and
mixins it has not been easy.
Is there some standard way this is done?
Optimal would be to print out
On Thursday, 9 September 2021 at 05:37:35 UTC, Tejas wrote:
On Thursday, 9 September 2021 at 05:32:29 UTC, Tejas wrote:
On Tuesday, 7 September 2021 at 17:47:15 UTC, james.p.leblanc
wrote:
[...]
writeln([0]);
scope(exit) AlignedMallocator.instance.deallocate(buffer);
//...
}
```
Dear All,
In searching through the forum archives (going back to 2013, 2016
etc), and experiments, it **appears to me** that LDC does indeed
respect the standard "align" properties. (Meaning: proper
alignment
for using AVX with static arrays can be guaranteed).
Experiments (and forum
On Tuesday, 7 September 2021 at 17:33:31 UTC, Adam D Ruppe wrote:
On Tuesday, 7 September 2021 at 17:24:34 UTC, james.p.leblanc
wrote:
If you want to do a runtime lookup, you need to separate the
two pieces. This pattern works:
switch(runtime_index) {
foreach(i, val; item.tupleof)
Dear All,
In playing with some reflection and meta programming, this
curiosity
appeared.
Does someone understand what is happening? I would appreciate
learning
about it if possible. Enclosed code snippet tells the story:
```d
import std.stdio;
import std.traits;
import std.meta;
struct
On Sunday, 5 September 2021 at 21:25:06 UTC, jfondren wrote:
On Sunday, 5 September 2021 at 20:49:08 UTC, james.p.leblanc
wrote:
Here's a reduction of your myArray.d that works with your
unchanged usage code:
```d
module myArray;
import std.stdio;
void opOpAssign(string op)(myArray
On Sunday, 5 September 2021 at 21:06:49 UTC, Ali Çehreli wrote:
On 9/5/21 12:43 PM, james.p.leblanc wrote:
m[4 .. $] -= 100;
writeln(m);
m[] *= 2;
writeln(m);
}
Ali
Ali,
Thanks for your example code ... I have much to learn from this
and will need to study it tomorrow when I am
On Sunday, 5 September 2021 at 20:38:29 UTC, Paul Backus wrote:
On Sunday, 5 September 2021 at 19:43:20 UTC, james.p.leblanc
wrote:
Dear D-ers,
I have constructed a custom array type that works, but is
missing
correct functioning on some operator overloads.
[...]
```d
import std.stdio;
Dear D-ers,
I have constructed a custom array type that works, but is missing
correct functioning on some operator overloads.
The stripped down minimum example (module) was over 100 lines (due
overloading opAssign, etc.) Probably too long to be a good forum
post.
However, a short main may
On Sunday, 5 September 2021 at 17:55:09 UTC, Steven Schveighoffer
wrote:
On 9/5/21 1:48 PM, james.p.leblanc wrote:
Dear All,
In case you can't find it, the info is
[here](https://forum.dlang.org/help#markdown)
-Steve
THANKS! (Also ... sigh ... I swear I have looked at the
markdon page
Dear All,
I have noticed that quite a few posts and responses on this
forum include d snippets made with **nicely colored syntax
highlighting.**
(I do not mean just the bold markdown text.)
This increases post clarity significantly.
How is this being done? (I hope that this is not
On Wednesday, 1 September 2021 at 22:11:29 UTC, user1234 wrote:
On Wednesday, 1 September 2021 at 22:01:12 UTC, user1234 wrote:
```
ProcessPipes gnuplot () {
__gshared ProcessPipes pipe;
return pipe.pid ? pipe : (pipe =
pipeProcess("/usr/local/bin/gnuplot"));
}
```
user1234,
On Wednesday, 1 September 2021 at 19:54:14 UTC, user1234 wrote:
On Wednesday, 1 September 2021 at 16:02:47 UTC, james.p.leblanc
wrote:
Dear D-ers,
For simple plotting using a gnuplot process, I have created a
singleton object (a stripped
down minimal working example is below.)
[...]
Dear D-ers,
For simple plotting using a gnuplot process, I have created a
singleton object (a stripped
down minimal working example is below.)
In the example, there are two plots calls:
1) First, call is made using the object member function
"gp.plot(x, etc.)"
2) The second uses a
On Monday, 30 August 2021 at 16:51:12 UTC, Ali Çehreli wrote:
In this case, converting your ~this to a named function solves
the issue:
// Was: ~this()
void close() {
// ...
}
// ...
auto gp = new Gnuplot();
scope (exit) {
gp.close();
}
Ali
Ali
Ali,
Yet again, you
D-ers,
I am attempting to use pipeProcess for interacting with an
external process.
My simplified routine can work somewhat. But, trying to print
any messages
that process writes to stderr yields the message:
(master) gnuplot > gnuplot_example
On Tuesday, 24 August 2021 at 05:34:08 UTC, Ali Çehreli wrote:
On 8/23/21 10:25 PM, james.p.leblanc wrote:
So, you need a "property". Easy... :)
1) Rename the member e.g. as a_.
2) Write setter and getter functions named 'a'.
struct Foo{
int a_;
int a() const {
return a_;
}
Greetings,
With a struct, there are many overload possibilities available.
However, I haven't been able to find how to overload assignment
of **selected fields** of a struct.
For example, suppose:
struct Foo{
int a;
int b;
...
}
void main(){
auto x =
On Sunday, 22 August 2021 at 14:35:48 UTC, Ali Çehreli wrote:
On 8/22/21 6:03 AM, james.p.leblanc wrote:
> struct Foo {
> int a, b, c;
> Foo* myadd;
>
> this(int a, int b, int c) {
> this.a = a;
> this.b = b;
> this.c = c;
>
On Sunday, 22 August 2021 at 13:37:50 UTC, jfondren wrote:
this(this) {
unique = null;
}
~this() {
pureFree(unique);
}
}
Dear jfondren,
I truly appreciate you taking the time to help me with my
question!
**This bit of magic with the postblit may hold the
On Sunday, 22 August 2021 at 11:10:33 UTC, jfondren wrote:
On Sunday, 22 August 2021 at 07:58:12 UTC, james.p.leblanc
wrote:
Hello,
If you don't get an answer that you like, I suggesting posting
functional code and then stating your dissastisfactions with it.
Mattias, jfondren,
Thanks both
Hello,
Question about a possible strategy to avoid problems with
undesired/unintended copying of a structure:
1) We have a struct, call this **Foo**.
2) We instantiate it with, **x = Foo(a,b,c);**
a. our constructor will initialize a field: **this.myadd
= **
b. this capture
On Friday, 20 August 2021 at 15:38:04 UTC, Paul Backus wrote:
The most straightforward way would be to change your functions
from accepting only `T[]` to accepting either `T[]` or
`fakeArray`. For example:
```d
import std.traits: isDynamicArray;
// assuming `fakeArray` is a template
Greetings,
I have a user created struct, let's call this "**fakeArray**":
For all intents and purposes fakeArray behaves like an array (or
slice, I guess).
(i.e. It has a number of operator overloadings, and *foreach*
extensions implemented.)
I have a fairly large number of function in a
On Wednesday, 18 August 2021 at 06:53:51 UTC, Tejas wrote:
void funcTemplate(T:int)(T a){
writeln("argument is int");
}
void funcTemplate(T : long)(T a){
writeln("argument is long integer");
}
void main(){
int a;
long b;
func(a);
func(b);
funcTemplate(a);
On Tuesday, 17 August 2021 at 20:28:20 UTC, Alexandru Ermicioi
wrote:
On Tuesday, 17 August 2021 at 19:53:52 UTC, james.p.leblanc
wrote:
Wow! That is absolutely beautiful ... I had never seen (or
even
imagined) a recursive template! This expands my mind in a good
way ... and is going into
On Tuesday, 17 August 2021 at 20:13:59 UTC, Paul Backus wrote:
FYI: in this particular case, you can use
std.meta.staticIndexOf instead of writing the recursion out
yourself:
import std.meta: staticIndexOf;
enum isAmong(T, S...) = staticIndexOf!(T, S) >= 0;
Docs:
On Tuesday, 17 August 2021 at 19:44:29 UTC, H. S. Teoh wrote:
You could use a helper template and an AliasSeq for this:
template isAmong(T, S...) {
static if (S.length == 0)
enum isAmong = false;
else
enum
On Tuesday, 17 August 2021 at 18:28:53 UTC, Steven Schveighoffer
wrote:
On 8/17/21 2:11 PM, james.p.leblanc wrote:
Evening All,
[Template
constraints](https://dlang.org/spec/template.html#template_constraints).
-Steve
Dear All,
Thanks! I was aware of, and have used template constraints
Evening All,
Eponymous templates allow a nice calling syntax. For example,
"foo" here can
be called without needing the exclamation mark (!) at calling
sites. We see that
foo is restricting a, and b to be of the same type ... so far, so
good.
auto foo(T)(T a, T b) { ... }
Now, suppose I
On Monday, 16 August 2021 at 10:48:19 UTC, Alexandru Ermicioi
wrote:
On Monday, 16 August 2021 at 06:36:02 UTC, james.p.leblanc
wrote:
To be honest, I am not exactly sure what is happening here. I
am unfamiliar with the "(T : T[])" syntax ... need to read
That is template argument
On Monday, 16 August 2021 at 06:42:48 UTC, Tejas wrote:
If the code works, what's the problem?
Hej Again,
I was able to construct the working code shown above from help I
obtained here in the forum and other resources.
My original code was not working ... but updated code is working
fine
On Monday, 16 August 2021 at 06:20:11 UTC, Tejas wrote:
Maybe just write `T[]` in code rather than making it happen via
the colon?
I also have similar troubles, removing the default value always
helped me.
Can you show the code where you're trying to apply this?
Hej Tejas,
Sure, here is
On Monday, 16 August 2021 at 05:26:00 UTC, Tejas wrote:
If you're finding the spec too hard, please try Ali's book. I'm
sharing the part on operator overloading below:
http://ddili.org/ders/d.en/operator_overloading.html
Please ping if you still have problems; I'll then write a full
On Sunday, 15 August 2021 at 21:28:53 UTC, james.p.leblanc wrote:
On Sunday, 15 August 2021 at 21:15:02 UTC, Bastiaan Veelo wrote:
On Sunday, 15 August 2021 at 20:41:51 UTC, james.p.leblanc
— Bastiaan.
Bastiaan,
Thanks once again,
James
On Sunday, 15 August 2021 at 21:28:53 UTC,
On Sunday, 15 August 2021 at 21:15:02 UTC, Bastiaan Veelo wrote:
On Sunday, 15 August 2021 at 20:41:51 UTC, james.p.leblanc
— Bastiaan.
Bastiaan,
Thanks kindly for your response!
Unfortunately, I do not see what the program does. I mean A is a
structure
that has only functions. So, how
Greetings,
I have been trying to get a working example of slice assignment
operator
overloading ... and am befuddled. From the spec (section
20.6.2), the
code below appears:
struct A
{
int opIndexAssign(int v); // overloads a[] = v
int opIndexAssign(int v, size_t[2]
On Saturday, 14 August 2021 at 20:20:01 UTC, Stefan Koch wrote:
On Saturday, 14 August 2021 at 20:07:21 UTC, james.p.leblanc
wrote:
mes
it is possible
look for `AliasSeq`
in `std.meta`
foreach(T; AliasSeq!(float, double))
{
...
}
Stefan,
Thanks very much for your help here ... I had
Good Evening/Day,
Suppose I have a number of function templates that each take
two types, say S and T.
I would like to exercise my routines over the combinations
of types:
set of all S: ( double[], float[], Complex!double[],
Complex!float[])
set of all T: ( double, float)
Is something
On Friday, 13 August 2021 at 15:14:00 UTC, Steven Schveighoffer
wrote:
There isn't a way to alias it. You can wrap it though, and hope
the inliner takes care of the difference:
```d
auto foo(T)(T arg)
{
static if(is(T == int)) return bar(arg, 42.33);
else return bar(7, arg);
}
```
Dear All,
How does one use 'alias' to incorporate function arguments as
well?
(I believe this is possible, from some of the examples of
aliasSeq, and
the traits.Parameters documentation. However, I was unable to
come up
with anything that works.)
What should replace the question marks
On Monday, 9 August 2021 at 18:44:34 UTC, Paul Backus wrote:
On Monday, 9 August 2021 at 18:35:56 UTC, james.p.leblanc wrote:
```d
T[] foo_temp(Complex!T[])(T x, T y){
auto r = [x, x];
auto i = [y, y];
auto z = [ Complex!T(x, y), Complex!T(x,y) ];
return z;
}
```
void main(){
auto yd
Suppose "foo_double" should return a complex double slice, with
double input args.
Similarly "foo_float" should return a float slice, with float
input args.
I thought it should be easy to parameterize with a template
taking a SINGLE
argument, either a"double" or "float" as follows:
import
I have a struct where I use a number of
"invariant(){enforce( blah, blah ...);}"
statements in the struct body to enforce certain
conditions on a struct member.
Since these "invariants" are only called when struct member
functions are exercised, must I overload each
individual
On Sunday, 8 August 2021 at 11:36:51 UTC, FeepingCreature wrote:
You can make a field set function like so:
```
struct S
{
private int x_;
int x(int value) { return this.x_ = value; }
int x() { return this.x_; }
}
```
This will then run invariants.
(boilerplate can automate that for
Hello,
With structs, I understand that "invariant checking" is called
(from dlang tour):
It's called after the constructor has run and before the
destructor is called.
It's called before entering a member function
invariant() is called after exiting a member function.
But, is
On Sunday, 8 August 2021 at 10:40:51 UTC, Ali Çehreli wrote:
I understand your question differently from jfondren. You may
be looking for a 'const' (or 'immutable') member:
struct S {
const int i;
this(int i) {
// This will work because "first assignment is
initialization"
On Sunday, 8 August 2021 at 10:19:46 UTC, jfondren wrote:
On Sunday, 8 August 2021 at 10:11:37 UTC, james.p.leblanc wrote:
Hello All.
Is there a standard way to protect a field of a struct after
the struct has been initialized?
Is this possible with a struct?
If not, I suppose a class
Hello All.
Is there a standard way to protect a field of a struct after
the struct has been initialized?
Is this possible with a struct?
If not, I suppose a class (object) would be needed? If so,
are there any simple pointers to an example of this?
Thanks in advance,
James
On Sunday, 8 August 2021 at 02:00:26 UTC, Tejas wrote:
On Saturday, 7 August 2021 at 19:07:04 UTC, Paul Backus wrote:
On Saturday, 7 August 2021 at 15:41:24 UTC, Tejas wrote:
On Saturday, 7 August 2021 at 15:21:01 UTC, Paul Backus wrote:
[...]
Oh wow, and here I thought I was being smart :(
On Saturday, 7 August 2021 at 12:08:00 UTC, Paul Backus wrote:
On Saturday, 7 August 2021 at 07:32:04 UTC, Tejas wrote:
And if it really is correct, then it seems once again that
static arrays are the answer after all:
```d
align(your_alignment) int[your_length] array;
```
No need for structs
mes
On Friday, 6 August 2021 at 17:25:24 UTC, Tejas wrote:
Okay we were overthinking the solution.
Just use a static array
```d
int[your_max_length]/*or whatever type*/ var;
```
You're good to go!
I almost feel stupid now lol
Hello Tejas,
Kind thanks for your replies ... all are
On Friday, 6 August 2021 at 11:58:59 UTC, Paul Backus wrote:
struct MySlice(T, size_t maxLength)
{
private T[] payload;
invariant(payload.length <= maxLength);
this(T[] slice) { payload = slice; }
T opIndex(size_t i) { return payload[i]; }
// etc.
}
```
Paul,
Thanks very
I am aware of the "capacity" concept with slices.
But, I would like to know if it is possible to set a
hard limit on a slice size.
I prefer it to error and crash instead of a doing an
extension or reallocation.
I understand my question screams of "convoluted
thinking". But, I need to align my
On Wednesday, 4 August 2021 at 01:10:15 UTC, Mike Parker wrote:
On Tuesday, 3 August 2021 at 21:40:09 UTC, james.p.leblanc
wrote:
[...]
The alias to Complex!double is a template instantiation. A
template instantiation creates a symbol that needs to be
linked. So you need to compile
I am getting linker errors with this stripped-down example:
---
**my_main.d:**
import std.stdio;
import std.complex;
import my_module;
void main(){
my_TYPE xxx;
writeln(xxx);
}
---
On Tuesday, 3 August 2021 at 17:57:47 UTC, Ali Çehreli wrote:
On 8/3/21 10:50 AM, james.p.leblanc wrote:
> **Is there some highly visible place this is already
documented?
For what it's worth, it appears as "slice from pointer" in my
index:
On Tuesday, 3 August 2021 at 16:32:34 UTC, kinke wrote:
On Tuesday, 3 August 2021 at 12:33:56 UTC, james.p.leblanc
wrote:
Concise question:
=
I would like to use dynamic arrays, not for their
dynamic sizing properties per se' (slicing, appending, etc).
But, more for their
Concise question:
=
I would like to use dynamic arrays, not for their
dynamic sizing properties per se' (slicing, appending, etc).
But, more for their memory protection and efficiencies (for
example,using foreach).
However, I must have the start of my array at an avx
friendly 32
I am trying to initialize a complex dynamic array, from two
strictly real dynamic arrays (one to be the real part, the other
to be the imaginary part.
Here is simple sample of what I have tried:
-
import std.stdio;
import std.math;
78 matches
Mail list logo