Functions Index :: A :: ArraySum

[<< up one level]

Module:

array :: operators

Definition:

ArraySum(string array, string "elm_func", string "elm_args", string "sum_func", string "sum_args")

Description:

Returns the sum of all array elements as it is deduced by applying a user-defined function for the evaluation of each array element and another one for the summing of the resulting values.

In effect the function is the equivalent of taking the integral of an array.

Arguments:

array: The array who's elements will be summed.

"elm_func" (Optional, defaults to "Self"): The function to evaluate each array element and return a value to be used by sum_func. The default function simply returns element unchanged.

"elm_args" (Optional, defaults to ""): A string in the form of a function call argument list (ie a comma delimited list of values) containing additional arguments to be passed to the elm_func function.

"sum_func" (Optional, defaults to "Sum2"): The function to evaluate the sum of values produced by the application of elm_func on each array element. The default function simply adds the values by using the "+" operator.

"sum_args" (Optional, defaults to ""): A string in the form of a function call argument list (ie a comma delimited list of values) containing additional arguments to be passed to the sum_func function.

Notes and conditions on arguments relations:

1] elm_func must accept one required argument with type compatible to array elements' type(s). The argument must be first in elm_func's argument list. An arbitrary number of other (possibly optional) arguments is allowed, but if any of them is not optional it must always be specified in elm_args.

2] sum_func must accept two required arguments with types compatible to the type(s) of the result of application of elm_func to array's elements. The arguments must be first in sum_func's argument list. An arbitrary number of other (possibly optional) arguments is allowed, but if any of them is not optional it must always be specified in sum_args.

3] Both the elm_args and sum_args argument list strings can only contain value literals and global names (expressions of them are supported also). Use the String() function to convert local variables to value literals.

Examples:

a1 = "0.5, 1.0, 1.5, 2.0, 2.5"

num = a1.ArraySum() # num == 7.5

# sum an array of clips

a2 = ArrayCreate(AVISource(.1.), ..., AVISource(.20.))

fin_clip = a2.ArraySum() # same as (.1.)+(.2.)+...

# filter and then sum an array of clips

Function myfilter(clip c) {

return c.ConvertToYUY2().Tweak(cont=1.2)

}

flt_clip = a2.ArraySum(elm_func="myfilter")

# filter and then sum an array of clips

# blending with Dissolve(...,10)

blflt_clip = a2.ArraySum(elm_func="myfilter", \

sum_func="Dissolve", sum_args="10")

 

[<< top]

 

More examples and in-depth explanation of operator functions can be found at the "Container operators" tutorial.