Skip to content

Commit

Permalink
solving issue #319
Browse files Browse the repository at this point in the history
  • Loading branch information
jgdumas committed Dec 5, 2024
1 parent 71d20c6 commit 4a1e139
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
52 changes: 26 additions & 26 deletions linbox/vector/blas-subvector.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* linbox/matrix/blas-vector.h
* Copyright (C) 2013 the LinBox group
* 2019 Pascal Giorgi
* 2019 Pascal Giorgi
*
* Written by :
* Pascal Giorgi [email protected]
Expand Down Expand Up @@ -45,7 +45,7 @@ namespace LinBox {
// forward declaration
template <class Field, class Storage>
class BlasVector;


template <typename _Vector>
class VectorEltPointer {
Expand All @@ -61,7 +61,7 @@ namespace LinBox {
typedef typename _Vector::Storage::const_reference reference;
using Element=const typename _Vector::Field::Element;
};

template<class _Vector>
class BlasSubvector {

Expand All @@ -88,7 +88,7 @@ namespace LinBox {
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;

protected:
pointer _ptr;
pointer _ptr;
size_t _size;
size_t _inc;
Field const*_field;
Expand All @@ -101,7 +101,7 @@ namespace LinBox {
//////////////////

BlasSubvector(){}

/** Constructor from an existing @ref BlasVector and dimensions.
* \param V Pointer to @ref BlasVector of which to construct subvector
* \param beg Starting idx
Expand All @@ -110,17 +110,17 @@ namespace LinBox {
*/
BlasSubvector (vectorType &V, size_t beg, size_t inc, size_t dim) :
_ptr(V.getPointer()+beg), _size(dim), _inc(inc), _field(&V.field()) {}

/** Constructor from an existing @ref BlasSubvector and dimensions.
* \param V Pointer to @ref DenseSubector of which to construct subvector
* \param beg Starting idx
* \param dim dimension
* \param inc distance between two element
*/
BlasSubvector (Self_t &V, size_t beg, size_t inc, size_t dim) :
_ptr(V.data()+beg), _size(dim), _inc(inc), _field(&V.field()) {}
_ptr(V.getPointer()+beg), _size(dim), _inc(inc), _field(&V.field()) {}



/** Constructor from an existing @ref BlasVector
* \param V Pointer to @ref BlasVector of which to construct submatrix
*/
Expand All @@ -132,17 +132,17 @@ namespace LinBox {
*/
BlasSubvector (const Field& F, pointer ptr, size_t inc, size_t dim) :
_ptr(ptr), _size(dim), _inc(inc), _field(&F) {}



BlasSubvector (const Field& F, std::vector<Element>& v) :
_ptr(v.data()), _size(v.size()), _inc(1), _field(&F)
_ptr(v.data()), _size(v.size()), _inc(1), _field(&F)
{
std::cerr<<"WARNING "<<__LINE__<<" ("<<__FILE__<<") : creating a BlasSubvector from a std::vector -> MUST BE DEPRECATED"<<std::endl;
throw LinBoxError("Deprecated Subvector cstor from std::vector");
}



/** Copy operator */
BlasSubvector& operator= (const BlasSubvector& V){
Expand All @@ -157,18 +157,18 @@ namespace LinBox {

template<class Vect>
Self_t& copy(const Vect& A){
assert(_size == A.size());
assert(_size == A.size());
auto it=A.begin(); auto jt=begin();
for( ; it!=A.end();++it,++jt)
field().assign(*jt,*it);
return *this;
}

//! Rebind operator
template<typename _Tp1, typename _Rep2 = typename Rebind<Storage, _Tp1>::other>
struct rebind {
typedef BlasVector<_Tp1, _Rep2> other;

void operator() (other & Ap, const Self_t& A) {
typedef typename Self_t::const_iterator ConstSelfIterator ;
typedef typename other::iterator OtherIterator ;
Expand All @@ -180,14 +180,14 @@ namespace LinBox {
}
};



/////////////////
// ACCESSORS //
/////////////////

const Field& field() const { return *_field;}

// dimension of the vector
size_t size() const{ return _size; }
size_t max_size() const{ return _size; }
Expand All @@ -203,14 +203,14 @@ namespace LinBox {
* @return the inc value of the subvector
*/
size_t getInc() const {return _inc;}


void setEntry (size_t i, const Element &a_i){ field().assign(_ptr[i],a_i); }

reference refEntry (size_t i){ return _ptr[i]; }

const_reference getEntry (size_t i) const { return _ptr[i]; }

Element& getEntry (Element &x, size_t i) const{ return field().assign(x,_ptr[i]); }

// write
Expand All @@ -226,7 +226,7 @@ namespace LinBox {
case (Tag::FileFormat::Maple) :
{
os << '<' ;
for(size_t i=0; i<_size; i++){
for(size_t i=0; i<_size; i++){
field().write(os, *(_ptr+_inc*i));
if (i != _size-1)
os << ',' ;
Expand All @@ -237,7 +237,7 @@ namespace LinBox {
return os << "not implemented" ;
}
}

//read
std::istream &read ( std::istream &is, Tag::FileFormat fmt = Tag::FileFormat::Pretty ) {
return is;
Expand Down Expand Up @@ -275,10 +275,10 @@ namespace LinBox {
const_reference front (void) const { return _ptr[0];}
reference back (void) { return _ptr[(_size-1)*_inc];}
const_reference back (void) const { return _ptr[(_size-1)*_inc];}

bool empty() const {return (_size==0);}
};

template <class Vector>
std::ostream& operator<< (std::ostream & os, const BlasSubvector<Vector> & V) {
return V.write(os);
Expand All @@ -296,7 +296,7 @@ namespace LinBox {




} // LinBox
#endif
// Local Variables:
Expand Down
6 changes: 6 additions & 0 deletions tests/test-subvector.C
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,12 @@ static bool testSubvector3(Field &F, size_t n)
//vector<int> ww(3, 77);
w = ww;
report << ww << std::endl;

report << "Constructing subvectors from subvector: ";
subVector ww1(w, 0, 0, Length);
report << ww1 << std::endl;


#if 0
report << "Constructing subvector from iterators: ";
Subvect www(w.begin(), w.end());
Expand Down

0 comments on commit 4a1e139

Please sign in to comment.