| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
package net.sourceforge.combean.mathprog.linalg.statics; |
| 6 | |
|
| 7 | |
import net.sourceforge.combean.interfaces.mathprog.linalg.SparseVec; |
| 8 | |
import net.sourceforge.combean.interfaces.mathprog.linalg.VectorIterator; |
| 9 | |
import net.sourceforge.combean.interfaces.mathprog.linalg.VectorValue; |
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | 0 | public class SparseVectorStringifier { |
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
public static <Label> String convertToString(SparseVec<Label> svec) { |
| 27 | 0 | StringBuffer result = new StringBuffer(); |
| 28 | |
|
| 29 | 0 | result.append("LPSparseVector { "); |
| 30 | |
|
| 31 | 0 | result.append(" values {"); |
| 32 | 0 | VectorIterator<Label> itVec = svec.iterator(); |
| 33 | 0 | while (itVec.hasNext()) { |
| 34 | 0 | VectorValue<Label> val = itVec.next(); |
| 35 | 0 | result.append(" " + val.label() + "[" + val.index() + "]=" + |
| 36 | |
val.doubleValue()); |
| 37 | |
|
| 38 | 0 | } |
| 39 | 0 | result.append(" } }"); |
| 40 | |
|
| 41 | 0 | return result.toString(); |
| 42 | |
} |
| 43 | |
|
| 44 | |
} |