April 20, 2020
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.
>
> In the same time, the SliceKind isn't matter for assignment operations:
>
> auto b = a.slice; // copy a to b
> b[] *= a.transposed; // works well

BTW for the following operation

auto b = a * a.transposed.slice;

`b` isn't allocated as well because `*` is lazy.

> auto b = a.slice; // copy a to b
> b[] *= a.transposed; // works well

So, the assignment operations are preferable anyway.
April 20, 2020
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. Even when I tried to do a raw for loop I ran into issues because modifying the original a in any way caused all the calculations to be wrong.
>
> Honestly, it's kind of rare that I would do an element-wise multiplication of a matrix and its transpose.

It is. I was trying to calculate the covariance matrix of some dataset X which would be XX^T.
April 20, 2020
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 work with time series data that is TXN where T > N. Couldn't do a calculation with element-wise multiplication in that case.

Try using Lubeck's covariance function or checking your results with the covariance function in other languages.

April 20, 2020
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" not working because "a.transposed" is not allocated.
>>
>> In the same time, the SliceKind isn't matter for assignment operations:
>>
>> auto b = a.slice; // copy a to b
>> b[] *= a.transposed; // works well
>
> BTW for the following operation
>
> auto b = a * a.transposed.slice;
>
> `b` isn't allocated as well because `*` is lazy.
>
>> auto b = a.slice; // copy a to b
>> b[] *= a.transposed; // works well
>
> So, the assignment operations are preferable anyway.

Interesting, thanks for the examples.
1 2
Next ›   Last »