This function checks to see if a sparse output is desireable given the inputs and if so, casts the inputs to sparse in order to make it so.
480378
def convert_inputs_to_sparse_if_necessary(lhs, rhs):
    '''
    
    '''
    if not sp.issparse(lhs) or not sp.issparse(rhs):
        if sparse_is_desireable(lhs, rhs):
            if not sp.issparse(lhs):
                lhs = sp.csc_matrix(lhs)
                #print "converting lhs into sparse matrix"
            if not sp.issparse(rhs):
                rhs = sp.csc_matrix(rhs)
                #print "converting rhs into sparse matrix"
    return lhs, rhs
789497
public static SparseVector fromMatrixMarket(InputStream is) throws IOException {
        return Vector.fromMatrixMarket(is).to(Vectors.SPARSE);
    }
6426
function isEmpty(value: mixed): boolean {
  if (Array.isArray(value)) {
    return value.length === 0;
  } else if (typeof value === 'object') {
    if (value) {
      invariant(
        !isIterable(value) || value.size === undefined,
        'isEmpty() does not support iterable collections.',
      );
      for (const _ in value) {
        return false;
      }
    }
    return true;
  } else {
    return !value;
  }
}
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
616383
def _transform_should_cast(self, func_nm):
        
        return (self.size().fillna(0) > 0).any() and (
            func_nm not in base.cython_cast_blacklist)
285152
def _maybe_to_sparse(array):
    
    if isinstance(array, ABCSparseSeries):
        array = array.values.copy()
    return array
792552
def check(self):
        
        if self.sparselib not in self.sparselib_alt:
            logger.warning("Invalid sparse library <{}>".format(self.sparselib))
            self.sparselib = 'umfpack'

        if self.sparselib == 'klu' and not KLU:
            logger.info("Optional package \"cvxoptklu\" available for speed up")
            self.sparselib = 'umfpack'

        return True
1363219
function(args, cb) {
        self.availableEncoders(function(err, encoders) {
          for (var i = 0; i < args.length; i++) {
            if (args[i] === '-acodec' || args[i] === '-vcodec') {
              i++;

              if ((args[i] in encoders) && encoders[args[i]].experimental) {
                args.splice(i + 1, 0, '-strict', 'experimental');
                i += 2;
              }
            }
          }

          cb(null, args);
        });
      }
231739
def sparse(numRows, numCols, colPtrs, rowIndices, values):
        
        return SparseMatrix(numRows, numCols, colPtrs, rowIndices, values)
1011379
private void add(SparseDoubleVector dest, TernaryVector src) {
        for (int p : src.positiveDimensions())
            dest.add(p, 1);
        for (int n : src.negativeDimensions())
            dest.add(n, -1);
    }
198526
@SuppressWarnings("unchecked")
    private void ensureCapacity(int capacity) {
        checkCapacity(capacity);
        Elem<V>[] newArray = (Elem<V>[]) Array.newInstance(Elem.class, capacity + 2);
        if (newArray.length >= array.length) {
            System.arraycopy(array, 0, newArray, 0, array.length);
            for (int i = array.length; i < newArray.length; i++) {
                newArray[i] = new Elem<V>(SUP_KEY, null);
            }
        } else {
            System.arraycopy(array, 0, newArray, 0, newArray.length);
        }
        array = newArray;
    }
