| 1 | /*
|
|---|
| 2 | * $Id: veccount.cc,v 1.1.1.1 1999-11-26 16:37:05 ansari Exp $
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright (C) 1997 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
|
|---|
| 5 | * All rights reserved. Please see <blitz/blitz.h> for terms and
|
|---|
| 6 | * conditions of use.
|
|---|
| 7 | *
|
|---|
| 8 | * $Log: not supported by cvs2svn $
|
|---|
| 9 | // Revision 1.1.1.1 1999/04/09 17:59:01 ansari
|
|---|
| 10 | // Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99
|
|---|
| 11 | //
|
|---|
| 12 | * Revision 1.2 1998/03/14 00:04:47 tveldhui
|
|---|
| 13 | * 0.2-alpha-05
|
|---|
| 14 | *
|
|---|
| 15 | * Revision 1.1 1997/07/16 14:51:20 tveldhui
|
|---|
| 16 | * Update: Alpha release 0.2 (Arrays)
|
|---|
| 17 | *
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | #ifndef BZ_VECCOUNT_CC
|
|---|
| 21 | #define BZ_VECCOUNT_CC
|
|---|
| 22 |
|
|---|
| 23 | #ifndef BZ_VECGLOBS_H
|
|---|
| 24 | #error <blitz/veccount.cc> must be included via <blitz/vecglobs.h>
|
|---|
| 25 | #endif
|
|---|
| 26 |
|
|---|
| 27 | BZ_NAMESPACE(blitz)
|
|---|
| 28 |
|
|---|
| 29 | template<class P_expr>
|
|---|
| 30 | inline int _bz_vec_count(P_expr vector)
|
|---|
| 31 | {
|
|---|
| 32 | int length = vector._bz_suggestLength();
|
|---|
| 33 | int count = 0;
|
|---|
| 34 |
|
|---|
| 35 | if (vector._bz_hasFastAccess())
|
|---|
| 36 | {
|
|---|
| 37 | for (int i=0; i < length; ++i)
|
|---|
| 38 | if (vector._bz_fastAccess(i))
|
|---|
| 39 | ++count;
|
|---|
| 40 | }
|
|---|
| 41 | else {
|
|---|
| 42 | for (int i=0; i < length; ++i)
|
|---|
| 43 | if (vector[i])
|
|---|
| 44 | ++count;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | return count;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | template<class P_numtype>
|
|---|
| 51 | inline int count(const Vector<P_numtype>& x)
|
|---|
| 52 | {
|
|---|
| 53 | return _bz_vec_count(x._bz_asVecExpr());
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | template<class P_expr>
|
|---|
| 57 | inline int count(_bz_VecExpr<P_expr> expr)
|
|---|
| 58 | {
|
|---|
| 59 | return _bz_vec_count(expr);
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | template<class P_numtype>
|
|---|
| 63 | inline int count(const VectorPick<P_numtype>& x)
|
|---|
| 64 | {
|
|---|
| 65 | return _bz_vec_count(x._bz_asVecExpr());
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | template<class P_numtype, int N_dimensions>
|
|---|
| 69 | inline int count(const TinyVector<P_numtype, N_dimensions>& x)
|
|---|
| 70 | {
|
|---|
| 71 | return _bz_vec_count(x._bz_asVecExpr());
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | BZ_NAMESPACE_END
|
|---|
| 75 |
|
|---|
| 76 | #endif // BZ_VECCOUNT_CC
|
|---|
| 77 |
|
|---|