Re: Sharing code between largely identical functions



In article <443047FA.30006@xxxxxxxxx>,
spamtrap@xxxxxxxxxx says...

[ ... ]

In case anyone is interested, these functions are simple
(so called BLAS) functions from linear algebra.
One pair is: norm and norm squared of a vector where the
only difference is a square root at the end in the more
common norm case which is bypassed by the other one. The
first function might be considered redundant since the
same result could be achieved by following the call to
the second function with a square root call outside the
function; however, I do not want to upset the much more
common case for the benefit of the less common one, which
is good design in my opinion.

The obvious answer in this case would be to just write it
as two functions. The first function implements the non-
normalized version. The second calls the first, then does
the square root.

At least to me, it seems pretty obvious that this is
cleaner. Given the work CPU designers have put into
optimizing function calls, on any reasonably recent CPU,
it's almost certain to be faster as well.

The other pair is one that renders a vector unit norm but
discards the norm where its companion optionally returns
the (square of the) original norm "by value".
The norm, conforming to __cdecl, is returned in FPU ST(0),
so the only difference is that the function which does not
return the norm pops the FPU stack whereas the other does
not (its caller will do that somewhere after using or
copying the value).

This sounds like it could (and almost certainly should)
be implemented essentially the same way as above -- the
version that does the pop becomes almost completely
trivial, just calling the other one and then doing a fpop
before returning.

--
Later,
Jerry.

The universe is a figment of its own imagination.

.



Relevant Pages

  • Re: Minimizing matrix norm
    ... OFF-DIAGONAL elements. ... This isn't a norm, of course, but it is still easily minimized. ... In article, Ronald Bruck ... the solutions are rational (as is the square of the Frobenius ...
    (sci.math.num-analysis)
  • Re: Diophantine question-II
    ... If alpha is a primitive cube root of unity, ... The norm of a square is the square of the norm. ... 44 months after Japan attacked Pearl Harbor, ...
    (sci.math)
  • Re: Minimizing matrix norm
    ... I also tried something else: instead of using the Frobenius ... This isn't a norm, of course, but it is still easily minimized. ... rationale was sort of a Gershgorin approach: ... the solutions are rational (as is the square of the Frobenius ...
    (sci.math.num-analysis)
  • Re: Minimizing matrix norm
    ... I also tried something else: instead of using the Frobenius ... >This isn't a norm, of course, but it is still easily minimized. ... >In article, Ronald Bruck ... the solutions are rational (as is the square of the Frobenius ...
    (sci.math.num-analysis)
  • Re: Some math, algebraic integers
    ... > algebra. ... > MUST have non-unit algebraic integer factors in common with 2. ... the case that q_1 divides 6 in the ring of algebraic integers. ... the norm of Qis computed by taking the product of all ...
    (sci.math)