|
1 #!/usr/bin/python |
|
2 # Produces two polynomial matrices P1, P2 |
|
3 # P1 consists of first p1 columns of P |
|
4 # P2 consists of remaining p2 columns of P |
|
5 |
|
6 import pylab as pl |
|
7 from polyfuncs import polsize |
|
8 |
|
9 def colsplit(P, degP, p1, p2): |
|
10 P = pl.atleast_2d(P) |
|
11 if pl.atleast_2d(P).size is 0: |
|
12 P1 = pl.atleast_2d([]) |
|
13 P2 = pl.atleast_2d([]) |
|
14 return P1, None, P2, None |
|
15 |
|
16 rP, cP = polsize(P, degP) |
|
17 |
|
18 if not 0 <= p1 <= cP or not 0 <= p2 <= cP or p1+p2 != cP: |
|
19 print 'colsplit: Inconsistent numbers of columns' |
|
20 return None |
|
21 exit(1) |
|
22 |
|
23 P1 = pl.atleast_2d(pl.zeros((rP, (degP+1)*p1))) |
|
24 P2 = pl.atleast_2d(pl.zeros((rP, (degP+1)*p2))) |
|
25 |
|
26 |
|
27 for i in range(degP+1): |
|
28 P1[:,i*p1:(i+1)*p1] = P[:,i*cP:i*cP+p1] |
|
29 P2[:,i*p2:(i+1)*p2] = P[:,i*cP+p1:(i+1)*cP] |
|
30 |
|
31 return P1, degP, P2, degP |
|
32 |
|
33 if __name__== "__main__": |
|
34 s = """P = pl.array([[1, 2, 3, 4, 1, 2, 3, 4], |
|
35 [9, 10, 11, 12, 9, 10, 11, 12], |
|
36 [5, 6, 7, 8, 5, 6, 7, 8]])""" |
|
37 print s |
|
38 exec(s) |
|
39 print """colsplit(P, 3, 1, 1)""" |
|
40 print colsplit(P, 3, 1, 1) |