/[ascend]/trunk/ascxx/matrix.cpp
ViewVC logotype

Contents of /trunk/ascxx/matrix.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2327 - (show annotations) (download) (as text)
Wed Dec 22 07:17:24 2010 UTC (8 years, 11 months ago) by jpye
File MIME type: text/x-c++src
File size: 1391 byte(s)
Merging in refactor of the C++ code, which is moved out of 'pygtk' and into 'ascxx'.
Adding support for IPOPT 3.9.1, the current latest version.
Support in dtar for parallel builds (possibly needs some testing still).
1 extern "C"{
2 #include <ascend/utilities/config.h>
3 #include <ascend/general/panic.h>
4 }
5
6 #include <stdexcept>
7 #include <sstream>
8
9 #include "matrix.h"
10
11 using namespace std;
12
13 Matrix::Matrix() : M(NULL){
14 // nothing else
15 }
16
17 Matrix::Matrix(const Matrix &old) : M(old.M){
18 asc_assert(M!=NULL);
19 }
20
21 Matrix::Matrix(mtx_matrix_t M) : M(M){
22 asc_assert(M!=NULL);
23 }
24
25 /**
26 Write out a matrix to a file, in a format by the user
27
28 @param format format in which to write output ("mtx","debug", others as
29 implemented)
30
31 Return 0 on success, 1 on error
32 */
33 int
34 Matrix::write(FILE *fp, const string &format) const{
35
36 CONSOLE_DEBUG("HERE IN MATRIX::WRITE");
37
38 CONSOLE_DEBUG("Writing matrix in format '%s'",format.c_str());
39
40 if(M==NULL)throw runtime_error("Matrix is NULL");
41 if(fp==NULL)throw runtime_error("File is NULL");
42
43 if(format=="matlab"){
44 mtx_write_region_matlab(fp, M, mtx_ENTIRE_MATRIX);
45 #ifdef ASC_WITH_MMIO
46 }else if(format=="mtx"||format=="mmio"||format=="matrixmarket"){
47 return mtx_write_region_mmio(fp, M, mtx_ENTIRE_MATRIX);
48 #endif
49 }else if(format=="debug"){
50 mtx__debug_output(fp, M);
51 }else{
52 throw runtime_error("Unrecognised export format requested");
53 }
54
55 return 0;
56 }
57
58 /**
59 Return the size of the mtx (the entire matrix)
60 */
61 vector<unsigned>
62 Matrix::size() const{
63 asc_assert(M!=NULL);
64 vector<unsigned> v;
65 v.push_back(mtx_order(M));
66 v.push_back(mtx_order(M));
67 return v;
68 }
69
70
71
72
73

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22