1043587
public static void validateBroadcastDims(INDArray x, INDArray y, INDArray z, int... dimensions){
        Preconditions.checkArgument(x == z || x.equalShapes(z), "X and Z arrays must be equal shape. X shape: %s, Z shape: %s",
                x.shape(), z.shape());
        long[] sx = x.shape();
        long[] sy = y.shape();
        //Possibility 1: equal ranks - dimensions must match
        if(dimensions.length == 1 && sy.length == 2 && (sy[0] == 1 || sy[1] == 1)) {
            //Edge case: x=[a,b,c], y=[1,b], dim=1 etc
            int d2 = dimensions[0] < 0 ? dimensions[0] + sx.length : dimensions[0]; //Handle negative dimensions
            if (sy[0] == 1) {
                Preconditions.checkState(sx[d2] == sy[1], "Shapes do not match: dimensions[0] - x[%s] must match y[%s], x shape %s, y shape %s, dimensions %s",
                        dimensions[0], 1, sx, sy, dimensions);
            } else {
                Preconditions.checkState(sx[d2] == sy[0], "Shapes do not match: dimensions[0] - x[%s] must match y[%s], x shape %s, y shape %s, dimensions %s",
                        dimensions[0], 0, sx, sy, dimensions);
            }
        } else if(sx.length == sy.length){
            for(int d : dimensions){
                int d2 = d < 0 ? d + sx.length : d; //Handle negative dimensions
                Preconditions.checkState(sx[d2] == sy[d2], "Dimensions mismatch on dimension %s: x shape %s, y shape %s", d, sx, sy);
            }
        } else if(dimensions.length == sy.length) {
            //Possibility 2: different ranks - for example, mul([a,b,c],[a,c], [0,2]) - dimensions refer to x
            for (int i = 0; i < dimensions.length; i++) {
                int d2 = dimensions[i] < 0 ? dimensions[i] + sx.length : dimensions[i]; //Handle negative dimensions
                Preconditions.checkState(sx[d2] == sy[i], "Shapes do not match: dimensions[%s] - x[%s] must match y[%s], x shape %s, y shape %s, dimensions %s",
                        i, d2, i, sx, sy, dimensions);
            }
        } else {
            throw new IllegalStateException("Invalid broadcast dimensions: x shape " + Arrays.toString(sx) + ", y shape " + Arrays.toString(sy)
                    + ", dimensions " + Arrays.toString(dimensions));
        }
    }
198079
public static SparseTensor diagonal(int[] dimensionNumbers, int[] dimensionSizes, double value) {
    int minDimensionSize = Ints.min(dimensionSizes);
    double[] values = new double[minDimensionSize];
    Arrays.fill(values, value);

    return diagonal(dimensionNumbers, dimensionSizes, values);
  }
852988
def is_sparse_vector(x):
    
    return sp.issparse(x) and len(x.shape) == 2 and x.shape[0] == 1
621787
private byte[] bufD(final int valsz, boolean na_sparse){
    int elem_size = valsz+4;
    byte [] res = MemoryManager.malloc1(CXIChunk._OFF + _sparseLen*elem_size);
    UnsafeUtils.set4(res,0,_len);
    res[4] = (byte)4;
    res[5] = (byte)valsz;
    res[6] = na_sparse?(byte)1:0;
    if(na_sparse)res[6] = (byte)1;
    for(int i = 0; i < _sparseLen; ++i){
      UnsafeUtils.set4(res,CXIChunk._OFF+i*elem_size+0,_id[i]);
      if(valsz == 4){
        UnsafeUtils.set4f(res,CXIChunk._OFF+i*elem_size+4,(float)_ds[i]);
      } else if(valsz == 8) {
        UnsafeUtils.set8d(res,CXIChunk._OFF+i*elem_size+4,_ds[i]);
      } else throw H2O.unimpl();
    }
    return res;
  }
150050
private Either<FEELEvent, Object> actualInputsMatchInputValues(EvaluationContext ctx, Object[] params) {
        // check that all the parameters match the input list values if they are defined
        for( int i = 0; i < params.length; i++ ) {
            final DTInputClause input = inputs.get( i );
            // if a list of values is defined, check the the parameter matches the value
            if ( input.getInputValues() != null && ! input.getInputValues().isEmpty() ) {
                final Object parameter = params[i];
                boolean satisfies = input.getInputValues().stream().map( ut -> ut.apply( ctx, parameter ) ).filter( Boolean::booleanValue ).findAny().orElse( false );

                if ( !satisfies ) {
                    String values = input.getInputValuesText();
                    return Either.ofLeft(new InvalidInputEvent( FEELEvent.Severity.ERROR,
                                                  input.getInputExpression()+"='" + parameter + "' does not match any of the valid values " + values + " for decision table '" + getName() + "'.",
                                                  getName(),
                                                  null,
                                                  values )
                            );
                }
            }
        }
        return Either.ofRight(true);
    }
1145315
def _wrap_result(name, data, sparse_index, fill_value, dtype=None):
    
    if name.startswith('__'):
        # e.g. __eq__ --> eq
        name = name[2:-2]

    if name in ('eq', 'ne', 'lt', 'gt', 'le', 'ge'):
        dtype = np.bool

    fill_value = lib.item_from_zerodim(fill_value)

    if is_bool_dtype(dtype):
        # fill_value may be np.bool_
        fill_value = bool(fill_value)
    return SparseArray(data,
                       sparse_index=sparse_index,
                       fill_value=fill_value,
                       dtype=dtype)