For ``BasisKet.create(ind, hs)`` with an integer label `ind`, return a
    :class:`ZeroKet` if `ind` is outside of the range of the underlying Hilbert
    space
174935
def basis_ket_zero_outside_hs(cls, ops, kwargs):
    
    from qnet.algebra.core.state_algebra import ZeroKet
    ind, = ops
    hs = kwargs['hs']
    if isinstance(ind, int):
        if ind < 0 or (hs._dimension is not None and ind >= hs._dimension):
            return ZeroKet
    return ops, kwargs
997944
def areIndicesValid(self, inds):
        
        return reduce(operator.and_, [0 <= inds[d] < self.dims[d]
                                      for d in range(self.ndims)], True)
729034
def getSparseTensor(numNonzeros, inputSize, outputSize,
                    onlyPositive=False,
                    fixedRange=1.0/24):
  
  # Initialize weights in the typical fashion.
  w = torch.Tensor(outputSize, inputSize, )

  if onlyPositive:
    w.data.uniform_(0, fixedRange)
  else:
    w.data.uniform_(-fixedRange, fixedRange)

  # Zero out weights for sparse weight matrices
  if numNonzeros < inputSize:
    numZeros = inputSize - numNonzeros

    outputIndices = np.arange(outputSize)
    inputIndices = np.array([np.random.permutation(inputSize)[:numZeros]
                             for _ in outputIndices], dtype=np.long)

    # Create tensor indices for all non-zero weights
    zeroIndices = np.empty((outputSize, numZeros, 2), dtype=np.long)
    zeroIndices[:, :, 0] = outputIndices[:, None]
    zeroIndices[:, :, 1] = inputIndices
    zeroIndices = torch.LongTensor(zeroIndices.reshape(-1, 2))

    zeroWts = (zeroIndices[:, 0], zeroIndices[:, 1])
    w.data[zeroWts] = 0.0

  return w
98879
def nonzero(self):
        
        return [i for i in xrange(self.size()) if self.test(i)]
528492
def unbounded(self):
        """"""
        self._check_valid()

        status = self._problem._p.Status
        if (status == gurobipy.GRB.INF_OR_UNBD and
                self._problem._p.params.DualReductions):
            # Disable dual reductions to obtain a definitve answer
            self._problem._p.params.DualReductions = 0
            try:
                self._problem._p.optimize()
            finally:
                self._problem._p.params.DualReductions = 1

            status = self._problem._p.Status
        return status == gurobipy.GRB.UNBOUNDED
256094
def union(self, b):
        

        if not allow_dsis:
            return StridedInterval.least_upper_bound(self, b)

        else:
            if self.cardinality > discrete_strided_interval_set.DEFAULT_MAX_CARDINALITY_WITHOUT_COLLAPSING or \
                    b.cardinality > discrete_strided_interval_set.DEFAULT_MAX_CARDINALITY_WITHOUT_COLLAPSING:
                return StridedInterval.least_upper_bound(self, b)

            else:
                dsis = DiscreteStridedIntervalSet(bits=self._bits, si_set={ self })
                return dsis.union(b)
1258554
def init_algebra(*, default_hs_cls='LocalSpace'):
    
    from qnet.algebra.core.hilbert_space_algebra import LocalSpace
    from qnet.algebra.core.abstract_quantum_algebra import QuantumExpression
    default_hs_cls = getattr(importlib.import_module('qnet'), default_hs_cls)
    if issubclass(default_hs_cls, LocalSpace):
        QuantumExpression._default_hs_cls = default_hs_cls
    else:
        raise TypeError("default_hs_cls must be a subclass of LocalSpace")
1202790
def _create_s(y, h):
        """"""
        s = np.zeros_like(y)
        s[:-1] = (y[1:] - y[:-1]) / h[:-1]
        s[-1] = 0.0
        return s
694919
private IMolecularFormula getFormula(List<IIsotope> isoToCond_new, int[] value_In) {
        IMolecularFormula mf = builder.newInstance(IMolecularFormula.class);
        for (int i = 0; i < isoToCond_new.size(); i++) {
            if (value_In[i] != 0) {
                for (int j = 0; j < value_In[i]; j++)
                    mf.addIsotope(isoToCond_new.get(i));

            }
        }
        mf = putInOrder(mf);
        return mf;
    }
816447
def _create_h(x):
        """"""
        h = np.zeros_like(x)
        h[:-1] = x[1:] - x[:-1]
        # border
        h[-1] = h[-2]
        return h
509200
def _range(self, xloc, cache):
        
        uloc = numpy.zeros((2, len(self)))
        for dist in evaluation.sorted_dependencies(self, reverse=True):
            if dist not in self.inverse_map:
                continue
            idx = self.inverse_map[dist]
            xloc_ = xloc[idx].reshape(1, -1)
            uloc[:, idx] = evaluation.evaluate_bound(
                dist, xloc_, cache=cache).flatten()
        return uloc
143908
function create() {
  var out = new glMatrix.ARRAY_TYPE(3);
  if (glMatrix.ARRAY_TYPE != Float32Array) {
    out[0] = 0;
    out[1] = 0;
    out[2] = 0;
  }
  return out;
}
451241
function createRange(fromRight) {
  return function(start, end, step) {
    if (step && typeof step != 'number' && _isIterateeCall(start, end, step)) {
      end = step = undefined;
    }
    // Ensure the sign of `-0` is preserved.
    start = toFinite_1(start);
    if (end === undefined) {
      end = start;
      start = 0;
    } else {
      end = toFinite_1(end);
    }
    step = step === undefined ? (start < end ? 1 : -1) : toFinite_1(step);
    return _baseRange(start, end, step, fromRight);
  };
}
282760
def ijk_jlk_to_il(A, B):
    
    res = np.zeros((A.shape[0], B.shape[1]))
    [np.add(np.dot(A[:,:,k], B[:,:,k]), res, out=res) for k in range(B.shape[-1])]
    return res
1257426
def _check_kets(*ops, same_space=False, disjunct_space=False):
    """"""
    if not all([(isinstance(o, State) and o.isket) for o in ops]):
        raise TypeError("All operands must be Kets")
    if same_space:
        if not len({o.space for o in ops if o is not ZeroKet}) == 1:
            raise UnequalSpaces(str(ops))
    if disjunct_space:
        spc = TrivialSpace
        for o in ops:
            if o.space & spc > TrivialSpace:
                raise OverlappingSpaces(str(ops))
            spc *= o.space
1364330
def constraint(self, n=-1, fid=0):
        
        c = self._getval("constr", fid)
        if n < 0 or n > self.deficiency(fid):
            return c
        else:
            raise RuntimeError("Not yet implemented")
739156
def fromone(cls, index, pad=0, autostep=None):
        """"""
        inst = RangeSet(autostep=autostep)
        # support slice object with duck-typing
        try:
            inst.add(index, pad)
        except TypeError:
            if not index.stop:
                raise ValueError("Invalid range upper limit (%s)" % index.stop)
            inst.add_range(index.start or 0, index.stop, index.step or 1, pad)
        return inst