- refactored read_armadillo into matrix

- added test_norbs
This commit is contained in:
2025-12-21 18:16:48 +01:00
parent e11f775aff
commit ff05c729e8
4 changed files with 81 additions and 22 deletions
+20 -2
View File
@@ -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