octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #61968] pow2 with two arguments is not Matlab


From: Kai Torben Ohlhus
Subject: [Octave-bug-tracker] [bug #61968] pow2 with two arguments is not Matlab compatible
Date: Fri, 4 Feb 2022 04:26:21 -0500 (EST)

Update of bug #61968 (project octave):

                  Status:             In Progress => Patch Submitted        

    _______________________________________________________

Follow-up Comment #11:

Thanks for the input.  I overhauled the patch (file #52801) to only include a
single file in libinterp/corefcn.  I think this pattern is much better to keep
the implementation at a single place, than spread about all libinterp.

This way I can also use this code in my own project as single file 🙂

Regarding comment #8.  I also find the current implementation of pow2() too
simple to be true.  If "2.^x" was really required, I find this statement more
expressive than pow2(x).  One does not need an extra function for this.

Unfortunately, pow2() does not do what Matlab intended it to do.  Further it
is inefficient for sparse input, as "2.^e" fills-up merciless to a dense NxN
matrix, even though the final "f .* 2 .^ e" is very sparse 😓


>> e = rand(500); tic; y = pow3(e); toc, tic; y = pow2(e); tocElapsed time is
0.021579 seconds.
Elapsed time is 0.00504899 seconds.
>> N = 1e3; f = sprand (N, N, 1/N); e = sparse(N,N); tic; y = pow3(f,e); toc,
tic; y = pow2(f,e); toc
Elapsed time is 0.0445991 seconds.
Elapsed time is 0.000132799 seconds.


A final (a little exotic) issue I care about is of numerical stability nature
of exp2(x) vs. pow(2,x): https://godbolt.org/z/zs3s9dqfs

Again, the great advantage of the patch is it finally makes pow2() do what
Matlab is doing for the two argument call.

If no further objections, I would push the patch next week.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?61968>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]