<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel rdf:about="https://community.wolfram.com">
    <title>Community RSS Feed</title>
    <link>https://community.wolfram.com</link>
    <description>RSS Feed for Wolfram Community showing any discussions tagged with Tuning and Debugging sorted by most likes.</description>
    <items>
      <rdf:Seq>
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1931315" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1763688" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2763509" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2330900" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2437685" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/293403" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1347913" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2726860" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1037730" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2409025" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1855244" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/849935" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2981586" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/181641" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/3531785" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/3252532" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1108896" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1065699" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/967397" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2741009" />
      </rdf:Seq>
    </items>
  </channel>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1931315">
    <title>CodeParser and CodeInspector</title>
    <link>https://community.wolfram.com/groups/-/m/t/1931315</link>
    <description>[![enter image description here][2]][1]&#xD;
&#xD;
&amp;amp;[Wolfram Notebook][3]&#xD;
&#xD;
  [1]: https://youtu.be/rOa5IntICFA&#xD;
  [2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2020-04-09at12.54.33PM.png&amp;amp;userId=11733&#xD;
  [3]: https://www.wolframcloud.com/obj/afe2a2fb-ee55-4df5-a6fb-9bc16dd08af7</description>
    <dc:creator>Brenton Bostick</dc:creator>
    <dc:date>2020-04-09T15:04:38Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1763688">
    <title>[LiVE] Request for suggestions for a livestreamed &amp;#034;Bugs Review&amp;#034; event</title>
    <link>https://community.wolfram.com/groups/-/m/t/1763688</link>
    <description>**Update: This event is scheduled for 9/6/2019 at 3:30pm US Central timezone.**&#xD;
&#xD;
We are planning to have our live-streamed &amp;#034;Bugs Review&amp;#034; event soon, where Stephen Wolfram will discuss issues (bugs: incorrect behaviors, crashes, hangs, performance issues, etc.) that you care the most about. If you plan to attend and to help prepare for this event, please reply to this post with issues in the Wolfram Language (including the Notebook Interface) you think are the most important to discuss.&#xD;
&#xD;
Thanks!</description>
    <dc:creator>Arnoud Buzing</dc:creator>
    <dc:date>2019-08-14T17:04:55Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2763509">
    <title>Optimize search for rational numbers on unit circle?</title>
    <link>https://community.wolfram.com/groups/-/m/t/2763509</link>
    <description>*Crossposted: https://mathematica.stackexchange.com/q/278250/13 *&#xD;
&#xD;
![enter image description here][1]&#xD;
&#xD;
&#xD;
&amp;amp;[Wolfram Notebook][2]&#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=RealRational_560.jpg&amp;amp;userId=11733&#xD;
  [2]: https://www.wolframcloud.com/obj/4dd2dfe1-b258-4a55-a8c4-39f6b4f0cfe9</description>
    <dc:creator>Vitaliy Kaurov</dc:creator>
    <dc:date>2023-01-06T18:30:28Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2330900">
    <title>[WSG21] Daily Study Group: programming tutorials</title>
    <link>https://community.wolfram.com/groups/-/m/t/2330900</link>
    <description>Daily Study Groups are back, now providing expertise on practical programming! After a short break, we&amp;#039;re starting up with a series that picks up where Wolfram Language Basics sessions ended. This 3-week series will take you from basic programming concepts to package development. &#xD;
&#xD;
Need tips on improving your code’s speed or functionality? Programming Tutorials offer a great opportunity to level-up your skills while interacting with software development professionals. See hands-on examples and get questions answered by Wolfram Language experts. Plus: participants who pass weekly quizzes are awarded a program completion certificate. Level 1 certification is available for those who pass manually graded exercises. &#xD;
&#xD;
Join us any time between August 2 and August 20! Check out our [registration page][1] for more details.&#xD;
&#xD;
&#xD;
&#xD;
 [1]: https://wolfr.am/Study_Group15</description>
    <dc:creator>Wolfram U</dc:creator>
    <dc:date>2021-07-30T15:24:02Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2437685">
    <title>Load DICOM with actual data values: Import/Export changes data</title>
    <link>https://community.wolfram.com/groups/-/m/t/2437685</link>
    <description>I&amp;#039;m very happy with the continued improvement of the Dicom import and export functionality and speed. &#xD;
However, there is one issue with the current implementation that makes it very unuseful if you do quantitative image analysis. It might be that I miss an option if not I think this should be fixed.&#xD;
&#xD;
In the Mathematica documentation and examples, Dicom data is typically shown and imported as images which I understand for display purposes. But I consider the information in Dicom files as data, very well curated and standardized. &#xD;
For many (MRI) applications, the actual quantitative values of voxels stored in Dicom actually have meaning, values, and even units. For example in the image below each voxel value is actually a quantitative measure of T2 relaxation time in the heart, where the values are stored in milliseconds as voxel values as is also mentioned in the metadata. &#xD;
&#xD;
![enter image description here][1]&#xD;
&#xD;
![enter image description here][2]&#xD;
&#xD;
To get from the stored values to quantitative values (WV, DV or FP) the fields from the header and the equations are well defined.&#xD;
&#xD;
Header values:&#xD;
&#xD;
- SV = stored value of DICOM PIXEL DATA without scaling&#xD;
- WS = RealWorldValue slope (0040,9225) &amp;#034;RWVSlope&amp;#034;&#xD;
- WI = RealWorldValue intercept (0040,9224) &amp;#034;RWVIntercept&amp;#034;&#xD;
- RS = rescale slope (0028,1053) &amp;#034;RescaleSlope&amp;#034;&#xD;
- RI = rescale intercept (0028,1052) &amp;#034;RescaleIntercept&amp;#034;&#xD;
- SS = scale slope (2005,100E) &amp;#034;ScaleSlope&amp;#034;&#xD;
&#xD;
Outputs:&#xD;
&#xD;
- WV = real world value&#xD;
- FP = precise value&#xD;
- DV = displayed value&#xD;
&#xD;
Formulas:&#xD;
&#xD;
- WV = SV * WS + WI&#xD;
- DV = SV * RS + RI&#xD;
- FP = DV / (RS * SS)&#xD;
&#xD;
So my first try was that I want to obtain the &amp;#034;RawData&amp;#034; to access the SV pixel data, which does not output anything. &#xD;
&#xD;
![enter image description here][3]&#xD;
&#xD;
Eventually, if I import this Dicom file into Mathematica I have to use a lot of tricks to get to the correct stored values. The Dicom images I use are stored as 12-bit Integers but are converted by Mathematica to a Numerical array with type Int16. Also, I have to specifically specify that I don&amp;#039;t want any &amp;#034;DataTransformation&amp;#034; which by default rescales the data and actually changes some voxel values!!!!&#xD;
&#xD;
    In[1]:= &amp;lt;&amp;lt; QMRITools`&#xD;
    &#xD;
    {meta, data, bd} = &#xD;
      Import[file, {&amp;#034;dicom&amp;#034;, {&amp;#034;MetaInformation&amp;#034;, &amp;#034;Data&amp;#034;, &amp;#034;BitDepth&amp;#034;}}, &#xD;
       &amp;#034;DataTransformation&amp;#034; -&amp;gt; None];&#xD;
    dataT = Import[file, {&amp;#034;dicom&amp;#034;, {&amp;#034;Data&amp;#034;}}];&#xD;
    &#xD;
    {dd = ToExpression[&#xD;
       StringJoin @@ &#xD;
        StringCases[NumericArrayType[data], DigitCharacter]], bd}&#xD;
    {ss, rs, ri} = &#xD;
     meta /@ {&amp;#034;2005_100e&amp;#034;, &amp;#034;RescaleSlope&amp;#034;, &amp;#034;RescaleIntercept&amp;#034;}&#xD;
    &#xD;
    {data, dataT} = Normal@{data, dataT};&#xD;
    &#xD;
    svT = 2.^bd (dataT/(2.^dd));&#xD;
    pfT = (rs svT + ri)/(rs ss);&#xD;
    &#xD;
    sv = 2.^bd (data/(2.^dd));&#xD;
    pf = (rs sv + ri)/(rs ss);&#xD;
    &#xD;
    PlotData[pfT, pf]&#xD;
    &#xD;
    Out[3]= {16, 12}&#xD;
    &#xD;
    Out[4]= {1.99854, 0.500366, -2.}&#xD;
&#xD;
For my current research, I need the PF values and to get them correctly I have to:&#xD;
&#xD;
 1. Use &amp;#034;DataTransformation&amp;#034;-&amp;gt;None, which is not really well documented what it actually does. But based on what I see actual values of the data are changed by clipping the histogram, which for default handling of medical data is never OK!! &#xD;
![enter image description here][4]&#xD;
 2. As far as I am aware the only way to obtain the actual stored values of my Dicom data (the actual binary values stored in the file itself) I have to find the actual BiteDepth and the imported data type and rescale my data accordingly.&#xD;
&#xD;
&#xD;
Below are the obtained PF valued data I need with and without DataTransformation. Although the image on the right might look less appealing with default range and scaling it is actually correct when scaled apropriately. &#xD;
![enter image description here][5]&#xD;
![enter image description here][6]&#xD;
&#xD;
Am I missing a correct option for getting the actual data stored? If not this should definitely be changed. Dicom is the international standard to transmit, store, retrieve, print, process, and display medical imaging information. With the current implementation, it is impossible to Import and Export such files without actually changing the stored data.&#xD;
&#xD;
Thanks, Martijn&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
 &#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=dcmtag.png&amp;amp;userId=1332602&#xD;
  [2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=T2map.png&amp;amp;userId=1332602&#xD;
  [3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=raw.png&amp;amp;userId=1332602&#xD;
  [4]: https://community.wolfram.com//c/portal/getImageAttachment?filename=hist.png&amp;amp;userId=1332602&#xD;
  [5]: https://community.wolfram.com//c/portal/getImageAttachment?filename=dataTrans1.png&amp;amp;userId=1332602&#xD;
  [6]: https://community.wolfram.com//c/portal/getImageAttachment?filename=dataTrans2.png&amp;amp;userId=1332602</description>
    <dc:creator>Martijn Froeling</dc:creator>
    <dc:date>2022-01-05T09:42:43Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/293403">
    <title>Issues with AstronomicalData and SunPosition</title>
    <link>https://community.wolfram.com/groups/-/m/t/293403</link>
    <description>TL;DR
---
I have three issues with getting sun positions in Mathematica V10:

 - It is extremely slow compared to V9
 - It doesn&amp;#039;t *seem* to yield correct results
 - a) It needs an Internet connection, which b) is not assured to always return results and c) if not used optimally can easily consume your monthly allowance of W|A calls

Long story
===
With the advent of V10 `AstronomicalData` has been deprecated, as shown on its documentation page:
![enter image description here][1].

I&amp;#039;m not an astronomer, so my main use of this function has been restricted to its capability to get the sun position using functions calls like this:

    {
      AstronomicalData[&amp;#034;Sun&amp;#034;, {&amp;#034;Azimuth&amp;#034;, {2013, 3, 1, #, 0, 0}, {52.37`, 4.89`}}, TimeZone -&amp;gt; 1], 
      AstronomicalData[&amp;#034;Sun&amp;#034;, {&amp;#034;Altitude&amp;#034;, {2013, 3, 1, #, 0, 0}, {52.37`, 4.89`}},  TimeZone -&amp;gt; 1]
    } &amp;amp; /@ Range[0, 23]

&amp;gt; {{341.47732, -43.93930}, {2.33417, -45.21747}, {22.94232, -43.19133},
&amp;gt; {41.52167, -38.28400}, {57.55208, -31.30276}, {71.47253, -23.03159},
&amp;gt; {84.02194, -14.08294}, {95.91940, -4.92723}, {107.80166, 4.03418}, {120.23770, 12.40167}, {133.72303, 19.72563}, {148.59433, 
&amp;gt;   25.48377}, {164.84179, 29.12209}, {181.93103, 30.19428}, {198.91284,
&amp;gt;    28.55117}, {214.89602, 24.41962}, {229.46400, 
&amp;gt;   18.28613}, {242.70064, 10.70703}, {254.98998, 
&amp;gt;   2.19073}, {266.84760, -6.82566}, {278.85594, -15.94505},  {291.66723, -24.75464}, {306.00911, -32.75641}, {322.57956, 
&amp;gt; -39.29877}}

So, this gets me the sun positions in steps of an hour during a particular day in Amsterdam (TZ 1).

The same call still works in V10, though it now returns numbers with units; degrees in this case. On its first call, it reads some paclet information from a Wolfram server, but on any successive call no Internet connection is needed. I will be going into detail about timing further on, but I&amp;#039;ll say here that the V10 function takes about three times longer than its V9 namesake. I blame the addition of units for that.

With `AstronomicalData` apparently deprecated we are supposed to use its successors. In this case I need `SunPosition`. A direct translation of the above would be:

    SunPosition[GeoPosition[{52.37`, 4.89`}], DateObject[{2013, 3, 1, #, 0, 0}, TimeZone -&amp;gt; 1]] &amp;amp; /@ Range[0, 23]

&amp;gt; {{95.7, -5.1}, {107.6, 3.9}, {120.0, 12.3}, {133.5, 19.6}, {148.3, 25.4}, {164.5, 29.1}, {181.6, 30.2}, {198.6, 28.6}, {214.6, 24.5}, {229.2, 18.4}, {242.5, 10.9}, {254.8, 2.4}, {266.6, -6.7}, {278.6, -15.8}, {291.4, -24.6}, {305.7, 
-32.6}, {322.2, -39.2}, {341.3, -43.5}, {2.0, -44.8}, {22.5, -42.9}, 
{41.1, -38.0}, {57.1, -31.1}, {71.0, -22.9}, {83.6, -13.9}}

As with the new `AstronomicalData` the output is actually in degrees which I have removed in the above output for the sake of clarity. There are a few things to note:

 - `SunPosition` uses position and date objects, the latter being new in V10
 - `SunPosition` does not have a `TimeZone` option, but you can set it in `DateObject`
 - `SunPosition` can use the old lat/long list position indication. It also can use a date list to enter the date instead of a `DateObject`. In the latter case you are out of options with respect to time zones and you have to add the appropriate amount of time offset
 - It is extremely slow, and it may even time-out: 

![enter image description here][2]

 - Last but not least: the results seem to be plain wrong. It suggests that sunrise is somewhat before 1 am, which is -of course- incorrect. I assume that this has something to do with a `$GeoLocation` setting for the observer of the sun positions, but I haven&amp;#039;t managed to sort out what I am supposed to enter to get the correct sun positions for the location provided in the same call.

As to timing: I noticed very inconsistent timings for `SunPosition` compared to `AstronomicalData`, so I used the following code to collect a somewhat more statistical  sound sample:

    SetAttributes[timingTest, HoldFirst];
    timingTest[code_, repeats_Integer] :=
       Table[
          ClearSystemCache[];
          code // AbsoluteTiming // First,
          {repeats}
        ]

Using this, I collected timing of 20 calls to the following code snippets:

 - `AstronomicalData` V9 and V10: As above
 - `SunPosition`: As above
 - `SunPosition` without `GeoPosition`, just the lat/long list.
 - `SunPosition`  without `GeoPosition`, and also without the `DateObject` date, just a classical date list (with the hour set to +1 to accommodate TZ 1)
 - `SunPosition` V10 without `GeoPosition` and with the `Map` (`/@`) gone and replaced by a `DateRange` inside the call.

In the last case, the returned value is a `TimeSeries` object from which I extract the positions using the `&amp;#034;Paths&amp;#034;` method:

     SunPosition[{52.37`, 4.89`}, DateRange[{2013, 3, 1, 1, 0, 0}, {2013, 3, 1, 24, 0, 0}, &amp;#034;Hour&amp;#034;]][&amp;#034;Paths&amp;#034;][[1, All, 2]]

The results were as follows:

![enter image description here][3]

Clearly, the `SunPosition` results are very disappointing. Getting the sun positions with `SunPosition` is almost 40 times slower than using the old V9 method (which, I should add, wasn&amp;#039;t particularly quick either. I have an implementation in Mathematica code which is faster). The V10 implementation of `AstronomicalData` is also more than three times slower than the V9 version. The `DateRange` version of the call saves a lot of communication overhead. Still, it is almost *five times slower* than in V9.

The cause of all this slowness is that `SunPosition` simply does a call to Wolfram|Alpha. Sniffing the communication one sees the following string passed to the server:

    &amp;#034;1:eJxTTMoPSuNgYGAoZgESPpnFJcHcQEZwaV5AfnFmSWZ+XhoTsmxR/6GvGjH9wg4Qhr6XQxobsnzmXXYGhkxmIC+TEUSIgwggZihigIJgoAIGj/yizKr8PJigA5yBZtubwB1yrdxeDkXVIuvcH1aJOBRzAqUcS0vycxNLMpMBSAArww==&amp;#034;

which can be turned into readable form using `Uncompress`:

    {&amp;#034;SunPosition&amp;#034;, {4.89, 52.37}, {2013, 3, 1, 23, 0, 0.}, &amp;#034;Horizon&amp;#034;, 2., 2., {52.09, 5.12}, Automatic}

Here, we can recognize the lat/long of the position I used (but with lat/long reversed - Is this somehow significant?). At the end is my own `$GeoLocation`, but I don&amp;#039;t believe it is used at all (and it shouldn&amp;#039;t: I&amp;#039;m asking for the sun position over Amsterdam, not where I live). Changing it with `Block` I get the same results:

    Block[{$GeoLocation = GeoPosition[{52.37`, 40.89`}]}, SunPosition[{52.37`, 4.89`}, {2013, 3, 1, 1, 0, 0}]]

Apart from the slowness, there&amp;#039;s the issue of the necessary Internet connectivity (Want to give a demonstration and you don&amp;#039;t have Internet? Sorry, you&amp;#039;re out of luck). 

And what of the use of W|A calls? Each of the `SunPosition` tests (except the last one) took me 20 * 24 = 480 calls. So this part of my testing only already took 1440 calls, and one should be reminded that a typical Home Use license allows for only 3,000 calls per month. Things like this can go pretty fast. In fact, I once wrote an application that calculates the impact of building changes on shadows around your house throughout the year. It does in the order of 17,000 `AstronomicalData` calls. I couldn&amp;#039;t implement that naively using `SunPosition` and have it actually work. Clearly, one should now use the `DateRange` version of the call as much as possible.

----------

To wrap up: I have one real question, i.e., how to get `SunPosition` to return the same values as `AstronomicalData`, and a request to the WRI team: please put `SunPosition` in the kernel and don&amp;#039;t use W|A calls, because the situation as it is now is rather annoying and IMHO a real step backwards.

  [1]: /c/portal/getImageAttachment?filename=AstronomicalData.png&amp;amp;userId=43903
  [2]: /c/portal/getImageAttachment?filename=timeout.png&amp;amp;userId=43903
  [3]: /c/portal/getImageAttachment?filename=results.png&amp;amp;userId=43903</description>
    <dc:creator>Sjoerd de Vries</dc:creator>
    <dc:date>2014-07-13T16:39:48Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1347913">
    <title>Are there plans to make Mathematica actually usable for network analysis?</title>
    <link>https://community.wolfram.com/groups/-/m/t/1347913</link>
    <description>This is a follow-up on [the discussion about the future of the `Graph` functionality in Mathematica](http://community.wolfram.com/groups/-/m/t/1321057).&#xD;
&#xD;
[@Charles Pooh][at0] was kind enough to respond in that thread and indicate that new developments are in the pipeline.  However, the elephant in the room was not addressed: namely, will practical user needs be finally taken into account?&#xD;
&#xD;
Charles showed statistics that most bugs are reported internally, and every version has multiple bugfixes.  The problem is that very serious bugs that surfaced when users tried to get actual work done have not been addressed through several versions.  Problems with usability and workflow have also not been addressed.  Bugs that hinder everyday work don&amp;#039;t seem to be prioritized.&#xD;
&#xD;
A fundamental necessity for doing any non-trivial network analysis is to be able to associate attributes with edges and vertices of graphs, and then modify the graph (e.g. take a subgraph) while preserving attributes.  This is near-unusable with Mathematica, and I am not exaggerating at all. If anyone believes otherwise, I challenge you to prove me wrong.&#xD;
&#xD;
Let&amp;#039;s create a random graph of moderate size and associate attributes with its vertices and edges.  To make the task not too challenging, I will use the built-in `EdgeWeight` property, which is easier to use than custom properties.&#xD;
&#xD;
    rg = RandomGraph[{10000, 50000}, EdgeWeight -&amp;gt; RandomReal[1, 50000]];&#xD;
&#xD;
Let&amp;#039;s add a custom vertex property:&#xD;
&#xD;
    rg = SetProperty[rg, Properties -&amp;gt; Thread[VertexList[rg] -&amp;gt; List /@ Thread[&amp;#034;foo&amp;#034; -&amp;gt; RandomInteger[100, VertexCount[rg]]]]];&#xD;
&#xD;
This looks pretty complicated. Why does it have to be so?  With igraph&amp;#039;s R interface, one would simply do `V(rg)$foo &amp;lt;- runif(vcount(g))`.  Forget that some functions names are shorter, as that&amp;#039;s mostly irrelevant. Look at how much simpler and easier the syntax is!&#xD;
&#xD;
Now let&amp;#039;s add some vertex coordinates.  Since `VertexCoordinates` is a built-in property, this is a bit simpler, but still not as simple as it should be.&#xD;
&#xD;
    In[80]:= rg = SetProperty[rg, VertexCoordinates -&amp;gt; Thread[VertexList[rg] -&amp;gt; RandomReal[1, {VertexCount[rg], 2}]]]; // AbsoluteTiming&#xD;
    Out[80]= {2.49243, Null}&#xD;
&#xD;
Also, it takes 2.5 seconds, which is unacceptably long considering that we are only processing 10000 pairs of machine reals!&#xD;
&#xD;
Now try something trivial: take a subgraph. This is probably the single most common operation one does on such datasets.  Well, `Subgraph` doesn&amp;#039;t support properties *at all*, so what do we do?  Luckily we have `VertexDelete`, which *should* support them, but has been slow and buggy for as long as it has existed.&#xD;
&#xD;
    sg = VertexDelete[rg, RandomSample[VertexList[rg], 5000]]; // AbsoluteTiming&#xD;
&#xD;
This took 6 seconds (!!!) on my computer.  In igraph/R it takes no perceptible time, as it should.  Imagine e.g. a very typical task where on would try to do some statistics on a large set of subgraphs.  This is basically impossible in Mathematica (at least if we do use `Graph`).&#xD;
&#xD;
Furthermore, it turns out that `sg` is now corrupted and can&amp;#039;t be used anymore. To make things more confusing, it is not immediately apparent that this is so, and that is was `VertexDelete` that broke it.  `GraphQ[sg]` is still true. But now try &#xD;
&#xD;
    In[82]:= {Length@PropertyValue[sg, EdgeWeight], EdgeCount[sg]}&#xD;
    Out[82]= {50000, 12429}&#xD;
&#xD;
The edge weight vector is longer than the number of edges, so functions like. `EdgeBetweennessCentrality` will simply refuse to operate on the graph (without reporting any meaningful error BTW).&#xD;
&#xD;
At least I was able to check the length of the edge weight vector. With custom properties this isn&amp;#039;t even possible (but they&amp;#039;re also mishandled by `VertexDelete`).  `VertexDelete` also frequently messes up vertex properties (not just edge properties), and again in a way that the symptoms will appear only much later in the workflow.&#xD;
&#xD;
In other words, we can&amp;#039;t perform even the most trivial operations on graph with attributes.&#xD;
&#xD;
Finally, multigraphs simply don&amp;#039;t work with properties, but there is absolutely no mention in the documentation that this is not supported.  Things simply don&amp;#039;t work, or break, or the `Graph` objects get corrupted.&#xD;
&#xD;
So, to sum up:&#xD;
&#xD;
It&amp;#039;s great that `Graph` will get more attention. But will actual use cases be considered?  Will the most fundamental problems, the problems that currently make it unusable for such work, be fixed?  Is Mathematica trying to be suitable for this type of work at all, or, to ask once again, should we just give up and go to igraph and networkx, to R and Python, like nearly everyone else does?  (I certainly wouldn&amp;#039;t like to do that as I already invested a lot in Mathematica.)&#xD;
&#xD;
Bug(-fix) counts alone are not a good measure of progress.  Effort should be concentrated where it actually matters.&#xD;
&#xD;
 [at0]: http://community.wolfram.com/web/charlesp</description>
    <dc:creator>Szabolcs Horvát</dc:creator>
    <dc:date>2018-05-29T10:38:30Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2726860">
    <title>Benchmarking numerical differential equations in Wolfram Language</title>
    <link>https://community.wolfram.com/groups/-/m/t/2726860</link>
    <description>&amp;amp;[Wolfram Notebook][1]&#xD;
&#xD;
&#xD;
  [1]: https://www.wolframcloud.com/obj/d0094aa1-c4bc-47eb-b693-6f30a4f26f3c</description>
    <dc:creator>Hanfeng Zhai</dc:creator>
    <dc:date>2022-12-12T15:08:24Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1037730">
    <title>Performance tuning in Wolfram Language</title>
    <link>https://community.wolfram.com/groups/-/m/t/1037730</link>
    <description>*NOTE:  Please see the original version of this post [**HERE**][1]. Cross-posted here per suggestion of  [@Vitaliy Kaurov][at0].*&#xD;
&#xD;
----------&#xD;
&#xD;
&#xD;
Since Mathematica is a symbolic system, with symbolic evaluator much more&#xD;
general than in numerically-based languages, it is not surprising that performance-tuning can be &#xD;
more tricky here. There are many techniques, but they can all be understood &#xD;
from a single main principle. It is:&#xD;
&#xD;
   *Avoid full Mathematica symbolic evaluation process as much as possible.*&#xD;
   &#xD;
All techniques seem to  reflect some facet of it. The main idea here is that most of the &#xD;
time, a slow Mathematica program is such because many Mathematica functions are very general. This &#xD;
generality is a great strength, since it enables the language to support better and more powerful abstractions, but in many places in the program such generality, used without care, can be a (huge) overkill. &#xD;
&#xD;
I won&amp;#039;t be able to give many illustrative examples in the limited space, but they can be found in &#xD;
several places, including some WRI technical reports (Daniel Lichtblau&amp;#039;s &#xD;
one on efficient data structures in Mathematica comes to mind), a very good&#xD;
book of David Wagner on Mathematica programming, and most notably, many Mathgroup&#xD;
posts. I also discuss a limited subset of them in  [my book][3]. I will supply more references soon.&#xD;
&#xD;
Here are a few most common ones (I only list those available within Mathematica &#xD;
language itself, not mentioning CUDA \ OpenCL, or links to other languages, which are &#xD;
of course also the possibilities):&#xD;
&#xD;
1.	*Push as much work into the kernel at once as possible, work with as large &#xD;
chunks of data at a time as possible, without breaking them into pieces*&#xD;
&#xD;
	1.1. Use built-in functions whenever possible. Since they are implemented &#xD;
	in the kernel, in a lower-level language (C), they are typically (but not always!)&#xD;
	much faster	than user-defined ones solving the same problem. The more specialized&#xD;
	version of a built-in function you are able to use, the more chances you have for a speed-up.&#xD;
&#xD;
	1.2. Use functional programming (`Map, Apply`, and friends). Also, use pure functions&#xD;
	in `#-&amp;amp;` notation when you can, they tend to be faster than Function-s with named&#xD;
	arguments or those based on patterns (especially for not computationally-intensive&#xD;
	functions mapped on large lists).&#xD;
   &#xD;
	1.3. Use structural and vectorized operations (`Transpose, Flatten, &#xD;
	Partition, Part` and friends), they are even faster than functional.&#xD;
   &#xD;
	1.4. Avoid using procedural programming (loops etc), because this programming&#xD;
	style tends to break large structures into pieces (array indexing etc).&#xD;
	This pushes larger part of the computation outside of the kernel and makes it slower. &#xD;
&#xD;
   	&#xD;
    &#xD;
   &#xD;
2. *Use machine-precision whenever possible*&#xD;
&#xD;
	2.1. Be aware and use Listability of built-in numerical functions, applying them to &#xD;
        large lists of data rather than using `Map` or loops.&#xD;
		&#xD;
	2.2. Use `Compile`, when you can. Use the new capabilities of `Compile`, such as `CompilationTarget-&amp;gt;&amp;#034;C&amp;#034;`,&#xD;
	and making our compile functions parallel and Listable.&#xD;
	&#xD;
	2.3. Whenever possible, use vectorized operations (`UnitStep, Clip, Sign, Abs`, etc)&#xD;
	inside `Compile`, to realize &amp;#034;vectorized control flow&amp;#034; constructs such as `If`, so that &#xD;
	you can avoid 	explicit loops (at least as innermost loops) also inside `Compile`. This &#xD;
	can move you 	in speed from Mathematica byte-code to almost native C speed, in some cases.&#xD;
&#xD;
       2.4. When using `Compile`, make sure that the compiled function doesn&amp;#039;t bail out to non-compiled evaluation.  See examples [in this MathGroup thread][4].&#xD;
&#xD;
3. *Be aware that Lists are implemented as arrays in Mathematica*&#xD;
&#xD;
    3.1. Pre-allocate large lists&#xD;
	&#xD;
	3.2. Avoid `Append, Prepend, AppendTo` and `PrependTo` in loops, for building &#xD;
	lists etc (because they copy entire list to add a single element, which leads&#xD;
	to quadratic rather than linear complexity for list-building)&#xD;
	&#xD;
	3.3. Use linked lists (structures like `{1,{2,{3,{}}}}` ) instead of plain lists&#xD;
	for list accumulation in a program. The typical idiom is `a = {new element, a}`.&#xD;
	Because a is a reference, a single assignment is constant-time.&#xD;
	&#xD;
	3.4. Be aware that pattern-matching for sequence patterns (BlankSequence, &#xD;
	BlankNullSequence) is also based on Sequences being arrays. Therefore, a rule&#xD;
	`{fst_,rest___}:&amp;gt;{f[fst],g[rest]}` will copy the entire list when applied. In particular, don&amp;#039;t&#xD;
   use recursion in a way which may look natural in other languages. If you want to use recursion on lists, first convert your lists to linked lists.&#xD;
	&#xD;
4.  *Avoid inefficient patterns, construct efficient patterns*&#xD;
&#xD;
	4.1. Rule-based programming can be both very fast and very slow, depending on how &#xD;
	you build your structures and rules, but in practice it is easier to inadvertently &#xD;
	make it slow. It will be slow for rules which force the pattern-matcher to make many &#xD;
	a priory doomed matching attempts, for example by under-utilizing each run of the &#xD;
	pattern-matcher through a long list (expression). Sorting elements is a good example:&#xD;
	`list//.{left___,x_,y_,right___}/;x&amp;gt;y:&amp;gt;{left,y,x,right}` - has a cubic complexity in the&#xD;
	size of the list (explanation is e.g. [here][5]).&#xD;
	&#xD;
	4.2. Build efficient patterns, and corresponding  structures to store your data, making &#xD;
	pattern-matcher to waste as little time on false matching attempts as possible.&#xD;
	&#xD;
	4.3. Avoid using patterns with  computationally intensive conditions or tests. The &#xD;
    pattern-matcher will give you the most speed when  patterns	are mostly syntactic in &#xD;
	nature (test structure, heads, etc). Every time when condition `(/;)` or pattern test `(?)`&#xD;
	is used, for every potential match, the evaluator is invoked by the pattern-matcher,&#xD;
	and this slows it down.&#xD;
	&#xD;
5.  *Be aware of immutable nature of most Mathematica built-in functions*&#xD;
    &#xD;
    Most Mathematica built-in functions which process lists create a copy of an original list and &#xD;
    operate on that copy. Therefore, they may have a linear time (and space) complexity in the &#xD;
    size of the original list, even if they modify a list in only a few places. One universal &#xD;
    built-in function that does not create a copy, modifies the original expression and does not &#xD;
    have this issue, is `Part`.&#xD;
  &#xD;
    5.1. Avoid using most list-modifying built-in functions for a large number of&#xD;
    small independent list modifications, which can not be formulated as a single step&#xD;
    (for example, `NestWhile[Drop[#,1]&amp;amp;,Range[1000],#&amp;lt;500&amp;amp;]` )&#xD;
&#xD;
    5.2. Use extended functionality of `Part` to extract and modify a large number of &#xD;
	list (or more general expression) elements at the same time. This is very fast,&#xD;
	and not just for packed numerical arrays (`Part` modifies the original list).&#xD;
	&#xD;
	5.3. Use `Extract` to extract many elements at different levels at once, passing &#xD;
	to it a possibly large list of element positions.&#xD;
	&#xD;
	&#xD;
6. *Use efficient built-in data structures*&#xD;
&#xD;
    The following internal data structures are very efficient and can be used in &#xD;
	many more situations than it may appear from their stated main purpose. Lots of such examples can be found by searching the Mathgroup archive, particularly contributions of Carl Woll. &#xD;
&#xD;
	6.1. Packed arrays&#xD;
&#xD;
    6.2. Sparse arrays	&#xD;
	&#xD;
7. *Use hash - tables.* &#xD;
&#xD;
   Starting with version 10,  immutable associative arrays are available in Mathematica (Associations)&#xD;
&#xD;
7.1 Associations&#xD;
&#xD;
the fact that they are immutable does not prevent them to have efficient insertion and deletion of key-value pairs (cheap copies different from the original association by the presence, or absence, of a given key-value pair). They represent the idiomatic associative arrays in Mathematica, and have very good performance characteristics.&#xD;
&#xD;
For earlier versions,the following alternatives work pretty well, being based on internal Mathematica&amp;#039;s hash-tables:&#xD;
&#xD;
7.2. Hash-tables based on `DownValues` or `SubValues`&#xD;
	&#xD;
7.3. `Dispatch`	&#xD;
	&#xD;
8. *Use element - position duality*&#xD;
&#xD;
	Often you can write faster functions to work with positions of elements rather than &#xD;
	elements themselves, since positions are integers (for flat lists). This can give you &#xD;
	up to an order of magnitude speed-up, even compared to generic built-in functions &#xD;
	(`Position` comes to mind as an example).&#xD;
	&#xD;
9.  *Use Reap - Sow*&#xD;
&#xD;
    `Reap` and `Sow` provide an efficient way of collecting intermediate results, and generally &#xD;
	&amp;#034;tagging&amp;#034; parts you want to collect, during the computation. These commands also go well&#xD;
	with functional programming.&#xD;
	&#xD;
10.  *Use caching, dynamic programming, lazy evaluation*&#xD;
&#xD;
    10.1. Memoization is very easily implemented in Mathematica, and can save a lot of execution &#xD;
	time for certain problems.&#xD;
	&#xD;
	10.2. In Mathematica, you can implement more complex versions of memoization, where you can &#xD;
	define functions (closures) at run-time, which will use some pre-computed parts in their&#xD;
	definitions and therefore will be faster.&#xD;
	&#xD;
	10.3. Some problems can benefit from lazy evaluation. This seems more relevant to memory - &#xD;
	efficiency, but can also affect run-time efficiency. Mathematica&amp;#039;s symbolic constructs make &#xD;
	it easy to 	implement.&#xD;
	&#xD;
	&#xD;
A successful performance - tuning process usually employs a combination of these techniques, &#xD;
and you will need some practice to identify cases where each of them will be beneficial.&#xD;
&#xD;
&#xD;
  [1]: http://mathematica.stackexchange.com/a/29351&#xD;
  [2]: https://groups.google.com/d/topic/comp.soft-sys.math.mathematica/XOXapJm_Q1Q/discussion&#xD;
  [3]: http://www.mathprogramming-intro.org/&#xD;
  [4]: https://groups.google.com/d/topic/comp.soft-sys.math.mathematica/XOXapJm_Q1Q/discussion&#xD;
  [5]: http://www.mathprogramming-intro.org/book/node355.html&#xD;
&#xD;
 [at0]: http://community.wolfram.com/web/vitaliyk</description>
    <dc:creator>Leonid Shifrin</dc:creator>
    <dc:date>2017-03-22T20:05:20Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2409025">
    <title>Performance degradation from 11.3,12.1.1,12.2.0 =&amp;gt; 12.3.1 on Raspberry Pi</title>
    <link>https://community.wolfram.com/groups/-/m/t/2409025</link>
    <description>I know that calculating the digits of Pi is something very specific and probably irrelevant to the real practical problems, but somehow it feels appropriate to quickly test the performance of Wolfram Mathematica, especially if the machine is actually called Raspberry **Pi** :)&#xD;
&#xD;
So, here is the log of running `AbsoluteTiming[N[Pi,10^6];]` on a Raspberry Pi with different versions of Wolfram Mathematica, from which it is clear that 11.3, 12.1.1 and 12.2.0 give approximately the same timings, but 12.3.1 is substantially worse.&#xD;
&#xD;
    $ math11&#xD;
    Wolfram Language 11.3.0 Engine for Linux ARM (32-bit)&#xD;
    Copyright 1988-2018 Wolfram Research, Inc.&#xD;
    &#xD;
    In[1]:= AbsoluteTiming[N[Pi,10^6];]&#xD;
    Out[1]= {2.03026, Null}&#xD;
    &#xD;
    --------------------------------------------------------&#xD;
    &#xD;
    $ math12.1&#xD;
    Mathematica 12.1.1 Kernel for Linux ARM (32-bit)&#xD;
    Copyright 1988-2020 Wolfram Research, Inc.&#xD;
    &#xD;
    In[1]:= AbsoluteTiming[N[Pi,10^6];]           &#xD;
    Out[1]= {2.08772, Null}&#xD;
    &#xD;
    --------------------------------------------------------&#xD;
    $ math12.2&#xD;
    Mathematica 12.2.0 Kernel for Linux ARM (32-bit)&#xD;
    Copyright 1988-2021 Wolfram Research, Inc.&#xD;
    &#xD;
    In[1]:= AbsoluteTiming[N[Pi,10^6];]&#xD;
    Out[1]= {3.25156, Null}&#xD;
    &#xD;
    --------------------------------------------------------&#xD;
    $ math&#xD;
    Mathematica 12.3.1 Kernel for Linux ARM (32-bit)&#xD;
    Copyright 1988-2021 Wolfram Research, Inc.&#xD;
    &#xD;
    In[1]:= AbsoluteTiming[N[Pi,10^6];]&#xD;
    Out[1]= {7.66692, Null}</description>
    <dc:creator>Tigran Aivazian</dc:creator>
    <dc:date>2021-11-18T07:43:31Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1855244">
    <title>The Most Convenient Keyboard Shortcuts Ever</title>
    <link>https://community.wolfram.com/groups/-/m/t/1855244</link>
    <description>Here are two simple but extremely convenient keyboard shortcuts that I&amp;#039;ve used for years. &#xD;
&#xD;
 - This post is a favor to all my friends who type slowly (like me)&#xD;
 - These shortcuts simply create a pair of brackets containing a template placeholder as the current new selection&#xD;
 - Essentially, it&amp;#039;s just a stripped-down version of the bulky (Command + Shift + K + Up/Down Arrow + Enter) completion&#xD;
&#xD;
**Favorite Shortcut #1:** &#xD;
Autocomplete single brackets by pressing `CommandKey + [`&#xD;
&#xD;
![enter image description here][1]&#xD;
&#xD;
**Favorite Shortcut #2:** Autocomplete part brackets by pressing `CommandKey + ]`&#xD;
&#xD;
![enter image description here][2]&#xD;
&#xD;
## How to set them up ##&#xD;
&#xD;
On MacOS, first make a backup of the following file, in case you break it:&#xD;
&#xD;
    FileNameJoin[{$InstallationDirectory, &amp;#034;SystemFiles/FrontEnd/TextResources/Macintosh/KeyEventTranslations.tr&amp;#034;}];&#xD;
&#xD;
On my machine this path resolves to: *&amp;#034;/Applications/Mathematica.app/Contents/SystemFiles/FrontEnd/TextResources/Macintosh/KeyEventTranslations.tr&amp;#034;*&#xD;
&#xD;
Then, preferably in a non-Mathematica editor (e.g. Sublime), open the above file and copy-and-paste these following code into the list inside `EventTranslations`. For the first shortcut:&#xD;
&#xD;
    Item[KeyEvent[&amp;#034;[&amp;#034;,Modifiers-&amp;gt;{Command}],FrontEndExecute[{FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],&amp;#034;[\[SelectionPlaceholder]]&amp;#034;],FrontEndToken[&amp;#034;MovePreviousPlaceHolder&amp;#034;]}]]&#xD;
    &#xD;
And for the second (of course making sure they are separated by a comma):&#xD;
&#xD;
    Item[KeyEvent[&amp;#034;]&amp;#034;,Modifiers-&amp;gt;{Command}],FrontEndExecute[{FrontEnd`NotebookWrite[FrontEnd`InputNotebook[],&amp;#034;\[LeftDoubleBracket]\[SelectionPlaceholder]\[RightDoubleBracket]&amp;#034;],FrontEndToken[&amp;#034;MovePreviousPlaceHolder&amp;#034;],FrontEndToken[&amp;#034;MovePreviousPlaceHolder&amp;#034;]}]]&#xD;
    &#xD;
Finally, restart Mathematica, and presto, they should both be working. And to remove the shortcuts, simply remove those items or replace the .tr file with the backup.&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=own.gif&amp;amp;userId=900170&#xD;
  [2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=part.gif&amp;amp;userId=900170</description>
    <dc:creator>Michael Sollami</dc:creator>
    <dc:date>2020-01-08T20:42:08Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/849935">
    <title>VoronoiMesh: user error, tetgen error, else?</title>
    <link>https://community.wolfram.com/groups/-/m/t/849935</link>
    <description>I found some unusual error in VoronoiMesh. I have the points *pts*, and first I compute the VoronoiMesh for that, Note the red circle: these are two close datapoints, and it correctly draws a line between them.&#xD;
&#xD;
&#xD;
    dom=1.25\[Pi] (* domain size *)&#xD;
    domspec=Transpose[{{0,0},{dom,dom}}] &#xD;
    pts={{1.880951464600067`,1.473752017061138`},{1.8913812543459405`,2.319493673670671`},{1.7674367495794008`,3.5325088938533917`},{1.9320143413972677`,3.611151717969884`},{1.8107126970778207`,3.6790935311559876`},{1.804725058474518`,3.8520729911980185`},{1.805368854133445`,3.852728507949241`},{1.563939776616803`,3.9192958794919646`}};&#xD;
    VoronoiMesh[pts,domspec,Epilog-&amp;gt;{Point[pts],Red,Circle[pts[[6]],0.1]},PlotRange-&amp;gt;domspec,ImageSize-&amp;gt;500,PlotRangePadding-&amp;gt;Scaled[.05]]&#xD;
   &#xD;
![enter image description here][1]&#xD;
&#xD;
&#xD;
Now, I add points around it (to make the Voronoi periodic), leaving the old ones, and only adding more points *around* it. Then the voronoi is not correctly computed:&#xD;
&#xD;
    allpts=Join@@Join@@Table[p+dom {i,j},{i,-1,1},{j,-1,1},{p,pts}];  (* add groups of points around it, making it periodic *)&#xD;
    VoronoiMesh[allpts,Epilog-&amp;gt;{Point[pts],Red,Circle[pts[[6]],0.1]},PlotRange-&amp;gt;domspec,ImageSize-&amp;gt;500,PlotRangePadding-&amp;gt;Scaled[.05]]&#xD;
&#xD;
&#xD;
![enter image description here][2]&#xD;
&#xD;
I have millions and millions of points and it took me several hours to &amp;#039;minimize&amp;#039; the error and go to the core of it. &#xD;
&#xD;
Any help is welcome! Is there some option that controls when two points are considered the same? It looks like some points are deleted because they are too close?&#xD;
&#xD;
The distance between point 6 and 7 is:&#xD;
&#xD;
    Log10[Norm[pts[[6]] - pts[[7]]]]&#xD;
&#xD;
-3.03678&#xD;
&#xD;
So it should not be some machine-precision issue I presume!  If someone can confirm it on different versions that would be appreciated.&#xD;
&#xD;
This is done in 10.4.1 and 10.3.1 on Mac, both show the error.&#xD;
&#xD;
&#xD;
  [1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2016-05-03at16.23.33.png&amp;amp;userId=73716&#xD;
  [2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2016-05-03at16.24.30.png&amp;amp;userId=73716</description>
    <dc:creator>Sander Huisman</dc:creator>
    <dc:date>2016-05-03T14:33:03Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2981586">
    <title>Tips for preventing memory issues with Graphics3D</title>
    <link>https://community.wolfram.com/groups/-/m/t/2981586</link>
    <description>Quadro M1200  &#xD;
Intel i7  &#xD;
32 Gb RAM&#xD;
&#xD;
I&amp;#039;m currently rendering some large 3D scenes for some projects. I&amp;#039;m aware I&amp;#039;m pushing my hardware and Mathematica to its limits. I previously [asked some questions][1] about frontend crashes when using Graphics3D and export and I now better understand why and can work around it.&#xD;
&#xD;
I am managing to get the results I want by closely monitoring my system when pushing the settings just below failure. But I&amp;#039;m wondering if some of the issues I&amp;#039;m working around can be prevented. Therefore I&amp;#039;m posting my experience here and hoping to get some tips to improve.&#xD;
&#xD;
But first the nice results before the boring evaluation.&#xD;
&#xD;
![enter image description here][2]&#xD;
![enter image description here][3]&#xD;
&#xD;
My laptop is a Intel i7 with 32 Gb RAM and and Nvidia Quadro M1200. for the graphs below red is memory usage and green is CPU usage both in %. For my scene I have 60 transparent iso-volumes and 4 solid ones. The streamlines I render are subsampled from around 500K lines i generate. For lines I select 12.5k lines with around 100 vertices each, for tubes I select 7.5 k lines. My `$HistoryLength` setting is always 0 since I&amp;#039;m working with sizable data.&#xD;
&#xD;
When exporting my scene using lines this is my system memory. I don&amp;#039;t display the scene in the frontend only export it to *.png files. The export is clearly handled by the frontend and CPU and at the moment of export the memory spikes and the GPU does some work. However after everything is done and i quit the kernel the Mathematica frontend is still using between 3-4 Gb of RAM. Exporting one PNG takes around 2-3 Gb.&#xD;
&#xD;
![enter image description here][4]&#xD;
&#xD;
When exporting tubes things get a bit more heavy and needs between 6-8 Gb of memory per image. after everything is done i have lost around 5 Gb of RAM that I can only get back by closing the frontend. &#xD;
&#xD;
For a clean system and Mathematica start i use around 25% memory. After loading and processing i have 35% in use. After one round of exporting lines and tubes, closing Mathematica reopening loading and processing the data I&amp;#039;m at 50% memory usage so somewhere I lost 15%. &#xD;
&#xD;
![enter image description here][5]&#xD;
&#xD;
If I push everything to far the export will overflow the memory resulting in a frontend crash and sometimes a GPU driver crash. I now somewhat know the limits of what I can do but after working for a while exporting and optimizing visualization at some point my memory keeps growing. I now monitor this and when i come to the point of getting close to a crash the only thing i can do is restart everything to reset my memory. &#xD;
&#xD;
  [1]: https://community.wolfram.com/groups/-/m/t/2920496?p_p_auth=86KqZmOz&#xD;
  [2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=line.gif&amp;amp;userId=1332602&#xD;
  [3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=tube.gif&amp;amp;userId=1332602&#xD;
  [4]: https://community.wolfram.com//c/portal/getImageAttachment?filename=lines.png&amp;amp;userId=1332602&#xD;
  [5]: https://community.wolfram.com//c/portal/getImageAttachment?filename=6379tubes.png&amp;amp;userId=1332602</description>
    <dc:creator>Martijn Froeling</dc:creator>
    <dc:date>2023-08-02T10:10:50Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/181641">
    <title>An experiment in Moment of Inertia with Raspberry Pi / Arduino</title>
    <link>https://community.wolfram.com/groups/-/m/t/181641</link>
    <description>Wanted to share with my kids the classical experiment on a rolling object down an incline plane using legos, arduino and Mathematica for the Raspberry Pi.

Using a window valance and some lego technic pieces we proceeded to build the inclined plane platform.

[img=width: 300px; height: 400px;]/c/portal/getImageAttachment?filename=inclinedplane1.JPG&amp;amp;userId=78214[/img]

Using legos was great to allow to attach both leds and photorresistors to the inclined plane. It also allowed us to set up build a platform from where to attach a servo motor and a protractor to measure the angle of inclination.
[img=width: 400px; height: 533px;]/c/portal/getImageAttachment?filename=inclinedplane2.JPG&amp;amp;userId=78214[/img]

We&amp;#039;ll detect when the ball reaches a certain point of the platform by the the disminution of the LED light received at the photoresistors.
[img=width: 300px; height: 400px;]/c/portal/getImageAttachment?filename=8270photo(1).JPG&amp;amp;userId=78214[/img]

The adafruit web site is a very good site to explain the details on how to connect the photoresistors and leds to the Arduino.
[url=http://learn.adafruit.com/adafruit-arduino-lesson-2-leds/leds]http://learn.adafruit.com/adafruit-arduino-lesson-2-leds/leds[/url]
[url=http://learn.adafruit.com/photocells/using-a-photocell]http://learn.adafruit.com/photocells/using-a-photocell[/url]

As the readings of the photocells require of analog inputs, we decided to use a spare arduino we had at our disposal, and to have more fun, use XBEE modules to connect the arduino to the raspberry pi.
[img=width: 300px; height: 225px;]/c/portal/getImageAttachment?filename=6471photo(2).JPG&amp;amp;userId=78214[/img]

The following is the code at the Arduino.[code]
#include &amp;lt;Servo.h&amp;gt; 
int servoPin = 9;
int LightSensor[4]={A1,A2,A3,A4};
int current[4]={0,0,0,0};
double timers[4]={0,0,0,0};
int previous[4]={0,0,0,0};

Servo servo;  
int i=0; 
double factor=0.7;
double timer = 0; 
int inByte =0;

void setup() 
{ 
  Serial.begin(19200);
  servo.attach(servoPin); 
  servo.write(0);
  delay(2000);
  for (i=0;i&amp;lt;4;i++){
    previous[i]=analogRead(LightSensor[i]);
  }
} 
void loop() 
{ 
if(Serial.available()&amp;gt;0){

  inByte=Serial.read();

 if (inByte==65) {
    servo.write(90);
    timer=millis();
    trackBall();
    for (i=0;i&amp;lt;4;i++){
      Serial.println(timers[i]);
    }
    servo.write(0);
  }
}
}

void trackBall(){
 int m =0;
  while (m&amp;lt;4){
    current[m]=analogRead(LightSensor[m]);
    if (current[m]&amp;lt;factor*previous[m]){
      timers[m]=millis()-timer;
      m++;
  }
  }
}[/code]
Mathematica code and results to follow
[mcode]serial = DeviceOpen[&amp;#034;Serial&amp;#034;, {&amp;#034;/dev/ttyUSB0&amp;#034;, &amp;#034;BaudRate&amp;#034; -&amp;gt; 19200}]
lengths = {0., 0.175, 0.43, 

   0.69} ;(*Distance between light sensors in meters*)
data = {};(*List to capture the time between sensors*)
ping := Module[{}, DeviceWriteBuffer[serial, {&amp;#034;A&amp;#034;}]; Pause[3]; 

  ToExpression[StringSplit[FromCharacterCode[DeviceReadBuffer[serial]]]]/1000]
(*Function pings sends an &amp;#034;A&amp;#034; to the arduino to release the ball and \

collect timing*)
Button[&amp;#034;Collect Data&amp;#034;, data = Append[data, ping]]
Dynamic[tdata = Transpose@data;

 dataPoints = 

  Flatten[Table[{tdata[[i, j]], lengths[[i]]}, {i, 

     Length[lengths]}, {j, Length[data]}], 1];

 lm = Fit[dataPoints, {1, x, x^2}, x];

 Plot[lm, {x, -0.3, 1.2}, 

  Epilog -&amp;gt; {Red, PointSize[Large], Point[dataPoints]}, 

  AspectRatio -&amp;gt; 1, PlotLabel -&amp;gt; lm]][/mcode]Using a hollow ball, we can work out the gravity value
[img=width: 440px; height: 500px;]/c/portal/getImageAttachment?filename=Untitled.png&amp;amp;userId=78214[/img]

Using a golf ball
[img=width: 500px; height: 482px;]/c/portal/getImageAttachment?filename=InclinedPlane.png&amp;amp;userId=78214[/img]

A couple of videos of the experiment in action
[url=https://www.youtube.com/watch?v=4eRZ48N3vM8]https://www.youtube.com/watch?v=4eRZ48N3vM8[/url]
[url=https://www.youtube.com/watch?v=eLVPpEcyw_0]https://www.youtube.com/watch?v=eLVPpEcyw_0[/url]
[url=https://www.youtube.com/watch?v=53WaEcRWY_0]https://www.youtube.com/watch?v=53WaEcRWY_0[/url]</description>
    <dc:creator>Diego Zviovich</dc:creator>
    <dc:date>2014-01-08T01:09:54Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/3531785">
    <title>Wolfram video processing is too slow for real-life situations</title>
    <link>https://community.wolfram.com/groups/-/m/t/3531785</link>
    <description>Wolfram Video Processing is too slow in real-life situations. I love using Wolfram Language for real-life applications, and I appreciate that Wolfram has recently focused on first-class video functionality. However, it’s a pity that while it works fine for demonstrations, it is far too slow for practical use.&#xD;
&#xD;
For example, when I use CapCut to edit and render a 5-minute video, it takes only a few seconds. But in Wolfram Mathematica, the same process is extremely slow. For a simple 7-minute video (with only text overlay), Wolfram takes 6 minutes just to render. That is unusable! Imagine processing a **30-minute video&amp;#x2014;it could take 45 minutes**, while CapCut would finish in under a minute.&#xD;
![enter image description here][1]&#xD;
&#xD;
I have also tried adjusting encoders, frame rates, and other settings, but it didn’t help.&#xD;
Can someone suggest a solution? Thank you very much.&#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=1755454340--0Codec.nb_-Wolfram.jpg&amp;amp;userId=138946</description>
    <dc:creator>Jaques Secretin</dc:creator>
    <dc:date>2025-08-17T18:15:27Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/3252532">
    <title>Wolfram Language Runtime (SDK) demo in Zig</title>
    <link>https://community.wolfram.com/groups/-/m/t/3252532</link>
    <description>![Wolfram Language Runtime (SDK) demo in Zig][1]&#xD;
&#xD;
&amp;amp;[Wolfram Notebook][2]&#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=1169Hero.png&amp;amp;userId=20103&#xD;
  [2]: https://www.wolframcloud.com/obj/5c80768d-a495-4c9a-baa0-655d8dc47903</description>
    <dc:creator>Daniel Sanchez</dc:creator>
    <dc:date>2024-08-21T02:25:51Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1108896">
    <title>Improvement on the magic number 0x5f3759df</title>
    <link>https://community.wolfram.com/groups/-/m/t/1108896</link>
    <description>One of the well-known algorithm of doing the inverse square root:&#xD;
&#xD;
$$\frac{1}{\sqrt{x}}$$&#xD;
&#xD;
is the so-called &amp;#034;fast inverse square root&amp;#034; algorithm, see [wikipedia][1]. This code gives a very good approximation of this function, possibly good enough for lighting in video-games. Even now, with modern CPUs, with many new instructions, this is still quite a bit faster than the actual inverse square root. The most surprising thing about this code is the appearance of a magic constant (note that this is C code, including the original comments)&#xD;
&#xD;
    float Q_rsqrt( float number )&#xD;
    {&#xD;
    	long i;&#xD;
    	float x2, y;&#xD;
    	const float threehalfs = 1.5F;&#xD;
    &#xD;
    	x2 = number * 0.5F;&#xD;
    	y  = number;&#xD;
    	i  = * ( long * ) &amp;amp;y;                       // evil floating point bit level hacking&#xD;
    	i  = 0x5f3759df - ( i &amp;gt;&amp;gt; 1 );               // what the f*ck? &#xD;
    	y  = * ( float * ) &amp;amp;i;&#xD;
    	y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration&#xD;
&#xD;
        return y;&#xD;
    }&#xD;
&#xD;
As you can see, the input is a float (a 32 bit floating point number), which is cast in to a long integer, the bits are shifted, and the result subtracted from a magic constant, this number is then re-interpreted again as a float.&#xD;
&#xD;
To understand why this works is actually quite a long story, but realise that floats are stored as 32 bits as follows:&#xD;
&#xD;
    SEEEEEEEEMMMMMMMMMMMMMMMMMMMMMMM&#xD;
&#xD;
where S= sign, E = exponent, and M = Mantissa. So once you interpret this as a long, and start shifted bits, you can get very unpredictable behavior. The question that I&amp;#039;m after is: can this constant be improved? &#xD;
&#xD;
Let&amp;#039;s create a library function in c and link it back in to Mathematica, such that we can try different magic constants and different values x:&#xD;
&#xD;
    Needs[&amp;#034;CCompilerDriver`&amp;#034;]&#xD;
    src=&amp;#034;&#xD;
    #include \&amp;#034;WolframLibrary.h\&amp;#034;&#xD;
    DLLEXPORT mint WolframLibrary_getVersion(){&#xD;
      return WolframLibraryVersion;&#xD;
    }&#xD;
    DLLEXPORT int WolframLibrary_initialize( WolframLibraryData libData) {return 0;}&#xD;
    DLLEXPORT void WolframLibrary_uninitialize( WolframLibraryData libData) {return;}&#xD;
    DLLEXPORT int constantzero(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res){&#xD;
       MArgument_setInteger(Res, 0);&#xD;
       return LIBRARY_NO_ERROR;&#xD;
    }&#xD;
    DLLEXPORT int fastinvsqrt(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {&#xD;
    	double in = MArgument_getReal(Args[0]);&#xD;
    	int magic = MArgument_getInteger(Args[1]);&#xD;
    	float x = in;&#xD;
    	float halfx = 0.5f * x;&#xD;
    	int i = *(int*)&amp;amp;x;&#xD;
    	i = magic - (i &amp;gt;&amp;gt; 1); &#xD;
    	x = *(float*)&amp;amp;i;&#xD;
    	x = x*(1.5f-(halfx*x*x));&#xD;
    	double I1; &#xD;
    	I1 = x;&#xD;
    	MArgument_setReal(Res, I1);&#xD;
    	return LIBRARY_NO_ERROR;&#xD;
    }&amp;#034;;&#xD;
    Quiet@LibraryFunctionUnload[fastinvsqrt]&#xD;
    fastinvsqrtlib=CreateLibrary[src,&amp;#034;fastinvsqrt&amp;#034;]&#xD;
    fastinvsqrt=LibraryFunctionLoad[fastinvsqrtlib, &amp;#034;fastinvsqrt&amp;#034;,{Real,Integer},Real]&#xD;
    magicconst=16^^5f3759df&#xD;
    Plot[{1/Sqrt[x],fastinvsqrt[x,magicconst]},{x,0.1,5},PlotRange-&amp;gt;{0,2}]&#xD;
    LogLogPlot[{1/Sqrt[x]-fastinvsqrt[x,magicconst],1/Sqrt[x]},{x,0.01,100000},PlotRange-&amp;gt;{All,{10^-6,10}},Frame-&amp;gt;True,PlotRangePadding-&amp;gt;None,PlotPoints-&amp;gt;1200,MaxRecursion-&amp;gt;3]&#xD;
&#xD;
![enter image description here][2]&#xD;
&#xD;
The match is indeed great! and we can see that the error (second plot, in blue) is of the order 0.1% of the result for the original magic constant!&#xD;
&#xD;
Let&amp;#039;s introduce the relative error:&#xD;
&#xD;
    ClearAll[relativeerror]&#xD;
    relativeerror[x_Real, magic_Integer] := (1/Sqrt[x] - fastinvsqrt[x, magic])/(1/Sqrt[x])&#xD;
&#xD;
and plot it:&#xD;
&#xD;
    LogLogPlot[relativeerror[x, magicconst], {x, 0.01, 100000}, &#xD;
     Frame -&amp;gt; True, PlotRangePadding -&amp;gt; None, PlotRange -&amp;gt; {10^-5, 1}, &#xD;
     PlotPoints -&amp;gt; 1200, MaxRecursion -&amp;gt; 3]&#xD;
&#xD;
![enter image description here][3]&#xD;
&#xD;
This plot is periodic because of the way floating point numbers are defined/implemented, we can zoom in on one of the parts:&#xD;
&#xD;
    LogLinearPlot[relativeerror[x, magicconst], {x, 1, 4}, Frame -&amp;gt; True, &#xD;
     PlotRangePadding -&amp;gt; None, PlotRange -&amp;gt; All, PlotPoints -&amp;gt; 1200, &#xD;
     MaxRecursion -&amp;gt; 3]&#xD;
&#xD;
![enter image description here][4]&#xD;
&#xD;
We can plot slight deviations from the magic constant to see the new relative errors:&#xD;
&#xD;
    LogLinearPlot[{relativeerror[x, magicconst], &#xD;
      relativeerror[x, magicconst - 20000], &#xD;
      relativeerror[x, magicconst + 20000]}, {x, 1, 4}, Frame -&amp;gt; True, &#xD;
     PlotRangePadding -&amp;gt; None, PlotRange -&amp;gt; All, PlotPoints -&amp;gt; 1200, &#xD;
     MaxRecursion -&amp;gt; 3, PlotLegends -&amp;gt; {&amp;#034;0&amp;#034;, &amp;#034;-20000&amp;#034;, &amp;#034;+20000&amp;#034;}]&#xD;
&#xD;
![enter image description here][5]&#xD;
&#xD;
If the constant increases, the center peaks go up, but the far-right and far-left peak go down. &#xD;
&#xD;
Let&amp;#039;s try a bunch of magic-constants, and check the maximum (relative) error we find. I do this by sampling many point and looking for the maximum error I find in those points:&#xD;
&#xD;
    Dynamic[d]&#xD;
    data = Table[{d,  Max[Table[With[{x = 2^s}, ((1/Sqrt[x] - fastinvsqrt[x, d + magicconst])/(1/Sqrt[x]))], {s, 0, 2, 0.00001}]]}, {d, -100000, 100000, &#xD;
        1000}];&#xD;
    data // ListLogPlot&#xD;
    TakeSmallestBy[data, Last, 1]&#xD;
&#xD;
![enter image description here][6]&#xD;
&#xD;
    {{0, 0.00175225}}&#xD;
&#xD;
If there is a better constant, it sure is close to the original constant. Let&amp;#039;s zoom in a bit:&#xD;
&#xD;
    Dynamic[d]&#xD;
    data = Table[{d,  Max[Table[With[{x = 2^s}, ((1/Sqrt[x] - fastinvsqrt[x, d + magicconst])/(1/Sqrt[x]))], {s, 0, 2, 0.00001}]]}, {d, -1000, 1000, 10}];&#xD;
    data // ListLogPlot&#xD;
    TakeSmallestBy[data, Last, 1]&#xD;
&#xD;
![enter image description here][7]&#xD;
&#xD;
    {{160, 0.00175121}}&#xD;
&#xD;
We can zoom in even further:&#xD;
&#xD;
    Dynamic[d]&#xD;
    data=Table[{d,Max[Table[With[{x=2^s},((1/Sqrt[x]-fastinvsqrt[x,d+magicconst])/(1/Sqrt[x]))],{s,0,2,0.0000001}]]},{d,160,170,1}];&#xD;
    data//ListLogPlot&#xD;
    TakeSmallestBy[data,Last,1]&#xD;
&#xD;
![enter image description here][8]&#xD;
&#xD;
    {{166, 0.00175129}}&#xD;
&#xD;
magicconstant + 166 seems to have a slightly better worst-case performance. This corresponds to the follow new magic constant:&#xD;
&#xD;
    BaseForm[magicconst + 166, 16]&#xD;
&#xD;
or in C (in hex):&#xD;
&#xD;
    0x5f375a85&#xD;
&#xD;
We could also use the built-in FindMaximum:&#xD;
&#xD;
    ClearAll[FindMaxima]&#xD;
    FindMaxima[d_Integer]:=Module[{x},&#xD;
        Max[Table[First@FindMaximum[((1/Sqrt[x]-fastinvsqrt[x,d+magicconst])/(1/Sqrt[x])),{x,x0,1,4},MaxIterations-&amp;gt;5000,WorkingPrecision-&amp;gt;50],{x0,1.0,4.0,0.03}]]&#xD;
    ]&#xD;
&#xD;
Now using this function and look around our probable minimum:&#xD;
&#xD;
    Dynamic[d]&#xD;
    data=Quiet@Table[{d,FindMaxima[d]},{d,150,175,1}];&#xD;
    data//ListLogPlot&#xD;
    TakeSmallestBy[data,Last,1]&#xD;
&#xD;
![enter image description here][9]&#xD;
&#xD;
Which also find 166. So that seems to be in agreement. Another [paper][10] found 0x5f375a86 which 16^^5f375a86 - magicconst = 167. So perhaps he/me is wrong with rounding somehow&#xD;
&#xD;
## Average error ##&#xD;
&#xD;
So far, we&amp;#039;ve been looking at maximum error possible, but what about minimising the average error? Since we&amp;#039;re using floating point numbers that can range over many many decades I would like to minimize the following integral of the error:&#xD;
&#xD;
    Integrate[relativeerror[2^s]^2,{s,0,2}]&#xD;
&#xD;
Note that I do not sample the domain x 1 to 4 linearly. Again we can run for large deviations from the magic constant:&#xD;
&#xD;
    Dynamic[d]&#xD;
    data=Table[{d,Total[Table[With[{x=2^s},((1/Sqrt[x]-fastinvsqrt[x,d+magicconst])/(1/Sqrt[x]))^2],{s,0,2,0.00001}]]},{d,-250000,250000,10000}];&#xD;
    data//ListLogPlot&#xD;
    TakeSmallestBy[data,Last,1]&#xD;
&#xD;
![enter image description here][11]&#xD;
&#xD;
Let&amp;#039;s zoom in a bit more:&#xD;
&#xD;
    Dynamic[d]&#xD;
    data=Table[{d,Total[Table[With[{x=2^s},((1/Sqrt[x]-fastinvsqrt[x,d+magicconst])/(1/Sqrt[x]))^2],{s,0,2,0.00001}]]},{d,-96000,-94000,20}];&#xD;
    data//ListLogPlot&#xD;
    TakeSmallestBy[data,Last,1]&#xD;
&#xD;
![enter image description here][12]&#xD;
&#xD;
And zooming a bit more and using a smaller &amp;#039;integration&amp;#039; steps:&#xD;
&#xD;
    Dynamic[d]&#xD;
    data=Table[{d,Total[Table[With[{x=2^s},((1/Sqrt[x]-fastinvsqrt[x,d+magicconst])/(1/Sqrt[x]))^2],{s,0,2,0.00000005}]]},{d,-94900,-94800,1}];&#xD;
    data[[All,2]]=Rescale[data[[All,2]]];&#xD;
    ListPlot[data,PlotRange-&amp;gt;All]&#xD;
    TakeSmallestBy[data,Last,1]&#xD;
&#xD;
![enter image description here][13]&#xD;
&#xD;
The lowest value happens at magicconstant - 94863:&#xD;
&#xD;
    LogLogPlot[{relativeerror[x,magicconst],relativeerror[x,magicconst-94863]},{x,0.01,100000},Frame-&amp;gt;True,PlotRangePadding-&amp;gt;None,PlotRange-&amp;gt;{10^-5,1},PlotPoints-&amp;gt;1200,MaxRecursion-&amp;gt;3]&#xD;
    LogLinearPlot[{relativeerror[x,magicconst]^2,relativeerror[x,magicconst-94863]^2},{x,1,4},Frame-&amp;gt;True,PlotRangePadding-&amp;gt;None,PlotRange-&amp;gt;All,PlotPoints-&amp;gt;1200,MaxRecursion-&amp;gt;3]&#xD;
&#xD;
![enter image description here][14]&#xD;
&#xD;
Here (in orange) the average (square) relative error is better as compared to the original constant. &#xD;
&#xD;
Hope you enjoyed this little exploration of using C code inside Mathematica and to optimize low-level algorithms interactively using Mathematica&amp;#039;s library functionality and plotting functionality. The original code includes a single Newton iteration to further hone in to the correct answer, the plots I&amp;#039;ve showed are for a single iteration. Other people have optimized the constant for not a single iteration or two iterations So there are different constants out there. And, since the values are always under-estimated, the Newton iteration can also be modified to account for this. &#xD;
&#xD;
&#xD;
  [1]: https://en.wikipedia.org/wiki/Fast_inverse_square_root&#xD;
  [2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2017-05-27at01.36.58.png&amp;amp;userId=73716&#xD;
  [3]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2017-05-27at01.40.10.png&amp;amp;userId=73716&#xD;
  [4]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2017-05-27at01.41.11.png&amp;amp;userId=73716&#xD;
  [5]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2017-05-27at01.43.40.png&amp;amp;userId=73716&#xD;
  [6]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2017-05-27at01.49.01.png&amp;amp;userId=73716&#xD;
  [7]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2017-05-27at01.47.42.png&amp;amp;userId=73716&#xD;
  [8]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2017-05-27at01.50.33.png&amp;amp;userId=73716&#xD;
  [9]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2017-05-27at01.54.12.png&amp;amp;userId=73716&#xD;
  [10]: https://cs.uwaterloo.ca/~m32rober/rsqrt.pdf&#xD;
  [11]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2017-05-27at02.04.47.png&amp;amp;userId=73716&#xD;
  [12]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2017-05-27at02.05.39.png&amp;amp;userId=73716&#xD;
  [13]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2017-05-27at02.07.26.png&amp;amp;userId=73716&#xD;
  [14]: http://community.wolfram.com//c/portal/getImageAttachment?filename=ScreenShot2017-05-27at02.13.55.png&amp;amp;userId=73716</description>
    <dc:creator>Sander Huisman</dc:creator>
    <dc:date>2017-05-27T00:25:47Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1065699">
    <title>Possible bug: Map puts SparseArray in inconsistent state</title>
    <link>https://community.wolfram.com/groups/-/m/t/1065699</link>
    <description>It seems that `Map`ing a function over a `SparseArray` can produce a result where one of the explicit values in the array is the same as the background value.  It seems to me that this is a bug because other functions appear to assume that an explicit value will never be the same as the background value.&#xD;
&#xD;
## Example&#xD;
&#xD;
Let us create a sparse array,&#xD;
&#xD;
    In[1]:= sa = SparseArray[{1, 0, 2, 0, 3}];&#xD;
&#xD;
and check its explicit values.&#xD;
    &#xD;
    In[2]:= sa[&amp;#034;NonzeroValues&amp;#034;]&#xD;
    Out[2]= {1, 2, 3}&#xD;
&#xD;
Let us now change the first element (which is nonzero) to have the background value.&#xD;
    &#xD;
    In[3]:= sa[[1]] = 0;&#xD;
&#xD;
And check explicit values again:&#xD;
    &#xD;
    In[4]:= sa[&amp;#034;NonzeroValues&amp;#034;]&#xD;
    Out[4]= {2, 3}&#xD;
&#xD;
As you can see, the sparse array has been recomputed so that none of the explicit values is 0. It is in a consistent state.  This is what I expected.&#xD;
&#xD;
Now let us modify elements in a different manner. Let us map a function over the sparse array in such a way that it will transform some of the explicit values to zero:&#xD;
    &#xD;
    In[5]:= sa = SparseArray[{1, 0, 2, 0, 3}];&#xD;
    &#xD;
    In[6]:= sa2 = Map[If[# &amp;gt; 2, 0, #] &amp;amp;, sa];&#xD;
&#xD;
Check explicit values in the result:&#xD;
    &#xD;
    In[7]:= sa2[&amp;#034;NonzeroValues&amp;#034;]&#xD;
    Out[7]= {1, 2, 0}&#xD;
&#xD;
Oops!  What is that `0` doing in the list?  Is should have been removed from the explicit values list.&#xD;
&#xD;
**Is this a bug?**  Do decide, let us take a look at how other functions handle this sparse array.&#xD;
&#xD;
`ArrayRules` works on both sparse and dense arrays. `ArrayRules[arr, b]` gives the positions of elements that are different from `b`. It works fine even if `b` is different from the background element of a sparse `arr`.&#xD;
&#xD;
But here `ArrayRules` fails to give the result I expect, even though the second element was given explicitly:&#xD;
    &#xD;
    In[8]:= ArrayRules[sa2, 0]&#xD;
    Out[8]= {{1} -&amp;gt; 1, {3} -&amp;gt; 2, {5} -&amp;gt; 0, {_} -&amp;gt; 0}&#xD;
&#xD;
That `{5} -&amp;gt; 0` should not be in the list.&#xD;
&#xD;
See how ArrayRules works if the default element is set to `1`.  There is no problem this time:&#xD;
    &#xD;
    In[9]:= ArrayRules[sa2, 1]&#xD;
    Out[9]= {{2} -&amp;gt; 0, {3} -&amp;gt; 2, {4} -&amp;gt; 0, {5} -&amp;gt; 0, {_} -&amp;gt; 1}&#xD;
&#xD;
This suggests that either `ArrayRules` or `SparseArray` is misbehaving here.  Which one should be considered the buggy one?  &#xD;
&#xD;
Does this `SparseArray` have a broken internal state? Or does `ArrayRules` fail to take a special case into account?&#xD;
&#xD;
----&#xD;
&#xD;
This array can be fixed using `SparseArray[sa2]`.</description>
    <dc:creator>Szabolcs Horvát</dc:creator>
    <dc:date>2017-04-19T08:36:10Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/967397">
    <title>Delayed evaluation and automatic memory management in Mathematica</title>
    <link>https://community.wolfram.com/groups/-/m/t/967397</link>
    <description>Hello everyone,&#xD;
&#xD;
In this post I would like to share a programming technique I find interesting, as well as ask for feedback on it.&#xD;
&#xD;
## The problem&#xD;
&#xD;
The [MaTeX package][1] typesets LaTeX directly within Mathematica. Unfortunately, every call to the `MaTeX` function involves one run of LaTeX, which is very slow: it takes about 0.5 seconds. Typesetting 20 formulae would take 10 secondsmuch too slow.&#xD;
&#xD;
![Mathematica graphics](http://i.stack.imgur.com/jEDCR.png)&#xD;
&#xD;
To mitigrate this, MaTeX can typeset a list of expressions with a single LaTeX run.  This is much faster:&#xD;
&#xD;
    In[37]:= ClearMaTeXCache[]&#xD;
    MaTeX@Range[20]; // AbsoluteTiming&#xD;
    &#xD;
    Out[38]= {0.480417, Null}&#xD;
&#xD;
But it is not always convenient to put everything we want to compile into a single list.  MaTeX is meant for creating figure labels and each label would usually appear in a different position in the Mathematica code we write.  **Could we still gather all these inputs, appearing in different places in the code, and compile them with a single run?**&#xD;
&#xD;
## The solution&#xD;
&#xD;
Here&amp;#039;s how we can do this: delay the evaluation.  Let&amp;#039;s have a function called `delayedMaTeX` that doesn&amp;#039;t evaluate immediately, but simply acts as a placeholder object. It also collects the inputs into a queue for later evaluation.  Then we can trigger batch-evaluation with one command, which assigns the results to the placeholders.&#xD;
&#xD;
We also want to prevent the unlimited accumulation of compiled results, which take up memory. Let&amp;#039;s get rid of them as soon as they are no longer referenced anywhere. This can be achieved using the rarely used [`Temporary`](http://reference.wolfram.com/language/ref/Temporary.html) attribute.&#xD;
&#xD;
For the following proof-of-concept example, let&amp;#039;s forget that `MaTeX` can take optionstaking that into account would just make the code longer and harder to understand without being educational.  Let&amp;#039;s load MaTeX and set some options right away, just so the examples below will look a bit nicer.&#xD;
&#xD;
    &amp;lt;&amp;lt; MaTeX`&#xD;
    SetOptions[MaTeX, &amp;#034;DisplayStyle&amp;#034; -&amp;gt; False, FontSize -&amp;gt; 16];&#xD;
&#xD;
Turning off history prevents unwanted references to symbols. Then we can observe how unreferenced results get cleared.&#xD;
&#xD;
    $HistoryLength = 0;&#xD;
&#xD;
The inputs will be queued up for evaluation in this variable:&#xD;
&#xD;
    queue = &amp;lt;||&amp;gt;;&#xD;
&#xD;
Let the placeholder be called `delayed`. It holds a unique `Temporary` symbol that allows for reference tracking, as well as the TeX input itself.  If the input is not yet in the queue, it adds it:&#xD;
&#xD;
    expr : delayed[s_Symbol, texcode_] /; Not@KeyExistsQ[queue, ToString[s]] :=&#xD;
       (AppendTo[queue, ToString[s] -&amp;gt; texcode]; expr)&#xD;
&#xD;
When the input is processed, the result will be assigned to the temporary symbol.  The result from MaTeX always has head `Graphics`.  If `delayed` sees this, it simply evaluates directly to the result:&#xD;
&#xD;
    delayed[g_Graphics, ___] := g&#xD;
&#xD;
Finally let&amp;#039;s add a nice printed form for these `delayed` expressions.  This is irrelevant for the functioning of the system; it&amp;#039;s purely for beautification.&#xD;
&#xD;
    delayed /: MakeBoxes[expr : delayed[_, texcode_], StandardForm | TraditionalForm] := &#xD;
      With[{boxes = ToBoxes@Tooltip[&#xD;
          Panel[&#xD;
           Style[&amp;#034;$\[Ellipsis]$&amp;#034;, &amp;#034;Code&amp;#034;, ShowStringCharacters -&amp;gt; False, &#xD;
            Background -&amp;gt; None], FrameMargins -&amp;gt; 2&#xD;
           ],&#xD;
          texcode]},&#xD;
        InterpretationBox[boxes, expr]&#xD;
      ]&#xD;
&#xD;
The `delayedMaTeX` function simply creates the temporary symbol (named as `id$...`) and places it within a `delayed` expression along with the TeX input:&#xD;
&#xD;
    delayedMaTeX[texcode_] :=&#xD;
     With[{id = Unique[id]},&#xD;
      SetAttributes[id, Temporary];&#xD;
      delayed[id, texcode]&#xD;
     ]&#xD;
&#xD;
Finally we will have an `update[]` function that processes the queue:&#xD;
&#xD;
    update[] :=&#xD;
     Module[{},&#xD;
      queue = KeySelect[queue, NameQ]; (* drop keys that don&amp;#039;t have a corresponding temporary symbol *)&#xD;
      With[{syms = Symbol /@ Keys[queue]},&#xD;
       syms = MaTeX[Values[queue]]&#xD;
       ];&#xD;
      queue = &amp;lt;||&amp;gt;;&#xD;
     ]&#xD;
&#xD;
----&#xD;
&#xD;
We are ready to try it out now.&#xD;
&#xD;
Let&amp;#039;s put some MaTeX tick labels in a plot:&#xD;
&#xD;
    plot = Plot[Sin[x], {x, 0, 2 Pi},&#xD;
      Ticks -&amp;gt; {&#xD;
        Table[{x, delayedMaTeX[x]}, {x, 0, 2 Pi, Pi/3}],&#xD;
        Table[{y, delayedMaTeX[y]}, {y, -1, 1, 1/2}]&#xD;
        }&#xD;
      ]&#xD;
&#xD;
![Mathematica graphics](http://i.stack.imgur.com/7pEQT.png)&#xD;
&#xD;
Only the placeholders show for now.  Let&amp;#039;s process the queue:&#xD;
&#xD;
    In[25]:= update[] // AbsoluteTiming&#xD;
    Out[25]= {0.455054, Null}&#xD;
&#xD;
It was fast.  Let&amp;#039;s look at the plot again:&#xD;
&#xD;
    plot&#xD;
&#xD;
![Mathematica graphics](http://i.stack.imgur.com/DjKOK.png)&#xD;
&#xD;
Everything is in place now.&#xD;
&#xD;
At this moment we have lots of temporary symbols holding the results:&#xD;
&#xD;
    In[17]:= Names[&amp;#034;id*&amp;#034;]&#xD;
    Out[17]= {&amp;#034;id&amp;#034;, &amp;#034;id$&amp;#034;, &amp;#034;id$4271&amp;#034;, &amp;#034;id$4272&amp;#034;, &amp;#034;id$4273&amp;#034;, &amp;#034;id$4274&amp;#034;, \&#xD;
    &amp;#034;id$4275&amp;#034;, &amp;#034;id$4276&amp;#034;, &amp;#034;id$4277&amp;#034;, &amp;#034;id$4278&amp;#034;, &amp;#034;id$4279&amp;#034;, &amp;#034;id$4280&amp;#034;, \&#xD;
    &amp;#034;id$4281&amp;#034;, &amp;#034;id$4282&amp;#034;}&#xD;
&#xD;
They are gone as soon as `plot` is cleared:&#xD;
&#xD;
    In[18]:= plot =.&#xD;
    &#xD;
    In[19]:= Names[&amp;#034;id*&amp;#034;]&#xD;
    Out[19]= {&amp;#034;id&amp;#034;, &amp;#034;id$&amp;#034;}&#xD;
&#xD;
## To wrap up&#xD;
&#xD;
I hope you found this technique interesting.  Any comments, improvements, additions, criticisms are welcome.&#xD;
&#xD;
If you use MaTeX yourself and you would like to have this feature properly implemented and integrated into MaTeX, let me know.  It would eliminate any remaining disadvantages MaTeX has relative to [MathPSFrag](http://wwwth.mpp.mpg.de/members/jgrosse/mathpsfrag/).  But given that MaTeX already uses a caching system, and that I personally don&amp;#039;t find performance to be a problem, I&amp;#039;m not sure it&amp;#039;s worth the effort.&#xD;
&#xD;
&#xD;
  [1]: https://github.com/szhorvat/MaTeX</description>
    <dc:creator>Szabolcs Horvát</dc:creator>
    <dc:date>2016-11-21T19:49:25Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2741009">
    <title>Debugging and performance tuning for data parallelism</title>
    <link>https://community.wolfram.com/groups/-/m/t/2741009</link>
    <description>&amp;amp;[Wolfram Notebook][1]&#xD;
&#xD;
&#xD;
  [1]: https://www.wolframcloud.com/obj/bcaad1e3-6a91-4b39-8aec-c829b4e94d11</description>
    <dc:creator>Roman Maeder</dc:creator>
    <dc:date>2022-12-21T16:17:47Z</dc:date>
  </item>
</rdf:RDF>

