|
| 1 | +From 4a1e1395804d4630ec556c61ba3f2cb67e140248 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jean-Guillaume Dumas < [email protected]> |
| 3 | +Date: Thu, 5 Dec 2024 15:38:58 +0100 |
| 4 | +Subject: [PATCH] solving issue #319 |
| 5 | + |
| 6 | +--- |
| 7 | + linbox/vector/blas-subvector.h | 52 +++++++++++++++++----------------- |
| 8 | + tests/test-subvector.C | 6 ++++ |
| 9 | + 2 files changed, 32 insertions(+), 26 deletions(-) |
| 10 | + |
| 11 | +diff --git a/linbox/vector/blas-subvector.h b/linbox/vector/blas-subvector.h |
| 12 | +index e1582723c3d4488504ca1473dec7260c33a06a23..8f290dd4362872a6b98a08b4e775ad66b5cde2dd 100644 |
| 13 | +--- a/linbox/vector/blas-subvector.h |
| 14 | ++++ b/linbox/vector/blas-subvector.h |
| 15 | +@@ -1,6 +1,6 @@ |
| 16 | + /* linbox/matrix/blas-vector.h |
| 17 | + * Copyright (C) 2013 the LinBox group |
| 18 | +- * 2019 Pascal Giorgi |
| 19 | ++ * 2019 Pascal Giorgi |
| 20 | + * |
| 21 | + * Written by : |
| 22 | + |
| 23 | +@@ -45,7 +45,7 @@ namespace LinBox { |
| 24 | + // forward declaration |
| 25 | + template <class Field, class Storage> |
| 26 | + class BlasVector; |
| 27 | +- |
| 28 | ++ |
| 29 | + |
| 30 | + template <typename _Vector> |
| 31 | + class VectorEltPointer { |
| 32 | +@@ -61,7 +61,7 @@ namespace LinBox { |
| 33 | + typedef typename _Vector::Storage::const_reference reference; |
| 34 | + using Element=const typename _Vector::Field::Element; |
| 35 | + }; |
| 36 | +- |
| 37 | ++ |
| 38 | + template<class _Vector> |
| 39 | + class BlasSubvector { |
| 40 | + |
| 41 | +@@ -88,7 +88,7 @@ namespace LinBox { |
| 42 | + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 43 | + |
| 44 | + protected: |
| 45 | +- pointer _ptr; |
| 46 | ++ pointer _ptr; |
| 47 | + size_t _size; |
| 48 | + size_t _inc; |
| 49 | + Field const*_field; |
| 50 | +@@ -101,7 +101,7 @@ namespace LinBox { |
| 51 | + ////////////////// |
| 52 | + |
| 53 | + BlasSubvector(){} |
| 54 | +- |
| 55 | ++ |
| 56 | + /** Constructor from an existing @ref BlasVector and dimensions. |
| 57 | + * \param V Pointer to @ref BlasVector of which to construct subvector |
| 58 | + * \param beg Starting idx |
| 59 | +@@ -110,7 +110,7 @@ namespace LinBox { |
| 60 | + */ |
| 61 | + BlasSubvector (vectorType &V, size_t beg, size_t inc, size_t dim) : |
| 62 | + _ptr(V.getPointer()+beg), _size(dim), _inc(inc), _field(&V.field()) {} |
| 63 | +- |
| 64 | ++ |
| 65 | + /** Constructor from an existing @ref BlasSubvector and dimensions. |
| 66 | + * \param V Pointer to @ref DenseSubector of which to construct subvector |
| 67 | + * \param beg Starting idx |
| 68 | +@@ -118,9 +118,9 @@ namespace LinBox { |
| 69 | + * \param inc distance between two element |
| 70 | + */ |
| 71 | + BlasSubvector (Self_t &V, size_t beg, size_t inc, size_t dim) : |
| 72 | +- _ptr(V.data()+beg), _size(dim), _inc(inc), _field(&V.field()) {} |
| 73 | ++ _ptr(V.getPointer()+beg), _size(dim), _inc(inc), _field(&V.field()) {} |
| 74 | ++ |
| 75 | + |
| 76 | +- |
| 77 | + /** Constructor from an existing @ref BlasVector |
| 78 | + * \param V Pointer to @ref BlasVector of which to construct submatrix |
| 79 | + */ |
| 80 | +@@ -132,17 +132,17 @@ namespace LinBox { |
| 81 | + */ |
| 82 | + BlasSubvector (const Field& F, pointer ptr, size_t inc, size_t dim) : |
| 83 | + _ptr(ptr), _size(dim), _inc(inc), _field(&F) {} |
| 84 | +- |
| 85 | +- |
| 86 | ++ |
| 87 | ++ |
| 88 | + |
| 89 | + BlasSubvector (const Field& F, std::vector<Element>& v) : |
| 90 | +- _ptr(v.data()), _size(v.size()), _inc(1), _field(&F) |
| 91 | ++ _ptr(v.data()), _size(v.size()), _inc(1), _field(&F) |
| 92 | + { |
| 93 | + std::cerr<<"WARNING "<<__LINE__<<" ("<<__FILE__<<") : creating a BlasSubvector from a std::vector -> MUST BE DEPRECATED"<<std::endl; |
| 94 | + throw LinBoxError("Deprecated Subvector cstor from std::vector"); |
| 95 | + } |
| 96 | +- |
| 97 | +- |
| 98 | ++ |
| 99 | ++ |
| 100 | + |
| 101 | + /** Copy operator */ |
| 102 | + BlasSubvector& operator= (const BlasSubvector& V){ |
| 103 | +@@ -157,18 +157,18 @@ namespace LinBox { |
| 104 | + |
| 105 | + template<class Vect> |
| 106 | + Self_t& copy(const Vect& A){ |
| 107 | +- assert(_size == A.size()); |
| 108 | ++ assert(_size == A.size()); |
| 109 | + auto it=A.begin(); auto jt=begin(); |
| 110 | + for( ; it!=A.end();++it,++jt) |
| 111 | + field().assign(*jt,*it); |
| 112 | + return *this; |
| 113 | + } |
| 114 | +- |
| 115 | ++ |
| 116 | + //! Rebind operator |
| 117 | + template<typename _Tp1, typename _Rep2 = typename Rebind<Storage, _Tp1>::other> |
| 118 | + struct rebind { |
| 119 | + typedef BlasVector<_Tp1, _Rep2> other; |
| 120 | +- |
| 121 | ++ |
| 122 | + void operator() (other & Ap, const Self_t& A) { |
| 123 | + typedef typename Self_t::const_iterator ConstSelfIterator ; |
| 124 | + typedef typename other::iterator OtherIterator ; |
| 125 | +@@ -180,14 +180,14 @@ namespace LinBox { |
| 126 | + } |
| 127 | + }; |
| 128 | + |
| 129 | +- |
| 130 | ++ |
| 131 | + |
| 132 | + ///////////////// |
| 133 | + // ACCESSORS // |
| 134 | + ///////////////// |
| 135 | + |
| 136 | + const Field& field() const { return *_field;} |
| 137 | +- |
| 138 | ++ |
| 139 | + // dimension of the vector |
| 140 | + size_t size() const{ return _size; } |
| 141 | + size_t max_size() const{ return _size; } |
| 142 | +@@ -203,14 +203,14 @@ namespace LinBox { |
| 143 | + * @return the inc value of the subvector |
| 144 | + */ |
| 145 | + size_t getInc() const {return _inc;} |
| 146 | +- |
| 147 | ++ |
| 148 | + |
| 149 | + void setEntry (size_t i, const Element &a_i){ field().assign(_ptr[i],a_i); } |
| 150 | +- |
| 151 | ++ |
| 152 | + reference refEntry (size_t i){ return _ptr[i]; } |
| 153 | + |
| 154 | + const_reference getEntry (size_t i) const { return _ptr[i]; } |
| 155 | +- |
| 156 | ++ |
| 157 | + Element& getEntry (Element &x, size_t i) const{ return field().assign(x,_ptr[i]); } |
| 158 | + |
| 159 | + // write |
| 160 | +@@ -226,7 +226,7 @@ namespace LinBox { |
| 161 | + case (Tag::FileFormat::Maple) : |
| 162 | + { |
| 163 | + os << '<' ; |
| 164 | +- for(size_t i=0; i<_size; i++){ |
| 165 | ++ for(size_t i=0; i<_size; i++){ |
| 166 | + field().write(os, *(_ptr+_inc*i)); |
| 167 | + if (i != _size-1) |
| 168 | + os << ',' ; |
| 169 | +@@ -237,7 +237,7 @@ namespace LinBox { |
| 170 | + return os << "not implemented" ; |
| 171 | + } |
| 172 | + } |
| 173 | +- |
| 174 | ++ |
| 175 | + //read |
| 176 | + std::istream &read ( std::istream &is, Tag::FileFormat fmt = Tag::FileFormat::Pretty ) { |
| 177 | + return is; |
| 178 | +@@ -275,10 +275,10 @@ namespace LinBox { |
| 179 | + const_reference front (void) const { return _ptr[0];} |
| 180 | + reference back (void) { return _ptr[(_size-1)*_inc];} |
| 181 | + const_reference back (void) const { return _ptr[(_size-1)*_inc];} |
| 182 | +- |
| 183 | ++ |
| 184 | + bool empty() const {return (_size==0);} |
| 185 | + }; |
| 186 | +- |
| 187 | ++ |
| 188 | + template <class Vector> |
| 189 | + std::ostream& operator<< (std::ostream & os, const BlasSubvector<Vector> & V) { |
| 190 | + return V.write(os); |
| 191 | +@@ -296,7 +296,7 @@ namespace LinBox { |
| 192 | + |
| 193 | + |
| 194 | + |
| 195 | +- |
| 196 | ++ |
| 197 | + } // LinBox |
| 198 | + #endif |
| 199 | + // Local Variables: |
| 200 | +diff --git a/tests/test-subvector.C b/tests/test-subvector.C |
| 201 | +index be4850e23344c95f762c09d8fdfe2cdbbac896b2..fc1d2c658afdb4cf6a8338443e29d73b583de9f4 100644 |
| 202 | +--- a/tests/test-subvector.C |
| 203 | ++++ b/tests/test-subvector.C |
| 204 | +@@ -752,6 +752,12 @@ static bool testSubvector3(Field &F, size_t n) |
| 205 | + //vector<int> ww(3, 77); |
| 206 | + w = ww; |
| 207 | + report << ww << std::endl; |
| 208 | ++ |
| 209 | ++ report << "Constructing subvectors from subvector: "; |
| 210 | ++ subVector ww1(w, 0, 0, Length); |
| 211 | ++ report << ww1 << std::endl; |
| 212 | ++ |
| 213 | ++ |
| 214 | + #if 0 |
| 215 | + report << "Constructing subvector from iterators: "; |
| 216 | + Subvect www(w.begin(), w.end()); |
0 commit comments