Re: Multiplying transposed matrices in mir

2020-04-20 Thread p.shkadzko via Digitalmars-d-learn
On Monday, 20 April 2020 at 02:50:29 UTC, 9il wrote: On Monday, 20 April 2020 at 02:42:33 UTC, 9il wrote: On Sunday, 19 April 2020 at 20:29:54 UTC, p.shkadzko wrote: On Sunday, 19 April 2020 at 20:06:23 UTC, jmh530 wrote: [...] Thanks. I somehow missed the whole point of "a * a.transposed"

Re: Multiplying transposed matrices in mir

2020-04-20 Thread jmh530 via Digitalmars-d-learn
On Monday, 20 April 2020 at 19:06:53 UTC, p.shkadzko wrote: [snip] It is. I was trying to calculate the covariance matrix of some dataset X which would be XX^T. Incorrect. The covariance matrix is calculated with matrix multiplication, not element-wise multiplication. For instance, I often

Re: Multiplying transposed matrices in mir

2020-04-20 Thread p.shkadzko via Digitalmars-d-learn
On Sunday, 19 April 2020 at 21:27:43 UTC, jmh530 wrote: On Sunday, 19 April 2020 at 20:29:54 UTC, p.shkadzko wrote: [snip] Thanks. I somehow missed the whole point of "a * a.transposed" not working because "a.transposed" is not allocated. a.transposed is just a view of the original matrix.

Re: Multiplying transposed matrices in mir

2020-04-19 Thread 9il via Digitalmars-d-learn
On Monday, 20 April 2020 at 02:42:33 UTC, 9il wrote: On Sunday, 19 April 2020 at 20:29:54 UTC, p.shkadzko wrote: On Sunday, 19 April 2020 at 20:06:23 UTC, jmh530 wrote: [...] Thanks. I somehow missed the whole point of "a * a.transposed" not working because "a.transposed" is not allocated.

Re: Multiplying transposed matrices in mir

2020-04-19 Thread 9il via Digitalmars-d-learn
On Sunday, 19 April 2020 at 20:29:54 UTC, p.shkadzko wrote: On Sunday, 19 April 2020 at 20:06:23 UTC, jmh530 wrote: On Sunday, 19 April 2020 at 19:20:28 UTC, p.shkadzko wrote: [...] Ah, you're right. I use it in other places where it hasn't been an issue. I can do it with an allocation

Re: Multiplying transposed matrices in mir

2020-04-19 Thread jmh530 via Digitalmars-d-learn
On Sunday, 19 April 2020 at 20:29:54 UTC, p.shkadzko wrote: [snip] Thanks. I somehow missed the whole point of "a * a.transposed" not working because "a.transposed" is not allocated. a.transposed is just a view of the original matrix. Even when I tried to do a raw for loop I ran into issues

Re: Multiplying transposed matrices in mir

2020-04-19 Thread p.shkadzko via Digitalmars-d-learn
On Sunday, 19 April 2020 at 20:06:23 UTC, jmh530 wrote: On Sunday, 19 April 2020 at 19:20:28 UTC, p.shkadzko wrote: [snip] well no, "assumeContiguous" reverts the results of the "transposed" and it's "a * a". I would expect it to stay transposed as NumPy does "assert

Re: Multiplying transposed matrices in mir

2020-04-19 Thread jmh530 via Digitalmars-d-learn
On Sunday, 19 April 2020 at 19:20:28 UTC, p.shkadzko wrote: [snip] well no, "assumeContiguous" reverts the results of the "transposed" and it's "a * a". I would expect it to stay transposed as NumPy does "assert np.all(np.ascontiguous(a.T) == a.T)". Ah, you're right. I use it in other places

Re: Multiplying transposed matrices in mir

2020-04-19 Thread p.shkadzko via Digitalmars-d-learn
On Sunday, 19 April 2020 at 19:13:14 UTC, p.shkadzko wrote: On Sunday, 19 April 2020 at 18:59:00 UTC, jmh530 wrote: On Sunday, 19 April 2020 at 17:55:06 UTC, p.shkadzko wrote: snip So, lubeck mtimes is equivalent to NumPy "a.dot(a.transpose())". There are elementwise operation on two

Re: Multiplying transposed matrices in mir

2020-04-19 Thread p.shkadzko via Digitalmars-d-learn
On Sunday, 19 April 2020 at 18:59:00 UTC, jmh530 wrote: On Sunday, 19 April 2020 at 17:55:06 UTC, p.shkadzko wrote: snip So, lubeck mtimes is equivalent to NumPy "a.dot(a.transpose())". There are elementwise operation on two matrices of the same size and then there is matrix

Re: Multiplying transposed matrices in mir

2020-04-19 Thread jmh530 via Digitalmars-d-learn
On Sunday, 19 April 2020 at 17:55:06 UTC, p.shkadzko wrote: snip So, lubeck mtimes is equivalent to NumPy "a.dot(a.transpose())". There are elementwise operation on two matrices of the same size and then there is matrix multiplication. Two different things. You had initially said using an

Re: Multiplying transposed matrices in mir

2020-04-19 Thread p.shkadzko via Digitalmars-d-learn
On Sunday, 19 April 2020 at 17:22:12 UTC, jmh530 wrote: On Sunday, 19 April 2020 at 17:07:36 UTC, p.shkadzko wrote: I'd like to calculate XX^T where X is some [m x n] matrix. // create a 3 x 3 matrix Slice!(double*, 2LU) a = [2.1, 1.0, 3.2, 4.5, 2.4, 3.3, 1.5, 0, 2.1].sliced(3, 3); auto b =

Re: Multiplying transposed matrices in mir

2020-04-19 Thread jmh530 via Digitalmars-d-learn
On Sunday, 19 April 2020 at 17:07:36 UTC, p.shkadzko wrote: I'd like to calculate XX^T where X is some [m x n] matrix. // create a 3 x 3 matrix Slice!(double*, 2LU) a = [2.1, 1.0, 3.2, 4.5, 2.4, 3.3, 1.5, 0, 2.1].sliced(3, 3); auto b = a * a.transposed; // error Looks like it is not possible

Multiplying transposed matrices in mir

2020-04-19 Thread p.shkadzko via Digitalmars-d-learn
I'd like to calculate XX^T where X is some [m x n] matrix. // create a 3 x 3 matrix Slice!(double*, 2LU) a = [2.1, 1.0, 3.2, 4.5, 2.4, 3.3, 1.5, 0, 2.1].sliced(3, 3); auto b = a * a.transposed; // error Looks like it is not possible due to "incompatible types for (a) * (transposed(a)):