Returns the code to declare an Ftype object that handles memory
    deallocation for Fortran return arrays that were allocated by the
    method called in ctypes.
171087
def _py_ftype(parameter, tab):
    
    splice = ', '.join(["{0}_{1:d}".format(parameter.lname, i)
                        for i in range(parameter.D)])       
    return "{2}{0}_ft = Ftype({0}_o, [{1}], libpath)".format(parameter.lname, splice, tab)
1053416
def get_code(self):
        
        stub = []

        for deco in self.decorators:
            if (deco in DECORATORS) or deco.endswith(".setter"):
                stub.append("@" + deco)

        parameters = []
        for name, type_, has_default in self.parameters:
            decl = "%(n)s%(t)s%(d)s" % {
                "n": name,
                "t": ": " + type_ if type_ else "",
                "d": " = ..." if has_default else "",
            }
            parameters.append(decl)

        slots = {
            "a": "async " if self._async else "",
            "n": self.name,
            "p": ", ".join(parameters),
            "r": self.rtype,
        }

        prototype = "%(a)sdef %(n)s(%(p)s) -> %(r)s: ..." % slots
        if len(prototype) <= LINE_LENGTH_LIMIT:
            stub.append(prototype)
        elif len(INDENT + slots["p"]) <= LINE_LENGTH_LIMIT:
            stub.append("%(a)sdef %(n)s(" % slots)
            stub.append(INDENT + slots["p"])
            stub.append(") -> %(r)s: ..." % slots)
        else:
            stub.append("%(a)sdef %(n)s(" % slots)
            for param in parameters:
                stub.append(INDENT + param + ",")
            stub.append(") -> %(r)s: ..." % slots)

        return stub
666763
def asnumpy(self):
        """"""

        # Create C variables that will serve as out parameters for TCMPS.
        data_ptr = _ctypes.POINTER(_ctypes.c_float)()    # float* data_ptr
        shape_ptr = _ctypes.POINTER(_ctypes.c_size_t)()  # size_t* shape_ptr
        dim = _ctypes.c_size_t()                         # size_t dim

        # Obtain pointers into memory owned by the C++ object self.handle.
        # Note that this may trigger synchronization with another thread
        # producing the data.
        status_code = self._LIB.TCMPSReadFloatArray(
            self.handle, _ctypes.byref(data_ptr), _ctypes.byref(shape_ptr),
            _ctypes.byref(dim))
        assert status_code == 0, "Error calling TCMPSReadFloatArray"

        return _numpy_array_from_ctypes(data_ptr, shape_ptr, dim)
966769
def get_one_meth_type(self, mtype, method_list):
        
        cond = method_list['dtype'] == mtype
        codes = method_list[cond]
        return codes
667115
function compileDefinition(def) {
  if (_.isArray(def)) {
    return _.map(def, compileDefinition);
  }

  try {
    if (def[0] == '{') {
      // Plain object defined behaviour => wrap in braces.
      return eval(`(${def})`);
    }
    else if (def[0] == '[') {
      // Definition array => first deserialize array, then definitions inside.
      let behArr = eval(`(${def})`);

      return _.map(behArr, item => compileDefinition(item));
    }

    return eval(def);
  }
  catch (err) {
    parentPort.postMessage({ error: 'Compilation error: ' + err });

    process.exit(1);
  }
}
829256
def unpack_classical_reg(c):
    
    if isinstance(c, list) or isinstance(c, tuple):
        if len(c) > 2 or len(c) == 0:
            raise ValueError("if c is a list/tuple, it should be of length <= 2")
        if len(c) == 1:
            c = (c[0], 0)
        if not isinstance(c[0], str):
            raise ValueError("if c is a list/tuple, its first member should be a string")
        if not isinstance(c[1], int):
            raise ValueError("if c is a list/tuple, its second member should be an int")
        return MemoryReference(c[0], c[1])
    if isinstance(c, MemoryReference):
        return c
    elif isinstance(c, str):
        return MemoryReference(c, 0)
    else:
        raise TypeError("c should be a list of length 2, a pair, a string, or a MemoryReference")
721554
def _as_array(arr, dtype=None):
    
    if arr is None:
        return None
    if isinstance(arr, np.ndarray) and dtype is None:
        return arr
    if isinstance(arr, integer_types + (float,)):
        arr = [arr]
    out = np.asarray(arr)
    if dtype is not None:
        if out.dtype != dtype:
            out = out.astype(dtype)
    if out.dtype not in _ACCEPTED_ARRAY_DTYPES:
        raise ValueError("'arr' seems to have an invalid dtype: "
                         "{0:s}".format(str(out.dtype)))
    return out
610806
def _resize_with_dtype(arr, dtype):
    
    structured_arrays = dtype.names is not None and arr.dtype.names is not None
    old_columns = arr.dtype.names or []
    new_columns = dtype.names or []

    # In numpy 1.9 the ndarray.astype method used to handle changes in number of fields. The code below
    # should replicate the same behaviour the old astype used to have.
    #
    # One may be tempted to use np.lib.recfunctions.stack_arrays to implement both this step and the
    # concatenate that follows but it 2x slower and it requires providing your own default values (instead
    # of np.zeros).
    #
    # Numpy 1.14 supports doing new_arr[old_columns] = arr[old_columns], which is faster than the code below
    # (in benchmarks it seems to be even slightly faster than using the old astype). However, that is not
    # supported by numpy 1.9.2.
    if structured_arrays and (old_columns != new_columns):
        old_columns = set(old_columns)
        new_columns = set(new_columns)

        new_arr = np.zeros(arr.shape, dtype)
        for c in old_columns & new_columns:
            new_arr[c] = arr[c]

        # missing float columns should default to nan rather than zero
        _is_float_type = lambda _dtype: _dtype.type in (np.float32, np.float64)
        _is_void_float_type = lambda _dtype: _dtype.type == np.void and _is_float_type(_dtype.subdtype[0])
        _is_float_or_void_float_type = lambda _dtype: _is_float_type(_dtype) or _is_void_float_type(_dtype)
        _is_float = lambda column: _is_float_or_void_float_type(dtype.fields[column][0])
        for new_column in filter(_is_float, new_columns - old_columns):
            new_arr[new_column] = np.nan

        return new_arr.astype(dtype)
    else:
        return arr.astype(dtype)
743924
def _fix_tbit_dtype(self, array, colnums):
        
        descr = array.dtype.descr
        for i, colnum in enumerate(colnums):
            npy_type, isvar, istbit = self._get_tbl_numpy_dtype(colnum)
            if (istbit):
                coldescr = list(descr[i])
                coldescr[1] = '?'
                descr[i] = tuple(coldescr)

        return array.view(descr)
639355
def load( typecode )
      offset = 0
      typecode.typecodes.collect do |t|
        value = GCCValue.new @function,
          "*(#{GCCType.new( t ).identifier} *)( #{self} + #{offset} )"
        offset += t.storage_size
        value
      end
    end
608964
def _ctypes_ex_variables(executable):
    
    result = []
    for p in executable.ordered_parameters:
        _ctypes_code_parameter(result, p, "indices")
        _ctypes_code_parameter(result, p, "variable")
        _ctypes_code_parameter(result, p, "out")

    if type(executable).__name__ == "Function":
        #For functions, we still create a subroutine-type interface and then just add an extra
        #output-type parameter for the function's return type.
        _ctypes_code_parameter(result, executable, "indices")
        _ctypes_code_parameter(result, executable, "variable")
        _ctypes_code_parameter(result, executable, "out")
        
    return result
1093538
def get_rec_dtype(self, **keys):
        
        colnums = keys.get('colnums', None)
        vstorage = keys.get('vstorage', self._vstorage)

        if colnums is None:
            colnums = self._extract_colnums()

        descr = []
        isvararray = numpy.zeros(len(colnums), dtype=numpy.bool)
        for i, colnum in enumerate(colnums):
            dt, isvar = self.get_rec_column_descr(colnum, vstorage)
            descr.append(dt)
            isvararray[i] = isvar
        dtype = numpy.dtype(descr)

        offsets = numpy.zeros(len(colnums), dtype='i8')
        for i, n in enumerate(dtype.names):
            offsets[i] = dtype.fields[n][1]
        return dtype, offsets, isvararray
814096
def codes_get_string_array(handle, key, size, length=None):
    # type: (cffi.FFI.CData, bytes, int, int) -> T.List[bytes]
    
    if length is None:
        length = codes_get_string_length(handle, key)
    values_keepalive = [ffi.new('char[]', length) for _ in range(size)]
    values = ffi.new('char*[]', values_keepalive)
    size_p = ffi.new('size_t *', size)
    _codes_get_string_array(handle, key.encode(ENC), values, size_p)
    return [ffi.string(values[i]).decode(ENC) for i in range(size_p[0])]
528613
def asarray(self):
		
		# most codes don't use this feature, this is the only place
		# numpy is used here, and importing numpy can be
		# time-consuming, so we derfer the import until needed.
		import numpy
		try:
			dtype = ligolwtypes.ToNumPyType[self.Type]
		except KeyError as e:
			raise TypeError("cannot determine numpy dtype for Column '%s': %s" % (self.getAttribute("Name"), e))
		return numpy.fromiter(self, dtype = dtype)
626653
def save_array_types(self, fname):
    '''
    '''
    type_defs = {'arrays': sorted(list(self.array_types))}
    with open(fname, 'wt') as fh:
      pprint(type_defs, stream=fh)
873670
def codes_get_long_array(handle, key, size):
    # type: (cffi.FFI.CData, str, int) -> T.List[int]
    
    values = ffi.new('long[]', size)
    size_p = ffi.new('size_t *', size)
    _codes_get_long_array(handle, key.encode(ENC), values, size_p)
    return list(values)
1317218
def get_libgfortran_dir():
    
    for ending in [".3.dylib", ".dylib", ".3.so", ".so"]:
        try:
            p = Popen(['gfortran', "-print-file-name=libgfortran" + ending],
                      stdout=PIPE, stderr=PIPE)
            p.stderr.close()
            line = p.stdout.readline().decode().strip()
            p.stdout.close()
            if os.path.exists(line):
                return [os.path.dirname(line)]
        except:
            continue
        return []