コード例 #1
0
ファイル: test_signal.py プロジェクト: xlong0513/nengo
def make_signal(sig_type, shape, indices, data):
    dense = np.zeros(shape)
    dense[indices[:, 0], indices[:, 1]] = data
    if sig_type == "sparse_scipy":
        m = scipy_sparse.csr_matrix((data, indices.T), shape=shape)
    elif sig_type == "sparse_nengo":
        m = nengo.transforms.SparseMatrix(data=data,
                                          indices=indices,
                                          shape=shape)
    else:
        m = dense
    return Signal(m, name="MySignal"), dense
コード例 #2
0
    def allocate(self):
        """Return a `scipy.sparse.csr_matrix` or dense matrix equivalent.

        We mark this data as readonly to be consistent with how other
        data associated with signals are allocated. If this allocated
        data is to be modified, it should be copied first.
        """

        if self._allocated is not None:
            return self._allocated

        if scipy_sparse is None:
            warnings.warn("Sparse operations require Scipy, which is not "
                          "installed. Using dense matrices instead.")
            self._allocated = self.toarray().view()
        else:
            self._allocated = scipy_sparse.csr_matrix(
                (self.data, self.indices.T), shape=self.shape)
            self._allocated.data.setflags(write=False)

        return self._allocated