octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #56594] [Patch] containers.Map does not auto-c


From: Guillaume
Subject: [Octave-bug-tracker] [bug #56594] [Patch] containers.Map does not auto-convert differing numeric key-types
Date: Mon, 15 Jul 2019 09:29:53 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0

Follow-up Comment #1, bug #56594 (project octave):

Thanks Markus, it seems that this was an oversight and the conversion was only
taking place when the keys were provided in a cell array. I modified your
patch to make the change in "encode_keys" and use "feval" instead of "cast"
(as the former is used a few lines above - not sure what is best). I also
added some more tests.
This made me notice another issue with "vertcat" where the KeyType of the new
object is not dealt with specifically.


--- a/scripts/+containers/Map.m Sat Jul 13 15:24:57 2019 -0700
+++ b/scripts/+containers/Map.m Mon Jul 15 14:22:52 2019 +0100
@@ -485,6 +485,8 @@
         else
           keys = cell2mat (keys);
         endif
+      elseif (! isa (keys, this.KeyType))
+        keys = feval (this.KeyType, keys);
       endif
       keys = num2hex (keys);  # Force to char matrix with single logical
column
       if (cell_input)
@@ -725,6 +727,34 @@
 %!   assert (m.keys (), {key});
 %! endfor
 
+## Test using mixed numerical keys (subsref)
+%!test
+%! key = [1, 2, 3];
+%! val = {"One", "Two", "Three"};
+%! types = {"double", "single", "int32", "uint32", "int64", "uint64", ...
+%!          "int8", "uint8", "int16", "uint16"};
+%! for type1 = types
+%!   type = type1{1};
+%!   k = feval (type, key);
+%!   m = containers.Map (k, val);
+%!   for type2 = [types, "logical"]
+%!     type = type2{1};
+%!     k = feval (type, key(1));
+%!     assert (m(k), "One");
+%!   endfor
+%! endfor
+
+## Test using mixed numerical keys (subsasgn)
+%!test
+%! key = [1, 2, 3];
+%! val = {"One", "Two", "Three"};
+%! m = containers.Map(key, val);
+%! m (uint32 (1)) = "Four";
+%! assert (m.Count, uint64(3));
+%! assert (keys (m), {1, 2, 3});
+%! assert (m(1), "Four");
+%! assert (m(uint16 (1)), "Four");
+
 ## Test sort order of keys and values
 %!test
 %! key = {"d","a","b"};



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?56594>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]