Comments (3)
I pulled the relevant C code out of owl, compiled it independently, and ran the following:
#include<math.h>
#include "owl_maths.h"
#include "igami.c"
#include <stdio.h>
int main() {
double t = -1;
double x = 0.9;
double y = 0.292000000000000037;
t = igami(x,y);
printf("%.10f\n",t);
return(0);
}
This returns the correct value of 1.1000096747.
This would seem to disqualify the C library itself being buggy, I think. I tried it at the -O3 optimization level and it still worked correctly. I can post the standalone C code if anyone wants to try it.
I'm at a loss, this is really bizarre.
from owl.
I edited the igami function in-place so it would run in the same context (being called from OCaml) and
- isnormal(x) returns false.
- x == x returns true
- isnan(x) returns false
- fpclassify(x) returns FP_NORMAL
- Returning to OCaml, Float.classify_float says nan
- the hexadecimal value is 0xFFF8000000000000
from owl.
I have identified the source of the bug.
As documented in the INSTALL.md, by default configure.ml sets the default C compiler flags to
OWL_CFLAGS="-g -O3 -Ofast -funroll-loops -ffast-math -DSFMT_MEXP=19937 -msse2 -fno-strict-aliasing"`
Removing -Ofast
and -ffast-math
from the configuration causes the bug to disappear. The problem originates from -ffinite-math-only
, one of the flags set by -ffast-math
. The igami
algorithm contains multiple checks for isnan
and to check whether a value is infinite, see here, here and here.
When the -ffinite-math-only
flag is passed to the compiler, these checks are ignored (they are optimized away under the assumption that your program contains no nan's). Checking for whether a number is infinite is likely a core part of the algorithm which cannot be ignored.
Because the code relies on numerous calls to owl_isnan, and references owl_posinf and other related values, it seems imprudent to use the -ffast-math
flag which eliminates all such function calls and references. x<OWL_POSINF
will be optimized to true
. It is at least an inconsistency: if one does not need the isnan checks, why write them in the first place?
I propose a git pr of changing the default OWL_CFLAGS
to omit -ffast-math
and -Ofast
.
I believe that beyond the immediate bug, this change would be more in keeping with the spirit of the OCaml community, which values the correctness guarantees offered by static typing and would also probably appreciate compliance with IEEE 754 standards about floating point numbers. -ffast-math
includes -funsafe-math-optimizations
. The gcc manual says that this option βallows optimizations for floating-point arithmetic that (a) assume that arguments and results are valid and (b) may violate IEEE or ANSI standards.β This is somewhat embarrassing given the goal stated in the README to "provide both researchers and industry programmers a powerful framework to write concise, fast and safe analytical code" (emphasis mine).
from owl.
Related Issues (20)
- Documentation is not in sync with current way plots are working
- OCaml cannot fins owl package HOT 1
- ssqr_diff' modifies inputs in place HOT 2
- Failure to load datasets for neural nets HOT 1
- Broken link to Algodiff module. HOT 2
- Exponential regression -- incorrect case HOT 1
- Test fails with GCC 13 HOT 1
- `Dataframe.to_cols` returns columns of incorrect size HOT 1
- Move project to ocaml-community HOT 7
- OCaml 5.2 support HOT 4
- Reintroduce owl-plplot HOT 6
- Dead link to TODO list HOT 1
- Random.float bounds are inclusive, be careful with logarithms
- Dataframe issues
- Slack issues
- Map a fancy/basic index list into a list of array coordinates? HOT 1
- `set_fancy` does not work for some arrays with certain `Bigarray.kind` types. HOT 4
- load_mnist_test_data can't download data HOT 1
- Serious bug with `not_equal_scalar` function always returning the wrong result.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from owl.