Function index_spec (o2scl_hdf)

O2scl : Function List

void o2scl_hdf::index_spec()

Index specifications for acol.

The tensor rearrange commands use index specifications to specify how the tensor should be rearranged. Index specifications may be specified as separate arguments or multiple index specifications may be given in a single argument separated by spaces or commas. The indices begin with 0, the first index so that index 1 is the second index. The list of index specifications is:

  • index(ix): Retain index ix in the new tensor.

  • fixed(ix): Fix the value of index ix.

  • sum(ix): Sum over the value of index ix

  • trace(ix1,ix2): Trace (sum) over indices ix and ix2. If the number of entries in either index is smaller than the other, then the remaining entries are ignored in the sum.

  • reverse(ix): Retain index ix but reverse the order.

  • range(ix,start,end): Retain index ix but modify range. Ranges include both of their endpoints.

  • interp(ix,value) (for tensor_grid ): fix index ix by interpolating ‘value’ into the grid for index ix.

  • grid(ix,begin,end,n_bins,log) (for tensor_grid ): interpolate the specified index on a grid to create a new index. If the value of ‘log’ is 1, then the grid is logarithmic.

  • gridw(ix,begin,end,bin_width,log) (for tensor_grid ): interpolate the specified index on a grid with a fixed bin width to create a new index. If the value of ‘log’ is 1, then the grid is logarithmic and ‘bin_width’ is the multiplicative factor between bin edges.

Note that the index specifications which result in a tensor index (all except ‘fixed’, ‘sum’, ‘trace’ and ‘interp’) must be given in the order they should appear in the tensor which results. Also, the rearrange commands require that the result of the rearrangement must have at least one index left.

Examples:

acol -create tensor_grid 3 9 10 11 -set-grid 0 "i^2" -set-grid 1 "2*i" -set-grid 2 "(2-i)" -function "sin(x0+x1*x2)" -entry 4 2 5 -rearrange "index(1) index(0)" "fixed(2,5)" -entry 2 4

This example creates a rank three tensor of size 9 by 10 by 11 and then flips the first two indices while fixing the third index to select the 6th value to create a rank 2 tensor of size 10 by 9. Additionally, this example demonstrates that one can put multiple index specifications into the same argument (as in the first argument to rearrange) or place additional index specifications in additional arguments. The entry command shows an entry in the original rank 3 tensor and the output command shows that that entry has now moved to the to the (2,4) location in the final rank 2 tensor.

acol -create tensor_grid 3 8 10 6 -set-grid 0 "i*m" \ -set-grid 1 "m/5*i+x" -set-grid 2 "(2-i)" -function \ "sin(x0+x1*x2)" -get-grid -entry 5 1 3 -entry 5 2 3 -rearrange \ "reverse(2),range(0,7,3),interp(1,4.5)" -get-grid -entry 2 2

This example creates a rank three tensor of size 8 by 10 by 6 and then creates a rank 2 tensor from it. In this example, the set-grid commands use variables ‘m’ and ‘x’. In the first call to set-grid, the variable m refers to the value 8, while in the second call, the variable m refers to the value 10. The value ‘x’ always refers to the previous grid value which is set by the create command to be equal to the index. The first index in the rank 2 tensor is a reversed version of the last index in the rank 3 tensor. The second index of the rank 2 tensor is constructed from a subset of the second index of the rank 3 tensor and also reversed (since 7 and 3 are given in the opposite order). The rank two tensor is constructed by linearly interpolating the value 4.5 into the second index of the rank three tensor, thus halfway between values when the index takes values 1 and 2. The final tensor thus has size 6x5. As an example, the (2,2) entry in the final tensor comes from the average of the (5,1,3) and (5,2,3) entries in the original rank 3 tensor.

acol -create tensor_grid 3 6 8 4 -set-grid 0 "erf(i*m/20)" -set-grid 1 "m/(i+1)" -set-grid 2 "exp(i)" -function "sin(x0+x1*x2+i0+i2)" -get-grid -rearrange "grid(2,5,20,5)" "gridw(1,7,1.2,0.9,1)" "interp(0,(erf(6/20)+erf(12/20))/2)" -get-grid

This example creates a rank three tensor of size 6 by 8 by 4 and then creates a rank 2 tensor from it. In this example, the set-grid commands uses the error and exponential functions to set the initial grid. The first index of the final tensor comes from the last index of the initial tensor, and the values are obtained by interpolating the original exponential grid to a linear grid beginning at 5 and ending at 20 with 5 bins (i.e. 6 grid points). The second index of the final tensor is obtained by interpolating the second index of the initial tensor, creating a logarithmic grid from 7 to 1.2. The final tensor is also created by interpolating the result of the mathematical expression “(erf(6/20)+erf(12/20))/2” into the first index of the initial tensor.