From c574dfb7b16726e32db904a6d250ece661f8706e Mon Sep 17 00:00:00 2001 From: Jan-Kristian Mathisen Date: Sat, 4 Nov 2023 13:48:23 +0100 Subject: [PATCH] Casted pointers to work on different platforms --- lax/src/alloc.rs | 4 ++-- lax/src/cholesky.rs | 6 +++--- lax/src/eig.rs | 16 ++++++++-------- lax/src/eigh.rs | 16 ++++++++-------- lax/src/eigh_generalized.rs | 16 ++++++++-------- lax/src/opnorm.rs | 2 +- lax/src/rcond.rs | 4 ++-- lax/src/solve.rs | 6 +++--- lax/src/solveh.rs | 12 ++++++------ lax/src/svd.rs | 16 ++++++++-------- lax/src/svddc.rs | 8 ++++---- lax/src/triangular.rs | 6 +++--- lax/src/tridiagonal/rcond.rs | 6 +++--- lax/src/tridiagonal/solve.rs | 4 ++-- 14 files changed, 61 insertions(+), 61 deletions(-) diff --git a/lax/src/alloc.rs b/lax/src/alloc.rs index 63458818..b4ca3c4b 100644 --- a/lax/src/alloc.rs +++ b/lax/src/alloc.rs @@ -13,7 +13,7 @@ macro_rules! impl_as_ptr { impl AsPtr for $target { type Elem = $elem; fn as_ptr(vec: &[Self]) -> *const Self::Elem { - vec.as_ptr() as *const _ + vec.as_ptr().cast() as *const _ } fn as_mut_ptr(vec: &mut [Self]) -> *mut Self::Elem { vec.as_mut_ptr() as *mut _ @@ -55,7 +55,7 @@ impl VecAssumeInit for Vec> { } unsafe fn slice_assume_init_ref(&self) -> &[T] { - std::slice::from_raw_parts(self.as_ptr() as *const T, self.len()) + std::slice::from_raw_parts(self.as_ptr().cast() as *const T, self.len()) } unsafe fn slice_assume_init_mut(&mut self) -> &mut [T] { diff --git a/lax/src/cholesky.rs b/lax/src/cholesky.rs index 785f6e5e..ab947bfe 100644 --- a/lax/src/cholesky.rs +++ b/lax/src/cholesky.rs @@ -27,7 +27,7 @@ macro_rules! impl_cholesky_ { } let mut info = 0; unsafe { - $trf(uplo.as_ptr(), &n, AsPtr::as_mut_ptr(a), &n, &mut info); + $trf(uplo.as_ptr().cast(), &n, AsPtr::as_mut_ptr(a), &n, &mut info); } info.as_lapack_result()?; if matches!(l, MatrixLayout::C { .. }) { @@ -66,7 +66,7 @@ macro_rules! impl_inv_cholesky { } let mut info = 0; unsafe { - $tri(uplo.as_ptr(), &n, AsPtr::as_mut_ptr(a), &l.lda(), &mut info); + $tri(uplo.as_ptr().cast(), &n, AsPtr::as_mut_ptr(a), &l.lda(), &mut info); } info.as_lapack_result()?; if matches!(l, MatrixLayout::C { .. }) { @@ -115,7 +115,7 @@ macro_rules! impl_solve_cholesky { } unsafe { $trs( - uplo.as_ptr(), + uplo.as_ptr().cast(), &n, &nrhs, AsPtr::as_ptr(a), diff --git a/lax/src/eig.rs b/lax/src/eig.rs index 710beb9c..53f31ea4 100644 --- a/lax/src/eig.rs +++ b/lax/src/eig.rs @@ -156,8 +156,8 @@ macro_rules! impl_eig_work_c { let mut work_size = [<$c>::zero()]; unsafe { $ev( - jobvl.as_ptr(), - jobvr.as_ptr(), + jobvl.as_ptr().cast(), + jobvr.as_ptr().cast(), &n, std::ptr::null_mut(), &n, @@ -200,8 +200,8 @@ macro_rules! impl_eig_work_c { let mut info = 0; unsafe { $ev( - self.jobvl.as_ptr(), - self.jobvr.as_ptr(), + self.jobvl.as_ptr().cast(), + self.jobvr.as_ptr().cast(), &self.n, AsPtr::as_mut_ptr(a), &self.n, @@ -279,8 +279,8 @@ macro_rules! impl_eig_work_r { let mut work_size: [$f; 1] = [0.0]; unsafe { $ev( - jobvl.as_ptr(), - jobvr.as_ptr(), + jobvl.as_ptr().cast(), + jobvr.as_ptr().cast(), &n, std::ptr::null_mut(), &n, @@ -325,8 +325,8 @@ macro_rules! impl_eig_work_r { let mut info = 0; unsafe { $ev( - self.jobvl.as_ptr(), - self.jobvr.as_ptr(), + self.jobvl.as_ptr().cast(), + self.jobvr.as_ptr().cast(), &self.n, AsPtr::as_mut_ptr(a), &self.n, diff --git a/lax/src/eigh.rs b/lax/src/eigh.rs index bb3ca500..46023d5d 100644 --- a/lax/src/eigh.rs +++ b/lax/src/eigh.rs @@ -47,8 +47,8 @@ macro_rules! impl_eigh_work_c { let mut work_size = [Self::Elem::zero()]; unsafe { $ev( - jobz.as_ptr(), - UPLO::Upper.as_ptr(), // dummy, working memory is not affected by UPLO + jobz.as_ptr().cast(), + UPLO::Upper.as_ptr().cast(), // dummy, working memory is not affected by UPLO &n, std::ptr::null_mut(), &n, @@ -80,8 +80,8 @@ macro_rules! impl_eigh_work_c { let mut info = 0; unsafe { $ev( - self.jobz.as_ptr(), - uplo.as_ptr(), + self.jobz.as_ptr().cast(), + uplo.as_ptr().cast(), &self.n, AsPtr::as_mut_ptr(a), &self.n, @@ -128,8 +128,8 @@ macro_rules! impl_eigh_work_r { let mut work_size = [Self::Elem::zero()]; unsafe { $ev( - jobz.as_ptr(), - UPLO::Upper.as_ptr(), // dummy, working memory is not affected by UPLO + jobz.as_ptr().cast(), + UPLO::Upper.as_ptr().cast(), // dummy, working memory is not affected by UPLO &n, std::ptr::null_mut(), &n, @@ -160,8 +160,8 @@ macro_rules! impl_eigh_work_r { let mut info = 0; unsafe { $ev( - self.jobz.as_ptr(), - uplo.as_ptr(), + self.jobz.as_ptr().cast(), + uplo.as_ptr().cast(), &self.n, AsPtr::as_mut_ptr(a), &self.n, diff --git a/lax/src/eigh_generalized.rs b/lax/src/eigh_generalized.rs index 5d4d83ca..4a3902d0 100644 --- a/lax/src/eigh_generalized.rs +++ b/lax/src/eigh_generalized.rs @@ -58,8 +58,8 @@ macro_rules! impl_eigh_generalized_work_c { unsafe { $gv( &1, // ITYPE A*x = (lambda)*B*x - jobz.as_ptr(), - UPLO::Upper.as_ptr(), // dummy, working memory is not affected by UPLO + jobz.as_ptr().cast(), + UPLO::Upper.as_ptr().cast(), // dummy, working memory is not affected by UPLO &n, std::ptr::null_mut(), &n, @@ -95,8 +95,8 @@ macro_rules! impl_eigh_generalized_work_c { unsafe { $gv( &1, // ITYPE A*x = (lambda)*B*x - self.jobz.as_ptr(), - uplo.as_ptr(), + self.jobz.as_ptr().cast(), + uplo.as_ptr().cast(), &self.n, AsPtr::as_mut_ptr(a), &self.n, @@ -147,8 +147,8 @@ macro_rules! impl_eigh_generalized_work_r { unsafe { $gv( &1, // ITYPE A*x = (lambda)*B*x - jobz.as_ptr(), - UPLO::Upper.as_ptr(), // dummy, working memory is not affected by UPLO + jobz.as_ptr().cast(), + UPLO::Upper.as_ptr().cast(), // dummy, working memory is not affected by UPLO &n, std::ptr::null_mut(), &n, @@ -183,8 +183,8 @@ macro_rules! impl_eigh_generalized_work_r { unsafe { $gv( &1, // ITYPE A*x = (lambda)*B*x - self.jobz.as_ptr(), - uplo.as_ptr(), + self.jobz.as_ptr().cast(), + uplo.as_ptr().cast(), &self.n, AsPtr::as_mut_ptr(a), &self.n, diff --git a/lax/src/opnorm.rs b/lax/src/opnorm.rs index 1789f385..94b4b34d 100644 --- a/lax/src/opnorm.rs +++ b/lax/src/opnorm.rs @@ -40,7 +40,7 @@ macro_rules! impl_operator_norm { }; unsafe { $lange( - t.as_ptr(), + t.as_ptr().cast(), &m, &n, AsPtr::as_ptr(a), diff --git a/lax/src/rcond.rs b/lax/src/rcond.rs index 4d4a4c92..c7c16577 100644 --- a/lax/src/rcond.rs +++ b/lax/src/rcond.rs @@ -52,7 +52,7 @@ macro_rules! impl_rcond_work_c { }; unsafe { $con( - norm_type.as_ptr(), + norm_type.as_ptr().cast(), &n, AsPtr::as_ptr(a), &self.layout.lda(), @@ -103,7 +103,7 @@ macro_rules! impl_rcond_work_r { }; unsafe { $con( - norm_type.as_ptr(), + norm_type.as_ptr().cast(), &n, AsPtr::as_ptr(a), &self.layout.lda(), diff --git a/lax/src/solve.rs b/lax/src/solve.rs index 63f69983..617ea55c 100644 --- a/lax/src/solve.rs +++ b/lax/src/solve.rs @@ -119,12 +119,12 @@ macro_rules! impl_solve { } unsafe { $getrs( - t.as_ptr(), + t.as_ptr().cast(), &n, &nrhs, AsPtr::as_ptr(a), &l.lda(), - ipiv.as_ptr(), + ipiv.as_ptr().cast(), AsPtr::as_mut_ptr(b), &ldb, &mut info, @@ -205,7 +205,7 @@ macro_rules! impl_inv_work { &self.layout.len(), AsPtr::as_mut_ptr(a), &self.layout.lda(), - ipiv.as_ptr(), + ipiv.as_ptr().cast(), AsPtr::as_mut_ptr(&mut self.work), &lwork, &mut info, diff --git a/lax/src/solveh.rs b/lax/src/solveh.rs index abb75cb8..de25df7c 100644 --- a/lax/src/solveh.rs +++ b/lax/src/solveh.rs @@ -41,7 +41,7 @@ macro_rules! impl_bk_work { let mut work_size = [Self::Elem::zero()]; unsafe { $trf( - UPLO::Upper.as_ptr(), + UPLO::Upper.as_ptr().cast(), &n, std::ptr::null_mut(), &layout.lda(), @@ -66,7 +66,7 @@ macro_rules! impl_bk_work { let mut info = 0; unsafe { $trf( - uplo.as_ptr(), + uplo.as_ptr().cast(), &n, AsPtr::as_mut_ptr(a), &self.layout.lda(), @@ -128,11 +128,11 @@ macro_rules! impl_invh_work { let mut info = 0; unsafe { $tri( - uplo.as_ptr(), + uplo.as_ptr().cast(), &n, AsPtr::as_mut_ptr(a), &self.layout.lda(), - ipiv.as_ptr(), + ipiv.as_ptr().cast(), AsPtr::as_mut_ptr(&mut self.work), &mut info, ) @@ -175,12 +175,12 @@ macro_rules! impl_solveh_ { let mut info = 0; unsafe { $trs( - uplo.as_ptr(), + uplo.as_ptr().cast(), &n, &1, AsPtr::as_ptr(a), &l.lda(), - ipiv.as_ptr(), + ipiv.as_ptr().cast(), AsPtr::as_mut_ptr(b), &n, &mut info, diff --git a/lax/src/svd.rs b/lax/src/svd.rs index fc695108..872a3513 100644 --- a/lax/src/svd.rs +++ b/lax/src/svd.rs @@ -82,8 +82,8 @@ macro_rules! impl_svd_work_c { let mut work_size = [Self::Elem::zero()]; unsafe { $svd( - ju.as_ptr(), - jvt.as_ptr(), + ju.as_ptr().cast(), + jvt.as_ptr().cast(), &m, &n, std::ptr::null_mut(), @@ -122,8 +122,8 @@ macro_rules! impl_svd_work_c { let mut info = 0; unsafe { $svd( - self.ju.as_ptr(), - self.jvt.as_ptr(), + self.ju.as_ptr().cast(), + self.jvt.as_ptr().cast(), &m, &n, AsPtr::as_mut_ptr(a), @@ -217,8 +217,8 @@ macro_rules! impl_svd_work_r { let mut work_size = [Self::Elem::zero()]; unsafe { $svd( - ju.as_ptr(), - jvt.as_ptr(), + ju.as_ptr().cast(), + jvt.as_ptr().cast(), &m, &n, std::ptr::null_mut(), @@ -256,8 +256,8 @@ macro_rules! impl_svd_work_r { let mut info = 0; unsafe { $svd( - self.ju.as_ptr(), - self.jvt.as_ptr(), + self.ju.as_ptr().cast(), + self.jvt.as_ptr().cast(), &m, &n, AsPtr::as_mut_ptr(a), diff --git a/lax/src/svddc.rs b/lax/src/svddc.rs index c16db4bb..a96aa851 100644 --- a/lax/src/svddc.rs +++ b/lax/src/svddc.rs @@ -70,7 +70,7 @@ macro_rules! impl_svd_dc_work_c { let mut work_size = [Self::Elem::zero()]; unsafe { $sdd( - jobz.as_ptr(), + jobz.as_ptr().cast(), &m, &n, std::ptr::null_mut(), @@ -115,7 +115,7 @@ macro_rules! impl_svd_dc_work_c { let mut info = 0; unsafe { $sdd( - self.jobz.as_ptr(), + self.jobz.as_ptr().cast(), &m, &n, AsPtr::as_mut_ptr(a), @@ -205,7 +205,7 @@ macro_rules! impl_svd_dc_work_r { let mut work_size = [Self::Elem::zero()]; unsafe { $sdd( - jobz.as_ptr(), + jobz.as_ptr().cast(), &m, &n, std::ptr::null_mut(), @@ -249,7 +249,7 @@ macro_rules! impl_svd_dc_work_r { let mut info = 0; unsafe { $sdd( - self.jobz.as_ptr(), + self.jobz.as_ptr().cast(), &m, &n, AsPtr::as_mut_ptr(a), diff --git a/lax/src/triangular.rs b/lax/src/triangular.rs index da4dc4cf..078ce1ac 100644 --- a/lax/src/triangular.rs +++ b/lax/src/triangular.rs @@ -63,9 +63,9 @@ macro_rules! impl_triangular { let mut info = 0; unsafe { $trtrs( - uplo.as_ptr(), - Transpose::No.as_ptr(), - diag.as_ptr(), + uplo.as_ptr().cast(), + Transpose::No.as_ptr().cast(), + diag.as_ptr().cast(), &m, &nrhs, AsPtr::as_ptr(a_t.as_ref().map(|v| v.as_slice()).unwrap_or(a)), diff --git a/lax/src/tridiagonal/rcond.rs b/lax/src/tridiagonal/rcond.rs index a309cae4..fd8481ae 100644 --- a/lax/src/tridiagonal/rcond.rs +++ b/lax/src/tridiagonal/rcond.rs @@ -37,13 +37,13 @@ macro_rules! impl_rcond_tridiagonal_work_c { let mut info = 0; unsafe { $gtcon( - NormType::One.as_ptr(), + NormType::One.as_ptr().cast(), &n, AsPtr::as_ptr(&lu.a.dl), AsPtr::as_ptr(&lu.a.d), AsPtr::as_ptr(&lu.a.du), AsPtr::as_ptr(&lu.du2), - ipiv.as_ptr(), + ipiv.as_ptr().cast(), &lu.a_opnorm_one, &mut rcond, AsPtr::as_mut_ptr(&mut self.work), @@ -84,7 +84,7 @@ macro_rules! impl_rcond_tridiagonal_work_r { let mut info = 0; unsafe { $gtcon( - NormType::One.as_ptr(), + NormType::One.as_ptr().cast(), &n, AsPtr::as_ptr(&lu.a.dl), AsPtr::as_ptr(&lu.a.d), diff --git a/lax/src/tridiagonal/solve.rs b/lax/src/tridiagonal/solve.rs index 43f7d120..15774b06 100644 --- a/lax/src/tridiagonal/solve.rs +++ b/lax/src/tridiagonal/solve.rs @@ -35,14 +35,14 @@ macro_rules! impl_solve_tridiagonal { let mut info = 0; unsafe { $trs( - t.as_ptr(), + t.as_ptr().cast(), &n, &nrhs, AsPtr::as_ptr(&lu.a.dl), AsPtr::as_ptr(&lu.a.d), AsPtr::as_ptr(&lu.a.du), AsPtr::as_ptr(&lu.du2), - ipiv.as_ptr(), + ipiv.as_ptr().cast(), AsPtr::as_mut_ptr(b_t.as_mut().map(|v| v.as_mut_slice()).unwrap_or(b)), &ldb, &mut info,