filesep extension

View: New views
12 Messages — Rating Filter:   Alert me  

filesep extension

by Michael Goffioul-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I noticed a problem in fileparts tests: some tests uses forward slash,
while fileparts uses filesep, which is the backward slash under Windows.
This makes most tests to fail.

To solve that, I thought about extending filesep behavior and make it
return all file separators when 'all' is given as argument. See the attached
changeset (OK to apply?). However, now I'd like to modify fileparts.m,
but I'm not sure about the most efficient way to implement find_last_of
functionality in ocave. Any idea?

Michael.


filesep_extend (2K) Download Attachment

filesep extension

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 11-Nov-2008, Michael Goffioul wrote:

| I noticed a problem in fileparts tests: some tests uses forward slash,
| while fileparts uses filesep, which is the backward slash under Windows.
| This makes most tests to fail.
|
| To solve that, I thought about extending filesep behavior and make it
| return all file separators when 'all' is given as argument. See the attached
| changeset (OK to apply?). However, now I'd like to modify fileparts.m,
| but I'm not sure about the most efficient way to implement find_last_of
| functionality in ocave. Any idea?

See also this thread:

  https://www-old.cae.wisc.edu/pipermail/octave-maintainers/2008-October/009169.html

I think your patch is also OK.

I'm not sure what to suggest for the best scripting language
equivalent for find_last_of.  A regular expression?  That doesn't seem
like a great solution and would be a bit messy in the current case
because \ is special in a regular expression.  For example, you need
something like

  regexp ('/foo/bar\baz', '[\\/][^\\/]*$')

Do we need a new function, or can someone think of a good way to do
this with functions we currently have?

jwe







Re: filesep extension

by Jaroslav Hajek-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 11, 2008 at 5:31 PM, John W. Eaton <jwe@...> wrote:

> On 11-Nov-2008, Michael Goffioul wrote:
>
> | I noticed a problem in fileparts tests: some tests uses forward slash,
> | while fileparts uses filesep, which is the backward slash under Windows.
> | This makes most tests to fail.
> |
> | To solve that, I thought about extending filesep behavior and make it
> | return all file separators when 'all' is given as argument. See the attached
> | changeset (OK to apply?). However, now I'd like to modify fileparts.m,
> | but I'm not sure about the most efficient way to implement find_last_of
> | functionality in ocave. Any idea?
>
> See also this thread:
>
>  https://www-old.cae.wisc.edu/pipermail/octave-maintainers/2008-October/009169.html
>
> I think your patch is also OK.
>
> I'm not sure what to suggest for the best scripting language
> equivalent for find_last_of.  A regular expression?  That doesn't seem
> like a great solution and would be a bit messy in the current case
> because \ is special in a regular expression.  For example, you need
> something like
>
>  regexp ('/foo/bar\baz', '[\\/][^\\/]*$')
>
> Do we need a new function, or can someone think of a good way to do
> this with functions we currently have?
>

What about implementing this using find (), with similar input &
output arguments?

Say, like this:

function varargout = strchr (str, chars, varargin)
  if (nargin < 2 || ! ischar (str) || ! ischar (chars))
    print_usage ();
  endif
  f = false (1, 256);
  f(chars) = true;
  varargout = cell (1, nargout);
  [varargout{:}] = find (reshape (f(str), size (str)), varargin{:});
endfunction

Two notes:
1. I think the function name should start with "str"
2. Note that this currently doesn't work with nargout = 0 due to a
strange indexing bug.

--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

Re: filesep extension

by Jaroslav Hajek-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 11, 2008 at 6:42 PM, Jaroslav Hajek <highegg@...> wrote:

> On Tue, Nov 11, 2008 at 5:31 PM, John W. Eaton <jwe@...> wrote:
>> On 11-Nov-2008, Michael Goffioul wrote:
>>
>> | I noticed a problem in fileparts tests: some tests uses forward slash,
>> | while fileparts uses filesep, which is the backward slash under Windows.
>> | This makes most tests to fail.
>> |
>> | To solve that, I thought about extending filesep behavior and make it
>> | return all file separators when 'all' is given as argument. See the attached
>> | changeset (OK to apply?). However, now I'd like to modify fileparts.m,
>> | but I'm not sure about the most efficient way to implement find_last_of
>> | functionality in ocave. Any idea?
>>
>> See also this thread:
>>
>>  https://www-old.cae.wisc.edu/pipermail/octave-maintainers/2008-October/009169.html
>>
>> I think your patch is also OK.
>>
>> I'm not sure what to suggest for the best scripting language
>> equivalent for find_last_of.  A regular expression?  That doesn't seem
>> like a great solution and would be a bit messy in the current case
>> because \ is special in a regular expression.  For example, you need
>> something like
>>
>>  regexp ('/foo/bar\baz', '[\\/][^\\/]*$')
>>
>> Do we need a new function, or can someone think of a good way to do
>> this with functions we currently have?
>>
>
> What about implementing this using find (), with similar input &
> output arguments?
>
> Say, like this:
>
> function varargout = strchr (str, chars, varargin)
>  if (nargin < 2 || ! ischar (str) || ! ischar (chars))
>    print_usage ();
>  endif
>  f = false (1, 256);
>  f(chars) = true;
>  varargout = cell (1, nargout);
>  [varargout{:}] = find (reshape (f(str), size (str)), varargin{:});
> endfunction
>
> Two notes:
> 1. I think the function name should start with "str"
> 2. Note that this currently doesn't work with nargout = 0 due to a
> strange indexing bug.
>

