void
matrix()
{
- int N=10;
- Matrix m(N,N), q(N,N);
- Vector v(N);
+ int N=10;
+ Matrix m(N,N), q(N,N);
+ Vector v(N);
- for (int i=0; i < N; i++) {
- v(i) =i;
- for (int j=0; j < N; j++) {
- m(i,j) = i+j;
- q(i,j) = (abs(i-j) > 3) ?0 :i-j;
- }
+ for (int i=0; i < N; i++) {
+ v(i) =i;
+ for (int j=0; j < N; j++) {
+ m(i,j) = i+j;
+ q(i,j) = (abs(i-j) > 3) ?0 :i-j;
}
+ }
- cout << "v: " << String(v);
- cout << "m: " << String(m );
- cout << "q: " << String(q);
- cout << "m*q; " << String(m*q);
- cout << "m*m: " << String(m*m);
- m.OK();
- cout << "m: " << String(m);
- cout << "q.band " << q.band_i() << endl;
- q.try_set_band();
- cout << "q(B): " << q;
- q.OK();
- Matrix sum(q+q);
- cout << "q + q " << sum;
- q.OK();
- cout << "q*q: " << q*q;
- q.OK();
+ cout << "v: " << String(v);
+ cout << "m: " << String(m );
+ cout << "q: " << String(q);
+ cout << "m*q; " << String(m*q);
+ cout << "m*m: " << String(m*m);
+ m.OK();
+ cout << "m: " << String(m);
+ cout << "q.band " << q.band_i() << endl;
+ q.try_set_band();
+ cout << "q(B): " << q;
+ q.OK();
+ Matrix sum(q+q);
+ cout << "q + q " << sum;
+ q.OK();
+ cout << "q*q: " << q*q;
+ q.OK();
- Matrix hilbert(N,N), h2(hilbert);
- for (int i=0; i < N; i++) {
- for (int j=0; j < N; j++) {
- hilbert(i,j) = 1/Real(i+j+1);
- h2 (i,j) = (abs(i-j) > 3) ?0 : hilbert(i,j);
- }
+ Matrix hilbert(N,N), h2(hilbert);
+ for (int i=0; i < N; i++) {
+ for (int j=0; j < N; j++) {
+ hilbert(i,j) = 1/Real(i+j+1);
+ h2 (i,j) = (abs(i-j) > 3) ?0 : hilbert(i,j);
}
- h2.try_set_band();
- Choleski_decomposition ch(h2);
- cout << "red Hilbert " << h2;
- cout << "choleski " << ch.L;
- Matrix T =ch.L.transposed();
- cout << "L^T " << T;
- cout << "L * L^T" << ch.L * T;
- cout << "H2^{-1} * H2" << h2 * ch.inverse();
+ }
+ h2.try_set_band();
+ Choleski_decomposition ch(h2);
+ cout << "red Hilbert " << h2;
+ cout << "choleski " << ch.L;
+ Matrix T =ch.L.transposed();
+ cout << "L^T " << T;
+ cout << "L * L^T" << ch.L * T;
+ cout << "H2^{-1} * H2" << h2 * ch.inverse();
}
ADD_TEST(matrix);
void
ctors()
{
- cout << "constructors"<<endl;
-
+ cout << "constructors"<<endl;
+ {
String str( "hai" );
- String def;
- String fromi(10);
- String fromc('c');
- String fromf(1.32e-2, "%g");
-
cout << str << endl;
- cout << def << endl;
+ }
+ {
+ String fromi(10);
cout << fromi<< endl;
+ }
+ {String fromf(1.32e-2, "%g");
+ cout << fromf<< endl;
+ }
+ {
+ String def;
+ cout << def << endl;
+ }
+ {
+ String fromc('c');
cout << fromc<< endl;
- cout << fromf<< endl;
+ }
}
-
void
cmp()
{
- Array<String> a;
- a.push("abcd");
- a.push("zxy");
- a.push("abc");
- a.push("");
- a.sort(String::compare_i);
- cout << "compares: "<<endl;
- for (int i=0; i < a.size(); i++)
- cout << a[i] << endl;
+ Array<String> a;
+ a.push("abcd");
+ a.push("zxy");
+ a.push("abc");
+ a.push("");
+ a.sort(String::compare_i);
+ cout << "compares: "<<endl;
+ for (int i=0; i < a.size(); i++)
+ cout << a[i] << endl;
}
void
searching()
{
- String hay = "foobarbazblub";
-
- char c = 'b';
- String cstr =c;
- String set = "bar";
- cout << "hay = \"" << hay << "\" len="<< hay.length_i()<<endl;
- cout << "index_i('"<< c<<"') " << c << "= " << hay.index_i(c) <<endl;
- cout << "last_index_i('"<< c<<"') " << c << "= " << hay.index_last_i(c) <<endl;
-// cout << "last index of cstr " << c << ": " << hay.index_last_i(cstr) <<endl;
-// cout << "index_last_i(\""<<set<<"\"): " << hay.index_last_i(set) <<endl;
- cout << "index_i(\""<<set<<"\"): " << hay.index_i(set) <<endl;
- cout << "index_any(\"" << set << "\"): " << cstr << ": " << hay.index_any_i(cstr) <<endl;
+ String hay = "foobarbazblub";
+
+ char c = 'b';
+ String cstr =c;
+ String set = "bar";
+ cout << "hay = \"" << hay << "\" len="<< hay.length_i()<<endl;
+ cout << "index_i('"<< c<<"') " << c << "= " << hay.index_i(c) <<endl;
+ cout << "last_index_i('"<< c<<"') " << c << "= " << hay.index_last_i(c) <<endl;
+ // cout << "last index of cstr " << c << ": " << hay.index_last_i(cstr) <<endl;
+ // cout << "index_last_i(\""<<set<<"\"): " << hay.index_last_i(set) <<endl;
+ cout << "index_i(\""<<set<<"\"): " << hay.index_i(set) <<endl;
+ cout << "index_any(\"" << set << "\"): " << cstr << ": " << hay.index_any_i(cstr) <<endl;
void
kutenpeer()
{
- String str( "hai" );
- for (int i=-1; i < str.length_i()+2; i++) {
- cout<<" left_str(" << i<<"): " << str.left_str( i ) << endl;
- cout<<" right_str( "<<i<<"): " << str.right_str( i ) << endl;
- }
- str = "blonde haren";
- cout << str<<endl;
- cout << "mid(2,6)="<<str.mid_str(2,6)<<endl;
- cout << "nomid(2,6)="<<str.nomid_str(2,6)<<endl;
+ String str( "hai" );
+ for (int i=-1; i < str.length_i()+2; i++) {
+ cout<<" left_str(" << i<<"): " << str.left_str( i ) << endl;
+ cout<<" right_str( "<<i<<"): " << str.right_str( i ) << endl;
+ }
+ str = "blonde haren";
+ cout << str<<endl;
+ cout << "mid(2,6)="<<str.cut(2,6)<<endl;
+ cout << "nomid(2,6)="<<str.nomid_str(2,6)<<endl;
}
bool
test_empty_b( String str )
{
- cout << "`" << str << "' is ";
+ cout << "`" << str << "' is ";
- if ( str == String( "" ) ) {
- cout << "empty" << endl;
- return true;
- }
+ if ( str == String( "" ) ) {
+ cout << "empty" << endl;
+ return true;
+ }
- cout << "not empty" << endl;
- return false;
+ cout << "not empty" << endl;
+ return false;
}
void
stringtest()
{
- ctors();
- cmp();
- searching();
- kutenpeer();
- String str( "hai" );
- cout << str << endl;
- cout << "left" << endl;
- str += " daar";
- cout << str << endl;
-
-// str = String( "Hallo" ) + " daaR" + '!'; // no go on doze-s gcc2.7.2?
- str = String( "Hallo" ) + " daaR" + "!";
- cout << str << endl;
-
- cout << "up: " << str.upper_str() << " down: " << str.lower_str()<<endl;
+ ctors();
+ cmp();
+ searching();
+ kutenpeer();
+ String str( "hai" );
+ cout << str << endl;
+ cout << "left" << endl;
+ str += " daar";
+ cout << str << endl;
+
+ // str = String( "Hallo" ) + " daaR" + '!'; // no go on doze-s gcc2.7.2?
+ str = String( "Hallo" ) + " daaR" + "!";
+ cout << str << endl;
+
+ cout << "up: " << str.upper_str() << " down: " << str.lower_str()<<endl;
- if ( test_empty_b( str ) )
- cout << "failed";
+ if ( test_empty_b( str ) )
+ cout << "failed";
- String fn = "";
- if ( !test_empty_b( fn ) )
- cout << "failed";
+ String fn = "";
+ if ( !test_empty_b( fn ) )
+ cout << "failed";
- fn = "";
- fn += "";
- delete fn.copy_byte_p();
- delete str.copy_byte_p();
-
- cout << String_convert::bin2hex_str( String( (char)0xff ) ) << endl;
- cout << "-1:" << String_convert::i2hex_str( -1, 2, '0' );
- cout << endl;
+ fn = "";
+ fn += "";
+ delete fn.copy_byte_p();
+ delete str.copy_byte_p();
+
+ cout << String_convert::bin2hex_str( String( (char)0xff ) ) << endl;
+ cout << "-1:" << String_convert::i2hex_str( -1, 2, '0' );
+ cout << endl;
}