original_docstring: This is the fast XDR conversion. A 100x100 array takes around 40 micro-
      seconds. This is a speedup of factor 100.
      
docstring: This is the fast XDR conversion. A 100x100 array takes around 40 micro
  seconds. This is a speedup of factor 100.
docstring_tokens: This is the fast XDR conversion . A 100x100 array takes around 40 micro seconds . This is a speedup of factor 100 .
code: def dods_encode(data, dtype):
      """This is the fast XDR conversion. A 100x100 array takes around 40 micro-
      seconds. This is a speedup of factor 100.
      """
  
      is_scalar = False
      if not hasattr(data, 'shape'):
          # if not hasattr(data, '__len__'):
          data = np.asarray(data)
          is_scalar = True
  
      length = np.prod(data.shape)
      packed_length = b''
      if not is_scalar:
          packed_length = length.astype('<i4').byteswap().tobytes() * 2
  
      yield packed_length
  
      if isinstance(data, da.Array):
          # Encode in chunks of a defined size if we work with dask.Array
          chunk_size = int(Config.DASK_ENCODE_CHUNK_SIZE / data.dtype.itemsize)
          serialize_data = data.ravel().rechunk(chunk_size)
          for block in serialize_data.blocks:
              yield block.astype(dtype.str).compute().tobytes()
      else:
          # Make sure we always encode an array or we will get wrong results
          data = np.asarray(data)
          yield data.astype(dtype.str).tobytes()
code_tokens: def dods_encode ( data , dtype ) : is_scalar = False if not hasattr ( data , 'shape' ) : data = np . asarray ( data ) is_scalar = True length = np . prod ( data . shape ) packed_length = b'' if not is_scalar : packed_length = length . astype ( '<i4' ) . byteswap ( ) . tobytes ( ) * 2 yield packed_length if isinstance ( data , da . Array ) : chunk_size = int ( Config . DASK_ENCODE_CHUNK_SIZE / data . dtype . itemsize ) serialize_data = data . ravel ( ) . rechunk ( chunk_size ) for block in serialize_data . blocks : yield block . astype ( dtype . str ) . compute ( ) . tobytes ( ) else : data = np . asarray ( data ) yield data . astype ( dtype . str ) . tobytes ( )
short_docstring: This is the fast XDR conversion.
short_docstring_tokens: This is the fast XDR conversion .
comment: """This is the fast XDR conversion. A 100x100 array takes around 40 micro-
      seconds. This is a speedup of factor 100.
      """$SEP$# if not hasattr(data, '__len__'):$SEP$# Encode in chunks of a defined size if we work with dask.Array$SEP$# Make sure we always encode an array or we will get wrong results