bugGNU Octave - Bugs: bug #53179, Wrong result with bsxfun (single...

 
 

bug #53179: Wrong result with bsxfun (single complex argument)

Submitter:  Ceral Paquet <octavebugs>
Submitted:  Sat 17 Feb 2018 09:53:05 PM UTC
   
 
Category:  Octave Function Severity:  4 - Important
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.2.2 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 21 Mar 2018 10:36:28 PM UTC, comment #5: 

There was actually quite a bit of cruft to clean up in bsxfun.  I did that here http://hg.savannah.gnu.org/hgweb/octave/rev/bff4a7c7bc39 and also added a BIST test for this bug report.

The change will be part of the 4.4.0 release.

Rik <rik5>
Group administrator
Thu 15 Mar 2018 10:09:26 PM UTC, comment #4: 

I'm about halfway through a changeset for this.  OctConf 2018 intervened and I've got work to do on Friday.  But I hope to commit something soon before the 4.4 release.

Rik <rik5>
Group administrator
Thu 15 Mar 2018 09:45:16 PM UTC, comment #3: 

Rik's suggestions plus one other change seem to fix this bug.


499,502c499,502
<                                have_ComplexNDArray = true;
<                                result_ComplexNDArray =
<                                  tmp(0).complex_array_value ();
<                                result_ComplexNDArray.resize (dvc);
---
>                               have_FloatComplexNDArray = true;
>                               result_FloatComplexNDArray =
>                                 tmp(0).float_complex_array_value ();
>                               result_FloatComplexNDArray.resize (dvc);
575c575
<                             FloatComplexNDArray (result_FloatNDArray);
---
>                             FloatComplexNDArray (result_FloatComplexNDArray);


Ceral Paquet <octavebugs>
Mon 19 Feb 2018 01:08:19 AM UTC, comment #2: 

This is almost certainly a bug in bsxfun.cc.  The following is taken from bsxfun.cc:


if (result_type == "double")
  {
    if (tmp(0).isreal ())
      {
        have_NDArray = true;
        result_NDArray = tmp(0).array_value ();
        result_NDArray.resize (dvc);
      }
    else
      {
        have_ComplexNDArray = true;
        result_ComplexNDArray =
          tmp(0).complex_array_value ();
        result_ComplexNDArray.resize (dvc);
      }
  }
else if (result_type == "single")
  {
    if (tmp(0).isreal ())
      {
        have_FloatNDArray = true;
        result_FloatNDArray
          = tmp(0).float_array_value ();
        result_FloatNDArray.resize (dvc);
      }
    else
      {
        have_ComplexNDArray = true;
        result_ComplexNDArray =
          tmp(0).complex_array_value ();
        result_ComplexNDArray.resize (dvc);
      }


Notice how when the result type is "single" and complex, a double complex NDAarray is used.  This may be a relatively simple fix.



Rik <rik5>
Group administrator
Sun 18 Feb 2018 06:21:45 AM UTC, comment #1: 

Confirmed.  And it is only bsxfun.  The interprter, with broadcasting, gets it right.


im .* mask
ans =

ans(:,:,1) =

   0 + 0i   0 + 0i   1 + 1i   1 + 1i
   0 + 0i   0 + 0i   1 + 1i   1 + 1i
   0 + 0i   0 + 0i   1 + 1i   1 + 1i
   0 + 0i   0 + 0i   1 + 1i   1 + 1i

ans(:,:,2) =

   0 + 0i   0 + 0i   1 + 1i   1 + 1i
   0 + 0i   0 + 0i   1 + 1i   1 + 1i
   0 + 0i   0 + 0i   1 + 1i   1 + 1i
   0 + 0i   0 + 0i   1 + 1i   1 + 1i




Rik <rik5>
Group administrator
Sat 17 Feb 2018 09:53:05 PM UTC, original submission:  

I just ran into a serious problem with bsxfun with single complex arguments.


>> im=ones(4,4,2)+single(i);
>> mask=true(4,4);
>> mask(:,1:2)=0;
>> bsxfun(@times,im,mask)
ans =

ans(:,:,1) =

   0   0   0   0
   0   0   0   0
   0   0   0   0
   0   0   0   0

ans(:,:,2) =

   0 + 0i   0 + 0i   0 + 0i   1 + 1i
   0 + 0i   0 + 0i   0 + 0i   1 + 1i
   0 + 0i   0 + 0i   0 + 0i   1 + 1i
   0 + 0i   0 + 0i   0 + 0i   1 + 1i



The result only seems to depend on "im" being single and complex.


>> bsxfun(@times,real(im),mask)
ans =

ans(:,:,1) =

   0   0   1   1
   0   0   1   1
   0   0   1   1
   0   0   1   1

ans(:,:,2) =

   0   0   1   1
   0   0   1   1
   0   0   1   1
   0   0   1   1

>> bsxfun(@times,double(im),mask)
ans =

ans(:,:,1) =

   0 + 0i   0 + 0i   1 + 1i   1 + 1i
   0 + 0i   0 + 0i   1 + 1i   1 + 1i
   0 + 0i   0 + 0i   1 + 1i   1 + 1i
   0 + 0i   0 + 0i   1 + 1i   1 + 1i

ans(:,:,2) =

   0 + 0i   0 + 0i   1 + 1i   1 + 1i
   0 + 0i   0 + 0i   1 + 1i   1 + 1i
   0 + 0i   0 + 0i   1 + 1i   1 + 1i
   0 + 0i   0 + 0i   1 + 1i   1 + 1i

>> bsxfun(@times,im,double(mask))
ans =

ans(:,:,1) =

   0   0   0   0
   0   0   0   0
   0   0   0   0
   0   0   0   0

ans(:,:,2) =

   0 + 0i   0 + 0i   0 + 0i   1 + 1i
   0 + 0i   0 + 0i   0 + 0i   1 + 1i
   0 + 0i   0 + 0i   0 + 0i   1 + 1i
   0 + 0i   0 + 0i   0 + 0i   1 + 1i


Ceral Paquet <octavebugs>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mtmiller (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by octavebugs (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-03-21 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2018-03-20 mtmiller CategoryNone Octave Function
        Severity3 - Normal 4 - Important
        Item GroupNone Incorrect Result
        Release4.2.1 4.2.2
    2018-02-18 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code