AddTogether_8py_source.html 18.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>ensembl-hive-python3: eHive/examples/LongMult/AddTogether.py Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">ensembl-hive-python3
   &#160;<span id="projectnumber">2.4</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('AddTogether_8py_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">AddTogether.py</div>  </div>
</div><!--header-->
<div class="contents">
<a href="AddTogether_8py.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"><a class="line" href="namespaceeHive_1_1examples_1_1LongMult_1_1AddTogether.html">    1</a></span>&#160;</div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="keyword">import</span> eHive</div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;</div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="keyword">import</span> time</div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;</div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="keyword">class </span><a class="code" href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html">AddTogether</a>(<a class="code" href="classeHive_1_1Process_1_1BaseRunnable.html">eHive.BaseRunnable</a>):</div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;    <span class="stringliteral">&quot;&quot;&quot;Runnable that adds up all the partial-multiplications from PartMultiply&quot;&quot;&quot;</span></div><div class="line"><a name="l00008"></a><span class="lineno"><a class="line" href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html">    8</a></span>&#160;</div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;    <span class="keyword">def </span><a class="code" href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html#a6f89c3ed58da74d020c53d9bbdc4698b">param_defaults</a>(self):</div><div class="line"><a name="l00010"></a><span class="lineno"><a class="line" href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html#a6f89c3ed58da74d020c53d9bbdc4698b">   10</a></span>&#160;        <span class="keywordflow">return</span> {</div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;            <span class="stringliteral">&#39;take_time&#39;</span> : 0,</div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;            <span class="stringliteral">&#39;partial_product&#39;</span> : {}</div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;        }</div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;</div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;    <span class="keyword">def </span><a class="code" href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html#a8f0aba59b14f4d86865c6f59598eb2fe">fetch_input</a>(self):</div><div class="line"><a name="l00017"></a><span class="lineno"><a class="line" href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html#a8f0aba59b14f4d86865c6f59598eb2fe">   17</a></span>&#160;        a_multiplier = self.<a class="code" href="classeHive_1_1Process_1_1BaseRunnable.html#acfa8fec0594a6d49f4bfb9b005216579">param_required</a>(<span class="stringliteral">&#39;a_multiplier&#39;</span>)</div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;        partial_product = self.<a class="code" href="classeHive_1_1Process_1_1BaseRunnable.html#a11adb84bc2b95f138346911b3acda14a">param</a>(<span class="stringliteral">&#39;partial_product&#39;</span>)</div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;        print(partial_product)</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;        partial_product[<span class="stringliteral">&#39;1&#39;</span>] = str(a_multiplier)</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;        partial_product[<span class="stringliteral">&#39;0&#39;</span>] = <span class="stringliteral">&#39;0&#39;</span></div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;    <span class="keyword">def </span><a class="code" href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html#a5664c8046bf0c7e2fd28db5e991a932d">run</a>(self):</div><div class="line"><a name="l00026"></a><span class="lineno"><a class="line" href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html#a5664c8046bf0c7e2fd28db5e991a932d">   26</a></span>&#160;        b_multiplier = self.<a class="code" href="classeHive_1_1Process_1_1BaseRunnable.html#acfa8fec0594a6d49f4bfb9b005216579">param_required</a>(<span class="stringliteral">&#39;b_multiplier&#39;</span>)</div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;        partial_product = self.<a class="code" href="classeHive_1_1Process_1_1BaseRunnable.html#a11adb84bc2b95f138346911b3acda14a">param</a>(<span class="stringliteral">&#39;partial_product&#39;</span>)</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;        self.<a class="code" href="classeHive_1_1Process_1_1BaseRunnable.html#a11adb84bc2b95f138346911b3acda14a">param</a>(<span class="stringliteral">&#39;result&#39;</span>, <a class="code" href="namespaceeHive_1_1examples_1_1LongMult_1_1AddTogether.html#ad6849b7f229340568e6e1bb315894a63">add_together</a>(b_multiplier, partial_product))</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;        time.sleep( self.<a class="code" href="classeHive_1_1Process_1_1BaseRunnable.html#a11adb84bc2b95f138346911b3acda14a">param</a>(<span class="stringliteral">&#39;take_time&#39;</span>) )</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    <span class="keyword">def </span><a class="code" href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html#a5c52d8d0a05f178252c3b660d462749d">write_output</a>(self):</div><div class="line"><a name="l00032"></a><span class="lineno"><a class="line" href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html#a5c52d8d0a05f178252c3b660d462749d">   32</a></span>&#160;        self.<a class="code" href="classeHive_1_1Process_1_1BaseRunnable.html#a69ff24d26cfba17948c81f96966d2319">dataflow</a>( { <span class="stringliteral">&#39;result&#39;</span>: self.<a class="code" href="classeHive_1_1Process_1_1BaseRunnable.html#a11adb84bc2b95f138346911b3acda14a">param</a>(<span class="stringliteral">&#39;result&#39;</span>) }, 1)</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="keyword">def </span><a class="code" href="namespaceeHive_1_1examples_1_1LongMult_1_1AddTogether.html#ad6849b7f229340568e6e1bb315894a63">add_together</a>(b_multiplier, partial_product):</div><div class="line"><a name="l00037"></a><span class="lineno"><a class="line" href="namespaceeHive_1_1examples_1_1LongMult_1_1AddTogether.html#ad6849b7f229340568e6e1bb315894a63">   37</a></span>&#160;</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    b_multiplier = str(b_multiplier)</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;    accu = [0] * (1 + len(b_multiplier) + len(partial_product[<span class="stringliteral">&#39;1&#39;</span>]))</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    <span class="keywordflow">for</span> (i,b_digit) <span class="keywordflow">in</span> enumerate(reversed(b_multiplier)):</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;        product = str(partial_product[b_digit])</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        <span class="keywordflow">for</span> (j,p_digit) <span class="keywordflow">in</span> enumerate(reversed(product)):</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;            accu[i+j] += int(p_digit)</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;    carry = 0</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    <span class="keywordflow">for</span> i <span class="keywordflow">in</span> range(len(accu)):</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;        val = carry + accu[i]</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;        accu[i] = val % 10</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;        carry = val // 10</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;    <span class="keywordflow">return</span> <span class="stringliteral">&#39;&#39;</span>.join(str(_) <span class="keywordflow">for</span> _ <span class="keywordflow">in</span> reversed(accu)).lstrip(<span class="stringliteral">&#39;0&#39;</span>)</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;1;</div><div class="ttc" id="classeHive_1_1Process_1_1BaseRunnable_html_acfa8fec0594a6d49f4bfb9b005216579"><div class="ttname"><a href="classeHive_1_1Process_1_1BaseRunnable.html#acfa8fec0594a6d49f4bfb9b005216579">eHive.Process.BaseRunnable.param_required</a></div><div class="ttdeci">def param_required(self, param_name)</div><div class="ttdoc">Returns the value of the parameter &quot;param_name&quot; or raises an exception if anything wrong happens or t...</div><div class="ttdef"><b>Definition:</b> <a href="Process_8py_source.html#l00245">Process.py:245</a></div></div>
<div class="ttc" id="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether_html"><div class="ttname"><a href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html">eHive.examples.LongMult.AddTogether.AddTogether</a></div><div class="ttdoc">Runnable that adds up all the partial-multiplications from PartMultiply. </div><div class="ttdef"><b>Definition:</b> <a href="AddTogether_8py_source.html#l00008">AddTogether.py:8</a></div></div>
<div class="ttc" id="namespaceeHive_1_1examples_1_1LongMult_1_1AddTogether_html_ad6849b7f229340568e6e1bb315894a63"><div class="ttname"><a href="namespaceeHive_1_1examples_1_1LongMult_1_1AddTogether.html#ad6849b7f229340568e6e1bb315894a63">eHive.examples.LongMult.AddTogether.add_together</a></div><div class="ttdeci">def add_together(b_multiplier, partial_product)</div><div class="ttdef"><b>Definition:</b> <a href="AddTogether_8py_source.html#l00037">AddTogether.py:37</a></div></div>
<div class="ttc" id="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether_html_a6f89c3ed58da74d020c53d9bbdc4698b"><div class="ttname"><a href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html#a6f89c3ed58da74d020c53d9bbdc4698b">eHive.examples.LongMult.AddTogether.AddTogether.param_defaults</a></div><div class="ttdeci">def param_defaults(self)</div><div class="ttdef"><b>Definition:</b> <a href="AddTogether_8py_source.html#l00010">AddTogether.py:10</a></div></div>
<div class="ttc" id="classeHive_1_1Process_1_1BaseRunnable_html"><div class="ttname"><a href="classeHive_1_1Process_1_1BaseRunnable.html">eHive.Process.BaseRunnable</a></div><div class="ttdoc">This is the counterpart of GuestProcess. </div><div class="ttdef"><b>Definition:</b> <a href="Process_8py_source.html#l00051">Process.py:51</a></div></div>
<div class="ttc" id="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether_html_a5664c8046bf0c7e2fd28db5e991a932d"><div class="ttname"><a href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html#a5664c8046bf0c7e2fd28db5e991a932d">eHive.examples.LongMult.AddTogether.AddTogether.run</a></div><div class="ttdeci">def run(self)</div><div class="ttdef"><b>Definition:</b> <a href="AddTogether_8py_source.html#l00026">AddTogether.py:26</a></div></div>
<div class="ttc" id="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether_html_a5c52d8d0a05f178252c3b660d462749d"><div class="ttname"><a href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html#a5c52d8d0a05f178252c3b660d462749d">eHive.examples.LongMult.AddTogether.AddTogether.write_output</a></div><div class="ttdeci">def write_output(self)</div><div class="ttdef"><b>Definition:</b> <a href="AddTogether_8py_source.html#l00032">AddTogether.py:32</a></div></div>
<div class="ttc" id="classeHive_1_1Process_1_1BaseRunnable_html_a11adb84bc2b95f138346911b3acda14a"><div class="ttname"><a href="classeHive_1_1Process_1_1BaseRunnable.html#a11adb84bc2b95f138346911b3acda14a">eHive.Process.BaseRunnable.param</a></div><div class="ttdeci">def param(self, param_name, args)</div><div class="ttdoc">When called as a setter: sets the value of the parameter &quot;param_name&quot;. </div><div class="ttdef"><b>Definition:</b> <a href="Process_8py_source.html#l00259">Process.py:259</a></div></div>
<div class="ttc" id="classeHive_1_1Process_1_1BaseRunnable_html_a69ff24d26cfba17948c81f96966d2319"><div class="ttname"><a href="classeHive_1_1Process_1_1BaseRunnable.html#a69ff24d26cfba17948c81f96966d2319">eHive.Process.BaseRunnable.dataflow</a></div><div class="ttdeci">def dataflow(self, output_ids, branch_name_or_code=1)</div><div class="ttdoc">Dataflows the output_id(s) on a given branch (default 1). </div><div class="ttdef"><b>Definition:</b> <a href="Process_8py_source.html#l00215">Process.py:215</a></div></div>
<div class="ttc" id="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether_html_a8f0aba59b14f4d86865c6f59598eb2fe"><div class="ttname"><a href="classeHive_1_1examples_1_1LongMult_1_1AddTogether_1_1AddTogether.html#a8f0aba59b14f4d86865c6f59598eb2fe">eHive.examples.LongMult.AddTogether.AddTogether.fetch_input</a></div><div class="ttdeci">def fetch_input(self)</div><div class="ttdef"><b>Definition:</b> <a href="AddTogether_8py_source.html#l00017">AddTogether.py:17</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_bcf2b5ea520bfa6f20268dea09bd4a14.html">eHive</a></li><li class="navelem"><a class="el" href="dir_9b36ea3c363e8da7705d97b8844eeb7f.html">examples</a></li><li class="navelem"><a class="el" href="dir_6f2f5733adf05eb84dd8d951e30b0702.html">LongMult</a></li><li class="navelem"><a class="el" href="AddTogether_8py.html">AddTogether.py</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
  </ul>
</div>
</body>
</html>