nberth / mlgmpidl Goto Github PK
View Code? Open in Web Editor NEWOCaml interface to the GMP library
License: Other
OCaml interface to the GMP library
License: Other
I face a problem using mlgmpidl 1.2.4 fetched from opam, compiled with both OCaml compiler chains 4.01.0 and 4.02.3. Here is a simplified version of my problem:
let _ =
let m = Mpzf.of_int 42 in
Format.printf "%a@\n" Mpzf.print m
ocamlbuild -use-ocamlfind -pkgs glpk,gmp main.byte -verbose 1 --
42
ocamlbuild -use-ocamlfind -pkgs glpk,gmp main.byte -verbose 1 --
/tmp/cc0hqkIW.o:(.data+0xd40): référence indéfinie vers « camlidl_mpz_mpz__export »
[...]
/tmp/cc0hqkIW.o:(.data+0xe68): référence indéfinie vers « camlidl_mpz_mpz_init_set »
collect2: error: ld returned 1 exit status
ocamlbuild -use-ocamlfind -pkgs gmp main.byte -verbose 1 --
42
After some painful investigation, it seems to me that the error is due to the absence of -lgmp_caml
in the final gcc invocation when I compile in bytecode. This library (libgmp_caml.a) defines the missing symbols and appears in the final gcc invocation for the native version.
This behaviour only happens with gmp and glpk, or apron and glpk (same missing symbols). Maybe glpk is faulty.
Important note : this behaviour does not happen with mlgmpidl 1.2.1, but does happen with mlgmpidl 1.2.2 and 1.2.4.
In the file mpfr.ml, there is a build error because of the use of string instead of bytes with OCaml 4.0.6
"File "mpfr.ml", line 551, characters 2-3:
Error: This expression has type string but an expression was expected of type bytes
"
Hi,
When trying to install mlgmpidl with opam install mlgmpidl
, on an opam switch with OCaml 4.12 compiled with flambda, musl and static, I get an error relating to a missing gmp.h file (see error summary below and attached file for details).
The installation seems to also fail on other switches (namely 4.11.1+musl+static+flambda and 4.08.0+musl+static+flambda)
As I understand it all dependencies are installed, please see opam depext command result below.
If there is any advice you could give concerning this error it would be greatly appreciated,
Thanks in advance in any case
Running opam depext mlgmpidl
I get :
# Detecting depexts using vars: arch=x86_64, os=linux, os-distribution=ubuntu, os-family=debian
# The following system packages are needed:
libgmp-dev
libmpfr-dev
perl
# All required OS packages found.
Error with opam install mlgmpidl
#=== ERROR while compiling mlgmpidl.1.2.13 ====================================#
# context 2.0.7 | linux/x86_64 | ocaml-option-flambda.1 ocaml-option-musl.1 ocaml-option-static.1 ocaml-variants.4.12.0+options | https://opam.ocaml.org/#fde0c1b5
# path ~/.opam/4.12.0+flambda+static/.opam-switch/build/mlgmpidl.1.2.13
# command ~/.opam/opam-init/hooks/sandbox.sh build make
# exit-code 2
# env-file ~/.opam/log/mlgmpidl-30803-6d07ae.env
# output-file ~/.opam/log/mlgmpidl-30803-6d07ae.out
### output ###
# [...]
# /home/jbarnes01/.opam/4.12.0+flambda+static/bin/ocamlfind ocamlc -package "bigarray" -annot -g -c gmp_random.ml
# /home/jbarnes01/.opam/4.12.0+flambda+static/bin/ocamlfind ocamlc -package "bigarray" -annot -g -c mpzf.ml
# /home/jbarnes01/.opam/4.12.0+flambda+static/bin/ocamlfind ocamlc -package "bigarray" -annot -g -c mpqf.ml
# /home/jbarnes01/.opam/4.12.0+flambda+static/bin/ocamlfind ocamlc -package "bigarray" -annot -g -c mpfrf.ml
# /home/jbarnes01/.opam/4.12.0+flambda+static/bin/ocamlfind ocamlopt -package "bigarray" -ccopt -U__STRICT_ANSI__ -ccopt -UNDEBUG -ccopt -O0 -ccopt -g -ccopt -Wcast-qual -ccopt -Wswitch -ccopt -Wall -ccopt -Wextra -ccopt -Wundef -ccopt -Wcast-align -ccopt -Wno-unused -ccopt -Wno-unused-parameter -ccopt -Wno-unused-function -ccopt -fPIC -ccopt -Werror-implicit-function-declaration -ccopt -Wbad-f[...]
# In file included from mpz_caml.c:21:0:
# gmp_caml.h:15:10: fatal error: gmp.h: No such file or directory
# #include "gmp.h"
# ^~~~~~~
# compilation terminated.
# Makefile:273: recipe for target 'mpz_caml.o' failed
# make: *** [mpz_caml.o] Error 2
The modules Mpzf, Mpqf and Mpfr (and more) offer comparison functions:
cmp : t -> t -> int
compare(...)
attribute.Could the documentation of MLGMPIDL state clearly if it is sound (or not) to use Pervasive.compare on its values?
Issue opened in thvnx/mlmpfr#21
It seems like the rounding mode is always Down
no matter what I set. I am on OSX, Ocaml 4.04.1, MFPR is version 3.1.2-p11. Here is a small concrete example:
(* Testing rounding modes in Mpfr. *)
Mpfr.set_default_rounding_mode Mpfr.Up ;;
let x = 32.0 +. 0.001 /. 3.0 ;;
Format.printf "x = %F@." x ;;
let a : Mpfr.t = Mpfr.of_float x Mpfr.Down ;;
Format.printf "a (Down) = %t@." (fun ppf -> Mpfr.print ppf a) ;;
let b : Mpfr.t = Mpfr.of_float x Mpfr.Up ;;
Format.printf "b (Up) = %t@." (fun ppf -> Mpfr.print ppf b) ;;
(* What if we copy b to b' with low precision and tell it to round up? *)
let b' = Mpfr.init2 4 ;;
ignore (Mpfr.set b' b Mpfr.Up) ;;
Format.printf "b' (Up) = %t@\n@." (fun ppf -> Mpfr.print ppf b') ;
This gives the following output:
x = 32.0003333333
a (Down) = 0.32000333333333330E2
b (Up) = 0.32000333333333330E2
b' (Up) = 0.320E2
As far as I am concrned b
should be larger than x
.
Hello,
I have been trying to install apron
which depends on mlgmpidl
. Problem is during the installation the script is not able to find GMP which I installed through homebrew
.
I notice that it would be easy if I could manually set the GMP_PREFIX
flag from what I googled, but I do not know how to do this or what other fix I can try.
Also I don't know if I should install GMP in another way, or maybe even install mlgmpidl
manually.
This is the output of the installation:
$ opam install mlgmpidl
The following actions will be performed:
- install mlgmpidl 1.2.14
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> retrieved mlgmpidl.1.2.14 (cached)
[ERROR] The compilation of mlgmpidl.1.2.14 failed at "sh ./configure --absolute-dylibs".
#=== ERROR while compiling mlgmpidl.1.2.14 ====================================#
# context 2.1.2 | macos/arm64 | ocaml.4.12.0 | https://opam.ocaml.org#0a4c2bf0
# path ~/.opam/default/.opam-switch/build/mlgmpidl.1.2.14
# command ~/.opam/opam-init/hooks/sandbox.sh build sh ./configure --absolute-dylibs
# exit-code 1
# env-file ~/.opam/log/mlgmpidl-3719-2f5e9f.env
# output-file ~/.opam/log/mlgmpidl-3719-2f5e9f.out
### output ###
# [...]
# binary perl: found in /opt/homebrew/bin
# binary install: found in /usr/bin
# looking for gmp without prefix
# include gmp.h: not found
# looking for gmp in prefix /usr/local
# include gmp.h: not found
# looking for gmp in prefix /usr
# include gmp.h: not found
# looking for gmp in prefix /Users/tiraboschi
# include gmp.h: not found
# library gmp not found
# GMP not found, set GMP_PREFIX
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
+- The following actions failed
| - build mlgmpidl 1.2.14
+-
- No changes have been performed
Any help is appreciated. Thanks in advance.
Hi,
I have the following:
The configure script fails to detect mpfr, although it is there. The reason seems to be that the compilation of the test file generated by the script in order to test for mpfr would require not only to give the path for mpfr but also to gmp.
Indeed, the generated compile command fails:
cc -Wcast-qual -Wswitch -Wall -Wextra -Wundef -Wcast-align -Wno-unused -Wno-unused-parameter -Wno-unused-function -fPIC -Werror-implicit-function-declaration -Wbad-function-cast -Wstrict-prototypes -std=c99 -L/opt/homebrew/opt/llvm/lib -I/opt/homebrew/Cellar/mpfr/4.2.0-p12//include -c tmp.c -o tmp.o
and produces:
In file included from tmp.c:1: /opt/homebrew/Cellar/mpfr/4.2.0-p12//include/mpfr.h:53:10: fatal error: 'gmp.h' file not found #include <gmp.h>
However, the following works:
cc -Wcast-qual -Wswitch -Wall -Wextra -Wundef -Wcast-align -Wno-unused -Wno-unused-parameter -Wno-unused-function -fPIC -Werror-implicit-function-declaration -Wbad-function-cast -Wstrict-prototypes -std=c99 -L/opt/homebrew/opt/llvm/lib -I/opt/homebrew/Cellar/mpfr/4.2.0-p12//include -I/opt/homebrew/Cellar/gmp/6.2.1_1/include -c tmp.c -o tmp.o
It seems that commit 454e47f did remove HAS_NATIVE_PLUGINS
from Makefile.config
, as seen in this line of the diff for configure
(possibly it was intended to replace it with HAS_SHARED
, which seems to appear in this other line).
However, the Makefile
itself still relies on the presence of this variable to decide whether to create gmp.cmxs
or not, effectively preventing it to be created, thus to dynamically load the library in native applications.
An obvious workaround is to compile with make HAS_NATIVE_PLUGINS=1
(or to export HAS_NATIVE_PLUGINS=1
before opam reinstall mlgmplib
), but it'd obviously be better to either define HAS_NATIVE_PLUGINS
in Makefile.config
, rely on HAS_SHARED
in Makefile
, or, given that the variable was apparently unconditionally set to 1
, get rid of the test altogether.
Hi.
mlgmpidl-1.3
raises the following error
[ERROR] The compilation of ez-conf-lib.1 failed at "sh -ecx sed -e 's_@@ez-conf-lib:lib@@_/home/runner/work/haechi/haechi/_opam/lib/ez-conf-lib_g' ez-conf-lib.config.in > ez-conf-lib.config".
#=== ERROR while compiling ez-conf-lib.1 ======================================#
# context 2.1.5 | linux/x86_64 | ocaml-base-compiler.4.13.1 | git+https://github.com/ocaml/opam-repository.git
# path ~/work/haechi/haechi/_opam/.opam-switch/build/ez-conf-lib.1
# command ~/.opam/opam-init/hooks/sandbox.sh build sh -ecx sed -e 's_@@ez-conf-lib:lib@@_/home/runner/work/haechi/haechi/_opam/lib/ez-conf-lib_g' ez-conf-lib.config.in > ez-conf-lib.config
# exit-code 1
# env-file ~/.opam/log/ez-conf-lib-24408-8f2518.env
# output-file ~/.opam/log/ez-conf-lib-24408-8f2518.out
### output ###
# + sed -e s_@@ez-conf-lib:lib@@_/home/runner/work/haechi/haechi/_opam/lib/ez-conf-lib_g ez-conf-lib.config.in
# sed: -e expression #1, char 56: unknown option to `s'
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build ez-conf-lib 1
└─
This error happens in the Github OCaml CI (Ubuntu). Unfortunately, I could not reproduce the error on my local machine (also Ubuntu).
Everything is OK with mlgmpidl-1.2.5
.
The OCaml compiler does not support profiling on all platforms. Whether profiling is supported can be checked calling ocamlopt -config | grep profiling
.
When building mlgmpidl
in such an environment, compilation fails with:
Profiling with "gprof" is not supported on this platform.
Here is an example of the log of a failed attempt to build: https://logs.nix.ci/?key=nixos/nixpkgs.55951&attempt_id=ecf69320-30a1-46d7-9437-734cd6e6af8a
Could the build of the profiling-enabled libraries be made optional?
Calling Mpfr.to_mpq abruptly halted my program with:
gmp: overflow in mpz type
Aborted
I join to this issue a program with two calls to Mpfr.to_mpq :
minimal_bug_mpfr_to_mpq.ml.txt
With my version of MLGMPIDL (1.2.9), this program produces this output:
Unsoundness
The float: 0.56294995342131200E23
The rational: 800000000Crash
The float: 0.10000000000000000E1
gmp: overflow in mpz type
Aborted
In my humble opinion, the code of Mpfr.to_mpq has never been functional, for any input. The failure arises when the mpz_mul_2exp is called with a negative exponent (which is almost always the case). I propose the patch attached to this issue (I could not push my branch directly).
mpfr_to_mpq.diff.txt
The patch fixes the failure and gives correct results. My argumentation is detailed below:
The documentation of MPFR says:
Function: mpfr_exp_t mpfr_get_z_2exp (mpz_t rop, mpfr_t op)
Put the scaled significand of op (regarded as an integer, with the precision of op) into rop, and return the exponent exp (which may be outside the current exponent range) such that op exactly equals rop times 2 raised to the power exp.
The documentation of GMP says:
Function: void mpz_mul_2exp (mpz_t rop, const mpz_t op1, mp_bitcnt_t op2)
Set rop to op1 times 2 raised to op2. This operation can also be defined as a left shift by op2 bits.
and:
Counts of bits of a multi-precision number are represented in the C type mp_bitcnt_t. Currently this is always an unsigned long, but on some systems it will be an unsigned long long
in the future.
From the GMP documentation, it is clear that mpz_mul_2exp must not be called with directly with a value of type mpfr_exp_t, which can be negative.
From a significand sig and exponent exp, the proposed code computes:
Both computation boils down to sig * 2 ^ exp, which happen to be the input value.
With the patch applied, the attached program produces the following output:
Unsoundness
The float: 0.56294995342131200E23
The rational: 56294995342131200000000Crash
The float: 0.10000000000000000E1
The rational: 1
Hi,
I am planing to use mlgmpidl in some software developed by my company, MathWorks. In this process I have found that a few functions had been incorrectly typed as returning a boolean instead of a "ternary value". Also, I needed a few additional functions which were not yet stubbed. Finally, I found it useful to provide a (very simple) interface to sprintf. This may or not be of general interest.
I'm sending the patch to mpfr.idl as an attachement. Please let me know if I should create a pull request.
mpfr.idl.txt
Best Regards,
Tiphaine Turpin
MathWorks
I see there have been some commits to help compiling under OCaml 5.
I've managed to compile master on OCaml 5.0.0 on the condition that profiling is disabled (it is enabled by default).
Should we disable profiling by default and do a new release and push to opam ?
Btw, I plan to make Apron compile under OCaml 5 and push a new opam version, which requires mlgmpidl, see antoinemine/apron#66
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.