Skip to content

Commit

Permalink
Remove more np calls
Browse files Browse the repository at this point in the history
  • Loading branch information
hang-yin committed Aug 12, 2024
1 parent 889d4a6 commit d6432bb
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 deletions.
5 changes: 3 additions & 2 deletions docs/tutorials/custom_robot_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ Now that we have the USD file for the robot, let's write our own robot class. Fo
??? code "stretch.py"
``` python linenums="1"
import os
import numpy as np
import math
import torch as th
from omnigibson.macros import gm
from omnigibson.robots.active_camera_robot import ActiveCameraRobot
from omnigibson.robots.manipulation_robot import GraspingPoint, ManipulationRobot
Expand Down Expand Up @@ -157,7 +158,7 @@ Now that we have the USD file for the robot, let's write our own robot class. Fo
def _default_joint_pos(self):
# Define the default joint positions for your robot

return np.array([0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0.0, 0, 0, np.pi / 8, np.pi / 8])
return th.tensor([0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0.0, 0, 0, math.pi / 8, math.pi / 8]. dtype=th.float32)

@property
def wheel_radius(self):
Expand Down
4 changes: 1 addition & 3 deletions omnigibson/prims/geom_prim.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from functools import cached_property

import numpy as np
import torch as th
import trimesh

import omnigibson as og
import omnigibson.lazy as lazy
Expand Down Expand Up @@ -92,7 +90,7 @@ def color(self, rgb):
if self.has_material():
self.material.diffuse_color_constant = rgb
else:
self.set_attribute("primvars:displayColor", np.array(rgb))
self.set_attribute("primvars:displayColor", rgb.cpu().numpy())

@property
def opacity(self):
Expand Down
8 changes: 2 additions & 6 deletions omnigibson/systems/micro_particle_system.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import datetime
import math
import os
import tempfile
import uuid
from collections import defaultdict
from pathlib import Path

import numpy as np
Expand All @@ -18,11 +16,9 @@
from omnigibson.prims.material_prim import MaterialPrim
from omnigibson.prims.prim_base import BasePrim
from omnigibson.systems.system_base import BaseSystem, PhysicalParticleSystem
from omnigibson.utils.geometry_utils import generate_points_in_volume_checker_function
from omnigibson.utils.physx_utils import create_physx_particle_system, create_physx_particleset_pointinstancer
from omnigibson.utils.python_utils import assert_valid_key, torch_delete
from omnigibson.utils.sampling_utils import sample_cuboid_on_object_full_grid_topdown
from omnigibson.utils.ui_utils import create_module_logger, disclaimer
from omnigibson.utils.ui_utils import create_module_logger
from omnigibson.utils.usd_utils import (
PoseAPI,
absolute_prim_path_to_scene_relative,
Expand Down Expand Up @@ -243,7 +239,7 @@ def particle_orientations(self):
th.tensor: (N, 4) numpy array, where each of the N particles' orientations are expressed in (x,y,z,w)
quaternion coordinates relative to this instancer's parent prim
"""
return th.from_numpy(np.array(self.get_attribute(attr="orientations")))
return th.from_numpy(np.array(self.get_attribute(attr="orientations"), dtype=np.float32))

@particle_orientations.setter
def particle_orientations(self, quat):
Expand Down
3 changes: 1 addition & 2 deletions omnigibson/utils/python_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from hashlib import md5
from importlib import import_module

import numpy as np
import torch as th

# Global dictionary storing all unique names
Expand Down Expand Up @@ -293,7 +292,7 @@ def get_uuid(name, n_digits=8, deterministic=True):
"""
# Make sure the number is float32 compatible
val = int(md5(name.encode()).hexdigest(), 16) if deterministic else abs(hash(name))
return int(np.float32(val % (10**n_digits)))
return int(th.tensor(val % (10**n_digits), dtype=th.float32).item())


def meets_minimum_version(test_version, minimum_version):
Expand Down
6 changes: 1 addition & 5 deletions omnigibson/utils/sampling_utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import itertools
import math
import random
import time
from collections import Counter, defaultdict

import numpy as np
import torch as th
import trimesh
from scipy.stats import truncnorm

import omnigibson as og
import omnigibson.lazy as lazy
import omnigibson.utils.transform_utils as T
from omnigibson.macros import create_module_macros, gm
from omnigibson.macros import create_module_macros
from omnigibson.utils.ui_utils import create_module_logger, draw_line

# Create module logger
Expand Down

0 comments on commit d6432bb

Please sign in to comment.