KX Community

Find answers, ask questions, and connect with our KX Community around the world.

Home Forums kdb+ wavg implementation detail

  • wavg implementation detail

    Posted by lan on August 26, 2021 at 12:00 am

    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.

    lan replied 1 month, 2 weeks ago 3 Members · 3 Replies
  • 3 Replies
  • leahs

    Member
    September 2, 2021 at 12:00 am

    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

    Member
    September 6, 2021 at 12:00 am

    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

    Member
    October 1, 2021 at 12:00 am

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

    q)0 wavg 5
    0n

     

Log in to reply.