what about sparse reps?
482053
protected final boolean isNA2(int idx) {
    if (isString()) return _is[idx] == -1;
    if(isUUID() || _ds == null) return _missing != null && _missing.get(idx);
    return Double.isNaN(_ds[idx]);
  }
675434
def forward_backward(self, parameters):
        
        # If the features are sparse, we can use an optimization.
        # I'm not using scipy.sparse here because we want to avoid a scipy dependency and also scipy.sparse doesn't seem
        # to handle arrays of shape higher than 2.
        if isinstance(self.sparse_x, str) and self.sparse_x == 'uninitialized':
            if (self.x == 0).sum() * 1.0 / self.x.size > 0.6:
                self.sparse_x = self._construct_sparse_features(self.x)
            else:
                self.sparse_x = 'not sparse'

        I, J, K = self.x.shape
        if not isinstance(self.sparse_x, str):
            C = self.sparse_x[0].shape[2]
            S, _ = parameters.shape
            x_dot_parameters = np.zeros((I, J, S))
            sparse_multiply(x_dot_parameters, self.sparse_x[0], self.sparse_x[1], parameters.T, I, J, K, C, S)
        else:
            x_dot_parameters = np.dot(self.x, parameters.T)  # Pre-compute the dot product
        alpha = self._forward(x_dot_parameters)
        beta = self._backward(x_dot_parameters)
        classes_to_ints = {k: i for i, k in enumerate(set(self.states_to_classes.values()))}
        states_to_classes = np.array([classes_to_ints[self.states_to_classes[state]]
                                      for state in range(max(self.states_to_classes.keys()) + 1)], dtype='int64')
        if not isinstance(self.sparse_x, str):
            ll, deriv = gradient_sparse(alpha, beta, parameters, states_to_classes,
                                        self.sparse_x[0], self.sparse_x[1], classes_to_ints[self.y],
                                        I, J, self.sparse_x[0].shape[2])
        else:
            ll, deriv = gradient(alpha, beta, parameters, states_to_classes,
                                 self.x, classes_to_ints[self.y], I, J, K)
        return ll, deriv
1347343
def _M2_sparse(Xvar, mask_X, Yvar, mask_Y, weights=None):
    
    C = np.zeros((len(mask_X), len(mask_Y)))
    C[np.ix_(mask_X, mask_Y)] = _M2_dense(Xvar, Yvar, weights=weights)
    return C
1283007
def as_sparse_array(self, kind=None, fill_value=None, copy=False):
        

        if fill_value is None:
            fill_value = self.fill_value
        if kind is None:
            kind = self.kind
        return SparseArray(self.values, sparse_index=self.sp_index,
                           fill_value=fill_value, kind=kind, copy=copy)
572051
@Benchmark void codePointAtNoSurrogates(int reps) {
    final int length = Math.min(this.length, MIN_SURROGATE);
    StringBuilder sb = new StringBuilder();
    for (int j = 0; j < length; j++) {
      sb.appendCodePoint(j);
    }
    for (int i = 0; i < reps; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < length - 1; k++) {
          if (sb.codePointAt(k) > MIN_SURROGATE)
            throw new Error();
        }
      }
    }
  }
137818
def edges_sparse(self):
        
        sparse = graph.edges_to_coo(self.edges,
                                    count=len(self.vertices))
        return sparse
218888
def _row_sparse_pull(self, parameter, out, row_id, full_idx=False):
        
        # initialize kv and params if not already
        if not self._kv_initialized:
            self._init_kvstore()
        if self._params_to_init:
            self._init_params()
        idx = self._param2idx[parameter.name]
        if full_idx and 'dist' not in self._kvstore.type:
            assert row_id.size == out.shape[0]
            self._kvstore.pull(idx, out=out, priority=-idx, ignore_sparse=False)
        else:
            self._kvstore.row_sparse_pull(idx, out=out, row_ids=row_id, priority=-idx)
