From 1ce6c5a6481494ffc27771473f21646dbce0e28e Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Wed, 28 Jun 2023 15:49:33 +0530 Subject: [PATCH 01/28] init tests for floor --- tests/floor.apln | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tests/residue.apln | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/floor.apln diff --git a/tests/floor.apln b/tests/floor.apln new file mode 100644 index 0000000..32c8785 --- /dev/null +++ b/tests/floor.apln @@ -0,0 +1,46 @@ +:Namespace floor + Assert←#.unittest.Assert + + ⍝ Run Variations of each test with normal, empty and multiple shaped data + ∇ tRes←tData RunVariations exp ;actualR;actualRE;expectedR;left;right;res;tID;tCmt;p;shape;shapeW0;actualRS + (expectedR p)←exp + (tID tCmt)←tData + tRes←⍬ + + ⍝ normal + actualR←⌊p + tRes,←tData Assert expectedR≡actualR + ∇ + + ∇ r←test_floor ;r;data;case;data2;case2;type;bool;i1;i2;i3;dbl;fl;cmplx;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;fltalmostd1;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc + ct_default←1E¯14 + dct_default←1E¯28 + fr_dbl←645 + fr_decf←1287 + + bool←0 1 ⍝ 11: 1 bit Boolean type arrays + i1←{⍵,0,-⍵}⍳120 ⍝ 83: 8 bits signed integer + i2←{⍵,0,-⍵}10000+⍳1000 ⍝ 163: 16 bits signed integer + i3←{⍵,0,-⍵}100000+⍳100 ⍝ 323: 32 bits signed integer + dbl←{⍵,0,-⍵}1000.5+⍳100 ⍝ 645: 64 bits Floating + ⍝ Hdbl is 645 but larger numbers + Hdbl←{⍵,-⍵}1E14+(2×⍳50) + ⍝ Hfl is 1287 but larger numbers + ⎕FR←fr_decf ⍝ use ⎕FR=1287 + fl←{⍵,0,-⍵}1000.5+⍳100 ⍝ 1287: 128 bits Decimal + Hfl←{⍵,-⍵}2E29+(1E16×⍳10) ⍝ 1287 but larger numbers + ⎕FR←fr_dbl ⍝ revert ⎕FR=645 + cmplx←{(-⍵),⍵,0,(+⍵),(-+⍵)}(0J1×⍳100)+⌽⍳100 ⍝ 1289: 128 bits Complex + Hcmplx←{(-⍵),⍵,(+⍵),(-+⍵)}(1E14J1E14×⍳20) ⍝ 1289 but larger numbers + + r←⍬ + testDesc←{'for ',case,{0∊⍴case2:'',⍵⋄' , ', case2,⍵},' & ⎕CT ⎕DCT:',⎕CT,⎕DCT, '& ⎕FR:', ⎕FR} + + case←⍬ + case2←⍬ + desc←testDesc⍬ + + r,← 'Ti1' desc RunVariations 1 ⌊1 + ∇ + +:EndNamespace \ No newline at end of file diff --git a/tests/residue.apln b/tests/residue.apln index 43f40e7..98d617f 100644 --- a/tests/residue.apln +++ b/tests/residue.apln @@ -30,7 +30,7 @@ tRes,←('ShapeW0',tID) tCmt Assert (shapeW0⍴0) ≡ actualRSW0 ∇ - ∇ r←test_residue ;genResidue;r;data;case;data2;case2;type;bool;i1;char1;char2;i2;char3;i3;ptr;dbl;fl;cmplx;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;fltalmostd1;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc + ∇ r←test_residue ;genResidue;r;data;case;data2;case2;type;bool;i1;i2;i3;ptr;dbl;fl;cmplx;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;fltalmostd1;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc ct_default←1E¯14 dct_default←1E¯28 fr_dbl←645 From f08951d387d21348ba40009532a83574b76fc9b6 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 29 Jun 2023 14:57:18 +0530 Subject: [PATCH 02/28] add basic tests and loops --- tests/floor.apln | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/floor.apln b/tests/floor.apln index 32c8785..2849ab4 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -40,7 +40,46 @@ case2←⍬ desc←testDesc⍬ - r,← 'Ti1' desc RunVariations 1 ⌊1 + + :For ct :In 0 1 + (⎕CT ⎕DCT)←ct × ct_default dct_default ⍝ set comparision tolerance + :For fr :In 2 1 + ⎕FR←fr⊃fr_dbl fr_decf + :For case :In 'i1' 'i2' 'i3' 'dbl' 'Hdbl' 'fl' 'Hfl' 'cmplx' 'Hcmplx' + data←⍎case + ⍝ Cross type tests + :For case2 :In 'i1' 'i2' 'i3' 'dbl' 'fl' + data2←⍎case2 + :If (⊂data)∊cmplx Hdbl Hfl Hcmplx + :Continue + :EndIf + desc←testDesc⍬ + :If (data≡data2) + :Continue + :EndIf + ⍝ r,← 'TCross1' desc RunVariations (data,data2) (data,data2) + :EndFor + + case2←⍬ ⍝ disposing case2 for testDesc + desc←testDesc⍬ + + ⍝ r,← 'T1' desc RunVariations (data genResidue ⌽data) data (⌽data) ⍝ generator func finds results on array + ⍝ d1←data[?≢data] + ⍝ d2←data[?≢(data~d1)] + ⍝ r,← 'T2' desc RunVariations (d1 genResidue d2) d1 d2 ⍝ generator func finds results on single element + + :If (⊂data)∊i1 i2 i3 + r,← 'TInt' desc RunVariations data data ⍝ floor of integers will always be floor + :EndIf + + :If case≡'dbl' + halfLen←(¯1+≢data)÷2 + r,← 'TDbl' desc RunVariations ({(⍵-0.5),0,-0.5+⍵}(halfLen↑data)) data ⍝ floor of dbl is removing the 0.5 from the number + :EndIf + :EndFor + + :EndFor + :EndFor ∇ :EndNamespace \ No newline at end of file From d09370b2c60643ef297154f16f6d5a40ab28cfa9 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Tue, 4 Jul 2023 17:12:46 +0530 Subject: [PATCH 03/28] push progress on Floor generator function using strings --- tests/floor.apln | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index 2849ab4..bb63517 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -35,17 +35,23 @@ r←⍬ testDesc←{'for ',case,{0∊⍴case2:'',⍵⋄' , ', case2,⍵},' & ⎕CT ⎕DCT:',⎕CT,⎕DCT, '& ⎕FR:', ⎕FR} - - case←⍬ - case2←⍬ - desc←testDesc⍬ + ⍝ Using strings to calculate floor of a number + ⍝ Other approaches included using {⍵-(1|⍵)} but residue uses floor in its derivation so can be conflicting + ⍝ Approach 2 was using binary conversion and stripping decimals similar to the string approach, but the sources use something similar + ⍝ The string approach is good because it deals with floor in a very non-co-related way so it can never be clashing + genFloor←{ + dotPos←{⍸,'.'⍷(⍕⍵)}⍵ ⍝ convert num to string and get position of the decimal point + int←⍎(⍕⍵)↑⍨¯1+dotPos ⍝ strip integer based on the decimal point + int-(⍵<0)∧(~0∊⍴dotPos) ⍝ Subtract 1 only when negative+non int component exists. eg: ¯123.32→¯124 + } + ⍝ genFloor←{(⍎(⍕⍵)↑⍨¯1+⍸,'.'⍷(⍕⍵))-(⍵<0)∧(~0∊⍴(⍸,'.'⍷(⍕⍵)))} :For ct :In 0 1 (⎕CT ⎕DCT)←ct × ct_default dct_default ⍝ set comparision tolerance :For fr :In 2 1 ⎕FR←fr⊃fr_dbl fr_decf - :For case :In 'i1' 'i2' 'i3' 'dbl' 'Hdbl' 'fl' 'Hfl' 'cmplx' 'Hcmplx' + :For case :In 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' ⍝'cmplx' 'Hcmplx' data←⍎case ⍝ Cross type tests :For case2 :In 'i1' 'i2' 'i3' 'dbl' 'fl' @@ -57,19 +63,18 @@ :If (data≡data2) :Continue :EndIf - ⍝ r,← 'TCross1' desc RunVariations (data,data2) (data,data2) + r,← 'TCross1' desc RunVariations (genFloor¨ data,data2) (data,data2) :EndFor case2←⍬ ⍝ disposing case2 for testDesc desc←testDesc⍬ - ⍝ r,← 'T1' desc RunVariations (data genResidue ⌽data) data (⌽data) ⍝ generator func finds results on array - ⍝ d1←data[?≢data] - ⍝ d2←data[?≢(data~d1)] - ⍝ r,← 'T2' desc RunVariations (d1 genResidue d2) d1 d2 ⍝ generator func finds results on single element + r,← 'T1' desc RunVariations (genFloor¨data) data ⍝ generator func finds results on array + d1←data[?≢data] + r,← 'T2' desc RunVariations (genFloor d1) d1 ⍝ generator func finds results on single element :If (⊂data)∊i1 i2 i3 - r,← 'TInt' desc RunVariations data data ⍝ floor of integers will always be floor + r,← 'TInt' desc RunVariations data data ⍝ floor of integers will always be floor :EndIf :If case≡'dbl' @@ -77,7 +82,6 @@ r,← 'TDbl' desc RunVariations ({(⍵-0.5),0,-0.5+⍵}(halfLen↑data)) data ⍝ floor of dbl is removing the 0.5 from the number :EndIf :EndFor - :EndFor :EndFor ∇ From 1839ed46e7d817e8e6225766ea9756311cf250e1 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 6 Jul 2023 16:31:58 +0530 Subject: [PATCH 04/28] use pp value max for generator function as it gets rounded off because of execute and format --- tests/floor.apln | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/floor.apln b/tests/floor.apln index bb63517..fa9f8e7 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -41,6 +41,7 @@ ⍝ Approach 2 was using binary conversion and stripping decimals similar to the string approach, but the sources use something similar ⍝ The string approach is good because it deals with floor in a very non-co-related way so it can never be clashing genFloor←{ + ⎕pp←34 ⍝ set to max as we are using strings, the execute and format primitives round the number to the ⎕pp value dotPos←{⍸,'.'⍷(⍕⍵)}⍵ ⍝ convert num to string and get position of the decimal point int←⍎(⍕⍵)↑⍨¯1+dotPos ⍝ strip integer based on the decimal point int-(⍵<0)∧(~0∊⍴dotPos) ⍝ Subtract 1 only when negative+non int component exists. eg: ¯123.32→¯124 From 702199dbdaff550878fe96921a7bc831b3f53f8f Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 6 Jul 2023 17:10:59 +0530 Subject: [PATCH 05/28] new tests: adding random decimals to dataset --- tests/floor.apln | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/floor.apln b/tests/floor.apln index fa9f8e7..e8a7b99 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -71,11 +71,16 @@ desc←testDesc⍬ r,← 'T1' desc RunVariations (genFloor¨data) data ⍝ generator func finds results on array + d1←data[?≢data] r,← 'T2' desc RunVariations (genFloor d1) d1 ⍝ generator func finds results on single element + dataplus←data+?0 ⍝ adding a number between (0,1) to data + r,← 'T3' desc Assert ((genFloor¨dataplus)≡⌊dataplus) ∨ (fr=1 ∧ case≡'Hfl') ⍝ genFloor fails for Hfl with ⎕fr=645 + :If (⊂data)∊i1 i2 i3 - r,← 'TInt' desc RunVariations data data ⍝ floor of integers will always be floor + r,← 'TInt1' desc RunVariations data data ⍝ floor of integers will always be floor + r,← 'TInt2' desc RunVariations data dataplus ⍝ floor of integers will always be floor :EndIf :If case≡'dbl' From 705851a6f9a6b8c69d355694e5293f2cc454cd82 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 6 Jul 2023 17:15:19 +0530 Subject: [PATCH 06/28] add variations for tests --- tests/floor.apln | 14 ++++++++++++++ tests/magnitude.apln | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/floor.apln b/tests/floor.apln index e8a7b99..f9de808 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -10,6 +10,20 @@ ⍝ normal actualR←⌊p tRes,←tData Assert expectedR≡actualR + + ⍝ empty + actualRE←⌊(0⍴p) ⍝ 0 in the shape means we have no elements in the array, i.e. it's empty. + tRes,←('Empty',tID) tCmt Assert ⍬≡actualRE + + ⍝ different shapes + shape←?(?4)/4 + actualRS←⌊(shape⍴actualR) + tRes,←('Multiple',tID) tCmt Assert (shape⍴expectedR)≡actualRS + + ⍝ ⍝ different shapes with 0 in shape + shapeW0←(0@(?(≢shape)))shape + actualRS←⌊(shapeW0⍴p) + tRes,←('ShapeW0',tID) tCmt Assert (shapeW0⍴0) ≡ actualRS ∇ ∇ r←test_floor ;r;data;case;data2;case2;type;bool;i1;i2;i3;dbl;fl;cmplx;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;fltalmostd1;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc diff --git a/tests/magnitude.apln b/tests/magnitude.apln index 0f88ee9..849186c 100644 --- a/tests/magnitude.apln +++ b/tests/magnitude.apln @@ -18,7 +18,7 @@ ⍝ empty actualRE←|(0⍴p) ⍝ 0 in the shape means we have no elements in the array, i.e. it's empty. - tRes,←('Empty',tID) tCmt Assert ((0⍴p))≡actualRE + tRes,←('Empty',tID) tCmt Assert ⍬≡actualRE ⍝ different shapes shape←?(?4)/4 From 8950986e8ca46f05af3fd086c04987386dc3456a Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 6 Jul 2023 17:40:06 +0530 Subject: [PATCH 07/28] localise vars --- tests/floor.apln | 2 +- tests/residue.apln | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index f9de808..17cf0b0 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -26,7 +26,7 @@ tRes,←('ShapeW0',tID) tCmt Assert (shapeW0⍴0) ≡ actualRS ∇ - ∇ r←test_floor ;r;data;case;data2;case2;type;bool;i1;i2;i3;dbl;fl;cmplx;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;fltalmostd1;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc + ∇ r←test_floor ;genFloor;r;data;dataplus;case;data2;case2;type;bool;i1;i2;i3;dbl;fl;cmplx;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;halfLen;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc ct_default←1E¯14 dct_default←1E¯28 fr_dbl←645 diff --git a/tests/residue.apln b/tests/residue.apln index 98d617f..fe46c8c 100644 --- a/tests/residue.apln +++ b/tests/residue.apln @@ -30,7 +30,7 @@ tRes,←('ShapeW0',tID) tCmt Assert (shapeW0⍴0) ≡ actualRSW0 ∇ - ∇ r←test_residue ;genResidue;r;data;case;data2;case2;type;bool;i1;i2;i3;ptr;dbl;fl;cmplx;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;fltalmostd1;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc + ∇ r←test_residue ;genResidue;r;data;case;data2;case2;type;bool;i1;i2;i3;ptr;dbl;fl;cmplx;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc ct_default←1E¯14 dct_default←1E¯28 fr_dbl←645 From bdfbaaf7273d829d9bfabcea7d92136f11695b19 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 6 Jul 2023 18:01:43 +0530 Subject: [PATCH 08/28] remove dfn wrap from dotPos --- tests/floor.apln | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/floor.apln b/tests/floor.apln index 17cf0b0..6d14ca1 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -56,7 +56,7 @@ ⍝ The string approach is good because it deals with floor in a very non-co-related way so it can never be clashing genFloor←{ ⎕pp←34 ⍝ set to max as we are using strings, the execute and format primitives round the number to the ⎕pp value - dotPos←{⍸,'.'⍷(⍕⍵)}⍵ ⍝ convert num to string and get position of the decimal point + dotPos←⍸,'.'⍷⍕⍵ ⍝ convert num to string and get position of the decimal point int←⍎(⍕⍵)↑⍨¯1+dotPos ⍝ strip integer based on the decimal point int-(⍵<0)∧(~0∊⍴dotPos) ⍝ Subtract 1 only when negative+non int component exists. eg: ¯123.32→¯124 } From 1765aadb5f14428a271e43d328d6b60ce47c7cbe Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 6 Jul 2023 18:41:03 +0530 Subject: [PATCH 09/28] add basic template for complex tests --- tests/floor.apln | 50 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index 6d14ca1..6bdd754 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -1,6 +1,18 @@ :Namespace floor Assert←#.unittest.Assert + ⍝ Using strings to calculate floor of a number + ⍝ Other approaches included using {⍵-(1|⍵)} but residue uses floor in its derivation so can be conflicting + ⍝ Approach 2 was using binary conversion and stripping decimals similar to the string approach, but the sources use something similar + ⍝ The string approach is good because it deals with floor in a very non-co-related way so it can never be clashing + genFloor←{ + ⎕pp←34 ⍝ set to max as we are using strings, the execute and format primitives round the number to the ⎕pp value + dotPos←⍸,'.'⍷⍕⍵ ⍝ convert num to string and get position of the decimal point + int←⍎(⍕⍵)↑⍨¯1+dotPos ⍝ strip integer based on the decimal point + int-(⍵<0)∧(~0∊⍴dotPos) ⍝ Subtract 1 only when negative+non int component exists. eg: ¯123.32→¯124 + } + ⍝ genFloor←{(⍎(⍕⍵)↑⍨¯1+⍸,'.'⍷(⍕⍵))-(⍵<0)∧(~0∊⍴(⍸,'.'⍷(⍕⍵)))} + ⍝ Run Variations of each test with normal, empty and multiple shaped data ∇ tRes←tData RunVariations exp ;actualR;actualRE;expectedR;left;right;res;tID;tCmt;p;shape;shapeW0;actualRS (expectedR p)←exp @@ -26,7 +38,7 @@ tRes,←('ShapeW0',tID) tCmt Assert (shapeW0⍴0) ≡ actualRS ∇ - ∇ r←test_floor ;genFloor;r;data;dataplus;case;data2;case2;type;bool;i1;i2;i3;dbl;fl;cmplx;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;halfLen;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc + ∇ r←test_floor ;r;data;dataplus;case;data2;case2;type;bool;i1;i2;i3;dbl;fl;cmplx;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;halfLen;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc ct_default←1E¯14 dct_default←1E¯28 fr_dbl←645 @@ -50,18 +62,6 @@ r←⍬ testDesc←{'for ',case,{0∊⍴case2:'',⍵⋄' , ', case2,⍵},' & ⎕CT ⎕DCT:',⎕CT,⎕DCT, '& ⎕FR:', ⎕FR} - ⍝ Using strings to calculate floor of a number - ⍝ Other approaches included using {⍵-(1|⍵)} but residue uses floor in its derivation so can be conflicting - ⍝ Approach 2 was using binary conversion and stripping decimals similar to the string approach, but the sources use something similar - ⍝ The string approach is good because it deals with floor in a very non-co-related way so it can never be clashing - genFloor←{ - ⎕pp←34 ⍝ set to max as we are using strings, the execute and format primitives round the number to the ⎕pp value - dotPos←⍸,'.'⍷⍕⍵ ⍝ convert num to string and get position of the decimal point - int←⍎(⍕⍵)↑⍨¯1+dotPos ⍝ strip integer based on the decimal point - int-(⍵<0)∧(~0∊⍴dotPos) ⍝ Subtract 1 only when negative+non int component exists. eg: ¯123.32→¯124 - } - ⍝ genFloor←{(⍎(⍕⍵)↑⍨¯1+⍸,'.'⍷(⍕⍵))-(⍵<0)∧(~0∊⍴(⍸,'.'⍷(⍕⍵)))} - :For ct :In 0 1 (⎕CT ⎕DCT)←ct × ct_default dct_default ⍝ set comparision tolerance :For fr :In 2 1 @@ -105,5 +105,27 @@ :EndFor :EndFor ∇ - + + ∇ r←test_cmplx_floor ;cmplx;Hcmplx;magCmplx;d1;case;data;testDesc;desc;ct_default;dct_default;fr_dbl;fr_decf + ct_default←1E¯14 + dct_default←1E¯28 + fr_dbl←645 + fr_decf←1287 + + cmplx←{(-⍵),⍵,0,(+⍵),(-+⍵)}(0J1×⍳100)+⌽⍳100 ⍝ 1289: 128 bits Complex + Hcmplx←{(-⍵),⍵,(+⍵),(-+⍵)}(1E14J1E14×⍳20) ⍝ 1289 but larger numbers + + r←⍬ + testDesc←{'for ',case} + + :For case :In 'cmplx' 'Hcmplx' + data←⍎case + desc←testDesc⍬ + r,←'Tc1' desc RunVariations data data + + d1←data[?≢data] + r,←'Tc2' desc RunVariations d1 d1 + :EndFor + ∇ + :EndNamespace \ No newline at end of file From 107f87856b845b68c8ea8a88d76f43c66b73d3f5 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 6 Jul 2023 19:07:01 +0530 Subject: [PATCH 10/28] cmplx floor --- tests/floor.apln | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index 6bdd754..dfca5c0 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -12,6 +12,17 @@ int-(⍵<0)∧(~0∊⍴dotPos) ⍝ Subtract 1 only when negative+non int component exists. eg: ¯123.32→¯124 } ⍝ genFloor←{(⍎(⍕⍵)↑⍨¯1+⍸,'.'⍷(⍕⍵))-(⍵<0)∧(~0∊⍴(⍸,'.'⍷(⍕⍵)))} + + genCmplxFloor←{ + r←9○⍵ + i←11○⍵ + b←(genFloor r)+0j1×genFloor i + x←r-genFloor r + y←i-genFloor i + 1>x+y: b + x≥y: b+1 + b+0j1 + } ⍝ Run Variations of each test with normal, empty and multiple shaped data ∇ tRes←tData RunVariations exp ;actualR;actualRE;expectedR;left;right;res;tID;tCmt;p;shape;shapeW0;actualRS @@ -66,7 +77,7 @@ (⎕CT ⎕DCT)←ct × ct_default dct_default ⍝ set comparision tolerance :For fr :In 2 1 ⎕FR←fr⊃fr_dbl fr_decf - :For case :In 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' ⍝'cmplx' 'Hcmplx' + :For case :In 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' data←⍎case ⍝ Cross type tests :For case2 :In 'i1' 'i2' 'i3' 'dbl' 'fl' @@ -89,7 +100,7 @@ d1←data[?≢data] r,← 'T2' desc RunVariations (genFloor d1) d1 ⍝ generator func finds results on single element - dataplus←data+?0 ⍝ adding a number between (0,1) to data + dataplus←data+?(≢data)/0 ⍝ adding a number between (0,1) to data r,← 'T3' desc Assert ((genFloor¨dataplus)≡⌊dataplus) ∨ (fr=1 ∧ case≡'Hfl') ⍝ genFloor fails for Hfl with ⎕fr=645 :If (⊂data)∊i1 i2 i3 @@ -118,13 +129,23 @@ r←⍬ testDesc←{'for ',case} - :For case :In 'cmplx' 'Hcmplx' - data←⍎case - desc←testDesc⍬ - r,←'Tc1' desc RunVariations data data + :For ct :In 0 1 + (⎕CT ⎕DCT)←ct × ct_default dct_default ⍝ set comparision tolerance + :For fr :In 2 1 + ⎕FR←fr⊃fr_dbl fr_decf + :For case :In 'cmplx' 'Hcmplx' + data←⍎case + desc←testDesc⍬ + r,←'T1' desc RunVariations data data + + d1←data[?≢data] + r,←'T2' desc RunVariations d1 d1 - d1←data[?≢data] - r,←'Tc2' desc RunVariations d1 d1 + dataplus←data+?(≢data)/0 ⍝ adding a number between (0,1) to data + ⍝ todo: add ?0 to imaginary component also + r,←'T3' desc RunVariations (genCmplxFloor¨dataplus) dataplus + :EndFor + :EndFor :EndFor ∇ From 970c5f0aa7a76ec5e64024abf8a65484165e1888 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 6 Jul 2023 19:21:48 +0530 Subject: [PATCH 11/28] new way to generate decimal cmplx numbers --- tests/floor.apln | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index dfca5c0..19d4099 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -127,7 +127,7 @@ Hcmplx←{(-⍵),⍵,(+⍵),(-+⍵)}(1E14J1E14×⍳20) ⍝ 1289 but larger numbers r←⍬ - testDesc←{'for ',case} + testDesc←{'for ',case,' & ⎕CT ⎕DCT:',⎕CT,⎕DCT, '& ⎕FR:', ⎕FR} :For ct :In 0 1 (⎕CT ⎕DCT)←ct × ct_default dct_default ⍝ set comparision tolerance @@ -141,9 +141,8 @@ d1←data[?≢data] r,←'T2' desc RunVariations d1 d1 - dataplus←data+?(≢data)/0 ⍝ adding a number between (0,1) to data - ⍝ todo: add ?0 to imaginary component also - r,←'T3' desc RunVariations (genCmplxFloor¨dataplus) dataplus + dataplus←data+(?(≢data)/0)+¯11○(?(≢data)/0) ⍝ adding a number between (0,1) to data + r,←'T3' desc Assert ((genCmplxFloor¨dataplus)≡⌊dataplus) ∨ (fr=2 ∧ case≡'Hcmplx') :EndFor :EndFor :EndFor From 188f67cc0b48246b6f59ff1968665864899775d9 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 6 Jul 2023 19:38:13 +0530 Subject: [PATCH 12/28] improve decimal generator for cmplxfloor tests --- tests/floor.apln | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/floor.apln b/tests/floor.apln index 19d4099..b2937e0 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -141,7 +141,7 @@ d1←data[?≢data] r,←'T2' desc RunVariations d1 d1 - dataplus←data+(?(≢data)/0)+¯11○(?(≢data)/0) ⍝ adding a number between (0,1) to data + dataplus←{data+1⊃⍵,data+2⊃⍵,data+3⊃⍵}{⍵ (?(≢⍵)/0) (¯11○(?(≢⍵)/0))}data ⍝ adding a number between (0,1) to data r,←'T3' desc Assert ((genCmplxFloor¨dataplus)≡⌊dataplus) ∨ (fr=2 ∧ case≡'Hcmplx') :EndFor :EndFor From 72692ba5fccf984757379aa2c1c1e2bef3bef688 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Fri, 7 Jul 2023 14:38:33 +0530 Subject: [PATCH 13/28] improve decimal cmplx number generator dfn --- tests/floor.apln | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index b2937e0..b7f1c5b 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -141,8 +141,9 @@ d1←data[?≢data] r,←'T2' desc RunVariations d1 d1 - dataplus←{data+1⊃⍵,data+2⊃⍵,data+3⊃⍵}{⍵ (?(≢⍵)/0) (¯11○(?(≢⍵)/0))}data ⍝ adding a number between (0,1) to data - r,←'T3' desc Assert ((genCmplxFloor¨dataplus)≡⌊dataplus) ∨ (fr=2 ∧ case≡'Hcmplx') + ⍝ adding a number between (0,1) to data making it a array of cmplx numbers of type 1J1 ¯1J1 1J¯1 ¯1J¯1 + dataplus←(data,data+2⊃⊣,data+2⊃⊣,data+(1⊃⊣)+2⊃⊣) (?0⍨¨data) (¯11○(?0⍨¨data)) + r,←'T3' desc Assert (genCmplxFloor¨dataplus)≡⌊dataplus :EndFor :EndFor :EndFor From 35237ac03bec2e36c589901e5a81af7b5f357a3c Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Fri, 7 Jul 2023 15:04:10 +0530 Subject: [PATCH 14/28] add basic ct tests --- tests/floor.apln | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/floor.apln b/tests/floor.apln index b7f1c5b..acce4dc 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -100,7 +100,7 @@ d1←data[?≢data] r,← 'T2' desc RunVariations (genFloor d1) d1 ⍝ generator func finds results on single element - dataplus←data+?(≢data)/0 ⍝ adding a number between (0,1) to data + dataplus←data+?0⍨¨data ⍝ adding a number between (0,1) to data r,← 'T3' desc Assert ((genFloor¨dataplus)≡⌊dataplus) ∨ (fr=1 ∧ case≡'Hfl') ⍝ genFloor fails for Hfl with ⎕fr=645 :If (⊂data)∊i1 i2 i3 @@ -112,6 +112,22 @@ halfLen←(¯1+≢data)÷2 r,← 'TDbl' desc RunVariations ({(⍵-0.5),0,-0.5+⍵}(halfLen↑data)) data ⍝ floor of dbl is removing the 0.5 from the number :EndIf + + ⍝ tests with comparision tolerance + almostd1←d1×1-fr⊃1E¯2×ct_default dct_default ⍝ infinitesimally close to d1 but smaller + :If ct ⍝ tolerant + :If (⊂data)∊Hdbl Hfl ⍝ bigger numbers + ⍝ Hdbl=Hdbl+1 with default CT, but not for DECF (similar for Hcmplx) + r,← 'CTDefault' desc Assert (((⌊d1)≡⌊(d1+1)) ∨ (fr=2 ∧ (case≡'Hdbl'))) + :Else ⍝ other than bigger numbers + r,← 'CTDefaultAlmost1' desc Assert (⌊d1)≡⌊almostd1 ⍝ No difference because tolerantly equal + :EndIf + :Else ⍝ exact + ⍝ d≠d+1 for all numeric types + r,← 'CTZero' desc Assert ((1+⌊d1)≡⌊d1+1) + + r,← 'CTDefaultAlmost1' desc Assert ((d1≤0)-⌊d1)≢⌊almostd1 ⍝ todo: can be changed to a better case + :EndIf :EndFor :EndFor :EndFor From 958250aa5ceab3fac1c22aba768c816e00f7d788 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Mon, 10 Jul 2023 19:38:02 +0530 Subject: [PATCH 15/28] add ct tests for cmplx --- tests/floor.apln | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/floor.apln b/tests/floor.apln index acce4dc..4ac7399 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -5,6 +5,12 @@ ⍝ Other approaches included using {⍵-(1|⍵)} but residue uses floor in its derivation so can be conflicting ⍝ Approach 2 was using binary conversion and stripping decimals similar to the string approach, but the sources use something similar ⍝ The string approach is good because it deals with floor in a very non-co-related way so it can never be clashing + ⍝ All cases: + ⍝ neg int juststrip + ⍝ 0 0 1 123.32→123 + ⍝ 0 1 1 123→123 + ⍝ 1 0 0 ¯123.32→¯124 + ⍝ 1 1 1 ¯123→¯123 genFloor←{ ⎕pp←34 ⍝ set to max as we are using strings, the execute and format primitives round the number to the ⎕pp value dotPos←⍸,'.'⍷⍕⍵ ⍝ convert num to string and get position of the decimal point @@ -13,6 +19,7 @@ } ⍝ genFloor←{(⍎(⍕⍵)↑⍨¯1+⍸,'.'⍷(⍕⍵))-(⍵<0)∧(~0∊⍴(⍸,'.'⍷(⍕⍵)))} + ⍝ Source: https://aplwiki.com/wiki/Complex_floor genCmplxFloor←{ r←9○⍵ i←11○⍵ @@ -100,7 +107,7 @@ d1←data[?≢data] r,← 'T2' desc RunVariations (genFloor d1) d1 ⍝ generator func finds results on single element - dataplus←data+?0⍨¨data ⍝ adding a number between (0,1) to data + dataplus←data+?0⍨¨data ⍝ adding a number between (0,1) to data r,← 'T3' desc Assert ((genFloor¨dataplus)≡⌊dataplus) ∨ (fr=1 ∧ case≡'Hfl') ⍝ genFloor fails for Hfl with ⎕fr=645 :If (⊂data)∊i1 i2 i3 @@ -160,6 +167,24 @@ ⍝ adding a number between (0,1) to data making it a array of cmplx numbers of type 1J1 ¯1J1 1J¯1 ¯1J¯1 dataplus←(data,data+2⊃⊣,data+2⊃⊣,data+(1⊃⊣)+2⊃⊣) (?0⍨¨data) (¯11○(?0⍨¨data)) r,←'T3' desc Assert (genCmplxFloor¨dataplus)≡⌊dataplus + + almostd1←d1×1-fr⊃1E¯3×ct_default dct_default ⍝ infinitesimally close to d1 but smaller + :If ct ⍝ tolerant + :If (⊂data)∊Hcmplx ⍝ bigger numbers + ⍝ Hdbl=Hdbl+1 with default CT, but not for DECF (similar for Hcmplx) + r,← 'CTDefault1' desc Assert (⌊d1)≡⌊(d1+1) + r,← 'CTDefault2' desc Assert (⌊d1)≡⌊(d1+0J1) + r,← 'CTDefault3' desc Assert (⌊d1)≡⌊(d1+1J1) + :Else ⍝ other than bigger numbers + r,← 'CTDefaultAlmost1' desc Assert (⌊d1)≡⌊almostd1 ⍝ No difference because tolerantly equal + :EndIf + :Else ⍝ exact + ⍝ d≠d+1 for all numeric types` + r,← 'CTZero1' desc Assert ((1+⌊d1)≡⌊d1+1) + r,← 'CTZero2' desc Assert ((0J1+⌊d1)≡⌊d1+0J1) + r,← 'CTZero3' desc Assert ((1J1+⌊d1)≡⌊d1+1J1) + r,← 'CTZeroAlmost1' desc Assert (⌊d1)≡⌊almostd1 + :EndIf :EndFor :EndFor :EndFor From 6c80d7355514e16eb58384fefa346f861cfa2706 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 13 Jul 2023 15:27:07 +0530 Subject: [PATCH 16/28] improve ct tests for floor --- tests/floor.apln | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index 4ac7399..1764b6a 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -124,16 +124,17 @@ almostd1←d1×1-fr⊃1E¯2×ct_default dct_default ⍝ infinitesimally close to d1 but smaller :If ct ⍝ tolerant :If (⊂data)∊Hdbl Hfl ⍝ bigger numbers - ⍝ Hdbl=Hdbl+1 with default CT, but not for DECF (similar for Hcmplx) - r,← 'CTDefault' desc Assert (((⌊d1)≡⌊(d1+1)) ∨ (fr=2 ∧ (case≡'Hdbl'))) + ⍝ Hdbl=Hdbl+1 with default CT, but not for DECF + r,← 'CTDefault1' desc Assert (((⌊d1)≡⌊(d1+1)) ∨ (fr=2 ∧ (case≡'Hdbl'))) :Else ⍝ other than bigger numbers - r,← 'CTDefaultAlmost1' desc Assert (⌊d1)≡⌊almostd1 ⍝ No difference because tolerantly equal + r,← 'CTDefault2' desc Assert ((⌊d1)≢⌊(d1+1)) + r,← 'CTDefaultAlmost' desc Assert ({(⌊=⊢)⍵:⍵⋄⍵-0.5}d1)≡⌊almostd1 ⍝ d1 and almostd1 are tolerantly equal, condition added to get integer :EndIf :Else ⍝ exact ⍝ d≠d+1 for all numeric types r,← 'CTZero' desc Assert ((1+⌊d1)≡⌊d1+1) - r,← 'CTDefaultAlmost1' desc Assert ((d1≤0)-⌊d1)≢⌊almostd1 ⍝ todo: can be changed to a better case + r,← 'CTZeroAlmost1' desc Assert (((d1-{(⌊=⊢)⍵:⍵≥0⋄0.5}d1)≡⌊almostd1) ∨ (fr=1 ∧ (case≡'Hfl'))) ⍝ Floor is the integer lesser than the number with no tolerance :EndIf :EndFor :EndFor @@ -168,9 +169,11 @@ dataplus←(data,data+2⊃⊣,data+2⊃⊣,data+(1⊃⊣)+2⊃⊣) (?0⍨¨data) (¯11○(?0⍨¨data)) r,←'T3' desc Assert (genCmplxFloor¨dataplus)≡⌊dataplus - almostd1←d1×1-fr⊃1E¯3×ct_default dct_default ⍝ infinitesimally close to d1 but smaller - :If ct ⍝ tolerant - :If (⊂data)∊Hcmplx ⍝ bigger numbers + ⍝ TODO + ⍝ almostd1←d1×1-fr⊃1E¯3×ct_default dct_default ⍝ infinitesimally close to d1 but smaller + almostd1← d1×1-1E¯15 + :If ct ∧ (fr≡1) ⍝ tolerant + :If (case≡'Hcmplx') ⍝ bigger numbers ⍝ Hdbl=Hdbl+1 with default CT, but not for DECF (similar for Hcmplx) r,← 'CTDefault1' desc Assert (⌊d1)≡⌊(d1+1) r,← 'CTDefault2' desc Assert (⌊d1)≡⌊(d1+0J1) @@ -183,7 +186,7 @@ r,← 'CTZero1' desc Assert ((1+⌊d1)≡⌊d1+1) r,← 'CTZero2' desc Assert ((0J1+⌊d1)≡⌊d1+0J1) r,← 'CTZero3' desc Assert ((1J1+⌊d1)≡⌊d1+1J1) - r,← 'CTZeroAlmost1' desc Assert (⌊d1)≡⌊almostd1 + ⍝ r,← 'CTZeroAlmost1' desc Assert (genCmplxFloor d1)≡⌊almostd1 :EndIf :EndFor :EndFor From 86ee7f47ebbf1887795310df6fd2f25a2d1af9dc Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 13 Jul 2023 15:59:13 +0530 Subject: [PATCH 17/28] fix data generation for dataplus in cmplxfloor --- tests/floor.apln | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index 1764b6a..8763874 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -155,7 +155,7 @@ :For ct :In 0 1 (⎕CT ⎕DCT)←ct × ct_default dct_default ⍝ set comparision tolerance - :For fr :In 2 1 + :For fr :In 1 2 ⎕FR←fr⊃fr_dbl fr_decf :For case :In 'cmplx' 'Hcmplx' data←⍎case @@ -166,12 +166,13 @@ r,←'T2' desc RunVariations d1 d1 ⍝ adding a number between (0,1) to data making it a array of cmplx numbers of type 1J1 ¯1J1 1J¯1 ¯1J¯1 - dataplus←(data,data+2⊃⊣,data+2⊃⊣,data+(1⊃⊣)+2⊃⊣) (?0⍨¨data) (¯11○(?0⍨¨data)) - r,←'T3' desc Assert (genCmplxFloor¨dataplus)≡⌊dataplus + dataplus←(data,(data+2⊃⊣),(data+2⊃⊣),(data+(1⊃⊣)+2⊃⊣)) (?0⍨¨data) (¯11○(?0⍨¨data)) + r,←'T3' desc Assert ((genCmplxFloor¨dataplus)≡⌊dataplus) ∨ ((fr=2) ∧ (case≡'Hcmplx')) ⍝ TODO - ⍝ almostd1←d1×1-fr⊃1E¯3×ct_default dct_default ⍝ infinitesimally close to d1 but smaller - almostd1← d1×1-1E¯15 + almostd1←d1×1-fr⊃1E¯0×ct_default dct_default ⍝ infinitesimally close to d1 but smaller + ⍝ ⎕←fr⊃1E¯1×ct_default dct_default + ⍝ almostd1← d1-1E¯15 :If ct ∧ (fr≡1) ⍝ tolerant :If (case≡'Hcmplx') ⍝ bigger numbers ⍝ Hdbl=Hdbl+1 with default CT, but not for DECF (similar for Hcmplx) @@ -186,7 +187,7 @@ r,← 'CTZero1' desc Assert ((1+⌊d1)≡⌊d1+1) r,← 'CTZero2' desc Assert ((0J1+⌊d1)≡⌊d1+0J1) r,← 'CTZero3' desc Assert ((1J1+⌊d1)≡⌊d1+1J1) - ⍝ r,← 'CTZeroAlmost1' desc Assert (genCmplxFloor d1)≡⌊almostd1 + r,← 'CTZeroAlmost1' desc Assert ((((genCmplxFloor d1)≡⌊almostd1) ∨ (fr=1) ∧ (case≡'Hcmplx'))) :EndIf :EndFor :EndFor From 6d195ac3202b048f56833545907b2b75f8ab3b68 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 13 Jul 2023 16:07:20 +0530 Subject: [PATCH 18/28] ct tests for cmplx work --- tests/floor.apln | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index 8763874..96f264c 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -169,9 +169,7 @@ dataplus←(data,(data+2⊃⊣),(data+2⊃⊣),(data+(1⊃⊣)+2⊃⊣)) (?0⍨¨data) (¯11○(?0⍨¨data)) r,←'T3' desc Assert ((genCmplxFloor¨dataplus)≡⌊dataplus) ∨ ((fr=2) ∧ (case≡'Hcmplx')) - ⍝ TODO - almostd1←d1×1-fr⊃1E¯0×ct_default dct_default ⍝ infinitesimally close to d1 but smaller - ⍝ ⎕←fr⊃1E¯1×ct_default dct_default + almostd1←d1×1-fr⊃ct_default dct_default ⍝ infinitesimally close to d1 but smaller ⍝ almostd1← d1-1E¯15 :If ct ∧ (fr≡1) ⍝ tolerant :If (case≡'Hcmplx') ⍝ bigger numbers @@ -180,14 +178,14 @@ r,← 'CTDefault2' desc Assert (⌊d1)≡⌊(d1+0J1) r,← 'CTDefault3' desc Assert (⌊d1)≡⌊(d1+1J1) :Else ⍝ other than bigger numbers - r,← 'CTDefaultAlmost1' desc Assert (⌊d1)≡⌊almostd1 ⍝ No difference because tolerantly equal + r,← 'CTDefaultAlmost1' desc Assert (d1)≡⌊almostd1 ⍝ No difference because tolerantly equal :EndIf :Else ⍝ exact ⍝ d≠d+1 for all numeric types` r,← 'CTZero1' desc Assert ((1+⌊d1)≡⌊d1+1) r,← 'CTZero2' desc Assert ((0J1+⌊d1)≡⌊d1+0J1) r,← 'CTZero3' desc Assert ((1J1+⌊d1)≡⌊d1+1J1) - r,← 'CTZeroAlmost1' desc Assert ((((genCmplxFloor d1)≡⌊almostd1) ∨ (fr=1) ∧ (case≡'Hcmplx'))) + r,← 'CTZeroAlmost1' desc Assert ((d1≡⌊almostd1) ∨ fr) ⍝ todo: not fully satisfied, needs more investigation :EndIf :EndFor :EndFor From 67286cfcfb443b22a2355026de49b0c017e99cf2 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Tue, 18 Jul 2023 13:03:55 +0530 Subject: [PATCH 19/28] refactor --- tests/floor.apln | 59 +++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index 96f264c..b0d3203 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -6,11 +6,11 @@ ⍝ Approach 2 was using binary conversion and stripping decimals similar to the string approach, but the sources use something similar ⍝ The string approach is good because it deals with floor in a very non-co-related way so it can never be clashing ⍝ All cases: - ⍝ neg int juststrip - ⍝ 0 0 1 123.32→123 - ⍝ 0 1 1 123→123 - ⍝ 1 0 0 ¯123.32→¯124 - ⍝ 1 1 1 ¯123→¯123 + ⍝ neg dotPos juststrip + ⍝ 0 1 1 123.32→123 + ⍝ 0 0 1 123→123 + ⍝ 1 1 0 ¯123.32→¯124 + ⍝ 1 0 1 ¯123→¯123 genFloor←{ ⎕pp←34 ⍝ set to max as we are using strings, the execute and format primitives round the number to the ⎕pp value dotPos←⍸,'.'⍷⍕⍵ ⍝ convert num to string and get position of the decimal point @@ -66,16 +66,17 @@ i1←{⍵,0,-⍵}⍳120 ⍝ 83: 8 bits signed integer i2←{⍵,0,-⍵}10000+⍳1000 ⍝ 163: 16 bits signed integer i3←{⍵,0,-⍵}100000+⍳100 ⍝ 323: 32 bits signed integer + dbl←{⍵,0,-⍵}1000.5+⍳100 ⍝ 645: 64 bits Floating - ⍝ Hdbl is 645 but larger numbers - Hdbl←{⍵,-⍵}1E14+(2×⍳50) - ⍝ Hfl is 1287 but larger numbers + Hdbl←{⍵,-⍵}1E14+(2×⍳50) ⍝ Hdbl is 645 closer to the default CT + ⎕FR←fr_decf ⍝ use ⎕FR=1287 fl←{⍵,0,-⍵}1000.5+⍳100 ⍝ 1287: 128 bits Decimal - Hfl←{⍵,-⍵}2E29+(1E16×⍳10) ⍝ 1287 but larger numbers + Hfl←{⍵,-⍵}2E29+(1E16×⍳10) ⍝ Hfl is 1287 closer to the default DCT ⎕FR←fr_dbl ⍝ revert ⎕FR=645 + cmplx←{(-⍵),⍵,0,(+⍵),(-+⍵)}(0J1×⍳100)+⌽⍳100 ⍝ 1289: 128 bits Complex - Hcmplx←{(-⍵),⍵,(+⍵),(-+⍵)}(1E14J1E14×⍳20) ⍝ 1289 but larger numbers + Hcmplx←{(-⍵),⍵,(+⍵),(-+⍵)}(1E14J1E14×⍳20) ⍝ 1289 closer to the default CT r←⍬ testDesc←{'for ',case,{0∊⍴case2:'',⍵⋄' , ', case2,⍵},' & ⎕CT ⎕DCT:',⎕CT,⎕DCT, '& ⎕FR:', ⎕FR} @@ -83,20 +84,15 @@ :For ct :In 0 1 (⎕CT ⎕DCT)←ct × ct_default dct_default ⍝ set comparision tolerance :For fr :In 2 1 - ⎕FR←fr⊃fr_dbl fr_decf - :For case :In 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' + ⎕FR←fr⊃fr_dbl fr_decf ⍝ set type of floating-point computations + :For case :In 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' data←⍎case ⍝ Cross type tests - :For case2 :In 'i1' 'i2' 'i3' 'dbl' 'fl' + :For case2 :In 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' data2←⍎case2 - :If (⊂data)∊cmplx Hdbl Hfl Hcmplx - :Continue - :EndIf desc←testDesc⍬ - :If (data≡data2) - :Continue - :EndIf - r,← 'TCross1' desc RunVariations (genFloor¨ data,data2) (data,data2) + r,← 'TCross1' desc RunVariations (genFloor¨ data,data2) (data,data2) ⍝ concat data and data2 + r,← 'TCross2' desc RunVariations (genFloor¨ data2,data) (data2,data) ⍝ concat data and data2 reserved :EndFor case2←⍬ ⍝ disposing case2 for testDesc @@ -113,9 +109,7 @@ :If (⊂data)∊i1 i2 i3 r,← 'TInt1' desc RunVariations data data ⍝ floor of integers will always be floor r,← 'TInt2' desc RunVariations data dataplus ⍝ floor of integers will always be floor - :EndIf - - :If case≡'dbl' + :ElseIf (⊂data)∊dbl fl halfLen←(¯1+≢data)÷2 r,← 'TDbl' desc RunVariations ({(⍵-0.5),0,-0.5+⍵}(halfLen↑data)) data ⍝ floor of dbl is removing the 0.5 from the number :EndIf @@ -133,7 +127,6 @@ :Else ⍝ exact ⍝ d≠d+1 for all numeric types r,← 'CTZero' desc Assert ((1+⌊d1)≡⌊d1+1) - r,← 'CTZeroAlmost1' desc Assert (((d1-{(⌊=⊢)⍵:⍵≥0⋄0.5}d1)≡⌊almostd1) ∨ (fr=1 ∧ (case≡'Hfl'))) ⍝ Floor is the integer lesser than the number with no tolerance :EndIf :EndFor @@ -148,7 +141,7 @@ fr_decf←1287 cmplx←{(-⍵),⍵,0,(+⍵),(-+⍵)}(0J1×⍳100)+⌽⍳100 ⍝ 1289: 128 bits Complex - Hcmplx←{(-⍵),⍵,(+⍵),(-+⍵)}(1E14J1E14×⍳20) ⍝ 1289 but larger numbers + Hcmplx←{(-⍵),⍵,(+⍵),(-+⍵)}(1E14J1E14×⍳20) ⍝ 1289 closer to the default CT r←⍬ testDesc←{'for ',case,' & ⎕CT ⎕DCT:',⎕CT,⎕DCT, '& ⎕FR:', ⎕FR} @@ -167,25 +160,25 @@ ⍝ adding a number between (0,1) to data making it a array of cmplx numbers of type 1J1 ¯1J1 1J¯1 ¯1J¯1 dataplus←(data,(data+2⊃⊣),(data+2⊃⊣),(data+(1⊃⊣)+2⊃⊣)) (?0⍨¨data) (¯11○(?0⍨¨data)) - r,←'T3' desc Assert ((genCmplxFloor¨dataplus)≡⌊dataplus) ∨ ((fr=2) ∧ (case≡'Hcmplx')) + r,←'T3' desc Assert ((genCmplxFloor¨dataplus)≡⌊dataplus) ∨ ((fr=2) ∧ case≡'Hcmplx') almostd1←d1×1-fr⊃ct_default dct_default ⍝ infinitesimally close to d1 but smaller ⍝ almostd1← d1-1E¯15 :If ct ∧ (fr≡1) ⍝ tolerant :If (case≡'Hcmplx') ⍝ bigger numbers ⍝ Hdbl=Hdbl+1 with default CT, but not for DECF (similar for Hcmplx) - r,← 'CTDefault1' desc Assert (⌊d1)≡⌊(d1+1) - r,← 'CTDefault2' desc Assert (⌊d1)≡⌊(d1+0J1) - r,← 'CTDefault3' desc Assert (⌊d1)≡⌊(d1+1J1) + r,← 'CTDefault1' desc Assert (⌊d1)≡⌊d1+1 + r,← 'CTDefault2' desc Assert (⌊d1)≡⌊d1+0J1 + r,← 'CTDefault3' desc Assert (⌊d1)≡⌊d1+1J1 :Else ⍝ other than bigger numbers r,← 'CTDefaultAlmost1' desc Assert (d1)≡⌊almostd1 ⍝ No difference because tolerantly equal :EndIf :Else ⍝ exact ⍝ d≠d+1 for all numeric types` - r,← 'CTZero1' desc Assert ((1+⌊d1)≡⌊d1+1) - r,← 'CTZero2' desc Assert ((0J1+⌊d1)≡⌊d1+0J1) - r,← 'CTZero3' desc Assert ((1J1+⌊d1)≡⌊d1+1J1) - r,← 'CTZeroAlmost1' desc Assert ((d1≡⌊almostd1) ∨ fr) ⍝ todo: not fully satisfied, needs more investigation + r,← 'CTZero1' desc Assert (1+⌊d1)≡⌊d1+1 + r,← 'CTZero2' desc Assert (0J1+⌊d1)≡⌊d1+0J1 + r,← 'CTZero3' desc Assert (1J1+⌊d1)≡⌊d1+1J1 + r,← 'CTZeroAlmost1' desc Assert (d1≡⌊almostd1) ∨ (fr=1) ⍝ todo: not fully satisfied, needs more investigation :EndIf :EndFor :EndFor From 882df50fc6250a678076270133004f60f9f50746 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Tue, 18 Jul 2023 17:07:38 +0530 Subject: [PATCH 20/28] add tests for numbers between -1 and 1 --- tests/floor.apln | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index b0d3203..e2a5028 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -73,6 +73,7 @@ ⎕FR←fr_decf ⍝ use ⎕FR=1287 fl←{⍵,0,-⍵}1000.5+⍳100 ⍝ 1287: 128 bits Decimal Hfl←{⍵,-⍵}2E29+(1E16×⍳10) ⍝ Hfl is 1287 closer to the default DCT + Sfl←{⍵,-⍵}(⍳10)×1E¯1 ⍝ 1287: 1287 between (-1,1) ⎕FR←fr_dbl ⍝ revert ⎕FR=645 cmplx←{(-⍵),⍵,0,(+⍵),(-+⍵)}(0J1×⍳100)+⌽⍳100 ⍝ 1289: 128 bits Complex @@ -85,7 +86,7 @@ (⎕CT ⎕DCT)←ct × ct_default dct_default ⍝ set comparision tolerance :For fr :In 2 1 ⎕FR←fr⊃fr_dbl fr_decf ⍝ set type of floating-point computations - :For case :In 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' + :For case :In 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' 'Sfl' data←⍎case ⍝ Cross type tests :For case2 :In 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' @@ -122,12 +123,12 @@ r,← 'CTDefault1' desc Assert (((⌊d1)≡⌊(d1+1)) ∨ (fr=2 ∧ (case≡'Hdbl'))) :Else ⍝ other than bigger numbers r,← 'CTDefault2' desc Assert ((⌊d1)≢⌊(d1+1)) - r,← 'CTDefaultAlmost' desc Assert ({(⌊=⊢)⍵:⍵⋄⍵-0.5}d1)≡⌊almostd1 ⍝ d1 and almostd1 are tolerantly equal, condition added to get integer + r,← 'CTDefaultAlmost' desc Assert (({(⌊=⊢)⍵:⍵⋄⍵-0.5}d1)≡⌊almostd1) ∨ (case≡'Sfl') ⍝ d1 and almostd1 are tolerantly equal, condition added to get integer :EndIf :Else ⍝ exact ⍝ d≠d+1 for all numeric types r,← 'CTZero' desc Assert ((1+⌊d1)≡⌊d1+1) - r,← 'CTZeroAlmost1' desc Assert (((d1-{(⌊=⊢)⍵:⍵≥0⋄0.5}d1)≡⌊almostd1) ∨ (fr=1 ∧ (case≡'Hfl'))) ⍝ Floor is the integer lesser than the number with no tolerance + r,← 'CTZeroAlmost1' desc Assert (((d1-{(⌊=⊢)⍵:⍵≥0⋄0.5}d1)≡⌊almostd1) ∨ (fr=1 ∧ (case≡'Hfl')) ∨ (case≡'Sfl')) ⍝ Floor is the integer lesser than the number with no tolerance :EndIf :EndFor :EndFor From a6c443a40717f6e932f1e022a6f080758921b5c9 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Tue, 18 Jul 2023 17:40:02 +0530 Subject: [PATCH 21/28] localize vars --- tests/floor.apln | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index e2a5028..f47323c 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -56,7 +56,7 @@ tRes,←('ShapeW0',tID) tCmt Assert (shapeW0⍴0) ≡ actualRS ∇ - ∇ r←test_floor ;r;data;dataplus;case;data2;case2;type;bool;i1;i2;i3;dbl;fl;cmplx;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;halfLen;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc + ∇ r←test_floor ;r;data;dataplus;case;data2;case2;type;bool;i1;i2;i3;dbl;fl;Sfl;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;halfLen;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc ct_default←1E¯14 dct_default←1E¯28 fr_dbl←645 @@ -76,9 +76,6 @@ Sfl←{⍵,-⍵}(⍳10)×1E¯1 ⍝ 1287: 1287 between (-1,1) ⎕FR←fr_dbl ⍝ revert ⎕FR=645 - cmplx←{(-⍵),⍵,0,(+⍵),(-+⍵)}(0J1×⍳100)+⌽⍳100 ⍝ 1289: 128 bits Complex - Hcmplx←{(-⍵),⍵,(+⍵),(-+⍵)}(1E14J1E14×⍳20) ⍝ 1289 closer to the default CT - r←⍬ testDesc←{'for ',case,{0∊⍴case2:'',⍵⋄' , ', case2,⍵},' & ⎕CT ⎕DCT:',⎕CT,⎕DCT, '& ⎕FR:', ⎕FR} @@ -135,7 +132,7 @@ :EndFor ∇ - ∇ r←test_cmplx_floor ;cmplx;Hcmplx;magCmplx;d1;case;data;testDesc;desc;ct_default;dct_default;fr_dbl;fr_decf + ∇ r←test_cmplx_floor ;cmplx;Hcmplx;dataplus;d1;almostd1;case;data;testDesc;desc;ct;fr;ct_default;dct_default;fr_dbl;fr_decf ct_default←1E¯14 dct_default←1E¯28 fr_dbl←645 From 040d84b9e835ff45ab512402f6b703f3b76b9c35 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Wed, 19 Jul 2023 11:40:04 +0530 Subject: [PATCH 22/28] refactor --- tests/floor.apln | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index f47323c..4bd2302 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -1,6 +1,7 @@ :Namespace floor Assert←#.unittest.Assert + ⍝ Generator function for floor ⍝ Using strings to calculate floor of a number ⍝ Other approaches included using {⍵-(1|⍵)} but residue uses floor in its derivation so can be conflicting ⍝ Approach 2 was using binary conversion and stripping decimals similar to the string approach, but the sources use something similar @@ -19,7 +20,8 @@ } ⍝ genFloor←{(⍎(⍕⍵)↑⍨¯1+⍸,'.'⍷(⍕⍵))-(⍵<0)∧(~0∊⍴(⍸,'.'⍷(⍕⍵)))} - ⍝ Source: https://aplwiki.com/wiki/Complex_floor + ⍝ Generator function for complex floor + ⍝ interpreted from: https://aplwiki.com/wiki/Complex_floor genCmplxFloor←{ r←9○⍵ i←11○⍵ @@ -45,18 +47,18 @@ actualRE←⌊(0⍴p) ⍝ 0 in the shape means we have no elements in the array, i.e. it's empty. tRes,←('Empty',tID) tCmt Assert ⍬≡actualRE - ⍝ different shapes + ⍝ randomize shape of expectedR and p shape←?(?4)/4 - actualRS←⌊(shape⍴actualR) + actualRS←⌊shape⍴p ⍝ change shape and then evaluate tRes,←('Multiple',tID) tCmt Assert (shape⍴expectedR)≡actualRS - ⍝ ⍝ different shapes with 0 in shape + ⍝ randomize shapes with 0 a random position of shape shape shapeW0←(0@(?(≢shape)))shape - actualRS←⌊(shapeW0⍴p) - tRes,←('ShapeW0',tID) tCmt Assert (shapeW0⍴0) ≡ actualRS + actualRS←⌊shapeW0⍴p + tRes,←('ShapeW0',tID) tCmt Assert (shapeW0⍴0)≡actualRS ∇ - ∇ r←test_floor ;r;data;dataplus;case;data2;case2;type;bool;i1;i2;i3;dbl;fl;Sfl;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;halfLen;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc + ∇ r←test_floor ;r;data;dataplus;case;data2;case2;type;zero;bool;i1;i2;i3;dbl;fl;Hdbl;Hfl;Hcmplx;d1;d2;almostd1;halfLen;ct;fr;⎕CT;⎕DCT;⎕FR;ct_default;dct_default;fr_dbl;fr_decf;testDesc;desc ct_default←1E¯14 dct_default←1E¯28 fr_dbl←645 @@ -71,9 +73,9 @@ Hdbl←{⍵,-⍵}1E14+(2×⍳50) ⍝ Hdbl is 645 closer to the default CT ⎕FR←fr_decf ⍝ use ⎕FR=1287 + zero←,0 ⍝ DECF 0 is required for a special case at apl/allos/src/arith_su.c#L2875 fl←{⍵,0,-⍵}1000.5+⍳100 ⍝ 1287: 128 bits Decimal Hfl←{⍵,-⍵}2E29+(1E16×⍳10) ⍝ Hfl is 1287 closer to the default DCT - Sfl←{⍵,-⍵}(⍳10)×1E¯1 ⍝ 1287: 1287 between (-1,1) ⎕FR←fr_dbl ⍝ revert ⎕FR=645 r←⍬ @@ -83,33 +85,33 @@ (⎕CT ⎕DCT)←ct × ct_default dct_default ⍝ set comparision tolerance :For fr :In 2 1 ⎕FR←fr⊃fr_dbl fr_decf ⍝ set type of floating-point computations - :For case :In 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' 'Sfl' + :For case :In 'zero' 'bool' 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' data←⍎case ⍝ Cross type tests - :For case2 :In 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' + :For case2 :In 'bool' 'i1' 'i2' 'i3' 'dbl' 'fl' 'Hdbl' 'Hfl' data2←⍎case2 desc←testDesc⍬ r,← 'TCross1' desc RunVariations (genFloor¨ data,data2) (data,data2) ⍝ concat data and data2 - r,← 'TCross2' desc RunVariations (genFloor¨ data2,data) (data2,data) ⍝ concat data and data2 reserved + r,← 'TCross2' desc RunVariations (genFloor¨ data2,data) (data2,data) ⍝ concat data and data2 reversed :EndFor case2←⍬ ⍝ disposing case2 for testDesc desc←testDesc⍬ - r,← 'T1' desc RunVariations (genFloor¨data) data ⍝ generator func finds results on array + r,← 'T1' desc RunVariations (genFloor¨data) data ⍝ generator func finds results on array d1←data[?≢data] - r,← 'T2' desc RunVariations (genFloor d1) d1 ⍝ generator func finds results on single element + r,← 'T2' desc RunVariations (genFloor d1) d1 ⍝ generator func finds results on single element - dataplus←data+?0⍨¨data ⍝ adding a number between (0,1) to data - r,← 'T3' desc Assert ((genFloor¨dataplus)≡⌊dataplus) ∨ (fr=1 ∧ case≡'Hfl') ⍝ genFloor fails for Hfl with ⎕fr=645 + dataplus←data+?0⍨¨data ⍝ adding a number between (0,1) to data + r,← 'T3' desc Assert ((genFloor¨dataplus)≡⌊dataplus) ∨ (fr=1 ∧ case≡'Hfl') ⍝ ⎕fr=645 and Hfl is skipped because of rounding off :If (⊂data)∊i1 i2 i3 - r,← 'TInt1' desc RunVariations data data ⍝ floor of integers will always be floor - r,← 'TInt2' desc RunVariations data dataplus ⍝ floor of integers will always be floor + r,← 'TInt1' desc RunVariations data data ⍝ floor of integers will always be floor + r,← 'TInt2' desc RunVariations data dataplus ⍝ floor of integers will always be floor :ElseIf (⊂data)∊dbl fl halfLen←(¯1+≢data)÷2 - r,← 'TDbl' desc RunVariations ({(⍵-0.5),0,-0.5+⍵}(halfLen↑data)) data ⍝ floor of dbl is removing the 0.5 from the number + r,← 'TDbl' desc RunVariations ({(⍵-0.5),0,-0.5+⍵}(halfLen↑data)) data ⍝ floor of dbl is removing the 0.5 from the number :EndIf ⍝ tests with comparision tolerance @@ -119,13 +121,13 @@ ⍝ Hdbl=Hdbl+1 with default CT, but not for DECF r,← 'CTDefault1' desc Assert (((⌊d1)≡⌊(d1+1)) ∨ (fr=2 ∧ (case≡'Hdbl'))) :Else ⍝ other than bigger numbers - r,← 'CTDefault2' desc Assert ((⌊d1)≢⌊(d1+1)) - r,← 'CTDefaultAlmost' desc Assert (({(⌊=⊢)⍵:⍵⋄⍵-0.5}d1)≡⌊almostd1) ∨ (case≡'Sfl') ⍝ d1 and almostd1 are tolerantly equal, condition added to get integer + r,← 'CTDefault2' desc Assert ((⌊d1)≢⌊(d1+1)) ⍝ not tolerantly equal for other numbers + r,← 'CTDefaultAlmost' desc Assert (({(⌊=⊢)⍵:⍵⋄⍵-0.5}d1)≡⌊almostd1) ⍝ d1 and almostd1 are tolerantly equal, condition added to get integer :EndIf :Else ⍝ exact ⍝ d≠d+1 for all numeric types r,← 'CTZero' desc Assert ((1+⌊d1)≡⌊d1+1) - r,← 'CTZeroAlmost1' desc Assert (((d1-{(⌊=⊢)⍵:⍵≥0⋄0.5}d1)≡⌊almostd1) ∨ (fr=1 ∧ (case≡'Hfl')) ∨ (case≡'Sfl')) ⍝ Floor is the integer lesser than the number with no tolerance + r,← 'CTZeroAlmost1' desc Assert (((d1-{(⌊=⊢)⍵:⍵>0⋄0.5}d1)≡⌊almostd1) ∨ (fr=1 ∧ (case≡'Hfl'))) ⍝ floor is the integer lesser than the number with no tolerance :EndIf :EndFor :EndFor @@ -158,10 +160,9 @@ ⍝ adding a number between (0,1) to data making it a array of cmplx numbers of type 1J1 ¯1J1 1J¯1 ¯1J¯1 dataplus←(data,(data+2⊃⊣),(data+2⊃⊣),(data+(1⊃⊣)+2⊃⊣)) (?0⍨¨data) (¯11○(?0⍨¨data)) - r,←'T3' desc Assert ((genCmplxFloor¨dataplus)≡⌊dataplus) ∨ ((fr=2) ∧ case≡'Hcmplx') + r,←'T3' desc Assert ((genCmplxFloor¨dataplus)≡⌊dataplus) ∨ ((fr=2) ∧ case≡'Hcmplx') ⍝ DECF Hcmplx is skipped because of rounding off almostd1←d1×1-fr⊃ct_default dct_default ⍝ infinitesimally close to d1 but smaller - ⍝ almostd1← d1-1E¯15 :If ct ∧ (fr≡1) ⍝ tolerant :If (case≡'Hcmplx') ⍝ bigger numbers ⍝ Hdbl=Hdbl+1 with default CT, but not for DECF (similar for Hcmplx) @@ -169,14 +170,14 @@ r,← 'CTDefault2' desc Assert (⌊d1)≡⌊d1+0J1 r,← 'CTDefault3' desc Assert (⌊d1)≡⌊d1+1J1 :Else ⍝ other than bigger numbers - r,← 'CTDefaultAlmost1' desc Assert (d1)≡⌊almostd1 ⍝ No difference because tolerantly equal + r,← 'CTDefaultAlmost1' desc Assert d1≡⌊almostd1 ⍝ No difference because tolerantly equal :EndIf :Else ⍝ exact - ⍝ d≠d+1 for all numeric types` + ⍝ d≠d+1 for all numeric types with cmplx variations r,← 'CTZero1' desc Assert (1+⌊d1)≡⌊d1+1 r,← 'CTZero2' desc Assert (0J1+⌊d1)≡⌊d1+0J1 r,← 'CTZero3' desc Assert (1J1+⌊d1)≡⌊d1+1J1 - r,← 'CTZeroAlmost1' desc Assert (d1≡⌊almostd1) ∨ (fr=1) ⍝ todo: not fully satisfied, needs more investigation + r,← 'CTZeroAlmost1' desc Assert (d1≡⌊almostd1) ∨ (fr=1) ⍝ todo: not fully sure if this is the right way :EndIf :EndFor :EndFor From 355474adc1d9089b26500be66c0a709c4058d5d5 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Wed, 19 Jul 2023 11:42:11 +0530 Subject: [PATCH 23/28] fix test names --- tests/floor.apln | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index 4bd2302..57f190e 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -127,7 +127,7 @@ :Else ⍝ exact ⍝ d≠d+1 for all numeric types r,← 'CTZero' desc Assert ((1+⌊d1)≡⌊d1+1) - r,← 'CTZeroAlmost1' desc Assert (((d1-{(⌊=⊢)⍵:⍵>0⋄0.5}d1)≡⌊almostd1) ∨ (fr=1 ∧ (case≡'Hfl'))) ⍝ floor is the integer lesser than the number with no tolerance + r,← 'CTZeroAlmost' desc Assert (((d1-{(⌊=⊢)⍵:⍵>0⋄0.5}d1)≡⌊almostd1) ∨ (fr=1 ∧ (case≡'Hfl'))) ⍝ floor is the integer lesser than the number with no tolerance :EndIf :EndFor :EndFor @@ -170,14 +170,14 @@ r,← 'CTDefault2' desc Assert (⌊d1)≡⌊d1+0J1 r,← 'CTDefault3' desc Assert (⌊d1)≡⌊d1+1J1 :Else ⍝ other than bigger numbers - r,← 'CTDefaultAlmost1' desc Assert d1≡⌊almostd1 ⍝ No difference because tolerantly equal + r,← 'CTDefaultAlmost' desc Assert d1≡⌊almostd1 ⍝ No difference because tolerantly equal :EndIf :Else ⍝ exact ⍝ d≠d+1 for all numeric types with cmplx variations r,← 'CTZero1' desc Assert (1+⌊d1)≡⌊d1+1 r,← 'CTZero2' desc Assert (0J1+⌊d1)≡⌊d1+0J1 r,← 'CTZero3' desc Assert (1J1+⌊d1)≡⌊d1+1J1 - r,← 'CTZeroAlmost1' desc Assert (d1≡⌊almostd1) ∨ (fr=1) ⍝ todo: not fully sure if this is the right way + r,← 'CTZeroAlmost' desc Assert (d1≡⌊almostd1) ∨ (fr=1) ⍝ todo: not fully sure if this is the right way :EndIf :EndFor :EndFor From 3598fc08b957838ba9fb085059e20c8d2bba9e61 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 20 Jul 2023 10:21:00 +0530 Subject: [PATCH 24/28] add scalar tests as a variations instead of a separate test --- tests/floor.apln | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index 57f190e..b9d4f4c 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -43,6 +43,13 @@ actualR←⌊p tRes,←tData Assert expectedR≡actualR + ⍝ scalar + rand←?≢p + trimmedp←rand↓p ⍝ so that not always the first is selected + shape←⍬ ⍝ scalar shape + actualRS←⌊shape⍴trimmedp + tRes,←('Scalar',tID) tCmt Assert (shape⍴rand↓expectedR)≡actualRS + ⍝ empty actualRE←⌊(0⍴p) ⍝ 0 in the shape means we have no elements in the array, i.e. it's empty. tRes,←('Empty',tID) tCmt Assert ⍬≡actualRE @@ -100,11 +107,8 @@ r,← 'T1' desc RunVariations (genFloor¨data) data ⍝ generator func finds results on array - d1←data[?≢data] - r,← 'T2' desc RunVariations (genFloor d1) d1 ⍝ generator func finds results on single element - dataplus←data+?0⍨¨data ⍝ adding a number between (0,1) to data - r,← 'T3' desc Assert ((genFloor¨dataplus)≡⌊dataplus) ∨ (fr=1 ∧ case≡'Hfl') ⍝ ⎕fr=645 and Hfl is skipped because of rounding off + r,← 'T2' desc Assert ((genFloor¨dataplus)≡⌊dataplus) ∨ (fr=1 ∧ case≡'Hfl') ⍝ ⎕fr=645 and Hfl is skipped because of rounding off :If (⊂data)∊i1 i2 i3 r,← 'TInt1' desc RunVariations data data ⍝ floor of integers will always be floor @@ -115,6 +119,7 @@ :EndIf ⍝ tests with comparision tolerance + d1←data[?≢data] almostd1←d1×1-fr⊃1E¯2×ct_default dct_default ⍝ infinitesimally close to d1 but smaller :If ct ⍝ tolerant :If (⊂data)∊Hdbl Hfl ⍝ bigger numbers @@ -153,16 +158,14 @@ :For case :In 'cmplx' 'Hcmplx' data←⍎case desc←testDesc⍬ - r,←'T1' desc RunVariations data data - - d1←data[?≢data] - r,←'T2' desc RunVariations d1 d1 + r,←'T1' desc RunVariations data data ⍝ all of data are whole cmplx numbers ⍝ adding a number between (0,1) to data making it a array of cmplx numbers of type 1J1 ¯1J1 1J¯1 ¯1J¯1 dataplus←(data,(data+2⊃⊣),(data+2⊃⊣),(data+(1⊃⊣)+2⊃⊣)) (?0⍨¨data) (¯11○(?0⍨¨data)) - r,←'T3' desc Assert ((genCmplxFloor¨dataplus)≡⌊dataplus) ∨ ((fr=2) ∧ case≡'Hcmplx') ⍝ DECF Hcmplx is skipped because of rounding off + r,←'T2' desc Assert ((genCmplxFloor¨dataplus)≡⌊dataplus) ∨ ((fr=2) ∧ case≡'Hcmplx') ⍝ DECF Hcmplx is skipped because of rounding off - almostd1←d1×1-fr⊃ct_default dct_default ⍝ infinitesimally close to d1 but smaller + d1←data[?≢data] + almostd1←d1×1-fr⊃1E¯2× ct_default dct_default ⍝ infinitesimally close to d1 but smaller :If ct ∧ (fr≡1) ⍝ tolerant :If (case≡'Hcmplx') ⍝ bigger numbers ⍝ Hdbl=Hdbl+1 with default CT, but not for DECF (similar for Hcmplx) From c147326c7c8396284b73f14e0e292986aacd3c86 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 20 Jul 2023 10:27:26 +0530 Subject: [PATCH 25/28] improve comment for cmplx dataplus --- tests/floor.apln | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/floor.apln b/tests/floor.apln index b9d4f4c..a104630 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -160,7 +160,7 @@ desc←testDesc⍬ r,←'T1' desc RunVariations data data ⍝ all of data are whole cmplx numbers - ⍝ adding a number between (0,1) to data making it a array of cmplx numbers of type 1J1 ¯1J1 1J¯1 ¯1J¯1 + ⍝ adding a number between (0,1) to data making it a array of cmplx numbers of type xJy ¯xJy xJ¯y ¯xJ¯y dataplus←(data,(data+2⊃⊣),(data+2⊃⊣),(data+(1⊃⊣)+2⊃⊣)) (?0⍨¨data) (¯11○(?0⍨¨data)) r,←'T2' desc Assert ((genCmplxFloor¨dataplus)≡⌊dataplus) ∨ ((fr=2) ∧ case≡'Hcmplx') ⍝ DECF Hcmplx is skipped because of rounding off From f688943eac399d76c7d751506b8bb093b8f6ee0c Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Thu, 20 Jul 2023 10:29:16 +0530 Subject: [PATCH 26/28] improve comment for cmplx dataplus --- tests/floor.apln | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/floor.apln b/tests/floor.apln index a104630..521a519 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -107,7 +107,7 @@ r,← 'T1' desc RunVariations (genFloor¨data) data ⍝ generator func finds results on array - dataplus←data+?0⍨¨data ⍝ adding a number between (0,1) to data + dataplus←data+?0⍨¨data ⍝ data plus a number between (0,1) to data r,← 'T2' desc Assert ((genFloor¨dataplus)≡⌊dataplus) ∨ (fr=1 ∧ case≡'Hfl') ⍝ ⎕fr=645 and Hfl is skipped because of rounding off :If (⊂data)∊i1 i2 i3 From 90c48fa88b56d9e2fa2391a0949942a3e272a717 Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Tue, 1 Aug 2023 11:42:42 +0530 Subject: [PATCH 27/28] fix: missing paranthesis --- tests/floor.apln | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index 521a519..da544e4 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -124,7 +124,7 @@ :If ct ⍝ tolerant :If (⊂data)∊Hdbl Hfl ⍝ bigger numbers ⍝ Hdbl=Hdbl+1 with default CT, but not for DECF - r,← 'CTDefault1' desc Assert (((⌊d1)≡⌊(d1+1)) ∨ (fr=2 ∧ (case≡'Hdbl'))) + r,← 'CTDefault1' desc Assert (((⌊d1)≡⌊(d1+1)) ∨ ((fr=2) ∧ case≡'Hdbl')) :Else ⍝ other than bigger numbers r,← 'CTDefault2' desc Assert ((⌊d1)≢⌊(d1+1)) ⍝ not tolerantly equal for other numbers r,← 'CTDefaultAlmost' desc Assert (({(⌊=⊢)⍵:⍵⋄⍵-0.5}d1)≡⌊almostd1) ⍝ d1 and almostd1 are tolerantly equal, condition added to get integer @@ -132,7 +132,7 @@ :Else ⍝ exact ⍝ d≠d+1 for all numeric types r,← 'CTZero' desc Assert ((1+⌊d1)≡⌊d1+1) - r,← 'CTZeroAlmost' desc Assert (((d1-{(⌊=⊢)⍵:⍵>0⋄0.5}d1)≡⌊almostd1) ∨ (fr=1 ∧ (case≡'Hfl'))) ⍝ floor is the integer lesser than the number with no tolerance + r,← 'CTZeroAlmost' desc Assert (((d1-{(⌊=⊢)⍵:⍵>0⋄0.5}d1)≡⌊almostd1) ∨ ((fr=1) ∧ case≡'Hfl')) ⍝ floor is the integer lesser than the number with no tolerance :EndIf :EndFor :EndFor From 90b40d0c95728aad7675d82e5110cd60a28f624c Mon Sep 17 00:00:00 2001 From: Aarush Bhat Date: Fri, 11 Aug 2023 16:36:41 +0530 Subject: [PATCH 28/28] add tests for domain error and some refactor --- tests/floor.apln | 26 ++++++++++++++++++++++++-- unittest.apln | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/floor.apln b/tests/floor.apln index da544e4..499f78e 100644 --- a/tests/floor.apln +++ b/tests/floor.apln @@ -59,7 +59,7 @@ actualRS←⌊shape⍴p ⍝ change shape and then evaluate tRes,←('Multiple',tID) tCmt Assert (shape⍴expectedR)≡actualRS - ⍝ randomize shapes with 0 a random position of shape shape + ⍝ randomize shapes with 0 a random position of shape shapeW0←(0@(?(≢shape)))shape actualRS←⌊shapeW0⍴p tRes,←('ShapeW0',tID) tCmt Assert (shapeW0⍴0)≡actualRS @@ -85,6 +85,12 @@ Hfl←{⍵,-⍵}2E29+(1E16×⍳10) ⍝ Hfl is 1287 closer to the default DCT ⎕FR←fr_dbl ⍝ revert ⎕FR=645 + char1←⎕UCS ⍳255 ⍝ 80: 8 bits character + char2←⎕UCS (1000+⍳100) ⍝ 160: 16 bits character + char3←⎕UCS (100000+⍳100) ⍝ 320: 32 bits character + ptr←2,/⎕A ⍝ 326: Pointer (32-bit or 64-bit as appropriate) + + r←⍬ testDesc←{'for ',case,{0∊⍴case2:'',⍵⋄' , ', case2,⍵},' & ⎕CT ⎕DCT:',⎕CT,⎕DCT, '& ⎕FR:', ⎕FR} @@ -108,7 +114,7 @@ r,← 'T1' desc RunVariations (genFloor¨data) data ⍝ generator func finds results on array dataplus←data+?0⍨¨data ⍝ data plus a number between (0,1) to data - r,← 'T2' desc Assert ((genFloor¨dataplus)≡⌊dataplus) ∨ (fr=1 ∧ case≡'Hfl') ⍝ ⎕fr=645 and Hfl is skipped because of rounding off + r,← 'T2' desc Assert ((genFloor¨dataplus)≡⌊dataplus) ∨ ((fr=1) ∧ case≡'Hfl') ⍝ ⎕fr=645 and Hfl is skipped because of rounding off :If (⊂data)∊i1 i2 i3 r,← 'TInt1' desc RunVariations data data ⍝ floor of integers will always be floor @@ -134,6 +140,22 @@ r,← 'CTZero' desc Assert ((1+⌊d1)≡⌊d1+1) r,← 'CTZeroAlmost' desc Assert (((d1-{(⌊=⊢)⍵:⍵>0⋄0.5}d1)≡⌊almostd1) ∨ ((fr=1) ∧ case≡'Hfl')) ⍝ floor is the integer lesser than the number with no tolerance :EndIf + + ⍝ tests for known errors + :For case2 :In 'char1' 'char2' 'char3' 'ptr' + data←⍎case2 + desc←testDesc⍬ + c1←data[?≢data] + + f←0 ⍝ flag + :Trap 11 ⍝ 11: Domain error + ⌊c1 + :Else + f←1 + :EndTrap + r,← 'TDomainE1' desc Assert f + :EndFor + case2←⍬ ⍝ disposing case2 for testDesc :EndFor :EndFor :EndFor diff --git a/unittest.apln b/unittest.apln index 309772d..1d724e9 100644 --- a/unittest.apln +++ b/unittest.apln @@ -44,7 +44,7 @@ 'Stop can only be 0 or 1'⎕SIGNAL (stop ∊ 0 1)↓11 ⍝ 0 is used to generate a random seed value and the random value is the noted in the logs - ⎕RL←rl←{⍵≡0:(?(¯2+2*31))⋄⍵} randLink + ⎕RL←rl←{⍵≡0:?¯2+2*31⋄⍵} randLink ⎕←'Options:' ⎕←(6⍴' '),'⎕RL is set to:', {0∊⍴⍵:' ⍬'⋄⍵}rl :If verbose