Skip to content

Instantly share code, notes, and snippets.

@hameerabbasi
Created June 12, 2018 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hameerabbasi/0230eb7b6359416d1db4167f802ada83 to your computer and use it in GitHub Desktop.
Save hameerabbasi/0230eb7b6359416d1db4167f802ada83 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import sparse"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import dask.array as da"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"s = sparse.random((100000, 100000), density=0.0001)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"x = da.from_array(s, chunks=(10000, 10000), asarray=False, fancy=False).persist()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.571170042811673e+22\n",
"CPU times: user 18 s, sys: 2.83 s, total: 20.9 s\n",
"Wall time: 15.6 s\n"
]
}
],
"source": [
"%%time\n",
"for i in range(4):\n",
" s = (s + s.T) * s.sum(axis=0)\n",
"print(s.sum())"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.5711700428116743e+22\n",
"CPU times: user 15.5 s, sys: 2.84 s, total: 18.3 s\n",
"Wall time: 7.34 s\n"
]
}
],
"source": [
"%%time \n",
"for i in range(4):\n",
" x = (x + x.T) * x.sum(axis=0)\n",
"y = x.sum()\n",
"print(y.compute())"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/hameerabbasi/anaconda3/lib/python3.6/site-packages/dask/array/core.py:2187: UserWarning: Increasing number of chunks by factor of 10\n",
" (nparts / max_parts))\n"
]
},
{
"data": {
"text/plain": [
"6.720557033161344e+41"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x.dot(x.T).sum().compute()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment