bugGNU Octave - Bugs: bug #66652, Element power operator introduces...

 
 

bug #66652: Element power operator introduces numerical error when broadcasting

Submitter:  None
Submitted:  Fri 10 Jan 2025 04:39:20 PM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Confirmed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * 9.3.0
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 10 Jan 2025 08:44:33 PM UTC, comment #3: 


>> x = [i; 2i; 3i] .^ [2 1 0]
x =
  -1.0000 + 0.0000i   0.0000 + 1.0000i   1.0000 +      0i
  -4.0000 + 0.0000i   0.0000 + 2.0000i   1.0000 +      0i
  -9.0000 + 0.0000i   0.0000 + 3.0000i   1.0000 +      0i

>> y = bsxfun ('power', [i; 2i; 3i], [2 1 0])
y =
  -1 + 0i   0 + 1i   1 + 0i
  -4 + 0i   0 + 2i   1 + 0i
  -9 + 0i   0 + 3i   1 + 0i

>> x - y
ans =
            0 + 1.2246e-16i   6.1232e-17 +          0i            0 +          0i
            0 + 4.8986e-16i   1.2246e-16 +          0i            0 +          0i
  -1.7764e-15 + 1.1022e-15i   1.8370e-16 + 4.4409e-16i            0 +          0i


Paavo

Anonymous
Fri 10 Jan 2025 07:18:32 PM UTC, comment #2: 

On MacOS octave 10 there is no difference:

octave:1> # exponent vector
p = [2 1 0]

# scalar .^ vector is correct
x = i .^ p, x - round(x)
x = (2i) .^ p, x - round(x)
x = (3i) .^ p, x - round(x)

# column vector .^ row vector has numerical error
x = [i; 2i; 3i] .^ p, x - round(x)

# expanding vectors to full matrix is correct again
x = [i i i; 2i 2i 2i; 3i 3i 3i] .^ [2 1 0; 2 1 0; 2 1 0]
x - round (x)
p =

   2   1   0

x =

  -1.0000 + 0.0000i   0.0000 + 1.0000i   1.0000 +      0i

ans =

            0 + 1.2246e-16i   6.1232e-17 +          0i            0 +          0i

x =

  -4.0000 + 0.0000i   0.0000 + 2.0000i   1.0000 +      0i

ans =

            0 + 4.8986e-16i   1.2246e-16 +          0i            0 +          0i

x =

  -9.0000 + 0.0000i   0.0000 + 3.0000i   1.0000 +      0i

ans =

  -1.7764e-15 + 1.1022e-15i   1.8370e-16 + 4.4409e-16i            0 +          0i

x =

  -1.0000 + 0.0000i   0.0000 + 1.0000i   1.0000 +      0i
  -4.0000 + 0.0000i   0.0000 + 2.0000i   1.0000 +      0i
  -9.0000 + 0.0000i   0.0000 + 3.0000i   1.0000 +      0i

ans =

            0 + 1.2246e-16i   6.1232e-17 +          0i            0 +          0i
            0 + 4.8986e-16i   1.2246e-16 +          0i            0 +          0i
  -1.7764e-15 + 1.1022e-15i   1.8370e-16 + 4.4409e-16i            0 +          0i

x =

  -1.0000 + 0.0000i   0.0000 + 1.0000i   1.0000 +      0i
  -4.0000 + 0.0000i   0.0000 + 2.0000i   1.0000 +      0i
  -9.0000 + 0.0000i   0.0000 + 3.0000i   1.0000 +      0i

ans =

            0 + 1.2246e-16i   6.1232e-17 +          0i            0 +          0i
            0 + 4.8986e-16i   1.2246e-16 +          0i            0 +          0i
  -1.7764e-15 + 1.1022e-15i   1.8370e-16 + 4.4409e-16i            0 +          0i

octave:8> x = [i i i; 2i 2i 2i; 3i 3i 3i] .^ [2 1 0; 2 1 0; 2 1 0], x - round (x)
x =

  -1.0000 + 0.0000i   0.0000 + 1.0000i   1.0000 +      0i
  -4.0000 + 0.0000i   0.0000 + 2.0000i   1.0000 +      0i
  -9.0000 + 0.0000i   0.0000 + 3.0000i   1.0000 +      0i

