@@ -27,7 +27,7 @@ poolForwardList nrows ncols srows scols inRows inCols outputRows outputCols ms =
28poolForwardFit :: [(Int,Int)] -> Int -> Int -> Int -> Int -> Matrix Double -> Matrix Double
28poolForwardFit :: [(Int,Int)] -> Int -> Int -> Int -> Int -> Matrix Double -> Matrix Double
29poolForwardFit starts nrows ncols _ outputCols m =
29poolForwardFit starts nrows ncols _ outputCols m =
30− let els = fmap (\start -> unsafeMaxElement $ subMatrix start (nrows, ncols) m) starts
30+ let els = fmap (\start -> unsafeMaxElementSubmatrix start (nrows, ncols) m) starts
31 in LA.matrix outputCols els
31 in LA.matrix outputCols els
33poolBackward :: Int -> Int -> Int -> Int -> Matrix Double -> Matrix Double -> Matrix Double
33poolBackward :: Int -> Int -> Int -> Int -> Matrix Double -> Matrix Double -> Matrix Double
@@ -42,16 +42,6 @@ poolBackwardList krows kcols srows scols inRows inCols inputMatrices =
42 let starts = fittingStarts inRows krows srows inCols kcols scols
42 let starts = fittingStarts inRows krows srows inCols kcols scols
43 in uncurry (poolBackwardFit starts krows kcols) <$> inputMatrices
43 in uncurry (poolBackwardFit starts krows kcols) <$> inputMatrices
45−-- poolBackwardFit :: [(Int,Int)] -> Int -> Int -> Matrix Double -> Matrix Double -> Matrix Double
46−-- poolBackwardFit starts krows kcols inputMatrix gradientMatrix =
47−-- let inRows = rows inputMatrix
48−-- inCols = cols inputMatrix
49−-- inds = fmap (\start -> unsafeMaxIndex $ subMatrix start (krows, kcols) inputMatrix) starts
50−-- grads = toList $ flatten gradientMatrix
51−-- grads' = zip3 starts grads inds
52−-- accums = fmap (\((stx',sty'),grad,(inx, iny)) -> ((stx' + inx, sty' + iny), grad)) grads'
53−-- in accum (LA.konst 0 (inRows, inCols)) (+) accums
55poolBackwardFit :: [(Int,Int)] -> Int -> Int -> Matrix Double -> Matrix Double -> Matrix Double
45poolBackwardFit :: [(Int,Int)] -> Int -> Int -> Matrix Double -> Matrix Double -> Matrix Double
56poolBackwardFit starts krows kcols inputMatrix gradientMatrix = U.runSTMatrix $ do
46poolBackwardFit starts krows kcols inputMatrix gradientMatrix = U.runSTMatrix $ do
57 let inRows = rows inputMatrix
47 let inRows = rows inputMatrix
@@ -67,16 +57,8 @@ poolBackwardFit starts krows kcols inputMatrix gradientMatrix = U.runSTMatrix $
68 return retM
58 return retM
70−unsafeMaxElement :: Matrix Double -> Double
60+unsafeMaxElementSubmatrix :: (Int,Int) -> (Int,Int) -> Matrix Double -> Double
71−unsafeMaxElement m = uncurry (U.atM' m) $ unsafeMaxIndex m
61+unsafeMaxElementSubmatrix starts extent m = uncurry (U.atM' m) $ unsafeMaxIndexSubMatrix starts extent m
73−unsafeMaxIndex :: Matrix Double -> (Int, Int)
75− let mrows = [0 .. rows m - 1]
76− mcols = [0 .. cols m - 1]
77− pairs = concatMap ( \r -> fmap (\c -> (r , c)) mcols ) mrows
78− in maximumBy (compare `on` uncurry (U.atM' m)) pairs
81unsafeMaxIndexSubMatrix :: (Int,Int) -> (Int,Int) -> Matrix Double -> (Int, Int)
63unsafeMaxIndexSubMatrix :: (Int,Int) -> (Int,Int) -> Matrix Double -> (Int, Int)
82unsafeMaxIndexSubMatrix (startRow, startCol) (extentRow, extentCold) m =
64unsafeMaxIndexSubMatrix (startRow, startCol) (extentRow, extentCold) m =