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

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

[Octave-bug-tracker] [bug #49559] Implementation of containers.Map


From: Rik
Subject: [Octave-bug-tracker] [bug #49559] Implementation of containers.Map
Date: Wed, 5 Apr 2017 14:13:20 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0

Follow-up Comment #15, bug #49559 (project octave):

@Guillaume: Thank you for the excellent work.  I made some changes for
performance, and to fix the issue with ordering of numeric keys, and checked
it in here (http://hg.savannah.gnu.org/hgweb/octave/rev/5ab7192f91d8).  Any
further development can take place on the development branch.

Using the example with 2,000 key pairs, the original code ran in an average of
143 milliseconds.

One of the first things I did was to optimize the use of cellfun. 
Unfortunately, arbitrary anonymous functions as inputs to cellfun are slower
than using the small list of know functions which are accelerated in cellfun. 
Instead of writing,


all (cellfun (@(x) isreal (x) && isscalar (x), keys))


I wrote


all (cellfun ("isreal", keys) & (cellfun ("numel", keys) == 1))


Changes of this sort made a -25% difference in run time to 107 milliseconds.

Next, I agree that the keys should always be strings, but rather than use
typecast and num2hex I simply use sprintf.


keys = ostrsplit (sprintf ("%.16g\n", keys{:}), "\n");


This brings the runtime down to ~40 milliseconds or -70% of the original code.
 It has the added benefit of properly handling numeric keys with negative
values.

I also added extensive BIST testing for the error conditions.

There is still some more work to do.  Matlab documentation suggests that
different sizes should cause the ValueType to be set to "any".


Default: 'any' when you create an empty Map object or when you specify values
of different sizes or types, otherwise determined by the data type of
valueSet.


Currently, Octave makes the decision based on multiple value type, but not
their sizes.  Could someone with access to Matlab try the following?


m = containers.Map ([1, 2], {magic(3), magic(4)})
m.ValueType


Octave returns "double".

As a second issue, do we need to follow Matlab exactly and not implement
horzcat?  Octave is a superset of Matlab and if a programmer writes


map3 = [map1, map2]


it seems pretty obvious that they meant to concatenate the two.





    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?49559>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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