Unknown and slow behavior of a SetDelayed manipulate

 Unknown and slow behavior of a SetDelayed manipulate

I couldn’t find much info about this problem so jumping right in: I have a large data matrix that I wish to select parts of and view in real-time using manipulate. But in coding it up I’ve found some odd behavior of manipulate when I try to make a function out of it using SetDelayed. For example, the following code works very quickly and presumably as intended:

rawdata = Table[{i, i + 1, i + 2}, {i, 100000}];
Manipulate[rawdata[[y;y+200]], {y, 500}]

The data matrix I’m using is about as large, but ordinarily there would be more selection criteria than a single element–however not an unreasonably complicated selection process: only a few criteria using one iteration of Cases[] for particular numeric values.

In any case, the aberrant behavior appears in this toy example when I wish to define the manipulate as a function for more general use (ultimately for use in a package):

displaydata[rawdatavar_] := Manipulate[rawdatavar[[y;;y+200]], {y, 500}]

This second example takes 0.14s compared to the previous 0. In this specific example the evaluation time is short enough to not be too problematic but nevertheless demonstrates the strange behavior. With my real data however, despite only a difference of non-integer matrix elements and a use of Cases[] which separately behaves quickly, the evaluation time can be in tens of seconds or minutes.

Any insight or resources would be greatly appreciated. I am still somewhat a Mathematica novice so forgive me if this is a simple problem with the implementation of SetDelayed, but based on the documentation for Manipulate[] this should be valid.

edit* Some interesting results: I’ve found that timing my minutes-long evaluation (using real data) only results in a 0.14 s duration. The rest of the time is apparently rendering the output. This is further explained because I get a temporary prompt window displaying “Formatting Notebook Contents”. This appears to be the real problem–again any insight would be greatly appreciated.

Let’s block ads! (Why?)

Recent Questions – Mathematica Stack Exchange