dtype.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>dtype - Boost.Python NumPy extension 1.0 documentation</title>
  7. <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  8. <link rel="stylesheet" href="../_static/style.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '../',
  12. VERSION: '1.0',
  13. COLLAPSE_MODINDEX: false,
  14. FILE_SUFFIX: '.html'
  15. };
  16. </script>
  17. <script type="text/javascript" src="../_static/jquery.js"></script>
  18. <script type="text/javascript" src="../_static/underscore.js"></script>
  19. <script type="text/javascript" src="../_static/doctools.js"></script>
  20. <link rel="index" title="Index" href="../genindex.html" />
  21. <link rel="search" title="Search" href="../search.html" />
  22. <link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
  23. <link rel="up" title="Boost.Python NumPy extension Reference" href="index.html" />
  24. <link rel="next" title="ndarray" href="ndarray.html" />
  25. <link rel="prev" title="Boost.Python NumPy extension Reference" href="index.html" />
  26. </head>
  27. <body>
  28. <div class="header">
  29. <table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
  30. "header">
  31. <tr>
  32. <td valign="top" width="300">
  33. <h3><a href="../index.html"><img
  34. alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
  35. </td>
  36. <td >
  37. <h1 align="center"><a href="../index.html">(NumPy)</a></h1>
  38. <!-- <h2 align="center">CallPolicies Concept</h2>-->
  39. </td>
  40. <td>
  41. <div id="searchbox" style="display: none">
  42. <form class="search" action="../search.html" method="get">
  43. <input type="text" name="q" size="18" />
  44. <input type="submit" value="Search" />
  45. <input type="hidden" name="check_keywords" value="yes" />
  46. <input type="hidden" name="area" value="default" />
  47. </form>
  48. </div>
  49. <script type="text/javascript">$('#searchbox').show(0);</script>
  50. </td>
  51. </tr>
  52. </table>
  53. </div>
  54. <hr/>
  55. <div class="content">
  56. <div class="navbar" style="text-align:right;">
  57. <a class="prev" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/prev.png" alt="prev"/></a>
  58. <a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
  59. <a class="next" title="ndarray" href="ndarray.html"><img src="../_static/next.png" alt="next"/></a>
  60. </div>
  61. <div class="section" id="dtype">
  62. <h1><a class="toc-backref" href="#id2">dtype</a></h1>
  63. <div class="contents topic" id="table-of-contents">
  64. <p class="topic-title first">Table of Contents</p>
  65. <ul class="simple">
  66. <li><a class="reference internal" href="#dtype" id="id2">dtype</a><ul>
  67. <li><a class="reference internal" href="#synopsis" id="id3">synopsis</a></li>
  68. <li><a class="reference internal" href="#constructors" id="id4">constructors</a></li>
  69. <li><a class="reference internal" href="#accessors" id="id5">accessors</a></li>
  70. <li><a class="reference internal" href="#example-s" id="id6">Example(s)</a></li>
  71. </ul>
  72. </li>
  73. </ul>
  74. </div>
  75. <p>A <a class="reference external" href="http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#data-type-objects-dtype">dtype</a> is an object describing the type of the elements of an ndarray</p>
  76. <blockquote>
  77. <div><code class="docutils literal"><span class="pre">&lt;boost/python/numpy/dtype.hpp&gt;</span></code> contains the method calls necessary to generate a python object equivalent to a numpy.dtype from builtin C++ objects, as well as to create custom dtypes from user defined types</div></blockquote>
  78. <div class="section" id="synopsis">
  79. <h2><a class="toc-backref" href="#id3">synopsis</a></h2>
  80. <div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">boost</span>
  81. <span class="p">{</span>
  82. <span class="k">namespace</span> <span class="n">python</span>
  83. <span class="p">{</span>
  84. <span class="k">namespace</span> <span class="n">numpy</span>
  85. <span class="p">{</span>
  86. <span class="k">class</span> <span class="nc">dtype</span> <span class="o">:</span> <span class="k">public</span> <span class="n">object</span>
  87. <span class="p">{</span>
  88. <span class="k">static</span> <span class="n">python</span><span class="o">::</span><span class="n">detail</span><span class="o">::</span><span class="n">new_reference</span> <span class="n">convert</span><span class="p">(</span><span class="n">object</span><span class="o">::</span><span class="n">object_cref</span> <span class="n">arg</span><span class="p">,</span> <span class="kt">bool</span> <span class="n">align</span><span class="p">);</span>
  89. <span class="k">public</span><span class="o">:</span>
  90. <span class="c1">// Convert an arbitrary Python object to a data-type descriptor object.</span>
  91. <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
  92. <span class="k">explicit</span> <span class="n">dtype</span><span class="p">(</span><span class="n">T</span> <span class="n">arg</span><span class="p">,</span> <span class="kt">bool</span> <span class="n">align</span><span class="o">=</span><span class="nb">false</span><span class="p">);</span>
  93. <span class="c1">// Get the built-in numpy dtype associated with the given scalar template type.</span>
  94. <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span> <span class="k">static</span> <span class="n">dtype</span> <span class="n">get_builtin</span><span class="p">();</span>
  95. <span class="c1">// Return the size of the data type in bytes.</span>
  96. <span class="kt">int</span> <span class="nf">get_itemsize</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
  97. <span class="p">};</span>
  98. <span class="p">}</span>
  99. <span class="p">}</span>
  100. <span class="p">}</span>
  101. </pre></div>
  102. </div>
  103. </div>
  104. <div class="section" id="constructors">
  105. <h2><a class="toc-backref" href="#id4">constructors</a></h2>
  106. <div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
  107. <span class="k">explicit</span> <span class="n">dtype</span><span class="p">(</span><span class="n">T</span> <span class="n">arg</span><span class="p">,</span> <span class="kt">bool</span> <span class="n">align</span><span class="o">=</span><span class="nb">false</span><span class="p">)</span>
  108. </pre></div>
  109. </div>
  110. <table class="docutils field-list" frame="void" rules="none">
  111. <col class="field-name" />
  112. <col class="field-body" />
  113. <tbody valign="top">
  114. <tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body"><p class="first"><code class="docutils literal"><span class="pre">T</span></code> must be either :</p>
  115. <ul class="simple">
  116. <li>a built-in C++ typename convertible to object</li>
  117. <li>a valid python object or convertible to object</li>
  118. </ul>
  119. </td>
  120. </tr>
  121. <tr class="field-even field"><th class="field-name">Effects:</th><td class="field-body"><p class="first">Constructs an object from the supplied python object / convertible
  122. to object / builtin C++ data type</p>
  123. </td>
  124. </tr>
  125. <tr class="field-odd field"><th class="field-name">Throws:</th><td class="field-body"><p class="first last">Nothing</p>
  126. </td>
  127. </tr>
  128. </tbody>
  129. </table>
  130. <div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span> <span class="k">static</span> <span class="n">dtype</span> <span class="n">get_builtin</span><span class="p">();</span>
  131. </pre></div>
  132. </div>
  133. <table class="docutils field-list" frame="void" rules="none">
  134. <col class="field-name" />
  135. <col class="field-body" />
  136. <tbody valign="top">
  137. <tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body">The typename supplied, <code class="docutils literal"><span class="pre">T</span></code> must be a builtin C++ type also supported by numpy</td>
  138. </tr>
  139. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Numpy dtype corresponding to builtin C++ type</td>
  140. </tr>
  141. </tbody>
  142. </table>
  143. </div>
  144. <div class="section" id="accessors">
  145. <h2><a class="toc-backref" href="#id5">accessors</a></h2>
  146. <div class="highlight-c++"><div class="highlight"><pre><span class="kt">int</span> <span class="nf">get_itemsize</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
  147. </pre></div>
  148. </div>
  149. <table class="docutils field-list" frame="void" rules="none">
  150. <col class="field-name" />
  151. <col class="field-body" />
  152. <tbody valign="top">
  153. <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">the size of the data type in bytes.</td>
  154. </tr>
  155. </tbody>
  156. </table>
  157. </div>
  158. <div class="section" id="example-s">
  159. <h2><a class="toc-backref" href="#id6">Example(s)</a></h2>
  160. <div class="highlight-c++"><div class="highlight"><pre><span class="k">namespace</span> <span class="n">p</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="p">;</span>
  161. <span class="k">namespace</span> <span class="n">np</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="o">::</span><span class="n">numpy</span><span class="p">;</span>
  162. <span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">dtype</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="o">::</span><span class="n">get_builtin</span><span class="o">&lt;</span><span class="kt">double</span><span class="o">&gt;</span><span class="p">();</span>
  163. <span class="n">p</span><span class="o">::</span><span class="n">tuple</span> <span class="n">for_custom_dtype</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="s">&quot;ha&quot;</span><span class="p">,</span><span class="n">dtype</span><span class="p">);</span>
  164. <span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">custom_dtype</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="p">(</span><span class="n">list_for_dtype</span><span class="p">);</span>
  165. </pre></div>
  166. </div>
  167. </div>
  168. </div>
  169. <div class="navbar" style="text-align:right;">
  170. <a class="prev" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/prev.png" alt="prev"/></a>
  171. <a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
  172. <a class="next" title="ndarray" href="ndarray.html"><img src="../_static/next.png" alt="next"/></a>
  173. </div>
  174. </div>
  175. </body>
  176. </html>