just sharing/archiving.
fortran wrapper:
! lapdog.f90
! f95 -shared -o lapdog.so types.o constants.o utils.o lapack.o linalg.o lapdog.o -llapack
module lapdog
use linalg, only: solve ! https://github.com/certik/fortran-utils
use iso_c_binding, only: c_int, c_double
implicit none
contains
subroutine solver(n,a,b,x) bind(c)
integer(c_int), intent(in) :: n
real(c_double), intent(in) :: a(n,n)
real(c_double), intent(in) :: b(n)
real(c_double), intent(out) :: x(n)
x = solve(a,b)
end subroutine solver
end module lapdog
nim test program:
# test.nim
# nim c test.nim
const
N = 3
type
m1 = array[1..N, float64]
m2 = array[1..N, m1]
proc solver(n: ptr int; a: m2; b: m1; x: var m1)
{. dynlib: "./lapdog.so", importc .}
when isMainModule:
# solve for x, y, z where:
# 1) 1x + 1y − 1z = 4
# 2) 1x − 2y + 3z = −6
# 3) 2x + 3y + 1z = 7
var
n: int = N
A: m2
B: m1
X: m1
A[1][1] = 1
A[1][2] = 1
A[1][3] = 2
A[2][1] = 1
A[2][2] = -2
A[2][3] = 3
A[3][1] = -1
A[3][2] = 3
A[3][3] = 1
B[1] = 4
B[2] = -6
B[3] = 7
solver(n.addr(),A,B,X)
for i in 1..N:
echo X[i]
For anyone interested, there is some solver functionality via lapack in linalg.
@smitty Would you be interested in contributing? :-)
@smitty Well, at first I suggest that you try what is working in linalg and let me know what you don't like or what is not clear in the documentation (I know, they should be expanded and there should be a tutorial as well). :-)
From there, there are a lot of things to do. A few of them are documented in the TODO, but here are some others:
Then one could build other things on top of linalg, probably in other packages - for instance
and so on.
Also, another thing may be to work out some statically typed analogue of dataframes, to have something like Pandas in the Nim world
I will soon be on holidays until about mid September, but I'd be happy to give any help about the internals of the library