Skip to content

Commit cf1f99e

Browse files
committed
Running ruff format
1 parent 090f892 commit cf1f99e

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

docs/source/tutorial/algorithm_cp_als.ipynb

+26-13
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"np.random.seed(0)\n",
5454
"\n",
5555
"# Create a low-rank dense tensor from a Kruskal tensor\n",
56-
"factor_matrices = [np.random.rand(s,R) for s in tensor_shape]\n",
56+
"factor_matrices = [np.random.rand(s, R) for s in tensor_shape]\n",
5757
"M_true = ttb.ktensor(factor_matrices)\n",
5858
"X = M_true.to_tensor()"
5959
]
@@ -103,7 +103,8 @@
103103
"outputs": [],
104104
"source": [
105105
"print(\"M1_info:\")\n",
106-
"for k, v in M1_info.items(): print(f\"\\t{k}: {v}\")"
106+
"for k, v in M1_info.items():\n",
107+
" print(f\"\\t{k}: {v}\")"
107108
]
108109
},
109110
{
@@ -121,7 +122,9 @@
121122
"source": [
122123
"# Compute a solution with final ktensor stored in M2\n",
123124
"np.random.seed(2) # Set seed for reproducibility\n",
124-
"M2, M2_init, _ = ttb.cp_als(X, R, maxiters=few_iters) # Will not use third output, so leaving unassigned"
125+
"M2, M2_init, _ = ttb.cp_als(\n",
126+
" X, R, maxiters=few_iters\n",
127+
") # Will not use third output, so leaving unassigned"
125128
]
126129
},
127130
{
@@ -254,7 +257,7 @@
254257
"M3, _, _ = ttb.cp_als(X, R, maxiters=few_iters, init=\"nvecs\", printitn=0)\n",
255258
"score_M3 = M3.score(M_true)\n",
256259
"print(f\"Score of M2 and M_true: {score_M2[0]}\")\n",
257-
"print(f\"Score of M3 and M_true: {score_M3[0]}\")\n"
260+
"print(f\"Score of M3 and M_true: {score_M3[0]}\")"
258261
]
259262
},
260263
{
@@ -271,10 +274,12 @@
271274
"metadata": {},
272275
"outputs": [],
273276
"source": [
274-
"M4, _, M4_info = ttb.cp_als(X, R, maxiters=few_iters, init=\"nvecs\", printitn=0, dimorder=[2, 1, 0])\n",
277+
"M4, _, M4_info = ttb.cp_als(\n",
278+
" X, R, maxiters=few_iters, init=\"nvecs\", printitn=0, dimorder=[2, 1, 0]\n",
279+
")\n",
275280
"score_M4 = M4.score(M_true)\n",
276281
"print(f\"Score of M3 and M_true: {score_M3[0]}\")\n",
277-
"print(f\"Score of M4 and M_true: {score_M4[0]}\")\n"
282+
"print(f\"Score of M4 and M_true: {score_M4[0]}\")"
278283
]
279284
},
280285
{
@@ -295,10 +300,12 @@
295300
"print(f\"Score of M4 and M4_rerun: {score_M4_rerun[0]}\")\n",
296301
"\n",
297302
"print(\"M4_info:\")\n",
298-
"for k, v in M4_info.items(): print(f\"\\t{k}: {v}\")\n",
303+
"for k, v in M4_info.items():\n",
304+
" print(f\"\\t{k}: {v}\")\n",
299305
"\n",
300306
"print(\"M4_rerun_info:\")\n",
301-
"for k, v in M4_rerun_info.items(): print(f\"\\t{k}: {v}\")"
307+
"for k, v in M4_rerun_info.items():\n",
308+
" print(f\"\\t{k}: {v}\")"
302309
]
303310
},
304311
{
@@ -332,21 +339,23 @@
332339
"metadata": {},
333340
"outputs": [],
334341
"source": [
335-
"# Create rank-2 tensor \n",
342+
"# Create rank-2 tensor\n",
336343
"X2 = ttb.ktensor(\n",
337344
" factor_matrices=[\n",
338345
" np.array([[1.0, 1.0], [-1.0, -10.0]]),\n",
339346
" np.array([[1.0, 1.0], [-2.0, -10.0]]),\n",
340347
" ],\n",
341-
" weights=np.array([1.0, 1.0])\n",
348+
" weights=np.array([1.0, 1.0]),\n",
342349
")\n",
343350
"print(f\"X2=\\n{X2}\\n\")\n",
344351
"\n",
345352
"M_fixsigns, _, _ = ttb.cp_als(X2, 2, printitn=0, init=ttb.ktensor(X2.factor_matrices))\n",
346353
"print(f\"M_fixsigns=\\n{M_fixsigns}\\n\") # default behavior, fixsigns called\n",
347354
"\n",
348-
"M_no_fixsigns, _, _ = ttb.cp_als(X2, 2, printitn=0, init=ttb.ktensor(X2.factor_matrices), fixsigns=False)\n",
349-
"print(f\"M_no_fixsigns=\\n{M_no_fixsigns}\\n\") # fixsigns not called\n"
355+
"M_no_fixsigns, _, _ = ttb.cp_als(\n",
356+
" X2, 2, printitn=0, init=ttb.ktensor(X2.factor_matrices), fixsigns=False\n",
357+
")\n",
358+
"print(f\"M_no_fixsigns=\\n{M_no_fixsigns}\\n\") # fixsigns not called"
350359
]
351360
},
352361
{
@@ -359,7 +368,11 @@
359368
]
360369
}
361370
],
362-
"metadata": {},
371+
"metadata": {
372+
"language_info": {
373+
"name": "python"
374+
}
375+
},
363376
"nbformat": 4,
364377
"nbformat_minor": 2
365378
}

0 commit comments

Comments
 (0)