mirror of
https://github.com/tensorflow/haskell.git
synced 2024-11-30 06:49:44 +01:00
98 lines
14 KiB
HTML
98 lines
14 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html>
|
|
<head>
|
|
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
|
|
<title>src/TensorFlow/ControlFlow.hs</title>
|
|
<link type='text/css' rel='stylesheet' href='hscolour.css' />
|
|
</head>
|
|
<body>
|
|
<pre><a name="line-1"></a><span class='hs-comment'>-- Copyright 2016 TensorFlow authors.</span>
|
|
<a name="line-2"></a><span class='hs-comment'>--</span>
|
|
<a name="line-3"></a><span class='hs-comment'>-- Licensed under the Apache License, Version 2.0 (the "License");</span>
|
|
<a name="line-4"></a><span class='hs-comment'>-- you may not use this file except in compliance with the License.</span>
|
|
<a name="line-5"></a><span class='hs-comment'>-- You may obtain a copy of the License at</span>
|
|
<a name="line-6"></a><span class='hs-comment'>--</span>
|
|
<a name="line-7"></a><span class='hs-comment'>-- <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a></span>
|
|
<a name="line-8"></a><span class='hs-comment'>--</span>
|
|
<a name="line-9"></a><span class='hs-comment'>-- Unless required by applicable law or agreed to in writing, software</span>
|
|
<a name="line-10"></a><span class='hs-comment'>-- distributed under the License is distributed on an "AS IS" BASIS,</span>
|
|
<a name="line-11"></a><span class='hs-comment'>-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
|
|
<a name="line-12"></a><span class='hs-comment'>-- See the License for the specific language governing permissions and</span>
|
|
<a name="line-13"></a><span class='hs-comment'>-- limitations under the License.</span>
|
|
<a name="line-14"></a>
|
|
<a name="line-15"></a><span class='hs-comment'>{-# LANGUAGE GADTs #-}</span>
|
|
<a name="line-16"></a><span class='hs-comment'>{-# LANGUAGE OverloadedStrings #-}</span>
|
|
<a name="line-17"></a><span class='hs-comment'>{-# LANGUAGE RankNTypes #-}</span>
|
|
<a name="line-18"></a><span class='hs-comment'>{-# LANGUAGE ScopedTypeVariables #-}</span>
|
|
<a name="line-19"></a>
|
|
<a name="line-20"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>TensorFlow</span><span class='hs-varop'>.</span><span class='hs-conid'>ControlFlow</span>
|
|
<a name="line-21"></a> <span class='hs-layout'>(</span> <span class='hs-comment'>-- * Dependencies</span>
|
|
<a name="line-22"></a> <span class='hs-varid'>withControlDependencies</span>
|
|
<a name="line-23"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>group</span>
|
|
<a name="line-24"></a> <span class='hs-comment'>-- * Operations</span>
|
|
<a name="line-25"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>identity</span>
|
|
<a name="line-26"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>noOp</span>
|
|
<a name="line-27"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>named</span>
|
|
<a name="line-28"></a> <span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
|
|
<a name="line-29"></a>
|
|
<a name="line-30"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Set</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>Set</span>
|
|
<a name="line-31"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Text</span> <span class='hs-layout'>(</span><span class='hs-conid'>Text</span><span class='hs-layout'>)</span>
|
|
<a name="line-32"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Lens</span><span class='hs-varop'>.</span><span class='hs-conid'>Family2</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varop'>&</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-layout'>(</span><span class='hs-varop'>^.</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-layout'>(</span><span class='hs-varop'>.~</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
|
|
<a name="line-33"></a>
|
|
<a name="line-34"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>TensorFlow</span><span class='hs-varop'>.</span><span class='hs-conid'>BuildOp</span>
|
|
<a name="line-35"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>TensorFlow</span><span class='hs-varop'>.</span><span class='hs-conid'>Build</span>
|
|
<a name="line-36"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>TensorFlow</span><span class='hs-varop'>.</span><span class='hs-conid'>Nodes</span>
|
|
<a name="line-37"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>TensorFlow</span><span class='hs-varop'>.</span><span class='hs-conid'>Output</span>
|
|
<a name="line-38"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>TensorFlow</span><span class='hs-varop'>.</span><span class='hs-conid'>Tensor</span>
|
|
<a name="line-39"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>TensorFlow</span><span class='hs-varop'>.</span><span class='hs-conid'>Types</span>
|
|
<a name="line-40"></a>
|
|
<a name="line-41"></a><a name="withControlDependencies"></a><span class='hs-comment'>-- | Modify a 'Build' action, such that all new ops rendered in it will depend</span>
|
|
<a name="line-42"></a><span class='hs-comment'>-- on the nodes in the first argument.</span>
|
|
<a name="line-43"></a><span class='hs-definition'>withControlDependencies</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Nodes</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Build</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Build</span> <span class='hs-varid'>a</span>
|
|
<a name="line-44"></a><span class='hs-definition'>withControlDependencies</span> <span class='hs-varid'>deps</span> <span class='hs-varid'>act</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
|
|
<a name="line-45"></a> <span class='hs-varid'>nodes</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>getNodes</span> <span class='hs-varid'>deps</span>
|
|
<a name="line-46"></a> <span class='hs-varid'>withNodeDependencies</span> <span class='hs-varid'>nodes</span> <span class='hs-varid'>act</span>
|
|
<a name="line-47"></a>
|
|
<a name="line-48"></a><span class='hs-comment'>-- TODO(judahjacobson): Reimplement withDependencies.</span>
|
|
<a name="line-49"></a>
|
|
<a name="line-50"></a><a name="group"></a><span class='hs-comment'>-- | Create an op that groups multiple operations.</span>
|
|
<a name="line-51"></a><span class='hs-comment'>--</span>
|
|
<a name="line-52"></a><span class='hs-comment'>-- When this op finishes, all ops in the input @n@ have finished. This op has</span>
|
|
<a name="line-53"></a><span class='hs-comment'>-- no output.</span>
|
|
<a name="line-54"></a><span class='hs-definition'>group</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Nodes</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Build</span> <span class='hs-conid'>ControlNode</span>
|
|
<a name="line-55"></a><span class='hs-definition'>group</span> <span class='hs-varid'>deps</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
|
|
<a name="line-56"></a> <span class='hs-varid'>nodes</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>Set</span><span class='hs-varop'>.</span><span class='hs-varid'>toList</span> <span class='hs-varop'><$></span> <span class='hs-varid'>getNodes</span> <span class='hs-varid'>deps</span>
|
|
<a name="line-57"></a> <span class='hs-comment'>-- TODO: slicker way</span>
|
|
<a name="line-58"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-varid'>buildOp</span> <span class='hs-varop'>$</span> <span class='hs-varid'>opDef</span> <span class='hs-str'>"NoOp"</span> <span class='hs-varop'>&</span> <span class='hs-varid'>opControlInputs</span> <span class='hs-varop'>.~</span> <span class='hs-varid'>nodes</span>
|
|
<a name="line-59"></a>
|
|
<a name="line-60"></a>
|
|
<a name="line-61"></a><a name="identity"></a><span class='hs-comment'>-- | Returns a 'Tensor' with the same shape and contents as the input.</span>
|
|
<a name="line-62"></a><span class='hs-definition'>identity</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TensorType</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Tensor</span> <span class='hs-varid'>v</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Tensor</span> <span class='hs-varid'>v</span> <span class='hs-varid'>a</span>
|
|
<a name="line-63"></a><span class='hs-definition'>identity</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>namedIdentity</span> <span class='hs-varid'>implicitName</span>
|
|
<a name="line-64"></a>
|
|
<a name="line-65"></a><a name="named"></a><span class='hs-comment'>-- | Returns a 'Tensor' with a given name and the same shape and contents as</span>
|
|
<a name="line-66"></a><span class='hs-comment'>-- the input.</span>
|
|
<a name="line-67"></a><span class='hs-comment'>--</span>
|
|
<a name="line-68"></a><span class='hs-comment'>-- TODO(judahjacobson): This breaks when used with uninitialize @Tensor Ref@s,</span>
|
|
<a name="line-69"></a><span class='hs-comment'>-- since @RefIdentity@ doesn't have SetAllowsUninitializedInput(). Look into</span>
|
|
<a name="line-70"></a><span class='hs-comment'>-- whether we can change that op.</span>
|
|
<a name="line-71"></a><span class='hs-definition'>named</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TensorType</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Text</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Tensor</span> <span class='hs-varid'>v</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Tensor</span> <span class='hs-varid'>v</span> <span class='hs-varid'>a</span>
|
|
<a name="line-72"></a><span class='hs-definition'>named</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>namedIdentity</span> <span class='hs-varop'>.</span> <span class='hs-varid'>explicitName</span>
|
|
<a name="line-73"></a>
|
|
<a name="line-74"></a><a name="namedIdentity"></a><span class='hs-comment'>-- | An internal version of "identity" that allows setting the name</span>
|
|
<a name="line-75"></a><span class='hs-comment'>-- of the output Tensor.</span>
|
|
<a name="line-76"></a><span class='hs-definition'>namedIdentity</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyword'>forall</span> <span class='hs-varid'>a</span> <span class='hs-varid'>v</span> <span class='hs-varop'>.</span> <span class='hs-conid'>TensorType</span> <span class='hs-varid'>a</span>
|
|
<a name="line-77"></a> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>PendingNodeName</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Tensor</span> <span class='hs-varid'>v</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Tensor</span> <span class='hs-varid'>v</span> <span class='hs-varid'>a</span>
|
|
<a name="line-78"></a><span class='hs-definition'>namedIdentity</span> <span class='hs-varid'>n</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>case</span> <span class='hs-varid'>t</span> <span class='hs-varop'>^.</span> <span class='hs-varid'>tensorKind</span> <span class='hs-keyword'>of</span>
|
|
<a name="line-79"></a> <span class='hs-conid'>ValueKind</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>buildOp</span> <span class='hs-layout'>(</span><span class='hs-varid'>opDefWithName</span> <span class='hs-varid'>n</span> <span class='hs-str'>"Identity"</span> <span class='hs-varop'>&</span> <span class='hs-varid'>setTypeAttr</span><span class='hs-layout'>)</span> <span class='hs-varid'>t</span>
|
|
<a name="line-80"></a> <span class='hs-conid'>RefKind</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>buildOp</span> <span class='hs-layout'>(</span><span class='hs-varid'>opDefWithName</span> <span class='hs-varid'>n</span> <span class='hs-str'>"RefIdentity"</span> <span class='hs-varop'>&</span> <span class='hs-varid'>setTypeAttr</span><span class='hs-layout'>)</span> <span class='hs-varid'>t</span>
|
|
<a name="line-81"></a> <span class='hs-keyword'>where</span>
|
|
<a name="line-82"></a> <span class='hs-varid'>setTypeAttr</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>opAttr</span> <span class='hs-str'>"T"</span> <span class='hs-varop'>.~</span> <span class='hs-varid'>tensorType</span> <span class='hs-layout'>(</span><span class='hs-varid'>undefined</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span>
|
|
<a name="line-83"></a>
|
|
<a name="line-84"></a>
|
|
<a name="line-85"></a><a name="noOp"></a><span class='hs-comment'>-- | Does nothing. Only useful as a placeholder for control edges.</span>
|
|
<a name="line-86"></a><span class='hs-definition'>noOp</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>ControlNode</span>
|
|
<a name="line-87"></a><span class='hs-definition'>noOp</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>buildOp</span> <span class='hs-varop'>$</span> <span class='hs-varid'>opDef</span> <span class='hs-str'>"NoOp"</span>
|
|
</pre></body>
|
|
</html>
|