Did I find the right examples for you? yes no

# sputils.upcast

All Samples(54)  |  Call(37)  |  Derive(0)  |  Import(17)

```
from .base import spmatrix, isspmatrix
from .sputils import (isdense, getdtype, isshape, isintlike, isscalarlike,
upcast, upcast_scalar)

```
```    def _mul_vector(self, other):
# matrix * vector
result = np.zeros(self.shape[0], dtype=upcast(self.dtype,other.dtype))
for (i,j),v in iteritems(self):
result[i] += v * other[j]
```
```    def _mul_multivector(self, other):
# matrix * multivector
M,N = self.shape
n_vecs = other.shape[1]  # number of column vectors
result = np.zeros((M,n_vecs), dtype=upcast(self.dtype,other.dtype))
```

```from data import _data_matrix
import sparsetools
from sputils import upcast, to_native, isdense, isshape, getdtype, \
isscalarlike, isintlike

```
```    def _mul_vector(self, other):
M,N = self.shape

#output array
result = np.zeros( self.shape[0], dtype=upcast(self.dtype,other.dtype) )
```
```    def _mul_multivector(self, other):
M,N = self.shape
n_vecs = other.shape[1] #number of column vectors

result = np.zeros( (M,n_vecs), dtype=upcast(self.dtype,other.dtype) )
```
```        nnz = indptr[-1]
indices = np.empty(nnz, dtype=np.intc)
data    = np.empty(nnz, dtype=upcast(self.dtype,other.dtype))

fn = getattr(sparsetools, self.format + '_matmat_pass2')
```
```        #TODO support k-th diagonal
fn = getattr(sparsetools, self.format + "_diagonal")
y = np.empty( min(self.shape), dtype=upcast(self.dtype) )
fn(self.shape[0], self.shape[1], self.indptr, self.indices, self.data, y)
return y
```

```
from base import spmatrix, isspmatrix
from sputils import isdense, getdtype, isshape, isintlike, isscalarlike, upcast

try:
```
```    def _mul_vector(self, other):
#matrix * vector
result = np.zeros( self.shape[0], dtype=upcast(self.dtype,other.dtype) )
for (i,j),v in self.iteritems():
result[i] += v * other[j]
```
```    def _mul_multivector(self, other):
#matrix * multivector
M,N = self.shape
n_vecs = other.shape[1] #number of column vectors
result = np.zeros( (M,n_vecs), dtype=upcast(self.dtype,other.dtype) )
```

```from .dia import dia_matrix
from . import sparsetools
from .sputils import upcast, upcast_char, to_native, isdense, isshape, \
getdtype, isscalarlike, isintlike, IndexMixin

```
```        nnz = indptr[-1]
indices = np.empty(nnz, dtype=np.intc)
data = np.empty(nnz, dtype=upcast(self.dtype,other.dtype))

fn = getattr(sparsetools, self.format + '_matmat_pass2')
```
```        # TODO support k-th diagonal
fn = getattr(sparsetools, self.format + "_diagonal")
y = np.empty(min(self.shape), dtype=upcast(self.dtype))
fn(self.shape[0], self.shape[1], self.indptr, self.indices, self.data, y)
return y
```
```            data = np.empty(maxnnz, dtype=np.bool_)
else:
data = np.empty(maxnnz, dtype=upcast(self.dtype, other.dtype))

fn(self.shape[0], self.shape[1],
```

```from data import _data_matrix
import sparsetools
from sputils import upcast, upcast_char, to_native, isdense, isshape, \
getdtype, isscalarlike, isintlike

```
```        nnz = indptr[-1]
indices = np.empty(nnz, dtype=np.intc)
data    = np.empty(nnz, dtype=upcast(self.dtype,other.dtype))

fn = getattr(sparsetools, self.format + '_matmat_pass2')
```
```        #TODO support k-th diagonal
fn = getattr(sparsetools, self.format + "_diagonal")
y = np.empty( min(self.shape), dtype=upcast(self.dtype) )
fn(self.shape[0], self.shape[1], self.indptr, self.indices, self.data, y)
return y
```
```        indptr  = np.empty_like(self.indptr)
indices = np.empty(maxnnz, dtype=np.intc)
data    = np.empty(maxnnz, dtype=upcast(self.dtype,other.dtype))

fn(self.shape[0], self.shape[1], \
```

