matrix.h revision 98a704c566ce5a750d76d5fc9675ccc804ac65f5
/*
* Matrix, MatrixView, ConstMatrixView classes wrap the gsl matrix routines;
* "views" mimic the semantic of C++ references: any operation performed
* on a "view" is actually performed on the "viewed object"
*
* Authors:
* Marco Cecchetti <mrcekets at gmail.com>
*
* Copyright 2008 authors
*
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*/
#ifndef _NL_MATRIX_H_
#define _NL_MATRIX_H_
#include <cassert>
#include <utility> // for std::pair
#include <algorithm> // for std::swap
#include <sstream>
#include <string>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_linalg.h>
{
{
{
}
{
}
{
}
{
return *gsl_matrix_const_ptr(m_matrix, i, j);
}
const gsl_matrix* get_gsl_matrix() const
{
return m_matrix;
}
bool is_zero() const
{
return gsl_matrix_isnull(m_matrix);
}
bool is_positive() const
{
for ( unsigned int i = 0; i < rows(); ++i )
{
for ( unsigned int j = 0; j < columns(); ++j )
{
if ( (*this)(i,j) <= 0 ) return false;
}
}
return true;
}
bool is_negative() const
{
for ( unsigned int i = 0; i < rows(); ++i )
{
for ( unsigned int j = 0; j < columns(); ++j )
{
if ( (*this)(i,j) >= 0 ) return false;
}
}
return true;
}
bool is_non_negative() const
{
for ( unsigned int i = 0; i < rows(); ++i )
{
for ( unsigned int j = 0; j < columns(); ++j )
{
if ( (*this)(i,j) < 0 ) return false;
}
}
return true;
}
double max() const
{
return gsl_matrix_max(m_matrix);
}
double min() const
{
return gsl_matrix_min(m_matrix);
}
max_index() const
{
return indices;
}
min_index() const
{
return indices;
}
{
return m_rows;
}
{
return m_columns;
}
}; // end class BaseMatrixImpl
inline
{
return true;
}
inline
{
{
}
os << "]";
{
{
}
os << "]";
}
os << "]";
return os;
}
inline
{
}
{
typedef BaseMatrixImpl base_type;
void set_all( double x )
{
}
void set_identity()
{
}
{
}
{
return *gsl_matrix_ptr(m_matrix, i, j);
}
{
return m_matrix;
}
{
}
{
}
{
gsl_matrix_swap_rows(m_matrix, i, j);
}
{
gsl_matrix_swap_columns(m_matrix, i, j);
}
MatrixImpl & transpose()
{
return (*this);
}
MatrixImpl & scale(double x)
{
gsl_matrix_scale(m_matrix, x);
return (*this);
}
MatrixImpl & translate(double x)
{
return (*this);
}
{
return (*this);
}
{
return (*this);
}
}; // end class MatrixImpl
} // end namespace detail
{
// the matrix is not inizialized
{
}
{
}
: base_type()
{
}
{
}
{
return *this;
}
{
return *this;
}
{
}
{
}
{
}
{
}
{
}
{
}
}; // end class Matrix
// warning! this operation invalidates any view of the passed matrix objects
inline
{
}
inline
{
}
{
{
}
: base_type(),
{
}
: m_matrix_view(gsl_matrix_const_submatrix(_matrix.get_gsl_matrix(), 0, 0, _matrix.rows(), _matrix.columns()))
{
}
}; // end class ConstMatrixView
{
{
}
: base_type()
{
}
{
}
{
return *this;
}
{
return *this;
}
MatrixView & transpose()
{
}
MatrixView & scale(double x)
{
}
MatrixView & translate(double x)
{
}
{
}
{
}
}; // end class MatrixView
inline
{
}
detail::BaseVectorImpl const& v );
detail::BaseMatrixImpl const& B );
} } // end namespaces
#endif /*_NL_MATRIX_H_*/
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :