util module¶
-
class
util.
HiddenPrints
[source]¶ Bases:
object
This is a class that can be used to suppress stdout from function calls.
- Usage:
- with HiddenPrints():
>>do stuff without printing
-
util.
address_from_index
(level, index)[source]¶ Computes address vector from the index.
- Returns the address vector of a point with certain TLR index in
a graph of SG at some fixed level.
For point F_{w1} F_{w2} … F_{wm} q_{k} (0<=wi<=2, 0<=k<=2), we can represent it in two ways: 1. Address Vector: [wm, …, w1, k] (Note that this represents
picking transform F_{wm}, …, F_{w1} in this sequence and then finding vertex q_{k} in the final triangle. This order is weird but will prove to be useful)
TLR Index: k = wm * 3^m + … + w1 * 3 + k + 1
This function provides transform 2 -> 1.
- Parameters
level – A nonnegative integer representing the level of SG we’re working with.
index – A number in the range [1, 3^(level+1)] representing the TLR index of some point in level m.
- Returns
- np.array of length (level+1) representing the address
of the point specified by index in a particular level of SG.
- Return type
address
Example
address_from_index(1, 4) = [1, 0] address_from_index(2, 21) = [2, 1, 2]
-
util.
alternate_address
(level, address)[source]¶ Computes the alternate address of a point.
- Parameters
level – A nonnegative integer representing the level of SG we’re working with.
address – np.array of size (level+1) representing the address vector of a point in some SG graph.
- Returns
- np.array of size (level+1) representing the
alternate address of the same point in some SG graph.
- Return type
alt_address
Example
alternate_address(2, [0, 1, 2]) = [0, 2, 1] (F1F0q2 = F2F0q1) alternate_address(2, [1, 0, 0]) = [0, 1, 1] (F0F1q1 = F1F1q0)
-
util.
alternate_index
(level, index)[source]¶ Compute the alternate TLR index of a point
- Parameters
level – A nonnegative integer representing the level of SG we’re working with.
index – A number in the range [1, 3^(level+1)] representing the TLR index of some point in level m.
- Returns
- A number in the range [1, 3^(level+1)] representing
the alternate TLR index of the point in level m.
- Return type
alt_index
Example
alternate_index(1, 2) = 4 alternate_index(1, 3) = 7
-
util.
bmatrix
(a)[source]¶ Converts np.array into a LaTeX bmatrix :param a: numpy array
- Returns
LaTeX bmatrix of a as a string
-
util.
coeff_monomial_1_all
(level, max_order)[source]¶ Calculate the value of monomial P_{j1} up to some level
- Parameters
level – A nonnegative integer representing the highest level of SG we would like to calculate the monomial.
max_order – Maximal order of monomial P_{j3} that we would like to calculate
- Returns
- np.array + size (3^{(level+1)} * (max_order + 1)
First coordinate denote the TLR index, the second coordinate denote order of polynomial.
- Return type
monomial_mat_1
-
util.
coeff_monomial_3_all
(level, max_order)[source]¶ Calculate the value of monomial P_{j3} up to some level
- Parameters
level – A nonnegative integer representing the highest level of SG we would like to calculate the monomial.
max_order – Maximal order of monomial P_{j3} that we would like to calculate
- Returns
- np.array + size (3^{(level+1)} * (max_order + 1)
First coordinate denote the TLR index, the second coordinate denote order of polynomial.
- Return type
monomial_mat_3
-
util.
get_neighbors
(level, address)[source]¶ Compute the addresses of the 4 neighbors of a point
- Parameters
level – A nonnegative integer representing the level of SG we’re working with.
address – np.array of size (level+1) representing the address vector of a point in some SG graph.
- Returns
- np.array of size (4, level+1) representing the
address of the 4 neighbors of the point.
- Return type
nbhd_mat
-
util.
index_alternate_level
(current_level, target_level, address)[source]¶ Finds the index of a point in another level of SG
- Parameters
current_level – A nonnegative integer representing the current level of SG we’re working with.
target_level – A nonnegative integer representing the target level of SG we’re moving our point to. This should be larger than the current level.
address – np.array of size (current_level+1) representing the address vector of a point in some SG graph.
- Returns
- A number in the range [1, 3^(target_level+1)]
representing the TLR index of the point in target_level.
- Return type
target_index
Example
index_alternate_level(1, 1, [0, 1]) = 2 index_alternate_level(1, 2, [0, 1]) = 5 index_alternate_level(1, 3, [0, 1]) = 14
-
util.
index_from_address
(level, address)[source]¶ Computes TLR Index from Address vector.
- Returns the TLR index of a point with certain address vector in
a graph of SG at some fixed level.
- For point F_{w1} F_{w2} … F_{wm} q_{k} (0<=wi<=2, 0<=k<=2), we
can represent it in two ways:
- Address Vector: [wm, …, w1, k] (Note that this represents
picking transform F_{wm}, …, F_{w1} in this sequence and then finding vertex q_{l} in the final triangle)
TLR Index: k = wm * 3^m + … + w1 * 3 + k + 1
This function provides transform 1 -> 2.
- Parameters
level – A nonnegative integer representing the level of SG we’re working with.
address – np.array of size (level+1) representing the address vector of a point in some SG graph.
- Returns
- A number in the range [1, 3^(level+1)] representing the
TLR index of some point in level m.
- Return type
index
-
util.
q_contract
(orig_mat, base_point)[source]¶ Computes the image of points under some contraction.
- Contracts all points represented in rows of v toward the base_point
with a contraction ratio of 1/2.
- Parameters
orig_mat – A np.array of size (t, 2) for some integer t, with each row representing the coordinate of a point
base_point – A np.array of length 2 representing the coordinates of the point we’re contracting toward.
- Returns
- A np.array of size (t, 2) for some integer t, with
each row the contracted version of that in orig_mat.
- Return type
contract_mat
-
util.
rotate_address
(level, address, rotate_num)[source]¶ Rotates the address with respect to rotational symmetries of SG
- Parameters
level – A nonnegative integer representing the level of SG we’re working with.
address – np.array of size (level+1) representing the address vector of a point in some SG graph.
rotate_num – A number in {0, 1, 2} representing the type of rotation we’re making. 0 represent no rotation, 1 represent counterclockwise 2*np.pi/3, 2 represent counterclockwise 4*np.pi/3.
- Returns
- np.array of size (level+1) representing the address
vector of the rotated point in some SG graph.
- Return type
new_address
-
util.
sg_coordinates
(level)[source]¶ Computes the coordinates of points for SG at some level.
- Given base points q0 = [cos(5*pi/12) sin(5*pi/12)], q1=[0 0],
q2=[cos(pi/12) sin(pi/12)], we calculate the coordinates of all points up to some level of the SG graph.
- Parameters
level – A nonnegative integer representing the level of SG we’re working with.
- Returns
- A matrix with dimension (3^(level+1), 2), with each
row representing coordinate of one point in V_m
- Return type
coord_mat
-
util.
sg_edge_index
(level, ind1, ind2)[source]¶ Calculates an array of indices on a given edge
- Parameters
level – A nonnegative integer representing the level of SG we’re working with.
ind1 – a number representing the index of the first boundary point (1, 2, or 3)
ind2 – a number representing the index of the second boundary point (1, 2, or 3, should be larger than ind1)
- Returns
- np.array of length 2^(m+1), representing array of
indices on the edge (each point is counted twice except for the two boundary points.)
- Return type
index_arr
Example
sg_edge_index(2, 0, 2) = [1, 3, 7, 9, 19, 21, 25, 27]