void CRSMatrix::full2CRS(Matrix &A){ int nz = 0; //count non-zero elements int idx = 0; //data index /* *** count number of non-zero entries */ for(int i=0;i<A.numRows();i++) for(int j=0;j<A.numCols();j++) if(A(i,j)!=0) nz++; /* *** initialize private variables */ _rows = A.numRows(); _cols = A.numCols(); _nonZeros = nz; delete[] _data; delete []_colindex; delete[]_rowptr; _data = new double[nz]; _colindex = new int[nz]; _rowptr = new int[_rows+1]; /* *** fill _rowptr,_colindex,_data */ for(int i=0;i<_rows;i++){ _rowptr[i] = idx; for(int j=0; j<_cols;j++){ if(A(i,j)!=0){ _data[idx] = A(i,j); _colindex[idx]= j; idx++; } } } _rowptr[_rows]= nz; }
void fillMatrix(const Matrix <T> & m ) { int i, j; for ( i = 0; i < m.numRows(); i++ ) m[i][0] = T(); for ( j = 0; j < m.numCols(); j++ ) m[0][j] = T(); for ( i = 1; i < m.numRows(); i++ ) for ( j = 1; j < m.numCols(); j++ ) { m[i][j] = T(i * j); } }
//--------------------------------------------------------------------------- Matrix solveLinearSystem(const Matrix& A, const Matrix& b) { Matrix x; // Make sure A is square! if (A.numRows() != A.numCols()) { std::cerr << "ERROR! A must be square matrix!\n"; return x; } // Make sure b is a column vector with the same dimensions // as A if (b.numRows() != A.numRows()) { std::cerr << "ERROR! b must be a column vector with the same dimensions as square matrix A!\n"; return x; } // Make a copy of A since it gets modified Matrix Acopy(A); const int N = Acopy.numRows(); Matrix indx(N,1); double d; ludcmp(Acopy,indx,d); x = b; // x will contain solution lubksb(Acopy,indx,x); // Return solution column vector return x; }
//--------------------------------------------------------------------------- Matrix invert(const Matrix& A) { Matrix y(A.numRows(), A.numRows(), false); // Make sure A is square! if (A.numRows() != A.numCols()) { std::cerr << "ERROR! A must be square matrix!\n"; return y; } const int N = A.numRows(); // Make a copy of A since it gets modified Matrix Acopy(A); // y.setSize(N,N); Matrix col(N,1); Matrix indx(N,1); double d; int i,j; ludcmp(Acopy,indx,d); for (j = 0; j < N; j++) { for (i = 0; i < N; i++) col(i,0) = 0.0; col(j,0) = 1.0; lubksb(Acopy,indx,col); for (i = 0; i < N; i++) y(i,j) = col(i,0); } std::cout.flush(); // Return result return y; }
int main(){ Matrix a ( Matrix::readMatrix("../samples/my_code_1(1).data")); Matrix b ( Matrix::readMatrix("../samples/my_code_1(2).data")); int rows_a; int cols_b; int rows_b; rows_a=a.numRows(); cols_b=b.numCols(); rows_b=b.numRows(); Matrix result( rows_a , cols_b); for( int i = 0;i < rows_a ; i ++ ) { for(int j = 0; j < cols_b ; j ++ ){ *(result.access(i , j )) = 0; } } int i; int j; int k; for(i=0;i<=rows_a-1;i ++){ for(j=0;j<=cols_b-1;j ++){ for(k=0;k<=rows_b-1;k ++){ *( result.access(i,j )) = *( result.access(i,j ))+(*( a.access(i,k ))**( b.access(k,j ))) ; } } } cout<<result; }
void NRLib::ComputeEigenVectors(Matrix &A, Vector &eigen_values, Matrix &eigen_vectors) { Matrix dummy_mat(A.numRows(), A.numCols()); Vector dummy_vec(A.numRows()); flens::ev(false, true, A, eigen_values, dummy_vec, dummy_mat, eigen_vectors); }
void SetMatrixFrom2DArray(Matrix & A, T ** F) //------------------------------------ { for (int i=0 ; i < A.numRows() ; i++) { for (int j=0 ; j < A.numCols() ; j++) { A(i,j) = static_cast<double>( F[i][j] ); } } }
Matrix::Matrix(const Matrix& other) { rows = other.numRows(); cols = other.numCols(); data = allocData(rows, cols); for (int r = 0; r < rows; r++) { for (int c = 0; c < rows; c++) { data[r][c] = other.getElem(r, c); } } }
void Set2DArrayFromMatrix(const Matrix & A, T ** F) //------------------------------------------ { for (int i=0 ; i < A.numRows() ; i++) { for (int j=0 ; j < A.numCols() ; j++) { F[i][j] = static_cast<T>( A(i,j) ); } } }
void NRLib::WriteMatrix(const std::string & header, const Matrix & C) { int m = C.numRows(); int n = C.numCols(); LogKit::LogFormatted(LogKit::Error,"\n"+header+"\n"); for (int i=0; i < m ; i++) { for (int j=0; j < n ; j++) { LogKit::LogFormatted(LogKit::Error,"%20.8f ",C(i,j)); } LogKit::LogFormatted(LogKit::Error,"\n"); } LogKit::LogFormatted(LogKit::Error,"\n"); }
/** * \brief Implements cell() function for matrices. * * \arg \c rowIndex 1-based index of row to read data from. * \arg \c columnIndex 1-based index of column to read data from. */ double MuParserScript::matrixCellFunction(double rowIndex, double columnIndex) { Matrix *thisMatrix = qobject_cast<Matrix*>(s_currentInstance->Context); if (!thisMatrix) throw mu::Parser::exception_type(qPrintable(tr("cell() works only on tables and matrices!"))); int row = qRound(rowIndex) - 1; int column = qRound(columnIndex) - 1; if (row < 0 || row >= thisMatrix->numRows()) throw mu::Parser::exception_type(qPrintable(tr("There's no row %1 in matrix %2!"). arg(qRound(rowIndex)).arg(thisMatrix->objectName()))); if (column < 0 || column >= thisMatrix->numCols()) throw mu::Parser::exception_type(qPrintable(tr("There's no column %1 in matrix %2!"). arg(qRound(columnIndex)).arg(thisMatrix->objectName()))); return thisMatrix->cell(row, column); }
double muParserScript::cell(int row, int col) { if (!Context->isA("Matrix")) throw Parser::exception_type(tr("cell() works only on tables and matrices!").ascii()); Matrix *matrix = (Matrix*) Context; if (row < 1 || row > matrix->numRows()) throw Parser::exception_type(tr("There's no row %1 in matrix %2!"). arg(row).arg(Context->name()).ascii()); if (col < 1 || col > matrix->numCols()) throw Parser::exception_type(tr("There's no column %1 in matrix %2!"). arg(col).arg(Context->name()).ascii()); if (matrix->text(row-1,col-1).isEmpty()) throw new EmptySourceError(); else return matrix->cell(row-1,col-1); }
double muParserScript::cell(int row, int col) { if (!isOfType(context(), "Matrix")) throw Parser::exception_type( tr("cell() works only on tables and matrices!").toAscii().constData()); Matrix *matrix = static_cast<Matrix *>(const_cast<QObject *>(context())); if (row < 1 || row > matrix->numRows()) throw Parser::exception_type(tr("There's no row %1 in matrix %2!") .arg(row) .arg(context()->objectName()) .toAscii() .constData()); if (col < 1 || col > matrix->numCols()) throw Parser::exception_type(tr("There's no column %1 in matrix %2!") .arg(col) .arg(context()->objectName()) .toAscii() .constData()); if (matrix->text(row - 1, col - 1).isEmpty()) throw new EmptySourceError(); else return matrix->cell(row - 1, col - 1); }
int main(){ Matrix data ( Matrix::readMatrix("../samples/myData.data")); int rows; rows=data.numRows(); int cols; cols=data.numCols(); int season_length; season_length=7; int years; years=ceil(cols*1.0/season_length); Matrix avgScore( rows , 1); for( int row = 0;row < rows ; row ++ ) { for(int irrelevant = 0; irrelevant < 1 ; irrelevant ++ ){ *(avgScore.access(row , irrelevant )) = ({ Matrix pt( years , season_length); for( int i = 0;i < years ; i ++ ) { for(int j = 0; j < season_length ; j ++ ){ *(pt.access(i , j )) = ({ int k; k=i*season_length+j; ((k>=cols) ? (0.0-25) : (*( data.access(row,k ))) ) ; }); } } Matrix comparisonMatrix( years , years); for( int i = 0;i < years ; i ++ ) { for(int j = 0; j < years ; j ++ ){ *(comparisonMatrix.access(i , j )) = (j<=i) ? (0.0) : (({ float diff; diff=0; int k; for(k=0;k<=season_length-1;k ++){ diff=diff+*( pt.access(i,k ))-*( pt.access(j,k )); } (diff/season_length ) ; })); } } Matrix modelAvgScore( years , 1); for( int yr = 0;yr < years ; yr ++ ) { for(int dontcare = 0; dontcare < 1 ; dontcare ++ ){ *(modelAvgScore.access(yr , dontcare )) = ({ int x; int y; float score1; score1=0.0; for(x=0;x<=yr;x ++){ for(y=yr+1;y<=years-1;y ++){ score1=score1+*( comparisonMatrix.access(x,y )); } } score1=score1*2/(yr*(years-yr)); float score2; score2=0.0; for(x=0;x<=yr;x ++){ for(y=0;y<=yr;y ++){ score2=score2+*( comparisonMatrix.access(x,y )); } } score2=score2/((yr-1)*yr/2); float score3; score3=0.0; for(x=yr+1;x<=years-1;x ++){ for(y=yr+1;y<=years-1;y ++){ score3=score3+*( comparisonMatrix.access(x,y )); } } score3=score3/((years-yr)*(years-yr-1)/2); (score1-score2-score3 ) ; }); } } float maximum; maximum=0.0-25; int k; k=0; for(k=0;k<=years-1;k ++){ if(*( modelAvgScore.access(k,0 ))>maximum) { maximum=*( modelAvgScore.access(k,0 )); } } (maximum ) ; });
bool matrixTest() { bool status = true; // // Test construction. // { unsigned numRows = randomLength(); unsigned numCols = randomLength(); Matrix m(numRows, numCols); if ((m.numRows() != numRows) || (m.numCols() != numCols)) { cout << "matrixTest: Uninitialized constructor failed " << "to create correct size." << endl; status = false; } } { unsigned numRows = randomLength(); unsigned numCols = randomLength(); double value = randomValue(); Matrix m(numRows, numCols, value); if ((m.numRows() != numRows) || (m.numCols() != numCols)) { cout << "matrixTest: Scalar constructor failed to create correct size." << endl; status = false; } for (unsigned r = 0; r < m.numRows(); ++r) { for (unsigned c = 0; c < m.numCols(); ++c) { if (!similar(m[r][c], value)) { cout << "matrixTest: Scalar constructor failed to initialze " << "data correctly." << endl; status = false; break; } } if (!status) { break; } } } double data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }; unsigned numRows = 6; unsigned numCols = 3; Matrix m(numRows, numCols, data); if ((m.numRows() != numRows) || (m.numCols() != numCols)) { cout << "matrixTest: Array constructor failed to create correct size." << endl; status = false; } unsigned i; unsigned r; unsigned c; i = 0; for (r = 0; r < m.numRows(); ++r) { for (c = 0; i < m.numCols(); ++c) { if (!similar(m[r][c], data[i++])) { cout << "matrixTest: Array constructor failed to initialze " << "data correctly." << endl; status = false; break; } } if (!status) { break; } } Matrix copy(m); if ((copy.numRows() != numRows) || (copy.numCols() != numCols)) { cout << "matrixTest: Copy constructor failed to create correct size." << endl; status = false; } i = 0; for (r = 0; r < copy.numRows(); ++r) { for (c = 0; i < copy.numCols(); ++c) { if (!similar(copy[r][c], data[i++])) { cout << "matrixTest: Copy constructor failed to initialze " << "data correctly." << endl; status = false; break; } } if (!status) { break; } } Matrix assign; assign = m; if ((assign.numRows() != numRows) || (assign.numCols() != numCols)) { cout << "matrixTest: Assign operator failed to create correct size." << endl; status = false; } i = 0; for (r = 0; r < assign.numRows(); ++r) { for (c = 0; i < assign.numCols(); ++c) { if (!similar(assign[r][c], data[i++])) { cout << "matrixTest: Assign operator failed to initialze " << "data correctly." << endl; status = false; break; } } if (!status) { break; } } // // Test arithmetic operators. // Matrix a(numRows, numCols, data); a += m; i = 0; for (r = 0; r < copy.numRows(); ++r) { for (c = 0; i < copy.numCols(); ++c) { if (!similar(a[r][c], 2*data[i++])) { cout << "matrixTest: Operator += failed." << endl; status = false; break; } } if (!status) { break; } } a -= m; i = 0; for (r = 0; r < copy.numRows(); ++r) { for (c = 0; i < copy.numCols(); ++c) { if (!similar(a[r][c], data[i++])) { cout << "matrixTest: Operator -= failed." << endl; status = false; break; } } if (!status) { break; } } a *= 3; i = 0; for (r = 0; r < copy.numRows(); ++r) { for (c = 0; i < copy.numCols(); ++c) { if (!similar(a[r][c], 3*data[i++])) { cout << "matrixTest: Operator *= failed." << endl; status = false; break; } } if (!status) { break; } } a /= 3; i = 0; for (r = 0; r < copy.numRows(); ++r) { for (c = 0; i < copy.numCols(); ++c) { if (!similar(a[r][c], data[i++])) { cout << "matrixTest: Operator /= failed." << endl; status = false; break; } } if (!status) { break; } } Matrix neg = -a; i = 0; for (r = 0; r < copy.numRows(); ++r) { for (c = 0; i < copy.numCols(); ++c) { if (!similar(neg[r][c], -data[i++])) { cout << "matrixTest: Operator - failed." << endl; status = false; break; } } if (!status) { break; } } Matrix sum = a + m; i = 0; for (r = 0; r < copy.numRows(); ++r) { for (c = 0; i < copy.numCols(); ++c) { if (!similar(sum[r][c], 2*data[i++])) { cout << "matrixTest: Matrix + Matrix failed." << endl; status = false; break; } } if (!status) { break; } } Matrix dif = sum - m; i = 0; for (r = 0; r < copy.numRows(); ++r) { for (c = 0; i < copy.numCols(); ++c) { if (!similar(dif[r][c], data[i++])) { cout << "matrixTest: Matrix - Matrix failed." << endl; status = false; break; } } if (!status) { break; } } // // Test scaling. // Matrix dbl = m*2; i = 0; for (r = 0; r < copy.numRows(); ++r) { for (c = 0; i < copy.numCols(); ++c) { if (!similar(dbl[r][c], 2*data[i++])) { cout << "matrixTest: Matrix * double failed." << endl; status = false; break; } } if (!status) { break; } } Matrix haf = dbl/2; i = 0; for (r = 0; r < copy.numRows(); ++r) { for (c = 0; i < copy.numCols(); ++c) { if (!similar(haf[r][c], data[i++])) { cout << "matrixTest: Matrix / double failed." << endl; status = false; break; } } } Matrix pls = m + 2; i = 0; for (r = 0; r < copy.numRows(); ++r) { for (c = 0; i < copy.numCols(); ++c) { if (!similar(pls[r][c], data[i++] + 2)) { cout << "matrixTest: Matrix + double failed." << endl; status = false; break; } } if (!status) { break; } } Matrix min = m - 2; i = 0; for (r = 0; r < copy.numRows(); ++r) { for (c = 0; i < copy.numCols(); ++c) { if (!similar(min[r][c], data[i++] - 2)) { cout << "matrixTest: Matrix - double failed." << endl; status = false; break; } } if (!status) { break; } } // // TODO: Test sub-matrix operation. // return status; }
bool ImportOPJ::importTables(const OPJFile &opj) { int visible_count = 0; int QtiPlot_scaling_factor = 10; // in Origin width is measured in characters // while in QtiPlot - pixels --- need to be // accurate for (int s = 0; s < opj.numSpreads(); s++) { int nr_cols = opj.numCols(s); int maxrows = opj.maxRows(s); if (!nr_cols) // remove tables without cols continue; Table *table = (opj.spreadHidden(s) || opj.spreadLoose(s)) && opj.Version() == 7.5 ? mw->newHiddenTable(opj.spreadName(s), opj.spreadLabel(s), maxrows, nr_cols) : mw->newTable(opj.spreadName(s), maxrows, nr_cols); if (!table) return false; rect windowRect; if (opj.Version() == 7.5) { windowRect = opj.spreadWindowRect(s); table->resize(windowRect.width() - (table->frameGeometry().width() - table->width()), windowRect.height() - (table->frameGeometry().height() - table->height())); } table->setCaptionPolicy((MdiSubWindow::CaptionPolicy)opj.spreadTitle(s)); table->setBirthDate(JulianDateTime2String(opj.spreadCreationDate(s))); QLocale locale = mw->locale(); table->setWindowLabel(opj.spreadLabel(s)); for (int j = 0; j < nr_cols; j++) { QString name(opj.colName(s, j)); table->setColName(j, name.replace(QRegExp(".*_"), "")); table->setCommand(j, QString(opj.colCommand(s, j))); table->setColComment(j, QString(opj.colComment(s, j))); table->setColumnWidth(j, opj.colWidth(s, j) * QtiPlot_scaling_factor); switch (opj.colType(s, j)) { case X: table->setColPlotDesignation(j, Table::X); break; case Y: table->setColPlotDesignation(j, Table::Y); break; case Z: table->setColPlotDesignation(j, Table::Z); break; case XErr: table->setColPlotDesignation(j, Table::xErr); break; case YErr: table->setColPlotDesignation(j, Table::yErr); break; case Label: table->setColPlotDesignation(j, Table::Label); break; default: table->setColPlotDesignation(j, Table::None); } table->setHeaderColType(); // update header double **d_cells = new double *[nr_cols]; for (int i = 0; i < nr_cols; ++i) d_cells[i] = new double[table->numRows()]; for (int i = 0; i < opj.numRows(s, j); i++) { if (opj.colType(s, j) != Label && opj.colValueType(s, j) != 1) { // number double *val = (double *)opj.oData(s, j, i, true); if (fabs(*val) > 0 && fabs(*val) < 2.0e-300) // empty entry continue; table->setText(i, j, locale.toString(*val, 'g', 16)); d_cells[j][i] = *val; } else // label? doesn't seem to work table->setText(i, j, QString((char *)opj.oData(s, j, i))); } table->saveToMemory(d_cells); QString format; int f = 0; switch (opj.colValueType(s, j)) { case 0: // Numeric case 6: // Text&Numeric if (opj.colNumDisplayType(s, j) == 0) f = 0; else switch (opj.colValueTypeSpec(s, j)) { case 0: // Decimal 1000 f = 1; break; case 1: // Scientific f = 2; break; case 2: // Engeneering case 3: // Decimal 1,000 f = 0; break; } table->setColNumericFormat(f, opj.colDecPlaces(s, j), j); break; case 1: // Text table->setTextFormat(j); break; case 2: // Date switch (opj.colValueTypeSpec(s, j)) { case -128: format = "dd/MM/yyyy"; break; case -119: format = "dd/MM/yyyy HH:mm"; break; case -118: format = "dd/MM/yyyy HH:mm:ss"; break; case 0: case 9: case 10: format = "dd.MM.yyyy"; break; case 2: format = "MMM d"; break; case 3: format = "M/d"; break; case 4: format = "d"; break; case 5: case 6: format = "ddd"; break; case 7: format = "yyyy"; break; case 8: format = "yy"; break; case 11: case 12: case 13: case 14: case 15: format = "yyMMdd"; break; case 16: case 17: format = "MMM"; break; case 19: format = "M-d-yyyy"; break; default: format = "dd.MM.yyyy"; } table->setDateFormat(format, j); break; case 3: // Time switch (opj.colValueTypeSpec(s, j) + 128) { case 0: format = "hh:mm"; break; case 1: format = "hh"; break; case 2: format = "hh:mm:ss"; break; case 3: format = "hh:mm:ss.zzz"; break; case 4: format = "hh ap"; break; case 5: format = "hh:mm ap"; break; case 6: format = "mm:ss"; break; case 7: format = "mm:ss.zzz"; break; case 8: format = "hhmm"; break; case 9: format = "hhmmss"; break; case 10: format = "hh:mm:ss.zzz"; break; } table->setTimeFormat(format, j); break; case 4: // Month switch (opj.colValueTypeSpec(s, j)) { case 0: format = "MMM"; break; case 1: format = "MMMM"; break; case 2: format = "M"; break; } table->setMonthFormat(format, j); break; case 5: // Day switch (opj.colValueTypeSpec(s, j)) { case 0: format = "ddd"; break; case 1: format = "dddd"; break; case 2: format = "d"; break; } table->setDayFormat(format, j); break; } table->freeMemory(); } if (!(opj.spreadHidden(s) || opj.spreadLoose(s)) || opj.Version() != 7.5) { switch (opj.spreadState(s)) { case originWindow::Minimized: mw->minimizeWindow(table); break; case originWindow::Maximized: mw->maximizeWindow(table); break; default: table->showNormal(); } // cascade the tables if (opj.Version() == 7.5) { table->move(QPoint(windowRect.left, windowRect.top)); } else { int dx = table->verticalHeaderWidth(); int dy = table->frameGeometry().height() - table->height(); table->move(QPoint(visible_count * dx + xoffset * OBJECTXOFFSET, visible_count * dy)); visible_count++; } } } // Import matrices for (int s = 0; s < opj.numMatrices(); s++) { int nr_cols = opj.numMatrixCols(s); int nr_rows = opj.numMatrixRows(s); Matrix *matrix = mw->newMatrix(opj.matrixName(s), nr_rows, nr_cols); if (!matrix) return false; rect windowRect; if (opj.Version() == 7.5) { windowRect = opj.matrixWindowRect(s); matrix->resize(windowRect.width() - (matrix->frameGeometry().width() - matrix->width()), windowRect.height() - (matrix->frameGeometry().height() - matrix->height())); } matrix->setCaptionPolicy((MdiSubWindow::CaptionPolicy)opj.matrixTitle(s)); matrix->setBirthDate(JulianDateTime2String(opj.matrixCreationDate(s))); matrix->setWindowLabel(opj.matrixLabel(s)); matrix->setFormula(opj.matrixFormula(s)); matrix->setColumnsWidth(opj.matrixWidth(s) * QtiPlot_scaling_factor); if (opj.matrixViewType(s) == matrix::ImageView) matrix->setViewType(Matrix::ImageView); if (opj.matrixHeaderViewType(s) == matrix::XY) matrix->setHeaderViewType(Matrix::XY); vector<double> data = opj.matrixData(s); double *matrix_data = matrix->matrixModel()->dataVector(); int size = matrix->numRows() * matrix->numCols(); int cell = 0; for (int i = 0; i < size; i++) { double val = data[cell]; if (val < 2.0e-300) val = GSL_NAN; matrix_data[cell] = val; cell++; } QChar format; switch (opj.matrixValueTypeSpec(s)) { case 0: // Decimal 1000 format = 'f'; break; case 1: // Scientific format = 'e'; break; case 2: // Engeneering case 3: // Decimal 1,000 format = 'g'; break; } matrix->setNumericFormat(format, opj.matrixSignificantDigits(s)); if (!opj.matrixHidden(s) || opj.Version() != 7.5) { switch (opj.matrixState(s)) { case originWindow::Minimized: mw->minimizeWindow(matrix); break; case originWindow::Maximized: mw->maximizeWindow(matrix); break; default: matrix->showNormal(); } // cascade the matrices if (opj.Version() == 7.5) matrix->move(QPoint(windowRect.left, windowRect.top)); else { int dx = matrix->verticalHeaderWidth(); int dy = matrix->frameGeometry().height() - matrix->height(); matrix->move(QPoint(visible_count * dx + xoffset * OBJECTXOFFSET, visible_count * dy)); visible_count++; } } } if (visible_count > 0) xoffset++; return true; }
int muParserScript::setDynamicVars() { bool allSourcesEmpty = !rowIndexes.isEmpty(); if (Context->isA("Table")) { Table *table = (Table*) Context; strDict::iterator i=rowIndexes.begin(),j=colIndexes.begin(); while((i!=rowIndexes.end())&&(j!=colIndexes.end())) { int col, row; if (i.data() == "i" && variables["i"]) row = (int) *(variables["i"]) - 1; else { rparser.SetExpr(i.data().ascii()); row = qRound(rparser.Eval()) - 1; } col=j.data().toInt(); if (row < 0 || row >= table->tableRows() || col < 0 || col >= table->tableCols()) return 0; if (table->text(row,col).isEmpty()) setDouble(0, i.key().ascii()); else { setDouble((table->text(row,col)).toDouble(), i.key().ascii()); allSourcesEmpty = false; } i++; j++; } } else if (Context->isA("Matrix")) { Matrix *matrix = (Matrix*) Context; strDict::iterator i=rowIndexes.begin(),j=colIndexes.begin(); while((i!=rowIndexes.end())&&(j!=colIndexes.end())) { int col, row; if (i.data() == "i" && variables["i"]) row = (int) *(variables["i"]) - 1; else { rparser.SetExpr(i.data().ascii()); row = qRound(rparser.Eval()) - 1; } if (j.data() == "j" && variables["j"]) col = (int) *(variables["j"]) - 1; else { rparser.SetExpr(j.data().ascii()); col = qRound(rparser.Eval()) - 1; } if (row < 0 || row >= matrix->numRows() || col < 0 || col >= matrix->numCols()) return 0; if (matrix->text(row,col).isEmpty()) setDouble(0, i.key().ascii()); else { setDouble((matrix->text(row,col)).toDouble(), i.key().ascii()); allSourcesEmpty=false; } i++; j++; } } for (strDict::iterator i=userVariables.begin(); i!=userVariables.end(); i++) { rparser.SetExpr(i.data().ascii()); if (!setDouble(rparser.Eval(), i.key().ascii())) return 0; } if (allSourcesEmpty) return 2; return 1; }
int numCols (Matrix m) { return m.numCols(); }