Skip to content

Commit 952eed3

Browse files
committed
Add dtrtrs_
1 parent 2e43ed0 commit 952eed3

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

Sources/AccelerateLinux/MatrixOps/LAPACK.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,22 @@ public func dpotrf_(
137137
_ __lda: UnsafeMutablePointer<__CLPK_integer>!,
138138
_ __info: UnsafeMutablePointer<__CLPK_integer>!
139139
) -> Int32
140+
141+
/// Solves a triangular system of the form
142+
/// `A * X = B` or `A**T * X = B`,
143+
/// where A is a triangular matrix of order N, and B is an N-by-NRHS matrix.
144+
/// A check is made to verify that A is nonsingular.
145+
@_silgen_name("dtrtrs_")
146+
public func dtrtrs_(
147+
_ __uplo: UnsafeMutablePointer<CChar>!,
148+
_ __trans: UnsafeMutablePointer<CChar>!,
149+
_ __diag: UnsafeMutablePointer<CChar>!,
150+
_ __n: UnsafeMutablePointer<__CLPK_integer>!,
151+
_ __nrhs: UnsafeMutablePointer<__CLPK_integer>!,
152+
_ __a: UnsafeMutablePointer<__CLPK_doublereal>!,
153+
_ __lda: UnsafeMutablePointer<__CLPK_integer>!,
154+
_ __b: UnsafeMutablePointer<__CLPK_doublereal>!,
155+
_ __ldb: UnsafeMutablePointer<__CLPK_integer>!,
156+
_ __info: UnsafeMutablePointer<__CLPK_integer>!
157+
) -> Int32
140158
#endif // canImport(Accelerate)

Tests/AccelerateLinuxTests/MatrixTests/LAPACKTests.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,51 @@ struct LAPACKTests {
294294
0.00, 0.00, 0.00, 0.53,
295295
]
296296
)
297+
}
298+
299+
// https://numericalalgorithmsgroup.github.io/LAPACK_Examples/examples/doc/dtrtrs_example.html
300+
@Test("dtrtrs_")
301+
func test_dtrtrs_() {
302+
let N = 4
303+
let NRHS = 2
304+
let LDA = N
297305

306+
var n = __CLPK_integer(N)
307+
var nrhs = __CLPK_integer(NRHS)
308+
var lda = __CLPK_integer(LDA)
309+
var ldb = __CLPK_integer(N)
310+
var info = __CLPK_integer(0)
311+
312+
var a: [__CLPK_doublereal] = [
313+
4.30, -3.96, 0.40, -0.27,
314+
0.00, -4.87, 0.31, 0.07,
315+
0.00, 0.00, -8.02, -5.95,
316+
0.00, 0.00, 0.00, 0.12,
317+
]
318+
319+
var b: [__CLPK_doublereal] = [
320+
-12.90, 16.75, -17.55, -11.04,
321+
-21.50, 14.93, 6.33, 8.09,
322+
]
323+
324+
"L".withCString { uploPtr in
325+
"N".withCString { transPtr in
326+
"N".withCString { diagPtr in
327+
let mutableUploPtr = UnsafeMutablePointer(mutating: uploPtr)
328+
let mutableTransPtr = UnsafeMutablePointer(mutating: transPtr)
329+
let mutableDiagPtr = UnsafeMutablePointer(mutating: diagPtr)
330+
_ = dtrtrs_(mutableUploPtr, mutableTransPtr, mutableDiagPtr, &n, &nrhs, &a, &lda, &b, &ldb, &info)
331+
}
332+
}
333+
}
334+
335+
#expect(
336+
b.map {
337+
($0 * pow(10, 2)).rounded() / pow(10, 2)
338+
} == [
339+
-3.00, -1.00, 2.00, 1.00,
340+
-5.00, 1.00, -1.00, 6.00,
341+
]
342+
)
298343
}
299344
}

0 commit comments

Comments
 (0)