bugGNU Octave - Bugs: bug #32088, Feature request: -ALL option for...


bug #32088: Feature request: -ALL option for WHICH

Submitter:  Guillaume <gyom>
Submitted:  Mon 10 Jan 2011 12:51:24 PM UTC
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Feature Request
Status:  Confirmed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Jump to the original submission

Wed 16 Nov 2022 02:44:54 AM UTC, comment #22: 

I think warning the user is important.  I reviewed the patch and committed it to the stable branch (now version 8 of Octave) here: http://hg.savannah.gnu.org/hgweb/octave/rev/2569c40924e7.

Rik <rik5>
Group administrator
Tue 15 Nov 2022 10:45:49 PM UTC, comment #21: 

status update:

still present in Octave 7.3.0

-all is still the only option that doesn't work, noting however that it fails silently (assumedly because it can't find a nonexistent file/function named '-all'.), perhaps misleading the user.

ignoring the file #51094 version, the last patch submitted in 2011 obviously no longer applies cleanly to the code, and in any case it worked by modifying 'path' within which.m, which seemed to be an undesirable approach. 

the initial intent to process changes in __which__ mentioned in comment #14 stalled in 2015. 

@gyom's comment #16 file_in_loadpath m-code level suggestion seems interesting but not sure it would capture all of the method and subfunction results as identified in earlier comments.

Removing the Patch Submitted status, as it doesn't seem to really apply anymore. 

If desired, since this likely won't make it for at least another version, attached is a patch that issues a warning rather than just failing silently. (it also then strips the -all out of varargin, perhaps that's not necessary since it currently fails silently.)

