AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
SparseMatrix.java
Go to the documentation of this file.
1package aud.graph.matrix;
2
3import aud.Vector;
4import aud.util.*; // testing
5
19public class SparseMatrix<T> extends SparseMatrixCS<T> {
20
29 protected SparseMatrixCS<T> rmat_ = null;
30
32 public SparseMatrix() {
33 this(false);
34 }
35
37 public SparseMatrix(boolean symmetric) {
38 super();
39 rmat_=symmetric ? this : new SparseMatrixCS<T>();
40 }
43 super(other);
44 rmat_= other.isSymmetricMatrix() ?
45 new SparseMatrixCS<T>(other.rmat_) : this;
46 }
48 public SparseMatrix(SparseMatrix<T> other,boolean transpose) {
49 super((transpose && !other.isSymmetricMatrix()) ? other.rmat_ : other);
50 if (other.isSymmetricMatrix())
51 rmat_=this;
52 else
53 rmat_=transpose ?
54 new SparseMatrixCS<T>(other) : new SparseMatrixCS<T>(other.rmat_);
55 }
56
58 public boolean isSymmetricMatrix() { return rmat_==this; }
59
61 @Override public int getNumRows() {
62 return rmat_.getNumColumns();
63 }
65 @Override public int getMinRowIndex() {
66 return rmat_.getMinColumnIndex();
67 }
68
69 @Override public T set(int i,int j,T data) {
70 T v,vr;
71 v=super.set(i,j,data);
72 vr=rmat_._set(j,i,data);
73 assert(v==vr || i==j);
74 return v;
75 }
76
80 public Vector<T> getRowEntries(int i) {
81 return rmat_.getColumnEntries(i);
82 }
83
87 public int[] getRowColumnIndices(int i) {
88 return rmat_.getColumnRowIndices(i);
89 }
90
95 public int rowDegree(int i) { return getRowEntries(i).size(); }
96
97 @Override public SparseMatrixCS<T> getTransposed() {
98 return new SparseMatrixCS<T>(rmat_);
99 }
100
101 //
102 // TODO multiply (spones)? --> spones_power
103 //
104
106 public static void main(String args[]) {
108
109 m.set(1,1,-1);
110 m.set(2,1,0);
111 m.set(3,1,1);
112 m.set(4,1,2);
113 m.set(5,1,3);
114 m.set(6,1,4);
115 m.set(7,1,5);
116 m.set(8,1,6);
117 m.set(9,1,7);
118 m.set(10,1,8);
119 m.set(11,1,9);
120 m.set(12,1,10);
121 m.set(13,1,11);
122 m.set(1,1,11);
123
124 m.set(1,5,11);
125
126 Colormap<Integer> colormap= new ColormapCount();
127
128 //m.renderSpySVG(new java.io.File("colormap.svg"),colormap);
129
130 m.spy("colormap",colormap);
131
132 System.out.println(m.spyTikZ(true,colormap));
133 }
134}
Implementation of an array-based vector.
Definition: Vector.java:44
Simple sparse matrix data structure.
SVGViewer spy(String caption, Colormap< T > colormap)
render spy plot in new window
String spyTikZ(boolean rulers, Colormap< T > colormap)
Simple sparse matrix data structure.
int getMinRowIndex()
get minimum column index [O(1)]
int getNumRows()
computed from maximum column index [O(1)]
T set(int i, int j, T data)
Set entry (i,j) to data [O(log(nnz))].
Vector< T > getRowEntries(int i)
get entries in row i as array
SparseMatrixCS< T > getTransposed()
get transposed matrix
boolean isSymmetricMatrix()
Was matrix created explicitly as symmetric matrix?
SparseMatrixCS< T > rmat_
Store transposed.
static void main(String args[])
Example and test: show aud.util.ColormapCount color map.
int rowDegree(int i)
get number of nonzero entries in row i
SparseMatrix(SparseMatrix< T > other, boolean transpose)
copy constructor
SparseMatrix(boolean symmetric)
create empty matrix (see isSymmetricMatrix)
SparseMatrix()
create empty matrix
SparseMatrix(SparseMatrix< T > other)
copy constructor
int[] getRowColumnIndices(int i)
get column indices in row i as array
color map for (small) positive integer counts
simple interface for color map
Definition: Colormap.java:4
utilities (not related to AuD lecture)
Definition: Colormap.java:1
AuD lecture: Data structures, algorithms, examples.
Definition: A234Tree.java:1