octave-maintainers
[Top][All Lists]
Advanced

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

NDArray and Matrix prototypes


From: Rik
Subject: NDArray and Matrix prototypes
Date: Sat, 23 Jun 2012 12:31:49 -0700

6/23/12

John,

I've come across what looks like some unnecessary code in some of the
special functions.  The code for betainc is probably the easiest to show
off what is going on.  In lo-specfun.h there are multiple ways of calling
the function.

extern OCTAVE_API double betainc (double x, double a, double b);
extern OCTAVE_API Matrix betainc (double x, double a, const Matrix& b);
extern OCTAVE_API Matrix betainc (double x, const Matrix& a, double b);
extern OCTAVE_API Matrix betainc (double x, const Matrix& a, const Matrix& b);

extern OCTAVE_API NDArray betainc (double x, double a, const NDArray& b);
extern OCTAVE_API NDArray betainc (double x, const NDArray& a, double b);
extern OCTAVE_API NDArray betainc (double x, const NDArray& a, const
NDArray& b);

extern OCTAVE_API Matrix betainc (const Matrix& x, double a, double b);
extern OCTAVE_API Matrix betainc (const Matrix& x, double a, const Matrix& b);
extern OCTAVE_API Matrix betainc (const Matrix& x, const Matrix& a, double b);
extern OCTAVE_API Matrix betainc (const Matrix& x, const Matrix& a, const
Matrix& b);

extern OCTAVE_API NDArray betainc (const NDArray& x, double a, double b);
extern OCTAVE_API NDArray betainc (const NDArray& x, double a, const
NDArray& b);
extern OCTAVE_API NDArray betainc (const NDArray& x, const NDArray& a,
double b);
extern OCTAVE_API NDArray betainc (const NDArray& x, const NDArray& a,
const NDArray& b);

In reality, there is only an actual algorithm for the function which takes
3 double values and returns a double value.  The others merely loop across
rows and columns (for Matrix arguments) or use Fortran indexing (for
NDArrays) and call the betainc routine on each element of the array.

My question is whether it is really necessary to support both Matrix and
NDArray calling forms.  If I knew the class hierarchy I might be able to
tell this.  As it is, I just ran the experiment.  I commented out all the
Matrix code forms in both lo-specfun.h and lo-specfun.cc, re-compiled, and
then ran tests on 2-D arrays and everything worked correctly.  In fact it
was even slightly faster, although not enough to be statistically significant.

--Rik



reply via email to

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