bugGNU Octave - Bugs: bug #32066, textscan error

 
 

bug #32066: textscan error

Submitter:  Guillaume <gyom>
Submitted:  Thu 06 Jan 2011 02:18:37 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 19 Jan 2011 12:10:31 PM UTC, comment #11: 

Thank you, it makes sense now. PCRE is indeed not installed on my system.
It works fine now - note that MATLAB was also returning a wrong answer with the previous regexp.

Guillaume <gyom>
Wed 19 Jan 2011 09:13:41 AM UTC, comment #10: 

I checked in the following changeset:

http://hg.savannah.gnu.org/hgweb/octave/rev/90f8d12f1964

This seems to fix the problem for me, so I'm closing this report.

John W. Eaton <jwe>
Group administrator
Tue 18 Jan 2011 08:27:19 PM UTC, comment #9: 

The tests will succeed if the PCRE library is used for regexps.  It fails on my system if the PCRE library is not used.

That difference is not intentional, so we should either fix the uses of regexp in sttread.m to not require PCRE, or we should probably just require PCRE to build Octave.  Then at least we would be able to count on a particular set of regexp capabilities being available.

John W. Eaton <jwe>
Group administrator
Tue 18 Jan 2011 07:54:51 PM UTC, comment #8: 

This works for mee with todays TIP

octave:4> t = textscan('aaa.bbb','%s','delimiter','.');
octave:5> t
t =
{
  [1,1] =
  {
    [1,1] = aaa
    [2,1] = bbb
  }
}
octave:6>


Doug Stewart <dastew>
Tue 18 Jan 2011 07:30:22 PM UTC, comment #7: 

I just checked again that the functions I'm calling from latest Octave dev are the same than here:

http://hg.savannah.gnu.org/hgweb/octave/file/1811f4f8b3b5/scripts/io/strread.m
http://hg.savannah.gnu.org/hgweb/octave/file/1811f4f8b3b5/scripts/io/textscan.m

same for you? All the tests fails with these files...

Guillaume <gyom>
Tue 18 Jan 2011 07:19:56 PM UTC, comment #6: 

Ok. for Octave built with sources current 48 yrs ago ...


octave:10> c = textscan ('aaa.bbb', '%s', 'delimiter', '.')
c =
{
  [1,1] =
  {
    [1,1] = aaa
    [2,1] = bbb
  }
}
octave:11> c{1}
ans =
{
  [1,1] = aaa
  [2,1] = bbb
}
octave:12> test textscan
PASSES 2 out of 2 tests
octave:13> test strread
PASSES 7 out of 7 tests


With Matalb


>> c = textscan ('aaa.bbb', '%s', 'delimiter', '.')

c =

    {2x1 cell}

>> c{1}

ans =

    'aaa'
    'bbb'
-verbatim_

I'm getting consistent results with no changeset attached. I've updated my sources and am building again now.

I don't know what could be different. Is it possible that something has changed in your copy of the sources?

How does mercurial respond if you type ...

+verbatim+
hg update -C



Ben Abbott <bpabbott>
Group Member
Tue 18 Jan 2011 06:51:59 PM UTC, comment #5: 

Thanks for looking into this but I'm really puzzled...
Using the developers sources, nothing works for textscan:

octave:1> test textscan
  ***** test
 str = "1,  2,  3,  4\n 5,  ,  ,  8\n 9, 10, 11, 12";
 fmtstr = "%f %d %f %s";
 c = textscan (str, fmtstr, 2, "delimiter", ",", "emptyvalue", -Inf);
 assert (isequal (c{1}, [1;5]))
 assert (length (c{1}), 2);
 assert (iscellstr (c{4}))
 assert (isequal (c{3}, [3; -Inf]))
!!!!! test failed
strread: FORMAT does not match data

For the example I sent, I get:

t = textscan('aaa.bbb','%s','delimiter','.');
error: strread: FORMAT does not match data
error: called from:
error:   /.../octave/scripts/io/strread.m at line 235, column 11
error:   /.../octave/scripts/io/textscan.m at line 106, column 15

