src.acoustools.Utilities.Points
1from torch import Tensor 2import torch 3 4from acoustools.Utilities.Setup import device, DTYPE 5 6def create_points(N:int=None,B:int=1,x:float|None=None,y:float|None=None,z:float|None=None, min_pos:float=-0.06, max_pos:float = 0.06) -> Tensor: 7 ''' 8 Creates a random set of N points in B batches in shape `Bx3xN` \n 9 :param N: Number of points per batch 10 :param B: Number of Batches 11 :param x: if not None all points will have this as their x position. Default: `None` 12 :param y: if not None all points will have this as their y position. Default: `None` 13 :param z: if not None all points will have this as their z position. Default: `None` 14 :param min_pos: Minimum position 15 :param max_pos: Maximum position 16 ``` 17 from acoustools.Utilities import create_points 18 p = create_points(N=3,B=1) 19 ``` 20 ''' 21 22 its = [list, tuple] 23 24 if N is None: 25 if (type(x) in its and type(y) in its and type(z) in its ): 26 N = len(x) 27 elif (type(x) == float and type(y) == float and type(z) == float) or (type(x) == int and type(y) == int and type(z) == int): 28 N = 1 29 else: 30 raise ValueError("If N is not provided x,y and z need to be lists of points or single values") 31 32 points = torch.zeros((B, 3, N), device=device) 33 34 if x is not None: 35 if type(x) in its: 36 for i in range(N): 37 points[:,0,i] = x[i] 38 else: 39 points[:,0,:] = x 40 else: 41 points[:,0,:].uniform_(min_pos, max_pos) 42 43 if y is not None: 44 if type(y) in its: 45 for i in range(N): 46 points[:,1,i] = y[i] 47 else: 48 points[:,1,:] = y 49 else: 50 points[:,1,:].uniform_(min_pos, max_pos) 51 52 if z is not None: 53 if type(z) in its: 54 for i in range(N): 55 points[:,2,i] = z[i] 56 else: 57 points[:,2,:] = z 58 else: 59 points[:,2,:].uniform_(min_pos, max_pos) 60 61 62 return points.to(DTYPE)
def
create_points( N: int = None, B: int = 1, x: float | None = None, y: float | None = None, z: float | None = None, min_pos: float = -0.06, max_pos: float = 0.06) -> torch.Tensor:
7def create_points(N:int=None,B:int=1,x:float|None=None,y:float|None=None,z:float|None=None, min_pos:float=-0.06, max_pos:float = 0.06) -> Tensor: 8 ''' 9 Creates a random set of N points in B batches in shape `Bx3xN` \n 10 :param N: Number of points per batch 11 :param B: Number of Batches 12 :param x: if not None all points will have this as their x position. Default: `None` 13 :param y: if not None all points will have this as their y position. Default: `None` 14 :param z: if not None all points will have this as their z position. Default: `None` 15 :param min_pos: Minimum position 16 :param max_pos: Maximum position 17 ``` 18 from acoustools.Utilities import create_points 19 p = create_points(N=3,B=1) 20 ``` 21 ''' 22 23 its = [list, tuple] 24 25 if N is None: 26 if (type(x) in its and type(y) in its and type(z) in its ): 27 N = len(x) 28 elif (type(x) == float and type(y) == float and type(z) == float) or (type(x) == int and type(y) == int and type(z) == int): 29 N = 1 30 else: 31 raise ValueError("If N is not provided x,y and z need to be lists of points or single values") 32 33 points = torch.zeros((B, 3, N), device=device) 34 35 if x is not None: 36 if type(x) in its: 37 for i in range(N): 38 points[:,0,i] = x[i] 39 else: 40 points[:,0,:] = x 41 else: 42 points[:,0,:].uniform_(min_pos, max_pos) 43 44 if y is not None: 45 if type(y) in its: 46 for i in range(N): 47 points[:,1,i] = y[i] 48 else: 49 points[:,1,:] = y 50 else: 51 points[:,1,:].uniform_(min_pos, max_pos) 52 53 if z is not None: 54 if type(z) in its: 55 for i in range(N): 56 points[:,2,i] = z[i] 57 else: 58 points[:,2,:] = z 59 else: 60 points[:,2,:].uniform_(min_pos, max_pos) 61 62 63 return points.to(DTYPE)
Creates a random set of N points in B batches in shape Bx3xN
Parameters
- N: Number of points per batch
- B: Number of Batches
- x: if not None all points will have this as their x position. Default:
None - y: if not None all points will have this as their y position. Default:
None - z: if not None all points will have this as their z position. Default:
None - min_pos: Minimum position
- max_pos: Maximum position
from acoustools.Utilities import create_points
p = create_points(N=3,B=1)