Skip to content

Commit c4578e8

Browse files
committed
fix slowdown in v1.006 - defer evaluation in paramauto
1 parent cf89c7b commit c4578e8

28 files changed

+1267
-530
lines changed

docs/class_examples.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ <h2>Welcome to Usage Class Examples</h2>
353353
<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>
354354
<p>Back to the <a href='index.html'>Python'Pizza3 documentation</a>.</p>
355355
<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>
356-
<p>Generated on: 2025-02-20 12:54:09</p>
356+
<p>Generated on: 2025-02-20 21:47:30</p>
357357

358358
</div>
359359

docs/datatemplate3.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
9797
<h3 style="color: red;">Notice</h3>
9898
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
99-
<p><strong>Date of Conversion:</strong> 2025-02-20 12:54:11</p>
99+
<p><strong>Date of Conversion:</strong> 2025-02-20 21:47:32</p>
100100
</div>
101101

102102
<h2></h2>

docs/dscript_math_example.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
9797
<h3 style="color: red;">Notice</h3>
9898
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
99-
<p><strong>Date of Conversion:</strong> 2025-02-20 12:54:13</p>
99+
<p><strong>Date of Conversion:</strong> 2025-02-20 21:47:33</p>
100100
</div>
101101

102102
<h2></h2>

docs/dump_case4.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
9797
<h3 style="color: red;">Notice</h3>
9898
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
99-
<p><strong>Date of Conversion:</strong> 2025-02-20 12:54:13</p>
99+
<p><strong>Date of Conversion:</strong> 2025-02-20 21:47:34</p>
100100
</div>
101101

102102
<h2></h2>

docs/dumpreduce.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
9797
<h3 style="color: red;">Notice</h3>
9898
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
99-
<p><strong>Date of Conversion:</strong> 2025-02-20 12:54:14</p>
99+
<p><strong>Date of Conversion:</strong> 2025-02-20 21:47:35</p>
100100
</div>
101101

102102
<h2></h2>

docs/dumptemplate.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
9797
<h3 style="color: red;">Notice</h3>
9898
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
99-
<p><strong>Date of Conversion:</strong> 2025-02-20 12:54:15</p>
99+
<p><strong>Date of Conversion:</strong> 2025-02-20 21:47:36</p>
100100
</div>
101101

102102
<h2></h2>

docs/dumptemplate3.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
9797
<h3 style="color: red;">Notice</h3>
9898
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
99-
<p><strong>Date of Conversion:</strong> 2025-02-20 12:54:14</p>
99+
<p><strong>Date of Conversion:</strong> 2025-02-20 21:47:35</p>
100100
</div>
101101

102102
<h2></h2>

docs/geometry.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<div style="border: 2px solid red; padding: 10px; margin-bottom: 20px;">
9797
<h3 style="color: red;">Notice</h3>
9898
<p>This is a raw view of the Python source code due to an error in generating the documentation.</p>
99-
<p><strong>Date of Conversion:</strong> 2025-02-20 12:54:36</p>
99+
<p><strong>Date of Conversion:</strong> 2025-02-20 21:47:51</p>
100100
</div>
101101

102102
<h2></h2>

docs/index.html

+217-217
Large diffs are not rendered by default.

docs/index_matlab.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ <h2>Welcome to Pizza3 Matlab Documentation</h2>
328328
<p>Back to the <a href='index.html'>Python'Pizza3 documentation</a>.</p>
329329
<hr>
330330
<p><i>When no function is selected, you see this welcome page.</i></p>
331-
Generated on: 2025-02-20 12:55:01</div>
331+
Generated on: 2025-02-20 21:48:17</div>
332332
<div id='Hertz_forces' class='doc-content' style='display: none;'>
333333
<h1>Code to explain the displacement of SPH particles (amorphous) along a rigid wall made with beads of the same size (organized)</h1>
334334
<p>INRAE\Olivier Vitrac, Han Chen - 2023-02-23</p>

docs/pizza/dforcefield.html

+22-7
Original file line numberDiff line numberDiff line change
@@ -9028,13 +9028,14 @@ <h3 id="dynamic-properties">Dynamic Properties</h3>
90289028
_maxdisplay = 40 # maximum number of characters to display (should be even)
90299029
_propertyasattribute = False
90309030
_precision = 4
9031+
_needs_sorting = False
90319032

90329033
# attributes for the iterator method
90339034
# Please keep it static, duplicate the object before changing _iter_
90349035
_iter_ = 0
90359036

