Skip to content

Commit 59f2b1a

Browse files
committed
Add vecdim, nanflag, and comparison method support to core data functions
This patch adds support for vecdim, nanflag, comparison method and direction input arguments to the following functions: min : add support for vecdim and "all", nanflag, and 'ComparisonMethod' paired argument with options "real", "abs", and "auto". max : add support for vecdim and "all", nanflag, and 'ComparisonMethod' paired argument with options "real", "abs", and "auto". cummin : add support for vecdim and "all", nanflag, direction, and 'ComparisonMethod' paired argument with options "real", "abs", and "auto". cummax : add support for vecdim and "all", nanflag, direction, and 'ComparisonMethod' paired argument with options "real", "abs", and "auto". * max.cc (get_dim_vecdim_all): New function for parsing dim, vecdim, and "all" arguments. * max.cc (do_minmax_red_op): New template functions. * max.cc (do_cumminmax_red_op): New template functions. * max.cc (Fmin, Fmax, Fcummin, Fcummax): Rewrite functions. Update documentation. Add BIST tests. This patch also improves the efficiency of the 'nanflag' implementation and fixes certain behavior in sparse matrices to the following functions: 'cumsum', 'cumprod', 'prod', 'sum', and 'sumsq'. * data.cc (Fcumsum, Fcumprod, Fprod, Fsum, Fsumsq): Rewrite functions. * CSparse.cc (cumsum, cumprod, prod, sum, sumsq): Rewrite functions. * dSparse.cc (cumsum, cumprod, prod, sum, sumsq): Rewrite functions. Add new templated functions to support the extended functionality to the following files: * mx-inlines.cc (mx_inline_xmin): Add inline functions to support nanflag and comparison methods. * mx-inlines.cc (mx_inline_xmax): Add inline functions to support nanflag and comparison methods. * mx-inlines.cc (mx_inline_min): Added support for nanflag and comparison methods in templated functions * mx-inlines.cc (mx_inline_max): Added support for nanflag and comparison methods in templated functions * mx-inlines.cc (mx_inline_cmin): Specialized templated functions for complex arrays. * mx-inlines.cc (mx_inline_cmax): Specialized templated functions for complex arrays. * mx-inlines.cc (mx_inline_chmin): Specialized templated functions for character arrays. * mx-inlines.cc (mx_inline_chmax): Specialized templated functions for character arrays. * mx-inlines.cc (mx_inline_cummin): Added support for nanflag and comparison methods in templated functions * mx-inlines.cc (mx_inline_cummax): Added support for nanflag and comparison methods in templated functions * mx-inlines.cc (mx_inline_ccummin): Specialized templated functions for complex arrays. * mx-inlines.cc (mx_inline_ccummax): Specialized templated functions for complex arrays. * mx-inlines.cc (do_mx_minmax_op): Add inline functions to support new functions. * mx-inlines.cc (do_mx_cumminmax_op): Add inline functions to support new functions. * mx-op-decl.h : Add function declarations for min/max inline functions to support nanflag and comparison methods. * mx-op-defs.h : Update MINMAX function declarations for min/max inline functions to support nanflag and comparison methods. * Sparse-op-defs.h : Change MACRO functions to add support for 'nanflag' and fix computations for 'cumprod', 'cumsum', 'prod', 'sum', and 'sumsq' methods. Add new templated methods to support binary min/max operations to the following files: * bsxfun-defs.cc (do_bsxfun1_op, do_bsxfun2_op): New methods to support nanflag and comparison methods. * bsxfun-defs.cc (do_bsxfun1_op, do_bsxfun2_op): New method declarations. * mappers.h: (min, max): New templated functions to support nanflag and comparison methods for binary min/max operations. Add new templated methods and update existing methods to support binary min/max operations to the following files: * chNDArray.cc (min, max): Update methods to use specialized mx-inline functions * CMatrix.cc (flip): New method. * CMatrix.h (flip): New method declaration. * CSparse.cc (min, max): Add support for 'nanflag' and comparison method. * CSparse.h (min, max): Update method declarations. * dMatrix.cc (flip): New method. * dMatrix.h (flip): New method declaration. * dNDArray.cc (flip): New method. * dNDArray.h (flip): New method declaration. * dSparse.cc (min, max): Add support for 'nanflag' and comparison method. * dSparse.h (min, max): Update method declarations. * fCNDArray.cc (flip, dsumsq): New methods. * fCNDArray.h (flip, dsumsq): New method declarations. * fMatrix.cc (flip): New method. * fMatrix.h (flip): New method declaration. * fNDArray.cc (flip, dsumsq): New methods. * fNDArray.h (flip, dsumsq): New method declarations. * intNDArray.cc (sumsq, flip, cumprod): New methods. * intNDArray.h (sumsq, flip, cumprod): New method declarations.
1 parent 91e497e commit 59f2b1a

