00001 #ifndef _SPARSEINSTANCE_H 00002 #define _SPARSEINSTANCE_H 00003 #include "osl/stl/vector.h" 00004 #include "osl/misc/fixedCapacityVector.h" 00005 #include <iosfwd> 00006 namespace osl 00007 { 00008 namespace stat 00009 { 00010 struct SparseElement 00011 { 00012 unsigned int index; 00013 int value; 00017 SparseElement() 00018 { 00019 } 00020 SparseElement(unsigned int i, int v) : index(i), value(v) 00021 { 00022 } 00023 }; 00024 struct SparseInstance : public vector<SparseElement> 00025 { 00026 double dot_product(const double *weight, double initial=0) const 00027 { 00028 double sum = initial; 00029 for (const_iterator p=begin(); p!=end(); ++p) 00030 sum += p->value * weight[p->index]; 00031 return sum; 00032 } 00033 }; 00034 std::ostream& operator<<(std::ostream&, const SparseInstance&); 00035 00036 template <int SIZE> 00037 struct SparseInstanceFixed 00038 : public FixedCapacityVector<SparseElement, SIZE> 00039 { 00040 }; 00041 00042 typedef vector<SparseInstance> SparseInstanceVector; 00043 } // namespace stat 00044 } // namespace osl 00045 00046 #endif /* _SPARSEINSTANCE_H */ 00047 // ;;; Local Variables: 00048 // ;;; mode:c++ 00049 // ;;; c-basic-offset:2 00050 // ;;; End: