bugGNU Octave - Bugs: bug #56639, rescale: new function to scale an...

 
 

bug #56639: rescale: new function to scale an array to match a given interval

Submitter:  CH <atcl>
Submitted:  Tue 16 Jul 2019 10:33:44 PM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  3 - Low Item Group:  Feature Request
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 02 Dec 2019 04:21:26 PM UTC, comment #12: 

I checked in additional changes (https://hg.savannah.gnu.org/hgweb/octave/rev/4e6249815ea6) that allow integer and logical inputs, as well as a lot more input validation and BIST tests.

Marking as Ready for Test.

Rik <rik5>
Group administrator
Mon 02 Dec 2019 07:51:01 AM UTC, comment #11: 

You are right. What about the following change?

diff -r 80d68a3e8ec0 scripts/general/rescale.m
--- a/scripts/general/rescale.m        Mon Dec 02 01:16:12 2019 -0600
+++ b/scripts/general/rescale.m        Mon Dec 02 08:42:28 2019 +0100
@@ -85,13 +85,13 @@
     inmax = max (A(:));
   endif

-  ## Truncate values in A
-  A(A < inmin) = inmin;
-  A(A > inmax) = inmax;
-
   ## Rescale A to interval [l,u] in range interval [inmin,inmax].
   B = l + ( (A - inmin) ./ (inmax - inmin) ) .* (u - l);

+  ## Truncate values
+  B(A < inmin) = l;
+  B(A > inmax) = u;
+
 endfunction

 %!assert (rescale (0:5), (0:5)/5)


The input checks could probably be more restrictive, too. The following typo e.g. doesn't trigger an error:

rescale (0:6, "inptumin", 1)


Markus Mützel <mmuetzel>
Group administrator
Mon 02 Dec 2019 01:06:52 AM UTC, comment #10: 

Thanks for the fixes. Though now, doesn't the truncation of elements in A induce a copy of the argument?

CH <atcl>
Sun 01 Dec 2019 01:13:25 AM UTC, comment #9: 

I pushed the original changeset.  I meant to follow it up with a changeset immediately to change over to Octave coding conventions like using '!' for the logical not operator rather than the functional form "not (...)".  Thanks for getting to that before me.  I still have a few changes to the documentation to make, and I'll take a look at handling vector L and U.

Rik <rik5>
Group administrator
Sat 30 Nov 2019 09:55:39 PM UTC, comment #8: 

Was the original function pushed by accident?
I pushed a follow up changeset here that fixes a few errors including some that broke the build:
http://hg.savannah.gnu.org/hgweb/octave/rev/1a8fd58af587

However, I think that non-scalar L and U are still not treated correctly.

Markus Mützel <mmuetzel>
Group administrator
Thu 18 Jul 2019 12:01:25 AM UTC, comment #7: 

Great.  Look for an m-file in Octave that is vaguely similar and start with that as a template.  That will have the basic form of the copyright notice, texinfo documentation, function prototype, input validation, function body, and BIST tests at end.

Rik <rik5>
Group administrator
Wed 17 Jul 2019 11:02:35 PM UTC, comment #6: 

Since this should be implemented in an m-file, I am willing to contribute this.

CH <atcl>
Wed 17 Jul 2019 04:36:39 AM UTC, comment #5: 

Added item to https://wiki.octave.org/Short_projects and overhauled that page.

Kai Torben Ohlhus <siko1056>
Group Member
Wed 17 Jul 2019 02:47:05 AM UTC, comment #4: 

This would be very easy to write as an m-file and get 90% of the functionality.  The documentation even describes the algorithm (which is simple to guess anyways).  This would make a suitable introductory project for programmers wishing to start contributing to Octave.

Rik <rik5>
Group administrator
Tue 16 Jul 2019 10:44:33 PM UTC, comment #3: 

I see, thank you. Updating the description. Here is a link to the Matlab documentation for the 'rescale' function. It's already listed in Octave's internal list of missing functions to be implemented.

https://www.mathworks.com/help/matlab/ref/rescale.html

Mike Miller <mtmiller>
Group Member
Tue 16 Jul 2019 10:40:36 PM UTC, comment #2: 

Thank you for your bug report. This needs a lot of clarification however, at least for me to understand what this is about.

Matlab 2019a does not appear to have any 'resize' function. Where is the function that you are referring to defined? Are you sure it's really part of Matlab?

Octave already has a function called 'resize', which changes the dimension of an array and pads or truncates as needed.

Mike Miller <mtmiller>
Group Member
Tue 16 Jul 2019 10:38:39 PM UTC, comment #1: 

Sorry, this was supposed to be called "rescale". Please re-title if possible.

CH <atcl>
Tue 16 Jul 2019 10:33:44 PM UTC, original submission:  

Matlab 2017b added a "resize" function, which scales the input data to a specific range. Does the function need to be specified here? Would this function be implemented as an .m file or low-level?

CH <atcl>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #47920:  rescale.m added by atcl (3KiB - text/x-objcsrc - Here is an initial attempt for "rescale.m". It still needs testing and BIST tests. Is the coding style acceptable?)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by atcl (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-01-04 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2019-12-02 rik5 StatusIn Progress Ready For Test
    2019-12-01 rik5 StatusConfirmed In Progress
    2019-11-21 atcl Attached File- Added rescale.m, #47920
    2019-07-16 mtmiller Severity3 - Normal 1 - Wish
        Priority5 - Normal 3 - Low
        Item GroupMatlab Compatibility Feature Request
        StatusNeed Info Confirmed
        Summaryresize function rescale: new function to scale an array to match a given interval
    2019-07-16 mtmiller CategoryInterpreter Octave Function
        StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code