Skip to content

Commit

Permalink
fix example in param_demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ovitrac committed Feb 7, 2025
1 parent 2cf9eb9 commit 2a16572
Show file tree
Hide file tree
Showing 28 changed files with 686 additions and 251 deletions.
14 changes: 14 additions & 0 deletions debug_mstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,17 @@
p.t = "1:10:100"
p.list = "${start}:${step}:${stop}"
p()

# %% nested
i = param(debug=True)
i.a = [1,2,3,4]
i.b = 1
i.c = "${a[${b+1}]}"
i.d = "${a[${b}+1]}" # as c with the increment performed outside the expression
i.f = {"A":1, "B":2, "C":3}
i.g = "C"
i.h ="${f['${g}']*100}"
i.a = "[10,20,30]" # previous values are multiplied by (without $, it is a list)
i.b = "2" # index +1
i.f = '{"A":100, "B":200, "C":300}' # previous values are multiplied by 100
i()
2 changes: 1 addition & 1 deletion docs/class_examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ <h2>Welcome to Usage Class Examples</h2>
<p>Select a module in the left menu to view usage examples. These examples are not for production and are automatically extracted from the main section of each module.</p>
<p>Back to the <a href='index.html'>Python'Pizza3 documentation</a>.</p>
<p>When no module is selected, you see this welcome page. They are used to test classes with typical codes. The main section often serves as a testing script, example usage block, or self-contained test block. It's a way to demonstrate how the module's functionality works or to run simple unit tests and examples inline.</p>
<p>Generated on: 2025-02-07 15:50:02</p>
<p>Generated on: 2025-02-07 20:34:01</p>

</div>

Expand Down
2 changes: 1 addition & 1 deletion docs/datatemplate3.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
<h3 style="color: red;">Notice</h3>
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 15:50:05</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 20:34:03</p>
</div>

<h2></h2>
Expand Down
16 changes: 15 additions & 1 deletion docs/debug_mstruct.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,21 @@ <h1 class="title">Module <code>debug_mstruct</code></h1>
p.stop = 100
p.t = &#34;1:10:100&#34;
p.list = &#34;${start}:${step}:${stop}&#34;
p()</code></pre>
p()

# %% nested
i = param(debug=True)
i.a = [1,2,3,4]
i.b = 1
i.c = &#34;${a[${b+1}]}&#34;
i.d = &#34;${a[${b}+1]}&#34; # as c with the increment performed outside the expression
i.f = {&#34;A&#34;:1, &#34;B&#34;:2, &#34;C&#34;:3}
i.g = &#34;C&#34;
i.h =&#34;${f[&#39;${g}&#39;]*100}&#34;
i.a = &#34;[10,20,30]&#34; # previous values are multiplied by (without $, it is a list)
i.b = &#34;2&#34; # index +1
i.f = &#39;{&#34;A&#34;:100, &#34;B&#34;:200, &#34;C&#34;:300}&#39; # previous values are multiplied by 100
i()</code></pre>
</details>
</section>
<section>
Expand Down
2 changes: 1 addition & 1 deletion docs/dscript_math_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
<h3 style="color: red;">Notice</h3>
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 15:50:06</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 20:34:05</p>
</div>

<h2></h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/dump_case4.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
<h3 style="color: red;">Notice</h3>
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 15:50:07</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 20:34:05</p>
</div>

<h2></h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/dumpreduce.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
<h3 style="color: red;">Notice</h3>
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 15:50:07</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 20:34:06</p>
</div>

<h2></h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/dumptemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
<h3 style="color: red;">Notice</h3>
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 15:50:08</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 20:34:07</p>
</div>

<h2></h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/dumptemplate3.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
<h3 style="color: red;">Notice</h3>
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 15:50:08</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 20:34:07</p>
</div>

<h2></h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/geometry.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
<h3 style="color: red;">Notice</h3>
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 15:50:17</p>
<p><strong>Date of Conversion:</strong> 2025-02-07 20:34:15</p>
</div>

<h2></h2>
Expand Down
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ <h2>Welcome to Pizza3 Documentation</h2>
const markdownContent = `
# Pizza Modules Documentation
Generated on: **2025-02-07 15:50:02**
Generated on: **2025-02-07 20:34:01**
<hr style="border: none; height: 1px; background-color: #e0e0e0;" />
Expand Down Expand Up @@ -1904,7 +1904,7 @@ <h2>Welcome to Pizza3 Documentation</h2>
| \`param\` | \`disp\` | display method | 3 | 1.0054 |
| \`param\` | \`dispmax\` | optimize display | 8 | 1.0054 |
| \`param\` | \`escape\` | escape \$\{\} as $\{\{\}\} --> keep variable names convert $\{\} as \{\} --> prepare Python replacement | 35 | 1.0054 |
| \`param\` | \`eval\` | Eval method for structure such as MS.alias | 203 | 1.0054 |
| \`param\` | \`eval\` | Eval method for structure such as MS.alias | 207 | 1.0054 |
| \`param\` | \`expand_ranges\` | Expands MATLAB-style ranges in a string. | 44 | 1.0054 |
| \`param\` | \`format\` | Format a string with fields using \{field\} as placeholders. Handles expressions like $\{variable1\}. | 55 | 1.0054 |
| \`param\` | \`format_array\` | Format NumPy array for display with distinctions for scalars, row/column vectors, and ND arrays. Recursively formats multi-dimensional arrays without introducing unwanted commas. | 106 | 1.0054 |
Expand Down Expand Up @@ -1968,7 +1968,7 @@ <h2>Welcome to Pizza3 Documentation</h2>
| \`paramauto\` | \`disp\` | display method | 3 | 1.0054 |
| \`paramauto\` | \`dispmax\` | optimize display | 8 | 1.0054 |
| \`paramauto\` | \`escape\` | escape \$\{\} as $\{\{\}\} --> keep variable names convert $\{\} as \{\} --> prepare Python replacement | 35 | 1.0054 |
| \`paramauto\` | \`eval\` | Eval method for structure such as MS.alias | 203 | 1.0054 |
| \`paramauto\` | \`eval\` | Eval method for structure such as MS.alias | 207 | 1.0054 |
| \`paramauto\` | \`expand_ranges\` | Expands MATLAB-style ranges in a string. | 44 | 1.0054 |
| \`paramauto\` | \`format\` | Format a string with fields using \{field\} as placeholders. Handles expressions like $\{variable1\}. | 55 | 1.0054 |
| \`paramauto\` | \`format_array\` | Format NumPy array for display with distinctions for scalars, row/column vectors, and ND arrays. Recursively formats multi-dimensional arrays without introducing unwanted commas. | 106 | 1.0054 |
Expand Down
2 changes: 1 addition & 1 deletion docs/index_matlab.html
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ <h2>Welcome to Pizza3 Matlab Documentation</h2>
<p>Back to the <a href='index.html'>Python'Pizza3 documentation</a>.</p>
<hr>
<p><i>When no function is selected, you see this welcome page.</i></p>
Generated on: 2025-02-07 15:50:41</div>
Generated on: 2025-02-07 20:34:42</div>
<div id='Hertz_forces' class='doc-content' style='display: none;'>
<h1>Code to explain the displacement of SPH particles (amorphous) along a rigid wall made with beads of the same size (organized)</h1>
<p>INRAE\Olivier Vitrac, Han Chen - 2023-02-23</p>
Expand Down
26 changes: 19 additions & 7 deletions docs/pizza/private/mstruct.html
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ <h3 id="evaluation-usage">Evaluation Usage</h3>
# 2025-02-01 better separation of param interpolation and global evaluation, consolidation of local evaluation: &#34;the sum p is ${sum(p)}&#34;, [${n},${o}]&#34; (version 1.0052)
# 2025-02-03 add _precision, fix generator for NumPy
# 2025-02-06 maintnance version (fixes and extensions) in agreement with the revised version of param_demo()
# 2025-02-07 add struct.numrepl(), major release (version 1.0054)
# 2025-02-07 add struct.numrepl(), major release (version 1.0054), improve evaluation error messages

__project__ = &#34;Pizza3&#34;
__author__ = &#34;Olivier Vitrac&#34;
Expand Down Expand Up @@ -2217,9 +2217,11 @@ <h3 id="evaluation-usage">Evaluation Usage</h3>
evaluator = SafeEvaluator(tmp)
reseval = evaluate_with_placeholders(resstr,
evaluator,evaluator_nocontext,raiseerror=True)
except:
except Exception as othererr:
if self._returnerror: # added on 2024-09-06
strnameerr = str(nameerr).replace(&#34;&#39;&#34;,&#34;&#34;)
if self._debug:
print(f&#39;Key Error for &#34;{key}&#34; &lt; {othererr} &gt;&#39;)
return &#39;&lt; undef %s &#34;${%s}&#34; &gt;&#39; % (self._ftype,strnameerr)
else:
return value #we keep the original value
Expand All @@ -2234,7 +2236,9 @@ <h3 id="evaluation-usage">Evaluation Usage</h3>
evaluator = SafeEvaluator(tmp)
reseval = evaluate_with_placeholders(resstr,
evaluator,evaluator_nocontext,raiseerror=True)
except:
except Exception as othererr:
if self._debug:
print(f&#39;Type Error for &#34;{key}&#34; &lt; {othererr} &gt;&#39;)
return &#34;Type Error &lt; %s &gt;&#34; % commonerr
else:
return reseval
Expand Down Expand Up @@ -4628,9 +4632,11 @@ <h3 id="notes">Notes</h3>
evaluator = SafeEvaluator(tmp)
reseval = evaluate_with_placeholders(resstr,
evaluator,evaluator_nocontext,raiseerror=True)
except:
except Exception as othererr:
if self._returnerror: # added on 2024-09-06
strnameerr = str(nameerr).replace(&#34;&#39;&#34;,&#34;&#34;)
if self._debug:
print(f&#39;Key Error for &#34;{key}&#34; &lt; {othererr} &gt;&#39;)
return &#39;&lt; undef %s &#34;${%s}&#34; &gt;&#39; % (self._ftype,strnameerr)
else:
return value #we keep the original value
Expand All @@ -4645,7 +4651,9 @@ <h3 id="notes">Notes</h3>
evaluator = SafeEvaluator(tmp)
reseval = evaluate_with_placeholders(resstr,
evaluator,evaluator_nocontext,raiseerror=True)
except:
except Exception as othererr:
if self._debug:
print(f&#39;Type Error for &#34;{key}&#34; &lt; {othererr} &gt;&#39;)
return &#34;Type Error &lt; %s &gt;&#34; % commonerr
else:
return reseval
Expand Down Expand Up @@ -6021,9 +6029,11 @@ <h3>Methods</h3>
evaluator = SafeEvaluator(tmp)
reseval = evaluate_with_placeholders(resstr,
evaluator,evaluator_nocontext,raiseerror=True)
except:
except Exception as othererr:
if self._returnerror: # added on 2024-09-06
strnameerr = str(nameerr).replace(&#34;&#39;&#34;,&#34;&#34;)
if self._debug:
print(f&#39;Key Error for &#34;{key}&#34; &lt; {othererr} &gt;&#39;)
return &#39;&lt; undef %s &#34;${%s}&#34; &gt;&#39; % (self._ftype,strnameerr)
else:
return value #we keep the original value
Expand All @@ -6038,7 +6048,9 @@ <h3>Methods</h3>
evaluator = SafeEvaluator(tmp)
reseval = evaluate_with_placeholders(resstr,
evaluator,evaluator_nocontext,raiseerror=True)
except:
except Exception as othererr:
if self._debug:
print(f&#39;Type Error for &#34;{key}&#34; &lt; {othererr} &gt;&#39;)
return &#34;Type Error &lt; %s &gt;&#34; % commonerr
else:
return reseval
Expand Down
Loading

0 comments on commit 2a16572

Please sign in to comment.