I'm currently trying to create a vectorSUM function in google scripts, which would sum up all vectors. I've looked into using the arguments method, but would much rather prefer using a rest parameter like the built in SUM function uses. I keep getting the error "missing formal parameter" this is my code. How would I go about using Optional parameters, as well as rest parameters in a custom function?
function vectorAdd(vector1, [vector2, ...]) {}
The built in SUM function uses
(value1, [value2, ...])
How can I achieve this?
Related
My use case is this: a function called 'time' that will return how long it takes to run any function you give it.
So the time function needs to know all the parameters to pass into the function when it calls it.
I know how to pass a function into another function, but how can I pass all its parameters, without knowing in advance how many and what type they are, so they can be used when calling the function?
For example, if I pass in an array of all the parameters I need to send, is there some Dart way to call a function by expanding an array into a list of parameters? Or perhaps there's another way to capture and pass a function call, including all parameters, as one executable object?
I'm also interested in knowing if there's a more Dartful way to accomplish what I'm trying to do re: timing function calls.
I believe using a List of parameters with the apply method is the most common way and practical of doing this and I have seen something similar used to pass parameters for JS interop. As far as I know, there isn't a way to expand an array into a list of parameters like you can for javascript. You could of course create your own object to pass arguments, but I think it would add unnecessary complexity and end up being more difficult.
Example of passing parameters to function in dart:js here.
I want to implement a custom loss function (from this paper: https://arxiv.org/abs/1706.00909) in MatConvNet.
My code uses the DagNN wrapper. I want to modify the class SegmentationLoss() to use a custom loss function, custom_loss() instead of vl_nnloss(). For the forward() pass, custom_loss() returns the calculated loss value.
What I don't understand is what custom_loss() should do during the backward() pass in SegmentationLoss(). What is the additional input derOutputs, where does it come from and what should be the return value of custom_loss()?
Thanks!
When i have 3 functions in a program, how do i check a specific function name ?
I want to know the name of those function for the sake of function selection.
Let say linear-kernel function, logistic-kernel function, and non-negative function, when i call the program, one of those function is called and i should to check whether it was linear, logistic or non-negative function, so i can execute another function related with the selected function.
I think doing function selection will save my time from repeating the base code. But doing function selection maybe is not the best design that i could use in Clojure.
FYI, at this level, i already use the "meta" keyword to access the function name, but when i create
(defn isKernel [krn]
(if (= (str (:name (meta #'krn))) "logistic-kernel") 1 0))
The compiler cannot resolve the 'krn' var
In Clojure functions are values, just like the number 4. This is a big part of the underpinnings of much of the language (and functional programming in general). Most of the time we store functions in vars though this is not required. functions as values don't have names* So rather than checking to see if the name of a passed function matches a known name, it makes more sense to ask "does this function have the same value as the function stored in the var" as #cgrand points out this can be accomplished simply by calling =.
If you are doing this kind of dispatch there is a good change that protocols are a better tool than rolling your own
*they do have names for the purpose of creating recursive function literals though thats not what I'm getting at here.
I'm working on a visual basic 6 and we have product made of VB6 modules that use each other. Every module has it's own exe.
I'm having a problem when I'm referring to one function in one module, which works, and in another module it doesn't.
For instance, in one module I'm calling the original VB6 Round function which takes following params:
Round(number,0)
But in another module there's a function defined as
Function Round(ByVal X As Variant) As Variant
That should be called as
Round(number)
And that causes a compile time error and it says that function call has a wrong number of parameters, while on other modules where this function is undefined there are no errors.
Now, I could use it, but there are other places where I actually need to specify decimal point precision where I call it as
Round(number,2)
Round(number,3)
etc.
How do I disambiguate between these functions to call only and ONLY the original VB6 rounding function?
I would recommend to avoid such ambiguities by choosing better names for your methods. If you canĀ“t change the method name you can use the full qualified name of the function.
VBA.Math.Round number, 2
I am having a few issues, calling Python functions defined in another script using tkinter. I would prefer to have a separate script for my functions that the GUI uses when needed. At the moment I am doing it like this.
ttk.Button(mainframe, text="1", command=one).grid(column=1, row=1, sticky=NW)
def one():
code_entry.insert(END,"1")
The above calls the command one on a button click, which will print the character one in a entry field with the GUI. I thought I could create a separate script to hold my functions and call them like this:
ttk.Button(mainframe, text="1", command=functions.one()).grid(column=1, row=1, sticky=NW)
And then simply add an import statement at the top of my GUI, like below:
import functions
This doesn't work and looking for some advice on how to approach this.
You didn't specify any error messages, but it's most likely that you're doing fuctions.one() - actually calling the one() function of that module before the Button is created. It's simply fixed by removing the () part - when you specify a function without (), you are passing a reference of the function object.
Also keep in mind the scope of the code_entry variable - if you were using it as a module level global before (or function local, if one() was inside the same function as your ttk.Button call), it won't be available when you move it to a new namespace without code_entry.
To solve this you should pass code_entry as a parameter to the callback without calling one() at first. The usual approach for this is creating a lambda - essentially creating a function that works on the same scope of the original one(), having access to variables like code_entry, but also calling a function in a different module.
ttk.Button(mainframe, text="1", command=lambda: functions.one(code_entry))
Note that this is basically the same as:
def some_anonymous_function():
functions.one(code_entry)
ttk.Button(mainframe, text="1", command=some_anonymous_function)
Both examples create a function object and pass that object as reference - the functions.one() call of the lambda is actually inside the body of the lambda function, to be called later by tkinter.
Of course you also have to redefine one() to accept this new parameter:
def one(code_entry):
code_entry.insert(END,"1")