Vector-valued functions

Vector-valued functions#

Some parameters require a function that returns a vector/array:

type flxVecPara#
Syntax:
canonical:

str | numpy.ndarray | collections.abc.Callable

Description:

A parameter that can pass a callable expression that returns an array (of pre-specified dimension N).

The dimension N is defined separately and mentioned in the documentation of each parameter of type flxVecPara.

The following types are accepted as input:
  • list: A list of size N where each entry is of type FlxPara.

  • str: The content of the string is parsed as a callable expression of type FlxMtxCode.

  • callable: A Python-callable that does not require any parameters is expected. Alternatively, a single parameter can be used as a reference to the result array - in which case the returned value of the function is ignored.

  • numpy.ndarray: A numpy.ndarray is assigned as value for the parameter.

Example:

import fesslix as flx
flx.load_engine()
import numpy as np

## ==============================================
## flxVecPara through Python function
## ==============================================

## -----------------------------------------
## function returns a numpy array
## -----------------------------------------
a = 3.3
def vec_help_a():
    return np.ones(5)*a
a = 2.2
vec_1a = flx.eval_vfun(5,vec_help_a) 
print( vec_1a )

## -----------------------------------------
## function takes array as argument
## -----------------------------------------
def vec_help_b(res_vec):
    for i in range(5):
        res_vec[i] = a*i
vec_1b = flx.eval_vfun(5,vec_help_b) 
print( vec_1b )

## ==============================================
## flxVecPara as list of flxPara
## ==============================================
def fun_hlp_2():
    return 42.
vec_2 = flx.eval_vfun(5,[ "pi", lambda: a, fun_hlp_2, "sin(pi)", "cos(pi)" ])
print( vec_2 )

## ==============================================
## flxVecPara as Fesslix-Code
## ==============================================
vec_3 = flx.eval_vfun(5,"""my_vec={
    mtxconst_new my_vec(5,1,pi);
}""")
print( vec_3 )

## ==============================================
## flxVecPara directly as <ndarray>
## ==============================================
vec_4 = flx.eval_vfun(5,np.ones(5)*7.1)
print( vec_4 )
Random Number Generator: MT19937 - initialized with rand()=267557737;
Random Number Generator: MT19937 - initialized with 1000 initial calls.
[2.2 2.2 2.2 2.2 2.2]
[0.  2.2 4.4 6.6 8.8]
[ 3.14159265e+00  2.20000000e+00  4.20000000e+01  1.22464680e-16
 -1.00000000e+00]
[3.14159265 3.14159265 3.14159265 3.14159265 3.14159265]
[7.1 7.1 7.1 7.1 7.1]
type FlxMtxCode#
VECNAME=CODE
Description:

Returns a vector from Fesslix with name VECNAME (of type Word) that is created/modified by the code in CODE (of type FlxCode).