Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


2 Pages12>
Options
Go to last post Go to first unread
Offline mkraska  
#1 Posted : 21 September 2013 12:27:34(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,980
Germany

Was thanked: 1120 time(s) in 718 post(s)
I open this topic for the snippets hatch and fill, as a place for further disussions.

You find these snippets and a corresponding example in the extension manager (online gallery).

Previous discussion can be found here.
mkraska attached the following image(s):
hf.PNG
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Ber7  
#2 Posted : 23 September 2013 21:24:31(UTC)
Ber7


Rank: Advanced Member

Groups: Registered
Joined: 15/07/2010(UTC)
Posts: 437
Man
Israel
Location: Beer-Sheva

Was thanked: 520 time(s) in 288 post(s)
Example of application
File Attachment(s):
EllipticGears.sm (41kb) downloaded 134 time(s).
thanks 3 users thanked Ber7 for this useful post.
on 24/09/2013(UTC),  on 24/09/2013(UTC),  on 14/10/2013(UTC)
Offline Ber7  
#3 Posted : 12 October 2013 00:58:10(UTC)
Ber7


Rank: Advanced Member

Groups: Registered
Joined: 15/07/2010(UTC)
Posts: 437
Man
Israel
Location: Beer-Sheva

Was thanked: 520 time(s) in 288 post(s)
File Attachment(s):
Graf1.smz (3kb) downloaded 94 time(s).
thanks 2 users thanked Ber7 for this useful post.
on 12/10/2013(UTC),  on 14/10/2013(UTC)
Offline mkraska  
#4 Posted : 12 October 2013 11:24:04(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,980
Germany

Was thanked: 1120 time(s) in 718 post(s)
It's amazing how compact the code is!
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
Offline Ber7  
#5 Posted : 19 October 2013 00:25:49(UTC)
Ber7


Rank: Advanced Member

Groups: Registered
Joined: 15/07/2010(UTC)
Posts: 437
Man
Israel
Location: Beer-Sheva

Was thanked: 520 time(s) in 288 post(s)
Two types of shading

File Attachment(s):
Reuleauxtriangle.sm (32kb) downloaded 85 time(s).
Reuleauxtriangle1.sm (35kb) downloaded 81 time(s).
thanks 1 user thanked Ber7 for this useful post.
on 19/10/2013(UTC)
Offline Razonar  
#6 Posted : 05 June 2016 05:38:42(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,356
Uruguay

Was thanked: 815 time(s) in 516 post(s)
Hi. From the orignal discussion:

Originally Posted by: mkraska Go to Quoted Post
Fridel, thanks for revisiting the snippet and the performance issue. Quite odd for me: The fastest way seems to be direct element adressing without pre-allocation and avoiding stack(). See attachment. The speed-up is significant.

Please post any response to the new dedicated topic



I understand that stack or augment are bad strategies, but without pre-allocation is better than with pre-allocation? If it is, why is without pre that good. Seems to be to much faster than I can explain or understand.

Best regards.

Alvaro.
Offline Jean Giraud  
#7 Posted : 05 June 2016 08:11:03(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Originally Posted by: Razonar Go to Quoted Post
I understand that stack or augment are bad strategies, but without pre-allocation is better than with pre-allocation? If it is, why is without pre that good. Seems to be to much faster than I can explain or understand.

Best regards.

Alvaro.


"memory allocation" vs "memory NOT allocation" is confusing to me.
Memory allocales itself from the construction. Visit the "Spot"
"stack" is very fast as being a vector operation. "augment" is slow
as not being a direct vector operation, but very fast within a program.
"hatch" creates a virtual matrix, a scalar matrix, i.e: a matrix at the
plot canvas. Same principle than plotting f(x) on the QuickPlot canvas.
Great construction, though I never used it. Watch it does not face infinity
governed by the N ... at infinity: it crashes Smath !

Jean

Forum Test Derivative.sm (12kb) downloaded 55 time(s).

Utilities Discrete Spot.sm (13kb) downloaded 56 time(s).



Offline Razonar  
#8 Posted : 05 June 2016 08:25:31(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,356
Uruguay

