/ proof-of-concept / benchcompress
Sign in
proof-of-concept / benchcompress
benchcompress / benchcompress / src / benchcompress / algorithms / ans / lpc_reconstruct.py
39 lines · 1.3 KBBlameHistoryRaw
1import numpy as np
2from .lpc_reconstruct_cpp_ext import (
3 lpc_reconstruct_int16,
4 lpc_reconstruct_int32,
5)
8def lpc_reconstruct(coeffs, initial, resid):
9 """Reconstruct signal from Markov model parameters and residuals using C++ implementation.
11 Args:
12 coeffs: Model coefficients from linear regression (float32)
13 initial: Initial values needed for prediction (int16 or int32)
14 resid: Prediction residuals (must match initial dtype)
16 Returns:
17 np.ndarray: Reconstructed signal (same dtype as input)
19 Raises:
20 ValueError: If initial/resid arrays are not int16 or int32, or if their dtypes don't match
21 """
22 # Convert coeffs to float32 if needed
23 coeffs = coeffs.astype(np.float32)
25 # Check input dtypes
26 if initial.dtype != resid.dtype:
27 raise ValueError(
28 f"Initial and residual arrays must have same dtype, got {initial.dtype} and {resid.dtype}"
29 )
31 # Call appropriate implementation based on dtype
32 if initial.dtype == np.int16:
33 return lpc_reconstruct_int16(coeffs, initial, resid)
34 elif initial.dtype == np.int32:
35 return lpc_reconstruct_int32(coeffs, initial, resid)
36 else:
37 raise ValueError(
38 f"Initial/residual arrays must be int16 or int32, got {initial.dtype}"
39 )
↑↓ move↵openescclose