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

Notification

Icon
Error

Login


2 Pages<12
Options
Go to last post Go to first unread
Offline Razonar  
#21 Posted : 03 February 2021 04:30:13(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
Originally Posted by: ElSid Go to Quoted Post
The only thing that remotely comes to mind is that M, being defined within the program structure as M:=Mo, is not having to read for the variable from the outside.
Have you, or anyone else, tried this on other programs?

What's wrong or incorrect in there is length it shouldn't exist in Smath

EvenFaster.PNG


Hi Jean. Of course that it exists: length(M):=rows(M)*cols(M).

The matrix is square 75x75. In your image you only execute the function for the first 75 values of M and not the 75x75 = 5625 values.

The program also makes use of SMath's ability to access the elements of a two dimensional array by means of a single index because it is more compact, since it requires only one loop.

For small matrices it seems that there are not difference between "the M=M" version and the other. It's just for big ones, whatever big means.

Best regards.
Alvaro.

Edited by user 03 February 2021 04:38:33(UTC)  | Reason: Not specified

Offline MarB  
#22 Posted : 03 February 2021 15:03:04(UTC)
MarB


Rank: Advanced Member

Groups: Registered
Joined: 21/10/2016(UTC)
Posts: 84

Was thanked: 21 time(s) in 17 post(s)
Nearly every function I use with a matrix M as argument starts with |M#:=M

A long time ago I stopped wondering why that's such a immense advantage in speed and just accepted it like it is.
Offline Jean Giraud  
#23 Posted : 03 February 2021 15:47:36(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
Hi Jean. Of course that it exists: length(M):=rows(M)*cols(M).

Thanks Alvaro for correcting my gross mistake.
The slow module can be improved "Unwrap", maybe valid otherwise.
Take care ... Jean

Maths eval(,) TEST.sm (19kb) downloaded 8 time(s).


Offline ndtma  
#24 Posted : 03 February 2021 17:08:25(UTC)
ndtma


Rank: Advanced Member

Groups: Registered
Joined: 05/06/2014(UTC)
Posts: 348
Man
Sri Lanka
Location: Colombo

Was thanked: 124 time(s) in 82 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Originally Posted by: ndtma [url=/forum/yaf_postsm67582_Advantage-of-vectorize-function.aspx#post67582][/url]Revised program to handle date strings.

Thanks Collab for that most useful work.
Saved ... for future use.
Cheers ... Jean


Thank you Jean for the kind and encouraging comments.
Take care.
Look within!... The secret is inside you.
Best Regards
Eng. NDTM Amarasekera - Sri Lanka
Offline ElSid  
#25 Posted : 03 February 2021 17:10:06(UTC)
ElSid


Rank: Advanced Member

Groups: Registered
Joined: 05/03/2009(UTC)
Posts: 433
Man
United States
Location: USA

Was thanked: 17 time(s) in 15 post(s)
Good morning,
Why the practice of using the program line when defining single variables like f(M):=|norme(M)? If you redefine it without the "program line" f(M):=norme(M), it speeds it up a little. I ask because I've seen other users do this without understanding the rationale. EvalTestRS1.sm (20kb) downloaded 7 time(s)..

In addition, I can't recall how to add a program line in the middle of a program. At the moment, I'm stretching the grip down and physically moving items which is not optimal.

Offline Jean Giraud  
#26 Posted : 03 February 2021 17:48:08(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: ElSid Go to Quoted Post
In addition, I can't recall how to add a program line in the middle of a program. At the moment, I'm stretching the grip down and physically moving items which is not optimal.

Elsid, you better have an example to crunch !
We can do what we want and much more.
Local definition often works well, for Legendre: a must
Snow up there but mild ... Jean.
Offline churichuro  
#27 Posted : 03 February 2021 18:15:46(UTC)
churichuro


Rank: Advanced Member

Groups: Registered
Joined: 27/03/2019(UTC)
Posts: 75
Mexico
Location: coah

Was thanked: 27 time(s) in 22 post(s)
Originally Posted by: ElSid Go to Quoted Post
Good morning,
Why the practice of using the program line when defining single variables like f(M):=|norme(M)? If you redefine it without the "program line" f(M):=norme(M), it speeds it up a little. I ask because I've seen other users do this without understanding the rationale. EvalTestRS1.sm (20kb) downloaded 7 time(s)..

In addition, I can't recall how to add a program line in the middle of a program. At the moment, I'm stretching the grip down and physically moving items which is not optimal.



use ","
thanks 1 user thanked churichuro for this useful post.
on 04/02/2021(UTC)
Offline Jean Giraud  
#28 Posted : 03 February 2021 22:22:14(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: ElSid Go to Quoted Post
Why the practice of using the program ... line

The single place holder program line you are talking about is the
Smath local definition ... to get it: ] delete 2nd place holder.
De Boor is the most demonstrative example.
Cheers ... Jean

