optional-parameters

Python : optional arguments for function calling lower level functions

依然范特西╮ 提交于 2019-12-24 16:14:34
问题 I have a function def weights(vector, loss_function, clipping, max_iterations=100, tolerance=1e-5) which needs to call a lower level loss function which can be any of these with the vector and clipping passed in argument : huber_loss(vector, clipping=2.38) cauchy_loss(vector, clipping=3.27) bisquare_loss(vector, clipping=1.04) Each loss function has a special proper default clipping value so we can call them either huber_loss(vector) or huber_loss(vector,2) for example. I want to make the

Are optional params available for the Compact Framework?

大城市里の小女人 提交于 2019-12-24 12:01:11
问题 I need to get a list of all files on a handheld device whose names fit a certain pattern, such as " ABC .XML" I adapted code from here (Hernaldo's answer), like so: public static List<string> GetXMLFiles(string fileType, string dir) { string dirName = dir; // call it like so: GetXMLFiles("ABC", "\\"); <= I think the double-whack is what I need for Windows CE device...am I right? var fileNames = new List<String>(); try { foreach (string f in Directory.GetFiles(dirName)) { if ((f.Contains

Angular Url without slash with optional parameters

不羁岁月 提交于 2019-12-24 08:13:28
问题 Both ui-router optional param without trailing slash and How to define optional parameter using UI-Router without trailing slash as well? have insufficient arguments and invalid (at least for my scenario i.e. working links (href) for angular routes without trailing slashes) answers . Live Demo Link Here are the example html links <div> <a ui-sref="home">Home</a> | <a href="#/posting/">Post 1</a> | <a href="#/posting">Post 2</a> | <a href="#/posting/sami">Post 3</a> | <a ui-sref="post">Post 4<

Variable argument pairs in MATLAB functions

人走茶凉 提交于 2019-12-24 07:59:18
问题 I'm trying to develop a function that contains multiple arguments. To be as robust as possible, I want to be able to call my function as follows: foo( x, y, z, 'OptionalArg1', bar, 'OptionalArg2', blah, 'OptionalArg3', val ) I want my function to be robust enough to contain any combination of these arguments in any order. I also need to be able to set defaults if the argument is not provided. Is there a standard way to do this in MATLAB? 回答1: The best way would be to use the inputParser class

Optional function arguments with no default value possible?

大兔子大兔子 提交于 2019-12-24 06:49:05
问题 In Chapel, we can set the default value of function formal arguments easily, for example, proc test( a = 1, b = 2.0, c = "hi" ) { ... } and call the function by using keywords also: test( 10 ); // a = 10, b = 2.0, c = "hi" test( b = 3.14 ); // a = 1, b = 3.14, c = "hi" test( c = "yo" ); // a = 1, b = 2.0, c = "yo" Here, I am wondering if it is possible to define a keyword argument that does not require a predefined default value. More specifically, I would like to write a function that can

Passing all elements of an array to a function with variable parameters (…)

假如想象 提交于 2019-12-24 05:19:26
问题 I need to pass a variable number of parameters to a c-function that allows a variable number of parameters. function a(int n , ...) {...} //*n* number of parameters int b[XXX]; //XXX is more or less run-time dynamic. //Filsignals.https://github.com/libpd/libpd/blob/master/pure-data/src/d_ugen.cl b with things. a(n, b[0], b[1] ... b[XXX]) How to write this without naming each single element of b? One thing: I cannot change the implementation of a() and it uses the va_list to access "...". Thus

creating a function that deals with optional parameters

荒凉一梦 提交于 2019-12-24 03:17:08
问题 I found this code in Jquery in Action: function complex(p1,options) { var settings = $.extend({ options1: devaultVal1, options2: devaultVal2, options3: devaultVal3, options4: devaultVal4, options5: devaultVal5, },options||{}); //remainder of function definition.. }; I don't understand three things about this pattern: The $.extend() function merges the options parameter with the first parameter object. If I were to pass an 'optional' parameter when invoking complex() , how would it tie into

Python function optional arguments - possible to add as condition?

血红的双手。 提交于 2019-12-23 17:12:15
问题 Is it possible, somehow, to aassign a condtional statement toan optional argument? My initial attempts, using the following construct, have been unsuccessful: y = {some value} if x == {someValue} else {anotherValue} where x has assigned beforehand. More specifically, I want my function signature to look something like: def x(a, b = 'a' if someModule.someFunction() else someModule.someOtherFunction()): : : Many thanks 回答1: Sure, that's exactly how you do it. You may want to keep in mind that b

Why can't typed optional arguments have a default of Null?

吃可爱长大的小学妹 提交于 2019-12-23 09:39:46
问题 In ActionScript 3, when you declare an optional argument by giving it a default value, the value null cannot be used on typed arguments. function Action(Param:int=null){ // 1184: Incompatible default value of type Null where int is expected. } function Action(Param:int=0){ // No compiler errors } Any workarounds for this, or general purpose values that can apply to all data types? 回答1: You can change your int to Number and then can set it to NaN which is a special number that means 'not a

parameter list (“*”) with lazy “by-name” parameters?

孤街醉人 提交于 2019-12-22 14:15:22
问题 I can: scala> def foo( f: => String) = println(f) foo: (f: => String)Unit and I can: scala> def foo( f: String*) = f.map(println) foo: (f: String*)Seq[Unit] but I can't: scala> def foo( f: =>String* ) = f.map(println) <console>:1: error: ')' expected but identifier found. def foo( f: =>String* ) = f.map(println) ^ nor scala> def foo( f: (=>String)* ) = f.map(println) <console>:1: error: no by-name parameter type allowed here def foo( f: (=>String)* ) = f.map(println) ^ Is there some other way