Commit c40c8571 authored by Philipp Frank's avatar Philipp Frank
Browse files

added html and docktree files

parent e92a5247
Pipeline #12659 passed with stage
in 4 minutes and 33 seconds
<!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/html; charset=utf-8" />
<title>abc &#8212; NIFTY 3.0.x documentation</title>
<link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '3.0.x',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head>
<body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for abc</h1><div class="highlight"><pre>
<span></span><span class="c1"># Copyright 2007 Google, Inc. All Rights Reserved.</span>
<span class="c1"># Licensed to PSF under a Contributor Agreement.</span>
<span class="sd">&quot;&quot;&quot;Abstract Base Classes (ABCs) according to PEP 3119.&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">types</span>
<span class="kn">from</span> <span class="nn">_weakrefset</span> <span class="k">import</span> <span class="n">WeakSet</span>
<span class="c1"># Instance of old-style class</span>
<span class="k">class</span> <span class="nc">_C</span><span class="p">:</span> <span class="k">pass</span>
<span class="n">_InstanceType</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="n">_C</span><span class="p">())</span>
<span class="k">def</span> <span class="nf">abstractmethod</span><span class="p">(</span><span class="n">funcobj</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;A decorator indicating abstract methods.</span>
<span class="sd"> Requires that the metaclass is ABCMeta or derived from it. A</span>
<span class="sd"> class that has a metaclass derived from ABCMeta cannot be</span>
<span class="sd"> instantiated unless all of its abstract methods are overridden.</span>
<span class="sd"> The abstract methods can be called using any of the normal</span>
<span class="sd"> &#39;super&#39; call mechanisms.</span>
<span class="sd"> Usage:</span>
<span class="sd"> class C:</span>
<span class="sd"> __metaclass__ = ABCMeta</span>
<span class="sd"> @abstractmethod</span>
<span class="sd"> def my_abstract_method(self, ...):</span>
<span class="sd"> ...</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">funcobj</span><span class="o">.</span><span class="n">__isabstractmethod__</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">return</span> <span class="n">funcobj</span>
<span class="k">class</span> <span class="nc">abstractproperty</span><span class="p">(</span><span class="nb">property</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;A decorator indicating abstract properties.</span>
<span class="sd"> Requires that the metaclass is ABCMeta or derived from it. A</span>
<span class="sd"> class that has a metaclass derived from ABCMeta cannot be</span>
<span class="sd"> instantiated unless all of its abstract properties are overridden.</span>
<span class="sd"> The abstract properties can be called using any of the normal</span>
<span class="sd"> &#39;super&#39; call mechanisms.</span>
<span class="sd"> Usage:</span>
<span class="sd"> class C:</span>
<span class="sd"> __metaclass__ = ABCMeta</span>
<span class="sd"> @abstractproperty</span>
<span class="sd"> def my_abstract_property(self):</span>
<span class="sd"> ...</span>
<span class="sd"> This defines a read-only property; you can also define a read-write</span>
<span class="sd"> abstract property using the &#39;long&#39; form of property declaration:</span>
<span class="sd"> class C:</span>
<span class="sd"> __metaclass__ = ABCMeta</span>
<span class="sd"> def getx(self): ...</span>
<span class="sd"> def setx(self, value): ...</span>
<span class="sd"> x = abstractproperty(getx, setx)</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">__isabstractmethod__</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">class</span> <span class="nc">ABCMeta</span><span class="p">(</span><span class="nb">type</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Metaclass for defining Abstract Base Classes (ABCs).</span>
<span class="sd"> Use this metaclass to create an ABC. An ABC can be subclassed</span>
<span class="sd"> directly, and then acts as a mix-in class. You can also register</span>
<span class="sd"> unrelated concrete classes (even built-in classes) and unrelated</span>
<span class="sd"> ABCs as &#39;virtual subclasses&#39; -- these and their descendants will</span>
<span class="sd"> be considered subclasses of the registering ABC by the built-in</span>
<span class="sd"> issubclass() function, but the registering ABC won&#39;t show up in</span>
<span class="sd"> their MRO (Method Resolution Order) nor will method</span>
<span class="sd"> implementations defined by the registering ABC be callable (not</span>
<span class="sd"> even via super()).</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># A global counter that is incremented each time a class is</span>
<span class="c1"># registered as a virtual subclass of anything. It forces the</span>
<span class="c1"># negative cache to be cleared before its next use.</span>
<span class="n">_abc_invalidation_counter</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">def</span> <span class="nf">__new__</span><span class="p">(</span><span class="n">mcls</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">bases</span><span class="p">,</span> <span class="n">namespace</span><span class="p">):</span>
<span class="bp">cls</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">ABCMeta</span><span class="p">,</span> <span class="n">mcls</span><span class="p">)</span><span class="o">.</span><span class="fm">__new__</span><span class="p">(</span><span class="n">mcls</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">bases</span><span class="p">,</span> <span class="n">namespace</span><span class="p">)</span>
<span class="c1"># Compute set of abstract method names</span>
<span class="n">abstracts</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">name</span>
<span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">namespace</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
<span class="k">if</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="s2">&quot;__isabstractmethod__&quot;</span><span class="p">,</span> <span class="kc">False</span><span class="p">))</span>
<span class="k">for</span> <span class="n">base</span> <span class="ow">in</span> <span class="n">bases</span><span class="p">:</span>
<span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">base</span><span class="p">,</span> <span class="s2">&quot;__abstractmethods__&quot;</span><span class="p">,</span> <span class="nb">set</span><span class="p">()):</span>
<span class="n">value</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="s2">&quot;__isabstractmethod__&quot;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
<span class="n">abstracts</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">__abstractmethods__</span> <span class="o">=</span> <span class="nb">frozenset</span><span class="p">(</span><span class="n">abstracts</span><span class="p">)</span>
<span class="c1"># Set up inheritance registry</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_registry</span> <span class="o">=</span> <span class="n">WeakSet</span><span class="p">()</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_cache</span> <span class="o">=</span> <span class="n">WeakSet</span><span class="p">()</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_negative_cache</span> <span class="o">=</span> <span class="n">WeakSet</span><span class="p">()</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_negative_cache_version</span> <span class="o">=</span> <span class="n">ABCMeta</span><span class="o">.</span><span class="n">_abc_invalidation_counter</span>
<span class="k">return</span> <span class="bp">cls</span>
<span class="k">def</span> <span class="nf">register</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">subclass</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Register a virtual subclass of an ABC.&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">subclass</span><span class="p">,</span> <span class="p">(</span><span class="nb">type</span><span class="p">,</span> <span class="n">types</span><span class="o">.</span><span class="n">ClassType</span><span class="p">)):</span>
<span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;Can only register classes&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">issubclass</span><span class="p">(</span><span class="n">subclass</span><span class="p">,</span> <span class="bp">cls</span><span class="p">):</span>
<span class="k">return</span> <span class="c1"># Already a subclass</span>
<span class="c1"># Subtle: test for cycles *after* testing for &quot;already a subclass&quot;;</span>
<span class="c1"># this means we allow X.register(X) and interpret it as a no-op.</span>
<span class="k">if</span> <span class="nb">issubclass</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">subclass</span><span class="p">):</span>
<span class="c1"># This would create a cycle, which is bad for the algorithm below</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Refusing to create an inheritance cycle&quot;</span><span class="p">)</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_registry</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">subclass</span><span class="p">)</span>
<span class="n">ABCMeta</span><span class="o">.</span><span class="n">_abc_invalidation_counter</span> <span class="o">+=</span> <span class="mi">1</span> <span class="c1"># Invalidate negative cache</span>
<span class="k">def</span> <span class="nf">_dump_registry</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Debug helper to print the ABC registry.&quot;&quot;&quot;</span>
<span class="nb">print</span> <span class="o">&gt;&gt;</span> <span class="n">file</span><span class="p">,</span> <span class="s2">&quot;Class: </span><span class="si">%s</span><span class="s2">.</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="vm">__name__</span><span class="p">)</span>
<span class="nb">print</span> <span class="o">&gt;&gt;</span> <span class="n">file</span><span class="p">,</span> <span class="s2">&quot;Inv.counter: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">ABCMeta</span><span class="o">.</span><span class="n">_abc_invalidation_counter</span>
<span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="vm">__dict__</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
<span class="k">if</span> <span class="n">name</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;_abc_&quot;</span><span class="p">):</span>
<span class="n">value</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
<span class="nb">print</span> <span class="o">&gt;&gt;</span> <span class="n">file</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: </span><span class="si">%r</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">__instancecheck__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">instance</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Override for isinstance(instance, cls).&quot;&quot;&quot;</span>
<span class="c1"># Inline the cache checking when it&#39;s simple.</span>
<span class="n">subclass</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">instance</span><span class="p">,</span> <span class="s1">&#39;__class__&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">subclass</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">subclass</span> <span class="ow">in</span> <span class="bp">cls</span><span class="o">.</span><span class="n">_abc_cache</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="n">subtype</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="n">instance</span><span class="p">)</span>
<span class="c1"># Old-style instances</span>
<span class="k">if</span> <span class="n">subtype</span> <span class="ow">is</span> <span class="n">_InstanceType</span><span class="p">:</span>
<span class="n">subtype</span> <span class="o">=</span> <span class="n">subclass</span>
<span class="k">if</span> <span class="n">subtype</span> <span class="ow">is</span> <span class="n">subclass</span> <span class="ow">or</span> <span class="n">subclass</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="n">_abc_negative_cache_version</span> <span class="o">==</span>
<span class="n">ABCMeta</span><span class="o">.</span><span class="n">_abc_invalidation_counter</span> <span class="ow">and</span>
<span class="n">subtype</span> <span class="ow">in</span> <span class="bp">cls</span><span class="o">.</span><span class="n">_abc_negative_cache</span><span class="p">):</span>
<span class="k">return</span> <span class="kc">False</span>
<span class="c1"># Fall back to the subclass check.</span>
<span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="fm">__subclasscheck__</span><span class="p">(</span><span class="n">subtype</span><span class="p">)</span>
<span class="k">return</span> <span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="fm">__subclasscheck__</span><span class="p">(</span><span class="n">subclass</span><span class="p">)</span> <span class="ow">or</span>
<span class="bp">cls</span><span class="o">.</span><span class="fm">__subclasscheck__</span><span class="p">(</span><span class="n">subtype</span><span class="p">))</span>
<span class="k">def</span> <span class="nf">__subclasscheck__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">subclass</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Override for issubclass(subclass, cls).&quot;&quot;&quot;</span>
<span class="c1"># Check cache</span>
<span class="k">if</span> <span class="n">subclass</span> <span class="ow">in</span> <span class="bp">cls</span><span class="o">.</span><span class="n">_abc_cache</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="c1"># Check negative cache; may have to invalidate</span>
<span class="k">if</span> <span class="bp">cls</span><span class="o">.</span><span class="n">_abc_negative_cache_version</span> <span class="o">&lt;</span> <span class="n">ABCMeta</span><span class="o">.</span><span class="n">_abc_invalidation_counter</span><span class="p">:</span>
<span class="c1"># Invalidate the negative cache</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_negative_cache</span> <span class="o">=</span> <span class="n">WeakSet</span><span class="p">()</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_negative_cache_version</span> <span class="o">=</span> <span class="n">ABCMeta</span><span class="o">.</span><span class="n">_abc_invalidation_counter</span>
<span class="k">elif</span> <span class="n">subclass</span> <span class="ow">in</span> <span class="bp">cls</span><span class="o">.</span><span class="n">_abc_negative_cache</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">False</span>
<span class="c1"># Check the subclass hook</span>
<span class="n">ok</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">__subclasshook__</span><span class="p">(</span><span class="n">subclass</span><span class="p">)</span>
<span class="k">if</span> <span class="n">ok</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">NotImplemented</span><span class="p">:</span>
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ok</span><span class="p">,</span> <span class="nb">bool</span><span class="p">)</span>
<span class="k">if</span> <span class="n">ok</span><span class="p">:</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_cache</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">subclass</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_negative_cache</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">subclass</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ok</span>
<span class="c1"># Check if it&#39;s a direct subclass</span>
<span class="k">if</span> <span class="bp">cls</span> <span class="ow">in</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">subclass</span><span class="p">,</span> <span class="s1">&#39;__mro__&#39;</span><span class="p">,</span> <span class="p">()):</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_cache</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">subclass</span><span class="p">)</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="c1"># Check if it&#39;s a subclass of a registered class (recursive)</span>
<span class="k">for</span> <span class="n">rcls</span> <span class="ow">in</span> <span class="bp">cls</span><span class="o">.</span><span class="n">_abc_registry</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">issubclass</span><span class="p">(</span><span class="n">subclass</span><span class="p">,</span> <span class="n">rcls</span><span class="p">):</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_cache</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">subclass</span><span class="p">)</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="c1"># Check if it&#39;s a subclass of a subclass (recursive)</span>
<span class="k">for</span> <span class="n">scls</span> <span class="ow">in</span> <span class="bp">cls</span><span class="o">.</span><span class="n">__subclasses__</span><span class="p">():</span>
<span class="k">if</span> <span class="nb">issubclass</span><span class="p">(</span><span class="n">subclass</span><span class="p">,</span> <span class="n">scls</span><span class="p">):</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_cache</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">subclass</span><span class="p">)</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="c1"># No dice; update negative cache</span>
<span class="bp">cls</span><span class="o">.</span><span class="n">_abc_negative_cache</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">subclass</span><span class="p">)</span>
<span class="k">return</span> <span class="kc">False</span>
</pre></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../index.html">
<img class="logo" src="../_static/nifty_logo_black.png" alt="Logo"/>
</a></p><div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="../index.html">Documentation overview</a><ul>
<li><a href="index.html">Module code</a><ul>
</ul></li>
</ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2017, Theo Steininger.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.1</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.10</a>
</div>
</body>
</html>
\ No newline at end of file
<!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/html; charset=utf-8" />
<title>Overview: module code &#8212; NIFTY 3.0.x documentation</title>
<link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '3.0.x',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head>
<body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>All modules for which code is available</h1>
<ul><li><a href="abc.html">abc</a></li>
<li><a href="nifty/field.html">nifty.field</a></li>
<li><a href="nifty/minimization/conjugate_gradient.html">nifty.minimization.conjugate_gradient</a></li>
<li><a href="nifty/minimization/descent_minimizer.html">nifty.minimization.descent_minimizer</a></li>
<li><a href="nifty/operators/composed_operator/composed_operator.html">nifty.operators.composed_operator.composed_operator</a></li>
<li><a href="nifty/operators/diagonal_operator/diagonal_operator.html">nifty.operators.diagonal_operator.diagonal_operator</a></li>
<li><a href="nifty/operators/fft_operator/fft_operator.html">nifty.operators.fft_operator.fft_operator</a></li>
<li><a href="nifty/operators/fft_operator/transformations/gllmtransformation.html">nifty.operators.fft_operator.transformations.gllmtransformation</a></li>
<li><a href="nifty/operators/fft_operator/transformations/hplmtransformation.html">nifty.operators.fft_operator.transformations.hplmtransformation</a></li>
<li><a href="nifty/operators/fft_operator/transformations/lmgltransformation.html">nifty.operators.fft_operator.transformations.lmgltransformation</a></li>
<li><a href="nifty/operators/fft_operator/transformations/lmhptransformation.html">nifty.operators.fft_operator.transformations.lmhptransformation</a></li>
<li><a href="nifty/operators/fft_operator/transformations/rgrgtransformation.html">nifty.operators.fft_operator.transformations.rgrgtransformation</a></li>
<li><a href="nifty/operators/invertible_operator_mixin/invertible_operator_mixin.html">nifty.operators.invertible_operator_mixin.invertible_operator_mixin</a></li>
<li><a href="nifty/operators/linear_operator/linear_operator.html">nifty.operators.linear_operator.linear_operator</a></li>
<li><a href="nifty/operators/projection_operator/projection_operator.html">nifty.operators.projection_operator.projection_operator</a></li>
<li><a href="nifty/operators/propagator_operator/propagator_operator.html">nifty.operators.propagator_operator.propagator_operator</a></li>
<li><a href="nifty/operators/response_operator/response_operator.html">nifty.operators.response_operator.response_operator</a></li>
<li><a href="nifty/operators/smoothing_operator/smoothing_operator.html">nifty.operators.smoothing_operator.smoothing_operator</a></li>
<li><a href="nifty/spaces/gl_space/gl_space.html">nifty.spaces.gl_space.gl_space</a></li>
<li><a href="nifty/spaces/hp_space/hp_space.html">nifty.spaces.hp_space.hp_space</a></li>
<li><a href="nifty/spaces/lm_space/lm_space.html">nifty.spaces.lm_space.lm_space</a></li>
<li><a href="nifty/spaces/power_space/power_space.html">nifty.spaces.power_space.power_space</a></li>
<li><a href="nifty/spaces/rg_space/rg_space.html">nifty.spaces.rg_space.rg_space</a></li>
<li><a href="nifty/spaces/space/space.html">nifty.spaces.space.space</a></li>
</ul>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../index.html">
<img class="logo" src="../_static/nifty_logo_black.png" alt="Logo"/>
</a></p><div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="../index.html">Documentation overview</a><ul>
</ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2017, Theo Steininger.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.1</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.10</a>
</div>
</body>
</html>
\ No newline at end of file
<!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/html; charset=utf-8" />
<title>nifty.field &#8212; NIFTY 3.0.x documentation</title>
<link rel="stylesheet" href="../../_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../',
VERSION: '3.0.x',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head>
<body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for nifty.field</h1><div class="highlight"><pre>
<span></span><span class="c1"># NIFTy</span>
<span class="c1"># Copyright (C) 2017 Theo Steininger</span>
<span class="c1">#</span>
<span class="c1"># Author: Theo Steininger</span>
<span class="c1">#</span>
<span class="c1"># This program is free software: you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation, either version 3 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">division</span>
<span class="kn">import</span> <span class="nn">itertools</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">keepers</span> <span class="k">import</span> <span class="n">Versionable</span><span class="p">,</span>\
<span class="n">Loggable</span>
<span class="kn">from</span> <span class="nn">d2o</span> <span class="k">import</span> <span class="n">distributed_data_object</span><span class="p">,</span>\
<span class="n">STRATEGIES</span> <span class="k">as</span> <span class="n">DISTRIBUTION_STRATEGIES</span>
<span class="kn">from</span> <span class="nn">nifty.config</span> <span class="k">import</span> <span class="n">nifty_configuration</span> <span class="k">as</span> <span class="n">gc</span>
<span class="kn">from</span> <span class="nn">nifty.domain_object</span> <span class="k">import</span> <span class="n">DomainObject</span>
<span class="kn">from</span> <span class="nn">nifty.spaces.power_space</span> <span class="k">import</span> <span class="n">PowerSpace</span>
<span class="kn">import</span> <span class="nn">nifty.nifty_utilities</span> <span class="k">as</span> <span class="nn">utilities</span>
<span class="kn">from</span> <span class="nn">nifty.random</span> <span class="k">import</span> <span class="n">Random</span>
<div class="viewcode-block" id="Field"><a class="viewcode-back" href="../../nifty.Field.html#nifty.Field">[docs]</a><span class="k">class</span> <span class="nc">Field</span><span class="p">(</span><span class="n">Loggable</span><span class="p">,</span> <span class="n">Versionable</span><span class="p">,</span> <span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; The discrete representation of a continuous field over multiple spaces.</span>
<span class="sd"> In NIFTY, Fields are used to store data arrays and carry all the needed</span>
<span class="sd"> metainformation (i.e. the domain) for operators to be able to work on them.</span>
<span class="sd"> In addition Field has methods to work with power-spectra.</span>
<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> domain : DomainObject</span>
<span class="sd"> One of the space types NIFTY supports. RGSpace, GLSpace, HPSpace,</span>
<span class="sd"> LMSpace or PowerSpace. It might also be a FieldArray, which is</span>
<span class="sd"> an unstructured domain.</span>
<span class="sd"> val : scalar, numpy.ndarray, distributed_data_object, Field</span>
<span class="sd"> The values the array should contain after init. A scalar input will</span>
<span class="sd"> fill the whole array with this scalar. If an array is provided the</span>
<span class="sd"> array&#39;s dimensions must match the domain&#39;s.</span>
<span class="sd"> dtype : type</span>
<span class="sd"> A numpy.type. Most common are int, float and complex.</span>
<span class="sd"> distribution_strategy: optional[{&#39;fftw&#39;, &#39;equal&#39;, &#39;not&#39;, &#39;freeform&#39;}]</span>
<span class="sd"> Specifies which distributor will be created and used.</span>
<span class="sd"> &#39;fftw&#39; uses the distribution strategy of pyfftw,</span>
<span class="sd"> &#39;equal&#39; tries to distribute the data as uniform as possible</span>
<span class="sd"> &#39;not&#39; does not distribute the data at all</span>
<span class="sd"> &#39;freeform&#39; distribute the data according to the given local data/shape</span>
<span class="sd"> copy: boolean</span>
<span class="sd"> Attributes</span>
<span class="sd"> ----------</span>
<span class="sd"> val : distributed_data_object</span>
<span class="sd"> domain : DomainObject</span>
<span class="sd"> See Parameters.</span>
<span class="sd"> domain_axes : tuple of tuples</span>
<span class="sd"> Enumerates the axes of the Field</span>
<span class="sd"> dtype : type</span>
<span class="sd"> Contains the datatype stored in the Field.</span>
<span class="sd"> distribution_strategy : string</span>
<span class="sd"> Name of the used distribution_strategy.</span>
<span class="sd"> Raise</span>
<span class="sd"> -----</span>
<span class="sd"> TypeError</span>
<span class="sd"> Raised if</span>
<span class="sd"> *the given domain contains something that is not a DomainObject</span>
<span class="sd"> instance</span>
<span class="sd"> *val is an array that has a different dimension than the domain</span>
<span class="sd"> Examples</span>
<span class="sd"> --------</span>
<span class="sd"> &gt;&gt;&gt; a = Field(RGSpace([4,5]),val=2)</span>
<span class="sd"> &gt;&gt;&gt; a.val</span>
<span class="sd"> &lt;distributed_data_object&gt;</span>
<span class="sd"> array([[2, 2, 2, 2, 2],</span>
<span class="sd"> [2, 2, 2, 2, 2],</span>
<span class="sd"> [2, 2, 2, 2, 2],</span>
<span class="sd"> [2, 2, 2, 2, 2]])</span>
<span class="sd"> &gt;&gt;&gt; a.dtype</span>