[Top] [Prev] [Next] [Bottom]

9.3 Additional Array Operations: arrayfnsmodule

A number of functions which emulate Yorick functions are used frequently by the 3D graphics, and in interpreted code simply run too slowly. These functions have been moved to arrayfnsmocule and written in C. Their diescriptions form this section of the manual.

9.3.1 Counting Occurrences of a Value: histogram

Calling Sequence

histogram (list [, weight])

Description

histogram accepts one or two arguments. The first is an array of non-negative integers and the second, if present, is an array of weights, which must be promotable to double. Call these arguments list and weight. Both must be one-dimensional with len (weight) >= max (list) + 1. If weight is not present:

histogram (list) [i] is the number of occurrences of i in list.

If weight is present:

histogram (list, weight) [i] is the sum of all weight [j] where list [j] == i.

9.3.2 Assigning to an Arbitrary Subset of an Array: array_set

Calling Sequence

array_set (vals1, indices, vals2)

Description

array_set accepts three arguments. The first is an array of numerics (Python characters, integers, or floats), and the third is of the same type. The second is an array of integers which are valid subscripts into the first. The third array must be at least long enough to supply all the elements called for by the subscript array. (It can also be a scalar, in which case its value will be broadcast.) The result is that elements of the third array are assigned in order to elements of the first whose subscripts are elements of the second.

arr_array_set (vals1, indices, vals2)

is equivalent to the Yorick assignment

vals1 (indices) = vals2

We have generalized this so that the source and target arrays may be two dimensional; the second dimensions must match. Then the array of subscripts is assumed to apply to the first subscript only of the target. The target had better be contiguous.

9.3.3 Sorting an array: index_sort

Calling Sequence

index_sort (x)

Description

index_sort accepts a one-dimensional array x of some numerical type and returns an integer array of the same length whose entries are the subscripts of the elements of the original array arranged in increasing order. We chose to use heap sort because its worst behavior is n*log(n), unlike quicksort, whose worst behavior is n**2.

9.3.4 Interpolating Values: interp

Calling Sequence

interp (x, y, z)

Description

interp (y, x, z) treats (x, y) as a piecewise linear function whose value is y [0] for x < x [0] and y [len (y) - 1] for x > x [len (y) - 1]. An array of floats the same length as z is returned, whose values are ordinates for the corresponding z abscissae interpolated into the piecewise linear function.

9.3.5 Digitizing an array: digitize

Calling Sequence

digitize (x, bins)

Description

bins is a one-dimensional array of integers which is either monotonically increasing or monotonically decreasing. digitize (x, bins) returns an array of python integers the same length as x (if x is a one-dimensional array), or just an integer (if x is a scalar). The values i returned are such that bins [i - 1] <= x < bins [i] if bins is monotonically increasing, or bins [i - 1] > x >= bins [i] if bins is monotonically decreasing. Beyond the bounds of bins, returns either i = 0 or i = len (bins) as appropriate.

9.3.6 Reversing a Two-Dimensional array: reverse

Calling Sequence

reverse (x, n)

Description

reverse (x, n) returns a PyFloat matrix the same size and shape as x, but with the elements along the nth dimension reversed. x must be two-dimensional.

9.3.7 Obtaining an Equally-Spaced Array of Floats: span

Calling Sequence

span (lo, hi, num, d2 = 0)

Description

span (lo, hi, num, d2 = 0) returns an array of num equally spaced PyFloats starting with lo and ending with hi. if d2 is not zero, it will return a two-dimensional array, each of the d2 rows of which is the array of equally spaced numbers.

9.3.8 Effective Length of an Array: nz

Calling Sequence

nz (x)

Description

nz (x): x is an array of unsigned bytes (Python typecode "b"). If x ends with a bunch of zeros, this returns with the index of the first zero element after the last nonzero element. It returns the length of the array if its last element is nonzero. This is essentially the ``effective length'' of the array.

9.3.9 Finding Edges Cut by Isosurfaces: find_mask

Calling Sequence

find_mask (fs, node_edges)

Description

This function is used to calculate a mask of integers whose corresponding entry is 1 precisely if an edge of a cell is cut by an isosurface or plane, i. e., if the function fs is one on one of the two vertices of an edge and zero on the other (fs = 1 represents where some function on the mesh was found to be negative by the calling routine). fs is ntotal by nv, where nv is the number of vertices of a cell (4 for a tetrahedron, 5 for a pyramid, 6 for a prism, 8 for a hexahedron). node_edges is a nv by ne array, where ne is the number of edges on a cell (6 for a tet, 8 for a pyramid, 9 for a prism, 12 for a hexahedron). The entries in each row are 1 precisely if the corresponding edge is incident on the vertex. The exclusive or of the rows which correspond to nonzero entries in fs contains 1 in entries corresponding to edges where fs has opposite values on the vertices. (The vertices and edges of a cell have a standard ordering which is discussed in "Standard ordering for the four types of mesh cells" on page 107.)

The mask returned by this function will be a one dimensional array ntotal * ne long. An entry [i * ne + j] in this mask will be 1 precisely if edge j of cell i is cut by the isosurface or plane.

9.3.10 Order Cut Edges of a cell: construct3

Calling Sequence

construct3 (mask, itype)

Description

Computes how the cut edges of a particular type of cell must be ordered so that the polygon of intersection can be drawn correctly. itype = 0 for tetrahedra; 1 for pyramids; 2 for prisms; 3 for hexahedra. Suppose nv is the number of vertices of the cell type, and ne is the number of edges. mask has been ravelled so that it is flat; originally it had 2**nv-2 rows, each with ne entries. Each row is ne long, and has an entry of 1 corresponding to each edge that is cut when the set of vertices corresponding to the row index has negative values. (The binary number for the row index + 1 has a one in position i if vertex i has a negative value.) The return array permute is ne by 2**nv-2, and the columns of permute tell how the edges should be ordered to draw the polygon properly.

9.3.11 Expand cell-centered values to node-centered values: to_corners

Calling Sequence

to_corners (values, nv, sumnv)

Description

values is a one-dimensional array of floating point values defined on a set of polygons. nv is an integer array of the same size telling how many vertices each of the polygons has. sumnv is the sum of all the values in nv. This routine takes an array of floats describing cell-centered values and returns an array of node-centered values. It is very unsophisticated, merely creating an array of floats sumnv long, whose first nv [0] entries are all values [0], next nv [1] entries are all values [1], etc.



[Top] [Prev] [Next] [Bottom]

support@icf.llnl.gov
Copyright © 1997,Regents of the University of California. All rights reserved.