@@ -1128,8 +1128,34 @@ internal typealias lapack_LU<T> = (UnsafeMutablePointer<__CLPK_integer>, UnsafeM
11281128
11291129internal typealias lapack_inv < T> = ( UnsafeMutablePointer < __CLPK_integer > , UnsafeMutablePointer < T > , UnsafeMutablePointer < __CLPK_integer > , UnsafeMutablePointer < __CLPK_integer > , UnsafeMutablePointer < T > , UnsafeMutablePointer < __CLPK_integer > , UnsafeMutablePointer < __CLPK_integer > ) -> Int32
11301130
1131+ // MARK: - Direct CLAPACK bindings
1132+ // The CLAPACK header declares these functions as returning int, but the actual
1133+ // compiled WASM functions return void (Fortran subroutines). We need to declare
1134+ // them with the correct signature to avoid WASM signature mismatch errors.
1135+ // Parameters use CLong (long int) which is 32-bit on wasm32.
1136+
1137+ @_silgen_name ( " dgetrf_ " )
1138+ private func clapack_dgetrf(
1139+ _ m: UnsafeMutablePointer < CLong > ,
1140+ _ n: UnsafeMutablePointer < CLong > ,
1141+ _ a: UnsafeMutablePointer < Double > ,
1142+ _ lda: UnsafeMutablePointer < CLong > ,
1143+ _ ipiv: UnsafeMutablePointer < CLong > ,
1144+ _ info: UnsafeMutablePointer < CLong >
1145+ )
1146+
1147+ @_silgen_name( " dgetri_" )
1148+ private func clapack_dgetri(
1149+ _ n: UnsafeMutablePointer < CLong > ,
1150+ _ a: UnsafeMutablePointer < Double > ,
1151+ _ lda: UnsafeMutablePointer < CLong > ,
1152+ _ ipiv: UnsafeMutablePointer < CLong > ,
1153+ _ work: UnsafeMutablePointer < Double > ,
1154+ _ lwork: UnsafeMutablePointer < CLong > ,
1155+ _ info: UnsafeMutablePointer < CLong >
1156+ )
1157+
11311158// MARK: - CLAPACK Wrapper Functions for WASI
1132- // dgetrf_ and dgetri_ are called directly from the CLAPACK C module
11331159// dgeev_ is implemented in pure Swift (swiftEigenDecomposition) above
11341160// Note: CLAPACK uses "integer" = long int, which on wasm32 is 32-bit (CLong)
11351161
@@ -1160,8 +1186,8 @@ internal func dgetrf_(_ m: UnsafeMutablePointer<__CLPK_integer>, _ n: UnsafeMuta
11601186 let minMN = min ( Int ( m. pointee) , Int ( n. pointee) )
11611187 var ipivLong = Array < CLong > ( repeating: 0 , count: minMN)
11621188
1163- // Call CLAPACK's dgetrf_ directly through C interop
1164- let _ = CLAPACK . dgetrf_ ( & mLong, & nLong, a, & ldaLong, & ipivLong, & infoLong)
1189+ // Call our direct binding with correct void-returning signature
1190+ clapack_dgetrf ( & mLong, & nLong, a, & ldaLong, & ipivLong, & infoLong)
11651191
11661192 for i in 0 ..< minMN {
11671193 ipiv [ i] = __CLPK_integer ( ipivLong [ i] )
@@ -1190,8 +1216,8 @@ internal func dgetri_(_ n: UnsafeMutablePointer<__CLPK_integer>, _ a: UnsafeMuta
11901216 ipivLong [ i] = CLong ( ipiv [ i] )
11911217 }
11921218
1193- // Call CLAPACK's dgetri_ directly through C interop
1194- let _ = CLAPACK . dgetri_ ( & nLong, a, & ldaLong, & ipivLong, work, & lworkLong, & infoLong)
1219+ // Call our direct binding with correct void-returning signature
1220+ clapack_dgetri ( & nLong, a, & ldaLong, & ipivLong, work, & lworkLong, & infoLong)
11951221
11961222 info. pointee = __CLPK_integer ( infoLong)
11971223 return Int32 ( infoLong)
0 commit comments