<
typenameT>
60 static inline Matrix <T>*
matrix(
size_tk_,
size_tm_,
size_tn_,
Ta_ =
static_cast <T>(0));
72 inline Matrix(
size_tm_,
size_tn_,
const T*vector_);
73 inline Matrix(
size_tm_,
size_tn_,
Ta_ =
static_cast <T>(0));
77 virtual inline void*
create(
boolisCopy_ =
false)
const;
78 virtual inline void copy(
size_tm_,
size_tn_,
const T*
const*matrix_);
79 virtual inline void copy(
size_tm_,
size_tn_,
const T*vector_);
80 virtual inline void copy(
size_tm_,
size_tn_,
Ta_ =
static_cast <T>(0));
82 virtual inline operator bool()
const;
84 virtual inlinestd::ostream &
out(std::ostream &ostr_)
const;
85 virtual inlinestd::istream &
in(std::istream &istr_);
90 virtual inline const T*
operator [](
size_ti_)
const;
94 virtual inline size_t getM()
const{
return d_m;}
95 virtual inline size_t getN()
const{
return d_n;}
106 virtual inline void init(
size_tm_,
size_tn_);
107 virtual inline void free();
128 template<
typenameT>
129 bool operator==(
constNjn::Matrix <T> &matrix_,
constNjn::Matrix <T> &matrix0_);
131 template<
typenameS,
typenameT>
132 void copy(Njn::Matrix <S> *matrix_,
constNjn::Matrix <T> &matrix0_);
134 template<
typenameT>
135std::ostream &
operator<<(std::ostream &ostr_,
constNjn::Matrix <T> &matrix_);
137 template<
typenameT>
138std::istream &
operator>>(std::istream &istr_, Njn::Matrix <T> &matrix_);
149 template<
typenameT>
157 for(
size_t i= 0;
i< k_;
i++)
158matrix [
i].
copy(m_, n_, a_);
163 template<
typenameT>
166 assert(x_.getM () == y_.getM ());
167 assert(x_.getN () == y_.getN ());
169 for(
size_t i= 0;
i< x_.getM ();
i++) {
170 for(
size_tj = 0; j < x_.getN (); j++) {
178 template<
typenameT>
181 assert(x_.getM () == y_.getM ());
182 assert(x_.getN () == y_.getN ());
184 for(
size_t i= 0;
i< x_.getM ();
i++) {
185 for(
size_tj = 0; j < x_.getN (); j++) {
193 template<
typenameT>
196 assert(x_.getM () == y_.getM ());
197 assert(x_.getN () == y_.getN ());
199 for(
size_t i= 0;
i< x_.getM ();
i++) {
200 for(
size_tj = 0; j < x_.getN (); j++) {
208 template<
typenameT>
211 if(x_.getM () != x_.getN ())
return false;
213 for(
size_t i= 0;
i< x_.getM ();
i++) {
214 for(
size_tj = 0; j <
i; j++) {
215 if(x_ [
i][j] != x_ [j][
i])
return false;
222 template<
typenameT>
224: d_m (0), d_n (0), d_matrix_p (0), d_value (0)
227 template<
typenameT>
229: d_m (0), d_n (0), d_matrix_p (0), d_value (0)
234 template<
typenameT>
239: d_m (0), d_n (0), d_matrix_p (0), d_value (0)
241 copy(m_, n_, vector_);
244 template<
typenameT>
249: d_m (0), d_n (0), d_matrix_p (0), d_value (0)
254 template<
typenameT>
257 template<
typenameT>
260 if(
this!= &matrix_)
262 copy(matrix_.getM (), matrix_.getN (), matrix_.getMatrix ());
263this->setValue () = matrix_.getValue ();
268 template<
typenameT>
272 if(isCopy_) matrix->operator= (*this);
276 template<
typenameT>
279 template<
typenameT>
296 for(
i= 0;
i< getM ();
i++) {
298 if(
i!= 0) ostr_ << endl;
300 for(
size_tj = 0; j < getN (); j++) {
302 if(j != 0) ostr_ <<
'\t';
303ostr_ << getMatrix () [
i][j];
312ostr_ << getM () <<
"\t! row dimension of matrix\n";
313ostr_ << getN () <<
"\t! column dimension of matrix\n";
315 for(
i= 0;
i< getM ();
i++) {
317 if(
i!= 0) ostr_ <<
"\t! matrix elements\n";
319 for(j = 0; j < getN (); j++) {
321 if(j != 0) ostr_ <<
'\t';
322ostr_ << getMatrix () [
i][j];
326ostr_ <<
"\t! matrix elements";
333 if(! isSymmetric (*
this))
IoUtil::abort(
"Matrix::out : matrix is not symmetric");
335 for(
i= 0;
i< getM ();
i++)
337 if(
i!= 0) ostr_ << endl;
339 for(
size_tj =
i; j < getN (); j++)
341 if(j !=
i) ostr_ <<
'\t';
342ostr_ << getMatrix () [
i][j];
346 else IoUtil::abort(
"Matrix::out : impossible MatrixIO::getFormat ()");
354 template<
typenameT>
369stringstream sstream;
372 T value= this->getValue ();
384 while(sstream >>
value) v.push_back (
value);
386 if(! sstream.eof ())
IoUtil::abort(
"Njn::Matrix::in : bad value for the MACHINE");
389 if(
n== 0)
IoUtil::abort(
"Njn::Matrix::in : bad n for the MACHINE");
391 while(istr_ >>
value) v.push_back (
value);
392 if(! sstream.eof ())
IoUtil::abort(
"Njn::Matrix::in : bad value for the MACHINE");
395 if(m *
n!= v.size ())
IoUtil::abort(
"Njn::Matrix::in : rows for the MACHINE have different lengths.");
397 if(m != this->getM () ||
n!= this->getN ()) {
403 for(
i= 0;
i< m;
i++) {
405 for(j = 0; j <
n; j++) d_matrix_p [
i][j] = v [k++];
414stringstream sstream;
421 if(sstream.fail ())
IoUtil::abort(
"Njn::Matrix::in : bad m");
428 if(sstream.fail ())
IoUtil::abort(
"Njn::Matrix::in : bad n");
430 if(m != this->getM () ||
n!= this->getN ()) {
436 for(
i= 0;
i< this->getM ();
i++) {
443 for(j = 0; j < this->getN (); j++) {
445sstream >> d_matrix_p [
i][j];
447 if(sstream.fail ()) {
449ostringstream sistream;
451ostringstream sjstream;
453 IoUtil::abort(
"Njn::Matrix::in : bad d_matrix_p ["+ sistream.str () +
"]["+ sjstream.str () +
"]");
467 while(sstream >>
value)
469v.push_back (
value);
471 if(! sstream.eof ())
IoUtil::abort(
"Njn::Matrix::in : bad value for the MatrixIO::SYMMETRIC");
474 if(
n== 0)
IoUtil::abort(
"Njn::Matrix::in : bad n for the MatrixIO::SYMMETRIC");
476 while(istr_ >>
value) v.push_back (
value);
477 if(! istr_.eof ())
IoUtil::abort(
"Njn::Matrix::in : bad value for the MatrixIO::SYMMETRIC");
480 if(m * (m + 1) / 2 != v.size ())
IoUtil::abort(
"Njn::Matrix::in : rows for the MatrixIO::SYMMETRIC have incorrect lengths.");
482 if(m != this->getM () ||
n!= this->getN ()) {
488 for(
i= 0;
i< m;
i++)
490 for(j = 0; j <
i; j++) d_matrix_p [
i][j] = d_matrix_p [j][
i];
491 for(j =
i; j <
n; j++) d_matrix_p [
i][j] = v [k++];
494 else IoUtil::abort(
"Matrix::in : impossible MatrixIO::getFormat ()");
502 template<
typenameT>
505 copy(this->getM (), this->getN (), a_);
509 template<
typenameT>
512 returnd_matrix_p [i_];
515 template<
typenameT>
518 returnd_matrix_p [i_];
521 template<
typenameT>
525 const T*
const*matrix_)
527 if(m_ != this->getM () || n_ != this->getN ()) {
529this->
init(m_, n_);
532 for(
size_t i= 0;
i< this->getM ();
i++)
534 for(
size_tj = 0; j < this->getN (); j++)
536d_matrix_p [
i][j] = matrix_ [
i][j];
541 template<
typenameT>
547 if(m_ != this->getM () || n_ != this->getN ()) {
549this->
init(m_, n_);
553 for(
size_t i= 0;
i< this->getM ();
i++)
555 for(
size_tj = 0; j < this->getN (); j++)
557d_matrix_p [
i][j] = vector_ [k++];
562 template<
typenameT>
568 if(m_ != this->getM () || n_ != this->getN ())
571this->
init(m_, n_);
574 for(
size_t i= 0;
i< this->getM ();
i++)
576 for(
size_tj = 0; j < this->getN (); j++)
578d_matrix_p [
i][j] = a_;
583 template<
typenameT>
586 if(m_ > 0) d_matrix_p =
new T* [m_];
588 for(
size_t i= 0;
i< m_;
i++)
590d_matrix_p [
i] =
new T[n_];
597 template<
typenameT>
600 for(
size_t i= 0;
i< this->getM ();
i++) {
601 delete[] d_matrix_p [
i]; d_matrix_p [
i] = 0;
603 if(this->getM () > 0)
delete[] d_matrix_p;
612 template<
typenameS,
typenameT>
613 void copy(Njn::Matrix <S> *matrix_,
constNjn::Matrix <T> &matrix0_)
615matrix_->copy (matrix0_.getM (), matrix0_.getN ());
617 for(
size_t i= 0;
i< matrix0_.getM ();
i++) {
618 for(
size_tj = 0; j < matrix0_.getN (); j++) {
619(*matrix_) [
i][j] =
static_cast <S>(matrix0_ [
i][j]);
625 template<
typenameT>
626 bool operator==(
constNjn::Matrix <T> &matrix_,
constNjn::Matrix <T> &matrix0_)
628 if(matrix_.getM () != matrix0_.getM ())
return false;
629 if(matrix_.getN () != matrix0_.getN ())
return false;
630 for(
size_t i= 0;
i< matrix_.getM ();
i++) {
631 for(
size_tj = 0; j < matrix_.getN (); j++) {
632 if(matrix_.getMatrix () [
i][j] != matrix0_.getMatrix () [
i][j])
return false;
639 template<
typenameT>
640std::ostream &
operator<<(std::ostream &ostr_,
constNjn::Matrix <T> &matrix_)
641{
returnmatrix_.out (ostr_);}
643 template<
typenameT>
644std::istream &
operator>>(std::istream &istr_, Njn::Matrix <T> &matrix_)
645{
returnmatrix_.in (istr_);}
static bool absRelApprox(const Matrix< T > &x_, const Matrix< T > &y_, T tol_, T rtol_)
virtual void * create(bool isCopy_=false) const
virtual T * operator[](size_t i_)
virtual const T getValue() const
virtual size_t getN() const
virtual const T *const * getMatrix() const
static bool approx(const Matrix< T > &x_, const Matrix< T > &y_, T eps_)
static bool relApprox(const Matrix< T > &x_, const Matrix< T > &y_, T eps_)
virtual std::istream & in(std::istream &istr_)
virtual std::ostream & out(std::ostream &ostr_) const
virtual void copy(size_t m_, size_t n_, const T *const *matrix_)
static bool isSymmetric(const Matrix< T > &x_)
Matrix & operator=(const Matrix &matrix_)
static Matrix< T > * matrix(size_t k_, size_t m_, size_t n_, T a_=static_cast< T >(0))
virtual void init(size_t m_, size_t n_)
virtual size_t getM() const
static void DLIST_NAME() init(DLIST_LIST_TYPE *list)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define USING_SCOPE(ns)
Use the specified namespace.
#define END_SCOPE(ns)
End the previously defined scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define BEGIN_SCOPE(ns)
Define a new scope.
const GenericPointer< typename T::ValueType > T2 value
Defines Limits for the types used in NCBI C/C++ toolkit.
bool relApprox(T x_, T y_, T eps_)
bool approx(T x_, T y_, T eps_)
bool absRelApprox(T x_, T y_, T tol_, T rtol_)
std::istream & getLine(std::istream &in_, std::string &str_, const char t_=getTerminator())
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
bool operator==(const Njn::Matrix< T > &matrix_, const Njn::Matrix< T > &matrix0_)
std::istream & operator>>(std::istream &istr_, Njn::Matrix< T > &matrix_)
void setFormat(Format format_)
std::ostream & operator<<(std::ostream &ostr_, const Njn::Matrix< T > &matrix_)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4