90369037
# excluded attributes (keep the , in the Tupple if it is singleton)
9037-
_excludedattr = {&#39;_iter_&#39;,&#39;__class__&#39;,&#39;_protection&#39;,&#39;_evaluation&#39;,&#39;_returnerror&#39;,&#39;_debug&#39;,&#39;_precision&#39;} # used by keys() and len()
9038+
_excludedattr = {&#39;_iter_&#39;,&#39;__class__&#39;,&#39;_protection&#39;,&#39;_evaluation&#39;,&#39;_returnerror&#39;,&#39;_debug&#39;,&#39;_precision&#39;,&#39;_needs_sorting&#39;} # used by keys() and len()
90389039

90399040

90409041
# Methods
@@ -9259,6 +9260,10 @@ <h3 id="dynamic-properties">Dynamic Properties</h3>
92599260

92609261
The new instance is created by copying the fields from the left-hand operand (a)
92619262
and then updating with the fields from the right-hand operand (b).
9263+
9264+
If self or s is of class paramauto, the current state of _needs_sorting is propagated
9265+
but not forced to be true.
9266+
92629267
&#34;&#34;&#34;
92639268
if not isinstance(s, struct):
92649269
raise TypeError(f&#34;the second operand must be {self._type}&#34;)
@@ -9274,15 +9279,24 @@ <h3 id="dynamic-properties">Dynamic Properties</h3>
92749279
else:
92759280
return 0 # fallback for unknown derivations
92769281

9282+
# current classes
9283+
leftprecedence = get_precedence(self)
9284+
rightprecedence = get_precedence(s)
92779285
# Determine which class to use for the duplicate.
92789286
# If s (b) has a higher precedence than self (a), use s&#39;s class; otherwise, use self&#39;s.
9279-
hi_class = self.__class__ if get_precedence(self) &gt;= get_precedence(s) else s.__class__
9287+
hi_class = self.__class__ if leftprecedence &gt;= rightprecedence else s.__class__
92809288
# Create a new instance of the chosen class by copying self&#39;s fields.
92819289
dup = hi_class(**self)
92829290
# Update with the fields from s.
92839291
dup.update(**s)
9284-
if sortdefinitions:
9285-
dup.sortdefinitions(raiseerror=raiseerror, silentmode=silentmode)
9292+
if sortdefinitions: # defer sorting by preserving the state of _needs_sorting
9293+
if leftprecedence &lt; rightprecedence == 2: # left is promoted
9294+
dup._needs_sorting = s._needs_sorting
9295+
elif rightprecedence &lt; leftprecedence == 2: # right is promoted
9296+
dup._needs_sorting = self._needs_sorting
9297+
elif leftprecedence == rightprecedence == 2: # left and right are equivalent
9298+
dup._needs_sorting = self._needs_sorting or s._needs_sorting
9299+
# dup.sortdefinitions(raiseerror=raiseerror, silentmode=silentmode)
92869300
return dup
92879301

92889302
def __iadd__(self,s,sortdefinitions=False,raiseerror=False, silentmode=True):
@@ -9292,7 +9306,9 @@ <h3 id="dynamic-properties">Dynamic Properties</h3>
92929306
if not isinstance(s,struct):
92939307
raise TypeError(f&#34;the second operand must be {self._type}&#34;)
92949308
self.update(**s)
9295-
if sortdefinitions: self.sortdefinitions(raiseerror=raiseerror,silentmode=silentmode)
9309+
if sortdefinitions:
9310+
self._needs_sorting = True
9311+
# self.sortdefinitions(raiseerror=raiseerror,silentmode=silentmode)
92969312
return self
92979313

92989314
def __sub__(self,s):
@@ -9563,6 +9579,7 @@ <h3 id="dynamic-properties">Dynamic Properties</h3>
95639579
s.setattr(k[i],True)
95649580
return s
95659581

9582+
95669583
def sortdefinitions(self,raiseerror=True,silentmode=False):
95679584
&#34;&#34;&#34; sortdefintions sorts all definitions
95689585
so that they can be executed as param().
@@ -9828,7 +9845,6 @@ <h3 id="dynamic-properties">Dynamic Properties</h3>
98289845
s.update(a=10, b=[1, 2, 3], new_field=&#34;new_value&#34;)
98299846
&#34;&#34;&#34;
98309847
protected_attributes = getattr(self, &#39;_excludedattr&#39;, ())
9831-
98329848
for key, value in kwargs.items():
98339849
if key in protected_attributes:
98349850
print(f&#34;Warning: Cannot update protected attribute &#39;{key}&#39;&#34;)
@@ -11347,7 +11363,6 @@ <h2 id="usage">Usage:</h2>
1134711363
s.update(a=10, b=[1, 2, 3], new_field=&#34;new_value&#34;)
1134811364
&#34;&#34;&#34;
1134911365
protected_attributes = getattr(self, &#39;_excludedattr&#39;, ())
11350-
1135111366
for key, value in kwargs.items():
1135211367
if key in protected_attributes:
1135311368
print(f&#34;Warning: Cannot update protected attribute &#39;{key}&#39;&#34;)

docs/pizza/dscript.html

+63-3
Original file line numberDiff line numberDiff line change
@@ -18187,16 +18187,31 @@ <h3 id="examples_1">Examples</h3>
1818718187
&#34;&#34;&#34;
1818818188

1818918189
def __add__(self,p):
18190-
return super(param,self).__add__(p,sortdefinitions=True,raiseerror=False)
18190+
return super().__add__(p,sortdefinitions=True,raiseerror=False)
18191+
self._needs_sorting = True
1819118192

1819218193
def __iadd__(self,p):
18193-
return super(param,self).__iadd__(p,sortdefinitions=True,raiseerror=False)
18194+
return super().__iadd__(p,sortdefinitions=True,raiseerror=False)
18195+
self._needs_sorting = True
1819418196

1819518197
def __repr__(self):
1819618198
self.sortdefinitions(raiseerror=False)
1819718199
#super(param,self).__repr__()
1819818200
super().__repr__()
18199-
return str(self)</code></pre>
18201+
return str(self)
18202+
18203+
def setattr(self,key,value):
18204+
&#34;&#34;&#34; set field and value &#34;&#34;&#34;
18205+
if isinstance(value,list) and len(value)==0 and key in self:
18206+
delattr(self, key)
18207+
else:
18208+
self.__dict__[key] = value
18209+
self.__dict__[&#34;_needs_sorting&#34;] = True
18210+
18211+
def sortdefinitions(self, raiseerror=True, silentmode=True):
18212+
if self._needs_sorting:
18213+
super().sortdefinitions(raiseerror=raiseerror, silentmode=silentmode)
18214+
self._needs_sorting = False</code></pre>
1820018215
</details>
1820118216
<h3>Ancestors</h3>
1820218217
<ul class="hlist">
@@ -18210,6 +18225,47 @@ <h3>Subclasses</h3>
1821018225
<li>pizza.forcefield.parameterforcefield</li>
1821118226
<li>pizza.region.regiondata</li>
1821218227
</ul>
18228+
<h3>Methods</h3>
18229+
<dl>
18230+
<dt id="dscript.paramauto.setattr"><code class="name flex">
18231+
<span>def <span class="ident">setattr</span></span>(<span>self, key, value)</span>
18232+
</code></dt>
18233+
<dd>
18234+
<div class="desc"><p>set field and value</p></div>
18235+
<details class="source">
18236+
<summary>
18237+
<span>Expand source code</span>
18238+
</summary>
18239+
<pre><code class="python">def setattr(self,key,value):
18240+
&#34;&#34;&#34; set field and value &#34;&#34;&#34;
18241+
if isinstance(value,list) and len(value)==0 and key in self:
18242+
delattr(self, key)
18243+
else:
18244+
self.__dict__[key] = value
18245+
self.__dict__[&#34;_needs_sorting&#34;] = True</code></pre>
18246+
</details>
18247+
</dd>
18248+
<dt id="dscript.paramauto.sortdefinitions"><code class="name flex">
18249+
<span>def <span class="ident">sortdefinitions</span></span>(<span>self, raiseerror=True, silentmode=True)</span>
18250+
</code></dt>
18251+
<dd>
18252+
<div class="desc"><p>sortdefintions sorts all definitions
18253+
so that they can be executed as param().
18254+
If any inconsistency is found, an error message is generated.</p>
18255+
<p>Flags = default values
18256+
raiseerror=True show erros of True
18257+
silentmode=False no warning if True</p></div>
18258+
<details class="source">
18259+
<summary>
18260+
<span>Expand source code</span>
18261+
</summary>
18262+
<pre><code class="python">def sortdefinitions(self, raiseerror=True, silentmode=True):
18263+
if self._needs_sorting:
18264+
super().sortdefinitions(raiseerror=raiseerror, silentmode=silentmode)
18265+
self._needs_sorting = False</code></pre>
18266+
</details>
18267+
</dd>
18268+
</dl>
1821318269
</dd>
1821418270
<dt id="dscript.pipescript"><code class="flex name class">
1821518271
<span>class <span class="ident">pipescript</span></span>
@@ -24054,6 +24110,10 @@ <h4><code><a title="dscript.lamdaScript" href="#dscript.lamdaScript">lamdaScript
2405424110
</li>
2405524111
<li>
2405624112
<h4><code><a title="dscript.paramauto" href="#dscript.paramauto">paramauto</a></code></h4>
24113+
<ul class="">
24114+
<li><code><a title="dscript.paramauto.setattr" href="#dscript.paramauto.setattr">setattr</a></code></li>
24115+
<li><code><a title="dscript.paramauto.sortdefinitions" href="#dscript.paramauto.sortdefinitions">sortdefinitions</a></code></li>
24116+
</ul>
2405724117
</li>
2405824118
<li>
2405924119
<h4><code><a title="dscript.pipescript" href="#dscript.pipescript">pipescript</a></code></h4>

0 commit comments

Comments
 (0)