import time
def stopwatch(info):
def _decorator(func):
def wrapper(*args, **kwargs):
t1 = time.time()
output = func(*args, **kwargs)
t2 = time.time()
print('%s: %.3fms' % (info,(t2-t1)*1000) )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
class TrieNode: | |
def __init__(self, char: str): | |
self.char = char | |
self.is_end = False | |
self.children = {} | |
def add_child(self, char: str) -> None: |
Scipy does not currently provide a routine for cholesky decomposition of a sparse matrix, and one have to rely on another external package such as scikit.sparse for the purpose. Here I implement cholesky decomposition of a sparse matrix only using scipy functions. Our implementation relies on sparse LU deconposition.
The following function receives a sparse symmetric positive-definite matrix A and returns a spase lower triangular matrix L such that A = LL^T.
from scipy.sparse import linalg as splinalg
import scipy.sparse as sparse
import sys
def sparse_cholesky(A): # The input matrix A must be a sparse symmetric positive-definite.