Spline De Boor [Colibri].sm (35kb) downloaded 9 time(s).

Offline ElSid  
#29 Posted : 04 February 2021 06:44:39(UTC)
ElSid


Rank: Advanced Member

Groups: Registered
Joined: 05/03/2009(UTC)
Posts: 433
Man
United States
Location: USA

Was thanked: 17 time(s) in 15 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post

The single place holder program line you are talking about is the Smath local definition ...

Why use it? In the sample file I attached, based on Alvaro's file, it actually slowed down the calculation a little. I've tried this on other files too.
Why do you use it?

Offline Razonar  
#30 Posted : 04 February 2021 08:39: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)
Originally Posted by: ElSid Go to Quoted Post
Good morning,
Why the practice of using the program line when defining single variables like f(M):=|norme(M)? If you redefine it without the "program line" f(M):=norme(M), it speeds it up a little. I ask because I've seen other users do this without understanding the rationale. EvalTestRS1.sm (20kb) downloaded 7 time(s)..



Hi ElSid. I see your yellow lines in the file, and it's true, it's faster without line(norme(M))

(If you don't know, you can copy an equation in smath and paste it in a text area or text editor to see it's structure, like line(), mat(), etc.)

Well, in my personal case, I use line() because ... well, I forgot why, but I use that since this 8 years old post (I'm adiaz there): https://en.smath.com/for...-a-program.aspx#post7966

Making memory if I go to define some "utility" I try to use line always. Maybe because you can use 1*line() for convert that into a non-line function but that's a poor argument. Another reason could be that if you have something very simple, let's say norme(v):=sqrt(dot(v*transpose(v))) and later you need to modify that for some more complex, in such case usually you can avoid the use of line(), and as you can see the SMath behavior could be a little different in that case. Using always line() you can prevent surprises later. I reserve f(x):=formula just for "working" functions, expected to be always simple expressions.

As you can see in that post there are an issue in SMath about "local" and "global" variables. Functions with / without line() could have different behavior respect to those kind of variables in a procedure. Some users use x# as arguments and local variables in procedures, I try also to use unicode characters, but my opinion about that is that the better solution is a local() command for ensure true local variables.

Originally Posted by: ElSid Go to Quoted Post

In addition, I can't recall how to add a program line in the middle of a program. At the moment, I'm stretching the grip down and physically moving items which is not optimal.



Recently Viacheslav post about some user's tutorial videos in youtube about smath. Maybe that can help better than written instructions.

Best regards.
Alvaro.

Edited by user 04 February 2021 08:50:33(UTC)  | Reason: Not specified

Offline Jean Giraud  
#31 Posted : 04 February 2021 16:18:32(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 ask because I've seen other users do this without understanding the rationale.

The rationale of Smath is that it is essentially a plugin system.
Then not like Mathcad a semi-compiled system.
There is no rule for eval(,), just best timing, or simply working or not.
The local definition is a much different story, dictated from error message.
Some use f(#), I don't ... more intuitive f(■)
That is not a fixed rule, it depends upon the algo involved.
Cheers ... Jean

Algo Styles.sm (21kb) downloaded 16 time(s).
Offline ndtma  
#32 Posted : 22 August 2021 16:28:04(UTC)
ndtma


Rank: Advanced Member

Groups: Registered
Joined: 05/06/2014(UTC)
Posts: 348
Man
Sri Lanka
Location: Colombo

Was thanked: 124 time(s) in 82 post(s)
Vectorize function on Nested Array revisited.

Cheers!

Nested_Arrays_Vectorize.png
Look within!... The secret is inside you.
Best Regards
Eng. NDTM Amarasekera - Sri Lanka
Users browsing this topic
2 Pages<12
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.