-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ reverse mode differentiation ] done reverse mode
- Loading branch information
Showing
11 changed files
with
159 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
-- | | ||
-- Module : HashedExpression.Differentiation.Exterior.Derivative | ||
-- Copyright : (c) OCA 2020 | ||
-- License : MIT (see the LICENSE file) | ||
-- Maintainer : [email protected] | ||
-- Stability : provisional | ||
-- Portability : unportable | ||
module HashedExpression.Differentiation.Exterior where | ||
|
||
import Data.Map.Strict (Map) | ||
import qualified Data.Map.Strict as Map | ||
import Data.Maybe (mapMaybe) | ||
import HashedExpression.Differentiation.Exterior.Collect | ||
import HashedExpression.Differentiation.Exterior.Derivative | ||
import HashedExpression.Internal | ||
import HashedExpression.Internal.Expression | ||
import HashedExpression.Internal.Node | ||
|
||
partialDerivativesMapByExterior :: Expression Scalar R -> (ExpressionMap, Map String NodeID) | ||
partialDerivativesMapByExterior exp = | ||
let (mp, rootID) = unwrap . collectDifferentials . derivativeAllVars $ exp | ||
in (mp, partialDerivativesMap (mp, rootID)) | ||
|
||
-- | Return a map from variable name to the corresponding partial derivative node id | ||
-- Partial derivatives in Expression Scalar Covector should be collected before passing to this function | ||
partialDerivativesMap :: (ExpressionMap, NodeID) -> Map String NodeID | ||
partialDerivativesMap (dfMp, dfId) = | ||
case retrieveOp dfId dfMp of | ||
Sum ns | retrieveElementType dfId dfMp == Covector -> Map.fromList $ mapMaybe getPartial ns | ||
_ -> Map.fromList $ mapMaybe getPartial [dfId] | ||
where | ||
getPartial :: NodeID -> Maybe (String, NodeID) | ||
getPartial nId | ||
| MulD partialId dId <- retrieveOp nId dfMp, | ||
DVar name <- retrieveOp dId dfMp = | ||
Just (name, partialId) | ||
| InnerProdD partialId dId <- retrieveOp nId dfMp, | ||
DVar name <- retrieveOp dId dfMp = | ||
Just (name, partialId) | ||
| otherwise = Nothing |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.