00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SELDON_FILE_SPARSE_VECTOR_HXX
00022
00023 namespace Seldon
00024 {
00025
00026
00028 template <class T, class Allocator>
00029 class Vector<T, VectSparse, Allocator>:
00030 public Vector<T, VectFull, Allocator>
00031 {
00032
00033 public:
00034 typedef typename Allocator::value_type value_type;
00035 typedef typename Allocator::pointer pointer;
00036 typedef typename Allocator::const_pointer const_pointer;
00037 typedef typename Allocator::reference reference;
00038 typedef typename Allocator::const_reference const_reference;
00039
00040 typedef VectSparse storage;
00041
00042 protected :
00043 static SELDON_DEFAULT_ALLOCATOR<int> index_allocator_;
00044
00045
00046 private:
00048 int* index_;
00049
00050
00051 public:
00052
00053 explicit Vector();
00054 explicit Vector(int i);
00055 Vector(const Vector<T, VectSparse, Allocator>& A);
00056
00057
00058 ~Vector();
00059 void Clear();
00060
00061
00062 void Reallocate(int i);
00063 void Resize(int i);
00064 void SetData(int nz, T* data, int* index);
00065 template<class Allocator2>
00066 void SetData(Vector<T, VectFull, Allocator2>& data,
00067 Vector<int>& index);
00068 template<class Allocator2>
00069 void SetData(const Vector<T, VectSparse, Allocator2>& V);
00070 void Nullify();
00071
00072
00073 reference Value(int i);
00074 #ifndef SWIG
00075 const_reference Value(int i) const;
00076 #endif
00077 int& Index(int i);
00078 #ifndef SWIG
00079 int Index(int i) const;
00080 #endif
00081
00082 value_type operator() (int i) const;
00083 reference Get(int i);
00084 reference Val(int i);
00085 #ifndef SWIG
00086 const_reference Get(int i) const;
00087 const_reference Val(int i) const;
00088 Vector<T, VectSparse, Allocator>& operator= (const Vector<T, VectSparse,
00089 Allocator>& X);
00090 #endif
00091 void Copy(const Vector<T, VectSparse, Allocator>& X);
00092
00093
00094 int* GetIndex() const;
00095
00096
00097 template <class T0>
00098 #ifndef SWIG
00099 Vector<T, VectSparse, Allocator>& operator= (const T0& X);
00100 #endif
00101 void Print() const;
00102 void Assemble();
00103 template<class T0>
00104 void RemoveSmallEntry(const T0& epsilon);
00105 void AddInteraction(int i, const T& val);
00106 void AddInteractionRow(int, int*, T*, bool already_sorted = false);
00107 template<class Allocator0>
00108 void AddInteractionRow(int nb, Vector<int> col,
00109 Vector<T, VectFull, Allocator0> val,
00110 bool already_sorted = false);
00111
00112
00113 void Write(string FileName) const;
00114 void Write(ostream& FileStream) const;
00115 void WriteText(string FileName) const;
00116 void WriteText(ostream& FileStream) const;
00117 void Read(string FileName);
00118 void Read(istream& FileStream);
00119 void ReadText(string FileName);
00120 void ReadText(istream& FileStream);
00121
00122 };
00123
00124 #ifndef SWIG
00125 template <class T, class Allocator>
00126 ostream& operator << (ostream& out,
00127 const Vector<T, VectSparse, Allocator>& V);
00128 #endif
00129
00130
00131 template<class T, class Allocator>
00132 SELDON_DEFAULT_ALLOCATOR<int>
00133 Vector<T, VectSparse, Allocator>::index_allocator_;
00134
00135
00136 }
00137
00138 #define SELDON_FILE_SPARSE_VECTOR_HXX
00139 #endif