summaryrefslogtreecommitdiff
path: root/utils/ts.cc
diff options
context:
space:
mode:
Diffstat (limited to 'utils/ts.cc')
-rw-r--r--utils/ts.cc41
1 files changed, 31 insertions, 10 deletions
diff --git a/utils/ts.cc b/utils/ts.cc
index 1febed3c..28b5f9b1 100644
--- a/utils/ts.cc
+++ b/utils/ts.cc
@@ -10,25 +10,46 @@
using namespace std;
+template <typename T>
+void Print(const T& x) {
+ typename T::const_iterator it = x.begin();
+ for (; it != x.end(); ++it) {
+ cerr << it->first << ":" << it->second << " ";
+ }
+ cerr << endl;
+}
+
+template <typename T>
+void test_unique() {
+ T x;
+ x.set_value(100, 1.0);
+ x.set_value(100, 2.0);
+ Print(x);
+ assert(x.size() == 1);
+ assert(x.value(100) == 2.0);
+}
+
int main() {
cerr << sizeof(prob_t) << " " << sizeof(LogVal<float>) << endl;
cerr << " sizeof(FSV<float>) = " << sizeof(FastSparseVector<float>) << endl;
cerr << "sizeof(FSV<double>) = " << sizeof(FastSparseVector<double>) << endl;
- sranddev();
+ test_unique<FastSparseVector<float> >();
+// sranddev();
int c = 0;
+ FastSparseVector<float> p;
for (int i = 0; i < 1000000; ++i) {
FastSparseVector<float> x;
- //SparseVector<float> x;
- for (int j = 0; j < 15; ++j) {
- const int k = rand() % 1000;
- const float v = rand() / 3.14f;
+ for (int j = 0; j < 10; ++j) {
+ const int k = rand() % 200;
+ const float v = 1000.0f / rand();
x.set_value(k,v);
}
- //SparseVector<float> y = x;
- FastSparseVector<float> y = x;
- y += x;
- y = x;
- if (y.value(50)) { c++; }
+ if (x.value(50)) { c++; }
+ p = x;
+ p += p;
+ FastSparseVector<float> y = p + p;
+ y *= 2;
+ y -= y;
}
cerr << "Counted " << c << " times\n";
return 0;