Update suitable examples and tests to use blank mode
[shapes.git] / source / mathematicarepresentation.cc
blob352530def394157e2a5f79c015b609fc1840a423
1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * any later version.
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008 Henrik Tidefelt
19 #include "mathematicarepresentation.h"
21 #include <sstream>
23 using namespace Shapes;
26 std::string
27 Helpers::mathematicaFormat( size_t n1, size_t n2, size_t tda, const double * data )
29 std::ostringstream os;
30 os << "{" ;
31 for( const double * row = data; row != data + n1 * tda; row += tda )
33 if( row != data )
35 os << "," ;
37 os << "{" ;
38 for( const double * src = row; src != row + n2; ++src )
40 if( src != row )
42 os << "," ;
44 os << *src ;
46 os << "}" ;
48 os << "}" ;
49 return os.str( );
52 std::string
53 Helpers::mathematicaFormatTransposed( size_t n1, size_t n2, size_t tda, const double * data )
55 std::ostringstream os;
56 os << "{" ;
57 for( const double * row = data; row != data + n2; ++row )
59 if( row != data )
61 os << "," ;
63 os << "{" ;
64 for( const double * src = row; src != row + n1 * tda; src += tda )
66 if( src != row )
68 os << "," ;
70 os << *src ;
72 os << "}" ;
74 os << "}" ;
75 return os.str( );
78 std::string
79 Helpers::mathematicaFormat( size_t n, size_t stride, const double ** begin, const double ** end )
81 std::ostringstream os;
82 os << "{" ;
83 for( const double ** row = begin; row != end; ++row )
85 if( row != begin )
87 os << "," ;
89 os << "{" ;
90 for( const double * src = *row; src != *row + n * stride; src += stride )
92 if( src != *row )
94 os << "," ;
96 os << *src ;
98 os << "}" ;
100 os << "}" ;
101 return os.str( );
104 std::string
105 Helpers::mathematicaFormat( size_t n, size_t stride, const double * data )
107 std::ostringstream os;
108 os << "{" ;
109 for( const double * src = data; src != data + n * stride; src += stride )
111 if( src != data )
113 os << "," ;
115 os << *src ;
117 os << "}" ;
118 return os.str( );
121 std::string
122 Helpers::mathematicaFormat( const gsl_vector & x )
124 return Helpers::mathematicaFormat( x.size, x.stride, x.data );
127 std::string
128 Helpers::mathematicaFormat( const gsl_matrix & x, bool transpose )
130 if( transpose )
132 return Helpers::mathematicaFormatTransposed( x.size1, x.size2, x.tda, x.data );
134 else
136 return Helpers::mathematicaFormat( x.size1, x.size2, x.tda, x.data );