<jupyter_start><jupyter_text>Generate a random sparse matrix<jupyter_code>%matplotlib inline
from matplotlib.pyplot import *

import numpy as np
from scipy.sparse import rand as rand_matrix
A = rand_matrix(200, 200, density=0.01, format='csc', dtype=np.float64, random_state=None)

fig = figure()
ax1 = fig.add_subplot(111)
ax1.spy(A)<jupyter_output><empty_output><jupyter_text>Compute and approximate SVD using libSkylark<jupyter_code>import El
import skylark.nla

parms = skylark.nla.SVDParams()
parms.num_iterations = 10
k = 50

U = El.Matrix()
S = El.Matrix()
V = El.Matrix()
skylark.nla.approximate_svd(A, U, S, V, k, parms)
print S.ToNumPy()[:5]<jupyter_output><empty_output><jupyter_text>Compare to scipy SVD<jupyter_code>from scipy import linalg
Us, Ss, Vs = linalg.svd(A.todense())
print Ss[:5]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12484993997599039, 'fraction_numerical': 0.026410564225690276, 'mean_word_length': 7.019230769230769, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '576210', 'license': 'Apache-2.0', 'n_tokens_mistral': 358, 'n_tokens_neox': 344, 'n_words': 71, 'path': 'python-skylark/skylark/notebooks/SparseSVD.ipynb', 'repo_name': 'xdata-skylark/libskylark', 'size': '833'}