(file #53962)

Nicholas Jankowski <nrjank>
Group Member
Wed 17 Nov 2021 10:22:49 PM UTC, comment #20: 

presently the Matlab version of which has the following permissible command and function syntax:

which item
which fun1 in fun2
which ___ -all
str = which(item)
str = which(fun1,'in',fun2)
str = which(___,'-all')

quick tests show that all of the above work except for -all. so this is still relevant in Octave 6.4.0.

Nicholas Jankowski <nrjank>
Group Member
Fri 26 Mar 2021 05:02:24 AM UTC, comment #19: 

@siko1056: I'm really sorry for the inconvenience. I did go through the wiki page for submitting patches and I tried to remove the tabs in my code but it seems that I missed a few, I'm really sorry for that.

I also just realized that the "which" function I created doesn't return any value which is why there are problems when the tests. I vaguely remember running the tests on the function and the function passed all of them but I may have messed up the path while running that.

I mainly tested what I wrote for cases without any requirements for a return value and they all gave the correct results that's why I uploaded this.

Thanks for the feedback I'll be more careful while uploading future contributions. I'll also look at some of the other short projects as well but I will still try to work on this.

Harsh Kulkarni <hhk>
Tue 23 Mar 2021 04:42:41 AM UTC, comment #18: 

@hhk: Thanks for file #51094.  I am very sorry, but this project does not qualify for a "short project".  It is now removed from the respective wiki list.

Please take a look at https://wiki.octave.org/Mercurial how to properly form an Octave patch contribution.  Your modified "which" function still contains tabs and debug output.

Again, this item does not qualify for a short project.  There are several submitted unreviewed patches.  Please do not submit new ones.

Kai Torben Ohlhus <siko1056>
Group Member
Wed 19 Aug 2020 02:26:31 AM UTC, comment #17: 

The requested new feature "which -all" doesn't seem to be implemented in Octave 5.2.0.

Tue 13 Mar 2018 10:50:40 AM UTC, comment #16: 

Looking back at this, my use case would be solved by calling file_in_loadpath (..., "all") instead of which (..., "-all") as I'm looking for all the occurrences of a specific M-file name in the path.

which does something a lot more complicated as it searches for functions, subfunctions, local functions, methods, possibly written as oct/mex files. Is "load_path::find_all_first_of" the right low level function to call in order to get the right information?

Guillaume <gyom>
Mon 21 Nov 2016 03:46:46 PM UTC, comment #15: 

I'm still very interested in this, and it seems that I'm not alone.

Looking at it again, I found an interesting file_in_loadpath which allows for a second optional argument "all" to be supplied. What is the best way to proceed? Shall we change _which_/do_which in libinterp/corefcn/help.cc to call load_path::find_all_first_of or stay at the M-code level and have which call file_in_loadpath?

Guillaume <gyom>
Sat 19 Nov 2016 02:41:29 PM UTC, comment #14: 

The requested new feature "which -all" doesn't seem to be implemented in Octave 4.2.0, yet.

Hartmut <hardy>
Thu 12 Nov 2015 03:56:24 AM UTC, comment #13: 

@Shaun: Following up on your post in June, since there was no response I think it is fair to proceed in the manner you suggested.  Modify do_which to return a string_vector.  The C++ function _which_ can decide based on the length whether to return a Cell with multiple entries, or just a single entry of type std::string.

Rik <rik5>
Group administrator
Sun 28 Jun 2015 05:14:58 AM UTC, comment #12: 

Preparing to work on help.cc to implement this.  The primary issue as I understand it is that do_which is capable of only returning std::string instead of string_vector.  Several ways to address this, jwe is there a preference or model for how you would like it handled? 

Most obvious to me would be to change do_which to always return a string vector, then have which.m handle the issue of changing it back to a char or leave as a cellstr depending on the size of the _which_ return value.  Appears to be limited calls to do_which throughout the codebase so modification of its return value may be feasible.

Shaun Eack <seack>
Sat 25 Jan 2014 09:56:12 PM UTC, comment #11: 

Thanks, that looks good. There may be other cases, I haven't started looking at adding this feature yet, but I wanted to see how which interacts with variables.

Mike Miller <mtmiller>
Group Member
Sat 25 Jan 2014 02:21:45 PM UTC, comment #10: 

Here you go!

>> which -all norm
built-in (/Applications/MATLAB_R2013b.app/toolbox/matlab/matfun/@single/norm)  % single method
built-in (/Applications/MATLAB_R2013b.app/toolbox/matlab/matfun/@double/norm)  % double method
/Users/mcgrant/Projects/CVX/trunk/builtins/@cvx/norm.m                         % cvx method
>> norm=10;
>> which -all norm
norm is a variable.
built-in (/Applications/MATLAB_R2013b.app/toolbox/matlab/matfun/@single/norm)  % Shadowed single method
built-in (/Applications/MATLAB_R2013b.app/toolbox/matlab/matfun/@double/norm)  % Shadowed double method
/Users/mcgrant/Projects/CVX/trunk/builtins/@cvx/norm.m                         % Shadowed cvx method
>> dd = which('norm','-all'); dd

dd =

    'built-in (/Applications/MATLAB_R2013b.app/toolbox/matlab/matfun/@single/norm)'
    'built-in (/Applications/MATLAB_R2013b.app/toolbox/matlab/matfun/@double/norm)'

Michael C. Grant <mcgrant>
Sat 25 Jan 2014 09:01:23 AM UTC, comment #9: 

If there is a normal workspace variable that shadows one or more functions, does which -all also show the variable at the top of the list? For example,

>> which -all norm
%% output shows the functions in the order you listed
>> norm = 10;
>> which -all norm
%% output shows the variable and then the same list of functions?

Thanks for the info.

Mike Miller <mtmiller>
Group Member
Tue 07 Jan 2014 03:54:02 PM UTC, comment #8: 

From what I am seeing, both in the documentation and my own usage of the command, WHICH -ALL has the following priorities:

-- non-shadowed standard functions/scripts in the path (e.g., 'norm')
-- all class methods in the path (e.g., '@cvx/norm'), in path order, including shadowed methods (which i grant you are very unlikely)
-- shadowed standard functions/scripts in the path, in path order

Michael C. Grant <mcgrant>
Mon 31 Jan 2011 01:36:16 PM UTC, comment #7: 

I agree that changing _which_ is the way forward.

There does not seem to be a mention of the order of the results to '-all' in the MATLAB documentation but, in practice, the order corresponds to the order of how the matching results are found in the path, so that the first one would actually be the function called. The output is like this:

>> which -all foo
/home/login/dir2/foo.m % Shadowed

For methods, you get:

>> which @foo/bar % the '@' is not necessary
/home/login/dir1/@foo/bar.m %foo method
>> which -all @foo/bar
/home/login/dir1/@foo/bar.m %foo method
/home/login/dir2/@foo/bar.m %foo method

At last, concerning subfunctions, I was not aware of the ">" notation and this is not mentioned in the MATLAB documentation, but it works:

>> which @foo/bar>sub
/home/login/dir1/@foo/bar.m (sub) % Subfunction of bar
>> which -all @foo/bar>sub
/home/login/dir1/@foo/bar.m (sub) % Subfunction of bar
>> which -all sub in @foo/bar
/home/login/dir1/@foo/bar.m (sub) % Subfunction of bar

i.e. the '-all' option does not work for subfunctions of methods of a class. It seems to me, however, to be of a very specific and limited use.

Guillaume <gyom>
Sat 22 Jan 2011 06:23:32 PM UTC, comment #6: 

I think it would be better to do this by changing the way _which_ works instead of playing tricks with the load path.

In Matlab, what exactly does which -all find, and does the order of the results matter?  Does it find subfucntions in the current scope, or all possible subfunctions (I don't think that is reasonable, as it means parsing every function on the load path). 

What does it do for

which -all @foo/bar

Does it find every @foo/bar.m file on the path if there are multiple @foo directories?

What about

which -all foo>bar

for looking up subfunctions?

I'm not sure this will make it into 3.4, but you do have a workaround with the function you've written.

John W. Eaton <jwe>
Group administrator
Thu 20 Jan 2011 09:04:02 PM UTC, comment #5: 

For coding guidelines and mercurial tips, take a look at the doc/interpreter/contrib.txi file.  If you have the documentation built as part of your local build from the hg archive, look at the "Contributing Guidelines" chapter in the manual.

John W. Eaton <jwe>
Group administrator
Thu 20 Jan 2011 06:44:48 PM UTC, comment #4: 

Another version for compatibility with MATLAB: WHICH should return a string while WHICH -ALL returns a cell array.
Maybe this should be implemented in octave/src/help.cc.

(file #22472)

Guillaume <gyom>
Thu 20 Jan 2011 03:29:36 PM UTC, comment #3: 

I've added an unwind_protect statement and slightly simplified the code.
Where can I find some more information about coding conventions used in Octave?
The new attached file is the output from 'hg diff'.

(file #22468)

Guillaume <gyom>
Thu 20 Jan 2011 08:37:52 AM UTC, comment #2: 

If you modify global state like the loadpath, you need to use some method to protect it from being changed in the event of an interrupt, either with unwind_protect or onCleanup.

It would help if you followed the coding conventions used in Octave and also submitted a Mercurial changeset instead of a new copy of the function.

John W. Eaton <jwe>
Group administrator
Wed 19 Jan 2011 07:47:44 PM UTC, comment #1: 

Please find attached a suggestion for an implementation of WHICH with the -ALL option.

(file #22458)

Guillaume <gyom>
Mon 10 Jan 2011 12:51:24 PM UTC, original submission:  

It would be useful if the WHICH command could support a '-ALL' option that would return the full path of all occurrences of a function.
See http://www.mathworks.com/help/techdoc/ref/which.html

Guillaume <gyom>


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

Attach Files:

Attached Files
file #53962:  which_all_warning.patch added by nrjank (1KiB - application/octet-stream - patch to add an unimplemented warning for the -all option)
file #51094:  which.m added by hhk (4KiB - text/x-objcsrc - Here is my implementation to solve this problem, it gives the location of all the required functions. This implementation works by removing the paths which are located and after all the instances are found the paths are added again.)
file #22472:  which.patch added by gyom (2KiB - text/x-patch)
file #22468:  which.patch added by gyom (2KiB - text/x-patch)
file #22458:  which.m added by gyom (2KiB - text/x-matlab)


Carbon-Copy List
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by hhk (Updated the item)
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by amro_octave
  • -email is unavailable- added by hardy (Posted a comment)
  • -email is unavailable- added by lachlan (Updated the item)
  • -email is unavailable- added by seack (Posted a comment)
  • -email is unavailable- added by mcgrant (Posted a comment)
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by mtmiller (Updated the item)
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by gyom (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 17 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-11-15 nrjank Attached File- Added which_all_warning.patch, #53962
        StatusPatch Submitted Confirmed
        Operating SystemGNU/Linux Any
    2021-03-23 siko1056 StatusNone Patch Submitted
    2021-03-20 hhk Attached File- Added which.m, #51094
    2020-08-19 siko1056 StatusIn Progress None
    2017-04-05 amro_octave Carbon-Copy- Added amro_octave
    2016-02-08 lachlan StatusPatch Submitted In Progress
    2014-01-11 mtmiller Dependencies- bugs #32973 is dependent
    2014-01-07 mtmiller Dependencies- bugs #41135 is dependent
    2013-10-17 rik5 StatusPostponed Patch Submitted
    2013-04-19 mtmiller CategoryNone Interpreter
        StatusNone Postponed
    2011-01-20 gyom Attached File- Added which.patch, #22472
    2011-01-20 gyom Attached File- Added which.patch, #22468
    2011-01-19 gyom Attached File- Added which.m, #22458
    2011-01-10 jwe Summary-ALL option for WHICH Feature request: -ALL option for WHICH

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code