are we talking about the same files ?!?

Concerning the output, it's as it should be (a cell array containing a cell array) and matches with MATLAB.

Guillaume <gyom>
Tue 18 Jan 2011 06:16:43 PM UTC, comment #4: 

opps ... I attached the same changeset. Try the 3rd attempt.

(file #22441)

Ben Abbott <bpabbott>
Group Member
Tue 18 Jan 2011 06:13:29 PM UTC, comment #3: 

If the prior simple change is the correct thing to do, then this second one is a better implementation and includes a new test.

(file #22440)

Ben Abbott <bpabbott>
Group Member
Tue 18 Jan 2011 06:07:59 PM UTC, comment #2: 

Unfortunately, using your suggestion the tests for strread and textscan produce failures for me.


octave:8> test textscan
warning: division by zero
  ***** test
 str = "1,  2,  3,  4\n 5,  ,  ,  8\n 9, 10, 11, 12";
 fmtstr = "%f %d %f %s";
 c = textscan (str, fmtstr, 2, "delimiter", ",", "emptyvalue", -Inf);
 assert (isequal (c{1}, [1;5]))
 assert (length (c{1}), 2);
 assert (iscellstr (c{4}))
 assert (isequal (c{3}, [3; -Inf]))
!!!!! test failed
some elements undefined in return list
octave:9> test strread
warning: division by zero
  ***** test
 [a, b] = strread ("1 2", "%f%f");
 assert (a == 1 && b == 2);
!!!!! test failed
element number 1 undefined in return list


Using the developers sources, all tests for strread and textscan pass.

For the original problem


octave:11> t = textscan('aaa.bbb','%s','delimiter','.')
t =
{
  [1,1] =
  {
    [1,1] = aaa
    [2,1] = bbb
  }
}
octave:12> whos t
Variables in the current scope:

  Attr Name        Size                     Bytes  Class
  ==== ====        ====                     =====  =====
       t           1x1                          6  cell

Total is 1 element using 6 bytes

octave:13> t = textscan('aaa.bbb','%s','delimiter','.'){1}
t =
{
  [1,1] = aaa
  [2,1] = bbb
}
octave:14> whos t
Variables in the current scope:

  Attr Name        Size                     Bytes  Class
  ==== ====        ====                     =====  =====
       t           2x1                          6  cell

Total is 2 elements using 6 bytes


This is parsing the data correctly, but is not returning it in the proper format.

I haven't studied this bug, but the fix might be quite simple. For example, see the attached changeset.

(file #22439)

Ben Abbott <bpabbott>
Group Member
Tue 18 Jan 2011 05:30:05 PM UTC, comment #1: 

Actually, I think it's an error in strread.m, following that change:
http://hg.savannah.gnu.org/hgweb/octave/diff/64728cd28d7a/scripts/io/strread.m
I replaced l.191 in latest version with
[~, ~, ~, fmt_words] = regexp (format, '\%\w+');
and the example below now works, as well as all the tests but two (compared to none before).

Guillaume <gyom>
Thu 06 Jan 2011 02:18:37 PM UTC, original submission:  

When running
  textscan('aaa.bbb','%s','delimiter','.')
in Octave dev, one gets:
  error: strread: format does not match data
while one gets the expected answer in MATLAB: {'aaa';'bbb'}

This relates to these:
http://octave.1599824.n4.nabble.com/textscan-wanted-td3002808.html
https://savannah.gnu.org/bugs/index.php?31380

Guillaume <gyom>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #22440:  changeset.patch added by bpabbott (1KiB - 2nd iteration)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by dastew (Posted a comment)
  • -email is unavailable- added by bpabbott (Updated the item)
  • -email is unavailable- added by gyom
  • -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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-01-19 jwe StatusNone Fixed
        Open/ClosedOpen Closed
    2011-01-18 bpabbott Attached File- Added changeset.patch, #22441
    2011-01-18 bpabbott Attached File- Added changeset.patch, #22440
    2011-01-18 bpabbott Attached File- Added changeset.patch, #22439
    2011-01-18 gyom Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code