From 0df4a83277dc986e95962426fdf93e49d1f21b42 Mon Sep 17 00:00:00 2001 From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be> Date: Mon, 22 Mar 2010 13:49:02 +0000 Subject: [PATCH] bindings for fullMatrix::print and add fullMatrix::setAsShapeProxy --- Numeric/fullMatrix.cpp | 3 +++ Numeric/fullMatrix.h | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Numeric/fullMatrix.cpp b/Numeric/fullMatrix.cpp index f7d154e46f..9875746c20 100644 --- a/Numeric/fullMatrix.cpp +++ b/Numeric/fullMatrix.cpp @@ -311,6 +311,9 @@ void fullMatrix<double>::registerBindings(binding *b) cm = cb->addMethod("gemm_naive", &fullMatrix<double>::gemm_naive); cm->setArgNames("A","B","alpha","beta",NULL); cm->setDescription("this = beta*this + alpha * (A.B)"); + cm = cb->addMethod("print", &fullMatrix<double>::print); + cm->setArgNames("name",NULL); + cm->setDescription("print the matrix"); cm = cb->setConstructor<fullMatrix<double>,int,int>(); cm->setDescription ("A new matrix of size 'nRows' x 'nColumns'"); cm->setArgNames("nRows","nColumns",NULL); diff --git a/Numeric/fullMatrix.h b/Numeric/fullMatrix.h index 80addf83f6..f2a2cdefa9 100644 --- a/Numeric/fullMatrix.h +++ b/Numeric/fullMatrix.h @@ -164,6 +164,17 @@ class fullMatrix _own_data = false; _data = original._data + c_start * _r; } + void setAsShapeProxy(fullMatrix<scalar> &original, int nbRow, int nbCol) + { + if(_data && _own_data) + delete [] _data; + _c = nbCol; + _r = nbRow; + if(_c*_r != original._c*original._r) + Msg::Error("trying to reshape a fullMatrix without conserving the total number of entries"); + _own_data = false; + _data = original._data; + } inline int size1() const { return _r; } inline int size2() const { return _c; } fullMatrix<scalar> & operator = (const fullMatrix<scalar> &other) @@ -356,9 +367,9 @@ class fullMatrix } #endif ; - void print(const char *name="") const + void print(const std::string name = "") const { - printf("Printing matrix %s:\n", name); + printf("Printing matrix %s:\n", name.c_str()); int ni = size1(); int nj = size2(); for(int I = 0; I < ni; I++){ -- GitLab