Mercurial > hg > octave-nkf
diff liboctave/Sparse-op-defs.h @ 10312:cbc402e64d83
untabify liboctave header files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 Feb 2010 12:14:48 -0500 |
parents | 4c0cdbe0acca |
children | b64803a8be4e |
line wrap: on
line diff
--- a/liboctave/Sparse-op-defs.h +++ b/liboctave/Sparse-op-defs.h @@ -46,7 +46,7 @@ SPARSE_BIN_OP_DECL (R2, operator *, M, S, API); \ SPARSE_BIN_OP_DECL (R2, operator /, M, S, API); -#define SPARSE_SMS_BIN_OP_1(R, F, OP, M, S) \ +#define SPARSE_SMS_BIN_OP_1(R, F, OP, M, S) \ R \ F (const M& m, const S& s) \ { \ @@ -61,7 +61,7 @@ return r; \ } -#define SPARSE_SMS_BIN_OP_2(R, F, OP, M, S) \ +#define SPARSE_SMS_BIN_OP_2(R, F, OP, M, S) \ R \ F (const M& m, const S& s) \ { \ @@ -73,8 +73,8 @@ \ for (octave_idx_type i = 0; i < nz; i++) \ { \ - r.data(i) = m.data(i) OP s; \ - r.ridx(i) = m.ridx(i); \ + r.data(i) = m.data(i) OP s; \ + r.ridx(i) = m.ridx(i); \ } \ for (octave_idx_type i = 0; i < nc + 1; i++) \ r.cidx(i) = m.cidx(i); \ @@ -101,7 +101,7 @@ SPARSE_CMP_OP_DECL (mx_el_eq, M, S, API); \ SPARSE_CMP_OP_DECL (mx_el_ne, M, S, API); -#define SPARSE_SMS_CMP_OP(F, OP, M, MZ, MC, S, SZ, SC) \ +#define SPARSE_SMS_CMP_OP(F, OP, M, MZ, MC, S, SZ, SC) \ SparseBoolMatrix \ F (const M& m, const S& s) \ { \ @@ -112,8 +112,8 @@ if (MC (MZ) OP SC (s)) \ { \ r = SparseBoolMatrix (nr, nc, true); \ - for (octave_idx_type j = 0; j < nc; j++) \ - for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ + for (octave_idx_type j = 0; j < nc; j++) \ + for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ if (! (MC (m.data (i)) OP SC (s))) \ r.data (m.ridx (i) + j * nr) = false; \ r.maybe_compress (true); \ @@ -123,9 +123,9 @@ r = SparseBoolMatrix (nr, nc, m.nnz ()); \ r.cidx (0) = static_cast<octave_idx_type> (0); \ octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < nc; j++) \ + for (octave_idx_type j = 0; j < nc; j++) \ { \ - for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ + for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ if (MC (m.data (i)) OP SC (s)) \ { \ r.ridx (nel) = m.ridx (i); \ @@ -138,16 +138,16 @@ return r; \ } -#define SPARSE_SMS_CMP_OPS(M, MZ, CM, S, SZ, CS) \ - SPARSE_SMS_CMP_OP (mx_el_lt, <, M, MZ, , S, SZ, ) \ - SPARSE_SMS_CMP_OP (mx_el_le, <=, M, MZ, , S, SZ, ) \ - SPARSE_SMS_CMP_OP (mx_el_ge, >=, M, MZ, , S, SZ, ) \ - SPARSE_SMS_CMP_OP (mx_el_gt, >, M, MZ, , S, SZ, ) \ - SPARSE_SMS_CMP_OP (mx_el_eq, ==, M, MZ, , S, SZ, ) \ +#define SPARSE_SMS_CMP_OPS(M, MZ, CM, S, SZ, CS) \ + SPARSE_SMS_CMP_OP (mx_el_lt, <, M, MZ, , S, SZ, ) \ + SPARSE_SMS_CMP_OP (mx_el_le, <=, M, MZ, , S, SZ, ) \ + SPARSE_SMS_CMP_OP (mx_el_ge, >=, M, MZ, , S, SZ, ) \ + SPARSE_SMS_CMP_OP (mx_el_gt, >, M, MZ, , S, SZ, ) \ + SPARSE_SMS_CMP_OP (mx_el_eq, ==, M, MZ, , S, SZ, ) \ SPARSE_SMS_CMP_OP (mx_el_ne, !=, M, MZ, , S, SZ, ) -#define SPARSE_SMS_EQNE_OPS(M, MZ, CM, S, SZ, CS) \ - SPARSE_SMS_CMP_OP (mx_el_eq, ==, M, MZ, , S, SZ, ) \ +#define SPARSE_SMS_EQNE_OPS(M, MZ, CM, S, SZ, CS) \ + SPARSE_SMS_CMP_OP (mx_el_eq, ==, M, MZ, , S, SZ, ) \ SPARSE_SMS_CMP_OP (mx_el_ne, !=, M, MZ, , S, SZ, ) #define SPARSE_SMS_BOOL_OP_DECLS(M, S, API) \ @@ -164,23 +164,23 @@ \ if (nr > 0 && nc > 0) \ { \ - if (LHS_ZERO OP (s != RHS_ZERO)) \ - { \ + if (LHS_ZERO OP (s != RHS_ZERO)) \ + { \ r = SparseBoolMatrix (nr, nc, true); \ - for (octave_idx_type j = 0; j < nc; j++) \ - for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ + for (octave_idx_type j = 0; j < nc; j++) \ + for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ if (! ((m.data(i) != LHS_ZERO) OP (s != RHS_ZERO))) \ r.data (m.ridx (i) + j * nr) = false; \ r.maybe_compress (true); \ } \ - else \ - { \ + else \ + { \ r = SparseBoolMatrix (nr, nc, m.nnz ()); \ r.cidx (0) = static_cast<octave_idx_type> (0); \ octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < nc; j++) \ + for (octave_idx_type j = 0; j < nc; j++) \ { \ - for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ + for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ if ((m.data(i) != LHS_ZERO) OP (s != RHS_ZERO)) \ { \ r.ridx (nel) = m.ridx (i); \ @@ -190,7 +190,7 @@ } \ r.maybe_compress (false); \ } \ - } \ + } \ return r; \ } @@ -202,7 +202,7 @@ SPARSE_SMS_BOOL_OPS2(M, S, ZERO, ZERO) #define SPARSE_SMS_OP_DECLS(R1, R2, M, S, API) \ - SPARSE_SMS_BIN_OP_DECLS (R1, R2, M, S, API) \ + SPARSE_SMS_BIN_OP_DECLS (R1, R2, M, S, API) \ SPARSE_SMS_CMP_OP_DECLS (M, S, API) \ SPARSE_SMS_BOOL_OP_DECLS (M, S, API) @@ -242,8 +242,8 @@ \ for (octave_idx_type i = 0; i < nz; i++) \ { \ - r.data(i) = s OP m.data(i); \ - r.ridx(i) = m.ridx(i); \ + r.data(i) = s OP m.data(i); \ + r.ridx(i) = m.ridx(i); \ } \ for (octave_idx_type i = 0; i < nc + 1; i++) \ r.cidx(i) = m.cidx(i); \ @@ -270,7 +270,7 @@ SPARSE_CMP_OP_DECL (mx_el_eq, S, M, API); \ SPARSE_CMP_OP_DECL (mx_el_ne, S, M, API); -#define SPARSE_SSM_CMP_OP(F, OP, S, SZ, SC, M, MZ, MC) \ +#define SPARSE_SSM_CMP_OP(F, OP, S, SZ, SC, M, MZ, MC) \ SparseBoolMatrix \ F (const S& s, const M& m) \ { \ @@ -281,8 +281,8 @@ if (SC (s) OP SC (MZ)) \ { \ r = SparseBoolMatrix (nr, nc, true); \ - for (octave_idx_type j = 0; j < nc; j++) \ - for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ + for (octave_idx_type j = 0; j < nc; j++) \ + for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ if (! (SC (s) OP MC (m.data (i)))) \ r.data (m.ridx (i) + j * nr) = false; \ r.maybe_compress (true); \ @@ -292,9 +292,9 @@ r = SparseBoolMatrix (nr, nc, m.nnz ()); \ r.cidx (0) = static_cast<octave_idx_type> (0); \ octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < nc; j++) \ + for (octave_idx_type j = 0; j < nc; j++) \ { \ - for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ + for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ if (SC (s) OP MC (m.data (i))) \ { \ r.ridx (nel) = m.ridx (i); \ @@ -307,16 +307,16 @@ return r; \ } -#define SPARSE_SSM_CMP_OPS(S, SZ, SC, M, MZ, MC) \ - SPARSE_SSM_CMP_OP (mx_el_lt, <, S, SZ, , M, MZ, ) \ - SPARSE_SSM_CMP_OP (mx_el_le, <=, S, SZ, , M, MZ, ) \ - SPARSE_SSM_CMP_OP (mx_el_ge, >=, S, SZ, , M, MZ, ) \ - SPARSE_SSM_CMP_OP (mx_el_gt, >, S, SZ, , M, MZ, ) \ - SPARSE_SSM_CMP_OP (mx_el_eq, ==, S, SZ, , M, MZ, ) \ +#define SPARSE_SSM_CMP_OPS(S, SZ, SC, M, MZ, MC) \ + SPARSE_SSM_CMP_OP (mx_el_lt, <, S, SZ, , M, MZ, ) \ + SPARSE_SSM_CMP_OP (mx_el_le, <=, S, SZ, , M, MZ, ) \ + SPARSE_SSM_CMP_OP (mx_el_ge, >=, S, SZ, , M, MZ, ) \ + SPARSE_SSM_CMP_OP (mx_el_gt, >, S, SZ, , M, MZ, ) \ + SPARSE_SSM_CMP_OP (mx_el_eq, ==, S, SZ, , M, MZ, ) \ SPARSE_SSM_CMP_OP (mx_el_ne, !=, S, SZ, , M, MZ, ) -#define SPARSE_SSM_EQNE_OPS(S, SZ, SC, M, MZ, MC) \ - SPARSE_SSM_CMP_OP (mx_el_eq, ==, S, SZ, , M, MZ, ) \ +#define SPARSE_SSM_EQNE_OPS(S, SZ, SC, M, MZ, MC) \ + SPARSE_SSM_CMP_OP (mx_el_eq, ==, S, SZ, , M, MZ, ) \ SPARSE_SSM_CMP_OP (mx_el_ne, !=, S, SZ, , M, MZ, ) #define SPARSE_SSM_BOOL_OP_DECLS(S, M, API) \ @@ -333,23 +333,23 @@ \ if (nr > 0 && nc > 0) \ { \ - if ((s != LHS_ZERO) OP RHS_ZERO) \ - { \ + if ((s != LHS_ZERO) OP RHS_ZERO) \ + { \ r = SparseBoolMatrix (nr, nc, true); \ - for (octave_idx_type j = 0; j < nc; j++) \ - for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ + for (octave_idx_type j = 0; j < nc; j++) \ + for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ if (! ((s != LHS_ZERO) OP (m.data(i) != RHS_ZERO))) \ r.data (m.ridx (i) + j * nr) = false; \ r.maybe_compress (true); \ } \ - else \ - { \ + else \ + { \ r = SparseBoolMatrix (nr, nc, m.nnz ()); \ r.cidx (0) = static_cast<octave_idx_type> (0); \ octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < nc; j++) \ + for (octave_idx_type j = 0; j < nc; j++) \ { \ - for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ + for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) \ if ((s != LHS_ZERO) OP (m.data(i) != RHS_ZERO)) \ { \ r.ridx (nel) = m.ridx (i); \ @@ -359,7 +359,7 @@ } \ r.maybe_compress (false); \ } \ - } \ + } \ return r; \ } @@ -371,19 +371,19 @@ SPARSE_SSM_BOOL_OPS2(S, M, ZERO, ZERO) #define SPARSE_SSM_OP_DECLS(R1, R2, S, M, API) \ - SPARSE_SSM_BIN_OP_DECLS (R1, R2, S, M, API) \ + SPARSE_SSM_BIN_OP_DECLS (R1, R2, S, M, API) \ SPARSE_SSM_CMP_OP_DECLS (S, M, API) \ SPARSE_SSM_BOOL_OP_DECLS (S, M, API) \ // matrix by matrix operations. -#define SPARSE_SMSM_BIN_OP_DECLS(R1, R2, M1, M2, API) \ +#define SPARSE_SMSM_BIN_OP_DECLS(R1, R2, M1, M2, API) \ SPARSE_BIN_OP_DECL (R1, operator +, M1, M2, API); \ SPARSE_BIN_OP_DECL (R1, operator -, M1, M2, API); \ SPARSE_BIN_OP_DECL (R2, product, M1, M2, API); \ SPARSE_BIN_OP_DECL (R2, quotient, M1, M2, API); -#define SPARSE_SMSM_BIN_OP_1(R, F, OP, M1, M2) \ +#define SPARSE_SMSM_BIN_OP_1(R, F, OP, M1, M2) \ R \ F (const M1& m1, const M2& m2) \ { \ @@ -401,7 +401,7 @@ r = OP R (m2); \ else \ { \ - r = R (m2_nr, m2_nc, m1.data(0) OP 0.); \ + r = R (m2_nr, m2_nc, m1.data(0) OP 0.); \ \ for (octave_idx_type j = 0 ; j < m2_nc ; j++) \ { \ @@ -411,7 +411,7 @@ { \ octave_quit (); \ r.data(idxj + m2.ridx(i)) = m1.data(0) OP m2.data(i); \ - } \ + } \ } \ r.maybe_compress (); \ } \ @@ -422,7 +422,7 @@ r = R (m1); \ else \ { \ - r = R (m1_nr, m1_nc, 0. OP m2.data(0)); \ + r = R (m1_nr, m1_nc, 0. OP m2.data(0)); \ \ for (octave_idx_type j = 0 ; j < m1_nc ; j++) \ { \ @@ -432,7 +432,7 @@ { \ octave_quit (); \ r.data(idxj + m1.ridx(i)) = m1.data(i) OP m2.data(0); \ - } \ + } \ } \ r.maybe_compress (); \ } \ @@ -441,7 +441,7 @@ gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ else \ { \ - r = R (m1_nr, m1_nc, (m1.nnz () + m2.nnz ())); \ + r = R (m1_nr, m1_nc, (m1.nnz () + m2.nnz ())); \ \ octave_idx_type jx = 0; \ r.cidx (0) = 0; \ @@ -470,16 +470,16 @@ else if (( !ja_lt_max ) || \ (jb_lt_max && (m2.ridx(jb) < m1.ridx(ja)) ) ) \ { \ - r.ridx(jx) = m2.ridx(jb); \ - r.data(jx) = 0. OP m2.data(jb); \ - jx++; \ + r.ridx(jx) = m2.ridx(jb); \ + r.data(jx) = 0. OP m2.data(jb); \ + jx++; \ jb++; \ jb_lt_max= jb < jb_max; \ } \ else \ { \ - if ((m1.data(ja) OP m2.data(jb)) != 0.) \ - { \ + if ((m1.data(ja) OP m2.data(jb)) != 0.) \ + { \ r.data(jx) = m1.data(ja) OP m2.data(jb); \ r.ridx(jx) = m1.ridx(ja); \ jx++; \ @@ -493,13 +493,13 @@ r.cidx(i+1) = jx; \ } \ \ - r.maybe_compress (); \ + r.maybe_compress (); \ } \ \ return r; \ } -#define SPARSE_SMSM_BIN_OP_2(R, F, OP, M1, M2) \ +#define SPARSE_SMSM_BIN_OP_2(R, F, OP, M1, M2) \ R \ F (const M1& m1, const M2& m2) \ { \ @@ -517,7 +517,7 @@ r = R (m2_nr, m2_nc); \ else \ { \ - r = R (m2); \ + r = R (m2); \ octave_idx_type m2_nnz = m2.nnz(); \ \ for (octave_idx_type i = 0 ; i < m2_nnz ; i++) \ @@ -534,7 +534,7 @@ r = R (m1_nr, m1_nc); \ else \ { \ - r = R (m1); \ + r = R (m1); \ octave_idx_type m1_nnz = m1.nnz(); \ \ for (octave_idx_type i = 0 ; i < m1_nnz ; i++) \ @@ -552,7 +552,7 @@ r = R (m1_nr, m1_nc, (m1.nnz () > m2.nnz () ? m1.nnz () : m2.nnz ())); \ \ octave_idx_type jx = 0; \ - r.cidx (0) = 0; \ + r.cidx (0) = 0; \ for (octave_idx_type i = 0 ; i < m1_nc ; i++) \ { \ octave_idx_type ja = m1.cidx(i); \ @@ -578,8 +578,8 @@ } \ else \ { \ - if ((m1.data(ja) OP m2.data(jb)) != 0.) \ - { \ + if ((m1.data(ja) OP m2.data(jb)) != 0.) \ + { \ r.data(jx) = m1.data(ja) OP m2.data(jb); \ r.ridx(jx) = m1.ridx(ja); \ jx++; \ @@ -591,13 +591,13 @@ r.cidx(i+1) = jx; \ } \ \ - r.maybe_compress (); \ + r.maybe_compress (); \ } \ \ return r; \ } -#define SPARSE_SMSM_BIN_OP_3(R, F, OP, M1, M2) \ +#define SPARSE_SMSM_BIN_OP_3(R, F, OP, M1, M2) \ R \ F (const M1& m1, const M2& m2) \ { \ @@ -630,7 +630,7 @@ { \ octave_quit (); \ r.data(idxj + m2.ridx(i)) = m1.elem(0,0) OP m2.data(i); \ - } \ + } \ } \ r.maybe_compress (); \ } \ @@ -656,7 +656,7 @@ { \ octave_quit (); \ r.data(idxj + m1.ridx(i)) = m1.data(i) OP m2.elem(0,0); \ - } \ + } \ } \ r.maybe_compress (); \ } \ @@ -685,7 +685,7 @@ if ((! jb_lt_max) || \ (ja_lt_max && (m1.ridx(ja) < m2.ridx(jb)))) \ { \ - /* keep those kludges coming */ \ + /* keep those kludges coming */ \ r.elem(m1.ridx(ja),i) = m1.data(ja) OP Complex (); \ ja++; \ ja_lt_max= ja < ja_max; \ @@ -693,8 +693,8 @@ else if (( !ja_lt_max ) || \ (jb_lt_max && (m2.ridx(jb) < m1.ridx(ja)) ) ) \ { \ - /* keep those kludges coming */ \ - r.elem(m2.ridx(jb),i) = Complex () OP m2.data(jb); \ + /* keep those kludges coming */ \ + r.elem(m2.ridx(jb),i) = Complex () OP m2.data(jb); \ jb++; \ jb_lt_max= jb < jb_max; \ } \ @@ -708,7 +708,7 @@ } \ } \ } \ - r.maybe_compress (true); \ + r.maybe_compress (true); \ } \ \ return r; \ @@ -740,7 +740,7 @@ // functions defined in the SPARSE_SSM_CMP_OP and SPARSE_SMS_CMP_OP // macros. -#define SPARSE_SMSM_CMP_OP(F, OP, M1, Z1, C1, M2, Z2, C2) \ +#define SPARSE_SMSM_CMP_OP(F, OP, M1, Z1, C1, M2, Z2, C2) \ SparseBoolMatrix \ F (const M1& m1, const M2& m2) \ { \ @@ -755,69 +755,69 @@ if (m1_nr == 1 && m1_nc == 1) \ { \ if (C1 (m1.elem(0,0)) OP C2 (Z2)) \ - { \ - r = SparseBoolMatrix (m2_nr, m2_nc, true); \ - for (octave_idx_type j = 0; j < m2_nc; j++) \ - for (octave_idx_type i = m2.cidx(j); i < m2.cidx(j+1); i++) \ - if (! (C1 (m1.elem (0,0)) OP C2 (m2.data(i)))) \ - r.data (m2.ridx (i) + j * m2_nr) = false; \ - r.maybe_compress (true); \ - } \ - else \ - { \ - r = SparseBoolMatrix (m2_nr, m2_nc, m2.nnz ()); \ - r.cidx (0) = static_cast<octave_idx_type> (0); \ - octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < m2_nc; j++) \ - { \ - for (octave_idx_type i = m2.cidx(j); i < m2.cidx(j+1); i++) \ - if (C1 (m1.elem (0,0)) OP C2 (m2.data(i))) \ - { \ - r.ridx (nel) = m2.ridx (i); \ - r.data (nel++) = true; \ - } \ - r.cidx (j + 1) = nel; \ - } \ - r.maybe_compress (false); \ - } \ + { \ + r = SparseBoolMatrix (m2_nr, m2_nc, true); \ + for (octave_idx_type j = 0; j < m2_nc; j++) \ + for (octave_idx_type i = m2.cidx(j); i < m2.cidx(j+1); i++) \ + if (! (C1 (m1.elem (0,0)) OP C2 (m2.data(i)))) \ + r.data (m2.ridx (i) + j * m2_nr) = false; \ + r.maybe_compress (true); \ + } \ + else \ + { \ + r = SparseBoolMatrix (m2_nr, m2_nc, m2.nnz ()); \ + r.cidx (0) = static_cast<octave_idx_type> (0); \ + octave_idx_type nel = 0; \ + for (octave_idx_type j = 0; j < m2_nc; j++) \ + { \ + for (octave_idx_type i = m2.cidx(j); i < m2.cidx(j+1); i++) \ + if (C1 (m1.elem (0,0)) OP C2 (m2.data(i))) \ + { \ + r.ridx (nel) = m2.ridx (i); \ + r.data (nel++) = true; \ + } \ + r.cidx (j + 1) = nel; \ + } \ + r.maybe_compress (false); \ + } \ } \ else if (m2_nr == 1 && m2_nc == 1) \ { \ - if (C1 (Z1) OP C2 (m2.elem (0,0))) \ - { \ - r = SparseBoolMatrix (m1_nr, m1_nc, true); \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - for (octave_idx_type i = m1.cidx(j); i < m1.cidx(j+1); i++) \ - if (! (C1 (m1.data (i)) OP C2 (m2.elem(0,0)))) \ - r.data (m1.ridx (i) + j * m1_nr) = false; \ - r.maybe_compress (true); \ - } \ - else \ - { \ - r = SparseBoolMatrix (m1_nr, m1_nc, m1.nnz ()); \ - r.cidx (0) = static_cast<octave_idx_type> (0); \ - octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - { \ - for (octave_idx_type i = m1.cidx(j); i < m1.cidx(j+1); i++) \ - if (C1 (m1.data (i)) OP C2 (m2.elem(0,0))) \ - { \ - r.ridx (nel) = m1.ridx (i); \ - r.data (nel++) = true; \ - } \ - r.cidx (j + 1) = nel; \ - } \ - r.maybe_compress (false); \ - } \ + if (C1 (Z1) OP C2 (m2.elem (0,0))) \ + { \ + r = SparseBoolMatrix (m1_nr, m1_nc, true); \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + for (octave_idx_type i = m1.cidx(j); i < m1.cidx(j+1); i++) \ + if (! (C1 (m1.data (i)) OP C2 (m2.elem(0,0)))) \ + r.data (m1.ridx (i) + j * m1_nr) = false; \ + r.maybe_compress (true); \ + } \ + else \ + { \ + r = SparseBoolMatrix (m1_nr, m1_nc, m1.nnz ()); \ + r.cidx (0) = static_cast<octave_idx_type> (0); \ + octave_idx_type nel = 0; \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + { \ + for (octave_idx_type i = m1.cidx(j); i < m1.cidx(j+1); i++) \ + if (C1 (m1.data (i)) OP C2 (m2.elem(0,0))) \ + { \ + r.ridx (nel) = m1.ridx (i); \ + r.data (nel++) = true; \ + } \ + r.cidx (j + 1) = nel; \ + } \ + r.maybe_compress (false); \ + } \ } \ else if (m1_nr == m2_nr && m1_nc == m2_nc) \ { \ - if (m1_nr != 0 || m1_nc != 0) \ - { \ + if (m1_nr != 0 || m1_nc != 0) \ + { \ if (C1 (Z1) OP C2 (Z2)) \ - { \ + { \ r = SparseBoolMatrix (m1_nr, m1_nc, true); \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ { \ octave_idx_type i1 = m1.cidx (j); \ octave_idx_type e1 = m1.cidx (j+1); \ @@ -853,7 +853,7 @@ r = SparseBoolMatrix (m1_nr, m1_nc, m1.nnz () + m2.nnz ()); \ r.cidx (0) = static_cast<octave_idx_type> (0); \ octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ { \ octave_idx_type i1 = m1.cidx (j); \ octave_idx_type e1 = m1.cidx (j+1); \ @@ -894,12 +894,12 @@ } \ r.maybe_compress (false); \ } \ - } \ - } \ + } \ + } \ else \ { \ - if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ - gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ + if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ + gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ } \ return r; \ } @@ -938,76 +938,76 @@ \ if (m1_nr == 1 && m1_nc == 1) \ { \ - if (m2_nr > 0 && m2_nc > 0) \ - { \ - if ((m1.elem(0,0) != LHS_ZERO) OP RHS_ZERO) \ - { \ - r = SparseBoolMatrix (m2_nr, m2_nc, true); \ - for (octave_idx_type j = 0; j < m2_nc; j++) \ - for (octave_idx_type i = m2.cidx(j); i < m2.cidx(j+1); i++) \ - if (! ((m1.elem(0,0) != LHS_ZERO) OP (m2.data(i) != RHS_ZERO))) \ - r.data (m2.ridx (i) + j * m2_nr) = false; \ - r.maybe_compress (true); \ - } \ - else \ - { \ - r = SparseBoolMatrix (m2_nr, m2_nc, m2.nnz ()); \ - r.cidx (0) = static_cast<octave_idx_type> (0); \ - octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < m2_nc; j++) \ - { \ - for (octave_idx_type i = m2.cidx(j); i < m2.cidx(j+1); i++) \ - if ((m1.elem(0,0) != LHS_ZERO) OP (m2.data(i) != RHS_ZERO)) \ - { \ - r.ridx (nel) = m2.ridx (i); \ - r.data (nel++) = true; \ - } \ - r.cidx (j + 1) = nel; \ - } \ - r.maybe_compress (false); \ - } \ - } \ + if (m2_nr > 0 && m2_nc > 0) \ + { \ + if ((m1.elem(0,0) != LHS_ZERO) OP RHS_ZERO) \ + { \ + r = SparseBoolMatrix (m2_nr, m2_nc, true); \ + for (octave_idx_type j = 0; j < m2_nc; j++) \ + for (octave_idx_type i = m2.cidx(j); i < m2.cidx(j+1); i++) \ + if (! ((m1.elem(0,0) != LHS_ZERO) OP (m2.data(i) != RHS_ZERO))) \ + r.data (m2.ridx (i) + j * m2_nr) = false; \ + r.maybe_compress (true); \ + } \ + else \ + { \ + r = SparseBoolMatrix (m2_nr, m2_nc, m2.nnz ()); \ + r.cidx (0) = static_cast<octave_idx_type> (0); \ + octave_idx_type nel = 0; \ + for (octave_idx_type j = 0; j < m2_nc; j++) \ + { \ + for (octave_idx_type i = m2.cidx(j); i < m2.cidx(j+1); i++) \ + if ((m1.elem(0,0) != LHS_ZERO) OP (m2.data(i) != RHS_ZERO)) \ + { \ + r.ridx (nel) = m2.ridx (i); \ + r.data (nel++) = true; \ + } \ + r.cidx (j + 1) = nel; \ + } \ + r.maybe_compress (false); \ + } \ + } \ } \ else if (m2_nr == 1 && m2_nc == 1) \ { \ - if (m1_nr > 0 && m1_nc > 0) \ - { \ - if (LHS_ZERO OP (m2.elem(0,0) != RHS_ZERO)) \ - { \ - r = SparseBoolMatrix (m1_nr, m1_nc, true); \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - for (octave_idx_type i = m1.cidx(j); i < m1.cidx(j+1); i++) \ - if (! ((m1.data(i) != LHS_ZERO) OP (m2.elem(0,0) != RHS_ZERO))) \ - r.data (m1.ridx (i) + j * m1_nr) = false; \ - r.maybe_compress (true); \ - } \ - else \ - { \ - r = SparseBoolMatrix (m1_nr, m1_nc, m1.nnz ()); \ - r.cidx (0) = static_cast<octave_idx_type> (0); \ - octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - { \ - for (octave_idx_type i = m1.cidx(j); i < m1.cidx(j+1); i++) \ - if ((m1.data(i) != LHS_ZERO) OP (m2.elem(0,0) != RHS_ZERO)) \ - { \ - r.ridx (nel) = m1.ridx (i); \ - r.data (nel++) = true; \ - } \ - r.cidx (j + 1) = nel; \ - } \ - r.maybe_compress (false); \ - } \ - } \ + if (m1_nr > 0 && m1_nc > 0) \ + { \ + if (LHS_ZERO OP (m2.elem(0,0) != RHS_ZERO)) \ + { \ + r = SparseBoolMatrix (m1_nr, m1_nc, true); \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + for (octave_idx_type i = m1.cidx(j); i < m1.cidx(j+1); i++) \ + if (! ((m1.data(i) != LHS_ZERO) OP (m2.elem(0,0) != RHS_ZERO))) \ + r.data (m1.ridx (i) + j * m1_nr) = false; \ + r.maybe_compress (true); \ + } \ + else \ + { \ + r = SparseBoolMatrix (m1_nr, m1_nc, m1.nnz ()); \ + r.cidx (0) = static_cast<octave_idx_type> (0); \ + octave_idx_type nel = 0; \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + { \ + for (octave_idx_type i = m1.cidx(j); i < m1.cidx(j+1); i++) \ + if ((m1.data(i) != LHS_ZERO) OP (m2.elem(0,0) != RHS_ZERO)) \ + { \ + r.ridx (nel) = m1.ridx (i); \ + r.data (nel++) = true; \ + } \ + r.cidx (j + 1) = nel; \ + } \ + r.maybe_compress (false); \ + } \ + } \ } \ else if (m1_nr == m2_nr && m1_nc == m2_nc) \ { \ - if (m1_nr != 0 || m1_nc != 0) \ - { \ + if (m1_nr != 0 || m1_nc != 0) \ + { \ r = SparseBoolMatrix (m1_nr, m1_nc, m1.nnz () + m2.nnz ()); \ r.cidx (0) = static_cast<octave_idx_type> (0); \ octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ { \ octave_idx_type i1 = m1.cidx (j); \ octave_idx_type e1 = m1.cidx (j+1); \ @@ -1047,12 +1047,12 @@ r.cidx (j + 1) = nel; \ } \ r.maybe_compress (false); \ - } \ - } \ + } \ + } \ else \ { \ - if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ - gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ + if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ + gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ } \ return r; \ } @@ -1071,13 +1071,13 @@ // matrix by matrix operations. -#define SPARSE_MSM_BIN_OP_DECLS(R1, R2, M1, M2, API) \ +#define SPARSE_MSM_BIN_OP_DECLS(R1, R2, M1, M2, API) \ SPARSE_BIN_OP_DECL (R1, operator +, M1, M2, API); \ SPARSE_BIN_OP_DECL (R1, operator -, M1, M2, API); \ SPARSE_BIN_OP_DECL (R2, product, M1, M2, API); \ SPARSE_BIN_OP_DECL (R2, quotient, M1, M2, API); -#define SPARSE_MSM_BIN_OP_1(R, F, OP, M1, M2) \ +#define SPARSE_MSM_BIN_OP_1(R, F, OP, M1, M2) \ R \ F (const M1& m1, const M2& m2) \ { \ @@ -1098,8 +1098,8 @@ r = R (m1_nr, m1_nc); \ \ for (octave_idx_type j = 0; j < m1_nc; j++) \ - for (octave_idx_type i = 0; i < m1_nr; i++) \ - r.elem (i, j) = m1.elem (i, j) OP m2.elem (i, j); \ + for (octave_idx_type i = 0; i < m1_nr; i++) \ + r.elem (i, j) = m1.elem (i, j) OP m2.elem (i, j); \ } \ return r; \ } @@ -1122,29 +1122,29 @@ gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ else \ { \ - /* Count num of non-zero elements */ \ - octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - for (octave_idx_type i = 0; i < m1_nr; i++) \ - if ((m1.elem(i, j) OP m2.elem(i, j)) != ZERO) \ - nel++; \ - \ + /* Count num of non-zero elements */ \ + octave_idx_type nel = 0; \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + for (octave_idx_type i = 0; i < m1_nr; i++) \ + if ((m1.elem(i, j) OP m2.elem(i, j)) != ZERO) \ + nel++; \ + \ r = R (m1_nr, m1_nc, nel); \ \ - octave_idx_type ii = 0; \ - r.cidx (0) = 0; \ + octave_idx_type ii = 0; \ + r.cidx (0) = 0; \ for (octave_idx_type j = 0 ; j < m1_nc ; j++) \ { \ - for (octave_idx_type i = 0 ; i < m1_nr ; i++) \ - { \ - if ((m1.elem(i, j) OP m2.elem(i, j)) != ZERO) \ - { \ - r.data (ii) = m1.elem(i, j) OP m2.elem(i,j); \ - r.ridx (ii++) = i; \ - } \ - } \ - r.cidx(j+1) = ii; \ - } \ + for (octave_idx_type i = 0 ; i < m1_nr ; i++) \ + { \ + if ((m1.elem(i, j) OP m2.elem(i, j)) != ZERO) \ + { \ + r.data (ii) = m1.elem(i, j) OP m2.elem(i,j); \ + r.ridx (ii++) = i; \ + } \ + } \ + r.cidx(j+1) = ii; \ + } \ } \ \ return r; \ @@ -1169,7 +1169,7 @@ SPARSE_CMP_OP_DECL (mx_el_eq, M1, M2, API); \ SPARSE_CMP_OP_DECL (mx_el_ne, M1, M2, API); -#define SPARSE_MSM_CMP_OP(F, OP, M1, C1, M2, C2) \ +#define SPARSE_MSM_CMP_OP(F, OP, M1, C1, M2, C2) \ SparseBoolMatrix \ F (const M1& m1, const M2& m2) \ { \ @@ -1185,38 +1185,38 @@ r = SparseBoolMatrix (F (m1, m2.elem(0,0))); \ else if (m1_nr == m2_nr && m1_nc == m2_nc) \ { \ - if (m1_nr != 0 || m1_nc != 0) \ - { \ - /* Count num of non-zero elements */ \ - octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - for (octave_idx_type i = 0; i < m1_nr; i++) \ - if (C1 (m1.elem(i, j)) OP C2 (m2.elem(i, j))) \ - nel++; \ + if (m1_nr != 0 || m1_nc != 0) \ + { \ + /* Count num of non-zero elements */ \ + octave_idx_type nel = 0; \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + for (octave_idx_type i = 0; i < m1_nr; i++) \ + if (C1 (m1.elem(i, j)) OP C2 (m2.elem(i, j))) \ + nel++; \ \ r = SparseBoolMatrix (m1_nr, m1_nc, nel); \ \ - octave_idx_type ii = 0; \ - r.cidx (0) = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - { \ - for (octave_idx_type i = 0; i < m1_nr; i++) \ - { \ - bool el = C1 (m1.elem(i, j)) OP C2 (m2.elem(i, j)); \ - if (el) \ - { \ - r.data(ii) = el; \ - r.ridx(ii++) = i; \ - } \ - } \ - r.cidx(j+1) = ii; \ - } \ - } \ - } \ + octave_idx_type ii = 0; \ + r.cidx (0) = 0; \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + { \ + for (octave_idx_type i = 0; i < m1_nr; i++) \ + { \ + bool el = C1 (m1.elem(i, j)) OP C2 (m2.elem(i, j)); \ + if (el) \ + { \ + r.data(ii) = el; \ + r.ridx(ii++) = i; \ + } \ + } \ + r.cidx(j+1) = ii; \ + } \ + } \ + } \ else \ { \ - if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ - gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ + if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ + gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ } \ return r; \ } @@ -1253,40 +1253,40 @@ r = SparseBoolMatrix (F (m1, m2.elem(0,0))); \ else if (m1_nr == m2_nr && m1_nc == m2_nc) \ { \ - if (m1_nr != 0 || m1_nc != 0) \ - { \ - /* Count num of non-zero elements */ \ - octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - for (octave_idx_type i = 0; i < m1_nr; i++) \ - if ((m1.elem(i, j) != LHS_ZERO) \ - OP (m2.elem(i, j) != RHS_ZERO)) \ - nel++; \ + if (m1_nr != 0 || m1_nc != 0) \ + { \ + /* Count num of non-zero elements */ \ + octave_idx_type nel = 0; \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + for (octave_idx_type i = 0; i < m1_nr; i++) \ + if ((m1.elem(i, j) != LHS_ZERO) \ + OP (m2.elem(i, j) != RHS_ZERO)) \ + nel++; \ \ r = SparseBoolMatrix (m1_nr, m1_nc, nel); \ \ - octave_idx_type ii = 0; \ - r.cidx (0) = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - { \ - for (octave_idx_type i = 0; i < m1_nr; i++) \ - { \ - bool el = (m1.elem(i, j) != LHS_ZERO) \ - OP (m2.elem(i, j) != RHS_ZERO); \ - if (el) \ - { \ - r.data(ii) = el; \ - r.ridx(ii++) = i; \ - } \ - } \ - r.cidx(j+1) = ii; \ - } \ - } \ - } \ + octave_idx_type ii = 0; \ + r.cidx (0) = 0; \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + { \ + for (octave_idx_type i = 0; i < m1_nr; i++) \ + { \ + bool el = (m1.elem(i, j) != LHS_ZERO) \ + OP (m2.elem(i, j) != RHS_ZERO); \ + if (el) \ + { \ + r.data(ii) = el; \ + r.ridx(ii++) = i; \ + } \ + } \ + r.cidx(j+1) = ii; \ + } \ + } \ + } \ else \ { \ - if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ - gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ + if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ + gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ } \ return r; \ } @@ -1305,13 +1305,13 @@ // matrix by matrix operations. -#define SPARSE_SMM_BIN_OP_DECLS(R1, R2, M1, M2, API) \ +#define SPARSE_SMM_BIN_OP_DECLS(R1, R2, M1, M2, API) \ SPARSE_BIN_OP_DECL (R1, operator +, M1, M2, API); \ SPARSE_BIN_OP_DECL (R1, operator -, M1, M2, API); \ SPARSE_BIN_OP_DECL (R2, product, M1, M2, API); \ SPARSE_BIN_OP_DECL (R2, quotient, M1, M2, API); -#define SPARSE_SMM_BIN_OP_1(R, F, OP, M1, M2) \ +#define SPARSE_SMM_BIN_OP_1(R, F, OP, M1, M2) \ R \ F (const M1& m1, const M2& m2) \ { \ @@ -1332,8 +1332,8 @@ r = R (m1_nr, m1_nc); \ \ for (octave_idx_type j = 0; j < m1_nc; j++) \ - for (octave_idx_type i = 0; i < m1_nr; i++) \ - r.elem (i, j) = m1.elem (i, j) OP m2.elem (i, j); \ + for (octave_idx_type i = 0; i < m1_nr; i++) \ + r.elem (i, j) = m1.elem (i, j) OP m2.elem (i, j); \ } \ return r; \ } @@ -1356,29 +1356,29 @@ gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ else \ { \ - /* Count num of non-zero elements */ \ - octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - for (octave_idx_type i = 0; i < m1_nr; i++) \ - if ((m1.elem(i, j) OP m2.elem(i, j)) != ZERO) \ - nel++; \ - \ + /* Count num of non-zero elements */ \ + octave_idx_type nel = 0; \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + for (octave_idx_type i = 0; i < m1_nr; i++) \ + if ((m1.elem(i, j) OP m2.elem(i, j)) != ZERO) \ + nel++; \ + \ r = R (m1_nr, m1_nc, nel); \ \ - octave_idx_type ii = 0; \ - r.cidx (0) = 0; \ + octave_idx_type ii = 0; \ + r.cidx (0) = 0; \ for (octave_idx_type j = 0 ; j < m1_nc ; j++) \ { \ - for (octave_idx_type i = 0 ; i < m1_nr ; i++) \ - { \ - if ((m1.elem(i, j) OP m2.elem(i, j)) != ZERO) \ - { \ - r.data (ii) = m1.elem(i, j) OP m2.elem(i,j); \ - r.ridx (ii++) = i; \ - } \ - } \ - r.cidx(j+1) = ii; \ - } \ + for (octave_idx_type i = 0 ; i < m1_nr ; i++) \ + { \ + if ((m1.elem(i, j) OP m2.elem(i, j)) != ZERO) \ + { \ + r.data (ii) = m1.elem(i, j) OP m2.elem(i,j); \ + r.ridx (ii++) = i; \ + } \ + } \ + r.cidx(j+1) = ii; \ + } \ } \ \ return r; \ @@ -1403,7 +1403,7 @@ SPARSE_CMP_OP_DECL (mx_el_eq, M1, M2, API); \ SPARSE_CMP_OP_DECL (mx_el_ne, M1, M2, API); -#define SPARSE_SMM_CMP_OP(F, OP, M1, C1, M2, C2) \ +#define SPARSE_SMM_CMP_OP(F, OP, M1, C1, M2, C2) \ SparseBoolMatrix \ F (const M1& m1, const M2& m2) \ { \ @@ -1419,38 +1419,38 @@ r = SparseBoolMatrix (F (m1.elem(0,0), m2)); \ else if (m1_nr == m2_nr && m1_nc == m2_nc) \ { \ - if (m1_nr != 0 || m1_nc != 0) \ - { \ - /* Count num of non-zero elements */ \ - octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - for (octave_idx_type i = 0; i < m1_nr; i++) \ - if (C1 (m1.elem(i, j)) OP C2 (m2.elem(i, j))) \ - nel++; \ + if (m1_nr != 0 || m1_nc != 0) \ + { \ + /* Count num of non-zero elements */ \ + octave_idx_type nel = 0; \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + for (octave_idx_type i = 0; i < m1_nr; i++) \ + if (C1 (m1.elem(i, j)) OP C2 (m2.elem(i, j))) \ + nel++; \ \ r = SparseBoolMatrix (m1_nr, m1_nc, nel); \ \ - octave_idx_type ii = 0; \ - r.cidx (0) = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - { \ - for (octave_idx_type i = 0; i < m1_nr; i++) \ - { \ - bool el = C1 (m1.elem(i, j)) OP C2 (m2.elem(i, j)); \ - if (el) \ - { \ - r.data(ii) = el; \ - r.ridx(ii++) = i; \ - } \ - } \ - r.cidx(j+1) = ii; \ - } \ - } \ - } \ + octave_idx_type ii = 0; \ + r.cidx (0) = 0; \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + { \ + for (octave_idx_type i = 0; i < m1_nr; i++) \ + { \ + bool el = C1 (m1.elem(i, j)) OP C2 (m2.elem(i, j)); \ + if (el) \ + { \ + r.data(ii) = el; \ + r.ridx(ii++) = i; \ + } \ + } \ + r.cidx(j+1) = ii; \ + } \ + } \ + } \ else \ { \ - if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ - gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ + if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ + gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ } \ return r; \ } @@ -1487,40 +1487,40 @@ r = SparseBoolMatrix (F (m1.elem(0,0), m2)); \ else if (m1_nr == m2_nr && m1_nc == m2_nc) \ { \ - if (m1_nr != 0 || m1_nc != 0) \ - { \ - /* Count num of non-zero elements */ \ - octave_idx_type nel = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - for (octave_idx_type i = 0; i < m1_nr; i++) \ - if ((m1.elem(i, j) != LHS_ZERO) \ - OP (m2.elem(i, j) != RHS_ZERO)) \ - nel++; \ + if (m1_nr != 0 || m1_nc != 0) \ + { \ + /* Count num of non-zero elements */ \ + octave_idx_type nel = 0; \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + for (octave_idx_type i = 0; i < m1_nr; i++) \ + if ((m1.elem(i, j) != LHS_ZERO) \ + OP (m2.elem(i, j) != RHS_ZERO)) \ + nel++; \ \ r = SparseBoolMatrix (m1_nr, m1_nc, nel); \ \ - octave_idx_type ii = 0; \ - r.cidx (0) = 0; \ - for (octave_idx_type j = 0; j < m1_nc; j++) \ - { \ - for (octave_idx_type i = 0; i < m1_nr; i++) \ - { \ - bool el = (m1.elem(i, j) != LHS_ZERO) \ - OP (m2.elem(i, j) != RHS_ZERO); \ - if (el) \ - { \ - r.data(ii) = el; \ - r.ridx(ii++) = i; \ - } \ - } \ - r.cidx(j+1) = ii; \ - } \ - } \ - } \ + octave_idx_type ii = 0; \ + r.cidx (0) = 0; \ + for (octave_idx_type j = 0; j < m1_nc; j++) \ + { \ + for (octave_idx_type i = 0; i < m1_nr; i++) \ + { \ + bool el = (m1.elem(i, j) != LHS_ZERO) \ + OP (m2.elem(i, j) != RHS_ZERO); \ + if (el) \ + { \ + r.data(ii) = el; \ + r.ridx(ii++) = i; \ + } \ + } \ + r.cidx(j+1) = ii; \ + } \ + } \ + } \ else \ { \ - if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ - gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ + if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ + gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ } \ return r; \ } @@ -1539,7 +1539,7 @@ // Avoid some code duplication. Maybe we should use templates. -#define SPARSE_CUMSUM(RET_TYPE, ELT_TYPE, FCN) \ +#define SPARSE_CUMSUM(RET_TYPE, ELT_TYPE, FCN) \ \ octave_idx_type nr = rows (); \ octave_idx_type nc = cols (); \ @@ -1549,33 +1549,33 @@ if (nr > 0 && nc > 0) \ { \ if ((nr == 1 && dim == -1) || dim == 1) \ - /* Ugly!! Is there a better way? */ \ + /* Ugly!! Is there a better way? */ \ retval = transpose (). FCN (0) .transpose (); \ else \ - { \ + { \ octave_idx_type nel = 0; \ - for (octave_idx_type i = 0; i < nc; i++) \ + for (octave_idx_type i = 0; i < nc; i++) \ { \ ELT_TYPE t = ELT_TYPE (); \ - for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) \ + for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) \ { \ t += data(j); \ if (t != ELT_TYPE ()) \ - { \ + { \ if (j == cidx(i+1) - 1) \ - nel += nr - ridx(j); \ - else \ - nel += ridx(j+1) - ridx(j); \ - } \ + nel += nr - ridx(j); \ + else \ + nel += ridx(j+1) - ridx(j); \ + } \ } \ - } \ - retval = RET_TYPE (nr, nc, nel); \ + } \ + retval = RET_TYPE (nr, nc, nel); \ retval.cidx(0) = 0; \ - octave_idx_type ii = 0; \ - for (octave_idx_type i = 0; i < nc; i++) \ + octave_idx_type ii = 0; \ + for (octave_idx_type i = 0; i < nc; i++) \ { \ ELT_TYPE t = ELT_TYPE (); \ - for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) \ + for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) \ { \ t += data(j); \ if (t != ELT_TYPE ()) \ @@ -1588,8 +1588,8 @@ retval.ridx (ii++) = k; \ } \ } \ - else \ - { \ + else \ + { \ for (octave_idx_type k = ridx(j); k < ridx(j+1); k++) \ { \ retval.data (ii) = t; \ @@ -1599,8 +1599,8 @@ } \ } \ retval.cidx(i+1) = ii; \ - } \ - } \ + } \ + } \ } \ else \ retval = RET_TYPE (nr,nc); \ @@ -1608,7 +1608,7 @@ return retval -#define SPARSE_CUMPROD(RET_TYPE, ELT_TYPE, FCN) \ +#define SPARSE_CUMPROD(RET_TYPE, ELT_TYPE, FCN) \ \ octave_idx_type nr = rows (); \ octave_idx_type nc = cols (); \ @@ -1618,17 +1618,17 @@ if (nr > 0 && nc > 0) \ { \ if ((nr == 1 && dim == -1) || dim == 1) \ - /* Ugly!! Is there a better way? */ \ + /* Ugly!! Is there a better way? */ \ retval = transpose (). FCN (0) .transpose (); \ else \ - { \ + { \ octave_idx_type nel = 0; \ - for (octave_idx_type i = 0; i < nc; i++) \ + for (octave_idx_type i = 0; i < nc; i++) \ { \ - octave_idx_type jj = 0; \ - for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) \ + octave_idx_type jj = 0; \ + for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) \ { \ - if (jj == ridx(j)) \ + if (jj == ridx(j)) \ { \ nel++; \ jj++; \ @@ -1636,17 +1636,17 @@ else \ break; \ } \ - } \ - retval = RET_TYPE (nr, nc, nel); \ + } \ + retval = RET_TYPE (nr, nc, nel); \ retval.cidx(0) = 0; \ - octave_idx_type ii = 0; \ - for (octave_idx_type i = 0; i < nc; i++) \ + octave_idx_type ii = 0; \ + for (octave_idx_type i = 0; i < nc; i++) \ { \ ELT_TYPE t = ELT_TYPE (1.); \ - octave_idx_type jj = 0; \ - for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) \ + octave_idx_type jj = 0; \ + for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) \ { \ - if (jj == ridx(j)) \ + if (jj == ridx(j)) \ { \ t *= data(j); \ retval.data(ii) = t; \ @@ -1656,8 +1656,8 @@ break; \ } \ retval.cidx(i+1) = ii; \ - } \ - } \ + } \ + } \ } \ else \ retval = RET_TYPE (nr,nc); \ @@ -1665,7 +1665,7 @@ return retval #define SPARSE_BASE_REDUCTION_OP(RET_TYPE, EL_TYPE, ROW_EXPR, COL_EXPR, \ - INIT_VAL, MT_RESULT) \ + INIT_VAL, MT_RESULT) \ \ octave_idx_type nr = rows (); \ octave_idx_type nc = cols (); \ @@ -1675,64 +1675,64 @@ if (nr > 0 && nc > 0) \ { \ if ((nr == 1 && dim == -1) || dim == 1) \ - { \ + { \ /* Define j here to allow fancy definition for prod method */ \ octave_idx_type j = 0; \ - OCTAVE_LOCAL_BUFFER (EL_TYPE, tmp, nr); \ + OCTAVE_LOCAL_BUFFER (EL_TYPE, tmp, nr); \ \ - for (octave_idx_type i = 0; i < nr; i++) \ - tmp[i] = INIT_VAL; \ - for (j = 0; j < nc; j++) \ + for (octave_idx_type i = 0; i < nr; i++) \ + tmp[i] = INIT_VAL; \ + for (j = 0; j < nc; j++) \ { \ - for (octave_idx_type i = cidx(j); i < cidx(j + 1); i++) \ + for (octave_idx_type i = cidx(j); i < cidx(j + 1); i++) \ { \ - ROW_EXPR; \ + ROW_EXPR; \ } \ - } \ - octave_idx_type nel = 0; \ - for (octave_idx_type i = 0; i < nr; i++) \ - if (tmp[i] != EL_TYPE ()) \ - nel++ ; \ - retval = RET_TYPE (nr, static_cast<octave_idx_type> (1), nel); \ - retval.cidx(0) = 0; \ - retval.cidx(1) = nel; \ - nel = 0; \ - for (octave_idx_type i = 0; i < nr; i++) \ - if (tmp[i] != EL_TYPE ()) \ - { \ - retval.data(nel) = tmp[i]; \ - retval.ridx(nel++) = i; \ - } \ - } \ + } \ + octave_idx_type nel = 0; \ + for (octave_idx_type i = 0; i < nr; i++) \ + if (tmp[i] != EL_TYPE ()) \ + nel++ ; \ + retval = RET_TYPE (nr, static_cast<octave_idx_type> (1), nel); \ + retval.cidx(0) = 0; \ + retval.cidx(1) = nel; \ + nel = 0; \ + for (octave_idx_type i = 0; i < nr; i++) \ + if (tmp[i] != EL_TYPE ()) \ + { \ + retval.data(nel) = tmp[i]; \ + retval.ridx(nel++) = i; \ + } \ + } \ else \ - { \ - OCTAVE_LOCAL_BUFFER (EL_TYPE, tmp, nc); \ + { \ + OCTAVE_LOCAL_BUFFER (EL_TYPE, tmp, nc); \ \ - for (octave_idx_type j = 0; j < nc; j++) \ - { \ - tmp[j] = INIT_VAL; \ - for (octave_idx_type i = cidx(j); i < cidx(j + 1); i++) \ + for (octave_idx_type j = 0; j < nc; j++) \ + { \ + tmp[j] = INIT_VAL; \ + for (octave_idx_type i = cidx(j); i < cidx(j + 1); i++) \ { \ - COL_EXPR; \ + COL_EXPR; \ } \ - } \ - octave_idx_type nel = 0; \ - for (octave_idx_type i = 0; i < nc; i++) \ - if (tmp[i] != EL_TYPE ()) \ - nel++ ; \ - retval = RET_TYPE (static_cast<octave_idx_type> (1), nc, nel); \ - retval.cidx(0) = 0; \ - nel = 0; \ - for (octave_idx_type i = 0; i < nc; i++) \ - if (tmp[i] != EL_TYPE ()) \ - { \ - retval.data(nel) = tmp[i]; \ - retval.ridx(nel++) = 0; \ - retval.cidx(i+1) = retval.cidx(i) + 1; \ - } \ - else \ - retval.cidx(i+1) = retval.cidx(i); \ - } \ + } \ + octave_idx_type nel = 0; \ + for (octave_idx_type i = 0; i < nc; i++) \ + if (tmp[i] != EL_TYPE ()) \ + nel++ ; \ + retval = RET_TYPE (static_cast<octave_idx_type> (1), nc, nel); \ + retval.cidx(0) = 0; \ + nel = 0; \ + for (octave_idx_type i = 0; i < nc; i++) \ + if (tmp[i] != EL_TYPE ()) \ + { \ + retval.data(nel) = tmp[i]; \ + retval.ridx(nel++) = 0; \ + retval.cidx(i+1) = retval.cidx(i) + 1; \ + } \ + else \ + retval.cidx(i+1) = retval.cidx(i); \ + } \ } \ else if (nc == 0 && (nr == 0 || (nr == 1 && dim == -1))) \ { \ @@ -1761,12 +1761,12 @@ { \ retval.ridx (i) = 0; \ retval.cidx (i+1) = i; \ - retval.data (i) = MT_RESULT; \ - } \ + retval.data (i) = MT_RESULT; \ + } \ } \ else \ retval = RET_TYPE (static_cast<octave_idx_type> (1), nc, \ - static_cast<octave_idx_type> (0)); \ + static_cast<octave_idx_type> (0)); \ } \ else if (nc == 0 && dim == 1) \ { \ @@ -1776,14 +1776,14 @@ retval.cidx(0) = 0; \ retval.cidx(1) = nr; \ for (octave_idx_type i = 0; i < nr; i++) \ - { \ - retval.ridx(i) = i; \ - retval.data(i) = MT_RESULT; \ - } \ + { \ + retval.ridx(i) = i; \ + retval.data(i) = MT_RESULT; \ + } \ } \ else \ retval = RET_TYPE (nr, static_cast<octave_idx_type> (1), \ - static_cast<octave_idx_type> (0)); \ + static_cast<octave_idx_type> (0)); \ } \ else \ retval.resize (nr > 0, nc > 0); \ @@ -1796,11 +1796,11 @@ #define SPARSE_REDUCTION_OP_COL_EXPR(OP) \ tmp[j] OP data (i) -#define SPARSE_REDUCTION_OP(RET_TYPE, EL_TYPE, OP, INIT_VAL, MT_RESULT) \ +#define SPARSE_REDUCTION_OP(RET_TYPE, EL_TYPE, OP, INIT_VAL, MT_RESULT) \ SPARSE_BASE_REDUCTION_OP (RET_TYPE, EL_TYPE, \ - SPARSE_REDUCTION_OP_ROW_EXPR (OP), \ - SPARSE_REDUCTION_OP_COL_EXPR (OP), \ - INIT_VAL, MT_RESULT) + SPARSE_REDUCTION_OP_ROW_EXPR (OP), \ + SPARSE_REDUCTION_OP_COL_EXPR (OP), \ + INIT_VAL, MT_RESULT) // Don't break from this loop if the test succeeds because @@ -1819,9 +1819,9 @@ #define SPARSE_ANY_ALL_OP(DIM, INIT_VAL, MT_RESULT, TEST_OP, TEST_TRUE_VAL) \ SPARSE_BASE_REDUCTION_OP (SparseBoolMatrix, char, \ - SPARSE_ANY_ALL_OP_ROW_CODE (TEST_OP, TEST_TRUE_VAL), \ - SPARSE_ANY_ALL_OP_COL_CODE (TEST_OP, TEST_TRUE_VAL), \ - INIT_VAL, MT_RESULT) + SPARSE_ANY_ALL_OP_ROW_CODE (TEST_OP, TEST_TRUE_VAL), \ + SPARSE_ANY_ALL_OP_COL_CODE (TEST_OP, TEST_TRUE_VAL), \ + INIT_VAL, MT_RESULT) #define SPARSE_ALL_OP(DIM) \ if ((rows() == 1 && dim == -1) || dim == 1) \ @@ -1829,7 +1829,7 @@ else \ { \ SPARSE_ANY_ALL_OP (DIM, (cidx(j+1) - cidx(j) < nr ? false : true), \ - true, ==, false); \ + true, ==, false); \ } #define SPARSE_ANY_OP(DIM) SPARSE_ANY_ALL_OP (DIM, false, false, !=, true) @@ -1850,8 +1850,8 @@ for (octave_idx_type i = 0; i < nz; i++) \ { \ octave_quit (); \ - r.data(i) = s * a.data(i); \ - r.ridx(i) = a.ridx(i); \ + r.data(i) = s * a.data(i); \ + r.ridx(i) = a.ridx(i); \ } \ for (octave_idx_type i = 0; i < a_nc + 1; i++) \ { \ @@ -1871,8 +1871,8 @@ for (octave_idx_type i = 0; i < nz; i++) \ { \ octave_quit (); \ - r.data(i) = m.data(i) * s; \ - r.ridx(i) = m.ridx(i); \ + r.data(i) = m.data(i) * s; \ + r.ridx(i) = m.ridx(i); \ } \ for (octave_idx_type i = 0; i < nc + 1; i++) \ { \ @@ -1893,7 +1893,7 @@ OCTAVE_LOCAL_BUFFER (octave_idx_type, w, nr); \ RET_TYPE retval (nr, a_nc, static_cast<octave_idx_type> (0)); \ for (octave_idx_type i = 0; i < nr; i++) \ - w[i] = 0; \ + w[i] = 0; \ retval.xcidx(0) = 0; \ \ octave_idx_type nel = 0; \ @@ -1904,103 +1904,103 @@ { \ octave_idx_type col = a.ridx(j); \ for (octave_idx_type k = m.cidx(col) ; k < m.cidx(col+1); k++) \ - { \ - if (w[m.ridx(k)] < i + 1) \ + { \ + if (w[m.ridx(k)] < i + 1) \ { \ - w[m.ridx(k)] = i + 1; \ - nel++; \ - } \ - octave_quit (); \ - } \ - } \ + w[m.ridx(k)] = i + 1; \ + nel++; \ + } \ + octave_quit (); \ + } \ + } \ retval.xcidx(i+1) = nel; \ - } \ + } \ \ if (nel == 0) \ - return RET_TYPE (nr, a_nc); \ + return RET_TYPE (nr, a_nc); \ else \ - { \ + { \ for (octave_idx_type i = 0; i < nr; i++) \ - w[i] = 0; \ - \ + w[i] = 0; \ + \ OCTAVE_LOCAL_BUFFER (RET_EL_TYPE, Xcol, nr); \ \ - retval.change_capacity (nel); \ - /* The optimal break-point as estimated from simulations */ \ - /* Note that Mergesort is O(nz log(nz)) while searching all */ \ - /* values is O(nr), where nz here is non-zero per row of */ \ - /* length nr. The test itself was then derived from the */ \ - /* simulation with random square matrices and the observation */ \ - /* of the number of non-zero elements in the output matrix */ \ - /* it was found that the breakpoints were */ \ - /* nr: 500 1000 2000 5000 10000 */ \ - /* nz: 6 25 97 585 2202 */ \ - /* The below is a simplication of the 'polyfit'-ed parameters */ \ - /* to these breakpoints */ \ + retval.change_capacity (nel); \ + /* The optimal break-point as estimated from simulations */ \ + /* Note that Mergesort is O(nz log(nz)) while searching all */ \ + /* values is O(nr), where nz here is non-zero per row of */ \ + /* length nr. The test itself was then derived from the */ \ + /* simulation with random square matrices and the observation */ \ + /* of the number of non-zero elements in the output matrix */ \ + /* it was found that the breakpoints were */ \ + /* nr: 500 1000 2000 5000 10000 */ \ + /* nz: 6 25 97 585 2202 */ \ + /* The below is a simplication of the 'polyfit'-ed parameters */ \ + /* to these breakpoints */ \ octave_idx_type n_per_col = (a_nc > 43000 ? 43000 : \ - (a_nc * a_nc) / 43000); \ - octave_idx_type ii = 0; \ - octave_idx_type *ri = retval.xridx(); \ - octave_sort<octave_idx_type> sort; \ - \ - for (octave_idx_type i = 0; i < a_nc ; i++) \ - { \ - if (retval.xcidx(i+1) - retval.xcidx(i) > n_per_col) \ - { \ - for (octave_idx_type j = a.cidx(i); j < a.cidx(i+1); j++) \ - { \ - octave_idx_type col = a.ridx(j); \ - EL_TYPE tmpval = a.data(j); \ - for (octave_idx_type k = m.cidx(col) ; \ - k < m.cidx(col+1); k++) \ - { \ - octave_quit (); \ - octave_idx_type row = m.ridx(k); \ - if (w[row] < i + 1) \ - { \ - w[row] = i + 1; \ - Xcol[row] = tmpval * m.data(k); \ - } \ - else \ - Xcol[row] += tmpval * m.data(k); \ - } \ - } \ - for (octave_idx_type k = 0; k < nr; k++) \ - if (w[k] == i + 1) \ - { \ - retval.xdata(ii) = Xcol[k]; \ - retval.xridx(ii++) = k; \ - } \ - } \ - else \ - { \ - for (octave_idx_type j = a.cidx(i); j < a.cidx(i+1); j++) \ - { \ - octave_idx_type col = a.ridx(j); \ - EL_TYPE tmpval = a.data(j); \ - for (octave_idx_type k = m.cidx(col) ; \ - k < m.cidx(col+1); k++) \ - { \ - octave_quit (); \ - octave_idx_type row = m.ridx(k); \ - if (w[row] < i + 1) \ - { \ - w[row] = i + 1; \ - retval.xridx(ii++) = row;\ - Xcol[row] = tmpval * m.data(k); \ - } \ - else \ - Xcol[row] += tmpval * m.data(k); \ - } \ - } \ - sort.sort (ri + retval.xcidx(i), ii - retval.xcidx(i)); \ - for (octave_idx_type k = retval.xcidx(i); k < ii; k++) \ - retval.xdata(k) = Xcol[retval.xridx(k)]; \ - } \ - } \ - retval.maybe_compress (true);\ - return retval; \ - } \ + (a_nc * a_nc) / 43000); \ + octave_idx_type ii = 0; \ + octave_idx_type *ri = retval.xridx(); \ + octave_sort<octave_idx_type> sort; \ + \ + for (octave_idx_type i = 0; i < a_nc ; i++) \ + { \ + if (retval.xcidx(i+1) - retval.xcidx(i) > n_per_col) \ + { \ + for (octave_idx_type j = a.cidx(i); j < a.cidx(i+1); j++) \ + { \ + octave_idx_type col = a.ridx(j); \ + EL_TYPE tmpval = a.data(j); \ + for (octave_idx_type k = m.cidx(col) ; \ + k < m.cidx(col+1); k++) \ + { \ + octave_quit (); \ + octave_idx_type row = m.ridx(k); \ + if (w[row] < i + 1) \ + { \ + w[row] = i + 1; \ + Xcol[row] = tmpval * m.data(k); \ + } \ + else \ + Xcol[row] += tmpval * m.data(k); \ + } \ + } \ + for (octave_idx_type k = 0; k < nr; k++) \ + if (w[k] == i + 1) \ + { \ + retval.xdata(ii) = Xcol[k]; \ + retval.xridx(ii++) = k; \ + } \ + } \ + else \ + { \ + for (octave_idx_type j = a.cidx(i); j < a.cidx(i+1); j++) \ + { \ + octave_idx_type col = a.ridx(j); \ + EL_TYPE tmpval = a.data(j); \ + for (octave_idx_type k = m.cidx(col) ; \ + k < m.cidx(col+1); k++) \ + { \ + octave_quit (); \ + octave_idx_type row = m.ridx(k); \ + if (w[row] < i + 1) \ + { \ + w[row] = i + 1; \ + retval.xridx(ii++) = row;\ + Xcol[row] = tmpval * m.data(k); \ + } \ + else \ + Xcol[row] += tmpval * m.data(k); \ + } \ + } \ + sort.sort (ri + retval.xcidx(i), ii - retval.xcidx(i)); \ + for (octave_idx_type k = retval.xcidx(i); k < ii; k++) \ + retval.xdata(k) = Xcol[retval.xridx(k)]; \ + } \ + } \ + retval.maybe_compress (true);\ + return retval; \ + } \ } #define SPARSE_FULL_MUL( RET_TYPE, EL_TYPE, ZERO ) \