<commit_before>{-# LANGUAGE TypeOperators #-}
--
-- A Mandelbrot set generator. Submitted by <NAME> as part of Issue #49.
--


import Config
import Control.Monad
import Control.Exception
import Foreign.Ptr
import Foreign.ForeignPtr
import System.IO.Unsafe
import System.Environment
import Data.Array.Accelerate.Array.Data         ( ptrsOfArrayData )
import Data.Array.Accelerate.Array.Sugar        ( Array(..) )

import Prelude                                  as P
import Data.Array.Accelerate                    as A hiding ( size )
import Data.Array.Accelerate.IO
import qualified Data.Array.Repa as R
import qualified Data.Array.Repa.Repr.ForeignPtr as R
import Data.Array.Repa.IO.DevIL


-- Mandelbrot Set --------------------------------------------------------------

-- <<types
type F            = Float
type Complex      = (F,F)
type ComplexPlane = Array DIM2 Complex
-- >>

-- <<mandelbrot
mandelbrot :: F -> F -> F -> F -> Int -> Int -> Int
           -> Acc (Array DIM2 (F,F,Int))

mandelbrot x y x' y' screenX screenY depth
  = iterate go zs0 !! depth                  -- <4>
  where
    cs  = genPlane x y x' y' screenX screenY -- <1>
    zs0 = mkinit cs                          -- <2>

    go :: Acc (Array DIM2 (F,F,Int))
       -> Acc (Array DIM2 (F,F,Int))
    go = A.zipWith iter cs                   -- <3>
-- >>


-- <<genPlane
genPlane :: F -> F
         -> F -> F
         -> Int
         -> Int
         -> Acc ComplexPlane
-- >>
genPlane lowx lowy highx highy viewx viewy
   = generate (constant (Z:.viewy:.viewx))
              (\ix -> let pr = unindex2 ix
                          x = A.fromIntegral (A.fst pr)<commit_msg>rename depth to max_depth<commit_after>{-# LANGUAGE TypeOperators #-}
--
-- A Mandelbrot set generator. Submitted by <NAME> as part of Issue #49.
--


import Config
import Control.Monad
import Control.Exception
import Foreign.Ptr
import Foreign.ForeignPtr
import System.IO.Unsafe
import System.Environment
import Data.Array.Accelerate.Array.Data         ( ptrsOfArrayData )
import Data.Array.Accelerate.Array.Sugar        ( Array(..) )

import Prelude                                  as P
import Data.Array.Accelerate                    as A hiding ( size )
import Data.Array.Accelerate.IO
import qualified Data.Array.Repa as R
import qualified Data.Array.Repa.Repr.ForeignPtr as R
import Data.Array.Repa.IO.DevIL


-- Mandelbrot Set --------------------------------------------------------------

-- <<types
type F            = Float
type Complex      = (F,F)
type ComplexPlane = Array DIM2 Complex
-- >>

-- <<mandelbrot
mandelbrot :: F -> F -> F -> F -> Int -> Int -> Int
           -> Acc (Array DIM2 (F,F,Int))

mandelbrot x y x' y' screenX screenY max_depth
  = iterate go zs0 !! max_depth              -- <4>
  where
    cs  = genPlane x y x' y' screenX screenY -- <1>
    zs0 = mkinit cs                          -- <2>

    go :: Acc (Array DIM2 (F,F,Int))
       -> Acc (Array DIM2 (F,F,Int))
    go = A.zipWith iter cs                   -- <3>
-- >>


-- <<genPlane
genPlane :: F -> F
         -> F -> F
         -> Int
         -> Int
         -> Acc ComplexPlane
-- >>
genPlane lowx lowy highx highy viewx viewy
   = generate (constant (Z:.viewy:.viewx))
              (\ix -> let pr = unindex2 ix
                          x = A.fromIntegral (A.fst pr)
{'fraction_non_alphanumeric': 0.1518987341772152, 'fraction_numerical': 0.007836045810729355, 'mean_word_length': 1.642515923566879, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4892431', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1037, 'n_words': 314}