```from .compressed import _cs_matrix
from .base import isspmatrix, _formats
from .sputils import isshape, getdtype, to_native, upcast
from . import sparsetools
from .sparsetools import bsr_matvec, bsr_matvecs, csr_matmat_pass1, \
```
```        M,N = self.shape
R,C = self.blocksize
y = np.empty(min(M,N), dtype=upcast(self.dtype))
sparsetools.bsr_diagonal(M//R, N//C, R, C,
self.indptr, self.indices, np.ravel(self.data), y)
```
```    def _mul_vector(self, other):
M,N = self.shape
R,C = self.blocksize

result = np.zeros(self.shape[0], dtype=upcast(self.dtype, other.dtype))
```
```        n_vecs = other.shape[1]  # number of column vectors

result = np.zeros((M,n_vecs), dtype=upcast(self.dtype,other.dtype))

bsr_matvecs(M//R, N//C, n_vecs, R, C,
```
```        bnnz = indptr[-1]
indices = np.empty(bnnz, dtype=np.intc)
data = np.empty(R*C*bnnz, dtype=upcast(self.dtype,other.dtype))

bsr_matmat_pass2(M//R, N//C, R, C, n,
```

```from compressed import _cs_matrix
from base import isspmatrix, _formats
from sputils import isshape, getdtype, to_native, upcast
import sparsetools
from sparsetools import bsr_matvec, bsr_matvecs, csr_matmat_pass1, \
```
```        M,N = self.shape
R,C = self.blocksize
y = np.empty(min(M,N), dtype=upcast(self.dtype))
sparsetools.bsr_diagonal(M//R, N//C, R, C, \
self.indptr, self.indices, np.ravel(self.data), y)
```
```    def _mul_vector(self, other):
M,N = self.shape
R,C = self.blocksize

result = np.zeros(self.shape[0], dtype=upcast(self.dtype, other.dtype))
```
```        n_vecs = other.shape[1] #number of column vectors

result = np.zeros((M,n_vecs), dtype=upcast(self.dtype,other.dtype))

bsr_matvecs(M//R, N//C, n_vecs, R, C, \
```
```        bnnz = indptr[-1]
indices = np.empty(bnnz, dtype=np.intc)
data    = np.empty(R*C*bnnz, dtype=upcast(self.dtype,other.dtype))

bsr_matmat_pass2( M//R, N//C, R, C, n, \
```

```import numpy as np

from .sputils import upcast

from .csr import csr_matrix
```
```        raise ValueError('B is not square')

dtype = upcast(A.dtype, B.dtype)

L = kron(eye(B.shape[0],dtype=dtype), A, format=format)
```
```    nnz = sum([A.nnz for A in blocks[block_mask]])
if dtype is None:
dtype = upcast(*tuple([A.dtype for A in blocks[block_mask]]))

row_offsets = np.concatenate(([0], np.cumsum(brow_lengths)))
```

```import numpy as np

from sputils import upcast

from csr import csr_matrix
```
```        raise ValueError('B is not square')

dtype = upcast(A.dtype, B.dtype)

L = kron(eye(B.shape[0],dtype=dtype), A, format=format)
```
```    nnz = sum([ A.nnz for A in blocks[block_mask] ])
if dtype is None:
dtype = upcast( *tuple([A.dtype for A in blocks[block_mask]]) )

row_offsets = np.concatenate(([0], np.cumsum(brow_lengths)))
```

```from .sparsetools import csc_tocsr
from . import sparsetools
from .sputils import upcast, isintlike, IndexMixin

from .compressed import _cs_matrix
```
```    def tocsr(self):
M,N = self.shape
indptr = np.empty(M + 1, dtype=np.intc)
indices = np.empty(self.nnz, dtype=np.intc)
data = np.empty(self.nnz, dtype=upcast(self.dtype))
```

1 | 2  Next