kaleidicassociates / lubeck Goto Github PK
View Code? Open in Web Editor NEWHigh level linear algebra library for Dlang
Home Page: http://lubeck.libmir.org/
License: Boost Software License 1.0
High level linear algebra library for Dlang
Home Page: http://lubeck.libmir.org/
License: Boost Software License 1.0
svd
pinv
- Moore-Penrose pseudoinverse of matrix.inv
)mir.ndslice.concatenation
reversed!0
/reversed!1
A[p].fuse
, where p
is 1D ndslice that is permutation, allocates new matrix with permuted raws.qrDecomp
and solve
methodcholeskyDecomp
and solve
methodluDecomp
and solve
methodldlDecomp
and solve
methodI installed some packages at last:
sudo apt install libopenblas-dev
But now I am getting this error:
when running dub -v
....
Search for versions of lapack77 (1 package suppliers)
No versions for lapack77 for registry at https://code.dlang.org/ (fallback ["registry at http://code.dlang.org/", "registry at https://code-mirror.dlang.io/", "registry at https://code-mirror2.dlang.io/", "registry at https://dub-registry.herokuapp.com/"])
Nothing found for lapack77
Search for versions of mir-blas (1 package suppliers)
Return for mir-blas: [0.1.0, 0.0.4, 0.0.2, 0.0.1, ~master]
Search for versions of cblas (1 package suppliers)
Return for cblas: [2.0.1, 2.0.0, 1.0.0, 0.2.0, 0.1.0, 0.0.4, 0.0.3, 0.0.2, 0.0.1, 0.0.0, ~master, ~remove-unittest, ~link-1, ~link, ~John-Colvin-patch-1]
Package mir-lapack contains invalid dependency lapack77 (no version candidates) (ci=10)
What ca I do? (Ubuntu 17.10. 64 Bit)
https://buildkite.com/dlang/dmd/builds/3946#3311f4b4-ae52-4df5-8388-6315ccc1db18
Unresolvable dependencies to package mir-algorithm:
| mir-blas 1.1.4 depends on mir-algorithm >=2.0.0-beta2 <4.0.0
| mir-random 2.2.0 depends on mir-algorithm ~>3.2.1
| mir-random 2.2.0 depends on mir-algorithm ~>3.2.1 (optional)
| Unresolvable dependencies to package mir-algorithm:
| mir-blas 1.1.4 depends on mir-algorithm >=2.0.0-beta2 <4.0.0
| mir-random 2.2.0 depends on mir-algorithm ~>3.2.1
| mir-random 2.2.0 depends on mir-algorithm ~>3.2.1 (optional)
Just a dependency problem, but as this seems to happen quite frequently it would be great if we could either change the Buildkite code to use the same testing as here or add the same testing here.
I am trying to use lubeck to calculate the eigenvalues of a symmetric matrix.
My code is as follows:
import std.stdio;
import mir.ndslice;
import lubeck;
void main()
{
// Test eigSymmetric
auto n = 4;
auto A = slice!double(n, n);
A[] = [[ 0.239960151286054, 0, 0.178712872351482, 0],
[ -0.372217567033019, 1.000000000000000, 0.270264106474929, 0],
[ -0.990087548834596, 0, 0.138859726355787, 0],
[-48.935406546734953, 64.100000000000009, 2.399234111713982, 1.0]];
auto ATA = slice!double(n, n);
ATA = A.transposed.mtimes(A);
auto eigs = ATA.eigSymmetric;
}
In my dub.json file I have the following:
"dependencies": {
"mir" : ">=3.1.0",
"lubeck": ">=1.1.0"
},
When I try to build to code using ldc-1.9 I get the following error:
Error: template lubeck.eigSymmetric cannot deduce function from argument types !()(Slice!(double*, 2LU, cast(mir_slice_kind)2)),
Could this be a bug?
Thanks,
Max
Using eigSymmetric
fails to compile.
/+dub.sdl:
dependency "mir-algorithm" version="~>3.9.2"
dependency "mir-random" version="~>2.2.14"
dependency "lubeck" version="~>1.3.0"
+/
import mir.ndslice;
import mir.random.variable : uniformVar;
import mir.random.algorithm : randomSlice;
import kaleidic.lubeck : eigSymmetric;
void main() {
auto s = uniformVar!int(-2, 2).randomSlice(10, 10);
s.eachUploPair!((upper, ref lower) { lower = upper; });
auto r = eigSymmetric('L', s);
}
attempting to run dub temp.d
blasint = int
.dub/packages/lubeck-1.3.0/lubeck/source/kaleidic/lubeck.d(1084,12): Error: module mir.math.numeric import Prod not found, did you mean template mir.math.numeric.prod(F, Range)(Range r) if (isFloatingPoint!F && isIterable!Range)?
temp.d(15,23): Error: template instance kaleidic.lubeck.eigSymmetric!(cast(Flag)true, int*, cast(mir_slice_kind)2) error instantiating
/usr/bin/dmd failed with exit code 1.
There was a question on the forum about how to install this on Windows. I tried to provide some help from my experiences, but it could probably be fleshed out in more detail and put in the wiki or something.
This breaks the BuildKite builds for all dlang repos. An example failure:
https://buildkite.com/dlang/phobos/builds/878#321a0649-a44d-463b-b358-ee3917549508
Unresolvable dependencies to package mir-core:
--
| mir-algorithm 3.1.21 depends on mir-core >=0.0.10 <1.0.0
| mir-random 2.1.5 depends on mir-core ~>0.0.6
| Unresolvable dependencies to package mir-core:
| mir-algorithm 3.1.21 depends on mir-core >=0.0.10 <1.0.0
| mir-random 2.1.5 depends on mir-core ~>0.0.6
The dub-sdl for lubeck has:
configuration "lapack" {
subConfiguration "mir-lapack" "lapack"
}
but the dub.sdl for mir-lapack does not have a lapack configuration
https://github.com/libmir/mir-lapack/blob/master/dub.sdl
The errors in this case are not so informative.
I think QRResult needs a helper function(s) that produces Q and R from matrix and tau.
I am comparing the result of one of the unittests to how I would do it in R and it doesn't match up. Compare https://run.dlang.io/is/fcMfi9 with below (in R). The lubeck version has a zero in the top left corner for matrix, but I thought it was upper trapezoidal...I know that given R, we can calculate Q as a*inv(R), but I'm not sure I would get the correct R given's lubeck's output.
> A <- matrix(c(1, 1, 0, 1, 0, 1, 0, 1, 1), 3, 3)
> X <- qr(A)
> X
$qr
[,1] [,2] [,3]
[1,] -1.4142136 -0.7071068 -0.7071068
[2,] 0.7071068 1.2247449 0.4082483
[3,] 0.0000000 -0.8164966 1.1547005
$rank
[1] 3
$qraux
[1] 1.707107 1.577350 1.154701
$pivot
[1] 1 2 3
attr(,"class")
[1] "qr"
> qr.Q(X)
[,1] [,2] [,3]
[1,] -0.7071068 0.4082483 -0.5773503
[2,] -0.7071068 -0.4082483 0.5773503
[3,] 0.0000000 0.8164966 0.5773503
> qr.R(X)
[,1] [,2] [,3]
[1,] -1.414214 -0.7071068 -0.7071068
[2,] 0.000000 1.2247449 0.4082483
[3,] 0.000000 0.0000000 1.1547005
>
Can I make BlasType public? That operation can be useful when writing a module outside of lubeck that depends on calling lubeck functions.
I met the following errors in this special case. I think using ger inside mtimes is the best.
unittest
{
import std.stdio;
auto a = [1.0, 2.0].sliced(2, 1);
auto b = [1.0, 2.0].sliced(2, 1);
auto bt = b.transposed;
// without slice
// (linked with cblas) ** On entry to cblas_dgemm parameter number 11 had an illegal value
// (linked with mkl_rt) Intel MKL ERROR: Parameter 11 was incorrect on entry to cblas_dgemm.
writeln(mtimes(a, bt)); // [[6.911e-310, 9.85365e-317], [0, 0]]
// but OK with slice
assert(mtimes(a, bt.slice) == [[1, 2], [2, 4]]);
// also I think mir.blas.ger is nice when a.length!1 == 1 && b.length!0 == 1
import mir.blas : ger;
auto c = uninitSlice!double(a.length!0, bt.length!1);
c[] = 0;
ger(1.0, a[0..$,0], b[0..$,0], c);
assert(c == [[1, 2], [2, 4]]);
}
I think this is related to the LDB
(the 11th arg) specification http://www.netlib.org/lapack/explore-html/d1/d54/group__double__blas__level3_gaeda3cbd99c8fb834a60a6412878226e1.html#gaeda3cbd99c8fb834a60a6412878226e1
On entry, LDB specifies the first dimension of B as declared
in the calling (sub) program. When TRANSB = 'N' or 'n' then
LDB must be at least max( 1, k ), otherwise LDB must be at
least max( 1, n ).
where B.shape == [k, n]
P.S.
The following transposed B (1 < k < n) seems to be OK. I think only k=1
has the problem.
unittest
{
auto a = [1.0, 2.0,
3.0, 4.0,
5.0, 6.0].sliced(3, 2);
auto b = [1.0, 2.0,
3.0, 4.0,
5.0, 6.0].sliced(3, 2);
auto bt = b.transposed;
auto result = [[5, 11, 17], [11, 25, 39], [17, 39, 61]];
// OK
assert(mtimes(a, bt) == result);
}
Tried building a test package with lubeck and mir-algorithm specifically trying to call inv function. Get the following error:
.dub/packages/mir-lapack-0.0.3/mir-lapack/source/mir/lapack.d:53: undefined reference to `dgetri_'
In the dub.json I include:
"dependencies": {"lubeck": ">0.0.3", "mir-algorithm": ">0.6.6"}
I think this could easily be a dmd problem, but I can't work it out right now.
pinv([1.0, 2, 3, 4].sliced(2, 2), 0.1)
Error: template lubeck.pinv cannot deduce function from argument types !()(Slice!(double*, 2LU, cast(mir_slice_kind)2), double), candidates are:
/home/john/.dub/packages/lubeck-1.1.8/lubeck/source/lubeck.d(754,5): pinv(Flag allowDestroy = No.allowDestroy, Iterator, mir_slice_kind kind)(Slice!(Iterator, 2, kind) matrix, BlasType!Iterator tolerance = BlasType!Iterator.nan)
workaround is to manually instantiate the template e.g.
pinv!(No.allowDestroy, double*, SliceKind.contiguous)([1.0, 2, 3, 4].sliced(2, 2), 0.1)
The following code outputs the runtime warning
** On entry to SGEMM parameter number 8 had an illegal value
and also produced a wrong/invalid result:
import std.stdio;
import mir.ndslice.slice;
import mir.ndslice.allocation;
import lubeck;
void main()
{
Slice!(cast(SliceKind)2, [2LU], float*) a = slice!float(1, 1);
Slice!(cast(SliceKind)0, [2LU], float*) b1 = slice!float(16, 1).transposed;
Slice!(cast(SliceKind)2, [2LU], float*) b2 = slice!float(1, 16);
a[] = 3;
b1[] = 4;
b2[] = 4;
writefln("a: %s\nb1: %s\nb2: %s", a, b1, b2);
// Outputs: ** On entry to SGEMM parameter number 8 had an illegal value
// And gives invalid result
writefln("a x b1 = %s", a.mtimes(b1));
// Works
writefln("a x b2 = %s", a.mtimes(b2));
}
dub file:
{
"name": "mtimes_bug",
"authors": [
"Marenz"
],
"dependencies": {
"lubeck": "~>0.0.4"
},
"license": "GPLv3",
"libs": [ "lapack", "blas", "cblas"]
}
Is there a link to the docs anywhere?
Thanks
The following tests are failing currently:
Additionally, I think it would be better if examples included import kaleidic.lubeck;
since the newcomers will be confused by having import mir.ndslice;
but things not working.
Documentation contains redundant backward slashes here and there: \min ||A * X - B|| Using the QR factorization: \A = Q * R
/home/john/.dub/packages/lubeck-1.3.1/lubeck/source/kaleidic/lubeck.d(1097,31): Error: template mir.ndslice.slice.sliced cannot deduce function from argument types !()(double[1], int, int), candidates are:
/home/john/.dub/packages/mir-algorithm-3.9.13/mir-algorithm/source/mir/ndslice/slice.d(245,6): sliced(ulong N, Iterator)(Iterator iterator, size_t[N] lengths...)
with N = 2LU,
Iterator = double[1]
must satisfy the following constraint:
!isStaticArray!Iterator
/home/john/.dub/packages/mir-algorithm-3.9.13/mir-algorithm/source/mir/ndslice/slice.d(312,12): sliced(T)(T[] array)
/home/john/.dub/packages/mir-algorithm-3.9.13/mir-algorithm/source/mir/ndslice/slice.d(335,5): sliced(Iterator, ulong N, mir_slice_kind kind)(Slice!(Iterator, 1, kind) slice, size_t[N] lengths...)
Error: template instance kaleidic.lubeck.eigSymmetric!(cast(Flag)false, double*, cast(mir_slice_kind)2) error instantiating
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.