Closed clorton closed 1 month ago
I fed the whole docstring (from doing a local help) to GPT and asked it to tell me about the class, what it was for, when I would use it, and some simple working example code which exercises a lot of features. It gave me this, which looks good and seems to work to:
import numpy as np
from laser_core.laserframe import LaserFrame
# Step 1: Initialize a LaserFrame with a capacity of 100 agents
laser_frame = LaserFrame(capacity=100)
# Step 2: Add scalar and vector properties
laser_frame.add_scalar_property('age', dtype=np.int32, default=0) # Scalar property 'age'
laser_frame.add_vector_property('position', length=3, dtype=np.float32, default=0.0) # 3D vector 'position'
# Step 3: Add 10 agents
start, end = laser_frame.add(10)
# Step 4: Set some values for the new agents
laser_frame.age[start:end] = np.arange(10, 20) # Set ages from 10 to 19
laser_frame.position[:, start:end] = np.random.random((3, 10)) # Random positions for each agent
# Step 5: Sort agents by age in descending order
indices = np.argsort(laser_frame.age[:10])[::-1] # Sort ages in descending order
laser_frame.sort(indices)
# Step 6: Squash the agents, keeping only those with age greater than 15
mask = laser_frame.age[:10] > 15
laser_frame.squash(mask)
# Step 7: Print the final ages and positions of remaining agents
print("Ages of remaining agents:", laser_frame.age[:laser_frame.count])
print("Positions of remaining agents:", laser_frame.position[:, :laser_frame.count])
This class is the one I've used the most up to this point so feeling pretty good about it, including the name! LGTM.
Renamed
Population
class from 2024 prototyping. Fixes #42 and #38