# HG changeset patch # User Kai T. Ohlhus # Date 1442951124 -7200 # Node ID 2aa4fb60ae77fa7e918152258bc5275de2dfa9d4 # Parent dd327c0909b08bf4c934ee3ff9d34b60eb66c9ff MSparse code simplification by macro removal without reduction of functionality. * boolSparse.h: Replace header inclusion. * CSparse.h: Remove merged header inclusion. * dSparse.h: Remove merged header inclusion. * module.mk: Remove merged header from build system. * MSparse-C.cc: Remove unnecessary header inclusion. * MSparse-d.cc: Remove unnecessary header inclusion. * MSparse.cc: Moved header inclusions to MSparse.h. * MSparse.h: New header files and macros from MSparse-defs.h. * MSparse-defs.h: Merged macro expanded code to MSparse.h. diff -r dd327c0909b0 -r 2aa4fb60ae77 liboctave/array/CSparse.h --- a/liboctave/array/CSparse.h Tue Sep 22 21:06:01 2015 +0200 +++ b/liboctave/array/CSparse.h Tue Sep 22 21:45:24 2015 +0200 @@ -34,7 +34,6 @@ #include "DET.h" #include "MSparse.h" -#include "MSparse-defs.h" #include "Sparse-op-decls.h" diff -r dd327c0909b0 -r 2aa4fb60ae77 liboctave/array/MSparse-C.cc --- a/liboctave/array/MSparse-C.cc Tue Sep 22 21:06:01 2015 +0200 +++ b/liboctave/array/MSparse-C.cc Tue Sep 22 21:45:24 2015 +0200 @@ -28,7 +28,6 @@ #include "oct-cmplx.h" #include "MSparse.h" -#include "MSparse.cc" template class OCTAVE_API MSparse; diff -r dd327c0909b0 -r 2aa4fb60ae77 liboctave/array/MSparse-d.cc --- a/liboctave/array/MSparse-d.cc Tue Sep 22 21:06:01 2015 +0200 +++ b/liboctave/array/MSparse-d.cc Tue Sep 22 21:45:24 2015 +0200 @@ -26,7 +26,6 @@ #endif #include "MSparse.h" -#include "MSparse.cc" template class OCTAVE_API MSparse; diff -r dd327c0909b0 -r 2aa4fb60ae77 liboctave/array/MSparse-defs.h --- a/liboctave/array/MSparse-defs.h Tue Sep 22 21:06:01 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,213 +0,0 @@ -/* - -Copyright (C) 2004-2015 David Bateman -Copyright (C) 1998-2004 Andy Adler - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 3 of the License, or (at your -option) any later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -. - -*/ - -#if !defined (octave_MSparse_defs_h) -#define octave_MSparse_defs_h 1 - -// Nothing like a little CPP abuse to brighten everyone's day. - -// A macro that can be used to declare and instantiate OP= operators. -#define SPARSE_OP_ASSIGN_DECL(A_T, E_T, OP, PFX, API, LTGT, RHS_T) \ - PFX API A_T& \ - operator OP LTGT (A_T&, const RHS_T&) - -// All the OP= operators that we care about. -#define SPARSE_OP_ASSIGN_DECLS(A_T, E_T, PFX, API, LTGT, RHS_T) \ - SPARSE_OP_ASSIGN_DECL (A_T, E_T, +=, PFX, API, LTGT, RHS_T); \ - SPARSE_OP_ASSIGN_DECL (A_T, E_T, -=, PFX, API, LTGT, RHS_T); - -// Generate forward declarations for OP= operators. -#define SPARSE_OP_ASSIGN_FWD_DECLS(A_T, RHS_T, API) \ - SPARSE_OP_ASSIGN_DECLS (A_T, T, template , API, , RHS_T) - -// Generate friend declarations for the OP= operators. -#define SPARSE_OP_ASSIGN_FRIENDS(A_T, RHS_T, API) \ - SPARSE_OP_ASSIGN_DECLS (A_T, T, friend, API, <>, RHS_T) - -// Instantiate the OP= operators. -#define SPARSE_OP_ASSIGN_DEFS(A_T, E_T, RHS_T, API) \ - SPARSE_OP_ASSIGN_DECLS (A_T, E_T, template, API, , RHS_T) - -// A function that can be used to forward OP= operations from derived -// classes back to us. -#define SPARSE_OP_ASSIGN_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \ - inline R \ - F (X_T& x, const Y_T& y) \ - { \ - return R (F (C_X (x), C_Y (y))); \ - } - -// All the OP= operators that we care about forwarding. -#define SPARSE_OP_ASSIGN_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \ - SPARSE_OP_ASSIGN_FWD_FCN (R, operator +=, T, C_X, X_T, C_Y, Y_T) \ - SPARSE_OP_ASSIGN_FWD_FCN (R, operator -=, T, C_X, X_T, C_Y, Y_T) - -// A macro that can be used to declare and instantiate unary operators. -#define SPARSE_UNOP(A_T, E_T, F, PFX, API, LTGT) \ - PFX API A_T \ - F LTGT (const A_T&) - -// All the unary operators that we care about. -#define SPARSE_UNOP_DECLS(A_T, E_T, PFX, API, LTGT) \ - SPARSE_UNOP (A_T, E_T, operator +, PFX, API, LTGT); \ - SPARSE_UNOP (A_T, E_T, operator -, PFX, API, LTGT); - -// Generate forward declarations for unary operators. -#define SPARSE_UNOP_FWD_DECLS(A_T, API) \ - SPARSE_UNOP_DECLS (A_T, T, template , API, ) - -// Generate friend declarations for the unary operators. -#define SPARSE_UNOP_FRIENDS(A_T, API) \ - SPARSE_UNOP_DECLS (A_T, T, friend, API, <>) - -// Instantiate the unary operators. -#define SPARSE_UNOP_DEFS(A_T, E_T, API) \ - SPARSE_UNOP_DECLS (A_T, E_T, template, API, ) - -// A function that can be used to forward unary operations from derived -// classes back to us. -#define SPARSE_UNOP_FWD_FCN(R, F, T, C_X, X_T) \ - inline R \ - F (const X_T& x) \ - { \ - return R (F (C_X (x))); \ - } - -// All the unary operators that we care about forwarding. -#define SPARSE_UNOP_FWD_DEFS(R, T, C_X, X_T) \ - SPARSE_UNOP_FWD_FCN (R, operator +, T, C_X, X_T) \ - SPARSE_UNOP_FWD_FCN (R, operator -, T, C_X, X_T) - -// A macro that can be used to declare and instantiate binary operators. -#define SPARSE_BINOP_DECL(A_T, E_T, F, PFX, API, LTGT, X_T, Y_T) \ - PFX API A_T \ - F LTGT (const X_T&, const Y_T&) - -// All the binary operators that we care about. We have two -// sets of macros since the MArray OP MArray operations use functions -// (product and quotient) instead of operators (*, /). -#define SPARSE_BINOP_DECLS(A_T, F_T, E_T, PFX, API, LTGT, X_T, Y_T) \ - SPARSE_BINOP_DECL (F_T, E_T, operator +, PFX, API, LTGT, X_T, Y_T); \ - SPARSE_BINOP_DECL (F_T, E_T, operator -, PFX, API, LTGT, X_T, Y_T); \ - SPARSE_BINOP_DECL (A_T, E_T, operator *, PFX, API, LTGT, X_T, Y_T); \ - SPARSE_BINOP_DECL (A_T, E_T, operator /, PFX, API, LTGT, X_T, Y_T); - -#define SPARSE_AA_BINOP_DECLS(A_T, E_T, PFX, API, LTGT) \ - SPARSE_BINOP_DECL (A_T, E_T, operator +, PFX, API, LTGT, A_T, A_T); \ - SPARSE_BINOP_DECL (A_T, E_T, operator -, PFX, API, LTGT, A_T, A_T); \ - SPARSE_BINOP_DECL (A_T, E_T, quotient, PFX, API, LTGT, A_T, A_T); \ - SPARSE_BINOP_DECL (A_T, E_T, product, PFX, API, LTGT, A_T, A_T); - -// Generate forward declarations for binary operators. -#define SPARSE_BINOP_FWD_DECLS(A_T, F_T, API) \ - SPARSE_BINOP_DECLS (A_T, F_T, T, template , API, , A_T, T) \ - SPARSE_BINOP_DECLS (A_T, F_T, T, template , API, , T, A_T) \ - SPARSE_AA_BINOP_DECLS (A_T, T, template , API, ) - -// Generate friend declarations for the binary operators. -#define SPARSE_BINOP_FRIENDS(A_T, F_T, API) \ - SPARSE_BINOP_DECLS (A_T, F_T, T, friend, API, <>, A_T, T) \ - SPARSE_BINOP_DECLS (A_T, F_T, T, friend, API, <>, T, A_T) \ - SPARSE_AA_BINOP_DECLS (A_T, T, friend, API, <>) - -// Instantiate the binary operators. -#define SPARSE_BINOP_DEFS(A_T, F_T, E_T, API) \ - SPARSE_BINOP_DECLS (A_T, F_T, E_T, template, API, , A_T, E_T) \ - SPARSE_BINOP_DECLS (A_T, F_T, E_T, template, API, , E_T, A_T) \ - SPARSE_AA_BINOP_DECLS (A_T, E_T, template, API, ) - -// A function that can be used to forward binary operations from derived -// classes back to us. -#define SPARSE_BINOP_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \ - inline R \ - F (const X_T& x, const Y_T& y) \ - { \ - return R (F (C_X (x), C_Y (y))); \ - } - -// The binary operators that we care about forwarding. We have two -// sets of macros since the MSparse OP MSparse operations use functions -// (product and quotient) instead of operators (*, /). -#define SPARSE_BINOP_FWD_DEFS(R, F, T, C_X, X_T, C_Y, Y_T) \ - SPARSE_BINOP_FWD_FCN (F, operator +, T, C_X, X_T, C_Y, Y_T) \ - SPARSE_BINOP_FWD_FCN (F, operator -, T, C_X, X_T, C_Y, Y_T) \ - SPARSE_BINOP_FWD_FCN (R, operator *, T, C_X, X_T, C_Y, Y_T) \ - SPARSE_BINOP_FWD_FCN (R, operator /, T, C_X, X_T, C_Y, Y_T) - -#define SPARSE_AA_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \ - SPARSE_BINOP_FWD_FCN (R, operator +, T, C_X, X_T, C_Y, Y_T) \ - SPARSE_BINOP_FWD_FCN (R, operator -, T, C_X, X_T, C_Y, Y_T) \ - SPARSE_BINOP_FWD_FCN (R, product, T, C_X, X_T, C_Y, Y_T) \ - SPARSE_BINOP_FWD_FCN (R, quotient, T, C_X, X_T, C_Y, Y_T) - -// Forward declarations for the MSparse operators. -#define SPARSE_OPS_FORWARD_DECLS(A_T, F_T, API) \ - template \ - class A_T; \ - \ - /* SPARSE_OP_ASSIGN_FWD_DECLS (A_T, T) */ \ - SPARSE_OP_ASSIGN_FWD_DECLS (A_T, A_T, API) \ - SPARSE_UNOP_FWD_DECLS (A_T, API) \ - SPARSE_BINOP_FWD_DECLS (A_T, F_T, API) - -// Friend declarations for the MSparse operators. -#define SPARSE_OPS_FRIEND_DECLS(A_T, F_T, API) \ - /* SPARSE_OP_ASSIGN_FRIENDS (A_T, T) */ \ - SPARSE_OP_ASSIGN_FRIENDS (A_T, A_T, API) \ - SPARSE_UNOP_FRIENDS (A_T, API) \ - SPARSE_BINOP_FRIENDS (A_T, F_T, API) - -// The following macros are for external use. - -// Instantiate all the MSparse friends for MSparse element type T. -#define INSTANTIATE_SPARSE_FRIENDS(T, API) \ - /* SPARSE_OP_ASSIGN_DEFS (MSparse, T, T) */ \ - SPARSE_OP_ASSIGN_DEFS (MSparse, T, MSparse, API) \ - SPARSE_UNOP_DEFS (MSparse, T, API) \ - SPARSE_BINOP_DEFS (MSparse, MArray, T, API) - -// Define all the MSparse forwarding functions for return type R and -// MSparse element type T -#define SPARSE_FORWARD_DEFS(B, R, F, T) \ - /* SPARSE_OP_ASSIGN_FWD_DEFS */ \ - /* (R, T, dynamic_cast&>, R, , T) */ \ - \ - SPARSE_OP_ASSIGN_FWD_DEFS \ - (R, T, \ - dynamic_cast&>, R, dynamic_cast&>, R) \ - \ - SPARSE_UNOP_FWD_DEFS \ - (R, T, dynamic_cast&>, R) \ - \ - SPARSE_BINOP_FWD_DEFS \ - (R, F, T, dynamic_cast&>, R, , T) \ - \ - SPARSE_BINOP_FWD_DEFS \ - (R, F, T, , T, dynamic_cast&>, R) \ - \ - SPARSE_AA_BINOP_FWD_DEFS \ - (R, T, dynamic_cast&>, R, dynamic_cast&>, R) - -// Now we have all the definitions we need. - -#endif diff -r dd327c0909b0 -r 2aa4fb60ae77 liboctave/array/MSparse.cc --- a/liboctave/array/MSparse.cc Tue Sep 22 21:06:01 2015 +0200 +++ b/liboctave/array/MSparse.cc Tue Sep 22 21:45:24 2015 +0200 @@ -21,20 +21,6 @@ */ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include "quit.h" -#include "lo-error.h" -#include "MArray.h" -#include "Array-util.h" - -#include "MSparse.h" -#include "MSparse-defs.h" - // sparse array with math ops. // Element by element MSparse by MSparse ops. diff -r dd327c0909b0 -r 2aa4fb60ae77 liboctave/array/MSparse.h --- a/liboctave/array/MSparse.h Tue Sep 22 21:06:01 2015 +0200 +++ b/liboctave/array/MSparse.h Tue Sep 22 21:45:24 2015 +0200 @@ -24,18 +24,20 @@ #if !defined (octave_MSparse_h) #define octave_MSparse_h 1 -#include "MArray.h" +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include "quit.h" +#include "lo-error.h" #include "Sparse.h" +#include "MArray.h" +#include "Array-util.h" + // Two dimensional sparse array with math ops. - -// But first, some preprocessor abuse... - -#include "MSparse-defs.h" - -SPARSE_OPS_FORWARD_DECLS (MSparse, MArray, ) - template class MSparse : public Sparse @@ -119,11 +121,100 @@ MSparse map (U (&fcn) (const T&)) const { return Sparse::template map (fcn); } - - // Currently, the OPS functions don't need to be friends, but that - // may change. - - // SPARSE_OPS_FRIEND_DECLS (MSparse, MArray) }; +// Include operator templates for MSparse +#include "MSparse.cc" + +// A macro that can be used to declare and instantiate OP= operators. +#define SPARSE_OP_ASSIGN_DECL(T, OP, API) \ + template API MSparse& \ + operator OP (MSparse&, const MSparse&) + +// A macro that can be used to declare and instantiate unary operators. +#define SPARSE_UNOP_DECL(T, OP, API) \ + template API MSparse \ + operator OP (const MSparse&) + +// A macro that can be used to declare and instantiate binary operators. +#define SPARSE_BINOP_DECL(A_T, T, F, API, X_T, Y_T) \ + template API A_T \ + F (const X_T&, const Y_T&) + +// A function that can be used to forward OP= operations from derived +// classes back to us. +#define SPARSE_OP_ASSIGN_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \ + inline R \ + F (X_T& x, const Y_T& y) \ + { \ + return R (F (C_X (x), C_Y (y))); \ + } + +// A function that can be used to forward unary operations from derived +// classes back to us. +#define SPARSE_UNOP_FWD_FCN(R, F, T, C_X, X_T) \ + inline R \ + F (const X_T& x) \ + { \ + return R (F (C_X (x))); \ + } + +// A function that can be used to forward binary operations from derived +// classes back to us. +#define SPARSE_BINOP_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \ + inline R \ + F (const X_T& x, const Y_T& y) \ + { \ + return R (F (C_X (x), C_Y (y))); \ + } + +// Instantiate all the MSparse friends for MSparse element type T. +#define INSTANTIATE_SPARSE_FRIENDS(T, API) \ + SPARSE_OP_ASSIGN_DECL (T, +=, API); \ + SPARSE_OP_ASSIGN_DECL (T, -=, API); \ + SPARSE_UNOP_DECL (T, +, API); \ + SPARSE_UNOP_DECL (T, -, API); \ + SPARSE_BINOP_DECL (MArray, T, operator +, API, MSparse, T); \ + SPARSE_BINOP_DECL (MArray, T, operator -, API, MSparse, T); \ + SPARSE_BINOP_DECL (MSparse, T, operator *, API, MSparse, T); \ + SPARSE_BINOP_DECL (MSparse, T, operator /, API, MSparse, T); \ + SPARSE_BINOP_DECL (MArray, T, operator +, API, T, MSparse); \ + SPARSE_BINOP_DECL (MArray, T, operator -, API, T, MSparse); \ + SPARSE_BINOP_DECL (MSparse, T, operator *, API, T, MSparse); \ + SPARSE_BINOP_DECL (MSparse, T, operator /, API, T, MSparse); \ + SPARSE_BINOP_DECL (MSparse, T, operator +, API, MSparse, MSparse); \ + SPARSE_BINOP_DECL (MSparse, T, operator -, API, MSparse, MSparse); \ + SPARSE_BINOP_DECL (MSparse, T, quotient, API, MSparse, MSparse); \ + SPARSE_BINOP_DECL (MSparse, T, product, API, MSparse, MSparse); + +// Define all the MSparse forwarding functions for return type R and +// MSparse element type T +#define SPARSE_FORWARD_DEFS(B, R, F, T) \ + SPARSE_OP_ASSIGN_FWD_FCN \ + (R, operator +=, T, dynamic_cast&>, R, dynamic_cast&>, R) \ + SPARSE_OP_ASSIGN_FWD_FCN \ + (R, operator -=, T, dynamic_cast&>, R, dynamic_cast&>, R) \ + SPARSE_UNOP_FWD_FCN (R, operator +, T, dynamic_cast&>, R) \ + SPARSE_UNOP_FWD_FCN (R, operator -, T, dynamic_cast&>, R) \ + SPARSE_BINOP_FWD_FCN (F, operator +, T, dynamic_cast&>, R, , T) \ + SPARSE_BINOP_FWD_FCN (F, operator -, T, dynamic_cast&>, R, , T) \ + SPARSE_BINOP_FWD_FCN (R, operator *, T, dynamic_cast&>, R, , T) \ + SPARSE_BINOP_FWD_FCN (R, operator /, T, dynamic_cast&>, R, , T) \ + SPARSE_BINOP_FWD_FCN (F, operator +, T, , T, dynamic_cast&>, R) \ + SPARSE_BINOP_FWD_FCN (F, operator -, T, , T, dynamic_cast&>, R) \ + SPARSE_BINOP_FWD_FCN (R, operator *, T, , T, dynamic_cast&>, R) \ + SPARSE_BINOP_FWD_FCN (R, operator /, T, , T, dynamic_cast&>, R) \ + SPARSE_BINOP_FWD_FCN \ + (R, operator +, T, dynamic_cast&>, R, \ + dynamic_cast&>, R) \ + SPARSE_BINOP_FWD_FCN \ + (R, operator -, T, dynamic_cast&>, R, \ + dynamic_cast&>, R) \ + SPARSE_BINOP_FWD_FCN \ + (R, product, T, dynamic_cast&>, R, \ + dynamic_cast&>, R) \ + SPARSE_BINOP_FWD_FCN \ + (R, quotient, T, dynamic_cast&>, R, \ + dynamic_cast&>, R) + #endif diff -r dd327c0909b0 -r 2aa4fb60ae77 liboctave/array/boolSparse.h --- a/liboctave/array/boolSparse.h Tue Sep 22 21:06:01 2015 +0200 +++ b/liboctave/array/boolSparse.h Tue Sep 22 21:45:24 2015 +0200 @@ -25,7 +25,7 @@ #define octave_boolSparse_h 1 #include "Sparse.h" -#include "MSparse-defs.h" +#include "MSparse.h" #include "boolMatrix.h" #include "boolNDArray.h" diff -r dd327c0909b0 -r 2aa4fb60ae77 liboctave/array/dSparse.h --- a/liboctave/array/dSparse.h Tue Sep 22 21:06:01 2015 +0200 +++ b/liboctave/array/dSparse.h Tue Sep 22 21:45:24 2015 +0200 @@ -32,7 +32,6 @@ #include "DET.h" #include "MSparse.h" -#include "MSparse-defs.h" #include "Sparse-op-decls.h" diff -r dd327c0909b0 -r 2aa4fb60ae77 liboctave/array/module.mk --- a/liboctave/array/module.mk Tue Sep 22 21:06:01 2015 +0200 +++ b/liboctave/array/module.mk Tue Sep 22 21:45:24 2015 +0200 @@ -42,7 +42,6 @@ liboctave/array/Matrix.h \ liboctave/array/MatrixType.h \ liboctave/array/MDiagArray2.h \ - liboctave/array/MSparse-defs.h \ liboctave/array/MSparse.h \ liboctave/array/PermMatrix.h \ liboctave/array/Range.h \