| 1 | /* | 
|---|
| 2 | * $Id: veccount.cc,v 1.1.1.1 1999-04-09 17:59:01 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.2  1998/03/14 00:04:47  tveldhui | 
|---|
| 10 | * 0.2-alpha-05 | 
|---|
| 11 | * | 
|---|
| 12 | * Revision 1.1  1997/07/16 14:51:20  tveldhui | 
|---|
| 13 | * Update: Alpha release 0.2 (Arrays) | 
|---|
| 14 | * | 
|---|
| 15 | */ | 
|---|
| 16 |  | 
|---|
| 17 | #ifndef BZ_VECCOUNT_CC | 
|---|
| 18 | #define BZ_VECCOUNT_CC | 
|---|
| 19 |  | 
|---|
| 20 | #ifndef BZ_VECGLOBS_H | 
|---|
| 21 | #error <blitz/veccount.cc> must be included via <blitz/vecglobs.h> | 
|---|
| 22 | #endif | 
|---|
| 23 |  | 
|---|
| 24 | BZ_NAMESPACE(blitz) | 
|---|
| 25 |  | 
|---|
| 26 | template<class P_expr> | 
|---|
| 27 | inline int _bz_vec_count(P_expr vector) | 
|---|
| 28 | { | 
|---|
| 29 | int length = vector._bz_suggestLength(); | 
|---|
| 30 | int count = 0; | 
|---|
| 31 |  | 
|---|
| 32 | if (vector._bz_hasFastAccess()) | 
|---|
| 33 | { | 
|---|
| 34 | for (int i=0; i < length; ++i) | 
|---|
| 35 | if (vector._bz_fastAccess(i)) | 
|---|
| 36 | ++count; | 
|---|
| 37 | } | 
|---|
| 38 | else { | 
|---|
| 39 | for (int i=0; i < length; ++i) | 
|---|
| 40 | if (vector[i]) | 
|---|
| 41 | ++count; | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 | return count; | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 | template<class P_numtype> | 
|---|
| 48 | inline int count(const Vector<P_numtype>& x) | 
|---|
| 49 | { | 
|---|
| 50 | return _bz_vec_count(x._bz_asVecExpr()); | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | template<class P_expr> | 
|---|
| 54 | inline int count(_bz_VecExpr<P_expr> expr) | 
|---|
| 55 | { | 
|---|
| 56 | return _bz_vec_count(expr); | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | template<class P_numtype> | 
|---|
| 60 | inline int count(const VectorPick<P_numtype>& x) | 
|---|
| 61 | { | 
|---|
| 62 | return _bz_vec_count(x._bz_asVecExpr()); | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 | template<class P_numtype, int N_dimensions> | 
|---|
| 66 | inline int count(const TinyVector<P_numtype, N_dimensions>& x) | 
|---|
| 67 | { | 
|---|
| 68 | return _bz_vec_count(x._bz_asVecExpr()); | 
|---|
| 69 | } | 
|---|
| 70 |  | 
|---|
| 71 | BZ_NAMESPACE_END | 
|---|
| 72 |  | 
|---|
| 73 | #endif // BZ_VECCOUNT_CC | 
|---|
| 74 |  | 
|---|