- refactored read_armadillo into matrix
- added test_norbs
This commit is contained in:
+20
-2
@@ -1,7 +1,6 @@
|
||||
import time
|
||||
from typing import TypeAlias
|
||||
|
||||
USE_CUDA = 1
|
||||
USE_CUDA = 0
|
||||
if USE_CUDA:
|
||||
import cupy as np
|
||||
Mat: TypeAlias = np.array
|
||||
@@ -36,3 +35,22 @@ def rms_error_accu(d_err: Mat):
|
||||
s = np.sum(d_err_squared) / d_err.size
|
||||
return s
|
||||
|
||||
def read_armadillo(filename: str) -> Mat:
|
||||
result = None
|
||||
with open(filename) as fp:
|
||||
identifier = fp.readline().replace("\n", '')
|
||||
if "ARMA_MAT_TXT_FN008" not in identifier:
|
||||
raise Exception("Not a armadillo data file!")
|
||||
|
||||
line = fp.readline().replace("\n", '').split(' ')
|
||||
shape = [int(s) for s in line]
|
||||
print(f"shape: {shape}")
|
||||
|
||||
result = np.zeros(shape=shape, dtype=np.float64)
|
||||
for row in range(shape[0]):
|
||||
line = fp.readline().replace("\n", '').split(' ')
|
||||
line = line[1:]
|
||||
data = [float(s) for s in line]
|
||||
result[row, :] = Mat(data)
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user