<commit_before>
module ShallowVector where

import qualified Data.Vector.Unboxed as V
import Types
import Debug.Trace

{-# RULES "darkenBy.brightenBy" forall im1 n. darkenBy n (brightenBy n im1) = im1 #-}
{-# RULES "brightenBy.darkenBy" forall im1 n. brightenBy n (darkenBy n im1) = im1 #-}

-- TODO: overload + and - to be brightenBy and darkenBy

-- inline the blur functions so that they can be fused when used together,
-- using the fusion optimisations in the vector library.

blurY = undefined

{-# INLINE blurX #-}
blurX (VectorImage pixels w h) = VectorImage newPixels w h
    where
      newPixels = V.imap blurPixel pixels
      blurPixel i p
         -- right end of a row<commit_msg>(Haskell) adds blurY to shallow vector implementation<commit_after>
module ShallowVector where

import qualified Data.Vector.Unboxed as V
import Types
import Debug.Trace

{-# RULES "darkenBy.brightenBy" forall im1 n. darkenBy n (brightenBy n im1) = im1 #-}
{-# RULES "brightenBy.darkenBy" forall im1 n. brightenBy n (darkenBy n im1) = im1 #-}

-- TODO: overload + and - to be brightenBy and darkenBy

-- inline the blur functions so that they can be fused when used together,
-- using the fusion optimisations in the vector library.

{-# INLINE blurY #-}
blurY :: VectorImage -> VectorImage
blurY (VectorImage pixels w h) = VectorImage newPixels w h
    where
      newPixels = V.imap blurPixel pixels
      blurPixel i p
         -- bottom of a column
         | (i+1) `mod` h == 0 =
             round ((fromIntegral ((pixels V.! (i-1)) + p*2 + p) ::Double) / 4.0)

         -- top of a column
         | i `mod` h == 0 =
             round ((fromIntegral (p + p*2 + (pixels V.! (i+1))) ::Double) / 4.0)

         -- somewhere in between
         | otherwise =
             round ((fromIntegral ((pixels V.! (i-1)) + p*2 + (pixels V.! (i+1))) ::Double) / 4.0)

{-# INLINE blurX #-}
blurX :: VectorImage -> VectorImage
blurX (VectorImage pixels w h) = VectorImage newPixels w h
    where
      newPixels = V.imap blurPixel pixels
      blurPixel i p
         -- right end of a row
{'fraction_non_alphanumeric': 0.10789980732177264, 'fraction_numerical': 0.01348747591522158, 'mean_word_length': 2.695729537366548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6268101', 'n_tokens_mistral': 710, 'n_tokens_neox': 683, 'n_words': 257}