Recursively create a multidimensional array (as lists of lists)
        from a bit generator.
551640
def _load_recursive(self, shape, gen):
        
        if len(shape) > 0:
            ans = []
            for i in range(shape[0]):
                ans.append(self._load_recursive(shape[1:], gen))
        else:
            fields = []
            for code, length in self.format:
                field = None
                raw = gen.send(length)
                if code == 'u':
                    field = raw
                elif code == 'i':
                    field = raw
                    # Interpret as 2's complement
                    if field >= 1 << (length - 1):
                        field -= 1 << length
                elif code == 'b':
                    field = bool(raw)
                elif code == 'c':
                    field = six.int2byte(raw)
                elif code == 'f':
                    if length == 32:
                        field = _np.uint32(raw).view(_np.float32)
                    elif length == 64:
                        field = _np.uint64(raw).view(_np.float64)
                    else:
                        raise ValueError('unhandled float length {0}'.format((code, length)))
                else:
                    raise ValueError('unhandled format {0}'.format((code, length)))
                fields.append(field)
            if len(fields) == 1:
                ans = fields[0]
            else:
                ans = tuple(fields)
        return ans
1062197
def chunks(data, n):
    """"""
    for i in range(0, len(data), n):
        yield data[i:i+n]
800295
function(array, n) {
      var ret = [];
      var sz = _.size(array);

      if (n <= 0) return [];
      if (n === 1) return array;

      for(var index = 0; index < sz; index += n) {
        ret.push(array[index]);
      }

      return ret;
    }
572136
def recursive_index_encode(int_array, max=32767, min=-32768):
    """"""
    out_arr = []
    for curr in int_array:
        if curr >= 0 :
            while curr >= max:
                out_arr.append(max)
                curr -=  max
        else:
            while curr <= min:
                out_arr.append(min)
                curr += int(math.fabs(min))
        out_arr.append(curr)
    return out_arr
173448
def slice_into_pieces(seq, n):
    """"""
    length = len(seq)
    if length % n == 0:
        size = length // n
    else:
        size = length // n + 1
    for it in slice_by_size(seq, size):
        yield it
1208305
private static void createList( int data[], int k , int level , List<int[]> ret )
    {
        data[k] = level;

        if( level < data.length-1 ) {
            for( int i = 0; i < data.length; i++ ) {
                if( data[i] == -1 ) {
                    createList(data,i,level+1,ret);
                }
            }
        } else {
            int []copy = new int[data.length];
            System.arraycopy(data,0,copy,0,data.length);
            ret.add(copy);
        }
        data[k] = -1;
    }
305473
def delta_encode(in_array):
    """"""
    if(len(in_array)==0):
        return []
    curr_ans = in_array[0]
    out_array = [curr_ans]
    for in_int in in_array[1:]:
        out_array.append(in_int-curr_ans)
        curr_ans = in_int
    return out_array
733871
def __make_matrix(self, n, val):
        """"""
        matrix = []
        for i in range(n):
            matrix += [[val for j in range(n)]]
        return matrix
1145265
def _initialize_with_array(self, data, rowBased=True):
        """"""
        if rowBased:
            self.matrix = []
            if len(data) != self._rows:
                raise ValueError("Size of Matrix does not match")
            for col in xrange(self._columns):
                self.matrix.append([])
                for row in xrange(self._rows):
                    if len(data[row]) != self._columns:
                        raise ValueError("Size of Matrix does not match")
                    self.matrix[col].append(data[row][col])
        else:
            if len(data) != self._columns:
                raise ValueError("Size of Matrix does not match")
            for col in data:
                if len(col) != self._rows:
                    raise ValueError("Size of Matrix does not match")
            self.matrix = copy.deepcopy(data)
631340
def get_array_ndim(self, key):
        """"""
        data = self.model.get_data()
        return data[key].ndim
52925
def C_array2dict(C):
    """"""
    d = OrderedDict()
    i=0
    for k in C_keys:
        s = C_keys_shape[k]
        if s == 1:
            j = i+1
            d[k] = C[i]
        else:
            j = i \
      + reduce(operator.mul, s, 1)
            d[k] = C[i:j].reshape(s)
        i = j
    return d
1163745
static int[] toArray(long set) {

        int[] vertices = new int[Long.bitCount(set)];
        int i = 0;

        // fill the cyclic vertices with the bits that have been set
        for (int v = 0; i < vertices.length; v++) {
            if (isBitSet(set, v)) vertices[i++] = v;
        }

        return vertices;
    }
404270
def cast(keys, data):
        """"""
        matrix = Matrix()
        matrix.keys = keys
        matrix.data = data
        return matrix
386777
private static Iterator<int[]> initializeValueIterator(VariableNumMap vars) {
		int[] dimensionSizes = new int[vars.size()];
		
		List<DiscreteVariable> discreteVars = vars.getDiscreteVariables();
		for (int i = 0; i < discreteVars.size(); i++) {
		  dimensionSizes[i] = discreteVars.get(i).numValues();
		}
		return new IntegerArrayIterator(dimensionSizes, new int[0]);
	}
317427
def frombits(cls, bits='0'):
        """"""
        if len(bits) > cls._len:
            raise ValueError('too many bits %r' % (bits,))
        return cls.fromint(bits[::-1], 2)
863912
def makeC(N):
    
    C = defaultdict(int)
    for d in N:
        C[tuple(d)] += 1

    return [i for i in C.items() if (0, 0, 0, 0) not in i]
1223195
function skeleton(cells, n) {
  if(n < 0) {
    return []
  }
  var result = []
    , k0     = (1<<(n+1))-1
  for(var i=0; i<cells.length; ++i) {
    var c = cells[i]
    for(var k=k0; k<(1<<c.length); k=bits.nextCombination(k)) {
      var b = new Array(n+1)
        , l = 0
      for(var j=0; j<c.length; ++j) {
        if(k & (1<<j)) {
          b[l++] = c[j]
        }
      }
      result.push(b)
    }
  }
  return normalize(result)
}