constants.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. """
  2. =========
  3. Constants
  4. =========
  5. Numpy includes several constants:
  6. %(constant_list)s
  7. """
  8. #
  9. # Note: the docstring is autogenerated.
  10. #
  11. from __future__ import division, absolute_import, print_function
  12. import textwrap, re
  13. # Maintain same format as in numpy.add_newdocs
  14. constants = []
  15. def add_newdoc(module, name, doc):
  16. constants.append((name, doc))
  17. add_newdoc('numpy', 'Inf',
  18. """
  19. IEEE 754 floating point representation of (positive) infinity.
  20. Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for
  21. `inf`. For more details, see `inf`.
  22. See Also
  23. --------
  24. inf
  25. """)
  26. add_newdoc('numpy', 'Infinity',
  27. """
  28. IEEE 754 floating point representation of (positive) infinity.
  29. Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for
  30. `inf`. For more details, see `inf`.
  31. See Also
  32. --------
  33. inf
  34. """)
  35. add_newdoc('numpy', 'NAN',
  36. """
  37. IEEE 754 floating point representation of Not a Number (NaN).
  38. `NaN` and `NAN` are equivalent definitions of `nan`. Please use
  39. `nan` instead of `NAN`.
  40. See Also
  41. --------
  42. nan
  43. """)
  44. add_newdoc('numpy', 'NINF',
  45. """
  46. IEEE 754 floating point representation of negative infinity.
  47. Returns
  48. -------
  49. y : float
  50. A floating point representation of negative infinity.
  51. See Also
  52. --------
  53. isinf : Shows which elements are positive or negative infinity
  54. isposinf : Shows which elements are positive infinity
  55. isneginf : Shows which elements are negative infinity
  56. isnan : Shows which elements are Not a Number
  57. isfinite : Shows which elements are finite (not one of Not a Number,
  58. positive infinity and negative infinity)
  59. Notes
  60. -----
  61. Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
  62. (IEEE 754). This means that Not a Number is not equivalent to infinity.
  63. Also that positive infinity is not equivalent to negative infinity. But
  64. infinity is equivalent to positive infinity.
  65. Examples
  66. --------
  67. >>> np.NINF
  68. -inf
  69. >>> np.log(0)
  70. -inf
  71. """)
  72. add_newdoc('numpy', 'NZERO',
  73. """
  74. IEEE 754 floating point representation of negative zero.
  75. Returns
  76. -------
  77. y : float
  78. A floating point representation of negative zero.
  79. See Also
  80. --------
  81. PZERO : Defines positive zero.
  82. isinf : Shows which elements are positive or negative infinity.
  83. isposinf : Shows which elements are positive infinity.
  84. isneginf : Shows which elements are negative infinity.
  85. isnan : Shows which elements are Not a Number.
  86. isfinite : Shows which elements are finite - not one of
  87. Not a Number, positive infinity and negative infinity.
  88. Notes
  89. -----
  90. Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
  91. (IEEE 754). Negative zero is considered to be a finite number.
  92. Examples
  93. --------
  94. >>> np.NZERO
  95. -0.0
  96. >>> np.PZERO
  97. 0.0
  98. >>> np.isfinite([np.NZERO])
  99. array([ True], dtype=bool)
  100. >>> np.isnan([np.NZERO])
  101. array([False], dtype=bool)
  102. >>> np.isinf([np.NZERO])
  103. array([False], dtype=bool)
  104. """)
  105. add_newdoc('numpy', 'NaN',
  106. """
  107. IEEE 754 floating point representation of Not a Number (NaN).
  108. `NaN` and `NAN` are equivalent definitions of `nan`. Please use
  109. `nan` instead of `NaN`.
  110. See Also
  111. --------
  112. nan
  113. """)
  114. add_newdoc('numpy', 'PINF',
  115. """
  116. IEEE 754 floating point representation of (positive) infinity.
  117. Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for
  118. `inf`. For more details, see `inf`.
  119. See Also
  120. --------
  121. inf
  122. """)
  123. add_newdoc('numpy', 'PZERO',
  124. """
  125. IEEE 754 floating point representation of positive zero.
  126. Returns
  127. -------
  128. y : float
  129. A floating point representation of positive zero.
  130. See Also
  131. --------
  132. NZERO : Defines negative zero.
  133. isinf : Shows which elements are positive or negative infinity.
  134. isposinf : Shows which elements are positive infinity.
  135. isneginf : Shows which elements are negative infinity.
  136. isnan : Shows which elements are Not a Number.
  137. isfinite : Shows which elements are finite - not one of
  138. Not a Number, positive infinity and negative infinity.
  139. Notes
  140. -----
  141. Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
  142. (IEEE 754). Positive zero is considered to be a finite number.
  143. Examples
  144. --------
  145. >>> np.PZERO
  146. 0.0
  147. >>> np.NZERO
  148. -0.0
  149. >>> np.isfinite([np.PZERO])
  150. array([ True], dtype=bool)
  151. >>> np.isnan([np.PZERO])
  152. array([False], dtype=bool)
  153. >>> np.isinf([np.PZERO])
  154. array([False], dtype=bool)
  155. """)
  156. add_newdoc('numpy', 'e',
  157. """
  158. Euler's constant, base of natural logarithms, Napier's constant.
  159. ``e = 2.71828182845904523536028747135266249775724709369995...``
  160. See Also
  161. --------
  162. exp : Exponential function
  163. log : Natural logarithm
  164. References
  165. ----------
  166. .. [1] http://en.wikipedia.org/wiki/Napier_constant
  167. """)
  168. add_newdoc('numpy', 'inf',
  169. """
  170. IEEE 754 floating point representation of (positive) infinity.
  171. Returns
  172. -------
  173. y : float
  174. A floating point representation of positive infinity.
  175. See Also
  176. --------
  177. isinf : Shows which elements are positive or negative infinity
  178. isposinf : Shows which elements are positive infinity
  179. isneginf : Shows which elements are negative infinity
  180. isnan : Shows which elements are Not a Number
  181. isfinite : Shows which elements are finite (not one of Not a Number,
  182. positive infinity and negative infinity)
  183. Notes
  184. -----
  185. Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
  186. (IEEE 754). This means that Not a Number is not equivalent to infinity.
  187. Also that positive infinity is not equivalent to negative infinity. But
  188. infinity is equivalent to positive infinity.
  189. `Inf`, `Infinity`, `PINF` and `infty` are aliases for `inf`.
  190. Examples
  191. --------
  192. >>> np.inf
  193. inf
  194. >>> np.array([1]) / 0.
  195. array([ Inf])
  196. """)
  197. add_newdoc('numpy', 'infty',
  198. """
  199. IEEE 754 floating point representation of (positive) infinity.
  200. Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for
  201. `inf`. For more details, see `inf`.
  202. See Also
  203. --------
  204. inf
  205. """)
  206. add_newdoc('numpy', 'nan',
  207. """
  208. IEEE 754 floating point representation of Not a Number (NaN).
  209. Returns
  210. -------
  211. y : A floating point representation of Not a Number.
  212. See Also
  213. --------
  214. isnan : Shows which elements are Not a Number.
  215. isfinite : Shows which elements are finite (not one of
  216. Not a Number, positive infinity and negative infinity)
  217. Notes
  218. -----
  219. Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
  220. (IEEE 754). This means that Not a Number is not equivalent to infinity.
  221. `NaN` and `NAN` are aliases of `nan`.
  222. Examples
  223. --------
  224. >>> np.nan
  225. nan
  226. >>> np.log(-1)
  227. nan
  228. >>> np.log([-1, 1, 2])
  229. array([ NaN, 0. , 0.69314718])
  230. """)
  231. add_newdoc('numpy', 'newaxis',
  232. """
  233. A convenient alias for None, useful for indexing arrays.
  234. See Also
  235. --------
  236. `numpy.doc.indexing`
  237. Examples
  238. --------
  239. >>> newaxis is None
  240. True
  241. >>> x = np.arange(3)
  242. >>> x
  243. array([0, 1, 2])
  244. >>> x[:, newaxis]
  245. array([[0],
  246. [1],
  247. [2]])
  248. >>> x[:, newaxis, newaxis]
  249. array([[[0]],
  250. [[1]],
  251. [[2]]])
  252. >>> x[:, newaxis] * x
  253. array([[0, 0, 0],
  254. [0, 1, 2],
  255. [0, 2, 4]])
  256. Outer product, same as ``outer(x, y)``:
  257. >>> y = np.arange(3, 6)
  258. >>> x[:, newaxis] * y
  259. array([[ 0, 0, 0],
  260. [ 3, 4, 5],
  261. [ 6, 8, 10]])
  262. ``x[newaxis, :]`` is equivalent to ``x[newaxis]`` and ``x[None]``:
  263. >>> x[newaxis, :].shape
  264. (1, 3)
  265. >>> x[newaxis].shape
  266. (1, 3)
  267. >>> x[None].shape
  268. (1, 3)
  269. >>> x[:, newaxis].shape
  270. (3, 1)
  271. """)
  272. if __doc__:
  273. constants_str = []
  274. constants.sort()
  275. for name, doc in constants:
  276. s = textwrap.dedent(doc).replace("\n", "\n ")
  277. # Replace sections by rubrics
  278. lines = s.split("\n")
  279. new_lines = []
  280. for line in lines:
  281. m = re.match(r'^(\s+)[-=]+\s*$', line)
  282. if m and new_lines:
  283. prev = textwrap.dedent(new_lines.pop())
  284. new_lines.append('%s.. rubric:: %s' % (m.group(1), prev))
  285. new_lines.append('')
  286. else:
  287. new_lines.append(line)
  288. s = "\n".join(new_lines)
  289. # Done.
  290. constants_str.append(""".. const:: %s\n %s""" % (name, s))
  291. constants_str = "\n".join(constants_str)
  292. __doc__ = __doc__ % dict(constant_list=constants_str)
  293. del constants_str, name, doc
  294. del line, lines, new_lines, m, s, prev
  295. del constants, add_newdoc