octave-maintainers
[Top][All Lists]
Advanced

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

Making sort a method of Array<T>, Sparse<T> and octave_value classes


From: David Bateman
Subject: Making sort a method of Array<T>, Sparse<T> and octave_value classes
Date: Sun, 27 Jan 2008 22:39:16 +0100
User-agent: Thunderbird 2.0.0.6 (X11/20070914)

There was some discussion before 3.0 to make functions like sort,
spkron, min, max, etc members of the the octave_value classes so that
the mess of if/else statements in these DEFUN functions might be
removed. I chose to give the sort method this treatment first as it
seemed to me to be probably the hardest to do and so is a good test of
whether it is worth the effort, and yes its taken me a while to get it
right.

Find attached a patch that moves the sort function to be methods of
Array<T> and Sparse<T> and then significantly simplifies the Fsort
function. In fact it moves Fsort to data.cc and DLD-FUNCTIONS/sort.cc
should also be removed.

In any case, this patch is for discussion and to see whether its a good
idea to do the same with other functions and if so which ones?

Regards
D.

Attachment: patch10.bz2
Description: BZip2 compressed data

2008-01-25  David Bateman  <address@hidden>

        * oct-sort.cc (IFLT): Allow IFLT macro to be overridden.
        * oct-sort.h (enum sortmode): Type of sort to perform.
        (vec_index): Simple class to aid in indexed sorts.
        
        * Array.h ( Array<T> sort (octave_idx_type, sortmode) const,
        Array<T> sort (Array<octave_idx_type> &, octave_idx_type,
        sortmode) const): Array sorting methods.
        (INSTANTIATE_ARRAY_SORT, NO_INSTANTIATE_ARRAY_SORT): Macros to
        instantiate the array sorting methods.
        * Array.cc (ascending_compare, descending_compare): New template
        functions for generic sort comparison.
        ( Array<T> Array<T>::sort (octave_idx_type, sortmode) const,
        Array<T> Array<T>::sort (Array<octave_idx_type> &, octave_idx_type,
        sortmode) const): Array sorting functions based of octave_sort
        class.
        * Array-C.cc: Instantiate the complex array sort methods. 
        (IFLT): New macro to override the one in the
        octave_sort class to avoid need for Complex < and > operators.
        (static double xabs (const Complex&)): Complex abs function
        avoiding std::abs(Inf) returning NaN with some compilers.
        (ascending_compare, descending compare): override template
        functions for complex comparison.
        * Array-d.cc: Instantiate the double array sort methods. 
        (Array<double> Array<double>::sort (octave_idx_type, 
        sortmode) const, Array<double> Array<double>::sort 
        (Array<octave_idx_type> &, octave_idx_type, sortmode) const): 
        Array sorting functions based of octave_sort using uint64 sorting
        on IEE754 doubles, for speed and correct sorting of Inf and NaN.
        (ascending_compare, descending compare): override template
        functions for double and uint64 comparison.
        * Array-b.cc, Array-ch.cc, Array-i.cc, Array-s.cc, Array-str.cc: 
        Instantiate the array sort methods.
        * Array-idx-vec.cc: Null instantiation of array sort methods.
        * Array2.h, Array3.h, ArrayN.h (sort): 2, 3 and N-dimensional
        versions of the sort methods based on Array<T>::sort.

        * CSparse.cc, dSparse.cc: Remove inclusion of octa-sort.h.
        * Sparse.h ( Sparse<T> sort (octave_idx_type, sortmode) const,
        Sparse<T> sort (Array<octave_idx_type> &, octave_idx_type,
        sortmode) const): Sparse sorting methods.
        (INSTANTIATE_ARRAY_SORT): Macro to instantiate the sparse sorting 
        methods.
        * Sparse.cc: replace sort with lsort throughout to avoid shadowing
        of new sort method.
        (sparse_ascending_compare, sparse_descending_compare): New template
        functions for generic sort comparison.
        ( Sparse<T> Sparse<T>::sort (octave_idx_type, sortmode) const,
        Sparse<T> Sparse<T>::sort (Sparse<octave_idx_type> &, octave_idx_type,
        sortmode) const): Sparse sorting functions based of octave_sort
        class.
        * Sparse-C.cc: Instantiate the complex sparse sort methods. 
        (IFLT): New macro to override the one in the
        octave_sort class to avoid need for Complex < and > operators.
        (static double xabs (const Complex&)): Complex abs function
        avoiding std::abs(Inf) returning NaN with some compilers.
        (sparse_ascending_compare, sparse_descending compare): override
        template functions for complex comparison.
        * Sparse-d.cc: Instantiate the cdouble sparse sort methods. 
        (sparse_ascending_compare, sparse_descending compare): override
        template functions for double comparison.
        * Array-b.cc: Instantiate the sparse sort methods.

2008-01-25  David Bateman  <address@hidden>

        * ov.cc (octave_value::octave_value (const ArrayN<bool>&),
        octave_value::octave_value (const Sparse<bool>&, const MatrixType &),
        octave_value::octave_value (const ArrayN<std::streamoff>&)): New 
        constructors.
        * ov.h: (octave_value (const ArrayN<bool>&),
        octave_value (const Sparse<bool>&, const MatrixType &),
        octave_value (const ArrayN<std::streamoff>&)): Declare them.
        (octave_value sort (octave_idx_type, sortmode) const, octave_value
        sort (Array<octave_idx_type> &, octave_idx_type, sortmode) const):
        octave_value sort method.
        
        
        * ov-base.cc (sort): Base versions of teh octave_value sort methods.
        * ov-base.h (sort): Declare the octave_value sort methods
        * ov-base-scalar.h (sort): Simple sort methods for scalars.
        * ov-base-mat.h, ov-base-sparse.h (sort): Sort methods calling
        underlying array or sparse sort methods.
        * ov-str-mat.h (sort): String specific sort methods.
        
        * TEMPLATE-INST/Array-tc.cc: Instantiate the array sort methods.
        * ov-streamoff.h (sort): Sort versions returning and error.
        * oct-stream.cc, ov-typeinfo.cc, Array-os.cc: Null instantiation
        of array sort methods.
        
        * Makefile.in (DLD_XSRC): Remove sort.cc
        * DLD-FUNCTIONS/sort.cc: Remove
        * data.cc (Fdata): New function using octave_value sort methods
        for the sorting. Add tests.

reply via email to

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