utils
edge_direction(edge_index, x, return_length=False)
Compute the unit vector (and optionally the length) along each edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
Tensor[2, E]
|
edge connectivity. |
required |
x
|
Tensor[N, D]
|
node coordinates. |
required |
return_length
|
bool
|
if |
False
|
Returns:
| Type | Description |
|---|---|
|
torch.Tensor [E, D] or tuple[torch.Tensor, torch.Tensor]: the |
|
|
normalized direction from source to target node, and, if |
|
|
|
Source code in src/torch_structure/utils.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
effective_stiffness(edge_index, E, A, length)
Compute effective stiffness.
Source code in src/torch_structure/utils.py
91 92 93 94 95 96 | |
scipy_jacobian(func)
Wrap a scalar-valued torch function for use with scipy's gradient-based optimizers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Tensor]
|
differentiable function that takes a 1D torch tensor (plus optional extra args) and returns a scalar loss. |
required |
Returns:
| Type | Description |
|---|---|
|
Callable[[numpy.ndarray, ...], tuple[float, numpy.ndarray]]: a |
|
|
function taking a numpy array (plus the same extra args) that |
|
|
returns the |
|
|
|
|
|
the best loss seen so far in its |
Source code in src/torch_structure/utils.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
transformation_matrix(edge_index, x, length)
Create a 3D tensor containing the transformation matrices for all edges in a 3D truss.
Parameters: - edge_index: Tensor of shape [2, num_edges], containing indices of connected nodes for each edge. - x: Tensor of shape [num_nodes, 3], containing the coordinates (x, y, z) of each node. - length: Tensor of shape [num_edges], containing the length of each edge.
Returns: - matrix: Tensor of shape [num_edges, 2, 6], containing the transformation matrices for all edges.
Source code in src/torch_structure/utils.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |