Skip to content

Commit

Permalink
got rid of lenses
Browse files Browse the repository at this point in the history
  • Loading branch information
mstksg committed Feb 15, 2018
1 parent 7dc4025 commit 7622e2f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 48 deletions.
6 changes: 0 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
Changelog
=========

Pending changes
---------------

* Added lenses `ixR`, `ixL`, `ixRow`, and `ixCol`, meant to be used with
`^^.` and `viewVar`.

Version 0.1.0.0
---------------

Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ re-exported.

[static]: https://hackage.haskell.org/package/hmatrix-0.18.2.0/docs/Numeric-LinearAlgebra-Static.html

Also includes a backpropagatable `sumElements`, and also lenses into *hmatrix*
types meant to be used with `^^.` and `viewVar`.

Formulas for gradients come from the following papers:

* <https://people.maths.ox.ac.uk/gilesm/files/NA-08-01.pdf>
Expand Down
40 changes: 1 addition & 39 deletions src/Numeric/LinearAlgebra/Static/Backprop.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
-- functions are automatically backpropagatable. Useful types are all
-- re-exported.
--
-- Also contains 'sumElements' 'BVar' operation, and lenses into hmatrix
-- types to use with '^^.' and 'viewVar'.
-- Also contains 'sumElements' 'BVar' operation.
--
-- Formulas for gradients come from the following papers:
--
Expand Down Expand Up @@ -178,15 +177,9 @@ module Numeric.LinearAlgebra.Static.Backprop (
, mTm
, unSym
, (<·>)
-- * Lenses
, ixR
, ixL
, ixRow
, ixCol
) where

import Data.ANum
import Data.Finite
import Data.Maybe
import Data.Proxy
import Foreign.Storable
Expand Down Expand Up @@ -1211,34 +1204,3 @@ unSym = liftOp1 (opIso H.unSym unsafeCoerce)
(<·>) = dot
infixr 8 <·>
{-# INLINE (<·>) #-}

--- | 'Lens' into an element of an /hmatrix/ vector.
--
-- @since 0.1.1.0
ixR :: KnownNat n => Finite n -> Lens' (H.R n) H.
ixR i f = fmap H.vecR . SVS.ix i f . H.rVec
{-# INLINE ixR #-}

-- | 'Lens' into an element of an /hmatrix/ matrix.
--
-- @since 0.1.1.0
ixL :: (KnownNat m, KnownNat n) => (Finite m, Finite n) -> Lens' (H.L m n) H.
ixL (i,j) f (H.extract->v) = fromJust . H.create . go <$> f (v `HU.atIndex` ij)
where
ij = (fromIntegral i, fromIntegral j)
go x = HU.accum v const [(ij, x)]
{-# INLINE ixL #-}

-- | 'Lens' into a row of an /hmatrix/ matrix.
--
-- @since 0.1.1.0
ixRow :: KnownNat m => Finite m -> Lens' (H.L m n) (H.R n)
ixRow i f = fmap H.rowsL . SV.ix i f . H.lRows
{-# INLINE ixRow #-}

-- | 'Lens' into a column of an /hmatrix/ matrix.
--
-- @since 0.1.1.0
ixCol :: KnownNat n => Finite n -> Lens' (H.L m n) (H.R m)
ixCol i f = fmap H.colsL . SV.ix i f . H.lCols
{-# INLINE ixCol #-}

0 comments on commit 7622e2f

Please sign in to comment.