33 files changed

+6797
-2259
lines changed

libinterp/corefcn/data.cc

Lines changed: 454 additions & 803 deletions
Large diffs are not rendered by default.

libinterp/corefcn/max.cc

Lines changed: 1120 additions & 244 deletions
Large diffs are not rendered by default.

liboctave/array/CMatrix.cc

Lines changed: 126 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,33 +2792,39 @@ ComplexMatrix::any (int dim) const
27922792
}
27932793

27942794
ComplexMatrix
2795-
ComplexMatrix::cumprod (int dim) const
2795+
ComplexMatrix::flip (int dim) const
27962796
{
2797-
return ComplexNDArray::cumprod (dim);
2797+
return ComplexNDArray::flip (dim);
27982798
}
27992799

28002800
ComplexMatrix
2801-
ComplexMatrix::cumsum (int dim) const
2801+
ComplexMatrix::cumprod (int dim, bool nanflag) const
28022802
{
2803-
return ComplexNDArray::cumsum (dim);
2803+
return ComplexNDArray::cumprod (dim, nanflag);
28042804
}
28052805

28062806
ComplexMatrix
2807-
ComplexMatrix::prod (int dim) const
2807+
ComplexMatrix::cumsum (int dim, bool nanflag) const
28082808
{
2809-
return ComplexNDArray::prod (dim);
2809+
return ComplexNDArray::cumsum (dim, nanflag);
28102810
}
28112811

28122812
ComplexMatrix
2813-
ComplexMatrix::sum (int dim) const
2813+
ComplexMatrix::prod (int dim, bool nanflag) const
28142814
{
2815-
return ComplexNDArray::sum (dim);
2815+
return ComplexNDArray::prod (dim, nanflag);
28162816
}
28172817

28182818
ComplexMatrix
2819-
ComplexMatrix::sumsq (int dim) const
2819+
ComplexMatrix::sum (int dim, bool nanflag) const
28202820
{
2821-
return ComplexNDArray::sumsq (dim);
2821+
return ComplexNDArray::sum (dim, nanflag);
2822+
}
2823+
2824+
ComplexMatrix
2825+
ComplexMatrix::sumsq (int dim, bool nanflag) const
2826+
{
2827+
return ComplexNDArray::sumsq (dim, nanflag);
28222828
}
28232829

28242830
Matrix
@@ -3480,6 +3486,22 @@ operator * (const ComplexMatrix& a, const ComplexMatrix& b)
34803486

