Re: Improving dot product for standard multidimensional D arrays

2020-03-03 Thread kdevel via Digitalmars-d-learn

On Sunday, 1 March 2020 at 20:58:42 UTC, p.shkadzko wrote:
pragma(inline) static int toIdx(T)(Matrix!T m, in int i, in int 
j)

{
return m.cols * i + j;
}


This is row-major order [1]. BTW: Why don't you make toIdx a 
member of Matrix? It saves one parameter. You may also define 
opIndex as


   ref T opIndex(in int r, in int c)

Then the innermost summation becomes more readable:

   m3[i, j] += m1[i, k] * m2[k, j];

How about performing an in-place transposition of m2 before 
performing the dot product? Then you can then rewrite the 
innermost loop:


   m3[i, j] += m1[i, k] * m2[j, k]; // note: j and k swapped

This should avoid the costly jumping thru the memory. A good 
starting point for a performance analysis would be looking over 
the assember code of the innermost loop.


[1] https://en.wikipedia.org/wiki/Row_major


Re: Can't compile dlangui

2020-03-03 Thread MrSmith via Digitalmars-d-learn

On Friday, 7 February 2020 at 12:04:10 UTC, A.Perea wrote:

Hi,

I'm trying to compile dlangide, and it fails when compiling the 
dependency dlangui. Trying to compile dlangui independently 
gives the same error message (see below for full stack trace)


[...]



On Friday, 7 February 2020 at 12:04:10 UTC, A.Perea wrote:


Here is reported issue: 
https://issues.dlang.org/show_bug.cgi?id=20623




Re: Improving dot product for standard multidimensional D arrays

2020-03-03 Thread jmh530 via Digitalmars-d-learn

On Tuesday, 3 March 2020 at 10:25:27 UTC, maarten van damme wrote:
it is difficult to write an efficient matrix matrix 
multiplication in any language. If you want a fair comparison, 
implement your naive method in python and compare those timings.

[snip]


And of course there's going to be a big slowdown in using native 
python. Numpy basically calls blas in the background. A naive C 
implementation might be another comparison.


Re: Improving dot product for standard multidimensional D arrays

2020-03-03 Thread p.shkadzko via Digitalmars-d-learn

On Tuesday, 3 March 2020 at 10:25:27 UTC, maarten van damme wrote:
it is difficult to write an efficient matrix matrix 
multiplication in any language. If you want a fair comparison, 
implement your naive method in python and compare those timings.


Op di 3 mrt. 2020 om 04:20 schreef 9il via Digitalmars-d-learn 
< digitalmars-d-learn@puremagic.com>:



On Sunday, 1 March 2020 at 20:58:42 UTC, p.shkadzko wrote:
> [...]

Matrix multiplication is about cache-friendly blocking. 
https://www.cs.utexas.edu/users/pingali/CS378/2008sp/papers/gotoPaper.pdf


`mir-blas` package can be used for matrix operations for 
ndslice.

  `cblas`  - if you want to work with your own matrix type .


Yeah, got it. After some reading, I understand that's not trivial 
once bigger matrices are involved.


Re: core.atomic.atomicStore and structs

2020-03-03 Thread Saurabh Das via Digitalmars-d-learn

On Tuesday, 3 March 2020 at 11:35:35 UTC, MoonlightSentinel wrote:

On Tuesday, 3 March 2020 at 11:04:53 UTC, Saurabh Das wrote:

PS: Any chance this will make it into DMD 2.091.0?


Yes, this fix will be in the upcoming release.


Excellent.

Thank you so much! :)

Saurabh



Re: core.atomic.atomicStore and structs

2020-03-03 Thread MoonlightSentinel via Digitalmars-d-learn

On Tuesday, 3 March 2020 at 11:04:53 UTC, Saurabh Das wrote:

PS: Any chance this will make it into DMD 2.091.0?


Yes, this fix will be in the upcoming release.


Re: core.atomic.atomicStore and structs

2020-03-03 Thread Saurabh Das via Digitalmars-d-learn

