comparison liboctave/Sparse-op-defs.h @ 5681:233d98d95659

[project @ 2006-03-16 17:48:55 by dbateman]
author dbateman
date Thu, 16 Mar 2006 17:48:56 +0000
parents 2857357f9d3c
children ace8d8d26933
comparison
equal deleted inserted replaced
5680:cc6a965ae4ca 5681:233d98d95659
61 R \ 61 R \
62 F (const M& m, const S& s) \ 62 F (const M& m, const S& s) \
63 { \ 63 { \
64 octave_idx_type nr = m.rows (); \ 64 octave_idx_type nr = m.rows (); \
65 octave_idx_type nc = m.cols (); \ 65 octave_idx_type nc = m.cols (); \
66 octave_idx_type nz = m.nzmax (); \ 66 octave_idx_type nz = m.nnz (); \
67 \ 67 \
68 R r (nr, nc, nz); \ 68 R r (nr, nc, nz); \
69 \ 69 \
70 for (octave_idx_type i = 0; i < nz; i++) \ 70 for (octave_idx_type i = 0; i < nz; i++) \
71 { \ 71 { \
101 SparseBoolMatrix \ 101 SparseBoolMatrix \
102 F (const M& m, const S& s) \ 102 F (const M& m, const S& s) \
103 { \ 103 { \
104 /* Count num of non-zero elements */ \ 104 /* Count num of non-zero elements */ \
105 octave_idx_type nel = 0; \ 105 octave_idx_type nel = 0; \
106 octave_idx_type nz = m.nzmax (); \ 106 octave_idx_type nz = m.nnz (); \
107 if (MC (MZ) OP SC (s)) \ 107 if (MC (MZ) OP SC (s)) \
108 nel += m.numel() - nz; \ 108 nel += m.numel() - nz; \
109 for (octave_idx_type i = 0; i < nz; i++) \ 109 for (octave_idx_type i = 0; i < nz; i++) \
110 if (MC (m.data (i)) OP SC (s)) \ 110 if (MC (m.data (i)) OP SC (s)) \
111 nel++; \ 111 nel++; \
176 SparseBoolMatrix \ 176 SparseBoolMatrix \
177 F (const M& m, const S& s) \ 177 F (const M& m, const S& s) \
178 { \ 178 { \
179 /* Count num of non-zero elements */ \ 179 /* Count num of non-zero elements */ \
180 octave_idx_type nel = 0; \ 180 octave_idx_type nel = 0; \
181 octave_idx_type nz = m.nzmax (); \ 181 octave_idx_type nz = m.nnz (); \
182 if (LHS_ZERO OP (s != RHS_ZERO)) \ 182 if (LHS_ZERO OP (s != RHS_ZERO)) \
183 nel += m.numel() - nz; \ 183 nel += m.numel() - nz; \
184 for (octave_idx_type i = 0; i < nz; i++) \ 184 for (octave_idx_type i = 0; i < nz; i++) \
185 if ((m.data(i) != LHS_ZERO) OP (s != RHS_ZERO))\ 185 if ((m.data(i) != LHS_ZERO) OP (s != RHS_ZERO))\
186 nel++; \ 186 nel++; \
271 R \ 271 R \
272 F (const S& s, const M& m) \ 272 F (const S& s, const M& m) \
273 { \ 273 { \
274 octave_idx_type nr = m.rows (); \ 274 octave_idx_type nr = m.rows (); \
275 octave_idx_type nc = m.cols (); \ 275 octave_idx_type nc = m.cols (); \
276 octave_idx_type nz = m.nzmax (); \ 276 octave_idx_type nz = m.nnz (); \
277 \ 277 \
278 R r (nr, nc, nz); \ 278 R r (nr, nc, nz); \
279 \ 279 \
280 for (octave_idx_type i = 0; i < nz; i++) \ 280 for (octave_idx_type i = 0; i < nz; i++) \
281 { \ 281 { \
311 SparseBoolMatrix \ 311 SparseBoolMatrix \
312 F (const S& s, const M& m) \ 312 F (const S& s, const M& m) \
313 { \ 313 { \
314 /* Count num of non-zero elements */ \ 314 /* Count num of non-zero elements */ \
315 octave_idx_type nel = 0; \ 315 octave_idx_type nel = 0; \
316 octave_idx_type nz = m.nzmax (); \ 316 octave_idx_type nz = m.nnz (); \
317 if (SC (s) OP MC (MZ)) \ 317 if (SC (s) OP MC (MZ)) \
318 nel += m.numel() - nz; \ 318 nel += m.numel() - nz; \
319 for (octave_idx_type i = 0; i < nz; i++) \ 319 for (octave_idx_type i = 0; i < nz; i++) \
320 if (SC (s) OP MC (m.data (i))) \ 320 if (SC (s) OP MC (m.data (i))) \
321 nel++; \ 321 nel++; \
386 SparseBoolMatrix \ 386 SparseBoolMatrix \
387 F (const S& s, const M& m) \ 387 F (const S& s, const M& m) \
388 { \ 388 { \
389 /* Count num of non-zero elements */ \ 389 /* Count num of non-zero elements */ \
390 octave_idx_type nel = 0; \ 390 octave_idx_type nel = 0; \
391 octave_idx_type nz = m.nzmax (); \ 391 octave_idx_type nz = m.nnz (); \
392 if ((s != LHS_ZERO) OP RHS_ZERO) \ 392 if ((s != LHS_ZERO) OP RHS_ZERO) \
393 nel += m.numel() - nz; \ 393 nel += m.numel() - nz; \
394 for (octave_idx_type i = 0; i < nz; i++) \ 394 for (octave_idx_type i = 0; i < nz; i++) \
395 if ((s != LHS_ZERO) OP m.data(i) != RHS_ZERO) \ 395 if ((s != LHS_ZERO) OP m.data(i) != RHS_ZERO) \
396 nel++; \ 396 nel++; \
475 \ 475 \
476 if (m1_nr != m2_nr || m1_nc != m2_nc) \ 476 if (m1_nr != m2_nr || m1_nc != m2_nc) \
477 gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ 477 gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \
478 else \ 478 else \
479 { \ 479 { \
480 r = R (m1_nr, m1_nc, (m1.nzmax () + m2.nzmax ())); \ 480 r = R (m1_nr, m1_nc, (m1.nnz () + m2.nnz ())); \
481 \ 481 \
482 octave_idx_type jx = 0; \ 482 octave_idx_type jx = 0; \
483 r.cidx (0) = 0; \ 483 r.cidx (0) = 0; \
484 for (octave_idx_type i = 0 ; i < m1_nc ; i++) \ 484 for (octave_idx_type i = 0 ; i < m1_nc ; i++) \
485 { \ 485 { \
549 \ 549 \
550 if (m1_nr != m2_nr || m1_nc != m2_nc) \ 550 if (m1_nr != m2_nr || m1_nc != m2_nc) \
551 gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ 551 gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \
552 else \ 552 else \
553 { \ 553 { \
554 r = R (m1_nr, m1_nc, (m1.nzmax () > m2.nzmax () ? m1.nzmax () : m2.nzmax ())); \ 554 r = R (m1_nr, m1_nc, (m1.nnz () > m2.nnz () ? m1.nnz () : m2.nnz ())); \
555 \ 555 \
556 octave_idx_type jx = 0; \ 556 octave_idx_type jx = 0; \
557 r.cidx (0) = 0; \ 557 r.cidx (0) = 0; \
558 for (octave_idx_type i = 0 ; i < m1_nc ; i++) \ 558 for (octave_idx_type i = 0 ; i < m1_nc ; i++) \
559 { \ 559 { \
1531 1531
1532 #define SPARSE_ALL_OP(DIM) SPARSE_ANY_ALL_OP (DIM, true, ==, false) 1532 #define SPARSE_ALL_OP(DIM) SPARSE_ANY_ALL_OP (DIM, true, ==, false)
1533 1533
1534 #define SPARSE_ANY_OP(DIM) SPARSE_ANY_ALL_OP (DIM, false, !=, true) 1534 #define SPARSE_ANY_OP(DIM) SPARSE_ANY_ALL_OP (DIM, false, !=, true)
1535 1535
1536 #define SPARSE_SPARSE_MUL( RET_TYPE, EL_TYPE ) \ 1536 #define SPARSE_SPARSE_MUL( RET_TYPE, RET_EL_TYPE, EL_TYPE ) \
1537 octave_idx_type nr = m.rows (); \ 1537 octave_idx_type nr = m.rows (); \
1538 octave_idx_type nc = m.cols (); \ 1538 octave_idx_type nc = m.cols (); \
1539 \ 1539 \
1540 octave_idx_type a_nr = a.rows (); \ 1540 octave_idx_type a_nr = a.rows (); \
1541 octave_idx_type a_nc = a.cols (); \ 1541 octave_idx_type a_nc = a.cols (); \
1575 else \ 1575 else \
1576 { \ 1576 { \
1577 for (octave_idx_type i = 0; i < nr; i++) \ 1577 for (octave_idx_type i = 0; i < nr; i++) \
1578 w[i] = 0; \ 1578 w[i] = 0; \
1579 \ 1579 \
1580 OCTAVE_LOCAL_BUFFER (EL_TYPE, Xcol, nr); \ 1580 OCTAVE_LOCAL_BUFFER (RET_EL_TYPE, Xcol, nr); \
1581 \ 1581 \
1582 RET_TYPE retval (nr, a_nc, nel); \ 1582 RET_TYPE retval (nr, a_nc, nel); \
1583 octave_idx_type ii = 0; \ 1583 octave_idx_type ii = 0; \
1584 /* The optimal break-point as estimated from simulations */ \ 1584 /* The optimal break-point as estimated from simulations */ \
1585 /* Note that Mergesort is O(nz log(nz)) while searching all */ \ 1585 /* Note that Mergesort is O(nz log(nz)) while searching all */ \
1661 } \ 1661 } \
1662 return retval; \ 1662 return retval; \
1663 } \ 1663 } \
1664 } 1664 }
1665 1665
1666 #define SPARSE_FULL_MUL( RET_TYPE, EL_TYPE ) \ 1666 #define SPARSE_FULL_MUL( RET_TYPE, EL_TYPE, ZERO ) \
1667 octave_idx_type nr = m.rows (); \ 1667 octave_idx_type nr = m.rows (); \
1668 octave_idx_type nc = m.cols (); \ 1668 octave_idx_type nc = m.cols (); \
1669 \ 1669 \
1670 octave_idx_type a_nr = a.rows (); \ 1670 octave_idx_type a_nr = a.rows (); \
1671 octave_idx_type a_nc = a.cols (); \ 1671 octave_idx_type a_nc = a.cols (); \
1675 gripe_nonconformant ("operator *", nr, nc, a_nr, a_nc); \ 1675 gripe_nonconformant ("operator *", nr, nc, a_nr, a_nc); \
1676 return RET_TYPE (); \ 1676 return RET_TYPE (); \
1677 } \ 1677 } \
1678 else \ 1678 else \
1679 { \ 1679 { \
1680 RET_TYPE retval (nr, a_nc, EL_TYPE ()); \ 1680 RET_TYPE retval (nr, a_nc, ZERO); \
1681 \ 1681 \
1682 for (octave_idx_type i = 0; i < a_nc ; i++) \ 1682 for (octave_idx_type i = 0; i < a_nc ; i++) \
1683 { \ 1683 { \
1684 for (octave_idx_type j = 0; j < a_nr; j++) \ 1684 for (octave_idx_type j = 0; j < a_nr; j++) \
1685 { \ 1685 { \
1691 } \ 1691 } \
1692 } \ 1692 } \
1693 return retval; \ 1693 return retval; \
1694 } 1694 }
1695 1695
1696 #define FULL_SPARSE_MUL( RET_TYPE, EL_TYPE ) \ 1696 #define FULL_SPARSE_MUL( RET_TYPE, EL_TYPE, ZERO ) \
1697 octave_idx_type nr = m.rows (); \ 1697 octave_idx_type nr = m.rows (); \
1698 octave_idx_type nc = m.cols (); \ 1698 octave_idx_type nc = m.cols (); \
1699 \ 1699 \
1700 octave_idx_type a_nr = a.rows (); \ 1700 octave_idx_type a_nr = a.rows (); \
1701 octave_idx_type a_nc = a.cols (); \ 1701 octave_idx_type a_nc = a.cols (); \
1705 gripe_nonconformant ("operator *", nr, nc, a_nr, a_nc); \ 1705 gripe_nonconformant ("operator *", nr, nc, a_nr, a_nc); \
1706 return RET_TYPE (); \ 1706 return RET_TYPE (); \
1707 } \ 1707 } \
1708 else \ 1708 else \
1709 { \ 1709 { \
1710 RET_TYPE retval (nr, a_nc, EL_TYPE ()); \ 1710 RET_TYPE retval (nr, a_nc, ZERO); \
1711 \ 1711 \
1712 for (octave_idx_type i = 0; i < a_nc ; i++) \ 1712 for (octave_idx_type i = 0; i < a_nc ; i++) \
1713 { \ 1713 { \
1714 for (octave_idx_type j = a.cidx(i); j < a.cidx(i+1); j++) \ 1714 for (octave_idx_type j = a.cidx(i); j < a.cidx(i+1); j++) \
1715 { \ 1715 { \