File: svectest.cc

package info (click to toggle)
eclib 20190909-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,196 kB
  • sloc: cpp: 47,090; makefile: 251; sh: 122
file content (115 lines) | stat: -rw-r--r-- 3,663 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// svectest.cc: Test of sparse vector package
//////////////////////////////////////////////////////////////////////////
//
// Copyright 1990-2012 John Cremona
// 
// This file is part of the eclib package.
// 
// eclib is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// eclib is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License
// along with eclib; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
// 
//////////////////////////////////////////////////////////////////////////
 
#include <eclib/arith.h>
#include <eclib/types.h>

int main(void)
{
 cout << "Test run of sparse vector package.\n\n"; 
 int i,j,n,a;
 cout << "Enter n : "; cin >> n;
 svec v;
 cout << "Uninitialized new vec v = " << v << endl;
 svec v2(v);
 cout << "Copy of v = " << v2 << endl;
 cout << "Enter new entries of v: ";
 cout << "Dimension = "; cin>>n;  v=svec(n);
 cout << "Number of entries = "; cin>>n;
 for(i=1; i<=n; i++)
   {
     cout<<"Position: "; cin>>j;  
     cout<<"Entry:    "; cin>>a;  
     v.set(j,a);
   }
 cout << "Now v = " << v << endl;

 svec w(3);
 cout << "w = " << w <<  endl;
 w = v;
 cout << "After w=v, " << endl;
 cout << "Now v = " << v << endl;
 cout << "Now w = " << w << endl;
 cout << "w==v: " << (w==v) << endl;
 cout << "w!=v: " << (w!=v) << endl;
 cout << "v+w = " << v+w << endl;
 cout << "v-w = " << v-w << endl;
 cout << "Enter i : "; cin >> i;
 w*=2;
 cout << "After w*=2, w = " << w << endl;
 cout << "3*v = " << (3*v) << endl;
 cout << "Now v = " << v << endl;
 cout << "v+w = " << v+w << endl;
 cout << "Now v = " << v << endl;
 cout << "v-w = " << v-w << endl;
 cout << "Now v = " << v << endl;
 cout << "w/2 = " << w/2 << endl;
 cout << "Now w = " << w << endl;
 cout << "-v  = " << -v  << endl;
 cout << "+v  = " << +v  << endl;
 cout << "+w  = " << +w  << endl;
 cout << "2*v-w = " << (2*v-w) << endl;
 cout << "Resetting w[1] to 99: "; w.set(1,99);
 cout << "w = " << w << endl;
 w -= 2*v;
 cout << "After w-=2*v, w = " << w << endl;

 vec vv = v.as_vec();
 cout << "v as an ordinary vector = "<<vv<<endl;

#if(0)
 cout << "Member test: Enter a test number: " ;
 cin >> i; cout << i;
 if (member(i,v)) cout << " IS "; else cout << " IS NOT ";
 cout << "a member of v." << endl;

 cout << "Subscript test\n";
 cout << "Enter length of subscript vec:";
 int m; cin >> m; vec index=vec(m);
 cout << "Enter subscript vector:";
 cin >> index;
 vec vv = v[index];
 cout << "The sub-vector is " << vv << endl;

 cout << "Change one entry of v.  Index?"; cin >> i;
 cout << "New entry?"; scalar x; cin >> x;
 v[i]=x;
 cout << "New entry: v[" << i << "] = " << v[i] << endl;
 cout << "Now v = " << v << endl;

 cout << "Initial slice; length? "; cin >> j;
 cout << "Slice = " << v.slice(j) << endl;
 cout << "Now v = " << v << endl;
 cout << "General slice; beginning, end? "; cin >> j >> k;
 cout << "Slice = " << v.slice(j,k) << endl;
 cout << "Now v = " << v << endl;
 cout << "w = " << w << "; vecgcd(w) = " << vecgcd(w) << endl;
 makeprimitive(w);
 cout << "After makeprimitive(w), w = " << w << endl;

 vec u(n);
 cout << "u = "<< u << endl;
 swapvec(u,v);
 cout << "After swapvec(u,v):\nu = " << u << "\nv = " << v << endl;
#endif
}