gsl_vector.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef GSLPP_VECTOR_HH
#define GSLPP_VECTOR_HH
#include <iostream>
#include <mia/core/gsl_defines.hh>
#include <mia/core/gsl_iterator.hh>
#include <gsl/gsl_vector.h>
namespace gsl
{
class EXPORT_GSL Vector
{
public:
typedef vector_iterator iterator;
typedef const_vector_iterator const_iterator;
typedef size_t size_type;
typedef double value_type;
typedef double& reference;
typedef const double& const_reference;
typedef gsl_vector vector_type;
typedef gsl_vector *vector_pointer_type;
typedef const gsl_vector *vector_const_pointer_type;
Vector();
Vector(size_type size, bool clear);
Vector(size_type size, const double *init);
Vector(gsl_vector *holder);
Vector(const gsl_vector *holder);
Vector(const Vector& other);
Vector(Vector&& other);
Vector& operator = (const Vector& other);
Vector& operator = (Vector&& other);
~Vector();
iterator begin();
iterator end();
const_iterator begin()const;
const_iterator end()const;
size_type size() const;
value_type operator[](size_t i) const
{
assert(cdata);
return cdata->data[i * cdata->stride];
};
reference operator[](size_t i)
{
assert(data);
return data->data[i * data->stride];
}
const gsl_vector *operator ->() const;
gsl_vector *operator ->();
operator Vector::vector_const_pointer_type () const;
operator Vector::vector_pointer_type ();
void print(std::ostream& os) const;
bool is_writable() const;
bool is_valid() const;
protected:
void reset_holder(gsl_vector *holder)
{
cdata = data = holder;
owner = false;
}
void reset_holder(const gsl_vector *holder)
{
cdata = holder;
owner = false;
}
private:
gsl_vector *data;
const gsl_vector *cdata;
bool owner;
};
inline Vector operator + (const Vector& lhs, const Vector& rhs)
{
Vector result(lhs);
gsl_vector_add(result, rhs);
return result;
}
inline Vector operator - (const Vector& lhs, const Vector& rhs)
{
Vector result(lhs);
gsl_vector_sub(result, rhs);
return result;
}
inline Vector operator * (const Vector& lhs, double f)
{
Vector result(lhs);
gsl_vector_scale(result, f);
return result;
}
class EXPORT_GSL VectorView : public Vector
{
public:
VectorView(gsl_vector_view vv): m_view(vv)
{
reset_holder(&m_view.vector);
};
private:
gsl_vector_view m_view;
};
class EXPORT_GSL ConstVectorView
{
public:
ConstVectorView(gsl_vector_const_view vv): m_view(vv),
m_holder(&m_view.vector)
{
};
Vector::const_iterator begin()const
{
return m_holder.begin();
}
Vector::const_iterator end()const
{
return m_holder.end();
}
Vector::size_type size() const
{
return m_holder.size();
}
double operator[](size_t i)const
{
return m_holder[i];
};
operator const Vector& ()
{
return m_holder;
}
const gsl_vector *operator ->() const
{
return m_holder.operator ->();
}
operator Vector::vector_const_pointer_type () const
{
return m_holder.operator Vector::vector_const_pointer_type();
}
private:
gsl_vector_const_view m_view;
const Vector m_holder;
};
inline std::ostream& operator << (std::ostream& os, const Vector& v)
{
v.print(os);
return os;
}
}
#endif
gsl::ConstVectorView::begin
Vector::const_iterator begin() const
Definition gsl_vector.hh:251
gsl::ConstVectorView::size
Vector::size_type size() const
Definition gsl_vector.hh:261
gsl::ConstVectorView::end
Vector::const_iterator end() const
Definition gsl_vector.hh:256
gsl::ConstVectorView::ConstVectorView
ConstVectorView(gsl_vector_const_view vv)
Definition gsl_vector.hh:246
gsl::ConstVectorView::operator[]
double operator[](size_t i) const
Definition gsl_vector.hh:266
gsl::VectorView::VectorView
VectorView(gsl_vector_view vv)
Definition gsl_vector.hh:230
gsl::Vector
Definition gsl_vector.hh:39
gsl::Vector::size
size_type size() const
gsl::Vector::vector_type
gsl_vector vector_type
Definition gsl_vector.hh:48
gsl::Vector::Vector
Vector(const Vector &other)
gsl::Vector::Vector
Vector(const gsl_vector *holder)
gsl::Vector::Vector
Vector(size_type size, const double *init)
gsl::Vector::reference
double & reference
Definition gsl_vector.hh:46
gsl::Vector::end
iterator end()
gsl::Vector::const_iterator
const_vector_iterator const_iterator
Definition gsl_vector.hh:43
gsl::Vector::value_type
double value_type
Definition gsl_vector.hh:45
gsl::Vector::is_valid
bool is_valid() const
gsl::Vector::~Vector
~Vector()
Destructor.
gsl::Vector::const_reference
const double & const_reference
Definition gsl_vector.hh:47
gsl::Vector::reset_holder
void reset_holder(gsl_vector *holder)
Definition gsl_vector.hh:183
gsl::Vector::Vector
Vector(size_type size, bool clear)
gsl::Vector::iterator
vector_iterator iterator
Definition gsl_vector.hh:42
gsl::Vector::end
const_iterator end() const
gsl::Vector::operator[]
reference operator[](size_t i)
Definition gsl_vector.hh:154
gsl::Vector::begin
iterator begin()
gsl::Vector::print
void print(std::ostream &os) const
gsl::Vector::is_writable
bool is_writable() const
gsl::Vector::Vector
Vector(gsl_vector *holder)
gsl::Vector::vector_const_pointer_type
const gsl_vector * vector_const_pointer_type
Definition gsl_vector.hh:50
gsl::Vector::Vector
Vector(Vector &&other)
gsl::Vector::vector_pointer_type
gsl_vector * vector_pointer_type
Definition gsl_vector.hh:49
gsl::Vector::Vector
Vector()
gsl::Vector::reset_holder
void reset_holder(const gsl_vector *holder)
Definition gsl_vector.hh:189
gsl::Vector::operator[]
value_type operator[](size_t i) const
Definition gsl_vector.hh:143
gsl::Vector::begin
const_iterator begin() const
gsl::Vector::size_type
size_t size_type
Definition gsl_vector.hh:44
gsl::const_vector_iterator
Definition gsl_iterator.hh:171
gsl::vector_iterator
Definition gsl_iterator.hh:32
gsl_defines.hh
EXPORT_GSL
#define EXPORT_GSL
Definition gsl_defines.hh:38
gsl_iterator.hh
gsl
Definition gsl_iterator.hh:29
gsl::operator-
vector_iterator operator-(const vector_iterator &it, int dist)
Definition gsl_iterator.hh:155
gsl::operator+
vector_iterator operator+(const vector_iterator &it, int dist)
Definition gsl_iterator.hh:148
gsl::operator*
Matrix EXPORT_GSL operator*(const Matrix &lhs, const Matrix &rhs)
gsl::operator<<
std::ostream & operator<<(std::ostream &os, const Matrix &m)
Definition gsl_matrix.hh:459