/ lib / numpy / core / numerictypes.pyc
numerictypes.pyc
  1  o

  2  [��c�E�
  3  @szdZddlZddlmZmZmZmZmZmZm	Z	m
  4  Z
  5  mZddlm
Z
gd�ZddlmZmZmZmZmZddlmZmZmZmZmZmZmZdd	lmZdd
  6  lm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)edZ*gd
�Z+e
d�dd��Z,e
d�dd��Z-e
d�d>dd��Z.e
d�dd��Z/e
d�dd��Z0e
d�dd��Z1Gdd�de2�Z3e3�Z4e3�Z5e3�Z6e3�Z7dd�Z8e8�e
d�dd ��Z9e3�Z:eD]
  7  Z;e;fd!d"�e:e;<q�d#d$�Z<e!e"e#e e&e%e=gZ>e>e?ee<d%�7Z>e@e>�Z>eD]Z;ee;eA�e;<e�Be;�q�[;d&d'd(d)d*d+d,d-d.d/�	ZCeZDgd0�ZEd1eCd2dd3�eCd4d5ZFeGeF�ZHd6d7�ZId?d8d9�ZJd:d;�ZKeK�e
d�d<d=��ZLdS)@a�
  8  numerictypes: Define the numeric type objects
  9  
 10  This module is designed so "from numerictypes import \*" is safe.
 11  Exported symbols include:
 12  
 13    Dictionary with all registered number types (including aliases):
 14      sctypeDict
 15  
 16    Type objects (not all will be available, depends on platform):
 17        see variable sctypes for which ones you have
 18  
 19      Bit-width names
 20  
 21      int8 int16 int32 int64 int128
 22      uint8 uint16 uint32 uint64 uint128
 23      float16 float32 float64 float96 float128 float256
 24      complex32 complex64 complex128 complex192 complex256 complex512
 25      datetime64 timedelta64
 26  
 27      c-based names
 28  
 29      bool_
 30  
 31      object_
 32  
 33      void, str_, unicode_
 34  
 35      byte, ubyte,
 36      short, ushort
 37      intc, uintc,
 38      intp, uintp,
 39      int_, uint,
 40      longlong, ulonglong,
 41  
 42      single, csingle,
 43      float_, complex_,
 44      longfloat, clongfloat,
 45  
 46     As part of the type-hierarchy:    xx -- is bit-width
 47  
 48     generic
 49       +-> bool_                                  (kind=b)
 50       +-> number
 51       |   +-> integer
 52       |   |   +-> signedinteger     (intxx)      (kind=i)
 53       |   |   |     byte
 54       |   |   |     short
 55       |   |   |     intc
 56       |   |   |     intp
 57       |   |   |     int_
 58       |   |   |     longlong
 59       |   |   \-> unsignedinteger  (uintxx)     (kind=u)
 60       |   |         ubyte
 61       |   |         ushort
 62       |   |         uintc
 63       |   |         uintp
 64       |   |         uint_
 65       |   |         ulonglong
 66       |   +-> inexact
 67       |       +-> floating          (floatxx)    (kind=f)
 68       |       |     half
 69       |       |     single
 70       |       |     float_          (double)
 71       |       |     longfloat
 72       |       \-> complexfloating  (complexxx)  (kind=c)
 73       |             csingle         (singlecomplex)
 74       |             complex_        (cfloat, cdouble)
 75       |             clongfloat      (longcomplex)
 76       +-> flexible
 77       |   +-> character
 78       |   |     str_     (string_, bytes_)       (kind=S)    [Python 2]
 79       |   |     unicode_                         (kind=U)    [Python 2]
 80       |   |
 81       |   |     bytes_   (string_)               (kind=S)    [Python 3]
 82       |   |     str_     (unicode_)              (kind=U)    [Python 3]
 83       |   |
 84       |   \-> void                              (kind=V)
 85       \-> object_ (not used much)               (kind=O)
 86  
 87  �N)	�ndarray�array�dtype�
datetime_data�datetime_as_string�
busday_offset�busday_count�	is_busday�busdaycalendar)�
 88  set_module)�
 89  sctypeDict�sctypes�
 90  ScalarType�
 91  obj2sctype�cast�nbytes�sctype2char�maximum_sctype�issctype�	typecodes�find_common_type�
 92  issubdtyperrrrr	r
 93  �)�
english_lower�
english_upper�english_capitalize�LOWER_TABLE�UPPER_TABLE)r�allTypes�bitnamer
�_concrete_types�_concrete_typeinfo�_bits_of)�
 94  _kind_name)�bool�int�float�complex�object�str�bytes)�long�unicode�generic)r$�int8�uint8�int16�uint16�int32�uint32�int64�uint64�int128�uint128�float16�float32�float64�float80�float96�float128�float256Z	complex32�	complex64�
 95  complex128�
 96  complex160�
 97  complex192�
 98  complex256�
 99  complex512r(�numpycCs<t|�}|dur
100  |S|}tt|��}|tvrt|dS|S)ai
101      Return the scalar type of highest precision of the same kind as the input.
102  
103      Parameters
104      ----------
105      t : dtype or dtype specifier
106          The input data type. This can be a `dtype` object or an object that
107          is convertible to a `dtype`.
108  
109      Returns
110      -------
111      out : dtype
112          The highest precision data type of the same kind (`dtype.kind`) as `t`.
113  
114      See Also
115      --------
116      obj2sctype, mintypecode, sctype2char
117      dtype
118  
119      Examples
120      --------
121      >>> np.maximum_sctype(int)
122      <class 'numpy.int64'>
123      >>> np.maximum_sctype(np.uint8)
124      <class 'numpy.uint64'>
125      >>> np.maximum_sctype(complex)
126      <class 'numpy.complex256'> # may vary
127  
128      >>> np.maximum_sctype(str)
129      <class 'numpy.str_'>
130  
131      >>> np.maximum_sctype('i2')
132      <class 'numpy.int64'>
133      >>> np.maximum_sctype('f4')
134      <class 'numpy.float128'> # may vary
135  
136      N�����)rr#rr
)�t�g�base�rJ��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\core\numerictypes.pyr�s'rcCsHt|ttf�s	dSzt|�}|r|tkrWdSWdSty#YdSw)ax
137      Determines whether the given object represents a scalar data-type.
138  
139      Parameters
140      ----------
141      rep : any
142          If `rep` is an instance of a scalar dtype, True is returned. If not,
143          False is returned.
144  
145      Returns
146      -------
147      out : bool
148          Boolean result of check whether `rep` is a scalar dtype.
149  
150      See Also
151      --------
152      issubsctype, issubdtype, obj2sctype, sctype2char
153  
154      Examples
155      --------
156      >>> np.issctype(np.int32)
157      True
158      >>> np.issctype(list)
159      False
160      >>> np.issctype(1.1)
161      False
162  
163      Strings are also a scalar type:
164  
165      >>> np.issctype(np.dtype('str'))
166      True
167  
168      FT)�
169  isinstance�typerr�object_�	Exception)�rep�resrJrJrKr�s#�rcCsRt|t�rt|t�r|St|t�r|jjSzt|�}W|jSty(|YSw)a�
170      Return the scalar dtype or NumPy equivalent of Python type of an object.
171  
172      Parameters
173      ----------
174      rep : any
175          The object of which the type is returned.
176      default : any, optional
177          If given, this is returned for objects whose types can not be
178          determined. If not given, None is returned for those objects.
179  
180      Returns
181      -------
182      dtype : dtype or Python type
183          The data type of `rep`.
184  
185      See Also
186      --------
187      sctype2char, issctype, issubsctype, issubdtype, maximum_sctype
188  
189      Examples
190      --------
191      >>> np.obj2sctype(np.int32)
192      <class 'numpy.int32'>
193      >>> np.obj2sctype(np.array([1., 2.]))
194      <class 'numpy.float64'>
195      >>> np.obj2sctype(np.array([1.j]))
196      <class 'numpy.complex128'>
197  
198      >>> np.obj2sctype(dict)
199      <class 'numpy.object_'>
200      >>> np.obj2sctype('string')
201  
202      >>> np.obj2sctype(1, default=list)
203      <class 'list'>
204  
205      )rLrM�
206  issubclassr-rrrO)rP�defaultrQrJrJrKr�s(
207  
208  ��rcCs"zt||�WStyYdSw)a^
209      Determine if a class is a subclass of a second class.
210  
211      `issubclass_` is equivalent to the Python built-in ``issubclass``,
212      except that it returns False instead of raising a TypeError if one
213      of the arguments is not a class.
214  
215      Parameters
216      ----------
217      arg1 : class
218          Input class. True is returned if `arg1` is a subclass of `arg2`.
219      arg2 : class or tuple of classes.
220          Input class. If a tuple of classes, True is returned if `arg1` is a
221          subclass of any of the tuple elements.
222  
223      Returns
224      -------
225      out : bool
226          Whether `arg1` is a subclass of `arg2` or not.
227  
228      See Also
229      --------
230      issubsctype, issubdtype, issctype
231  
232      Examples
233      --------
234      >>> np.issubclass_(np.int32, int)
235      False
236      >>> np.issubclass_(np.int32, float)
237      False
238      >>> np.issubclass_(np.float64, float)
239      True
240  
241      F)rR�	TypeError��arg1�arg2rJrJrK�issubclass_s
242  $�rXcCstt|�t|��S)a�
243      Determine if the first argument is a subclass of the second argument.
244  
245      Parameters
246      ----------
247      arg1, arg2 : dtype or dtype specifier
248          Data-types.
249  
250      Returns
251      -------
252      out : bool
253          The result.
254  
255      See Also
256      --------
257      issctype, issubdtype, obj2sctype
258  
259      Examples
260      --------
261      >>> np.issubsctype('S8', str)
262      False
263      >>> np.issubsctype(np.array([1]), int)
264      True
265      >>> np.issubsctype(np.array([1]), float)
266      False
267  
268      )rRrrUrJrJrK�issubsctypeDsrYcCs2t|t�s
269  t|�j}t|t�st|�j}t||�S)a?
270      Returns True if first argument is a typecode lower/equal in type hierarchy.
271  
272      This is like the builtin :func:`issubclass`, but for `dtype`\ s.
273  
274      Parameters
275      ----------
276      arg1, arg2 : dtype_like
277          `dtype` or object coercible to one
278  
279      Returns
280      -------
281      out : bool
282  
283      See Also
284      --------
285      :ref:`arrays.scalars` : Overview of the numpy type hierarchy.
286      issubsctype, issubclass_
287  
288      Examples
289      --------
290      `issubdtype` can be used to check the type of arrays:
291  
292      >>> ints = np.array([1, 2, 3], dtype=np.int32)
293      >>> np.issubdtype(ints.dtype, np.integer)
294      True
295      >>> np.issubdtype(ints.dtype, np.floating)
296      False
297  
298      >>> floats = np.array([1, 2, 3], dtype=np.float32)
299      >>> np.issubdtype(floats.dtype, np.integer)
300      False
301      >>> np.issubdtype(floats.dtype, np.floating)
302      True
303  
304      Similar types of different sizes are not subdtypes of each other:
305  
306      >>> np.issubdtype(np.float64, np.float32)
307      False
308      >>> np.issubdtype(np.float32, np.float64)
309      False
310  
311      but both are subtypes of `floating`:
312  
313      >>> np.issubdtype(np.float64, np.floating)
314      True
315      >>> np.issubdtype(np.float32, np.floating)
316      True
317  
318      For convenience, dtype-like objects are allowed too:
319  
320      >>> np.issubdtype('S1', np.string_)
321      True
322      >>> np.issubdtype('i4', np.signedinteger)
323      True
324  
325      )rXr-rrMrRrUrJrJrKrds
326  
327  ;
328  
329  
330  
331  rc@seZdZdZdd�ZdS)�	_typedictz�
332      Base object for a dictionary for look-up with any alias for an array dtype.
333  
334      Instances of `_typedict` can not be used as dictionaries directly,
335      first they have to be populated.
336  
337      cCst�|t|��S�N)�dict�__getitem__r)�self�objrJrJrKr]�sz_typedict.__getitem__N)�__name__�
338  __module__�__qualname__�__doc__r]rJrJrJrKrZ�srZcCsft��D],\}}|j}|jdt|<|jt|<t|�dkr(|jt	|<|j
339  t|<qdt	|<dt|<qdS)N��)r!�itemsrM�bitsr�	alignment�
340  _alignment�len�max�_maxvals�min�_minvals)�name�infor_rJrJrK�_construct_lookups�s
341  
342  
343  �rqcCs2t|�}|durtd��|tvrt|��t|�jS)a�
344      Return the string representation of a scalar dtype.
345  
346      Parameters
347      ----------
348      sctype : scalar dtype or object
349          If a scalar dtype, the corresponding string character is
350          returned. If an object, `sctype2char` tries to infer its scalar type
351          and then return the corresponding string character.
352  
353      Returns
354      -------
355      typechar : str
356          The string character corresponding to the scalar type.
357  
358      Raises
359      ------
360      ValueError
361          If `sctype` is an object for which the type can not be inferred.
362  
363      See Also
364      --------
365      obj2sctype, issctype, issubsctype, mintypecode
366  
367      Examples
368      --------
369      >>> for sctype in [np.int32, np.double, np.complex_, np.string_, np.ndarray]:
370      ...     print(np.sctype2char(sctype))
371      l # may vary
372      d
373      D
374      S
375      O
376  
377      >>> x = np.array([1., 2-1.j])
378      >>> np.sctype2char(x)
379      'D'
380      >>> np.sctype2char(list)
381      'O'
382  
383      Nzunrecognized type)r�
384  ValueErrorr �KeyErrorr�char)�sctyperJrJrKr�s+
385  rcCst|dd��|�S)NF)�copy)r�astype)�x�krJrJrK�<lambda>�srzcCst|�}|j��|jfS)z A ``key`` function for `sorted`.)r�kind�lower�itemsize)�typ�dtrJrJrK�_scalar_type_keysr�)�key�c�bhilqp�BHILQP�efdg�FDGZbBhHiIlLqQpP�efdgFDG�Mmz?bhilqpBHILQPefdgFDGSUVOMm)	�	Character�Integer�UnsignedInteger�Float�Complex�
386  AllInteger�AllFloat�Datetime�All)�b�u�i�fr��S�U�V�O�M�m�?r������r�r�cCsB||kr|Szt�|j�}Wn
387  tyYdSwt||g|d�S)N)�start)�__test_types�indexrtrr�_can_coerce_all)�ar��thisindrJrJrK�_find_common_coerce3s�r�csrt|�}|dkr
388  dS|dkr|dS|}|tkr7tt|��t�fdd�|D��}||kr/�S|d7}|tksdS)Nrrcsg|]}�|kr|�qSrJrJ��.0rx��newdtyperJrK�
389  <listcomp>Fsz#_can_coerce_all.<locals>.<listcomp>)rj�__len_test_typesrr�)Z	dtypelistr��Nr�Z	numcoercerJr�rKr�=s�r�cCs4tj�t�tj�t�tj�t�tj�t	�dSr[)
390  �numbers�Integral�register�integerr��inexact�Real�floating�Number�numberrJrJrJrK�_register_typesLsr�cCs�dd�|D�}dd�|D�}t|�}t|�}|dur|S|dur"|Szt�|j�}t�|j�}Wn
391  ty:YdSw||krDt||�S|S)a
392      Determine common type following standard coercion rules.
393  
394      Parameters
395      ----------
396      array_types : sequence
397          A list of dtypes or dtype convertible objects representing arrays.
398      scalar_types : sequence
399          A list of dtypes or dtype convertible objects representing scalars.
400  
401      Returns
402      -------
403      datatype : dtype
404          The common data type, which is the maximum of `array_types` ignoring
405          `scalar_types`, unless the maximum of `scalar_types` is of a
406          different kind (`dtype.kind`). If the kind is not understood, then
407          None is returned.
408  
409      See Also
410      --------
411      dtype, common_type, can_cast, mintypecode
412  
413      Examples
414      --------
415      >>> np.find_common_type([], [np.int64, np.float32, complex])
416      dtype('complex128')
417      >>> np.find_common_type([np.int64, np.float32], [])
418      dtype('float64')
419  
420      The standard casting rules ensure that a scalar cannot up-cast an
421      array unless the scalar is of a fundamentally different kind of data
422      (i.e. under a different hierarchy in the data type hierarchy) then
423      the array:
424  
425      >>> np.find_common_type([np.float32], [np.int64, np.float64])
426      dtype('float32')
427  
428      Complex is of a different type, so it up-casts the float in the
429      `array_types` argument:
430  
431      >>> np.find_common_type([np.float32], [complex])
432      dtype('complex128')
433  
434      Type specifier strings are convertible to dtypes and can therefore
435      be used instead of dtypes:
436  
437      >>> np.find_common_type(['f4', 'f4', 'i4'], ['c8'])
438      dtype('complex128')
439  
440      cS�g|]}t|��qSrJ�rr�rJrJrKr���z$find_common_type.<locals>.<listcomp>cSr�rJr�r�rJrJrKr��r�N)r��
441  _kind_listr�r{rrr�)Zarray_types�scalar_typesZmaxaZmaxscZindex_aZindex_scrJrJrKrUs"4�
442  rr[)r)Mrcr��numpy.core.multiarrayrrrrrrrr	r
443  �numpy.core.overridesr�__all__Z_string_helpersrrrrrZ
_type_aliasesrrrr
r r!r"�_dtyper#�builtinsr$r%r&r'r(r)r*�numpy.compatr+r,r-�genericTypeRankrrrrXrYrr\rZrrirlrnrqrrr�r��
444  memoryviewr�sorted�tuple�globals�appendr�typeDictr�r�rjr�r�r�r�rrJrJrJrK�<module>s�Q,	$	$
445  1
446  -5
447  )
448  
449  C
450  4�
 
451  
452