On Tuesday, 3 March 2020 at 10:57:36 UTC, MoonlightSentinel wrote:

On Tuesday, 3 March 2020 at 09:12:40 UTC, Saurabh Das wrote:

Is this supposed to not work anymore? Or is this a bug?


That is a bug, see 
https://issues.dlang.org/show_bug.cgi?id=20629


Oh wow you fixed it already! Amazing!

Thanks MoonlightSentinel.

Saurabh

PS: Any chance this will make it into DMD 2.091.0?





Re: core.atomic.atomicStore and structs

2020-03-03 Thread MoonlightSentinel via Digitalmars-d-learn

On Tuesday, 3 March 2020 at 09:12:40 UTC, Saurabh Das wrote:

Is this supposed to not work anymore? Or is this a bug?


That is a bug, see https://issues.dlang.org/show_bug.cgi?id=20629




Re: Improving dot product for standard multidimensional D arrays

2020-03-03 Thread maarten van damme via Digitalmars-d-learn
it is difficult to write an efficient matrix matrix multiplication in any
language. If you want a fair comparison, implement your naive method in
python and compare those timings.

Op di 3 mrt. 2020 om 04:20 schreef 9il via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com>:

> On Sunday, 1 March 2020 at 20:58:42 UTC, p.shkadzko wrote:
> > Hello again,
> >
> > Thanks to previous thread on multidimensional arrays, I managed
> > to play around with pure D matrix representations and even
> > benchmark a little against numpy:
> >
> > [...]
>
> Matrix multiplication is about cache-friendly blocking.
> https://www.cs.utexas.edu/users/pingali/CS378/2008sp/papers/gotoPaper.pdf
>
> `mir-blas` package can be used for matrix operations for ndslice.
>   `cblas`  - if you want to work with your own matrix type .
>


core.atomic.atomicStore and structs

2020-03-03 Thread Saurabh Das via Digitalmars-d-learn

Hi,

Consider this code:

```
import core.atomic;

struct MyStruct
{
uint a, b;
}
static assert(MyStruct.sizeof == ulong.sizeof);

void main()
{
shared MyStruct ms1;

MyStruct ms2 = atomicLoad(ms1); // This is fine

MyStruct ms3;
cas(, ms2, ms3);// This is also fine

atomicStore(ms1, ms2);  // This gives a compile 
error

}
```

This used to work in DMD 2.088.1. It does not work in the latest 
DMD 2.091.0-beta.2. It gives a compile error like this:


```
/home/ec2-user/dlang/dmd-2.091.0-beta.2/linux/bin64/../../src/druntime/import/core/internal/atomic.d(233):
 Error: template core.internal.atomic.atomicExchange cannot deduce function 
from argument types !(cast(MemoryOrder)5, false)(MyStruct*, MyStruct), 
candidates are:
/home/ec2-user/dlang/dmd-2.091.0-beta.2/linux/bin64/../../src/druntime/import/core/internal/atomic.d(291):
atomicExchange(MemoryOrder order = MemoryOrder.seq, bool result = true, 
T)(T* dest, T value)
  with order = order,
   result = false,
   T = MyStruct
  whose parameters have the following constraints:
  
  > is(T : ulong)
or:
  > is(T == class)
or:
  > is(T == interface)
or:
  > is(T U : U*)
  
  Tip: not satisfied constraints are marked with >
/home/ec2-user/dlang/dmd-2.091.0-beta.2/linux/bin64/../../src/druntime/import/core/atomic.d(127):
 Error: template instance core.internal.atomic.atomicStore!(cast(MemoryOrder)5, 
MyStruct) error instantiating
/home/ec2-user/dlang/dmd-2.091.0-beta.2/linux/bin64/../../src/druntime/import/core/atomic.d(142):
instantiated from here: atomicStore!(cast(MemoryOrder)5, MyStruct, 
MyStruct)
atomic_test.d(18):instantiated from here: 
atomicStore!(cast(MemoryOrder)5, MyStruct, MyStruct)

```

Is this supposed to not work anymore? Or is this a bug?

Thanks,
Saurabh