NMatrix矩阵的水平连接在第二列中不正确

时间:2019-07-08 07:22:57

标签: ruby nmatrix

借助Ruby和SciRuby的NMatrix模块,我正在生成符合CCSDS标准的LDPC奇偶校验矩阵。生成矩阵涉及创建子矩阵,将它们连接在一起以形成最终的奇偶校验矩阵。但是,级联的最终结果不正确。

这是我现在要进行的连接:

def pi_K(k, m)
    mat = NMatrix.zeros(m, dtype: :int8, stype: :yale)

    mat.each_with_indices { |elem, col, row|
        if col == pi(k, row, m)
            mat[col, row] = 1 
        end
    }

    return mat
end

def xor_mul(a, b)
    return (a.dot(b)).map { |e| e % 2 }
end

# Some code not shown here

m = $submatrix_m[code_rate][block_len]

z_m = NMatrix.zeros(m, dtype: :int8, stype: :yale)
i_m = NMatrix.eye(m, dtype: :int8, stype: :yale)

i_m_pi_1   = xor_mul(i_m, pi_K(1, m))
pi_2_3_4   = xor_mul(xor_mul(pi_K(2, m), pi_K(3, m)), pi_K(4, m))
pi_5_6     = xor_mul(pi_K(5, m), pi_K(6, m))
pi_7_8     = xor_mul(pi_K(7, m), pi_K(8, m))

h = z_m.hconcat(z_m, i_m, z_m, i_m_pi_1).vconcat( \
    i_m.hconcat(i_m, z_m, i_m, pi_2_3_4)).vconcat( \
    i_m.hconcat(pi_5_6, z_m, pi_7_8, i_m))

# Save h matrix...

这是我在Octave中绘制最终的 h 矩阵时得到的结果:

Matrix plot in Octave

如您所见,第二个块列为空,但这不是预期的。此块列应具有一个标识子矩阵和另一个子矩阵 pi_5_6 。 我感觉在连接子矩阵时出了点问题,但是我什么都没看到。

0 个答案:

没有答案