Okay so 2 doesn't matter since we always need to call find with at
least one output argument. Also, indexing by char should be shifted by
1, because char is 0..255. The attached version should work:

function varargout = strchr (str, chars, varargin)
  if (nargin < 2 || ! ischar (str) || ! ischar (chars))
    print_usage ();
  endif
  f = false (1, 256);
  f(chars+1) = true;
  varargout = cell (1, nargout){1} = [];
  [varargout{:}] = find (reshape (f(str+1), size (str)), varargin{:});
endfunction


--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

Re: filesep extension

by Jaroslav Hajek-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 11, 2008 at 7:04 PM, Jaroslav Hajek <highegg@...> wrote:

> On Tue, Nov 11, 2008 at 6:42 PM, Jaroslav Hajek <highegg@...> wrote:
>> On Tue, Nov 11, 2008 at 5:31 PM, John W. Eaton <jwe@...> wrote:
>>> On 11-Nov-2008, Michael Goffioul wrote:
>>>
>>> | I noticed a problem in fileparts tests: some tests uses forward slash,
>>> | while fileparts uses filesep, which is the backward slash under Windows.
>>> | This makes most tests to fail.
>>> |
>>> | To solve that, I thought about extending filesep behavior and make it
>>> | return all file separators when 'all' is given as argument. See the attached
>>> | changeset (OK to apply?). However, now I'd like to modify fileparts.m,
>>> | but I'm not sure about the most efficient way to implement find_last_of
>>> | functionality in ocave. Any idea?
>>>
>>> See also this thread:
>>>
>>>  https://www-old.cae.wisc.edu/pipermail/octave-maintainers/2008-October/009169.html
>>>
>>> I think your patch is also OK.
>>>
>>> I'm not sure what to suggest for the best scripting language
>>> equivalent for find_last_of.  A regular expression?  That doesn't seem
>>> like a great solution and would be a bit messy in the current case
>>> because \ is special in a regular expression.  For example, you need
>>> something like
>>>
>>>  regexp ('/foo/bar\baz', '[\\/][^\\/]*$')
>>>
>>> Do we need a new function, or can someone think of a good way to do
>>> this with functions we currently have?
>>>
>>
>> What about implementing this using find (), with similar input &
>> output arguments?
>>
>> Say, like this:
>>
>> function varargout = strchr (str, chars, varargin)
>>  if (nargin < 2 || ! ischar (str) || ! ischar (chars))
>>    print_usage ();
>>  endif
>>  f = false (1, 256);
>>  f(chars) = true;
>>  varargout = cell (1, nargout);
>>  [varargout{:}] = find (reshape (f(str), size (str)), varargin{:});
>> endfunction
>>
>> Two notes:
>> 1. I think the function name should start with "str"
>> 2. Note that this currently doesn't work with nargout = 0 due to a
>> strange indexing bug.
>>
>
> Okay so 2 doesn't matter since we always need to call find with at
> least one output argument. Also, indexing by char should be shifted by
> 1, because char is 0..255. The attached version should work:
>
> function varargout = strchr (str, chars, varargin)
>  if (nargin < 2 || ! ischar (str) || ! ischar (chars))
>    print_usage ();
>  endif
>  f = false (1, 256);
>  f(chars+1) = true;
>  varargout = cell (1, nargout){1} = [];
>  [varargout{:}] = find (reshape (f(str+1), size (str)), varargin{:});
> endfunction
>
>
> --
> RNDr. Jaroslav Hajek
> computing expert
> Aeronautical Research and Test Institute (VZLU)
> Prague, Czech Republic
> url: www.highegg.matfyz.cz
>

It seems I tried an ugly trick that wouldn't work. So here's a
hopefully working version:

 function varargout = strchr (str, chars, varargin)
 if (nargin < 2 || ! ischar (str) || ! ischar (chars))
   print_usage ();
 endif
 f = false (1, 256);
 f(chars+1) = true;
 varargout = cell (1, nargout);
 varagout{1} = [];
 [varargout{:}] = find (reshape (f(str+1), size (str)), varargin{:});
endfunction

--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

Re: filesep extension

by John W. Eaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 11-Nov-2008, Jaroslav Hajek wrote:

| It seems I tried an ugly trick that wouldn't work. So here's a
| hopefully working version:
|
|  function varargout = strchr (str, chars, varargin)
|  if (nargin < 2 || ! ischar (str) || ! ischar (chars))
|    print_usage ();
|  endif
|  f = false (1, 256);
|  f(chars+1) = true;
|  varargout = cell (1, nargout);
|  varagout{1} = [];
|  [varargout{:}] = find (reshape (f(str+1), size (str)), varargin{:});
| endfunction

What are you trying to do with

  varargout = cell (1, nargout);
  varagout{1} = [];

