cancel
Showing results for 
Search instead for 
Did you mean: 

wavg implementation detail

lan
New Contributor II

Hi, everyone. 

I have some questions about wavg function.

 

0 wavg 5  / 5
5 wavg 5  / 5
2 wavg 2 3 7  / 4
5 2 3 wavg 3  / 3

 

According to the doc, the x and y of wavg[x;y] must both be numeric lists. But for these invalid inputs, wavg still yields some results. Could anyone help me understand the results of these invalid x and y?

What's the behavior of wavg when x and y aren't numeric lists or they don't conform? It seems like avg y but I'm not sure.

If you know more about wavg's implementation detail, please help me. Thanks.

5 REPLIES 5

lkerr
New Contributor III
New Contributor III

Hi Ian, 

Great question! We're working on an answer for you. 

Thanks for your contribution and getting us thinking!

Laura

lan
New Contributor II

Thanks for your reply and looking forward to the answer!

Hello Ian,

Thank you for bringing this great question to our attention. 

  • We can confirm that 
    0 wavg x
    should indeed be 0n. This is a bug and will be fixed by our team. Thank you for sharing this observation. 

The following is an explanation for the other cases:

  • Atoms on both sides behave as if enlisted to single item vectors. 
5 wavg 5  / 5
enlist[5] wavg enlist[5] /5
  • An atom on one side and a vector on the other behaves as if the atom is repeated to match the length of the vector.
2 wavg 2 3 7  / 4
2 2 2 wavg 2 3 7 /4

5 2 3 wavg 3  / 3
5 2 3 wavg 3 3 3 /3

 We hope our feedback is helpful for you. 

Thank you again for your contribution and engagement with our KX community. We look forward to more. 

Kind regards,

Leah

lan
New Contributor II

Hi Leah,

Thanks for your explanation.

So for the case "0 wavg x", it is equivalent to (0*x)%0 => 0%0=0n. It really makes sense.

Thank you and your team again.

 

rocuinneagain
New Contributor III
New Contributor III

Todays release  kdb+4.0 2021.10.01 contains a fix for the issue in your first example:

q)0 wavg 5
0n