注意事項および制限事項

このページでは、NLCPy機能に共通する注意事項と制限事項について説明します。

注意事項

  1. PythonスクリプトでNLCPyを使用するには、パッケージ nlcpy をインポートする必要があります。詳細については、 基本的な使用法 を参照してください。

  2. Vector HostとVector Engineの間のオーバーヘッドを削減するために、NLCPyは遅延評価を採用しています。つまり、値は必要になるまで計算されません。 そのため、Pythonスクリプトが発生する警告の位置が正確でない場合があります。詳細については、 遅延評価 を参照してください。

    • 例:

      # sample.py
      import nlcpy as vp
      a = vp.divide(1, 0) # divide by zero warning
      b = a + 1
      print(b)
      
    • 結果:

      $ python sample.py
      sample.py:5: RuntimeWarning: divide by zero encountered in nlcpy.core.core
        print(b)
      inf
      
  3. NLCPyのAPIはNumPyに基づいています。ただし、パフォーマンス上の理由により、いくつかの違いがあります。たとえば、NumPyの関数がスカラー値を返す場合、NLCPyの関数はそれを0次元配列として返します。

    >>> import numpy, nlcpy
    >>> numpy.add(1,2)         # returns a scalar
    3
    >>> nlcpy.add(1,2)         # returns an array
    array(3)
    >>> nlcpy.add(1,2).ndim    # print the dimention of nlcpy.add(1.2)
    0
    
  4. Vector Host(x86)は非正規化数をサポートしていますが、Vector Engineはサポートしていません。 したがって、非正規化数がNLCPyの関数で計算される場合、それらはゼロに丸められます。

    >>> import numpy, nlcpy
    >>> x=numpy.array([-1.e-310, +1.e-310])    # denormal numbers in IEEE754 double precision format.
    >>> x
    array([-1.e-310,  1.e-310])
    >>>
    >>> numpy.add(x,0)   
    array([-1.e-310,  1.e-310])                # works on Vector Host
    >>>
    >>> nlcpy.add(x,0)                         # works on Vector Engine
    array([0., 0.])
    
  5. NumPyの関数はx86ノード(VH)で実行されます。 一方、ほとんどのNLCPyの関数は、自動的にndarrayをVector Engine(VE)にオフロードしてから、VEで実行します。したがって、計算コストがオフロードのコストと比べて小さくなるほど、NLCPyの性能は低下します。そのような場合は、NumPyを使用してください。

  6. Some functions return a view on the input array such as nlcpy.broadcast_arrays(), nlcpy.broadcast_to(), and nlcpy.moveaxis(). However, if a numpy.ndarray object is specified as an input array for them, updates of the object does not affect the return values because the numpy.ndarray object is conveted to an nlcpy.ndarray object once then the function returns the view on the nlcpy.ndarray object.

    >>> import numpy, nlcpy
    >>> nx = numpy.array([[1, 2, 3]])
    >>> ny = numpy.array([[4], [5]])
    >>> vz = nlcpy.broadcast_arrays(nx, ny)
    >>> vz
    [array([[1, 2, 3],
           [1, 2, 3]]), array([[4, 4, 4],
           [5, 5, 5]])]
    >>> nx[0, 2] = 999  # Updates nx
    >>> nx
    array([[  1,   2, 999]])
    >>> vz
    [array([[1, 2, 3],
           [1, 2, 3]]), array([[4, 4, 4],
           [5, 5, 5]])]
    

制限事項

NLCPyの関数に共通する制限のリストを次に示します。これらの制限に加えて、いくつかの個別の制限があります。各機能の詳細説明の"制限事項"もご覧ください。

  1. "dtype"と呼ばれるデータ型は、NumPyの関数と同じようにNLCPyの関数にも指定できます。ただし、NLCPyの現在のバージョンは、次のdtypeのみをサポートします。

    データの種類

    dtype

    文字コード

    bool

    'bool'

    '?'

    32-bit signed integer

    'int32', 'i4'

    'i'

    64-bit signed integer

    'int64', 'i8', int

    'l', 'q'

    32-bit unsigned integer

    'uint32', 'u4'

    'I'

    64-bit unsigned integer

    'uint64', 'u8', uint

    'L', 'Q'

    32-bit floating-point real

    'float32', 'f4'

    'f'

    64-bit floating-point real

    'float64', 'f8', 'float'

    'd'

    32-bit floating-point complex

    'complex64', 'c8'

    'F'

    64-bit floating-point complex

    'complex128', 'c16', 'complex'

    'D'

    各dtypeには、それを識別する文字コードがあります。 NLCPyでは、文字コード'q'と'Q'は内部でそれぞれ'l'と'L'に変換されます。 上記以外のdtypeと文字コードはまだサポートされていません。 さらに、現在のバージョンは、上記のdtypeを含む構造化データ型をサポートしていません。

    上記のdtypeをサポートできない関数もあることに注意してください。 たとえば、複素数型の nlcpy.mean() はサポートしていません。

    >>> import nlcpy
    >>> nlcpy.mean(nlcpy.array([1,2,3],dtype='complex64'))   
    NotImplementedError: dtype=complex64 not supported
    
  2. サポートされていないdtypeがパラメータリストまたはNLCPyの関数の戻り値の型に表示される場合、TypeError が発生します。NumPyの関数がfloat16タイプを内部的に処理する場合、対応するNLCPyの関数はそれをfloat32として扱います。同様に、int8、int16、uint8、またはuint16は、計算中にint32またはuint32として扱われます。このような場合、NLCPyの戻り値はNumPyの戻り値とは異なります。

    >>> import numpy
    >>>
    >>> # numpy.divide.accumulate() treats 1e-8 as float16.
    >>> numpy.divide.accumulate([1e-8], dtype='bool')
    array([0.], dtype=float16)
    >>>
    >>> # 1e-8 is internally rounded to zero in float16 type,
    >>> # so the boolean result becomes False.
    >>> numpy.divide.accumulate([1e-8], dtype='bool', out=numpy.array([True]))
    array([False])
    
    >>> import nlcpy
    >>>
    >>> # NLCPy does not support float16, so TypeError occors.
    >>> nlcpy.divide.accumulate([1e-8], dtype='bool') 
    TypeError: not support for float16.
    >>>
    >>> # 1e-8 is treated as float32, so the boolean result becomes True.
    >>> nlcpy.divide.accumulate([1e-8], dtype='bool', out=nlcpy.array([True]))
    array([ True])