robotic 0.2.9.dev1__cp311-cp311-manylinux2014_x86_64.whl → 0.3.4.dev5__cp311-cp311-manylinux2014_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robotic/DataGen.pyi +11 -1
- robotic/__init__.py +8 -1
- robotic/_robotic.pyi +228 -110
- robotic/_robotic.so +0 -0
- robotic/algo.pyi +17 -0
- robotic/include/rai/{Geo → Algo}/Lewiner/MarchingCubes.h +0 -29
- robotic/include/rai/Algo/SplineCtrlFeed.h +1 -1
- robotic/include/rai/Algo/marching_cubes.h +9 -0
- robotic/include/rai/Algo/rungeKutta.h +2 -2
- robotic/include/rai/Algo/spline.h +4 -8
- robotic/include/rai/Algo/trilinear.h +10 -0
- robotic/include/rai/Control/CtrlSolver.h +1 -1
- robotic/include/rai/Control/TimingMPC.h +2 -2
- robotic/include/rai/Core/array.h +99 -64
- robotic/include/rai/Core/array.ipp +290 -139
- robotic/include/rai/Core/arrayDouble.h +36 -26
- robotic/include/rai/Core/defines.h +7 -9
- robotic/include/rai/Core/graph.h +27 -23
- robotic/include/rai/Core/h5.h +3 -1
- robotic/include/rai/Core/thread.h +12 -12
- robotic/include/rai/Core/util.h +58 -79
- robotic/include/rai/DataGen/rndStableConfigs.h +1 -0
- robotic/include/rai/DataGen/shapenetGrasps.h +5 -3
- robotic/include/rai/Geo/depth2PointCloud.h +2 -0
- robotic/include/rai/Geo/geo.h +23 -15
- robotic/include/rai/Geo/{fclInterface.h → i_fcl.h} +3 -1
- robotic/include/rai/Geo/mesh.h +18 -13
- robotic/include/rai/Geo/pairCollision.h +43 -43
- robotic/include/rai/Geo/signedDistanceFunctions.h +7 -5
- robotic/include/rai/Geo/stb_image.h +1 -1
- robotic/include/rai/Gui/RenderData.h +9 -7
- robotic/include/rai/Gui/opengl.h +6 -6
- robotic/include/rai/Gui/plot.h +1 -1
- robotic/include/rai/KOMO/komo.h +6 -3
- robotic/include/rai/KOMO/komo_NLP.h +2 -2
- robotic/include/rai/KOMO/manipTools.h +7 -2
- robotic/include/rai/KOMO/testProblems_KOMO.h +5 -9
- robotic/include/rai/Kin/F_forces.h +3 -3
- robotic/include/rai/Kin/cameraview.h +24 -36
- robotic/include/rai/Kin/dof_forceExchange.h +7 -7
- robotic/include/rai/Kin/feature.h +1 -1
- robotic/include/rai/Kin/frame.h +22 -24
- robotic/include/rai/Kin/{kin_physx.h → i_Physx.h} +10 -8
- robotic/include/rai/Kin/kin.h +29 -21
- robotic/include/rai/Kin/proxy.h +1 -1
- robotic/include/rai/Kin/simulation.h +20 -10
- robotic/include/rai/Kin/viewer.h +14 -1
- robotic/include/rai/LGP/LGP_TAMP_Abstraction.h +33 -0
- robotic/include/rai/LGP/LGP_Tool.h +4 -25
- robotic/include/rai/LGP/LGP_computers.h +1 -1
- robotic/include/rai/LGP/LGP_computers2.h +196 -0
- robotic/include/rai/LGP/NLP_Descriptor.h +5 -0
- robotic/include/rai/Logic/folWorld.h +1 -1
- robotic/include/rai/Logic/treeSearchDomain.h +2 -2
- robotic/include/rai/Optim/BayesOpt.h +13 -6
- robotic/include/rai/Optim/CMA/boundary_transformation.h +73 -0
- robotic/include/rai/Optim/CMA/cmaes.h +175 -0
- robotic/include/rai/Optim/CMA/cmaes_interface.h +68 -0
- robotic/include/rai/Optim/GlobalIterativeNewton.h +7 -3
- robotic/include/rai/Optim/NLP.h +23 -7
- robotic/include/rai/Optim/NLP_GraphSolver.h +1 -1
- robotic/include/rai/Optim/NLP_Solver.h +5 -5
- robotic/include/rai/Optim/constrained.h +4 -4
- robotic/include/rai/Optim/{opt-ceres.h → i_Ceres.h} +2 -2
- robotic/include/rai/Optim/{opt-nlopt.h → i_NLopt.h} +4 -0
- robotic/include/rai/Optim/lagrangian.h +7 -5
- robotic/include/rai/Optim/liblbfgs/liblbfgs.h +755 -0
- robotic/include/rai/Optim/m_EvoStrategies.h +114 -0
- robotic/include/rai/Optim/{gradient.h → m_Gradient.h} +13 -12
- robotic/include/rai/Optim/m_LBFGS.h +21 -0
- robotic/include/rai/Optim/m_LeastSquaresZeroOrder.h +104 -0
- robotic/include/rai/Optim/m_LocalGreedy.h +31 -0
- robotic/include/rai/Optim/m_NelderMead.h +23 -0
- robotic/include/rai/Optim/{newton.h → m_Newton.h} +7 -4
- robotic/include/rai/Optim/{SlackGaussNewton.h → m_SlackGaussNewton.h} +0 -10
- robotic/include/rai/Optim/options.h +8 -7
- robotic/include/rai/Optim/primalDual.h +10 -6
- robotic/include/rai/Optim/testProblems_Opt.h +25 -19
- robotic/include/rai/Optim/utils.h +16 -85
- robotic/include/rai/PathAlgos/ConfigurationProblem.h +3 -2
- robotic/include/rai/PathAlgos/RRT_PathFinder.h +2 -2
- robotic/include/rai/Perception/pcl.h +10 -10
- robotic/include/rai/Perception/surfels.h +1 -1
- robotic/include/rai/Search/TreeSearchNode.h +1 -1
- robotic/include/rai/ry/py-algo.h +17 -0
- robotic/include/rai/ry/types.h +4 -2
- robotic/librai.so +0 -0
- robotic/manipulation.py +5 -7
- robotic/meshTool +0 -0
- robotic/mujoco-import.py +8 -0
- robotic/rai-robotModels/g1/g1.g +11 -2
- robotic/rai-robotModels/g1/g1_29dof_conv.yml +64 -0
- robotic/rai-robotModels/g1/g1_clean.g +38 -73
- robotic/rai-robotModels/g1/meshes/head_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_ankle_pitch_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_ankle_roll_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_elbow_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_hip_pitch_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_hip_roll_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_hip_yaw_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_knee_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_rubber_hand.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_shoulder_pitch_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_shoulder_roll_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_shoulder_yaw_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_wrist_pitch_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_wrist_roll_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/left_wrist_yaw_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/logo_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/pelvis.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/pelvis_contour_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_ankle_pitch_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_ankle_roll_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_elbow_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_hip_pitch_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_hip_roll_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_hip_yaw_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_knee_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_rubber_hand.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_shoulder_pitch_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_shoulder_roll_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_shoulder_yaw_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_wrist_pitch_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_wrist_roll_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/right_wrist_yaw_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/torso_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/waist_roll_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/waist_support_link.h5 +0 -0
- robotic/rai-robotModels/g1/meshes/waist_yaw_link.h5 +0 -0
- robotic/rai-robotModels/objects/shelf.g +1 -1
- robotic/rai-robotModels/panda/meshes/finger.h5 +0 -0
- robotic/rai-robotModels/panda/meshes/hand.h5 +0 -0
- robotic/rai-robotModels/panda/meshes/link0.h5 +0 -0
- robotic/rai-robotModels/panda/meshes/link1.h5 +0 -0
- robotic/rai-robotModels/panda/meshes/link2.h5 +0 -0
- robotic/rai-robotModels/panda/meshes/link3.h5 +0 -0
- robotic/rai-robotModels/panda/meshes/link4.h5 +0 -0
- robotic/rai-robotModels/panda/meshes/link5.h5 +0 -0
- robotic/rai-robotModels/panda/meshes/link6.h5 +0 -0
- robotic/rai-robotModels/panda/meshes/link7.h5 +0 -0
- robotic/rai-robotModels/panda/panda.g +10 -10
- robotic/rai-robotModels/panda/panda_arm_hand_conv.g +24 -0
- robotic/rai-robotModels/panda/panda_arm_hand_conv.yml +24 -0
- robotic/rai-robotModels/panda/panda_clean.g +21 -45
- robotic/rai-robotModels/panda/panda_gripper.g +5 -7
- robotic/rai-robotModels/panda/panda_withoutCollisionModels.g +3 -11
- robotic/rai-robotModels/pr2/meshes/base.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/base_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/caster.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/elbow_flex.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/elbow_flex_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/forearm.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/forearm_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/forearm_roll.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/gripper_palm.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/gripper_palm_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/head_pan.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/head_pan_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/head_tilt.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/head_tilt_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/l_finger.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/l_finger_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/l_finger_tip.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/l_finger_tip_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/shoulder_lift.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/shoulder_lift_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/shoulder_pan.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/shoulder_pan_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/tilting_hokuyo.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/tilting_hokuyo_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/torso_lift.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/torso_lift_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/upper_arm.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/upper_arm_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/upper_arm_roll.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/upper_arm_roll_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/wheel.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/wheel_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/wrist_color.png +0 -0
- robotic/rai-robotModels/pr2/meshes/wrist_flex.h5 +0 -0
- robotic/rai-robotModels/pr2/meshes/wrist_roll.h5 +0 -0
- robotic/rai-robotModels/pr2/pr2.g +12 -12
- robotic/rai-robotModels/pr2/pr2_clean.g +122 -118
- robotic/rai-robotModels/pr2/pr2_conv.g +218 -0
- robotic/rai-robotModels/pr2/pr2_modifications.g +2 -2
- robotic/rai-robotModels/ranger/meshes/ranger_mini3.h5 +0 -0
- robotic/rai-robotModels/ranger/meshes/ranger_mini_v3_wheel.h5 +0 -0
- robotic/rai-robotModels/ranger/meshes/ranger_mini_v3_wheel_right.h5 +0 -0
- robotic/rai-robotModels/ranger/ranger.g +8 -8
- robotic/rai-robotModels/ranger/ranger_clean.g +5 -5
- robotic/rai-robotModels/ranger/ranger_mini_conv.g +14 -0
- robotic/rai-robotModels/robotiq/meshes/robotiq_arg2f_85_base_link.h5 +0 -0
- robotic/rai-robotModels/robotiq/meshes/robotiq_arg2f_85_inner_finger.h5 +0 -0
- robotic/rai-robotModels/robotiq/meshes/robotiq_arg2f_85_inner_knuckle.h5 +0 -0
- robotic/rai-robotModels/robotiq/meshes/robotiq_arg2f_85_outer_finger.h5 +0 -0
- robotic/rai-robotModels/robotiq/meshes/robotiq_arg2f_85_outer_knuckle.h5 +0 -0
- robotic/rai-robotModels/robotiq/robotiq.g +2 -2
- robotic/rai-robotModels/robotiq/robotiq_arg2f_85_model_conv.yml +19 -0
- robotic/rai-robotModels/robotiq/robotiq_clean.g +16 -16
- robotic/rai-robotModels/scenarios/ballFinger.g +2 -2
- robotic/rai-robotModels/scenarios/liftRing.g +2 -2
- robotic/rai-robotModels/scenarios/pandaFloatingGripper.g +1 -1
- robotic/rai-robotModels/scenarios/pandaSingle.g +1 -1
- robotic/rai-robotModels/scenarios/panda_fixRobotiq.g +3 -3
- robotic/rai-robotModels/tests/arm.g +18 -19
- robotic/rai-robotModels/tests/compound.g +3 -6
- robotic/rai-robotModels/ur10/meshes/base.h5 +0 -0
- robotic/rai-robotModels/ur10/meshes/forearm.h5 +0 -0
- robotic/rai-robotModels/ur10/meshes/shoulder.h5 +0 -0
- robotic/rai-robotModels/ur10/meshes/upperarm.h5 +0 -0
- robotic/rai-robotModels/ur10/meshes/wrist1.h5 +0 -0
- robotic/rai-robotModels/ur10/meshes/wrist2.h5 +0 -0
- robotic/rai-robotModels/ur10/meshes/wrist3.h5 +0 -0
- robotic/rai-robotModels/ur10/ur10.g +2 -2
- robotic/rai-robotModels/ur10/ur10_clean.g +8 -8
- robotic/rai-robotModels/ur10/ur10_conv.g +17 -0
- robotic/ry-h5info +3 -12
- robotic/ry-test +5 -4
- robotic/ry-urdfConvert.py +74 -0
- robotic/ry-view +28 -6
- robotic/src/cleanMeshes.py +59 -0
- robotic/src/h5_helper.py +46 -0
- robotic/src/h5_helper.py~ +42 -0
- robotic/src/mesh_helper.py +395 -0
- robotic/{rai-robotModels/ranger/meshes/cleanMeshes.mlx → src/meshlabFilters.mlx} +0 -3
- robotic/src/mujoco_io.py +242 -0
- robotic/src/urdf_io.py +237 -0
- robotic/src/yaml_helper.py +29 -0
- robotic/version.py +1 -1
- robotic-0.3.4.dev5.data/scripts/ry-h5info +23 -0
- {robotic-0.2.9.dev1.data → robotic-0.3.4.dev5.data}/scripts/ry-test +5 -4
- robotic-0.3.4.dev5.data/scripts/ry-urdfConvert.py +74 -0
- robotic-0.3.4.dev5.data/scripts/ry-view +46 -0
- {robotic-0.2.9.dev1.dist-info → robotic-0.3.4.dev5.dist-info}/METADATA +18 -22
- robotic-0.3.4.dev5.dist-info/RECORD +386 -0
- {robotic-0.2.9.dev1.dist-info → robotic-0.3.4.dev5.dist-info}/WHEEL +1 -1
- robotic/nlp.py +0 -113
- robotic/rai-robotModels/baxter/baxter.g +0 -49
- robotic/rai-robotModels/baxter/baxter_clean.g +0 -116
- robotic/rai-robotModels/baxter/baxter_clean2.g +0 -205
- robotic/rai-robotModels/baxter/baxter_clean3.g +0 -223
- robotic/rai-robotModels/baxter/baxter_description/meshes/base/PEDESTAL.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_description/meshes/base/pedestal_link_collision.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_description/meshes/head/H0.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_description/meshes/head/H1.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_description/meshes/lower_elbow/E1.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_description/meshes/lower_forearm/W1.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_description/meshes/lower_shoulder/S1.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_description/meshes/torso/base_link.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_description/meshes/torso/base_link_collision.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_description/meshes/upper_elbow/E0.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_description/meshes/upper_forearm/W0.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_description/meshes/upper_shoulder/S0.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_description/meshes/wrist/W2.ply +0 -0
- robotic/rai-robotModels/baxter/baxter_new.g +0 -53
- robotic/rai-robotModels/baxter/rethink_ee_description/meshes/electric_gripper/electric_gripper_base.ply +0 -0
- robotic/rai-robotModels/baxter/rethink_ee_description/meshes/electric_gripper/fingers/extended_narrow.ply +0 -0
- robotic/rai-robotModels/baxter/rethink_ee_description/meshes/electric_gripper/fingers/half_round_tip.ply +0 -0
- robotic/rai-robotModels/baxter/rethink_ee_description/meshes/electric_gripper/fingers/paddle_tip.ply +0 -0
- robotic/rai-robotModels/baxter/rethink_ee_description/meshes/pneumatic_gripper/pneumatic_gripper_base.ply +0 -0
- robotic/rai-robotModels/baxter/rethink_ee_description/meshes/pneumatic_gripper/pneumatic_gripper_w_cup.ply +0 -0
- robotic/rai-robotModels/g1/meshes/head_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_ankle_pitch_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_ankle_roll_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_elbow_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_hand_index_0_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_hand_index_1_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_hand_middle_0_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_hand_middle_1_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_hand_palm_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_hand_thumb_0_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_hand_thumb_1_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_hand_thumb_2_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_hip_pitch_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_hip_roll_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_hip_yaw_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_knee_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_rubber_hand.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_shoulder_pitch_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_shoulder_roll_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_shoulder_yaw_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_wrist_pitch_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_wrist_roll_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_wrist_roll_rubber_hand.ply +0 -0
- robotic/rai-robotModels/g1/meshes/left_wrist_yaw_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/logo_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/pelvis.ply +0 -0
- robotic/rai-robotModels/g1/meshes/pelvis_contour_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_ankle_pitch_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_ankle_roll_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_elbow_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_hand_index_0_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_hand_index_1_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_hand_middle_0_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_hand_middle_1_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_hand_palm_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_hand_thumb_0_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_hand_thumb_1_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_hand_thumb_2_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_hip_pitch_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_hip_roll_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_hip_yaw_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_knee_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_rubber_hand.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_shoulder_pitch_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_shoulder_roll_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_shoulder_yaw_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_wrist_pitch_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_wrist_roll_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_wrist_roll_rubber_hand.ply +0 -0
- robotic/rai-robotModels/g1/meshes/right_wrist_yaw_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/torso_constraint_L_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/torso_constraint_L_rod_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/torso_constraint_R_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/torso_constraint_R_rod_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/torso_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/waist_constraint_L.ply +0 -0
- robotic/rai-robotModels/g1/meshes/waist_constraint_R.ply +0 -0
- robotic/rai-robotModels/g1/meshes/waist_roll_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/waist_support_link.ply +0 -0
- robotic/rai-robotModels/g1/meshes/waist_yaw_link.ply +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/collision/finger.stl +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/collision/hand.stl +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/collision/link0.stl +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/collision/link1.stl +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/collision/link2.stl +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/collision/link3.stl +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/collision/link4.stl +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/collision/link5.stl +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/collision/link6.stl +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/collision/link7.stl +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/visual/HOWTO.sh +0 -10
- robotic/rai-robotModels/panda/franka_description/meshes/visual/HOWTO2.sh +0 -7
- robotic/rai-robotModels/panda/franka_description/meshes/visual/convMeshes.mlx +0 -38
- robotic/rai-robotModels/panda/franka_description/meshes/visual/finger.ply +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/visual/hand.ply +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/visual/link0.ply +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/visual/link1.ply +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/visual/link2.ply +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/visual/link3.ply +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/visual/link4.ply +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/visual/link5.ply +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/visual/link6.ply +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/visual/link7.ply +0 -0
- robotic/rai-robotModels/panda/franka_description/meshes/visual/script.mlx +0 -28
- robotic/rai-robotModels/pr2/pr2_description/meshes/base_v0/base.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/base_v0/base_L.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/base_v0/caster.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/base_v0/caster_L.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/base_v0/pr2_wheel.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/base_v0/wheel.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/forearm_v0/forearm.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/forearm_v0/wrist_flex.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/forearm_v0/wrist_roll.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/forearm_v0/wrist_roll_L.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/gripper_v0/gripper_palm.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/gripper_v0/l_finger.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/gripper_v0/l_finger_tip.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/head_v0/head_pan.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/head_v0/head_pan_L.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/head_v0/head_tilt.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/head_v0/head_tilt_L.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/shoulder_v0/shoulder_lift.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/shoulder_v0/shoulder_pan.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/shoulder_v0/shoulder_yaw.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/shoulder_v0/upper_arm_roll.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/shoulder_v0/upper_arm_roll_L.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/tilting_laser_v0/hok_tilt.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/tilting_laser_v0/tilting_hokuyo.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/tilting_laser_v0/tilting_hokuyo_L.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/torso_v0/torso.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/torso_v0/torso_lift.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/torso_v0/torso_lift_L.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/upper_arm_v0/elbow_flex.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/upper_arm_v0/forearm_roll.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/upper_arm_v0/forearm_roll_L.ply +0 -0
- robotic/rai-robotModels/pr2/pr2_description/meshes/upper_arm_v0/upper_arm.ply +0 -0
- robotic/rai-robotModels/ranger/meshes/cleanMeshes.sh +0 -8
- robotic/rai-robotModels/ranger/meshes/ranger_mini3.ply +0 -0
- robotic/rai-robotModels/ranger/meshes/ranger_mini_v3_wheel.ply +0 -0
- robotic/rai-robotModels/ranger/meshes/ranger_mini_v3_wheel_right.ply +0 -0
- robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_base_link.ply +0 -0
- robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_base_link_x.ply +0 -10
- robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_inner_finger.ply +0 -0
- robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_inner_knuckle.ply +0 -0
- robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_outer_finger.ply +0 -0
- robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_outer_knuckle.ply +0 -0
- robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_pad.ply +0 -0
- robotic/rai-robotModels/robotiq/meshes/visual/robotiq_gripper_coupling.ply +0 -0
- robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/Base.ply +0 -0
- robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/Forearm.ply +0 -0
- robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/Shoulder.ply +0 -0
- robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/UpperArm.ply +0 -0
- robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/Wrist1.ply +0 -0
- robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/Wrist2.ply +0 -0
- robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/Wrist3.ply +0 -0
- robotic/ry-urdf2rai +0 -222
- robotic/ry-urdf2yaml +0 -250
- robotic-0.2.9.dev1.data/scripts/ry-h5info +0 -32
- robotic-0.2.9.dev1.data/scripts/ry-urdf2rai +0 -222
- robotic-0.2.9.dev1.data/scripts/ry-urdf2yaml +0 -250
- robotic-0.2.9.dev1.data/scripts/ry-view +0 -24
- robotic-0.2.9.dev1.dist-info/RECORD +0 -421
- /robotic/include/rai/{Geo → Algo}/Lewiner/LookUpTable.h +0 -0
- /robotic/include/rai/Geo/{assimpInterface.h → i_assimp.h} +0 -0
- /robotic/include/rai/Kin/{kin_bullet.h → i_Bullet.h} +0 -0
- /robotic/include/rai/Kin/{kin_feather.h → i_Feather.h} +0 -0
- /robotic/include/rai/Kin/{kin_ode.h → i_Ode.h} +0 -0
- /robotic/include/rai/Optim/{opt-ipopt.h → i_Ipopt.h} +0 -0
- /robotic/rai-robotModels/robotiq/meshes/{visual/robotiq_ft300.ply → robotiq_ft300.ply} +0 -0
- /robotic/{import.py → src/__init__.py} +0 -0
- {robotic-0.2.9.dev1.data → robotic-0.3.4.dev5.data}/scripts/ry-bot +0 -0
- {robotic-0.2.9.dev1.data → robotic-0.3.4.dev5.data}/scripts/ry-info +0 -0
- {robotic-0.2.9.dev1.data → robotic-0.3.4.dev5.data}/scripts/ry-meshTool +0 -0
- {robotic-0.2.9.dev1.dist-info → robotic-0.3.4.dev5.dist-info}/licenses/LICENSE +0 -0
- {robotic-0.2.9.dev1.dist-info → robotic-0.3.4.dev5.dist-info}/top_level.txt +0 -0
|
@@ -11,14 +11,13 @@
|
|
|
11
11
|
#include "array.h"
|
|
12
12
|
|
|
13
13
|
#include <algorithm>
|
|
14
|
+
#include <type_traits>
|
|
14
15
|
|
|
15
16
|
#define ARRAY_flexiMem true
|
|
16
17
|
|
|
17
18
|
namespace rai {
|
|
18
19
|
|
|
19
20
|
//fwd declarations
|
|
20
|
-
extern int64_t globalMemoryTotal, globalMemoryBound;
|
|
21
|
-
extern bool globalMemoryStrict;
|
|
22
21
|
|
|
23
22
|
extern uint lineCount;
|
|
24
23
|
char skip(std::istream& is, const char* skipSymbols, const char* stopSymbols, bool skipCommentLines);
|
|
@@ -42,7 +41,7 @@ template<class T> Array<T>::Array()
|
|
|
42
41
|
N(0),
|
|
43
42
|
nd(0),
|
|
44
43
|
d0(0), d1(0), d2(0),
|
|
45
|
-
|
|
44
|
+
_shape(&d0),
|
|
46
45
|
isReference(false),
|
|
47
46
|
M(0),
|
|
48
47
|
special(0) {
|
|
@@ -73,14 +72,18 @@ template<class T> Array<T>::Array(Array<T>&& a)
|
|
|
73
72
|
N(a.N),
|
|
74
73
|
nd(a.nd),
|
|
75
74
|
d0(a.d0), d1(a.d1), d2(a.d2),
|
|
76
|
-
|
|
75
|
+
_shape(&d0),
|
|
77
76
|
isReference(a.isReference),
|
|
78
77
|
M(a.M),
|
|
79
78
|
special(a.special) {
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
if constexpr(std::is_same_v<T, double>){
|
|
80
|
+
if(a.jac) jac = std::move(a.jac);
|
|
81
|
+
}
|
|
82
|
+
// CHECK_EQ(a.shape, &a.d0, "NIY for larger tensors");
|
|
83
|
+
if(a._shape!=&a.d0) { _shape=a._shape; a._shape=&a.d0; }
|
|
82
84
|
a.p=NULL;
|
|
83
85
|
a.N=a.nd=a.d0=a.d1=a.d2=0;
|
|
86
|
+
a.resetShape();
|
|
84
87
|
a.isReference=false;
|
|
85
88
|
a.special=NULL;
|
|
86
89
|
}
|
|
@@ -100,11 +103,14 @@ template<class T> Array<T>::Array(std::initializer_list<T> values) : Array() { o
|
|
|
100
103
|
/// initialization via {1., 2., 3., ...} lists, with certain dimensionality
|
|
101
104
|
template<class T> Array<T>::Array(std::initializer_list<uint> dim, std::initializer_list<T> values) : Array() { operator=(values); reshape(dim); }
|
|
102
105
|
|
|
106
|
+
template<class T> Array<T>::Array(const T* p, uint size, bool byReference) : Array() { if(byReference) referTo(p, size); else setCarray(p, size); }
|
|
107
|
+
|
|
103
108
|
template<class T> Array<T>::~Array() {
|
|
104
109
|
#if 0
|
|
105
110
|
clear();
|
|
106
111
|
#else //faster (leaves members non-zeroed..)
|
|
107
112
|
if(special) { delete special; special=NULL; }
|
|
113
|
+
if(_shape!=&d0) { delete[] _shape; }
|
|
108
114
|
if(M) {
|
|
109
115
|
globalMemoryTotal -= M*sizeT;
|
|
110
116
|
if(memMove==1) free(p); else delete[] p;
|
|
@@ -120,57 +126,56 @@ template<class T> Array<T>& Array<T>::clear() {
|
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
/// resize 1D array, discard the previous contents
|
|
123
|
-
template<class T> Array<T>& Array<T>::resize(uint D0) { nd=1; d0=D0;
|
|
129
|
+
template<class T> Array<T>& Array<T>::resize(uint D0) { nd=1; d0=D0; resetShape(); resizeMEM(d0, false); return *this; }
|
|
124
130
|
|
|
125
131
|
/// resize but copy the previous contents
|
|
126
|
-
template<class T> Array<T>& Array<T>::resizeCopy(uint D0) { nd=1; d0=D0;
|
|
132
|
+
template<class T> Array<T>& Array<T>::resizeCopy(uint D0) { nd=1; d0=D0; resetShape(); resizeMEM(d0, true); return *this; }
|
|
127
133
|
|
|
128
134
|
/// reshape the dimensionality (e.g. from 2D to 1D); throw an error if this actually requires to resize the memory
|
|
129
135
|
template<class T> Array<T>& Array<T>::reshape(int D0) {
|
|
130
136
|
if(D0<0) D0=N;
|
|
131
137
|
CHECK_EQ((int)N, D0, "reshape must preserve total memory size");
|
|
132
|
-
nd=1; d0=D0; d1=d2=0;
|
|
138
|
+
nd=1; d0=D0; d1=d2=0; resetShape();
|
|
133
139
|
return *this;
|
|
134
140
|
}
|
|
135
141
|
|
|
136
142
|
/// same for 2D ...
|
|
137
|
-
template<class T> Array<T>& Array<T>::resize(uint D0, uint D1) { nd=2; d0=D0; d1=D1;
|
|
143
|
+
template<class T> Array<T>& Array<T>::resize(uint D0, uint D1) { nd=2; d0=D0; d1=D1; resetShape(); resizeMEM(d0*d1, false); return *this; }
|
|
138
144
|
|
|
139
145
|
/// ...
|
|
140
|
-
template<class T> Array<T>& Array<T>::resizeCopy(uint D0, uint D1) { nd=2; d0=D0; d1=D1;
|
|
146
|
+
template<class T> Array<T>& Array<T>::resizeCopy(uint D0, uint D1) { nd=2; d0=D0; d1=D1; resetShape(); resizeMEM(d0*d1, true); return *this; }
|
|
141
147
|
|
|
142
148
|
/// ...
|
|
143
149
|
template<class T> Array<T>& Array<T>::reshape(int D0, int D1) {
|
|
144
150
|
if(D0<0) D0=N/D1; else if(D1<0) D1=N/D0;
|
|
145
151
|
CHECK_EQ((int)N, D0*D1, "reshape must preserve total memory size");
|
|
146
152
|
nd=2; d0=D0; d1=D1; d2=0;
|
|
147
|
-
|
|
153
|
+
resetShape();
|
|
148
154
|
return *this;
|
|
149
155
|
}
|
|
150
156
|
|
|
151
157
|
/// same for 3D ...
|
|
152
|
-
template<class T> Array<T>& Array<T>::resize(uint D0, uint D1, uint D2) { nd=3; d0=D0; d1=D1; d2=D2;
|
|
158
|
+
template<class T> Array<T>& Array<T>::resize(uint D0, uint D1, uint D2) { nd=3; d0=D0; d1=D1; d2=D2; resetShape(); resizeMEM(d0*d1*d2, false); return *this; }
|
|
153
159
|
|
|
154
160
|
/// ...
|
|
155
|
-
template<class T> Array<T>& Array<T>::resizeCopy(uint D0, uint D1, uint D2) { nd=3; d0=D0; d1=D1; d2=D2;
|
|
161
|
+
template<class T> Array<T>& Array<T>::resizeCopy(uint D0, uint D1, uint D2) { nd=3; d0=D0; d1=D1; d2=D2; resetShape(); resizeMEM(d0*d1*d2, true); return *this; }
|
|
156
162
|
|
|
157
163
|
/// ...
|
|
158
164
|
template<class T> Array<T>& Array<T>::reshape(int D0, int D1, int D2) {
|
|
159
165
|
if(D0<0) D0=N/(D1*D2); else if(D1<0) D1=N/(D0*D2); else if(D2<0) D2=N/(D0*D1);
|
|
160
166
|
CHECK_EQ((int)N, D0*D1*D2, "reshape must preserve total memory size");
|
|
161
167
|
nd=3; d0=D0; d1=D1; d2=D2;
|
|
162
|
-
|
|
168
|
+
resetShape();
|
|
163
169
|
return *this;
|
|
164
170
|
}
|
|
165
171
|
|
|
166
172
|
/// resize to multi-dimensional tensor
|
|
167
173
|
template<class T> Array<T>& Array<T>::resize(uint ND, uint* dim) {
|
|
168
|
-
nd=ND; d0=d1=d2=0;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
for(S=1, j=0; j<nd; j++) S*=dim[j];
|
|
174
|
+
nd=ND; d0=d1=d2=0;
|
|
175
|
+
if(nd>0){ d0=dim[0]; if(nd>1){ d1=dim[1]; if(nd>2){ d2=dim[2]; } } }
|
|
176
|
+
resetShape(dim);
|
|
177
|
+
uint64_t S=(nd>0?1:0);
|
|
178
|
+
for(uint j=0; j<nd; j++) S*=dim[j];
|
|
174
179
|
if(S>=(1ull <<32)) HALT("Array #elements " <<(S>>30) <<"G is >= 2^32");
|
|
175
180
|
resizeMEM((uint)S, false);
|
|
176
181
|
return *this;
|
|
@@ -178,12 +183,11 @@ template<class T> Array<T>& Array<T>::resize(uint ND, uint* dim) {
|
|
|
178
183
|
|
|
179
184
|
/// resize to multi-dimensional tensor
|
|
180
185
|
template<class T> Array<T>& Array<T>::resizeCopy(uint ND, uint* dim) {
|
|
181
|
-
nd=ND; d0=d1=d2=0;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
for(S=1, j=0; j<nd; j++) S*=dim[j];
|
|
186
|
+
nd=ND; d0=d1=d2=0;
|
|
187
|
+
if(nd>0){ d0=dim[0]; if(nd>1){ d1=dim[1]; if(nd>2){ d2=dim[2]; } } }
|
|
188
|
+
resetShape(dim);
|
|
189
|
+
uint64_t S=(nd>0?1:0);
|
|
190
|
+
for(uint j=0; j<nd; j++) S*=dim[j];
|
|
187
191
|
if(S>=(1ull <<32)) HALT("Array #elements " <<(S>>30) <<"G is >= 2^32");
|
|
188
192
|
resizeMEM((uint)S, true);
|
|
189
193
|
return *this;
|
|
@@ -191,19 +195,10 @@ template<class T> Array<T>& Array<T>::resizeCopy(uint ND, uint* dim) {
|
|
|
191
195
|
|
|
192
196
|
/// resize to multi-dimensional tensor
|
|
193
197
|
template<class T> Array<T>& Array<T>::reshape(uint ND, uint* dim) {
|
|
194
|
-
nd=ND; d0=d1=d2=0;
|
|
195
|
-
if(nd>0){
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
d1=dim[1];
|
|
199
|
-
if(nd>2){
|
|
200
|
-
d2=dim[2];
|
|
201
|
-
if(nd>3) { d=new uint[nd]; memmove(d, dim, nd*sizeof(uint)); }
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
//for(uint j=0; j<nd && j<3; j++) {(&d0)[j]=dim[j]; }
|
|
206
|
-
uint S=(nd>0?1:0);
|
|
198
|
+
nd=ND; d0=d1=d2=0;
|
|
199
|
+
if(nd>0){ d0=dim[0]; if(nd>1){ d1=dim[1]; if(nd>2){ d2=dim[2]; } } }
|
|
200
|
+
resetShape(dim);
|
|
201
|
+
uint64_t S=(nd>0?1:0);
|
|
207
202
|
for(uint j=0; j<nd; j++) S*=dim[j];
|
|
208
203
|
CHECK_EQ(N, S, "reshape must preserve total memory size");
|
|
209
204
|
return *this;
|
|
@@ -224,8 +219,7 @@ template<class T> Array<T>& Array<T>::resizeAs(const Array<T>& a) {
|
|
|
224
219
|
CHECK(this!=&a, "never do this!!!");
|
|
225
220
|
if(isReference) CHECK_EQ(N, a.N, "resize of a reference (e.g. subarray) is not allowed! (only a resize without changing memory size)");
|
|
226
221
|
nd=a.nd; d0=a.d0; d1=a.d1; d2=a.d2;
|
|
227
|
-
|
|
228
|
-
if(nd>3) { d=new uint[nd]; memmove(d, a.d, nd*sizeof(uint)); }
|
|
222
|
+
resetShape(a._shape);
|
|
229
223
|
resizeMEM(a.N, false);
|
|
230
224
|
return *this;
|
|
231
225
|
}
|
|
@@ -233,8 +227,8 @@ template<class T> Array<T>& Array<T>::resizeAs(const Array<T>& a) {
|
|
|
233
227
|
/// make it the same size as \c a and copy previous content
|
|
234
228
|
template<class T> Array<T>& Array<T>::resizeCopyAs(const Array<T>& a) {
|
|
235
229
|
CHECK(this!=&a, "never do this!!!");
|
|
236
|
-
nd=a.nd; d0=a.d0; d1=a.d1; d2=a.d2;
|
|
237
|
-
|
|
230
|
+
nd=a.nd; d0=a.d0; d1=a.d1; d2=a.d2;
|
|
231
|
+
resetShape(a._shape);
|
|
238
232
|
resizeMEM(a.N, true);
|
|
239
233
|
return *this;
|
|
240
234
|
}
|
|
@@ -242,20 +236,15 @@ template<class T> Array<T>& Array<T>::resizeCopyAs(const Array<T>& a) {
|
|
|
242
236
|
template<class T> Array<T>& Array<T>::reshapeAs(const Array<T>& a) {
|
|
243
237
|
CHECK(this!=&a, "never do this!!!");
|
|
244
238
|
CHECK_EQ(N, a.N, "reshape must preserve total memory size");
|
|
245
|
-
nd=a.nd; d0=a.d0; d1=a.d1; d2=a.d2;
|
|
246
|
-
|
|
247
|
-
return *this;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
template<class T> Array<T>& Array<T>::reshapeFlat() {
|
|
251
|
-
reshape(N);
|
|
239
|
+
nd=a.nd; d0=a.d0; d1=a.d1; d2=a.d2;
|
|
240
|
+
resetShape(a._shape);
|
|
252
241
|
return *this;
|
|
253
242
|
}
|
|
254
243
|
|
|
255
244
|
/// return the k-th dimensionality
|
|
256
245
|
template<class T> uint Array<T>::dim(uint k) const {
|
|
257
246
|
CHECK(k<nd, "dimensionality range check error: " <<k <<"!<" <<nd);
|
|
258
|
-
if(!
|
|
247
|
+
if(!_shape && k<3) return (&d0)[k]; else return _shape[k];
|
|
259
248
|
}
|
|
260
249
|
|
|
261
250
|
#ifdef RAI_CLANG
|
|
@@ -363,10 +352,9 @@ template<class T> void Array<T>::freeMEM() {
|
|
|
363
352
|
M=0;
|
|
364
353
|
}
|
|
365
354
|
#endif
|
|
366
|
-
if(
|
|
355
|
+
if(_shape!=&d0) { delete[] _shape; _shape=&d0; }
|
|
367
356
|
p=NULL;
|
|
368
357
|
N=nd=d0=d1=d2=0;
|
|
369
|
-
d=&d0;
|
|
370
358
|
isReference=false;
|
|
371
359
|
}
|
|
372
360
|
|
|
@@ -386,9 +374,13 @@ template<class T> Array<T>& Array<T>::dereference() {
|
|
|
386
374
|
}
|
|
387
375
|
|
|
388
376
|
/// reset the dimensionality pointer d to point to &d0
|
|
389
|
-
template<class T> void Array<T>::
|
|
390
|
-
if(
|
|
391
|
-
|
|
377
|
+
template<class T> void Array<T>::resetShape(uint* dim) {
|
|
378
|
+
if(_shape!=&d0) { delete[] _shape; _shape=&d0; }
|
|
379
|
+
if(nd>3) {
|
|
380
|
+
CHECK(dim, "need shape tuple");
|
|
381
|
+
_shape=new uint[nd];
|
|
382
|
+
memmove(_shape, dim, nd*sizeof(uint));
|
|
383
|
+
}
|
|
392
384
|
}
|
|
393
385
|
|
|
394
386
|
//***** append, insert & remove
|
|
@@ -641,10 +633,10 @@ template<class T> void Array<T>::delColumns(int i, uint k) {
|
|
|
641
633
|
}
|
|
642
634
|
|
|
643
635
|
/// inserts k columns at the i-th column [must be 2D]
|
|
644
|
-
template<class T>
|
|
636
|
+
template<class T> Array<T>& Array<T>::insColumns(int i, uint k) {
|
|
645
637
|
CHECK(memMove, "only with memMove");
|
|
646
638
|
CHECK_EQ(nd, 2, "only for matricies");
|
|
647
|
-
if(!k) return;
|
|
639
|
+
if(!k) return *this;
|
|
648
640
|
if(i<0) i+=d1+1;
|
|
649
641
|
CHECK_LE(i, (int)d1, "range check error");
|
|
650
642
|
uint n=d1;
|
|
@@ -654,6 +646,7 @@ template<class T> void Array<T>::insColumns(int i, uint k) {
|
|
|
654
646
|
memset(p+j*d1+i, 0, sizeT*k);
|
|
655
647
|
if(i) memmove(p+j*d1, p+j*n, sizeT*i);
|
|
656
648
|
}
|
|
649
|
+
return *this;
|
|
657
650
|
}
|
|
658
651
|
|
|
659
652
|
/// changes the range of one dimension (generalization of ins/delColumn to arbitrary tensors)
|
|
@@ -687,7 +680,7 @@ template<class T> void Array<T>::resizeDim(uint k, uint dk) {
|
|
|
687
680
|
/// return a uint-Array that contains (acutally refers to) the dimensions of 'this'
|
|
688
681
|
template<class T> Array<uint> Array<T>::dim() const {
|
|
689
682
|
Array<uint> dims;
|
|
690
|
-
dims.setCarray(
|
|
683
|
+
dims.setCarray(_shape, nd);
|
|
691
684
|
return dims;
|
|
692
685
|
}
|
|
693
686
|
|
|
@@ -710,8 +703,15 @@ template<class T> T& Array<T>::elem(int i, int j) {
|
|
|
710
703
|
if(j<0) j += d1;
|
|
711
704
|
CHECK(nd==2 && (uint)i<d0 && (uint)j<d1,
|
|
712
705
|
"2D range error (" <<nd <<"=2, " <<i <<"<" <<d0 <<", " <<j <<"<" <<d1 <<")");
|
|
706
|
+
if constexpr(std::is_same_v<T, double>){
|
|
707
|
+
if(isSparseMatrix(*this)) {
|
|
708
|
+
return sparse().addEntry(i, j);
|
|
709
|
+
}
|
|
710
|
+
if(isRowShifted(*this)) {
|
|
711
|
+
return rowShifted().elemNew(i, j);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
713
714
|
return p[i*d1+j];
|
|
714
|
-
|
|
715
715
|
}
|
|
716
716
|
|
|
717
717
|
/// multi-dimensional (tensor) access
|
|
@@ -767,7 +767,7 @@ template<class T> Array<T> Array<T>::ref() const {
|
|
|
767
767
|
|
|
768
768
|
template<class T> Array<T> Array<T>::operator()(std::pair<int, int> I) const {
|
|
769
769
|
Array<T> z;
|
|
770
|
-
z.referToRange(*this, I
|
|
770
|
+
z.referToRange(*this, I);
|
|
771
771
|
// if(I.size()==2) z.referToRange(*this, I.begin()[0], I.begin()[1]);
|
|
772
772
|
// else if(I.size()==0) z.referTo(*this);
|
|
773
773
|
// else if(I.size()==1) z.referToDim(*this, I.begin()[0]);
|
|
@@ -777,9 +777,8 @@ template<class T> Array<T> Array<T>::operator()(std::pair<int, int> I) const {
|
|
|
777
777
|
|
|
778
778
|
/// range reference access
|
|
779
779
|
template<class T> Array<T> Array<T>::operator()(int i, std::pair<int, int> J) const {
|
|
780
|
-
if(i<0) i += d0;
|
|
781
780
|
Array<T> z;
|
|
782
|
-
z.referToRange(*this, i, J
|
|
781
|
+
z.referToRange(*this, i, J);
|
|
783
782
|
// if(J.size()==2)
|
|
784
783
|
// else if(J.size()==0) z.referToDim(*this, i);
|
|
785
784
|
// else if(J.size()==1) z.referToDim(*this, i, J.begin()[0]);
|
|
@@ -789,10 +788,8 @@ template<class T> Array<T> Array<T>::operator()(int i, std::pair<int, int> J) co
|
|
|
789
788
|
|
|
790
789
|
/// range reference access
|
|
791
790
|
template<class T> Array<T> Array<T>::operator()(int i, int j, std::initializer_list<int> K) const {
|
|
792
|
-
if(i<0) i += d0;
|
|
793
|
-
if(j<0) j += d1;
|
|
794
791
|
Array<T> z;
|
|
795
|
-
if(K.size()==2) z.referToRange(*this, i, j, K.begin()[0], K.begin()[1]);
|
|
792
|
+
if(K.size()==2) z.referToRange(*this, i, j, {K.begin()[0], K.begin()[1]});
|
|
796
793
|
else if(K.size()==0) z.referToDim(*this, i, j);
|
|
797
794
|
else if(K.size()==1) z.referToDim(*this, i, j, K.begin()[0]);
|
|
798
795
|
else HALT("range list needs 0,1, or 2 entries exactly");
|
|
@@ -827,8 +824,9 @@ template<class T> Array<T> Array<T>::copy() const { return Array<T>(*this); }
|
|
|
827
824
|
/** @brief a sub array of a 1D Array (corresponds to matlab [i:I]); when
|
|
828
825
|
the upper limit I is -1, it is replaced by the max limit (like
|
|
829
826
|
[i:]) */
|
|
830
|
-
template<class T> Array<T> Array<T>::sub(int
|
|
827
|
+
template<class T> Array<T> Array<T>::sub(std::pair<int, int> _I) const {
|
|
831
828
|
CHECK_EQ(nd, 1, "1D range error ");
|
|
829
|
+
int i=_I.first, I=_I.second-1;
|
|
832
830
|
Array<T> x;
|
|
833
831
|
if(i<0) i+=d0;
|
|
834
832
|
if(I<0) I+=d0;
|
|
@@ -845,8 +843,9 @@ template<class T> Array<T> Array<T>::sub(int i, int I) const {
|
|
|
845
843
|
/** @brief copies a sub array of a 2D Array (corresponds to matlab [i:I, j:J]);
|
|
846
844
|
when the upper limits I or J are -1, they are replaced by the
|
|
847
845
|
max limit (like [i:, j:]) */
|
|
848
|
-
template<class T> Array<T> Array<T>::sub(int
|
|
846
|
+
template<class T> Array<T> Array<T>::sub(std::pair<int, int> _I, std::pair<int, int> _J) const {
|
|
849
847
|
CHECK_EQ(nd, 2, "2D range error ");
|
|
848
|
+
int i=_I.first, I=_I.second-1, j=_J.first, J=_J.second-1;
|
|
850
849
|
Array<T> x;
|
|
851
850
|
if(i<0) i+=d0;
|
|
852
851
|
if(j<0) j+=d1;
|
|
@@ -865,8 +864,9 @@ template<class T> Array<T> Array<T>::sub(int i, int I, int j, int J) const {
|
|
|
865
864
|
/** @brief copies a sub array of a 3D Array (corresponds to matlab [i:I, j:J]);
|
|
866
865
|
when the upper limits I or J are -1, they are replaced by the
|
|
867
866
|
max limit (like [i:, j:]) */
|
|
868
|
-
template<class T> Array<T> Array<T>::sub(int
|
|
867
|
+
template<class T> Array<T> Array<T>::sub(std::pair<int, int> _I, std::pair<int, int> _J, std::pair<int, int> _K) const {
|
|
869
868
|
CHECK_EQ(nd, 3, "3D range error ");
|
|
869
|
+
int i=_I.first, I=_I.second-1, j=_J.first, J=_J.second-1, k=_K.first, K=_K.second-1;
|
|
870
870
|
Array<T> x;
|
|
871
871
|
if(i<0) i+=d0;
|
|
872
872
|
if(j<0) j+=d1;
|
|
@@ -891,8 +891,9 @@ template<class T> Array<T> Array<T>::sub(int i, int I, int j, int J, int k, int
|
|
|
891
891
|
runs from i to I (as explained above) while the second index runs
|
|
892
892
|
over the columns explicitly referred to by cols. (col doesn't have
|
|
893
893
|
to be ordered or could also contain some columns multiply) */
|
|
894
|
-
template<class T> Array<T> Array<T>::
|
|
894
|
+
template<class T> Array<T> Array<T>::pick(std::pair<int, int> _I, Array<uint> cols) const {
|
|
895
895
|
CHECK_EQ(nd, 2, "2D range error ");
|
|
896
|
+
int i=_I.first, I=_I.second-1;
|
|
896
897
|
Array<T> x;
|
|
897
898
|
if(i<0) i+=d0;
|
|
898
899
|
if(I<0) I+=d0;
|
|
@@ -902,7 +903,7 @@ template<class T> Array<T> Array<T>::sub(int i, int I, Array<uint> cols) const {
|
|
|
902
903
|
return x;
|
|
903
904
|
}
|
|
904
905
|
|
|
905
|
-
template<class T> Array<T> Array<T>::
|
|
906
|
+
template<class T> Array<T> Array<T>::pick(Array<uint> elems) const {
|
|
906
907
|
Array<T> x;
|
|
907
908
|
if(nd==1) {
|
|
908
909
|
x.resize(elems.N);
|
|
@@ -930,7 +931,7 @@ template<class T> Array<T> Array<T>::sub(Array<uint> elems) const {
|
|
|
930
931
|
*/
|
|
931
932
|
template<class T>
|
|
932
933
|
Array<T> Array<T>::row(uint row_index) const {
|
|
933
|
-
return sub(row_index, row_index, 0, d1 - 1);
|
|
934
|
+
return sub({row_index, row_index+1},{ 0, d1 - 1+1});
|
|
934
935
|
}
|
|
935
936
|
|
|
936
937
|
/**
|
|
@@ -945,7 +946,7 @@ Array<T> Array<T>::row(uint row_index) const {
|
|
|
945
946
|
*/
|
|
946
947
|
template<class T>
|
|
947
948
|
Array<T> Array<T>::col(uint col_index) const {
|
|
948
|
-
return sub(0, d0 - 1, col_index, col_index).reshape(d0);
|
|
949
|
+
return sub({0, d0 - 1+1},{ col_index, col_index+1}).reshape(d0);
|
|
949
950
|
}
|
|
950
951
|
|
|
951
952
|
/**
|
|
@@ -961,7 +962,7 @@ Array<T> Array<T>::col(uint col_index) const {
|
|
|
961
962
|
*/
|
|
962
963
|
template<class T>
|
|
963
964
|
Array<T> Array<T>::rows(uint start_row, uint end_row) const {
|
|
964
|
-
return sub(start_row, end_row - 1, 0, d1 - 1);
|
|
965
|
+
return sub({start_row, end_row - 1+1},{ 0, d1 - 1+1});
|
|
965
966
|
}
|
|
966
967
|
|
|
967
968
|
/**
|
|
@@ -977,7 +978,7 @@ Array<T> Array<T>::rows(uint start_row, uint end_row) const {
|
|
|
977
978
|
*/
|
|
978
979
|
template<class T>
|
|
979
980
|
Array<T> Array<T>::cols(uint start_col, uint end_col) const {
|
|
980
|
-
return sub(0, d0 - 1, start_col, end_col - 1);
|
|
981
|
+
return sub({0, d0 - 1+1},{ start_col, end_col - 1+1});
|
|
981
982
|
}
|
|
982
983
|
|
|
983
984
|
/// makes this array a reference to the C buffer
|
|
@@ -1013,6 +1014,10 @@ template<class T> Array<T>& Array<T>::operator=(const Array<T>& a) {
|
|
|
1013
1014
|
if(memMove) memmove(p, a.p, sizeT*N);
|
|
1014
1015
|
else for(uint i=0; i<N; i++) p[i]=a.p[i];
|
|
1015
1016
|
if(special) { delete special; special=NULL; }
|
|
1017
|
+
if constexpr(std::is_same_v<T, double>){
|
|
1018
|
+
if(isSpecial(a)) special_copy(*this, a);
|
|
1019
|
+
if(a.jac) jac = std::make_unique<arr>(*a.jac);
|
|
1020
|
+
}
|
|
1016
1021
|
return *this;
|
|
1017
1022
|
}
|
|
1018
1023
|
|
|
@@ -1047,7 +1052,7 @@ template<class T> Array<T> catCol(const Array<Array<T>*>& X) {
|
|
|
1047
1052
|
// d1+=x->d1;
|
|
1048
1053
|
// }
|
|
1049
1054
|
} else {
|
|
1050
|
-
z.resize(d0, d1);
|
|
1055
|
+
z.resize(d0, d1).setZero();
|
|
1051
1056
|
d1=0;
|
|
1052
1057
|
for(const Array<T>* x: X) { z.setMatrixBlock(*x, 0, d1); d1+=x->nd==2?x->d1:1; }
|
|
1053
1058
|
}
|
|
@@ -1068,7 +1073,7 @@ template<class T> Array<T> catCol(const Array<Array<T>>& X) {
|
|
|
1068
1073
|
}
|
|
1069
1074
|
|
|
1070
1075
|
/// set all entries to same value x [default: don't change dimension]
|
|
1071
|
-
template<class T> void Array<T>::
|
|
1076
|
+
template<class T> void Array<T>::setConst(const T& x, int d) {
|
|
1072
1077
|
if(d!=-1) resize(d);
|
|
1073
1078
|
uint i;
|
|
1074
1079
|
for(i=0; i<N; i++) elem(i)=x;
|
|
@@ -1080,7 +1085,9 @@ template<class T> void Array<T>::setId(int d) {
|
|
|
1080
1085
|
CHECK(d!=-1 || (nd==2 && d0==d1), "need squared matrix to set to identity");
|
|
1081
1086
|
if(d!=-1) resize(d, d);
|
|
1082
1087
|
setZero();
|
|
1083
|
-
|
|
1088
|
+
if constexpr(std::is_scalar_v<T>){
|
|
1089
|
+
for(uint i=0; i<d0; i++) operator()(i, i)=(T)1;
|
|
1090
|
+
}else NIY;
|
|
1084
1091
|
}
|
|
1085
1092
|
|
|
1086
1093
|
template<class T> void Array<T>::setDiag(const T& x, int d) {
|
|
@@ -1117,13 +1124,38 @@ template<class T> void Array<T>::setBlockMatrix(const Array<T>& A, const Array<T
|
|
|
1117
1124
|
template<class T> void Array<T>::setBlockMatrix(const Array<T>& A, const Array<T>& B) {
|
|
1118
1125
|
CHECK(A.nd==2 && B.nd==2, "");
|
|
1119
1126
|
CHECK(A.d1==B.d1, "");
|
|
1120
|
-
|
|
1127
|
+
|
|
1128
|
+
if constexpr(std::is_same_v<T, double>){
|
|
1129
|
+
if(isSparse(A)){
|
|
1130
|
+
CHECK(isSparse(B), "");
|
|
1131
|
+
sparse().resize(A.d0+B.d0, A.d1, 0);
|
|
1132
|
+
}else{
|
|
1133
|
+
resize(A.d0+B.d0, A.d1).setZero();
|
|
1134
|
+
}
|
|
1135
|
+
}else{
|
|
1136
|
+
resize(A.d0+B.d0, A.d1).setZero();
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1121
1139
|
setMatrixBlock(A, 0, 0);
|
|
1122
1140
|
setMatrixBlock(B, A.d0, 0);
|
|
1123
1141
|
}
|
|
1124
1142
|
|
|
1125
1143
|
/// constructs a vector x=[a, b]
|
|
1126
1144
|
template<class T> void Array<T>::setBlockVector(const Array<T>& a, const Array<T>& b) {
|
|
1145
|
+
|
|
1146
|
+
if constexpr(std::is_same_v<T, double>){
|
|
1147
|
+
if(a.jac || b.jac) {
|
|
1148
|
+
const Array<T>& A=*a.jac;
|
|
1149
|
+
const Array<T>& B=*b.jac;
|
|
1150
|
+
if(isSparse(A)){
|
|
1151
|
+
CHECK(isSparse(B), "");
|
|
1152
|
+
J().sparse().resize(A.d0+B.d0, A.d1, 0);
|
|
1153
|
+
}else{
|
|
1154
|
+
CHECK(!isSparse(B), "");
|
|
1155
|
+
J().resize(A.d0+B.d0, A.d1).setZero();
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1127
1159
|
CHECK(a.nd==1 && b.nd==1, "");
|
|
1128
1160
|
resize(a.N+b.N);
|
|
1129
1161
|
setVectorBlock(a, 0); //for(i=0;i<a.N;i++) operator()(i )=a(i);
|
|
@@ -1132,6 +1164,13 @@ template<class T> void Array<T>::setBlockVector(const Array<T>& a, const Array<T
|
|
|
1132
1164
|
|
|
1133
1165
|
/// write the matrix B into 'this' matrix at location lo0, lo1
|
|
1134
1166
|
template<class T> void Array<T>::setMatrixBlock(const Array<T>& B, uint lo0, uint lo1) {
|
|
1167
|
+
if constexpr(std::is_same_v<T, double>){
|
|
1168
|
+
if(isSparse(*this)){
|
|
1169
|
+
sparse().add(B, lo0, lo1);
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1135
1174
|
CHECK(!special && !B.special, "");
|
|
1136
1175
|
CHECK(B.nd==1 || B.nd==2, "");
|
|
1137
1176
|
if(B.nd==2) {
|
|
@@ -1155,18 +1194,29 @@ template<class T> void Array<T>::setVectorBlock(const Array<T>& B, uint lo) {
|
|
|
1155
1194
|
CHECK(nd==1 && B.nd==1 && lo+B.N<=N, "");
|
|
1156
1195
|
uint i;
|
|
1157
1196
|
for(i=0; i<B.N; i++) elem(lo+i)=B.elem(i);
|
|
1197
|
+
if constexpr(std::is_same_v<T, double>){
|
|
1198
|
+
if(B.jac) {
|
|
1199
|
+
CHECK(jac && jac->d1==B.jac->d1, "Jacobian needs to be pre-sized");
|
|
1200
|
+
CHECK(!B.jac->jac, "NOT HANDLED YET");
|
|
1201
|
+
jac->setMatrixBlock(*B.jac, lo, 0);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1158
1204
|
}
|
|
1159
1205
|
|
|
1160
1206
|
/// sorted permutation of length \c n
|
|
1161
1207
|
template<class T> void Array<T>::setStraightPerm(int n) {
|
|
1162
1208
|
if(n!=-1) resize(n);
|
|
1163
|
-
|
|
1209
|
+
if constexpr(std::is_arithmetic_v<T>){
|
|
1210
|
+
for(uint i=0; i<N; i++) elem(i)=static_cast<T>(i);
|
|
1211
|
+
} else NIY;
|
|
1164
1212
|
}
|
|
1165
1213
|
|
|
1166
1214
|
/// reverse sorted permutation of lenth \c N
|
|
1167
1215
|
template<class T> void Array<T>::setReversePerm(int n) {
|
|
1168
1216
|
if(n!=-1) resize(n);
|
|
1169
|
-
|
|
1217
|
+
if constexpr(std::is_arithmetic_v<T>){
|
|
1218
|
+
for(uint i=0; i<N; i++) elem(N-1-i)=static_cast<T>(i);
|
|
1219
|
+
} else NIY;
|
|
1170
1220
|
}
|
|
1171
1221
|
|
|
1172
1222
|
/// permute all elements randomly
|
|
@@ -1190,7 +1240,7 @@ template<class T> Array<T>& Array<T>::setCarray(const T* buffer, uint D0) {
|
|
|
1190
1240
|
}
|
|
1191
1241
|
|
|
1192
1242
|
/// 'this' becomes a copy (not reference to!) of the 2D C array
|
|
1193
|
-
template<class T> Array<T>& Array<T>::setCarray(const
|
|
1243
|
+
template<class T> Array<T>& Array<T>::setCarray(T* const* buffer, uint D0, uint D1) {
|
|
1194
1244
|
resize(D0, D1);
|
|
1195
1245
|
uint i, j;
|
|
1196
1246
|
for(i=0; i<d0; i++) {
|
|
@@ -1209,8 +1259,9 @@ template<class T> void Array<T>::referTo(const Array<T>& a) {
|
|
|
1209
1259
|
}
|
|
1210
1260
|
|
|
1211
1261
|
/// make this array a subarray reference to \c a
|
|
1212
|
-
template<class T> void Array<T>::referToRange(const Array<T>& a, int
|
|
1262
|
+
template<class T> void Array<T>::referToRange(const Array<T>& a, std::pair<int, int> I) {
|
|
1213
1263
|
CHECK_LE(a.nd, 3, "not implemented yet");
|
|
1264
|
+
int i_lo=I.first, i_up=I.second-1;
|
|
1214
1265
|
if(i_lo<0) i_lo+=a.d0;
|
|
1215
1266
|
if(i_up<0) i_up+=a.d0;
|
|
1216
1267
|
if(i_lo>i_up) { clear(); return; }
|
|
@@ -1228,9 +1279,10 @@ template<class T> void Array<T>::referToRange(const Array<T>& a, int i_lo, int i
|
|
|
1228
1279
|
}
|
|
1229
1280
|
|
|
1230
1281
|
/// make this array a subarray reference to \c a
|
|
1231
|
-
template<class T> void Array<T>::referToRange(const Array<T>& a, int i, int
|
|
1282
|
+
template<class T> void Array<T>::referToRange(const Array<T>& a, int i, std::pair<int, int> J) {
|
|
1232
1283
|
CHECK(a.nd>1, "does not make sense");
|
|
1233
1284
|
CHECK_LE(a.nd, 3, "not implemented yet");
|
|
1285
|
+
int j_lo=J.first, j_up=J.second-1;
|
|
1234
1286
|
if(i<0) i+=a.d0;
|
|
1235
1287
|
if(j_lo<0) j_lo+=a.d1;
|
|
1236
1288
|
if(j_up<0) j_up+=a.d1;
|
|
@@ -1247,9 +1299,10 @@ template<class T> void Array<T>::referToRange(const Array<T>& a, int i, int j_lo
|
|
|
1247
1299
|
}
|
|
1248
1300
|
|
|
1249
1301
|
/// make this array a subarray reference to \c a
|
|
1250
|
-
template<class T> void Array<T>::referToRange(const Array<T>& a, int i, int j, int
|
|
1302
|
+
template<class T> void Array<T>::referToRange(const Array<T>& a, int i, int j, std::pair<int, int> K) {
|
|
1251
1303
|
CHECK(a.nd>2, "does not make sense");
|
|
1252
1304
|
CHECK_LE(a.nd, 3, "not implemented yet");
|
|
1305
|
+
int k_lo=K.first, k_up=K.second-1;
|
|
1253
1306
|
if(i<0) i+=a.d0;
|
|
1254
1307
|
if(j<0) j+=a.d1;
|
|
1255
1308
|
if(k_lo<0) k_lo+=a.d2;
|
|
@@ -1279,8 +1332,8 @@ template<class T> void Array<T>::referToDim(const Array<T>& a, int i) {
|
|
|
1279
1332
|
} else if(a.nd>3) {
|
|
1280
1333
|
uint n=a.N/a.d0;
|
|
1281
1334
|
referTo(a.p+i*n, n);
|
|
1282
|
-
nd=a.nd-1; d0=a.d1; d1=a.d2; d2=a.
|
|
1283
|
-
|
|
1335
|
+
nd=a.nd-1; d0=a.d1; d1=a.d2; d2=a._shape[3];
|
|
1336
|
+
resetShape(a._shape+1);
|
|
1284
1337
|
}
|
|
1285
1338
|
}
|
|
1286
1339
|
|
|
@@ -1302,14 +1355,14 @@ template<class T> void Array<T>::referToDim(const Array<T>& a, uint i, uint j, u
|
|
|
1302
1355
|
CHECK(i<a.d0 && j<a.d1 && k<a.d2, "SubDim range error (" <<i <<"<" <<a.d0 <<", " <<j <<"<" <<a.d1 <<", " <<k <<"<" <<a.d2 << ")");
|
|
1303
1356
|
|
|
1304
1357
|
if(a.nd==4) {
|
|
1305
|
-
referTo(&a(i, j, k), a.
|
|
1358
|
+
referTo(&a(i, j, k), a._shape[3]);
|
|
1306
1359
|
} else if(a.nd==5) {
|
|
1307
1360
|
NIY;
|
|
1308
1361
|
// nd=2; d0=a.d[3]; d1=a.d[4]; d2=0; N=d0*d1;
|
|
1309
1362
|
} else if(a.nd>5) {
|
|
1310
1363
|
NIY;
|
|
1311
1364
|
// nd=a.nd-3; d0=a.d[3]; d1=a.d[4]; d2=a.d[5]; N=a.N/(a.d0*a.d1*a.d2);
|
|
1312
|
-
//
|
|
1365
|
+
// resetShape();
|
|
1313
1366
|
// if(nd>3) { d=new uint[nd]; memmove(d, a.d+3, nd*sizeof(uint)); }
|
|
1314
1367
|
}
|
|
1315
1368
|
// p=a.p+(i*a.N+(j*a.N+(k*a.N/a.d2))/a.d1)/a.d0;
|
|
@@ -1322,6 +1375,7 @@ template<class T> void Array<T>::takeOver(Array<T>& a) {
|
|
|
1322
1375
|
freeMEM();
|
|
1323
1376
|
memMove=a.memMove;
|
|
1324
1377
|
N=a.N; nd=a.nd; d0=a.d0; d1=a.d1; d2=a.d2;
|
|
1378
|
+
resetShape(a._shape);
|
|
1325
1379
|
p=a.p; M=a.M;
|
|
1326
1380
|
special=a.special;
|
|
1327
1381
|
#if 0 //a remains reference on this
|
|
@@ -1330,53 +1384,12 @@ template<class T> void Array<T>::takeOver(Array<T>& a) {
|
|
|
1330
1384
|
#else //a is cleared
|
|
1331
1385
|
a.p=NULL;
|
|
1332
1386
|
a.M=a.N=a.nd=a.d0=a.d1=a.d2=0;
|
|
1333
|
-
|
|
1387
|
+
a.resetShape();
|
|
1334
1388
|
a.special=0;
|
|
1335
1389
|
a.isReference=false;
|
|
1336
1390
|
#endif
|
|
1337
1391
|
}
|
|
1338
1392
|
|
|
1339
|
-
/** @brief return a `dim'-dimensional grid with `steps' intervals
|
|
1340
|
-
filling the range [lo, hi] in each dimension. Note: returned array is
|
|
1341
|
-
`flat', rather than grid-shaped. */
|
|
1342
|
-
template<class T> Array<T>& Array<T>::setGrid(uint dim, T lo, T hi, uint steps) {
|
|
1343
|
-
CHECK(steps, "steps needs to be >0");
|
|
1344
|
-
uint i, j, k;
|
|
1345
|
-
if(dim==1) {
|
|
1346
|
-
resize(steps+1, 1);
|
|
1347
|
-
for(i=0; i<d0; i++) elem(i)=lo+(hi-lo)*i/steps;
|
|
1348
|
-
return *this;
|
|
1349
|
-
}
|
|
1350
|
-
if(dim==2) {
|
|
1351
|
-
resize(steps+1, steps+1, 2);
|
|
1352
|
-
for(i=0; i<d0; i++) for(j=0; j<d1; j++) {
|
|
1353
|
-
operator()(i, j, 0)=lo+(hi-lo)*i/steps;
|
|
1354
|
-
operator()(i, j, 1)=lo+(hi-lo)*j/steps;
|
|
1355
|
-
}
|
|
1356
|
-
reshape(d0*d1, 2);
|
|
1357
|
-
return *this;
|
|
1358
|
-
}
|
|
1359
|
-
if(dim==3) {
|
|
1360
|
-
resize(uintA{steps+1, steps+1, steps+1, 3});
|
|
1361
|
-
T dx = (hi-lo)/steps;
|
|
1362
|
-
for(i=0; i<d0; i++) for(j=0; j<d1; j++) {
|
|
1363
|
-
T* p = &elem(uintA{i, j, 0, 0});
|
|
1364
|
-
for(k=0; k<d2; k++) {
|
|
1365
|
-
*(p++) = lo+dx*i;
|
|
1366
|
-
*(p++) = lo+dx*j;
|
|
1367
|
-
*(p++) = lo+dx*k;
|
|
1368
|
-
// elem(uintA{i, j, k, 0}) = lo+dx*i;
|
|
1369
|
-
// elem(uintA{i, j, k, 1}) = lo+dx*j;
|
|
1370
|
-
// elem(uintA{i, j, k, 2}) = lo+dx*k;
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
reshape(d0*d1*d2, 3);
|
|
1374
|
-
return *this;
|
|
1375
|
-
}
|
|
1376
|
-
NIY;
|
|
1377
|
-
return *this;
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
1393
|
template<class T> T rai::Array<T>::median_nonConst() {
|
|
1381
1394
|
CHECK_GE(N, 1, "");
|
|
1382
1395
|
std::nth_element(p, p+N/2, p+N);
|
|
@@ -1498,7 +1511,7 @@ template<class T> void Array<T>::permuteInv(const Array<uint>& permutation) {
|
|
|
1498
1511
|
template<class T> void Array<T>::permuteRowsInv(const Array<uint>& permutation) {
|
|
1499
1512
|
CHECK_LE(permutation.N, d0, "array smaller than permutation ("<<N<<"<"<<permutation.N<<")");
|
|
1500
1513
|
Array<T> b=(*this);
|
|
1501
|
-
for(uint i=0; i<d0; i++) operator[](permutation(i))
|
|
1514
|
+
for(uint i=0; i<d0; i++) operator[](permutation(i))=b[i];
|
|
1502
1515
|
}
|
|
1503
1516
|
|
|
1504
1517
|
/// randomly permute all entries of 'this'
|
|
@@ -1531,9 +1544,28 @@ template<class T> void Array<T>::shift(int offset, bool wrapAround) {
|
|
|
1531
1544
|
|
|
1532
1545
|
//==================================================================================
|
|
1533
1546
|
|
|
1547
|
+
/// return fraction of non-zeros in the array
|
|
1548
|
+
template<class T> double Array<T>::sparsity() {
|
|
1549
|
+
uint i, m=0;
|
|
1550
|
+
for(i=0; i<N; i++) if(elem(i)) m++;
|
|
1551
|
+
return ((double)m)/N;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
//==================================================================================
|
|
1555
|
+
|
|
1534
1556
|
/** @brief prototype for operator<<, writes the array by separating elements with ELEMSEP, separating rows with LINESEP, using BRACKETS[0] and BRACKETS[1] to brace the data, optionally writs a dimensionality tag before the data (see below), and optinally in binary format */
|
|
1535
1557
|
template<class T> void Array<T>::write(std::ostream& os, const char* ELEMSEP, const char* LINESEP, const char* BRACKETS, bool dimTag, bool binary) const {
|
|
1536
|
-
|
|
1558
|
+
|
|
1559
|
+
if constexpr(std::is_same_v<T, double>){
|
|
1560
|
+
if(special){
|
|
1561
|
+
special_write(os, *this);
|
|
1562
|
+
if(jac) os <<" -- JACOBIAN:\n" <<*jac <<endl;
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
}else{
|
|
1566
|
+
CHECK(!special, "");
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1537
1569
|
CHECK(!binary || memMove, "binary write works only for memMoveable data");
|
|
1538
1570
|
uint i, j, k;
|
|
1539
1571
|
if(!ELEMSEP) ELEMSEP=arrayElemsep;
|
|
@@ -1572,15 +1604,19 @@ template<class T> void Array<T>::write(std::ostream& os, const char* ELEMSEP, co
|
|
|
1572
1604
|
}
|
|
1573
1605
|
}
|
|
1574
1606
|
if(nd>3) {
|
|
1575
|
-
CHECK(
|
|
1607
|
+
CHECK(_shape && _shape!=&d0, "");
|
|
1576
1608
|
for(i=0; i<N; i++) {
|
|
1577
|
-
if(i && !(i%
|
|
1578
|
-
if(nd>1 && !(i%(
|
|
1609
|
+
if(i && !(i%_shape[nd-1])) os <<LINESEP;
|
|
1610
|
+
if(nd>1 && !(i%(_shape[nd-2]*_shape[nd-1]))) os <<LINESEP;
|
|
1579
1611
|
os <<(i?ELEMSEP:"") <<elem(i);
|
|
1580
1612
|
}
|
|
1581
1613
|
}
|
|
1582
1614
|
if(BRACKETS[1]) os <<BRACKETS[1];
|
|
1583
1615
|
}
|
|
1616
|
+
|
|
1617
|
+
if constexpr(std::is_same_v<T, double>){
|
|
1618
|
+
if(jac) os <<" -- JACOBIAN:\n" <<*jac <<endl;
|
|
1619
|
+
}
|
|
1584
1620
|
}
|
|
1585
1621
|
|
|
1586
1622
|
/** @brief prototype for operator>>, if there is a dimensionality tag: fast reading of ascii (if there is brackets[]) or binary (if there is \\0\\0 brackets) data; otherwise slow ascii read */
|
|
@@ -1607,7 +1643,9 @@ template<class T> Array<T>& Array<T>::read(std::istream& is) {
|
|
|
1607
1643
|
} else { //fast ascii read
|
|
1608
1644
|
for(uint i=0; i<N; i++) {
|
|
1609
1645
|
if(is.fail()) PARSERR("could not read " <<i <<"-th element of an array");
|
|
1610
|
-
|
|
1646
|
+
if constexpr(!std::is_pointer_v<T>){
|
|
1647
|
+
is >>p[i];
|
|
1648
|
+
} else NIY;
|
|
1611
1649
|
}
|
|
1612
1650
|
}
|
|
1613
1651
|
if(expectBracket) {
|
|
@@ -1632,7 +1670,9 @@ template<class T> Array<T>& Array<T>::read(std::istream& is) {
|
|
|
1632
1670
|
continue;
|
|
1633
1671
|
}
|
|
1634
1672
|
if(c!=',') is.putback(c);
|
|
1635
|
-
|
|
1673
|
+
if constexpr(!std::is_pointer_v<T>){
|
|
1674
|
+
is >>x;
|
|
1675
|
+
}else NIY;
|
|
1636
1676
|
if(!is.good()) {
|
|
1637
1677
|
if(!expectBracket) is.clear(); //ok
|
|
1638
1678
|
else PARSERR("failed reading ending bracket ]");
|
|
@@ -1825,6 +1865,7 @@ template<class T> void writeConsecutiveConstant(std::ostream& os, const Array<T>
|
|
|
1825
1865
|
|
|
1826
1866
|
/// contatenation of two arrays
|
|
1827
1867
|
template<class T> Array<T> operator, (const Array<T>& y, const Array<T>& z) { Array<T> x(y); x.append(z); return x; }
|
|
1868
|
+
|
|
1828
1869
|
/// calls Array<T>::read
|
|
1829
1870
|
template<class T> std::istream& operator>>(std::istream& is, Array<T>& x) { x.read(is); return is; }
|
|
1830
1871
|
|
|
@@ -1869,4 +1910,114 @@ template<class T> bool operator<(const Array<T>& v, const Array<T>& w) {
|
|
|
1869
1910
|
return v.N<w.N;
|
|
1870
1911
|
}
|
|
1871
1912
|
|
|
1913
|
+
//core for matrix-matrix (elem-wise) update
|
|
1914
|
+
#define UpdateOperator_MM( op ) \
|
|
1915
|
+
if constexpr(std::is_same_v<T, double>){ \
|
|
1916
|
+
if(isNoArr(x)){ return; } \
|
|
1917
|
+
if(isSparseMatrix(x) && isSparseMatrix(y)){ x.sparse() op y.sparse(); return; } \
|
|
1918
|
+
if(isRowShifted(x) && isRowShifted(y)){ x.rowShifted() op y.rowShifted(); return; } \
|
|
1919
|
+
} \
|
|
1920
|
+
CHECK(!x.special, ""); \
|
|
1921
|
+
CHECK(!y.special, ""); \
|
|
1922
|
+
CHECK_EQ(x.N, y.N, "update operator on different array dimensions (" <<x.N <<", " <<y.N <<")"); \
|
|
1923
|
+
T *xp=x.p, *xstop=xp+x.N; \
|
|
1924
|
+
const T *yp=y.p; \
|
|
1925
|
+
for(; xp!=xstop; xp++, yp++) *xp op *yp;
|
|
1926
|
+
|
|
1927
|
+
//core for matrix-scalar update
|
|
1928
|
+
#define UpdateOperator_MS( op ) \
|
|
1929
|
+
if constexpr(std::is_same_v<T, double>){ \
|
|
1930
|
+
if(isNoArr(x)){ return; } \
|
|
1931
|
+
if(isSparseMatrix(x)){ x.sparse() op y; return; } \
|
|
1932
|
+
if(isRowShifted(x)){ x.rowShifted() op y; return; } \
|
|
1933
|
+
} \
|
|
1934
|
+
CHECK(!x.special, ""); \
|
|
1935
|
+
T *xp=x.p, *xstop=xp+x.N; \
|
|
1936
|
+
for(; xp!=xstop; xp++) *xp op y;
|
|
1937
|
+
|
|
1938
|
+
|
|
1939
|
+
template<class T> void operator+=(Array<T>& x, const Array<T>& y) {
|
|
1940
|
+
UpdateOperator_MM(+=);
|
|
1941
|
+
if constexpr(std::is_same_v<T, double>){
|
|
1942
|
+
if(y.jac) {
|
|
1943
|
+
if(x.jac) *x.jac += *y.jac;
|
|
1944
|
+
else x.J() = *y.jac;
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
template<class T> void operator+=(Array<T>& x, const T& y) {
|
|
1949
|
+
UpdateOperator_MS(+=);
|
|
1950
|
+
}
|
|
1951
|
+
template<class T> void operator-=(Array<T>& x, const Array<T>& y) {
|
|
1952
|
+
UpdateOperator_MM(-=);
|
|
1953
|
+
if constexpr(std::is_same_v<T, double>){
|
|
1954
|
+
if(y.jac) {
|
|
1955
|
+
if(x.jac) *x.jac -= *y.jac;
|
|
1956
|
+
else x.J() = -(*y.jac);
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
template<class T> void operator-=(Array<T>& x, const T& y) {
|
|
1961
|
+
UpdateOperator_MS(-=);
|
|
1962
|
+
}
|
|
1963
|
+
template<class T> void operator*=(Array<T>& x, const T& y) {
|
|
1964
|
+
if constexpr(std::is_same_v<T, double>){
|
|
1965
|
+
if(x.jac) *x.jac *= y;
|
|
1966
|
+
}
|
|
1967
|
+
UpdateOperator_MS(*=);
|
|
1968
|
+
}
|
|
1969
|
+
template<class T> void operator/=(Array<T>& x, const T& y) {
|
|
1970
|
+
if constexpr(std::is_same_v<T, double>){
|
|
1971
|
+
if(x.jac) *x.jac /= y;
|
|
1972
|
+
}
|
|
1973
|
+
UpdateOperator_MS(/=);
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
#undef UpdateOperator_MM
|
|
1977
|
+
#undef UpdateOperator_MS
|
|
1978
|
+
|
|
1979
|
+
//===========================================================================
|
|
1980
|
+
|
|
1981
|
+
/** @brief return a `dim'-dimensional grid with `steps' intervals
|
|
1982
|
+
filling the range [lo, hi] in each dimension. Note: returned array is
|
|
1983
|
+
`flat', rather than grid-shaped. */
|
|
1984
|
+
template<class T> Array<T> grid(uint dim, T lo, T hi, uint steps) {
|
|
1985
|
+
Array<T> x;
|
|
1986
|
+
CHECK(steps, "steps needs to be >0");
|
|
1987
|
+
uint i, j, k;
|
|
1988
|
+
if(dim==1) {
|
|
1989
|
+
x.resize(steps+1, 1);
|
|
1990
|
+
for(i=0; i<x.d0; i++) x.elem(i)=lo+(hi-lo)*i/steps;
|
|
1991
|
+
return x;
|
|
1992
|
+
}
|
|
1993
|
+
if(dim==2) {
|
|
1994
|
+
x.resize(steps+1, steps+1, 2);
|
|
1995
|
+
for(i=0; i<x.d0; i++) for(j=0; j<x.d1; j++) {
|
|
1996
|
+
x(i, j, 0)=lo+(hi-lo)*i/steps;
|
|
1997
|
+
x(i, j, 1)=lo+(hi-lo)*j/steps;
|
|
1998
|
+
}
|
|
1999
|
+
x.reshape(x.d0*x.d1, 2);
|
|
2000
|
+
return x;
|
|
2001
|
+
}
|
|
2002
|
+
if(dim==3) {
|
|
2003
|
+
x.resize(uintA{steps+1, steps+1, steps+1, 3});
|
|
2004
|
+
T dx = (hi-lo)/steps;
|
|
2005
|
+
for(i=0; i<x.d0; i++) for(j=0; j<x.d1; j++) {
|
|
2006
|
+
T* p = &x.elem(uintA{i, j, 0, 0});
|
|
2007
|
+
for(k=0; k<x.d2; k++) {
|
|
2008
|
+
*(p++) = lo+dx*i;
|
|
2009
|
+
*(p++) = lo+dx*j;
|
|
2010
|
+
*(p++) = lo+dx*k;
|
|
2011
|
+
// elem(uintA{i, j, k, 0}) = lo+dx*i;
|
|
2012
|
+
// elem(uintA{i, j, k, 1}) = lo+dx*j;
|
|
2013
|
+
// elem(uintA{i, j, k, 2}) = lo+dx*k;
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
x.reshape(x.d0*x.d1*x.d2, 3);
|
|
2017
|
+
return x;
|
|
2018
|
+
}
|
|
2019
|
+
NIY;
|
|
2020
|
+
return x;
|
|
2021
|
+
}
|
|
2022
|
+
|
|
1872
2023
|
} //namespace
|