| 1 |
#!/usr/bin/python |
| 2 |
|
| 3 |
import sys |
| 4 |
import argparse |
| 5 |
import numpy as np |
| 6 |
from scipy.io import mmread |
| 7 |
from pylab import * |
| 8 |
|
| 9 |
parser = argparse.ArgumentParser(sys.argv[0]) |
| 10 |
parser.add_argument('-x,--solution', dest='x', default='x.mtx', help='Solution vector') |
| 11 |
parser.add_argument('-p,--part', dest='p', default='partition.mtx', help='Partition vector') |
| 12 |
args = parser.parse_args(sys.argv[1:]) |
| 13 |
|
| 14 |
x = mmread(args.x) |
| 15 |
p = mmread(args.p) |
| 16 |
|
| 17 |
n = x.shape[0] |
| 18 |
x.shape = (n,) |
| 19 |
p.shape = (n,) |
| 20 |
|
| 21 |
i = np.arange(n) |
| 22 |
j = np.array(sorted(i, key=lambda k: p[k])) |
| 23 |
|
| 24 |
y = np.zeros(x.shape) |
| 25 |
y[j] = x |
| 26 |
|
| 27 |
m = int(np.sqrt(n)); |
| 28 |
y.shape = (m,m) |
| 29 |
|
| 30 |
figure(num=1, figsize=(10,7)) |
| 31 |
subplot(1,2,1) |
| 32 |
imshow(y, origin='lower') |
| 33 |
colorbar() |
| 34 |
title('solution') |
| 35 |
|
| 36 |
subplot(1,2,2) |
| 37 |
imshow(p.reshape((m,m)), origin='lower') |
| 38 |
colorbar() |
| 39 |
title('partition') |
| 40 |
|
| 41 |
show() |