A bug in containers.Map

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

A bug in containers.Map

Abdallah Elshamy
Hello everyone,

I am not sure if this is significant enough to be considered as a bug.

There is a different behaviour that happens when you try to create a containers.Map using n*n char array as a key. I will illustrate on this example

containers.Map(['foo';'bar';'baz'], [1,2])

  • In octave it creates the map with one key (the first row "foo"). This key has a value of [1,2]. if you tried to access the map with a key that equals another row ("bar" or "baz"), it will raise an error that there is no such key.
  • In MATLAB online (I don't have access to the PC version), it raises an error that the number of keys and values is not the same. 
Cheers,
Abdallah
Reply | Threaded
Open this post in threaded view
|

Re: A bug in containers.Map

nrjank
Administrator
containers.Map(['foo';'bar';'baz'], [1,2])

  • In octave it creates the map with one key (the first row "foo"). This key has a value of [1,2]. if you tried to access the map with a key that equals another row ("bar" or "baz"), it will raise an error that there is no such key.
  • In MATLAB online (I don't have access to the PC version), it raises an error that the number of keys and values is not the same. 

trying it out in Matlab 2020a:

 >> containers.Map(['foo';'bar';'baz'], [1,2])
Error using containers.Map
The number of keys and values must be the same.


generally, it's not an error for Octave to do things that Matlab doesn't.  I don't know enough about this function to know what it should do and if allowing creation of the map _should_ be an error. But if that is problematic, it could be a bug worth reporting.
Reply | Threaded
Open this post in threaded view
|

Re: A bug in containers.Map

siko1056
On 6/19/20 4:46 AM, Nicholas Jankowski wrote:

>     containers.Map(['foo';'bar';'baz'], [1,2])
>
>       * In octave it creates the map with one key (the first row "foo").
>         This key has a value of [1,2]. if you tried to access the map
>         with a key that equals another row ("bar" or "baz"), it will
>         raise an error that there is no such key.
>       * In MATLAB online (I don't have access to the PC version), it
>         raises an error that the number of keys and values is not the same. 
>
>
> trying it out in Matlab 2020a:
>
>  >> containers.Map(['foo';'bar';'baz'], [1,2])
> Error using containers.Map
> The number of keys and values must be the same.
>
>
> generally, it's not an error for Octave to do things that Matlab
> doesn't.  I don't know enough about this function to know what it should
> do and if allowing creation of the map _should_ be an error. But if that
> is problematic, it could be a bug worth reporting.


Abdallah, thanks for the observation.  I opened a bug report about it
[1].  It should not be too difficult to fix it.  Do you want to give it
a try (short project)?

In this case I would expect the key to be a 3x3 char array (which is not
compatible with Matlab), which gets silently truncated to a 1x3 array
without warning.  At least this should be fixed.

Kai

[1] https://savannah.gnu.org/bugs/index.php?58617

Reply | Threaded
Open this post in threaded view
|

Re: A bug in containers.Map

Abdallah Elshamy



On Fri, Jun 19, 2020, 4:35 AM Kai Torben Ohlhus <[hidden email]> wrote:
On 6/19/20 4:46 AM, Nicholas Jankowski wrote:
>     containers.Map(['foo';'bar';'baz'], [1,2])
>
>       * In octave it creates the map with one key (the first row "foo").
>         This key has a value of [1,2]. if you tried to access the map
>         with a key that equals another row ("bar" or "baz"), it will
>         raise an error that there is no such key.
>       * In MATLAB online (I don't have access to the PC version), it
>         raises an error that the number of keys and values is not the same. 
>
>
> trying it out in Matlab 2020a:
>
>  >> containers.Map(['foo';'bar';'baz'], [1,2])
> Error using containers.Map
> The number of keys and values must be the same.
>
>
> generally, it's not an error for Octave to do things that Matlab
> doesn't.  I don't know enough about this function to know what it should
> do and if allowing creation of the map _should_ be an error. But if that
> is problematic, it could be a bug worth reporting.


Abdallah, thanks for the observation.  I opened a bug report about it
[1].  It should not be too difficult to fix it.  Do you want to give it
a try (short project)?


Sure, I will work on it.
 
cheers,
Abdallah