Skip to content

Commit 4cac6e2

Browse files
committed
update README
1 parent 123a1ac commit 4cac6e2

File tree

3 files changed

+485
-1
lines changed

3 files changed

+485
-1
lines changed

README.ipynb

+325
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# MatrixPrintf\n",
8+
"\n",
9+
"[![Build Status](https://travis-ci.com/ohno/MatrixPrintf.jl.svg?branch=main)](https://travis-ci.com/ohno/MatrixPrintf.jl)\n",
10+
"[![Coverage](https://codecov.io/gh/ohno/MatrixPrintf.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ohno/MatrixPrintf.jl)\n",
11+
"[![Coverage](https://coveralls.io/repos/github/ohno/MatrixPrintf.jl/badge.svg?branch=main)](https://coveralls.io/github/ohno/MatrixPrintf.jl?branch=main)\n",
12+
"\n",
13+
"## Installation\n",
14+
"\n",
15+
"To add this package, run the following code in your Jupyter Notebook:"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": 1,
21+
"metadata": {},
22+
"outputs": [
23+
{
24+
"name": "stderr",
25+
"output_type": "stream",
26+
"text": [
27+
"\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m git-repo `https://github.com/ohno/MatrixPrintf.jl.git`\n",
28+
"\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m registry at `C:\\Users\\Shuhei\\.julia\\registries\\General.toml`\n",
29+
"\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n",
30+
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\Shuhei\\.julia\\environments\\v1.7\\Project.toml`\n",
31+
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\Shuhei\\.julia\\environments\\v1.7\\Manifest.toml`\n"
32+
]
33+
}
34+
],
35+
"source": [
36+
"using Pkg\n",
37+
"Pkg.add(path=\"https://github.com/ohno/MatrixPrintf.jl.git\")"
38+
]
39+
},
40+
{
41+
"cell_type": "markdown",
42+
"metadata": {},
43+
"source": [
44+
"or use `add` upon Pkg REPL:\n",
45+
"\n",
46+
"```julia\n",
47+
"]\n",
48+
"add https://github.com/ohno/MatrixPrintf.jl.git\n",
49+
"```"
50+
]
51+
},
52+
{
53+
"cell_type": "markdown",
54+
"metadata": {},
55+
"source": [
56+
"## Usage\n",
57+
"\n",
58+
"To use this package, run the following code in your Jupyter Notebook or code:"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": 2,
64+
"metadata": {},
65+
"outputs": [],
66+
"source": [
67+
"using MatrixPrintf"
68+
]
69+
},
70+
{
71+
"cell_type": "markdown",
72+
"metadata": {},
73+
"source": [
74+
"### Examples"
75+
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": 3,
80+
"metadata": {},
81+
"outputs": [
82+
{
83+
"data": {
84+
"text/plain": [
85+
"2×2 Matrix{Float64}:\n",
86+
" 0.01 2.0\n",
87+
" 3.0 -400.0"
88+
]
89+
},
90+
"execution_count": 3,
91+
"metadata": {},
92+
"output_type": "execute_result"
93+
}
94+
],
95+
"source": [
96+
"A = [1 2;\n",
97+
" 3 4]\n",
98+
"\n",
99+
"B = [1 0;\n",
100+
" 0 -1]\n",
101+
"\n",
102+
"C = [0.01 2;\n",
103+
" 3.0 -400]"
104+
]
105+
},
106+
{
107+
"cell_type": "code",
108+
"execution_count": 4,
109+
"metadata": {
110+
"scrolled": false
111+
},
112+
"outputs": [
113+
{
114+
"name": "stdout",
115+
"output_type": "stream",
116+
"text": [
117+
"### `msprintf(M)`\n",
118+
"\n",
119+
"```julia:input\n",
120+
"msprintf(A)\n",
121+
"msprintf(B)\n",
122+
"msprintf(C)\n",
123+
"```\n",
124+
"\n",
125+
"```julia:output\n",
126+
"[1.0 2.0;\n",
127+
" 3.0 4.0]\n",
128+
"[ 1.0  0.0;\n",
129+
"  0.0 -1.0]\n",
130+
"[   0.0    2.0;\n",
131+
"    3.0 -400.0]\n",
132+
"```\n",
133+
"\n",
134+
"### `msprintf(M, symbol=\"M\")`\n",
135+
"\n",
136+
"```julia:input\n",
137+
"msprintf(A, symbol=\"A\")\n",
138+
"msprintf(B, symbol=\"B\")\n",
139+
"msprintf(C, symbol=\"C\")\n",
140+
"```\n",
141+
"\n",
142+
"```julia:output\n",
143+
"A = [1.0 2.0;\n",
144+
"     3.0 4.0]\n",
145+
"B = [ 1.0  0.0;\n",
146+
"      0.0 -1.0]\n",
147+
"C = [   0.0    2.0;\n",
148+
"        3.0 -400.0]\n",
149+
"```\n",
150+
"\n",
151+
"### `msprintf(M, symbol=\"M\", digit=5)`\n",
152+
"\n",
153+
"```julia:input\n",
154+
"msprintf(A, symbol=\"A\", digit=5)\n",
155+
"msprintf(B, symbol=\"B\", digit=5)\n",
156+
"msprintf(C, symbol=\"C\", digit=5)\n",
157+
"```\n",
158+
"\n",
159+
"```julia:output\n",
160+
"A = [1.00000 2.00000;\n",
161+
"     3.00000 4.00000]\n",
162+
"B = [ 1.00000  0.00000;\n",
163+
"      0.00000 -1.00000]\n",
164+
"C = [   0.01000    2.00000;\n",
165+
"        3.00000 -400.00000]\n",
166+
"```\n",
167+
"\n",
168+
"### `msprintf(M, symbol=\"M\", digit=2)`\n",
169+
"\n",
170+
"```julia:input\n",
171+
"msprintf(A, symbol=\"A\", digit=2)\n",
172+
"msprintf(B, symbol=\"B\", digit=2)\n",
173+
"msprintf(C, symbol=\"C\", digit=2)\n",
174+
"```\n",
175+
"\n",
176+
"```julia:output\n",
177+
"A = [1.00 2.00;\n",
178+
"     3.00 4.00]\n",
179+
"B = [ 1.00  0.00;\n",
180+
"      0.00 -1.00]\n",
181+
"C = [   0.01    2.00;\n",
182+
"        3.00 -400.00]\n",
183+
"```\n",
184+
"\n",
185+
"### `msprintf(M, symbol=\"M\", digit=0)`\n",
186+
"\n",
187+
"```julia:input\n",
188+
"msprintf(A, symbol=\"A\", digit=0)\n",
189+
"msprintf(B, symbol=\"B\", digit=0)\n",
190+
"msprintf(C, symbol=\"C\", digit=0)\n",
191+
"```\n",
192+
"\n",
193+
"```julia:output\n",
194+
"A = [1 2;\n",
195+
"     3 4]\n",
196+
"B = [ 1  0;\n",
197+
"      0 -1]\n",
198+
"C = [   0    2;\n",
199+
"        3 -400]\n",
200+
"```\n",
201+
"\n",
202+
"### `msprintf(M, symbol=\"M\", format=\"%d\")`\n",
203+
"\n",
204+
"```julia:input\n",
205+
"msprintf(A, symbol=\"A\", format=\"%d\")\n",
206+
"msprintf(B, symbol=\"B\", format=\"%d\")\n",
207+
"msprintf(C, symbol=\"C\", format=\"%d\")\n",
208+
"```\n",
209+
"\n",
210+
"```julia:output\n",
211+
"A = [1 2;\n",
212+
"     3 4]\n",
213+
"B = [1 0;\n",
214+
"     0 -1]\n",
215+
"C = [0 2;\n",
216+
"     3 -400]\n",
217+
"```\n",
218+
"\n",
219+
"### `msprintf(M, symbol=\"M\", format=\"%8.1e\")`\n",
220+
"\n",
221+
"```julia:input\n",
222+
"msprintf(A, symbol=\"A\", format=\"%8.1e\")\n",
223+
"msprintf(B, symbol=\"B\", format=\"%8.1e\")\n",
224+
"msprintf(C, symbol=\"C\", format=\"%8.1e\")\n",
225+
"```\n",
226+
"\n",
227+
"```julia:output\n",
228+
"A = [ 1.0e+00  2.0e+00;\n",
229+
"      3.0e+00  4.0e+00]\n",
230+
"B = [ 1.0e+00  0.0e+00;\n",
231+
"      0.0e+00 -1.0e+00]\n",
232+
"C = [ 1.0e-02  2.0e+00;\n",
233+
"      3.0e+00 -4.0e+02]\n",
234+
"```\n",
235+
"\n"
236+
]
237+
}
238+
],
239+
"source": [
240+
"function table(title, codes...)\n",
241+
" f(code) = eval(Meta.parse(code))\n",
242+
" X = codes\n",
243+
" Y = f.(X)\n",
244+
" \n",
245+
" println(\"### `$(title)`\")\n",
246+
" println(\"\\n```julia:input\")\n",
247+
" for row in X\n",
248+
" println(replace(row, \" \"=>\" \"))\n",
249+
" end\n",
250+
" println(\"```\")\n",
251+
" println(\"\\n```julia:output\")\n",
252+
" for row in Y\n",
253+
" println(replace(row, \" \"=>\" \"))\n",
254+
" end\n",
255+
" println(\"```\\n\")\n",
256+
" \n",
257+
"end\n",
258+
"\n",
259+
"table(\"msprintf(M)\",\n",
260+
" \"msprintf(A)\",\n",
261+
" \"msprintf(B)\",\n",
262+
" \"msprintf(C)\"\n",
263+
")\n",
264+
"\n",
265+
"table(\"msprintf(M, symbol=\\\"M\\\")\",\n",
266+
" \"msprintf(A, symbol=\\\"A\\\")\",\n",
267+
" \"msprintf(B, symbol=\\\"B\\\")\",\n",
268+
" \"msprintf(C, symbol=\\\"C\\\")\"\n",
269+
")\n",
270+
"\n",
271+
"table(\"msprintf(M, symbol=\\\"M\\\", digit=5)\",\n",
272+
" \"msprintf(A, symbol=\\\"A\\\", digit=5)\",\n",
273+
" \"msprintf(B, symbol=\\\"B\\\", digit=5)\",\n",
274+
" \"msprintf(C, symbol=\\\"C\\\", digit=5)\"\n",
275+
")\n",
276+
"\n",
277+
"table(\"msprintf(M, symbol=\\\"M\\\", digit=2)\",\n",
278+
" \"msprintf(A, symbol=\\\"A\\\", digit=2)\",\n",
279+
" \"msprintf(B, symbol=\\\"B\\\", digit=2)\",\n",
280+
" \"msprintf(C, symbol=\\\"C\\\", digit=2)\"\n",
281+
")\n",
282+
"\n",
283+
"table(\"msprintf(M, symbol=\\\"M\\\", digit=0)\",\n",
284+
" \"msprintf(A, symbol=\\\"A\\\", digit=0)\",\n",
285+
" \"msprintf(B, symbol=\\\"B\\\", digit=0)\",\n",
286+
" \"msprintf(C, symbol=\\\"C\\\", digit=0)\"\n",
287+
")\n",
288+
"\n",
289+
"table(\"msprintf(M, symbol=\\\"M\\\", format=\\\"%d\\\")\",\n",
290+
" \"msprintf(A, symbol=\\\"A\\\", format=\\\"%d\\\")\",\n",
291+
" \"msprintf(B, symbol=\\\"B\\\", format=\\\"%d\\\")\",\n",
292+
" \"msprintf(C, symbol=\\\"C\\\", format=\\\"%d\\\")\"\n",
293+
")\n",
294+
"\n",
295+
"table(\"msprintf(M, symbol=\\\"M\\\", format=\\\"%8.1e\\\")\",\n",
296+
" \"msprintf(A, symbol=\\\"A\\\", format=\\\"%8.1e\\\")\",\n",
297+
" \"msprintf(B, symbol=\\\"B\\\", format=\\\"%8.1e\\\")\",\n",
298+
" \"msprintf(C, symbol=\\\"C\\\", format=\\\"%8.1e\\\")\"\n",
299+
")"
300+
]
301+
},
302+
{
303+
"cell_type": "markdown",
304+
"metadata": {},
305+
"source": [
306+
"`mprintf(M)` is same as `println(msprintf(M))`. If you want to get the return value as a string, use `msprintf(M)`. `format=\"\"` is the same as the first argument of `@sprintf` and `@printf`. For more information about `format=\"\"`, see [my article](https://zenn.dev/ohno/articles/8b35354a8140f8) or [the official documentation](https://docs.julialang.org/en/v1/stdlib/Printf/)."
307+
]
308+
}
309+
],
310+
"metadata": {
311+
"kernelspec": {
312+
"display_name": "Julia 1.7.1",
313+
"language": "julia",
314+
"name": "julia-1.7"
315+
},
316+
"language_info": {
317+
"file_extension": ".jl",
318+
"mimetype": "application/julia",
319+
"name": "julia",
320+
"version": "1.7.1"
321+
}
322+
},
323+
"nbformat": 4,
324+
"nbformat_minor": 4
325+
}

0 commit comments

Comments
 (0)