1163099
def generate_evenly_distributed_data_sparse(dim = 2000,
                                            num_active = 40,
                                            num_samples = 1000):
  
  indices = [numpy.random.choice(dim, size = num_active, replace = False)
      for _ in range(num_samples)]
  data = SM32()

  data.reshape(0, dim)
  for row in indices:
    data.addRowNZ(row, [1]*num_active)

  # data.reshape(num_samples, dim)
  # for sample, datapoint in enumerate(indices):
  #   for index in datapoint:
  #     data[sample, index] = 1.

  return data
1312079
def stack_sparse_frame(frame):
    
    lengths = [s.sp_index.npoints for _, s in frame.items()]
    nobs = sum(lengths)

    # this is pretty fast
    minor_codes = np.repeat(np.arange(len(frame.columns)), lengths)

    inds_to_concat = []
    vals_to_concat = []
    # TODO: Figure out whether this can be reached.
    # I think this currently can't be reached because you can't build a
    # SparseDataFrame with a non-np.NaN fill value (fails earlier).
    for _, series in frame.items():
        if not np.isnan(series.fill_value):
            raise TypeError('This routine assumes NaN fill value')

        int_index = series.sp_index.to_int_index()
        inds_to_concat.append(int_index.indices)
        vals_to_concat.append(series.sp_values)

    major_codes = np.concatenate(inds_to_concat)
    stacked_values = np.concatenate(vals_to_concat)
    index = MultiIndex(levels=[frame.index, frame.columns],
                       codes=[major_codes, minor_codes],
                       verify_integrity=False)

    lp = DataFrame(stacked_values.reshape((nobs, 1)), index=index,
                   columns=['foo'])
    return lp.sort_index(level=0)
1153296
@Benchmark boolean isSpace(int reps) {
        boolean dummy = false;
        if (overload == Overload.CHAR) {
            for (int i = 0; i < reps; ++i) {
                for (int ch = 0; ch < 65536; ++ch) {
                    dummy ^= ((char) ch == ' ');
                }
            }
        } else {
            for (int i = 0; i < reps; ++i) {
                for (int ch = 0; ch < 65536; ++ch) {
                    dummy ^= (ch == ' ');
                }
            }
        }
        return dummy;
    }
1234461
@Override
    public Matrix<T> repmat(final int rowRepeats, final int colRepeats) {
        N.checkArgument(rowRepeats > 0 && colRepeats > 0, "rowRepeats=%s and colRepeats=%s must be bigger than 0", rowRepeats, colRepeats);

        final T[][] c = N.newArray(arrayType, rows * rowRepeats);

        for (int i = 0, len = c.length; i < len; i++) {
            c[i] = N.newArray(componentType, cols * colRepeats);
        }

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < colRepeats; j++) {
                N.copy(a[i], 0, c[i], j * cols, cols);
            }
        }

        for (int i = 1; i < rowRepeats; i++) {
            for (int j = 0; j < rows; j++) {
                N.copy(c[j], 0, c[i * rows + j], 0, c[j].length);
            }
        }

        return new Matrix<T>(c);
    }
376936
protected void set_sparse(int num_noncompressibles, Compress sparsity_type) {
    assert !isUUID():"sparse for uuids is not supported";
    if ((sparsity_type == Compress.ZERO && isSparseNA()) || (sparsity_type == Compress.NA && isSparseZero()))
      cancel_sparse();
    if (sparsity_type == Compress.NA) {
      _sparseNA = true;
    }
    if (_id != null && _sparseLen == num_noncompressibles && _len != 0) return;
    if (_id != null)
      cancel_sparse();
    assert _sparseLen == _len : "_sparseLen = " + _sparseLen + ", _len = " + _len + ", num_noncompressibles = " + num_noncompressibles;
    int cs = 0; //number of compressibles
    if (_is != null) {
      assert num_noncompressibles <= _is.length;
      _id = MemoryManager.malloc4(_is.length);
      for (int i = 0; i < _len; i++) {
        if (_is[i] == -1) cs++; //same condition for NA and 0
        else {
          _is[i - cs] = _is[i];
          _id[i - cs] = i;
        }
      }
    } else if (_ds == null) {
      if (_len == 0) {
        _ms = new Mantissas(0);
        _xs = new Exponents(0);
        _id = new int[0];
        set_sparseLen(0);
        return;
      } else {
        assert num_noncompressibles <= _sparseLen;
        _id = MemoryManager.malloc4(_ms.len());
        for (int i = 0; i < _sparseLen; ++i) {
          if (is_compressible(i)) {
            ++cs;
          } else  {
            _ms.move(i - cs, i);
            _xs.move(i - cs, i);
            _id[i - cs] = i;
            if(sparsity_type != Compress.NA && _missing != null){
              _missing.set(i-cs,_missing.get(i));
            }
          }
        }
        if(_missing != null && _missing.length() > num_noncompressibles)
            _missing.clear(num_noncompressibles, _missing.length());
      }
    } else {
      assert num_noncompressibles <= _ds.length;
      _id = alloc_indices(_ds.length);
      for (int i = 0; i < _sparseLen; ++i) {
        if (is_compressible(_ds[i])) ++cs;
        else {
          _ds[i - cs] = _ds[i];
          _id[i - cs] = i;
        }
      }
    }
    assert cs == (_sparseLen - num_noncompressibles) : "cs = " + cs + " != " + (_sparseLen - num_noncompressibles) + ", sparsity type = " + sparsity_type;
    assert (sparsity_type == Compress.NA) == _sparseNA;
    if(sparsity_type == Compress.NA && _missing != null)
      _missing.clear();
    set_sparseLen(num_noncompressibles);
  }
118157
def repmat(x, r, c):
    '''
    
    '''
    if sps.issparse(x):
        row = sps.hstack([x for _ in range(c)])
        return sps.vstack([row for _ in range(r)], format=x.format)
    else: return np.matlib.repmat(x, r, c)
103676
@Benchmark long setMaskX64(int reps) {
    long count = 64L * reps;
    long bitMask = 0L;
    for (int i = 0; i < count; i++) {
      bitMask |= 1 << (i & 0x3F);
    }
    return bitMask;
  }
926493
def setStimReps(self):
        """"""
        reps = self.ui.nrepsSpnbx.value()
        self.stimModel.setRepCount(reps)
109773
def _construct_sparse_features(self, x):
        
        I, J, K = x.shape
        new_array_height = (x != 0).sum(axis=2).max()
        index_array = -np.ones((I, J, new_array_height), dtype='int64')
        value_array = -np.ones((I, J, new_array_height), dtype='float64')
        populate_sparse_features(x, index_array, value_array, I, J, K)
        return index_array, value_array
25262
def _compute_sparse_average_correct(
    input_, labels, per_example_weights, topk=1):
  """"""
  labels = tf.to_int64(labels)
  labels.get_shape().assert_is_compatible_with(
      [input_.get_shape()[0], None])
  if topk == 1:
    predictions = tf.reshape(tf.argmax(input_, 1), [-1, 1])
    in_topk = tf.reduce_any(tf.equal(labels, predictions),
                            reduction_indices=[1])
  else:
    # Use broadcasting to check if ANY of the predictions are in the top k.
    # TODO(eiderman): For a multi-label top k, what does accuracy mean?
    predictions = tf.reshape(tf.nn.top_k(input_, topk)[1], [-1, 1, topk])
    labels = tf.expand_dims(labels, [-1])

    in_topk = tf.reduce_any(tf.equal(tf.cast(labels, predictions.dtype),
                                     predictions),
                            reduction_indices=[1, 2])
  correct_predictions = tf.to_float(in_topk)

  # If individual examples are weighted, then we want to normalize by that.
  if per_example_weights is not None:
    per_example_weights = _convert_and_assert_per_example_weights_compatible(
        input_,
        per_example_weights,
        dtype=None)
    float_weights = tf.to_float(per_example_weights)
    # TODO(eiderman): This should use an op that doesn't support broadcasting.
    correct_predictions *= float_weights
    num_examples = tf.reduce_sum(float_weights)
  else:
    # shape only holds ints, but we want to always return the same type
    # for num_examples to make everything compatible.
    num_examples = tf.to_float(tf.gather(tf.shape(input_), 0))
  return tf.reduce_sum(correct_predictions), num_examples