javascriptdata / danfojs

Danfo.js is an open source, JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.
https://danfo.jsdata.org/
MIT License
4.79k stars 209 forks source link

Miscalculations with dataframes longer than ~45 row #578

Open fcorallini opened 1 year ago

fcorallini commented 1 year ago

Problem description

On some Dell Vostro 220 machines we found errors in the calculation in the following methods: .mul() .div() .add() .sub() When Dataframe are longer than 42 row we got calculations errors. We are using Danfo Javascript library in browser via CDN, the error occurs in both updated Chromium and Firefox. The error occurs only when dataframes have more than 42 rows.

Example Code

 var dati = [
        [1.5, 2.8, 3.2],
        [4.7, 5.1, 6.9],
        [7.3, 8.6, 9.4],
        [10.2, 11.9, 12.5],
        [13.7, 14.3, 15.8],
        [16.6, 17.9, 18.1],
        [19.4, 20.7, 21.3],
        [22.9, 23.5, 24.8],
        [25.6, 26.3, 27.7],
        [28.1, 29.9, 30.4],
        [31.8, 32.2, 33.6],
        [34.9, 35.2, 36.7],
        [37.4, 38.6, 39.9],
        [40.1, 41.5, 42.8],
        [43.9, 44.7, 45.2],
        [46.8, 47.3, 48.1],
        [49.4, 50.6, 51.9],
        [52.7, 53.1, 54.5],
        [55.2, 56.9, 57.3],
        [58.4, 59.7, 60.2],
        [61.3, 62.5, 63.9],
        [64.7, 65.2, 66.6],
        [67.9, 68.3, 69.1],
        [70.6, 71.4, 72.8],
        [73.2, 74.5, 75.9],
        [76.7, 77.1, 78.4],
        [79.3, 80.8, 81.6],
        [82.5, 83.7, 84.2],
        [85.1, 86.4, 87.9],
        [88.6, 89.2, 90.7],
        [91.4, 92.8, 93.3],
        [94.1, 95.6, 96.9],
        [97.8, 98.2, 99.5],
        [100.4, 101.7, 102.3],
        [103.6, 104.9, 105.1],
        [106.3, 107.5, 108.7],
        [109.9, 110.4, 111.8],
        [112.7, 113.1, 114.6],
        [115.2, 116.5, 117.3],
        [118.9, 119.3, 120.7],
        [121.5, 122.8, 123.6],
        [124.2, 125.7, 126.9],
        [127.6, 128.1, 129.4],
        [130.3, 131.7, 132.2]
      ]

var df = new dfd.DataFrame(dati)

df.mul(1).print() 

Wrong Results

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ 0                 │ 1                 │ 2                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 1.5               │ 2.80078125        │ 3.19921875        ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ 4.69921875        │ 5.1015625         │ 6.8984375         ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ 7.30078125        │ 8.6015625         │ 5.1015625         ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ 6.8984375         │ 7.30078125        │ 8.6015625         ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4          │ 13.703125         │ 14.296875         │ 15.796875         ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 5          │ 16.59375          │ 17.90625          │ 14.296875         ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 6          │ 15.796875         │ 16.59375          │ 13.703125         ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 7          │ 14.296875         │ 23.5              │ 16.59375          ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 8          │ 25.59375          │ 26.296875         │ 27.703125         ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 9          │ 28.09375          │ 29.90625          │ 30.40625          ║ 
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

Expected Results

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ 0                 │ 1                 │ 2                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 1.5               │ 2.7999999523162…  │ 3.2000000476837…  ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ 4.6999998092651…  │ 5.0999999046325…  │ 6.9000000953674…  ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ 7.3000001907348…  │ 8.6000003814697…  │ 9.3999996185302…  ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ 10.199999809265…  │ 11.899999618530…  │ 12.5              ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4          │ 13.699999809265…  │ 14.300000190734…  │ 15.800000190734…  ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 5          │ 16.600000381469…  │ 17.899999618530…  │ 18.100000381469…  ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 6          │ 19.399999618530…  │ 20.700000762939…  │ 21.299999237060…  ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 7          │ 22.899999618530…  │ 23.5              │ 24.799999237060…  ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 8          │ 25.600000381469…  │ 26.299999237060…  │ 27.700000762939…  ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 9          │ 28.100000381469…  │ 29.899999618530…  │ 30.399999618530…  ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

Desktop (please complete the following information):

Additional context

The error occurs with updated danfojs@1.1.2 The error occurs also with the latest browser version, in anonymous browsing without extension. In these machine only works an old version WebGL, I don't know if it could be related to that ...

Screenshots

webgl

radutanasa commented 1 year ago

I just tested this in https://jsonconsole.com with your exact code. I used Chrome Version 116.0.5845.96 (Official Build) (arm64) on macOS Ventura 13.4.1. It seems to be working as expected.

Screenshot 2023-08-25 at 15 55 32
fcorallini commented 1 year ago

The bug occurs only when only version 1 of webgl is present. if webgl is present in both versions or absent it does not occur

gcorazza1 commented 10 months ago

Any update?