Line | |
---|
1 | /* |
---|
2 | * $Id: veccount.cc,v 1.3 2003/12/11 03:44:22 julianc Exp $ |
---|
3 | * |
---|
4 | * Copyright (C) 1997 Todd Veldhuizen <tveldhui@oonumerics.org> |
---|
5 | * All rights reserved. Please see <blitz/blitz.h> for terms and |
---|
6 | * conditions of use. |
---|
7 | * |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef BZ_VECCOUNT_CC |
---|
11 | #define BZ_VECCOUNT_CC |
---|
12 | |
---|
13 | #ifndef BZ_VECGLOBS_H |
---|
14 | #error <blitz/veccount.cc> must be included via <blitz/vecglobs.h> |
---|
15 | #endif |
---|
16 | |
---|
17 | BZ_NAMESPACE(blitz) |
---|
18 | |
---|
19 | template<typename P_expr> |
---|
20 | inline int _bz_vec_count(P_expr vector) |
---|
21 | { |
---|
22 | int length = vector._bz_suggestLength(); |
---|
23 | int count = 0; |
---|
24 | |
---|
25 | if (vector._bz_hasFastAccess()) |
---|
26 | { |
---|
27 | for (int i=0; i < length; ++i) |
---|
28 | if (vector._bz_fastAccess(i)) |
---|
29 | ++count; |
---|
30 | } |
---|
31 | else { |
---|
32 | for (int i=0; i < length; ++i) |
---|
33 | if (vector[i]) |
---|
34 | ++count; |
---|
35 | } |
---|
36 | |
---|
37 | return count; |
---|
38 | } |
---|
39 | |
---|
40 | template<typename P_numtype> |
---|
41 | inline int count(const Vector<P_numtype>& x) |
---|
42 | { |
---|
43 | return _bz_vec_count(x._bz_asVecExpr()); |
---|
44 | } |
---|
45 | |
---|
46 | template<typename P_expr> |
---|
47 | inline int count(_bz_VecExpr<P_expr> expr) |
---|
48 | { |
---|
49 | return _bz_vec_count(expr); |
---|
50 | } |
---|
51 | |
---|
52 | template<typename P_numtype> |
---|
53 | inline int count(const VectorPick<P_numtype>& x) |
---|
54 | { |
---|
55 | return _bz_vec_count(x._bz_asVecExpr()); |
---|
56 | } |
---|
57 | |
---|
58 | template<typename P_numtype, int N_dimensions> |
---|
59 | inline int count(const TinyVector<P_numtype, N_dimensions>& x) |
---|
60 | { |
---|
61 | return _bz_vec_count(x._bz_asVecExpr()); |
---|
62 | } |
---|
63 | |
---|
64 | BZ_NAMESPACE_END |
---|
65 | |
---|
66 | #endif // BZ_VECCOUNT_CC |
---|
67 | |
---|
Note: See
TracBrowser
for help on using the repository browser.