ans =

            0 + 1.2246e-16i   6.1232e-17 +          0i            0 +          0i
            0 + 4.8986e-16i   1.2246e-16 +          0i            0 +          0i
  -1.7764e-15 + 1.1022e-15i   1.8370e-16 + 4.4409e-16i            0 +          0i

octave:9> x = [i; 2i; 3i] .^ [2 1 0], x - round (x)
x =

  -1.0000 + 0.0000i   0.0000 + 1.0000i   1.0000 +      0i
  -4.0000 + 0.0000i   0.0000 + 2.0000i   1.0000 +      0i
  -9.0000 + 0.0000i   0.0000 + 3.0000i   1.0000 +      0i

ans =

            0 + 1.2246e-16i   6.1232e-17 +          0i            0 +          0i
            0 + 4.8986e-16i   1.2246e-16 +          0i            0 +          0i
  -1.7764e-15 + 1.1022e-15i   1.8370e-16 + 4.4409e-16i            0 +          0i

octave:10>


Dmitri.
--


Dmitri A. Sergatskov <dasergatskov>
Fri 10 Jan 2025 05:36:01 PM UTC, comment #1: 

can confirm.  it seems any combination/orientation of matrix/vectors that require broadcasting introduce numerical error while 'the same' operations requiring no expansion do not.  This suggests different operations are being performed, or broadcasting is skipping some steps that are otherwise taken to ensure 'nice' answers.
these are mostly numerically small.  all values of x-round(x) appear to be smaller than eps(x).  So, I'm dropping severity and recategorizing from 'incorrect result' to 'inaccurate result', even though that might be overstating things.

It might be worth looking at why these operations result in different numerical results when they should be doing the same thing.

Nicholas Jankowski <nrjank>
Group Member
Fri 10 Jan 2025 04:39:20 PM UTC, original submission:  

Broadcasting with element power operator causes small but unnecessary numerical error.

Problem is only with broadcasting different sizes, not scalar or equal size matrix.


# exponent vector
p = [2 1 0]

# scalar .^ vector is correct
x = i .^ p, x - round(x)
x = (2i) .^ p, x - round(x)
x = (3i) .^ p, x - round(x)

# column vector .^ row vector has numerical error
x = [i; 2i; 3i] .^ p, x - round(x)

# expanding vectors to full matrix is correct again
x = [i i i; 2i 2i 2i; 3i 3i 3i] .^ [2 1 0; 2 1 0; 2 1 0]
x - round (x)


Full matrix result:

>> x = [i i i; 2i 2i 2i; 3i 3i 3i] .^ [2 1 0; 2 1 0; 2 1 0], x - round (x)
x =
  -1 + 0i   0 + 1i   1 + 0i
  -4 + 0i   0 + 2i   1 + 0i
  -9 + 0i   0 + 3i   1 + 0i

ans =
   0   0   0
   0   0   0
   0   0   0


Vector broadcast error result:

>> x = [i; 2i; 3i] .^ [2 1 0], x - round (x)
x =
  -1.0000 + 0.0000i   0.0000 + 1.0000i   1.0000 +      0i
  -4.0000 + 0.0000i   0.0000 + 2.0000i   1.0000 +      0i
  -9.0000 + 0.0000i   0.0000 + 3.0000i   1.0000 +      0i

ans =
            0 + 1.2246e-16i   6.1232e-17 +          0i            0 +          0i
            0 + 4.8986e-16i   1.2246e-16 +          0i            0 +          0i
  -1.7764e-15 + 1.1022e-15i   1.8370e-16 + 4.4409e-16i            0 +          0i


Anonymous

 

(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 dasergatskov (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  •  

    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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-01-10 nrjank Operating SystemGNU/Linux Any
    2025-01-10 nrjank Severity3 - Normal 2 - Minor
        Item GroupIncorrect Result Inaccurate Result
        StatusNone Confirmed
        SummaryElement power operator causes numerical error but only if broadcasting vector Element power operator introduces numerical error when broadcasting

    Back to the top

    Powered by Savane 3.14-708e.
    Corresponding source code