I am compiling and trying to run the UMfPackLU<SparseMatrix<>> routine from Eigen 3.2.9 and UMFPACK v4.5 libraries with TDM-GCC 5.1.0 on Win64 platform. But I am getting Appcrash with exception code c0000005.
What I need to implement is the following:
_ _ _ _
A = | P |, B = | R |, where P and Q are sparse and Z is 0 with 3 cols
| Q | | Z |
|_ _| |_ _|
X = A\B;
What I am doing (excerpt only) is the following:
#define num_t double
...
SparseMatrix<num_t,RowMajor> A(P.rows()+Q.rows(), P.cols());
A.topRows(P.rows()) = P;
A.bottomRows(Q.rows()) = Q;
Matrix<num_t, Dynamic, 3> B(P.rows()+Q.rows(), 3);
B.topLeftCorner(P.rows(), 3) = R;
B.bottomLeftCorner(Q.rows(), 3) = S;
UmfPackLU<SparseMatrix<num_t>> solver(A.transpose()*A);
auto AtB = A.transpose()*B;
X.col(0) = solver.solve(AtB.col(0)); // ### segmentation error here ###
X.col(1) = solver.solve(AtB.col(1));
X.col(2) = solver.solve(AtB.col(2));
Note the SparseMatrix<> is in RowMajor format.
On debugging with gdb: I get Program received signal SIGSEGV, Segmentation fault. at the line marked as above`.
Instead of UmfPackLU<SparseMatrix<>>, solving with SimplicialLLT<SparseMatrix<>>, SimplicialLDLT<SparseMatrix<>> or CholmodDecomposition<SparseMatrix<>> is working correctly.
Thanks in advance for any help.
This is a shortcoming in Eigen 3.2.9 that has been fixed a while ago in the 3.3 branch. It's now fixed in the 3.2 branch too (changeset 1e7d97fea51d).
You can workaround the issue by calling compute(...) instead of the constructor:
UmfPackLU<SparseMatrix<num_t>> solver;
solver.compute(A.transpose()*A);
Please feel free to correct/enhance/establish my answer.
What I have found is that, I need to instantiate an explicit ColMajor matrix AtA before feeding it to the solver (RowMajor is not working) as follows:
SparseMatrix<num_t, ColMajor> AtA = A.transpose()*A;
UmfPackLU<SparseMatrix<num_t>> solver(AtA);
Is this a requirement due to Eigen's lazy evaluation implementation for calling an external routine?
Related
I have a snippet of python code as a function here. The purpose of the code is to use the combinations tool of itertools and turn a list of pairs into a list of triplets by matching items that correlate with each other. Due to the time consuming nature of the function, I have been trying to get it to work using a GPU through numba. Here is the function followed by me calling it:
#jit(target_backend='cuda')
def combinator(size, theuniquegenes, thetuplelist):
limiter = size+1
lengths = [l + 1 for l in range(len(theuniquegenes)) if (l + 1 > 2) and (l + 1 < limiter)]
new_combs = {c for l in lengths for c in combinations(theuniquegenes, l)}
correlations = {x for x in new_combs if all([c in thetuplelist for c in combinations(x, 2)])}
print(len(correlations))
tuplelist = thetuplelist + list(correlations)
print(len(tuplelist))
return tuplelist
tuplelist = combinator(3, uniquegenes, tuplelist)
Unfortunately, I keep encountering the following error message:
numba.core.errors.UnsupportedError: Failed in object mode pipeline (step: inline calls to locally defined closures)
Use of unsupported opcode (SET_ADD) found
new_combs = {c for l in lengths for c in combinations(theuniquegenes, l)}
^
How can I rewrite this line to work?
I'm inconsistently getting this error in a first experiment with OCaml 5.0.0~beta1:
Fatal error: exception Stdlib.Effect.Unhandled(Domainslib__Task.Wait(_, _))
My setup:
Processor: Intel(R) Core(TM) i7-8750H CPU # 2.20GHz
Debian 10 (buster)
opam version 2.1.3 installed as binary from this script
opam switch: "→ 5.0.0~beta1 ocaml-base-compiler.5.0.0~beta1 5.0.0~beta1"
After a quick read of this tutorial, I copied the parallel_matrix_multiply function and added some code in the end just to use it:
open Domainslib
let parallel_matrix_multiply pool a b =
let i_n = Array.length a in
let j_n = Array.length b.(0) in
let k_n = Array.length b in
let res = Array.make_matrix i_n j_n 0 in
Task.parallel_for pool ~start:0 ~finish:(i_n - 1) ~body:(fun i ->
for j = 0 to j_n - 1 do
for k = 0 to k_n - 1 do
res.(i).(j) <- res.(i).(j) + a.(i).(k) * b.(k).(j)
done
done);
res ;;
let pool = Task.setup_pool ~num_domains:3 () in
let a = Array.make_matrix 2 2 1 in
let b = Array.make_matrix 2 2 2 in
let c = parallel_matrix_multiply pool a b in
for i = 0 to 1 do
for j = 0 to 1 do
Printf.printf "%d " c.(i).(j)
done;
print_char '\n'
done;;
I then compile it with no errors with
ocamlfind ocamlopt -linkpkg -package domainslib parallel_for.ml
and then comes the problem: executing the generated a.out file sometimes (rarely) prints the expected output
4 4
4 4
but usually ends with the error mentioned earlier:
Fatal error: exception Stdlib.Effect.Unhandled(Domainslib__Task.Wait(_, _))
Sorry if I am making some trivial mistake, but I can't understand what is going on, especially given that the error happens inconsistently.
The parallel_matrix_multiply computation is running outside of the Domainslib scheduler, thus whenever a task yields to the scheduler, the Wait effect is unhandled and transformed into a Effect.Unhandled exception.
The solution is to run the parallel computation within Task.run:
...
let c = Task.run pool (fun () -> parallel_matrix_multiply pool a b) in
...
The following code that was compiling successfully with Core v0.14 (ocaml 4.10), but fails with v0.15 (ocaml 4.11).
open Core;;
let command = Command.basic ~summary:"essai" (
let open Command.Let_syntax in
let%map_open s = anon(sequence ("n" %: int)) in
fun () ->
List.iter s ~f:(fun x -> Printf.printf "n = %d\n" x ) ;
)
let () = Command.run ~version:"0.0" ~build_info:"RWO" command;;
The error (with 4.11) :
File "cli.ml", line 10, characters 9-20:
10 | let () = Command.run ~version:"0.0" ~build_info:"RWO" command;;
^^^^^^^^^^^
Error (alert deprecated): Core.Command.run
[since 2021-03] Use [Command_unix]
File "cli.ml", line 10, characters 9-20:
10 | let () = Command.run ~version:"0.0" ~build_info:"RWO" command;;
^^^^^^^^^^^
Error: This expression has type [ `Use_Command_unix ]
This is not a function; it cannot be applied.
The documentation of Core.Command.run states that it is obsolete - but I fail to find how to replace it.
I think you're looking for Command_unix as indicated by the message you received. Documentation link for Command_unix.run.
The core library has been restructured in version 0.15: Unix-specific modules and functions have been moved to the core_unix library in order to make the main core library more portable (or at least javascript compatible).
The function Command_unix.run in core_unix library is exactly the same as the Command.run function in previous versions of the core library.
I am passing initial conditions as string, to be used to solving an ODE in sympy.
It is a first order ode, so for example, lets take initial conditions as y(0):3 for example. From help
ics is the set of initial/boundary conditions for the differential
equation. It should be given in the form of {f(x0): x1,
f(x).diff(x).subs(x, x2): x3}
I need to pass this to sympy.dsolve. But sympify(ic) gives an error for some reason.
What other tricks to use to make this work? Here is MWE. First one shows it works without initial conditions being string (normal mode of operation)
from sympy import *
x = Symbol('x')
y = Function('y')
ode = Eq(Derivative(y(x),x),1+2*x)
sol = dsolve(ode,y(x),ics={y(0):3})
gives sol Eq(y(x), x**2 + x + 3)
Now the case when ics is string
from sympy import *
ic = "y(0):3"
x = Symbol('x')
y = Function('y')
ode = Eq(Derivative(y(x),x),1+2*x)
sol = dsolve(ode,y(x),ics={ sympify(ic) })
gives
SympifyError: Sympify of expression 'could not parse 'y(0):3'' failed,
because of exception being raised: SyntaxError: invalid syntax
(, line 1)
So looking at sympify webpage
sympify(a, locals=None, convert_xor=True, strict=False, rational=False, evaluate=None)
And tried changing different options as shown above, still the syntax error shows up.
I also tried
sol = dsolve(ode,y(x),ics= { eval(ic) } )
But this gives syntax error as well
Is there a trick to use to convert this initial conditions string to something sympy is happy with?
Python 4.7 with sympy 1.5
As temporary work around, currently I do this
from sympy import *
ic = "y(0):3"
ic = ic.split(":")
x = Symbol('x')
y = Function('y')
ode = Eq(Derivative(y(x),x),1+2*x)
sol = dsolve(ode,y(x),ics= {S(ic[0]):S(ic[1])} )
Which works. So the problem is with : initially, sympify (or S) do not handle : it seems.
You can use sympify('{y(0):3}').
I don't know what your actual goal is but I don't recommend parsing strings like this in general. The format for ICs is actually slightly awkward so that for a second order ODE it looks like:
ics = '{y(0):3, y(x).diff(x).subs(x, 0):1}'
If you're parsing a string then you can come up with a better syntax than that like
ics = "y(0)=3, y'(0)=1"
Also you should use parse_expr rather than converting strings with sympify or S:
https://docs.sympy.org/latest/modules/parsing.html#sympy.parsing.sympy_parser.parse_expr
I want to do the following:
let dist = Stack.pop stck and dir = Stack.pop stck in (
print_endline(dist);
print_endline(dir);
......
......
)
The above gives me the following error:
Error: This expression has type unit
This is not a function; it cannot be applied.
How can I use the variables dist and dir over multiple lines?
The error is not in the piece of code you show here. I guess you forgot a ; somewhere.
But there is a subtle error in your code.
In this line of code
let dist = Stack.pop stck and dir = Stack.pop stck in
You expect to obtain the first element of the stack in dist and the second one in dir but it may not be the case as the order of evaluation is unspecified.
The basic syntax of your code is OK. Here's a simple example showing that it works fine:
$ ocaml
OCaml version 4.01.0
# let x = 5 and y = 4 in (
print_int x;
print_int y;
);;
54- : unit = ()
#
The reported errors have to do with other problems. We would need more context to see what's wrong. Possibly the errors are in the lines you elided. Or they could be caused by what comes next.