forked from M-Labs/artiq-zynq
kernel/linalg: remove redundant unsafe blocks
This commit is contained in:
parent
fbb636460b
commit
9f5e15e6d2
|
@ -55,8 +55,8 @@ pub unsafe extern "C" fn np_linalg_cholesky(mat1: *mut InputMatrix, out: *mut In
|
||||||
}
|
}
|
||||||
|
|
||||||
let outdim = out.get_dims();
|
let outdim = out.get_dims();
|
||||||
let out_slice = unsafe { slice::from_raw_parts_mut(out.data, outdim[0] * outdim[1]) };
|
let out_slice = slice::from_raw_parts_mut(out.data, outdim[0] * outdim[1]);
|
||||||
let data_slice1 = unsafe { slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]) };
|
let data_slice1 = slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]);
|
||||||
|
|
||||||
let matrix1 = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
let matrix1 = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
||||||
let result = matrix1.cholesky();
|
let result = matrix1.cholesky();
|
||||||
|
@ -93,9 +93,9 @@ pub unsafe extern "C" fn np_linalg_qr(mat1: *mut InputMatrix, out_q: *mut InputM
|
||||||
let outq_dim = (*out_q).get_dims();
|
let outq_dim = (*out_q).get_dims();
|
||||||
let outr_dim = (*out_r).get_dims();
|
let outr_dim = (*out_r).get_dims();
|
||||||
|
|
||||||
let data_slice1 = unsafe { slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]) };
|
let data_slice1 = slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]);
|
||||||
let out_q_slice = unsafe { slice::from_raw_parts_mut(out_q.data, outq_dim[0] * outq_dim[1]) };
|
let out_q_slice = slice::from_raw_parts_mut(out_q.data, outq_dim[0] * outq_dim[1]);
|
||||||
let out_r_slice = unsafe { slice::from_raw_parts_mut(out_r.data, outr_dim[0] * outr_dim[1]) };
|
let out_r_slice = slice::from_raw_parts_mut(out_r.data, outr_dim[0] * outr_dim[1]);
|
||||||
|
|
||||||
// Refer to https://github.com/dimforge/nalgebra/issues/735
|
// Refer to https://github.com/dimforge/nalgebra/issues/735
|
||||||
let matrix1 = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
let matrix1 = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
||||||
|
@ -138,10 +138,10 @@ pub unsafe extern "C" fn np_linalg_svd(
|
||||||
let outs_dim = (*outs).get_dims();
|
let outs_dim = (*outs).get_dims();
|
||||||
let outvh_dim = (*outvh).get_dims();
|
let outvh_dim = (*outvh).get_dims();
|
||||||
|
|
||||||
let data_slice1 = unsafe { slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]) };
|
let data_slice1 = slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]);
|
||||||
let out_u_slice = unsafe { slice::from_raw_parts_mut(outu.data, outu_dim[0] * outu_dim[1]) };
|
let out_u_slice = slice::from_raw_parts_mut(outu.data, outu_dim[0] * outu_dim[1]);
|
||||||
let out_s_slice = unsafe { slice::from_raw_parts_mut(outs.data, outs_dim[0]) };
|
let out_s_slice = slice::from_raw_parts_mut(outs.data, outs_dim[0]);
|
||||||
let out_vh_slice = unsafe { slice::from_raw_parts_mut(outvh.data, outvh_dim[0] * outvh_dim[1]) };
|
let out_vh_slice = slice::from_raw_parts_mut(outvh.data, outvh_dim[0] * outvh_dim[1]);
|
||||||
|
|
||||||
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
||||||
let result = matrix.svd(true, true);
|
let result = matrix.svd(true, true);
|
||||||
|
@ -180,8 +180,8 @@ pub unsafe extern "C" fn np_linalg_inv(mat1: *mut InputMatrix, out: *mut InputMa
|
||||||
}
|
}
|
||||||
|
|
||||||
let outdim = out.get_dims();
|
let outdim = out.get_dims();
|
||||||
let out_slice = unsafe { slice::from_raw_parts_mut(out.data, outdim[0] * outdim[1]) };
|
let out_slice = slice::from_raw_parts_mut(out.data, outdim[0] * outdim[1]);
|
||||||
let data_slice1 = unsafe { slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]) };
|
let data_slice1 = slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]);
|
||||||
|
|
||||||
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
||||||
if !matrix.is_invertible() {
|
if !matrix.is_invertible() {
|
||||||
|
@ -210,8 +210,8 @@ pub unsafe extern "C" fn np_linalg_pinv(mat1: *mut InputMatrix, out: *mut InputM
|
||||||
}
|
}
|
||||||
let dim1 = (*mat1).get_dims();
|
let dim1 = (*mat1).get_dims();
|
||||||
let outdim = out.get_dims();
|
let outdim = out.get_dims();
|
||||||
let out_slice = unsafe { slice::from_raw_parts_mut(out.data, outdim[0] * outdim[1]) };
|
let out_slice = slice::from_raw_parts_mut(out.data, outdim[0] * outdim[1]);
|
||||||
let data_slice1 = unsafe { slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]) };
|
let data_slice1 = slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]);
|
||||||
|
|
||||||
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
||||||
let svd = matrix.svd(true, true);
|
let svd = matrix.svd(true, true);
|
||||||
|
@ -247,11 +247,11 @@ pub unsafe extern "C" fn np_linalg_matrix_power(mat1: *mut InputMatrix, mat2: *m
|
||||||
}
|
}
|
||||||
|
|
||||||
let dim1 = (*mat1).get_dims();
|
let dim1 = (*mat1).get_dims();
|
||||||
let power = unsafe { slice::from_raw_parts_mut(mat2.data, 1) };
|
let power = slice::from_raw_parts_mut(mat2.data, 1);
|
||||||
let power = power[0];
|
let power = power[0];
|
||||||
let outdim = out.get_dims();
|
let outdim = out.get_dims();
|
||||||
let out_slice = unsafe { slice::from_raw_parts_mut(out.data, outdim[0] * outdim[1]) };
|
let out_slice = slice::from_raw_parts_mut(out.data, outdim[0] * outdim[1]);
|
||||||
let data_slice1 = unsafe { slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]) };
|
let data_slice1 = slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]);
|
||||||
let mut abs_power = power;
|
let mut abs_power = power;
|
||||||
if abs_power < 0.0 {
|
if abs_power < 0.0 {
|
||||||
abs_power = abs_power * -1.0;
|
abs_power = abs_power * -1.0;
|
||||||
|
@ -295,8 +295,8 @@ pub unsafe extern "C" fn np_linalg_det(mat1: *mut InputMatrix, out: *mut InputMa
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let dim1 = (*mat1).get_dims();
|
let dim1 = (*mat1).get_dims();
|
||||||
let out_slice = unsafe { slice::from_raw_parts_mut(out.data, 1) };
|
let out_slice = slice::from_raw_parts_mut(out.data, 1);
|
||||||
let data_slice1 = unsafe { slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]) };
|
let data_slice1 = slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]);
|
||||||
|
|
||||||
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
||||||
if !matrix.is_square() {
|
if !matrix.is_square() {
|
||||||
|
@ -334,9 +334,9 @@ pub unsafe extern "C" fn sp_linalg_lu(mat1: *mut InputMatrix, out_l: *mut InputM
|
||||||
let outl_dim = (*out_l).get_dims();
|
let outl_dim = (*out_l).get_dims();
|
||||||
let outu_dim = (*out_u).get_dims();
|
let outu_dim = (*out_u).get_dims();
|
||||||
|
|
||||||
let data_slice1 = unsafe { slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]) };
|
let data_slice1 = slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]);
|
||||||
let out_l_slice = unsafe { slice::from_raw_parts_mut(out_l.data, outl_dim[0] * outl_dim[1]) };
|
let out_l_slice = slice::from_raw_parts_mut(out_l.data, outl_dim[0] * outl_dim[1]);
|
||||||
let out_u_slice = unsafe { slice::from_raw_parts_mut(out_u.data, outu_dim[0] * outu_dim[1]) };
|
let out_u_slice = slice::from_raw_parts_mut(out_u.data, outu_dim[0] * outu_dim[1]);
|
||||||
|
|
||||||
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
||||||
let (_, l, u) = matrix.lu().unpack();
|
let (_, l, u) = matrix.lu().unpack();
|
||||||
|
@ -379,9 +379,9 @@ pub unsafe extern "C" fn sp_linalg_schur(mat1: *mut InputMatrix, out_t: *mut Inp
|
||||||
let out_t_dim = (*out_t).get_dims();
|
let out_t_dim = (*out_t).get_dims();
|
||||||
let out_z_dim = (*out_z).get_dims();
|
let out_z_dim = (*out_z).get_dims();
|
||||||
|
|
||||||
let data_slice1 = unsafe { slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]) };
|
let data_slice1 = slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]);
|
||||||
let out_t_slice = unsafe { slice::from_raw_parts_mut(out_t.data, out_t_dim[0] * out_t_dim[1]) };
|
let out_t_slice = slice::from_raw_parts_mut(out_t.data, out_t_dim[0] * out_t_dim[1]);
|
||||||
let out_z_slice = unsafe { slice::from_raw_parts_mut(out_z.data, out_z_dim[0] * out_z_dim[1]) };
|
let out_z_slice = slice::from_raw_parts_mut(out_z.data, out_z_dim[0] * out_z_dim[1]);
|
||||||
|
|
||||||
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
||||||
let (z, t) = matrix.schur().unpack();
|
let (z, t) = matrix.schur().unpack();
|
||||||
|
@ -428,9 +428,9 @@ pub unsafe extern "C" fn sp_linalg_hessenberg(
|
||||||
let out_h_dim = (*out_h).get_dims();
|
let out_h_dim = (*out_h).get_dims();
|
||||||
let out_q_dim = (*out_q).get_dims();
|
let out_q_dim = (*out_q).get_dims();
|
||||||
|
|
||||||
let data_slice1 = unsafe { slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]) };
|
let data_slice1 = slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]);
|
||||||
let out_h_slice = unsafe { slice::from_raw_parts_mut(out_h.data, out_h_dim[0] * out_h_dim[1]) };
|
let out_h_slice = slice::from_raw_parts_mut(out_h.data, out_h_dim[0] * out_h_dim[1]);
|
||||||
let out_q_slice = unsafe { slice::from_raw_parts_mut(out_q.data, out_q_dim[0] * out_q_dim[1]) };
|
let out_q_slice = slice::from_raw_parts_mut(out_q.data, out_q_dim[0] * out_q_dim[1]);
|
||||||
|
|
||||||
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
let matrix = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
|
||||||
let (q, h) = matrix.hessenberg().unpack();
|
let (q, h) = matrix.hessenberg().unpack();
|
||||||
|
|
Loading…
Reference in New Issue