()
| 47 | return Bytes |
| 48 | |
| 49 | def main(): |
| 50 | Host, Port = '127.0.0.1', 5006 |
| 51 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 52 | s.connect((Host, Port)) |
| 53 | for i in range(10): |
| 54 | N = np.random.randint(3,10) # 3 <= N < 10 |
| 55 | A = np.random.rand(N,N) |
| 56 | s.send(struct.pack('q',N)) # send N |
| 57 | print(f'sending A ({N:2d} x {N:2d}) ',end='') |
| 58 | s.send(A.tobytes()) # send A |
| 59 | Bytes = wait_for_nBytes(8*N*N, s) |
| 60 | Ainv = np.frombuffer(Bytes, dtype=np.float64) |
| 61 | # could also do |
| 62 | # Ainv = np.array(struct.unpack(f'{N*N}d',Bytes)) |
| 63 | Ainv = Ainv.reshape(N,N) |
| 64 | err = np.max(np.eye(N) - A@Ainv) |
| 65 | print(f'err = {err:e}') |
| 66 | s.close() |
| 67 | if __name__ == "__main__": main() |
no test coverage detected