From 4c416af356711887bf7dee16bfe78ae8daa28698 Mon Sep 17 00:00:00 2001 From: Adam Lugowski Date: Fri, 1 Sep 2023 00:01:51 -0700 Subject: [PATCH] HTML: specify cell align value for each cell --- doc/demo-edgecases.ipynb | 44 +- doc/demo-python-graphblas.ipynb | 730 ++++++++++++++++---------------- matrepr/html_formatter.py | 15 +- 3 files changed, 394 insertions(+), 395 deletions(-) diff --git a/doc/demo-edgecases.ipynb b/doc/demo-edgecases.ipynb index a6bd1ae..27bc768 100644 --- a/doc/demo-edgecases.ipynb +++ b/doc/demo-edgecases.ipynb @@ -21,8 +21,8 @@ "outputs_hidden": false }, "ExecuteTime": { - "end_time": "2023-09-01T05:35:54.033440Z", - "start_time": "2023-09-01T05:35:54.022552Z" + "end_time": "2023-09-01T06:59:28.652355Z", + "start_time": "2023-09-01T06:59:27.292068Z" } }, "outputs": [], @@ -60,8 +60,8 @@ "outputs_hidden": false }, "ExecuteTime": { - "end_time": "2023-09-01T05:35:54.243630Z", - "start_time": "2023-09-01T05:35:54.031933Z" + "end_time": "2023-09-01T06:59:28.668542Z", + "start_time": "2023-09-01T06:59:27.305887Z" } }, "outputs": [], @@ -83,15 +83,15 @@ "outputs_hidden": false }, "ExecuteTime": { - "end_time": "2023-09-01T05:35:54.253576Z", - "start_time": "2023-09-01T05:35:54.244739Z" + "end_time": "2023-09-01T06:59:28.677319Z", + "start_time": "2023-09-01T06:59:28.090059Z" } }, "outputs": [ { "data": { "text/plain": "", - "text/html": "
\n\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
5×5, 9 'float64' elements, coo
01234
011.2e+35
11e-06
22.1
2.2
33.1
3.2
3.3
40
\n
" + "text/html": "
\n\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
5×5, 9 'float64' elements, coo
01234
011.2e+35
11e-06
22.1
2.2
33.1
3.2
3.3
40
\n
" }, "metadata": {}, "output_type": "display_data" @@ -110,8 +110,8 @@ "outputs_hidden": false }, "ExecuteTime": { - "end_time": "2023-09-01T05:35:54.264038Z", - "start_time": "2023-09-01T05:35:54.255937Z" + "end_time": "2023-09-01T06:59:28.677500Z", + "start_time": "2023-09-01T06:59:28.090177Z" } }, "outputs": [ @@ -137,8 +137,8 @@ "outputs_hidden": false }, "ExecuteTime": { - "end_time": "2023-09-01T05:35:54.279315Z", - "start_time": "2023-09-01T05:35:54.268157Z" + "end_time": "2023-09-01T06:59:28.677607Z", + "start_time": "2023-09-01T06:59:28.090214Z" } }, "outputs": [ @@ -184,8 +184,8 @@ "outputs_hidden": false }, "ExecuteTime": { - "end_time": "2023-09-01T05:35:54.339182Z", - "start_time": "2023-09-01T05:35:54.334389Z" + "end_time": "2023-09-01T06:59:28.677652Z", + "start_time": "2023-09-01T06:59:28.090327Z" } }, "outputs": [], @@ -222,15 +222,15 @@ "outputs_hidden": false }, "ExecuteTime": { - "end_time": "2023-09-01T05:35:54.352136Z", - "start_time": "2023-09-01T05:35:54.341469Z" + "end_time": "2023-09-01T06:59:28.677730Z", + "start_time": "2023-09-01T06:59:28.090358Z" } }, "outputs": [ { "data": { "text/plain": "", - "text/html": "
\n\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
6×5, 18 elements, list
onetwothreefourfive
sci01.2e+351e-061.235e+08
single1
complex1+2i1.235e05 + 0.1235i
nested\n \n \n \n \n \n \n \n
1
\n \n \n \n \n \n \n \n \n \n \n \n \n \n
012
134
\n \n \n \n \n \n \n \n \n
2.12.2
\n \n \n \n \n \n \n \n \n \n \n \n \n \n
01.12.2
13.34.4
stringsmultiline
string
<escape!>\\begin{escape!}{'a Python set'}
numpy(False, 2)\n \n \n \n \n \n \n \n \n \n
123
\n \n \n \n \n \n \n \n \n \n \n \n \n \n
01122
13344
\n
" + "text/html": "
\n\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
6×5, 18 elements, list
onetwothreefourfive
sci01.2e+351e-061.235e+08
single1
complex1+2i1.235e05 + 0.1235i
nested\n \n \n \n \n \n \n
1
\n \n \n \n \n \n \n \n \n \n \n \n
12
34
\n \n \n \n \n \n \n \n
2.12.2
\n \n \n \n \n \n \n \n \n \n \n \n
1.12.2
3.34.4
stringsmultiline
string
<escape!>\\begin{escape!}{'a Python set'}
numpy(False, 2)\n \n \n \n \n \n \n \n \n
123
\n \n \n \n \n \n \n \n \n \n \n \n
1122
3344
\n
" }, "metadata": {}, "output_type": "display_data" @@ -249,8 +249,8 @@ "outputs_hidden": false }, "ExecuteTime": { - "end_time": "2023-09-01T05:35:54.364723Z", - "start_time": "2023-09-01T05:35:54.352608Z" + "end_time": "2023-09-01T06:59:28.677795Z", + "start_time": "2023-09-01T06:59:28.090447Z" } }, "outputs": [ @@ -276,8 +276,8 @@ "outputs_hidden": false }, "ExecuteTime": { - "end_time": "2023-09-01T05:35:54.378646Z", - "start_time": "2023-09-01T05:35:54.359958Z" + "end_time": "2023-09-01T06:59:28.677897Z", + "start_time": "2023-09-01T06:59:28.090630Z" } }, "outputs": [ @@ -298,8 +298,8 @@ "execution_count": 9, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:35:54.405760Z", - "start_time": "2023-09-01T05:35:54.376295Z" + "end_time": "2023-09-01T06:59:28.677948Z", + "start_time": "2023-09-01T06:59:28.606962Z" } }, "outputs": [], diff --git a/doc/demo-python-graphblas.ipynb b/doc/demo-python-graphblas.ipynb index 4231a2a..e8c098e 100644 --- a/doc/demo-python-graphblas.ipynb +++ b/doc/demo-python-graphblas.ipynb @@ -17,12 +17,11 @@ "execution_count": 1, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:07.430124Z", - "start_time": "2023-09-01T05:54:07.302550Z" + "end_time": "2023-09-01T06:59:37.099842Z", + "start_time": "2023-09-01T06:59:34.035386Z" }, - "collapsed": false, "jupyter": { - "outputs_hidden": false + "source_hidden": true } }, "outputs": [], @@ -40,25 +39,6 @@ "from matrepr import mdisplay" ] }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "ExecuteTime": { - "end_time": "2023-09-01T05:54:07.681076Z", - "start_time": "2023-09-01T05:54:07.431231Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [], - "source": [ - "A = gb.io.from_scipy_sparse(scipy.sparse.random(1000, 1000, density=0.212345))\n", - "v = gb.Vector.from_coo([0, 3, 4, 6], [12.1, -5.4e-12, 2.9e20, 2.2], size=8)" - ] - }, { "cell_type": "markdown", "metadata": { @@ -68,16 +48,16 @@ } }, "source": [ - "# Graph: Vertex-labeled Adjacency Matrix" + "## Graph: Adjacency Matrix with Vertex Weights/Labels" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 2, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:07.696714Z", - "start_time": "2023-09-01T05:54:07.686930Z" + "end_time": "2023-09-01T06:59:37.102468Z", + "start_time": "2023-09-01T06:59:34.040280Z" }, "collapsed": false, "jupyter": { @@ -92,16 +72,16 @@ " [3, 2, 3, 1, 5, 3, 7, 8, 3, 1, 7, 4],\n", " nrows=7, ncols=7\n", ")\n", - "vertices = gb.Vector.from_coo([range(7)], [f\"V{i+1}\" for i in range(7)], size=8)" + "vertices = gb.Vector.from_coo([range(7)], [f\"V{i+1}\" for i in range(7)], size=7)" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 3, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:07.709809Z", - "start_time": "2023-09-01T05:54:07.699189Z" + "end_time": "2023-09-01T06:59:37.104446Z", + "start_time": "2023-09-01T06:59:34.042277Z" }, "collapsed": false, "jupyter": { @@ -221,7 +201,6 @@ " }\n", "\n", "\n", - "\n", " \n", " \n", " \n", @@ -237,73 +216,73 @@ " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", "
7×7, 12 'INT64' elements, bitmapr, gb.Matrix
V12323
V28484
V311
V43333
V577
V611
V7573573
\n", @@ -318,7 +297,7 @@ } ], "source": [ - "mdisplay(edges, row_labels=vertices, col_labels=vertices)" + "mdisplay(edges, row_labels=vertices, col_labels=vertices, title=False)" ] }, { @@ -328,13 +307,32 @@ "## python-graphblas native formatting" ] }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "ExecuteTime": { + "end_time": "2023-09-01T06:59:37.121575Z", + "start_time": "2023-09-01T06:59:34.048236Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [], + "source": [ + "A = gb.io.from_scipy_sparse(scipy.sparse.random(1000, 1000, density=0.212345))\n", + "v = gb.Vector.from_coo([0, 3, 4, 6], [12.1, -5.4e-12, 2.9e20, 2.2], size=8)" + ] + }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:07.927772Z", - "start_time": "2023-09-01T05:54:07.716995Z" + "end_time": "2023-09-01T06:59:37.126377Z", + "start_time": "2023-09-01T06:59:34.833407Z" }, "collapsed": false, "jupyter": { @@ -445,7 +443,7 @@ " background-color: #f8ffed;\n", "}\n", "\n", - "
M0
\n", + "
M2
\n", "\n", " \n", " \n", @@ -775,7 +773,7 @@ "" ], "text/plain": [ - "\"M_0\" nvals nrows ncols dtype format\n", + "\"M_2\" nvals nrows ncols dtype format\n", "gb.Matrix 212345 1000 1000 FP64 csr\n", "----------------------------------------------\n", " 0 1 2 3 4 5 6 \\\n", @@ -832,8 +830,8 @@ "execution_count": 6, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:07.932468Z", - "start_time": "2023-09-01T05:54:07.930754Z" + "end_time": "2023-09-01T06:59:37.126609Z", + "start_time": "2023-09-01T06:59:34.833530Z" } }, "outputs": [ @@ -940,7 +938,7 @@ " background-color: #f8ffed;\n", "}\n", "\n", - "
v0
\n", + "
v1
\n", "
gb.Matrix
\n", " \n", " \n", @@ -1002,7 +1000,7 @@ "" ], "text/plain": [ - "\"v_0\" nvals size dtype format\n", + "\"v_1\" nvals size dtype format\n", "gb.Vector 4 8 FP64 bitmap\n", "-------------------------------------\n", "index 0 1 2 3 4 5 6 7\n", @@ -1030,8 +1028,8 @@ "execution_count": 7, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:07.934317Z", - "start_time": "2023-09-01T05:54:07.933411Z" + "end_time": "2023-09-01T06:59:37.126693Z", + "start_time": "2023-09-01T06:59:34.833629Z" }, "collapsed": false, "jupyter": { @@ -1048,8 +1046,8 @@ "execution_count": 8, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:08.011107Z", - "start_time": "2023-09-01T05:54:07.936197Z" + "end_time": "2023-09-01T06:59:37.126779Z", + "start_time": "2023-09-01T06:59:34.833679Z" } }, "outputs": [ @@ -1189,208 +1187,208 @@ " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", "
gb.Vector
00.38760.95220.86280.38760.95220.8628
10.58010.50850.89270.46420.7960.58010.50850.89270.46420.796
20.850.92240.850.9224
30.71420.81820.13960.71420.81820.1396
40.86310.2120.0630.86310.2120.063
9950.40870.26980.84790.24530.40870.26980.84790.2453
9960.4630.081070.23790.4630.081070.2379
9970.028870.8680.028870.868
9980.35520.036160.72210.35520.036160.7221
9990.26240.7290.26240.729
\n", "
" ], "text/plain": [ - "\"M_0\" nvals nrows ncols dtype format\n", + "\"M_2\" nvals nrows ncols dtype format\n", "gb.Matrix 212345 1000 1000 FP64 csr\n", "----------------------------------------------\n", " 0 1 2 3 4 5 6 \\\n", @@ -1447,8 +1445,8 @@ "execution_count": 9, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:08.016319Z", - "start_time": "2023-09-01T05:54:08.012301Z" + "end_time": "2023-09-01T06:59:37.126848Z", + "start_time": "2023-09-01T06:59:34.835635Z" } }, "outputs": [ @@ -1579,21 +1577,21 @@ " \n", " \n", " \n", - " 12.1\n", - " \n", - " \n", - " -5.4e-12\n", - " 2.9e+20\n", - " \n", - " 2.2\n", - " \n", + " 12.1\n", + " \n", + " \n", + " -5.4e-12\n", + " 2.9e+20\n", + " \n", + " 2.2\n", + " \n", " \n", " \n", "\n", "
" ], "text/plain": [ - "\"v_0\" nvals size dtype format\n", + "\"v_1\" nvals size dtype format\n", "gb.Vector 4 8 FP64 bitmap\n", "-------------------------------------\n", "index 0 1 2 3 4 5 6 7\n", @@ -1621,8 +1619,8 @@ "execution_count": 10, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:08.087401Z", - "start_time": "2023-09-01T05:54:08.014693Z" + "end_time": "2023-09-01T06:59:37.126913Z", + "start_time": "2023-09-01T06:59:34.835709Z" }, "collapsed": false, "jupyter": { @@ -1664,8 +1662,8 @@ "execution_count": 11, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:08.090705Z", - "start_time": "2023-09-01T05:54:08.088481Z" + "end_time": "2023-09-01T06:59:37.127005Z", + "start_time": "2023-09-01T06:59:34.835757Z" } }, "outputs": [ @@ -1705,8 +1703,8 @@ "execution_count": 12, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:08.178715Z", - "start_time": "2023-09-01T05:54:08.091149Z" + "end_time": "2023-09-01T06:59:37.127096Z", + "start_time": "2023-09-01T06:59:34.835862Z" }, "collapsed": false, "jupyter": { @@ -1747,8 +1745,8 @@ "execution_count": 13, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:08.184199Z", - "start_time": "2023-09-01T05:54:08.179307Z" + "end_time": "2023-09-01T06:59:37.127168Z", + "start_time": "2023-09-01T06:59:34.835902Z" }, "collapsed": false, "jupyter": { @@ -1777,8 +1775,8 @@ "execution_count": 14, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:08.186648Z", - "start_time": "2023-09-01T05:54:08.184349Z" + "end_time": "2023-09-01T06:59:37.127229Z", + "start_time": "2023-09-01T06:59:34.835935Z" }, "collapsed": false, "jupyter": { @@ -1813,8 +1811,8 @@ "execution_count": 15, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:08.192410Z", - "start_time": "2023-09-01T05:54:08.187584Z" + "end_time": "2023-09-01T06:59:37.127265Z", + "start_time": "2023-09-01T06:59:34.835968Z" }, "collapsed": false, "jupyter": { @@ -1835,8 +1833,8 @@ "execution_count": 16, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:08.200853Z", - "start_time": "2023-09-01T05:54:08.189341Z" + "end_time": "2023-09-01T06:59:37.127341Z", + "start_time": "2023-09-01T06:59:34.835994Z" }, "collapsed": false, "jupyter": { @@ -1972,110 +1970,110 @@ " \n", " \n", " 0\n", - " \n", - " \n", - " \n", - " \n", - " 0.3876\n", - " \n", - " ⋯\n", + " \n", + " \n", + " \n", + " \n", + " 0.3876\n", + " \n", + " ⋯\n", " \n", " \n", " 1\n", - " 0.5801\n", - " 0.5085\n", - " \n", - " 0.8927\n", - " \n", - " \n", - " ⋯\n", + " 0.5801\n", + " 0.5085\n", + " \n", + " 0.8927\n", + " \n", + " \n", + " ⋯\n", " \n", " \n", " 2\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " ⋯\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " ⋯\n", " \n", " \n", " 3\n", - " \n", - " \n", - " 0.7142\n", - " \n", - " \n", - " \n", - " ⋯\n", + " \n", + " \n", + " 0.7142\n", + " \n", + " \n", + " \n", + " ⋯\n", " \n", " \n", " 4\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " 0.8631\n", - " ⋯\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " 0.8631\n", + " ⋯\n", " \n", " \n", " 5\n", - " 0.7863\n", - " 0.1298\n", - " 0.9918\n", - " 0.71\n", - " \n", - " \n", - " ⋯\n", + " 0.7863\n", + " 0.1298\n", + " 0.9918\n", + " 0.71\n", + " \n", + " \n", + " ⋯\n", " \n", " \n", " 6\n", - " \n", - " \n", - " 0.9481\n", - " \n", - " \n", - " \n", - " ⋯\n", + " \n", + " \n", + " 0.9481\n", + " \n", + " \n", + " \n", + " ⋯\n", " \n", " \n", " 7\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " ⋯\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " ⋯\n", " \n", " \n", " 8\n", - " \n", - " \n", - " \n", - " \n", - " 0.4023\n", - " \n", - " ⋯\n", + " \n", + " \n", + " \n", + " \n", + " 0.4023\n", + " \n", + " ⋯\n", " \n", " \n", " \n", - " ⋮\n", - " ⋮\n", - " ⋮\n", - " ⋮\n", - " ⋮\n", - " ⋮\n", - " ⋱\n", + " ⋮\n", + " ⋮\n", + " ⋮\n", + " ⋮\n", + " ⋮\n", + " ⋮\n", + " ⋱\n", " \n", " \n", "\n", "" ], "text/plain": [ - "\"M_0\" nvals nrows ncols dtype format\n", + "\"M_2\" nvals nrows ncols dtype format\n", "gb.Matrix 212345 1000 1000 FP64 csr\n", "----------------------------------------------\n", " 0 1 2 3 4 5 6 \\\n", @@ -2132,8 +2130,8 @@ "execution_count": 17, "metadata": { "ExecuteTime": { - "end_time": "2023-09-01T05:54:08.218296Z", - "start_time": "2023-09-01T05:54:08.198363Z" + "end_time": "2023-09-01T06:59:37.127401Z", + "start_time": "2023-09-01T06:59:34.836103Z" }, "collapsed": false, "jupyter": { @@ -2267,20 +2265,20 @@ " \n", " \n", " \n", - " 12.1\n", - " \n", - " \n", - " -5.4e-12\n", - " 2.9e+20\n", - " \n", - " ⋯\n", + " 12.1\n", + " \n", + " \n", + " -5.4e-12\n", + " 2.9e+20\n", + " \n", + " ⋯\n", " \n", " \n", "\n", "" ], "text/plain": [ - "\"v_0\" nvals size dtype format\n", + "\"v_1\" nvals size dtype format\n", "gb.Vector 4 8 FP64 bitmap\n", "-------------------------------------\n", "index 0 1 2 3 4 5 6 7\n", diff --git a/matrepr/html_formatter.py b/matrepr/html_formatter.py index 0e5c3cc..4c6e0e6 100644 --- a/matrepr/html_formatter.py +++ b/matrepr/html_formatter.py @@ -31,7 +31,7 @@ def __init__(self, max_rows, max_cols, num_after_dots, title, indices=False, cel self.cell_align = cell_align self.floatfmt = floatfmt if floatfmt else lambda f: format(f) self.indent_width = 4 - self.center_header = False + self.bake_cell_align = False self.table_attributes = {} # noinspection PyMethodMayBeStatic @@ -103,6 +103,7 @@ def _write_matrix(self, mat: MatrixAdapterRow, if self.title: self.write(f"{self.title}") + attr_align = f' style="text-align: {self.cell_align};"' if self.bake_cell_align else "" # Header if self.indices and mat.has_col_labels(): self.write(f'', indent=body_indent) @@ -110,8 +111,8 @@ def _write_matrix(self, mat: MatrixAdapterRow, if mat.has_row_labels(): self.write(f"", indent=cell_indent) for idx in range(ncols): - attr = ' style="text-align: center;"' if self.center_header else "" - self.write(f"{self.pprint(mat.get_col_label(idx), is_index=True)}", indent=cell_indent) + self.write(f"{self.pprint(mat.get_col_label(idx), is_index=True)}", + indent=cell_indent) self.write("", indent=body_indent) self.write("", indent=body_indent) @@ -119,12 +120,12 @@ def _write_matrix(self, mat: MatrixAdapterRow, self.write("", indent=body_indent) for row_idx in range(nrows): self.write("", body_indent) - if mat.has_row_labels(): + if self.indices and mat.has_row_labels(): self.write(f"{self.pprint(mat.get_row_label(row_idx), is_index=True)}", cell_indent) col_range = (0, ncols) for col_idx, cell in enumerate(mat.get_dense_row(row_idx, col_range=col_range)): - self.write(f"{self.pprint(cell, cell_indent)}", cell_indent) + self.write(f"{self.pprint(cell, cell_indent)}", cell_indent) self.write("", body_indent) @@ -201,7 +202,7 @@ def _write_style(self, matrix_class: str, tensor_class: str): (thead, {"border": "0px"}), (tbody + "tr th", {**index_attributes, "text-align": "right"}), # row indices (thead + "tr th", {**index_attributes, "text-align": "center"}), # column indices - (tbody + "tr td", {"vertical-align": "middle", "text-align": self.cell_align, "position": "relative"}), + (tbody + "tr td", {"vertical-align": "middle", "text-align": "center", "position": "relative"}), (tbody + "tr td:first-of-type", {"border-left": border}), # left border (tbody + "tr td:last-of-type", {"border-right": border}), # right border # need two of these because ticks may narrow down one of them @@ -236,7 +237,7 @@ def format(self, mat: MatrixAdapter, indent: int = 0): if write_div: self.write("
") self._write_style(matrix_class=matrix_class, tensor_class=tensor_class) - self.center_header = True + self.bake_cell_align = True super().format(mat, indent=indent) if write_div: self.write("
")