Module: Muze::Core::DCT
- Defined in:
- lib/muze/core/dct.rb
Overview
DCT utilities.
Constant Summary collapse
- BASIS_CACHE =
Muze::Core::BoundedCache.new(max_size: 64)
Class Method Summary collapse
Class Method Details
.dct(x, type: 2, n: nil, axis: 0, norm: :ortho) ⇒ Numo::SFloat
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/muze/core/dct.rb', line 16 def dct(x, type: 2, n: nil, axis: 0, norm: :ortho) raise Muze::ParameterError, "only DCT type 2 is supported" unless type == 2 raise Muze::ParameterError, "axis must be 0 or 1" unless [0, 1].include?(axis) matrix = Numo::SFloat.cast(x) matrix = matrix.(1) if matrix.ndim == 1 matrix = matrix.transpose if axis == 1 rows, cols = matrix.shape target_length = n || rows working = adjust_rows(matrix, target_length) result = basis_matrix(rows: target_length, cols: target_length, norm:).dot(working).cast_to(Numo::SFloat) axis == 1 ? result.transpose : result end |