source: Sophya/trunk/SophyaExt/Blitz/blitz/veccount.cc@ 3670

Last change on this file since 3670 was 221, checked in by ansari, 26 years ago

Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99

File size: 1.5 KB
Line 
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
24BZ_NAMESPACE(blitz)
25
26template<class P_expr>
27inline 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
47template<class P_numtype>
48inline int count(const Vector<P_numtype>& x)
49{
50 return _bz_vec_count(x._bz_asVecExpr());
51}
52
53template<class P_expr>
54inline int count(_bz_VecExpr<P_expr> expr)
55{
56 return _bz_vec_count(expr);
57}
58
59template<class P_numtype>
60inline int count(const VectorPick<P_numtype>& x)
61{
62 return _bz_vec_count(x._bz_asVecExpr());
63}
64
65template<class P_numtype, int N_dimensions>
66inline int count(const TinyVector<P_numtype, N_dimensions>& x)
67{
68 return _bz_vec_count(x._bz_asVecExpr());
69}
70
71BZ_NAMESPACE_END
72
73#endif // BZ_VECCOUNT_CC
74
Note: See TracBrowser for help on using the repository browser.