I'm using the dgeev
algorithm from the LAPACK implementation in the Accelerate framework to calculate eigenvectors and eigenvalues of a matrix. Sadly the LAPACK functions are not described in the Apple Documentation with a mere link to http://netlib.org/lapack/faq.html included.
If you look it up, you will find that the first two arguments in dgeev
are characters signifying whether to calculate eigenvectors or not. In Swift, it is asking for UnsafeMutablePointer<Int8>
. When I simply use "N"
, I get an error. The dgeev
function and the error are described in the following screenshot
What should I do to solve this?
The "problem" is that the first two parameters are declared as
char *
and not asconst char *
, even if the strings are not modified by the function:is mapped to Swift as
A possible workaround is
Inside the block,
$0
is a pointer to a NUL-terminated array ofchar
with the UTF-8 representation of the string.Remark:
dgeev_()
does not modify the strings pointed to by the first two arguments, so it "should be" declared aswhich would be mapped to Swift as
and in that case you could simply call it as
because Swift strings are converted to
UnsafePointer<Int8>)
automatically, as explained in String value to UnsafePointer<UInt8> function parameter behavior.It is ugly, but you can use:
and use
unsafeMutablePointerOfN
as a parameter instead of "N".