34813487
ComplexMatrix
34823488
min (const Complex& c, const ComplexMatrix& m)
3489+
{
3490+
const bool nanflag = true;
3491+
const bool realabs = false;
3492+
return min (c, m, nanflag, realabs);
3493+
}
3494+
3495+
ComplexMatrix
3496+
min (const Complex& c, const ComplexMatrix& m, const bool nanflag)
3497+
{
3498+
const bool realabs = false;
3499+
return min (c, m, nanflag, realabs);
3500+
}
3501+
3502+
ComplexMatrix
3503+
min (const Complex& c, const ComplexMatrix& m,
3504+
const bool nanflag, const bool realabs)
34833505
{
34843506
octave_idx_type nr = m.rows ();
34853507
octave_idx_type nc = m.columns ();
@@ -3492,7 +3514,7 @@ min (const Complex& c, const ComplexMatrix& m)
34923514
for (octave_idx_type i = 0; i < nr; i++)
34933515
{
34943516
octave_quit ();
3495-
result(i, j) = octave::math::min (c, m(i, j));
3517+
result(i, j) = octave::math::min (c, m(i, j), nanflag, realabs);
34963518
}
34973519

34983520
return result;
@@ -3501,11 +3523,43 @@ min (const Complex& c, const ComplexMatrix& m)
35013523
ComplexMatrix
35023524
min (const ComplexMatrix& m, const Complex& c)
35033525
{
3504-
return min (c, m);
3526+
const bool nanflag = true;
3527+
const bool realabs = false;
3528+
return min (c, m, nanflag, realabs);
3529+
}
3530+
3531+
ComplexMatrix
3532+
min (const ComplexMatrix& m, const Complex& c, const bool nanflag)
3533+
{
3534+
const bool realabs = false;
3535+
return min (c, m, nanflag, realabs);
3536+
}
3537+
3538+
ComplexMatrix
3539+
min (const ComplexMatrix& m, const Complex& c,
3540+
const bool nanflag, const bool realabs)
3541+
{
3542+
return min (c, m, nanflag, realabs);
35053543
}
35063544

35073545
ComplexMatrix
35083546
min (const ComplexMatrix& a, const ComplexMatrix& b)
3547+
{
3548+
const bool nanflag = true;
3549+
const bool realabs = false;
3550+
return min (a, b, nanflag, realabs);
3551+
}
3552+
3553+
ComplexMatrix
3554+
min (const ComplexMatrix& a, const ComplexMatrix& b, const bool nanflag)
3555+
{
3556+
const bool realabs = false;
3557+
return min (a, b, nanflag, realabs);
3558+
}
3559+
3560+
ComplexMatrix
3561+
min (const ComplexMatrix& a, const ComplexMatrix& b,
3562+
const bool nanflag, const bool realabs)
35093563
{
35103564
octave_idx_type nr = a.rows ();
35113565
octave_idx_type nc = a.columns ();
@@ -3519,39 +3573,33 @@ min (const ComplexMatrix& a, const ComplexMatrix& b)
35193573
ComplexMatrix result (nr, nc);
35203574

35213575
for (octave_idx_type j = 0; j < nc; j++)
3522-
{
3523-
bool columns_are_real_only = true;
3524-
for (octave_idx_type i = 0; i < nr; i++)
3525-
{
3526-
octave_quit ();
3527-
if (std::imag (a(i, j)) != 0.0 || std::imag (b(i, j)) != 0.0)
3528-
{
3529-
columns_are_real_only = false;
3530-
break;
3531-
}
3532-
}
3533-
3534-
if (columns_are_real_only)
3535-
{
3536-
for (octave_idx_type i = 0; i < nr; i++)
3537-
result(i, j) = octave::math::min (std::real (a(i, j)),
3538-
std::real (b(i, j)));
3539-
}
3540-
else
3541-
{
3542-
for (octave_idx_type i = 0; i < nr; i++)
3543-
{
3544-
octave_quit ();
3545-
result(i, j) = octave::math::min (a(i, j), b(i, j));
3546-
}
3547-
}
3548-
}
3576+
for (octave_idx_type i = 0; i < nr; i++)
3577+
{
3578+
octave_quit ();
3579+
result(i, j) = octave::math::min (a(i, j), b(i, j), nanflag, realabs);
3580+
}
35493581

35503582
return result;
35513583
}
35523584

35533585
ComplexMatrix
35543586
max (const Complex& c, const ComplexMatrix& m)
3587+
{
3588+
const bool nanflag = true;
3589+
const bool realabs = false;
3590+
return max (c, m, nanflag, realabs);
3591+
}
3592+
3593+
ComplexMatrix
3594+
max (const Complex& c, const ComplexMatrix& m, const bool nanflag)
3595+
{
3596+
const bool realabs = false;
3597+
return max (c, m, nanflag, realabs);
3598+
}
3599+
3600+
ComplexMatrix
3601+
max (const Complex& c, const ComplexMatrix& m,
3602+
const bool nanflag, const bool realabs)
35553603
{
35563604
octave_idx_type nr = m.rows ();
35573605
octave_idx_type nc = m.columns ();
@@ -3564,7 +3612,7 @@ max (const Complex& c, const ComplexMatrix& m)
35643612
for (octave_idx_type i = 0; i < nr; i++)
35653613
{
35663614
octave_quit ();
3567-
result(i, j) = octave::math::max (c, m(i, j));
3615+
result(i, j) = octave::math::max (c, m(i, j), nanflag, realabs);
35683616
}
35693617

35703618
return result;
@@ -3573,11 +3621,43 @@ max (const Complex& c, const ComplexMatrix& m)
35733621
ComplexMatrix
35743622
max (const ComplexMatrix& m, const Complex& c)
35753623
{
3576-
return max (c, m);
3624+
const bool nanflag = true;
3625+
const bool realabs = false;
3626+
return max (c, m, nanflag, realabs);
3627+
}
3628+
3629+
ComplexMatrix
3630+
max (const ComplexMatrix& m, const Complex& c, const bool nanflag)
3631+
{
3632+
const bool realabs = false;
3633+
return max (c, m, nanflag, realabs);
3634+
}
3635+
3636+
ComplexMatrix
3637+
max (const ComplexMatrix& m, const Complex& c,
3638+
const bool nanflag, const bool realabs)
3639+
{
3640+
return max (c, m, nanflag, realabs);
35773641
}
35783642

35793643
ComplexMatrix
35803644
max (const ComplexMatrix& a, const ComplexMatrix& b)
3645+
{
3646+
const bool nanflag = true;
3647+
const bool realabs = false;
3648+
return max (a, b, nanflag, realabs);
3649+
}
3650+
3651+
ComplexMatrix
3652+
max (const ComplexMatrix& a, const ComplexMatrix& b, const bool nanflag)
3653+
{
3654+
const bool realabs = false;
3655+
return max (a, b, nanflag, realabs);
3656+
}
3657+
3658+
ComplexMatrix
3659+
max (const ComplexMatrix& a, const ComplexMatrix& b,
3660+
const bool nanflag, const bool realabs)
35813661
{
35823662
octave_idx_type nr = a.rows ();
35833663
octave_idx_type nc = a.columns ();
@@ -3591,37 +3671,11 @@ max (const ComplexMatrix& a, const ComplexMatrix& b)
35913671
ComplexMatrix result (nr, nc);
35923672

35933673
for (octave_idx_type j = 0; j < nc; j++)
3594-
{
3595-
bool columns_are_real_only = true;
3596-
for (octave_idx_type i = 0; i < nr; i++)
3597-
{
3598-
octave_quit ();
3599-
if (std::imag (a(i, j)) != 0.0 || std::imag (b(i, j)) != 0.0)
3600-
{
3601-
columns_are_real_only = false;
3602-
break;
3603-
}
3604-
}
3605-
3606-
// FIXME: is it so much faster?
3607-
if (columns_are_real_only)
3608-
{
3609-
for (octave_idx_type i = 0; i < nr; i++)
3610-
{
3611-
octave_quit ();
3612-
result(i, j) = octave::math::max (std::real (a(i, j)),
3613-
std::real (b(i, j)));
3614-
}
3615-
}
3616-
else
3617-
{
3618-
for (octave_idx_type i = 0; i < nr; i++)
3619-
{
3620-
octave_quit ();
3621-
result(i, j) = octave::math::max (a(i, j), b(i, j));
3622-
}
3623-
}
3624-
}
3674+
for (octave_idx_type i = 0; i < nr; i++)
3675+
{
3676+
octave_quit ();
3677+
result(i, j) = octave::math::max (a(i, j), b(i, j), nanflag, realabs);
3678+
}
36253679

36263680
return result;
36273681
}

liboctave/array/CMatrix.h

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,12 @@ class OCTAVE_API ComplexMatrix : public ComplexNDArray
411411
OCTAVE_API boolMatrix all (int dim = -1) const;
412412
OCTAVE_API boolMatrix any (int dim = -1) const;
413413

414-
OCTAVE_API ComplexMatrix cumprod (int dim = -1) const;
415-
OCTAVE_API ComplexMatrix cumsum (int dim = -1) const;
416-
OCTAVE_API ComplexMatrix prod (int dim = -1) const;
417-
OCTAVE_API ComplexMatrix sum (int dim = -1) const;
418-
OCTAVE_API ComplexMatrix sumsq (int dim = -1) const;
414+
OCTAVE_API ComplexMatrix flip (int dim = -1) const;
415+
OCTAVE_API ComplexMatrix cumprod (int dim = -1, bool nanflag = false) const;
416+
OCTAVE_API ComplexMatrix cumsum (int dim = -1, bool nanflag = false) const;
417+
OCTAVE_API ComplexMatrix prod (int dim = -1, bool nanflag = false) const;
418+
OCTAVE_API ComplexMatrix sum (int dim = -1, bool nanflag = false) const;
419+
OCTAVE_API ComplexMatrix sumsq (int dim = -1, bool nanflag = false) const;
419420
OCTAVE_API Matrix abs () const;
420421

421422
OCTAVE_API ComplexMatrix diag (octave_idx_type k = 0) const;
@@ -478,14 +479,40 @@ extern OCTAVE_API ComplexMatrix operator * (const ComplexMatrix&,
478479
const ComplexMatrix&);
479480

480481
extern OCTAVE_API ComplexMatrix min (const Complex& c, const ComplexMatrix& m);
482+
extern OCTAVE_API ComplexMatrix min (const Complex& c, const ComplexMatrix& m,
483+
const bool nanflag);
484+
extern OCTAVE_API ComplexMatrix min (const Complex& c, const ComplexMatrix& m,
485+
const bool nanflag, const bool realabs);
481486
extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& m, const Complex& c);
487+
extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& m, const Complex& c,
488+
const bool nanflag);
489+
extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& m, const Complex& c,
490+
const bool nanflag, const bool realabs);
482491
extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& a,
483492
const ComplexMatrix& b);
493+
extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& a,
494+
const ComplexMatrix& b, const bool nanflag);
495+
extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& a,
496+
const ComplexMatrix& b,
497+
const bool nanflag, const bool realabs);
484498

485499
extern OCTAVE_API ComplexMatrix max (const Complex& c, const ComplexMatrix& m);
500+
extern OCTAVE_API ComplexMatrix max (const Complex& c, const ComplexMatrix& m,
501+
const bool nanflag);
502+
extern OCTAVE_API ComplexMatrix max (const Complex& c, const ComplexMatrix& m,
503+
const bool nanflag, const bool realabs);
486504
extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& m, const Complex& c);
505+
extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& m, const Complex& c,
506+
const bool nanflag);
507+
extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& m, const Complex& c,
508+
const bool nanflag, const bool realabs);
487509
extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& a,
488510
const ComplexMatrix& b);
511+
extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& a,
512+
const ComplexMatrix& b, const bool nanflag);
513+
extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& a,
514+
const ComplexMatrix& b,
515+
const bool nanflag, const bool realabs);
489516

490517
extern OCTAVE_API ComplexMatrix linspace (const ComplexColumnVector& x1,
491518
const ComplexColumnVector& x2,

0 commit comments

Comments
 (0)