Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if an output is being ignored with ~ [duplicate]

In Matlab, you can ignore an output with the following syntax:

[~, ixMax] = max(foo);

I have a function, with signature

[out, out1, out2, out3] = function foo(in1, in2, in3)

out1, out2 and out3 are optional outputs, and each is only needed in very specific (unusual) circumstances. Foo is computationally expensive, and out1/out2/out3 are all even more computationally expensive, but rely on intermediate state generated by foo. I'd like to be able to avoid computing out1/out2/out3 if the caller is using a ~ to ignore them. How can I check for that in the definition of foo?

like image 424
John Avatar asked Oct 10 '17 13:10

John


People also ask

How to check if two strings are same ignoring their cases?

Check if two strings are same ignoring their cases. Given two strings str1 and str2. The task is to check if the two given strings are same if a case-insensitive comparison is followed, i.e., the cases of the strings are ignored in Java. Examples: Compare each character of the first string with the corresponding character of the second string.

How to check if a file is ignored or not in Git?

Git has an inbuilt command named check-ignore to check if a file is ignored or not. To validate the .gitignore file, first, we will look at an example .gitignore file. Also, you can take a look at the gitignore templates for reference. Now let’s look at different scenarios using the above .gitignore file as an example.

How to tell if the output has already been printed?

Show activity on this post. There's no way to tell once the output has already been printed.

Will output requirement 062 be fulfilled if invoice list is processed?

This means that output requirement 062 will not be fulfilled no matter if you process the invoice list or not. The interesting question is why you have billing documents with processed invoice lists and this output present.


1 Answers

It won't accelerate the process. The ~ is a way to the reader to tell him you won't need these outputs. It also saves the memory usage of this variable.

Matlab documentation says:

However, some functions return results that use much more memory. If you do not need those variables, they waste space on your system.

So it does not improve performance because these values are internally calculated anyway.

The book Accelerating MATLAB Performance: 1001 tips to speed up MATLAB programs by Yair M. Altman says (p187):

enter image description here

However, without using the ~, and if the first output is needed, the user will gain computational time by just removing the ~ and the brackets, and writing.

out = function foo(in1, in2, in3)
like image 101
alpereira7 Avatar answered Oct 13 '22 08:10

alpereira7