?  Why is the second statement needed?

jwe

Re: filesep extension

by Jaroslav Hajek-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 11, 2008 at 8:48 PM, John W. Eaton <jwe@...> wrote:

> On 11-Nov-2008, Jaroslav Hajek wrote:
>
> | It seems I tried an ugly trick that wouldn't work. So here's a
> | hopefully working version:
> |
> |  function varargout = strchr (str, chars, varargin)
> |  if (nargin < 2 || ! ischar (str) || ! ischar (chars))
> |    print_usage ();
> |  endif
> |  f = false (1, 256);
> |  f(chars+1) = true;
> |  varargout = cell (1, nargout);
> |  varagout{1} = [];
> |  [varargout{:}] = find (reshape (f(str+1), size (str)), varargin{:});
> | endfunction
>
> What are you trying to do with
>
>  varargout = cell (1, nargout);
>  varagout{1} = [];
>
> ?  Why is the second statement needed?
>

To force varargout to have at least one element. If strchr is called
with 0 arguments,
we should still call find with a single output arg and return it.

> jwe
>



--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

Re: filesep extension

by Michael Goffioul-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 11, 2008 at 6:28 PM, Jaroslav Hajek <highegg@...> wrote:

> It seems I tried an ugly trick that wouldn't work. So here's a
> hopefully working version:
>
>  function varargout = strchr (str, chars, varargin)
>  if (nargin < 2 || ! ischar (str) || ! ischar (chars))
>   print_usage ();
>  endif
>  f = false (1, 256);
>  f(chars+1) = true;
>  varargout = cell (1, nargout);
>  varagout{1} = [];
>  [varargout{:}] = find (reshape (f(str+1), size (str)), varargin{:});
> endfunction

I like this one. Why do you need to reshape?
How about commiting?

Michael.

Re: filesep extension

by Jaroslav Hajek-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Nov 12, 2008 at 11:37 AM, Michael Goffioul
<michael.goffioul@...> wrote:

> On Tue, Nov 11, 2008 at 6:28 PM, Jaroslav Hajek <highegg@...> wrote:
>> It seems I tried an ugly trick that wouldn't work. So here's a
>> hopefully working version:
>>
>>  function varargout = strchr (str, chars, varargin)
>>  if (nargin < 2 || ! ischar (str) || ! ischar (chars))
>>   print_usage ();
>>  endif
>>  f = false (1, 256);
>>  f(chars+1) = true;
>>  varargout = cell (1, nargout);
>>  varagout{1} = [];
>>  [varargout{:}] = find (reshape (f(str+1), size (str)), varargin{:});
>> endfunction
>
> I like this one. Why do you need to reshape?

If f and str happen to be both vectors, f(str+1) will inherit the
orientation of f rather than str. In all other cases, the reshape
operation does nothing.

> How about commiting?

OK. There is still a correction to be made to make the 3rd output
argument (if present) what one wants it to be - a char array rather
than a logical array.
I'll commit a changeset.

>
> Michael.
>



--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

Re: filesep extension

by Michael Goffioul-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Nov 12, 2008 at 12:56 PM, Jaroslav Hajek <highegg@...> wrote:
>> I like this one. Why do you need to reshape?
>
> If f and str happen to be both vectors, f(str+1) will inherit the
> orientation of f rather than str. In all other cases, the reshape
> operation does nothing.

f and str will (should) always be row vectors anyway, right?
Does strchr make sense for column vectors?

Michael.

Re: filesep extension

by Jaroslav Hajek-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Nov 12, 2008 at 2:18 PM, Michael Goffioul
<michael.goffioul@...> wrote:

> On Wed, Nov 12, 2008 at 12:56 PM, Jaroslav Hajek <highegg@...> wrote:
>>> I like this one. Why do you need to reshape?
>>
>> If f and str happen to be both vectors, f(str+1) will inherit the
>> orientation of f rather than str. In all other cases, the reshape
>> operation does nothing.
>
> f and str will (should) always be row vectors anyway, right?
> Does strchr make sense for column vectors?
>

It depends on what you want it to do. The version I aimed at should
mimick `find', allowing str to be any char matrix, it can be called
with 1-3 output arguments, and supporting the "N" and "DIRECTION"
additional arguments (as in `find').

Given that this function will actually be a wrapper over `find', it
seems logical to allow it to support everything that `find' supports.


> Michael.
>



--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

Re: filesep extension

by Søren Hauberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

ons, 12 11 2008 kl. 13:18 +0000, skrev Michael Goffioul:
> On Wed, Nov 12, 2008 at 12:56 PM, Jaroslav Hajek <highegg@...> wrote:
> >> I like this one. Why do you need to reshape?
> >
> > If f and str happen to be both vectors, f(str+1) will inherit the
> > orientation of f rather than str. In all other cases, the reshape
> > operation does nothing.
>
> f and str will (should) always be row vectors anyway, right?
> Does strchr make sense for column vectors?

I have one, slightly off-topic, question here. What does 'strchr' mean?
It's short for something, but I can't figure out what. My best guess is,
"string character", but I can't figure out what such a name means.

Søren