{"text": "{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE TypeApplications    #-}\nmodule ArrayFire.ArraySpec where\n\nimport Control.Exception\nimport Data.Complex\nimport Data.Word\nimport Foreign.C.Types\nimport GHC.Int\nimport Test.Hspec\n\nimport ArrayFire\n\nspec :: Spec\nspec =\n  describe \"Array tests\" $ do\n    it \"Should perform Array tests\" $ do\n      (1 + 1) `shouldBe` 2\n    it \"Should fail to create 0 dimension arrays\" $ do\n      let arr = mkArray @Int [0,0,0,0] [1..]\n      evaluate arr `shouldThrow` anyException\n    it \"Should fail to create 0 length arrays\" $ do\n      let arr = mkArray @Int [0,0,0,1] []\n      evaluate arr `shouldThrow` anyException\n    it \"Should fail to create 0 length arrays w/ 0 dimensions\" $ do\n      let arr = mkArray @Int [0,0,0,0] []\n      evaluate arr `shouldThrow` anyException\n    it \"Should create a column vector\" $ do\n      let arr = mkArray @Int [9,1,1,1] (repeat 9)\n      isColumn arr `shouldBe` True\n    it \"Should create a row vector\" $ do\n      let arr = mkArray @Int [1,9,1,1] (repeat 9)\n      isRow arr `shouldBe` True\n    it \"Should create a vector\" $ do\n      let arr = mkArray @Int [9,1,1,1] (repeat 9)\n      isVector arr `shouldBe` True\n    it \"Should create a vector\" $ do\n      let arr = mkArray @Int [1,9,1,1] (repeat 9)\n      isVector arr `shouldBe` True\n    it \"Should copy an array\" $ do\n      let arr = mkArray @Int [9,9,1,1] (repeat 9)\n      let newArray = copyArray arr\n      newArray `shouldBe` arr\n    it \"Should modify manual eval flag\" $ do\n      setManualEvalFlag False\n      (`shouldBe` False) =<< getManualEvalFlag\n    it \"Should return the number of elements\" $ do\n      let arr = mkArray @Int [9,9,1,1] [1..]\n      getElements arr `shouldBe` 81\n--    it \"Should give an empty array\" $ do\n--      let arr = mkArray @Int [-1,1,1,1] []\n--      getElements arr `shouldBe` 0\n--      isEmpty arr `shouldBe` True\n    it \"Should create a scalar array\" $ do\n      let arr = mkArray @Int [1] [1]\n      isScalar arr `shouldBe` True\n    it \"Should get number of dims specified\" $ do\n      let arr = mkArray @Int [1,1,1,1] [1]\n      getNumDims arr `shouldBe` 1\n      let arr = mkArray @Int [2,3,4,5] [1..]\n      getNumDims arr `shouldBe` 4\n      let arr = mkArray @Int [2,3,4] [1..]\n      getNumDims arr `shouldBe` 3\n    it \"Should get value of dims specified\" $ do\n      let arr = mkArray @Int [2,3,4,5] (repeat 1)\n      getDims arr `shouldBe` (2,3,4,5)\n\n    it \"Should test Sparsity\" $ do\n      let arr = mkArray @Double [2,2,1,1] (repeat 1)\n      isSparse arr `shouldBe` False\n\n    it \"Should make a Bit array\" $ do\n      let arr = mkArray @CBool [2,2] [1,1,1,1]\n      isBool arr `shouldBe` True\n\n    it \"Should make an integer array\" $ do\n      let arr = mkArray @Int [2,2] (repeat 1)\n      isInteger arr `shouldBe` True\n\n    it \"Should make a Floating array\" $ do\n      let arr = mkArray @Double [2,2] (repeat 1)\n      isFloating arr `shouldBe` True\n      let arr = mkArray @CBool [2,2] (repeat 1)\n      isFloating arr `shouldBe` False\n\n    it \"Should make a Complex array\" $ do\n      let arr = mkArray @(Complex Double) [2,2] (repeat 1)\n      isComplex arr `shouldBe` True\n      isReal arr `shouldBe` False\n\n    it \"Should make a Real array\" $ do\n      let arr = mkArray @Double [2,2] (repeat 1)\n      isReal arr `shouldBe` True\n      isComplex arr `shouldBe` False\n\n    it \"Should make a Double precision array\" $ do\n      let arr = mkArray @Double [2,2] (repeat 1)\n      isDouble arr `shouldBe` True\n      isSingle arr `shouldBe` False\n\n    it \"Should make a Single precision array\" $ do\n      let arr = mkArray @Float [2,2] (repeat 1)\n      isDouble arr `shouldBe` False\n      isSingle arr `shouldBe` True\n\n    it \"Should make a Real floating array\" $ do\n      let arr = mkArray @Float [2,2] (repeat 1)\n      isRealFloating arr `shouldBe` True\n      let arr = mkArray @Double [2,2] (repeat 1)\n      isRealFloating arr `shouldBe` True\n\n    it \"Should get reference count\" $ do\n      let arr1 = mkArray @Float [2,2] (repeat 1)\n          arr2 = retainArray arr1\n          arr3 = retainArray arr2\n      getDataRefCount arr3 `shouldBe` 3\n\n    it \"Should convert an array to a list\" $ do\n      let arr = mkArray @Double [30,30] (repeat 1)\n      toList arr `shouldBe` Prelude.replicate (30 * 30) 1\n\n      let arr = mkArray @Float [10,10] (repeat (5.5))\n      toList arr `shouldBe` Prelude.replicate 100 5.5\n\n      let arr = mkArray @CBool [4] [1,1,0,1]\n      toList arr `shouldBe` [1,1,0,1]\n\n      let arr = mkArray @Int16 [10] [1..]\n      toList arr `shouldBe` [1..10]\n\n      let arr = mkArray @Int32 [100] [1..100]\n      toList arr `shouldBe` [1..100]\n\n      let arr = mkArray @Int64 [100] [1..100]\n      toList arr `shouldBe` [1..100]\n\n      let arr = mkArray @Int [100] [1..100]\n      toList arr `shouldBe` [1..100]\n\n      let arr = mkArray @(Complex Float) [1] [1 :+ 1]\n      toList arr `shouldBe` [1 :+ 1]\n\n      let arr = mkArray @(Complex Double) [1] [1 :+ 1]\n      toList arr `shouldBe` [1 :+ 1]\n\n      let arr = mkArray @Word16 [10] [1..10]\n      toList arr `shouldBe` [1..10]\n\n      let arr = mkArray @Word32 [10] [1..10]\n      toList arr `shouldBe` [1..10]\n\n      let arr = mkArray @Word64 [10] [1..10]\n      toList arr `shouldBe` [1..10]\n\n      let arr = mkArray @Word [10] [1..10]\n      toList arr `shouldBe` [1..10]\n", "meta": {"hexsha": "1452a006c6c15840fd6c1f3d0fe26b8cf9481244", "size": 5280, "ext": "hs", "lang": "Haskell", "max_stars_repo_path": "test/ArrayFire/ArraySpec.hs", "max_stars_repo_name": "danielkroeni/arrayfire-haskell", "max_stars_repo_head_hexsha": "510b96cd4121272bdc39ba48aaf9e7e4db297a60", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 51, "max_stars_repo_stars_event_min_datetime": "2019-11-04T03:54:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-17T10:59:15.000Z", "max_issues_repo_path": "test/ArrayFire/ArraySpec.hs", "max_issues_repo_name": "danielkroeni/arrayfire-haskell", "max_issues_repo_head_hexsha": "510b96cd4121272bdc39ba48aaf9e7e4db297a60", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2019-11-04T03:45:02.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-24T00:49:36.000Z", "max_forks_repo_path": "test/ArrayFire/ArraySpec.hs", "max_forks_repo_name": "danielkroeni/arrayfire-haskell", "max_forks_repo_head_hexsha": "510b96cd4121272bdc39ba48aaf9e7e4db297a60", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-11-04T03:45:48.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-17T01:02:23.000Z", "avg_line_length": 33.6305732484, "max_line_length": 67, "alphanum_fraction": 0.6068181818, "num_tokens": 1702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. NO\n2. NO", "lm_q1_score": 0.4843800842769843, "lm_q2_score": 0.11124121534690624, "lm_q1q2_score": 0.053883029264808605}}
