sgpykit.tools.type_and_property_check_functions
Functions
Check if the input is a sparse grid. |
|
Check if a given struct is a tensor grid or a tensor grid in a sparse grid struct. |
|
|
Compare two sparse grids for equality. |
|
Compare two tensor grids field by field, checking that the two grids are identical and accounting for numerical tolerance when comparing knots and weights. |
|
Check lexicographic order of vectors. |
|
Check if vector a is lexicographically less-or-equal than vector b up to a numerical tolerance. |
|
Check if a given object is a reduced sparse grid. |
- sgpykit.tools.type_and_property_check_functions.is_sparse_grid(S)[source]
Check if the input is a sparse grid.
A sparse grid is a vector of structs with fields ‘knots’, ‘weights’, ‘size’, ‘knots_per_dim’, ‘m’, ‘coeff’, ‘idx’.
- Parameters:
- Sobject
Input object to check.
- Returns:
- bool
True if S is a sparse grid, False otherwise.
- sgpykit.tools.type_and_property_check_functions.is_tensor_grid(S)[source]
Check if a given struct is a tensor grid or a tensor grid in a sparse grid struct.
- Parameters:
- Sstruct
Input struct to be checked.
- Returns:
- int
1 if S is a tensor grid, -1 if S is a tensor grid in a sparse grid struct, 0 otherwise.
Notes
A tensor grid is a struct with fields: ‘knots’, ‘weights’, ‘size’, ‘knots_per_dim’, ‘m’. A tensor grid in a sparse grid struct is a struct with two more fields: ‘coeff’, ‘idx’.
- sgpykit.tools.type_and_property_check_functions.isequal_sparse_grids(S1, S2, tol=1e-14)[source]
Compare two sparse grids for equality.
This function checks if two sparse grids are identical tensor grid by tensor grid, accounting for numerical tolerance when comparing knots and weights.
- Parameters:
- S1StructArray
First sparse grid to compare.
- S2StructArray
Second sparse grid to compare.
- tolfloat, optional
Tolerance used when comparing points and weights. Default is 1e-14.
- Returns:
- iseqbool
True if the sparse grids are equal, False otherwise.
- whatfieldstr
Name of the first field found to be different, or ‘length’ if the sparse grids have a different number of tensor grids.
Notes
The function first checks if the inputs are valid sparse grids. Then, it compares the number of tensor grids in each sparse grid. If they differ, it returns False and ‘length’. Otherwise, it iterates through each tensor grid, comparing them using isequal_tensor_grids. If any tensor grid is found to be different, it returns False and the name of the field that differs. If all tensor grids are equal, it returns True and an empty string.
- sgpykit.tools.type_and_property_check_functions.isequal_tensor_grids(T1, T2, tol=1e-14)[source]
Compare two tensor grids field by field, checking that the two grids are identical and accounting for numerical tolerance when comparing knots and weights.
- Parameters:
- T1tensor grid
First tensor grid to compare.
- T2tensor grid
Second tensor grid to compare.
- tolfloat, optional
Tolerance used when comparing points and weights. Default is 1e-14.
- Returns:
- iseqbool
True if the tensor grids are equal, False otherwise.
- whatfieldstr
The name of the first field of the two tensor grids that are found different, or ‘size’ if the two sparse grids have a different number of tensor grids.
- sgpykit.tools.type_and_property_check_functions.islexico(a, b)[source]
Check lexicographic order of vectors.
Checks if vector a is lexicographically less than or equal to vector b. Returns True if a <= b in lexicographic sense, False otherwise.
- Parameters:
- aarray_like
First vector for comparison.
- barray_like
Second vector for comparison.
- Returns:
- bool
True if a is lexicographically less than or equal to b, False otherwise.
Examples
>>> islexico([1, 2, 3], [1, 2, 5]) True >>> islexico([1, 2, 3], [1, 2, 3]) True >>> islexico([1, 2, 3], [1, 2, 1]) False >>> islexico([2, 2, 3], [1, 7, 1]) False >>> islexico([1, 7, 3], [1, 5, 3]) False
- sgpykit.tools.type_and_property_check_functions.islexico_tol(a, b, tol)[source]
Check if vector a is lexicographically less-or-equal than vector b up to a numerical tolerance.
- Parameters:
- aarray_like
First input vector.
- barray_like
Second input vector.
- tolfloat
Numerical tolerance for component-wise comparison.
- Returns:
- bool
True if a is lexicographically less-or-equal than b up to the given tolerance, False otherwise.
Examples
>>> ii = [1, 3] >>> jj = [1, 4] >>> islexico_tol(ii, jj, 1e-12) # Returns True >>> ii = [1+1e-13, 3] >>> islexico_tol(ii, jj, 1e-12) # Returns True >>> islexico_tol(ii, jj, 1e-14) # Returns False
- sgpykit.tools.type_and_property_check_functions.isreduced(S)[source]
Check if a given object is a reduced sparse grid.
A reduced sparse grid is a struct with fields ‘knots’, ‘m’, ‘weights’, ‘n’, ‘size’.
- Parameters:
- Sobject
The object to check.
- Returns:
- int
1 if S is a reduced sparse grid, 0 otherwise.