lib/vsm: access to non-existing keys return 0.0
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 12 Oct 2017 00:47:50 +0000 (20:47 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 12 Oct 2017 00:49:00 +0000 (20:49 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/vsm/vsm.nit

index 41d5152..8eaeca8 100644 (file)
@@ -72,6 +72,11 @@ class Vector
                return cos
        end
 
+       redef fun [](k) do
+               if not has_key(k) then return 0.0
+               return super
+       end
+
        # The norm of the vector.
        #
        # `||x|| = (x1 ** 2 ... + xn ** 2).sqrt`