testing updates
This commit is contained in:
BIN
scripts/__pycache__/amsbinarrayrw.cpython-310.pyc
Normal file
BIN
scripts/__pycache__/amsbinarrayrw.cpython-310.pyc
Normal file
Binary file not shown.
81
scripts/amsbinarrayrw.py
Normal file
81
scripts/amsbinarrayrw.py
Normal file
@ -0,0 +1,81 @@
|
||||
#!/usr/bin/python3
|
||||
import os,sys,math
|
||||
import numpy as np
|
||||
|
||||
#Write double ndarray
|
||||
def fwrite_dndarray(fp,array):
|
||||
|
||||
array = np.array(array,dtype=np.float64,order='F')
|
||||
|
||||
Ndim = np.int32(len(array.shape))
|
||||
shp = np.int32(array.shape)
|
||||
|
||||
q = Ndim.tobytes()
|
||||
fp.write(q)
|
||||
if(Ndim>0):
|
||||
q = shp.tobytes()
|
||||
fp.write(q)
|
||||
|
||||
q = array.tobytes()
|
||||
fp.write(q)
|
||||
|
||||
return
|
||||
|
||||
#Read double ndarray
|
||||
def fread_dndarray(fp):
|
||||
|
||||
array = np.zeros((),dtype=np.float64,order='F')
|
||||
|
||||
q = fp.read(4)
|
||||
Ndim = np.frombuffer(q,dtype=np.int32,count=1)[0]
|
||||
|
||||
if(Ndim>0):
|
||||
q = fp.read(4*Ndim)
|
||||
shp = np.frombuffer(q,dtype=np.int32,count=Ndim)
|
||||
piprod = 1
|
||||
for i in range(0,len(shp)):
|
||||
piprod = piprod*shp[i]
|
||||
q = fp.read(8*piprod)
|
||||
array = np.frombuffer(q,dtype=np.float64,count=piprod)
|
||||
array = array.reshape(shp,order='F')
|
||||
|
||||
return array
|
||||
|
||||
#Write float ndarray
|
||||
def fwrite_fndarray(fp,array):
|
||||
|
||||
array = np.array(array,dtype=np.float32,order='F')
|
||||
|
||||
Ndim = np.int32(len(array.shape))
|
||||
shp = np.int32(array.shape)
|
||||
|
||||
q = Ndim.tobytes()
|
||||
fp.write(q)
|
||||
if(Ndim>0):
|
||||
q = shp.tobytes()
|
||||
fp.write(q)
|
||||
|
||||
q = array.tobytes()
|
||||
fp.write(q)
|
||||
|
||||
return
|
||||
|
||||
#Read float ndarray
|
||||
def fread_fndarray(fp):
|
||||
|
||||
array = np.zeros((),dtype=np.float32,order='F')
|
||||
|
||||
q = fp.read(4)
|
||||
Ndim = np.frombuffer(q,dtype=np.int32,count=1)[0]
|
||||
|
||||
if(Ndim>0):
|
||||
q = fp.read(4*Ndim)
|
||||
shp = np.frombuffer(q,dtype=np.int32,count=Ndim)
|
||||
piprod = 1
|
||||
for i in range(0,len(shp)):
|
||||
piprod = piprod*shp[i]
|
||||
q = fp.read(4*piprod)
|
||||
array = np.frombuffer(q,dtype=np.float32,count=piprod)
|
||||
array = array.reshape(shp,order='F')
|
||||
|
||||
return array
|
31
scripts/checkrandomness.py
Normal file
31
scripts/checkrandomness.py
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
import os,sys,math
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from amsbinarrayrw import *
|
||||
|
||||
def plot_random1():
|
||||
|
||||
fp = open("./build_linux64/tmp_testrand.bin","r+b")
|
||||
data = fread_dndarray(fp)
|
||||
N1 = data.shape[0]
|
||||
N2 = int(math.sqrt(N1))
|
||||
N3 = N2*N2
|
||||
data = data[0:N3]
|
||||
data = data.reshape([N2,N2])
|
||||
q = np.zeros([N2,N2,3])
|
||||
q[:,:,0] = data[:,:]
|
||||
q[:,:,1] = data[:,:]
|
||||
q[:,:,2] = data[:,:]
|
||||
|
||||
hf = plt.figure(1)
|
||||
plt.imshow(q)
|
||||
plt.show()
|
||||
fp.close()
|
||||
|
||||
if(__name__=="__main__"):
|
||||
plot_random1()
|
||||
|
||||
pass
|
Reference in New Issue
Block a user