Was thanked: 815 time(s) in 516 post(s)
Using stack, if you have a vector, lets says, [x,y,z], then stack(t,[x,y,z]) must to force to push z from 3th plate to 4th, y from 2nd to 3th, ... for finally, put t at first place. And that's can take a very long time.
Preallocating is when you say "let's V:=matrix(20,1)", and then just work defining V[1, V[2 ... etc. If you found that don't need all 20 numbers, just can use submatrix. But if you don't preallocate V, but use V[1 ... V[20, and program work fast, who is preallocating must to be SMath, and that's isn't very efficient for the general cases. Or have some pointer very good for handle that matrices, and I don't know C at that level.

In your example, "Utilities discretes", it is suposed that defining U:=matrix(N,1), and same for V, must to be faster than having U:=0 and then use U[i

Best regards.

Alvaro.

Edited by user 05 June 2016 08:28:49(UTC)  | Reason: Not specified

Offline Razonar  
#9 Posted : 05 June 2016 08:41:38(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,356
Uruguay

Was thanked: 815 time(s) in 516 post(s)
It is supossed that second algorithm must to be faster than your's, but it isn't.

Best regards.

Alvaro.

SymTime.gif

Offline Jean Giraud  
#10 Posted : 05 June 2016 08:44:51(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
See you tomorrow Alvaro.

That nice application of "hatch" is worth for "typesetting"

Jean

Forum Hatch Demo.gif


Offline mikekaganski  
#11 Posted : 05 June 2016 09:52:43(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Originally Posted by: Razonar Go to Quoted Post
I understand that stack or augment are bad strategies, but without pre-allocation is better than with pre-allocation? If it is, why is without pre that good. Seems to be to much faster than I can explain or understand.


Much faster than what? Please provide an example to discuss.

Originally Posted by: Razonar Go to Quoted Post
Preallocating is when you say "let's V:=matrix(20,1)", and then just work defining V[1, V[2 ... etc. If you found that don't need all 20 numbers, just can use submatrix. But if you don't preallocate V, but use V[1 ... V[20, and program work fast, who is preallocating must to be SMath, and that's isn't very efficient for the general cases. Or have some pointer very good for handle that matrices, and I don't know C at that level.


It's a common practice in libraries to pre-allocate some space for any container. Without this, it would be very inefficient to manage memory. Further, re-allocation strategies on the low level are quite efficient, because they either use % of current size to grow (typical are 2x or golden ratio), or linked lists that don't need reallocation at all. SMath doesn't need to do that itself, because it's .NET that does that for it. And it's VERY efficient for general cases.

Originally Posted by: Razonar Go to Quoted Post
It is supossed that second algorithm must to be faster than your's, but it isn't.


Well, your slower second time could be explained like this:
pre-allocation in SMath is high-level operation, and it simply adds one additional high-level (slow) operation.

And it could explain something, if not one little thing ... actually it doesn't matter. Good
SMath calculation time is very volatile, and it's hard to measure time reliably, even doing multiple comparisons/calculations. E.g., processor temperature, that raises towards second calculation, may cause it to slow down to prevent overheating (contemporary systems do that). Some memory leaks in SMath may cause slow-down of all subsequent calculations (and when the sheet is done calculation, .NET garbage collection may clean it up, so recalculation shows the same picture).

Here is a screenshot that shows that your "second" calculation, put first, outperforms original.

scrH52.png
Best regards,
Mike Kaganski
Offline Jean Giraud  
#12 Posted : 05 June 2016 18:42:41(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Alvaro, Mike: thanks for entertaining technical matters, very educative.

Though the "algo style" existed in Smath before I joined the team, it
was not elegant and in some ways not visible. As you can see, in the
attached, there is one less "augment" in ... pts(data,spec) compared to
plotG(vx,vy,char,size,color) decreasing the computing time by a factor
of 12 on my testing over 1000 points. You may have better suggestion(s).
For sure welcome in the experiment room .

Jean

Forum Compute Test Points Fill.sm (18kb) downloaded 57 time(s).

Inst_Segment Partial Random.sm (39kb) downloaded 56 time(s).


Offline Razonar  
#13 Posted : 06 June 2016 01:00:11(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,356
Uruguay

Was thanked: 815 time(s) in 516 post(s)
Originally Posted by: mikekaganski Go to Quoted Post
Originally Posted by: Razonar Go to Quoted Post
I understand that stack or augment are bad strategies, but without pre-allocation is better than with pre-allocation? If it is, why is without pre that good. Seems to be to much faster than I can explain or understand.


Much faster than what? Please provide an example to discuss.



Than I can explain or understand. Sorry, have not examples of that.


Originally Posted by: mikekaganski Go to Quoted Post


It's a common practice in libraries to pre-allocate some space for any container. Without this, it would be very inefficient to manage memory. Further, re-allocation strategies on the low level are quite efficient, because they either use % of current size to grow (typical are 2x or golden ratio), or linked lists that don't need reallocation at all. SMath doesn't need to do that itself, because it's .NET that does that for it. And it's VERY efficient for general cases.


Thanks for the explanation, now I understand why mkraska says "The fastest way seems to be direct element adressing without pre-allocation". Because preallocating is with a high level instruction, and then is slow. Even I have the doubt about why NET pre-allocat V:=0 as matrix when user define that as scalar. I suposse that default SMath types are complexes, not matrices.

So, for the best practices book in SMath, which is best? Never preallocat? Or there are some size when NET take more time than SMath because the NET pre-pre-allocation (the jus't in case one) isn't enough big?

Best regards.

Alvaro.


Offline mikekaganski  
#14 Posted : 06 June 2016 02:26:09(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Originally Posted by: Razonar Go to Quoted Post
now I understand why mkraska says "The fastest way seems to be direct element adressing without pre-allocation". Because preallocating is with a high level instruction, and then is slow.


No, I tried to show this. One single allocation instruction's duration is null, zero, nothing. You will be unable to notice it in any measurements in SMath. Martin was not correct. I will say it once more: one method (assigning 0 and then addressing elements) is not faster than the other.

Quote:
Even I have the doubt about why NET pre-allocat V:=0 as matrix when user define that as scalar. I suposse that default SMath types are complexes, not matrices.


No, it "allocates" a scalar (very fast) once, and then re-allocates a vector with a sensible pre-allocated size (very fast) once.

Quote:
So, for the best practices book in SMath, which is best? Never preallocat? Or there are some size when NET take more time than SMath because the NET pre-pre-allocation (the jus't in case one) isn't enough big?


I prefer always preallocating when I know the size. It won't hurt. Its "overhead" of high-level instruction is the same as of the assigning 0 and then re-allocating. In a function, it will not make any difference until the system preallocation size is exceeded, and then, when the function will handle big matrices, it will give you (insignificant, if any) performance gain.
Best regards,
Mike Kaganski
thanks 1 user thanked mikekaganski for this useful post.
on 06/06/2016(UTC)
Offline Jean Giraud  
#15 Posted : 06 June 2016 03:35:11(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Like this Alvaro in my own words,

Mathcad up to 11 [my last version up to may 30 that PT deactivated all Single User Edition]
Mathcad XY plot is on "pica" [from recollection 8 pixels] thus the imposibility to equally size
two graphs in height/width. Smath plots on the canvas pixel. Each time it reaches a pixel it
calculates the ordinate value and plug the color, thus finally tracing the function. This porocess
is very fast, but at the kernel level and not accessible to user. To get an export trace then you
must create a vector of discrete values in the number of points as you wish.

Martin program is very crafty ! Instead of hatching by creating each vertical bar manually, it
creates the same as manual but adjustabe in 'N' and between the two plots in question. His argument
of the plot is f,g,x.1,x.2,N in hatch(f,g,x.1,x.2,N), just like asking to plot 'x' in ln(x).
So, 'f,g,x.1,x.2,N' is purely "scalar" in the sense of a vanishing iterator once done the plotted
value on the Smath QuickPlot.

As you remember from Mathsoft Collaboratory, so much I loved Mathcad 2D ...
... so much Smath QuickPlot produces more convenient graphs. OK, some missing features but monkeys
survive with bananas only, is it ? On the hatching demo [attached next post], if you plot points
the hatching looks blank. Not at all, they are all there but not joining because the points confuse
on each plot trace.

Jean
Offline Jean Giraud  
#16 Posted : 06 June 2016 03:37:37(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
... the hatching demo

2DPlots Hatch Demo.sm (9kb) downloaded 60 time(s).
Offline Jean Giraud  
#17 Posted : 06 June 2016 04:30:46(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
... works as expected !

Forum Hatch Demo Curvature.gif

Maths Tangent.sm (19kb) downloaded 69 time(s).
Offline Razonar  
#18 Posted : 06 June 2016 10:34:38(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,356
Uruguay

Was thanked: 815 time(s) in 516 post(s)
My versions for fill and hatch.
Have a nice day.
Alvaro.

FillRnd.sm (45kb) downloaded 76 time(s).
Offline Jean Giraud  
#19 Posted : 06 June 2016 15:39:37(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Only the first module works. The ones "if/else" do not in Smath 5346
The first module is fully compatible with Maxima X_Y plot, i.e:
traces color, symbols, hatching color ... great for publishing.
Martin scalar hatching is slightly faster, not to account in project.
Your module [Alvaro] is great for extracting a particular bar but
couldn't add to the plot ???

Tanks, Jean

Forum Hatch Demo Alvaro.gif


2DPlots Hatch Demo [Martin, Alvaro].sm (24kb) downloaded 62 time(s).
Offline Razonar  
#20 Posted : 06 June 2016 23:26:19(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,356
Uruguay

Was thanked: 815 time(s) in 516 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Only the first module works. The ones "if/else" do not in Smath 5346


Well, works fine in last nightly build, but you're right, in others don't. I try to modify, but have a lot of issues. For instance, attached seems to work in last portable version, but can take a very long time for fill(phi(2), ...) , I suspect for some problem with the lele function. I'm interested in that function and rfill because rows of G are proportional to double integral of the functions f,g.

About the original fill function, it is a very nice job, but I prefer to define x range and Nx, Ny as number of points, instead of define the entire box x1,x2,y1,y2. But that's is ok for double integrals.

Best regards.

Alvaro.

fill.gif FillRnd (1).sm (45kb) downloaded 59 time(s).
Users browsing this topic
2 Pages12>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.