robotic 0.2.8.dev4__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.
Files changed (411) hide show
  1. robotic/DataGen.pyi +11 -1
  2. robotic/__init__.py +8 -1
  3. robotic/_robotic.pyi +236 -114
  4. robotic/_robotic.so +0 -0
  5. robotic/algo.pyi +17 -0
  6. robotic/include/rai/{Geo → Algo}/Lewiner/MarchingCubes.h +0 -29
  7. robotic/include/rai/Algo/SplineCtrlFeed.h +1 -1
  8. robotic/include/rai/Algo/marching_cubes.h +9 -0
  9. robotic/include/rai/Algo/rungeKutta.h +2 -2
  10. robotic/include/rai/Algo/spline.h +4 -8
  11. robotic/include/rai/Algo/trilinear.h +10 -0
  12. robotic/include/rai/Control/CtrlSolver.h +1 -1
  13. robotic/include/rai/Control/TimingMPC.h +2 -2
  14. robotic/include/rai/Core/array.h +99 -64
  15. robotic/include/rai/Core/array.ipp +290 -136
  16. robotic/include/rai/Core/arrayDouble.h +36 -26
  17. robotic/include/rai/Core/defines.h +7 -9
  18. robotic/include/rai/Core/graph.h +33 -37
  19. robotic/include/rai/Core/h5.h +3 -1
  20. robotic/include/rai/Core/thread.h +12 -12
  21. robotic/include/rai/Core/util.h +58 -79
  22. robotic/include/rai/DataGen/rndStableConfigs.h +1 -0
  23. robotic/include/rai/DataGen/shapenetGrasps.h +5 -3
  24. robotic/include/rai/Geo/depth2PointCloud.h +2 -0
  25. robotic/include/rai/Geo/geo.h +24 -16
  26. robotic/include/rai/Geo/{fclInterface.h → i_fcl.h} +3 -1
  27. robotic/include/rai/Geo/mesh.h +22 -16
  28. robotic/include/rai/Geo/pairCollision.h +43 -43
  29. robotic/include/rai/Geo/signedDistanceFunctions.h +7 -5
  30. robotic/include/rai/Geo/stb_image.h +1 -1
  31. robotic/include/rai/Gui/RenderData.h +12 -9
  32. robotic/include/rai/Gui/opengl.h +6 -6
  33. robotic/include/rai/Gui/plot.h +1 -1
  34. robotic/include/rai/KOMO/komo.h +6 -3
  35. robotic/include/rai/KOMO/komo_NLP.h +2 -2
  36. robotic/include/rai/KOMO/manipTools.h +7 -2
  37. robotic/include/rai/KOMO/testProblems_KOMO.h +5 -9
  38. robotic/include/rai/Kin/F_forces.h +3 -3
  39. robotic/include/rai/Kin/cameraview.h +24 -36
  40. robotic/include/rai/Kin/dof_forceExchange.h +7 -7
  41. robotic/include/rai/Kin/feature.h +1 -1
  42. robotic/include/rai/Kin/frame.h +24 -26
  43. robotic/include/rai/Kin/{kin_physx.h → i_Physx.h} +11 -10
  44. robotic/include/rai/Kin/kin.h +30 -20
  45. robotic/include/rai/Kin/proxy.h +1 -1
  46. robotic/include/rai/Kin/simulation.h +20 -10
  47. robotic/include/rai/Kin/viewer.h +14 -1
  48. robotic/include/rai/LGP/LGP_TAMP_Abstraction.h +33 -0
  49. robotic/include/rai/LGP/LGP_Tool.h +4 -25
  50. robotic/include/rai/LGP/LGP_computers.h +1 -1
  51. robotic/include/rai/LGP/LGP_computers2.h +196 -0
  52. robotic/include/rai/LGP/NLP_Descriptor.h +5 -0
  53. robotic/include/rai/Logic/folWorld.h +1 -1
  54. robotic/include/rai/Logic/treeSearchDomain.h +2 -2
  55. robotic/include/rai/Optim/BayesOpt.h +13 -6
  56. robotic/include/rai/Optim/CMA/boundary_transformation.h +73 -0
  57. robotic/include/rai/Optim/CMA/cmaes.h +175 -0
  58. robotic/include/rai/Optim/CMA/cmaes_interface.h +68 -0
  59. robotic/include/rai/Optim/GlobalIterativeNewton.h +7 -3
  60. robotic/include/rai/Optim/NLP.h +23 -7
  61. robotic/include/rai/Optim/NLP_GraphSolver.h +1 -1
  62. robotic/include/rai/Optim/NLP_Solver.h +5 -5
  63. robotic/include/rai/Optim/constrained.h +4 -4
  64. robotic/include/rai/Optim/{opt-ceres.h → i_Ceres.h} +2 -2
  65. robotic/include/rai/Optim/{opt-nlopt.h → i_NLopt.h} +4 -0
  66. robotic/include/rai/Optim/lagrangian.h +7 -5
  67. robotic/include/rai/Optim/liblbfgs/liblbfgs.h +755 -0
  68. robotic/include/rai/Optim/m_EvoStrategies.h +114 -0
  69. robotic/include/rai/Optim/{gradient.h → m_Gradient.h} +13 -12
  70. robotic/include/rai/Optim/m_LBFGS.h +21 -0
  71. robotic/include/rai/Optim/m_LeastSquaresZeroOrder.h +104 -0
  72. robotic/include/rai/Optim/m_LocalGreedy.h +31 -0
  73. robotic/include/rai/Optim/m_NelderMead.h +23 -0
  74. robotic/include/rai/Optim/{newton.h → m_Newton.h} +7 -4
  75. robotic/include/rai/Optim/{SlackGaussNewton.h → m_SlackGaussNewton.h} +0 -10
  76. robotic/include/rai/Optim/options.h +8 -7
  77. robotic/include/rai/Optim/primalDual.h +10 -6
  78. robotic/include/rai/Optim/testProblems_Opt.h +25 -19
  79. robotic/include/rai/Optim/utils.h +16 -85
  80. robotic/include/rai/PathAlgos/ConfigurationProblem.h +3 -2
  81. robotic/include/rai/PathAlgos/RRT_PathFinder.h +2 -2
  82. robotic/include/rai/Perception/pcl.h +10 -10
  83. robotic/include/rai/Perception/surfels.h +1 -1
  84. robotic/include/rai/Search/TreeSearchNode.h +1 -1
  85. robotic/include/rai/ry/py-algo.h +17 -0
  86. robotic/include/rai/ry/types.h +4 -2
  87. robotic/librai.so +0 -0
  88. robotic/manipulation.py +5 -7
  89. robotic/meshTool +0 -0
  90. robotic/mujoco-import.py +8 -0
  91. robotic/rai-robotModels/g1/g1.g +11 -2
  92. robotic/rai-robotModels/g1/g1_29dof_conv.yml +64 -0
  93. robotic/rai-robotModels/g1/g1_clean.g +38 -73
  94. robotic/rai-robotModels/g1/meshes/head_link.h5 +0 -0
  95. robotic/rai-robotModels/g1/meshes/left_ankle_pitch_link.h5 +0 -0
  96. robotic/rai-robotModels/g1/meshes/left_ankle_roll_link.h5 +0 -0
  97. robotic/rai-robotModels/g1/meshes/left_elbow_link.h5 +0 -0
  98. robotic/rai-robotModels/g1/meshes/left_hip_pitch_link.h5 +0 -0
  99. robotic/rai-robotModels/g1/meshes/left_hip_roll_link.h5 +0 -0
  100. robotic/rai-robotModels/g1/meshes/left_hip_yaw_link.h5 +0 -0
  101. robotic/rai-robotModels/g1/meshes/left_knee_link.h5 +0 -0
  102. robotic/rai-robotModels/g1/meshes/left_rubber_hand.h5 +0 -0
  103. robotic/rai-robotModels/g1/meshes/left_shoulder_pitch_link.h5 +0 -0
  104. robotic/rai-robotModels/g1/meshes/left_shoulder_roll_link.h5 +0 -0
  105. robotic/rai-robotModels/g1/meshes/left_shoulder_yaw_link.h5 +0 -0
  106. robotic/rai-robotModels/g1/meshes/left_wrist_pitch_link.h5 +0 -0
  107. robotic/rai-robotModels/g1/meshes/left_wrist_roll_link.h5 +0 -0
  108. robotic/rai-robotModels/g1/meshes/left_wrist_yaw_link.h5 +0 -0
  109. robotic/rai-robotModels/g1/meshes/logo_link.h5 +0 -0
  110. robotic/rai-robotModels/g1/meshes/pelvis.h5 +0 -0
  111. robotic/rai-robotModels/g1/meshes/pelvis_contour_link.h5 +0 -0
  112. robotic/rai-robotModels/g1/meshes/right_ankle_pitch_link.h5 +0 -0
  113. robotic/rai-robotModels/g1/meshes/right_ankle_roll_link.h5 +0 -0
  114. robotic/rai-robotModels/g1/meshes/right_elbow_link.h5 +0 -0
  115. robotic/rai-robotModels/g1/meshes/right_hip_pitch_link.h5 +0 -0
  116. robotic/rai-robotModels/g1/meshes/right_hip_roll_link.h5 +0 -0
  117. robotic/rai-robotModels/g1/meshes/right_hip_yaw_link.h5 +0 -0
  118. robotic/rai-robotModels/g1/meshes/right_knee_link.h5 +0 -0
  119. robotic/rai-robotModels/g1/meshes/right_rubber_hand.h5 +0 -0
  120. robotic/rai-robotModels/g1/meshes/right_shoulder_pitch_link.h5 +0 -0
  121. robotic/rai-robotModels/g1/meshes/right_shoulder_roll_link.h5 +0 -0
  122. robotic/rai-robotModels/g1/meshes/right_shoulder_yaw_link.h5 +0 -0
  123. robotic/rai-robotModels/g1/meshes/right_wrist_pitch_link.h5 +0 -0
  124. robotic/rai-robotModels/g1/meshes/right_wrist_roll_link.h5 +0 -0
  125. robotic/rai-robotModels/g1/meshes/right_wrist_yaw_link.h5 +0 -0
  126. robotic/rai-robotModels/g1/meshes/torso_link.h5 +0 -0
  127. robotic/rai-robotModels/g1/meshes/waist_roll_link.h5 +0 -0
  128. robotic/rai-robotModels/g1/meshes/waist_support_link.h5 +0 -0
  129. robotic/rai-robotModels/g1/meshes/waist_yaw_link.h5 +0 -0
  130. robotic/rai-robotModels/objects/shelf.g +1 -1
  131. robotic/rai-robotModels/panda/meshes/finger.h5 +0 -0
  132. robotic/rai-robotModels/panda/meshes/hand.h5 +0 -0
  133. robotic/rai-robotModels/panda/meshes/link0.h5 +0 -0
  134. robotic/rai-robotModels/panda/meshes/link1.h5 +0 -0
  135. robotic/rai-robotModels/panda/meshes/link2.h5 +0 -0
  136. robotic/rai-robotModels/panda/meshes/link3.h5 +0 -0
  137. robotic/rai-robotModels/panda/meshes/link4.h5 +0 -0
  138. robotic/rai-robotModels/panda/meshes/link5.h5 +0 -0
  139. robotic/rai-robotModels/panda/meshes/link6.h5 +0 -0
  140. robotic/rai-robotModels/panda/meshes/link7.h5 +0 -0
  141. robotic/rai-robotModels/panda/panda.g +10 -10
  142. robotic/rai-robotModels/panda/panda_arm_hand_conv.g +24 -0
  143. robotic/rai-robotModels/panda/panda_arm_hand_conv.yml +24 -0
  144. robotic/rai-robotModels/panda/panda_clean.g +21 -45
  145. robotic/rai-robotModels/panda/panda_gripper.g +5 -7
  146. robotic/rai-robotModels/panda/panda_withoutCollisionModels.g +3 -11
  147. robotic/rai-robotModels/pr2/meshes/base.h5 +0 -0
  148. robotic/rai-robotModels/pr2/meshes/base_color.png +0 -0
  149. robotic/rai-robotModels/pr2/meshes/caster.h5 +0 -0
  150. robotic/rai-robotModels/pr2/meshes/elbow_flex.h5 +0 -0
  151. robotic/rai-robotModels/pr2/meshes/elbow_flex_color.png +0 -0
  152. robotic/rai-robotModels/pr2/meshes/forearm.h5 +0 -0
  153. robotic/rai-robotModels/pr2/meshes/forearm_color.png +0 -0
  154. robotic/rai-robotModels/pr2/meshes/forearm_roll.h5 +0 -0
  155. robotic/rai-robotModels/pr2/meshes/gripper_palm.h5 +0 -0
  156. robotic/rai-robotModels/pr2/meshes/gripper_palm_color.png +0 -0
  157. robotic/rai-robotModels/pr2/meshes/head_pan.h5 +0 -0
  158. robotic/rai-robotModels/pr2/meshes/head_pan_color.png +0 -0
  159. robotic/rai-robotModels/pr2/meshes/head_tilt.h5 +0 -0
  160. robotic/rai-robotModels/pr2/meshes/head_tilt_color.png +0 -0
  161. robotic/rai-robotModels/pr2/meshes/l_finger.h5 +0 -0
  162. robotic/rai-robotModels/pr2/meshes/l_finger_color.png +0 -0
  163. robotic/rai-robotModels/pr2/meshes/l_finger_tip.h5 +0 -0
  164. robotic/rai-robotModels/pr2/meshes/l_finger_tip_color.png +0 -0
  165. robotic/rai-robotModels/pr2/meshes/shoulder_lift.h5 +0 -0
  166. robotic/rai-robotModels/pr2/meshes/shoulder_lift_color.png +0 -0
  167. robotic/rai-robotModels/pr2/meshes/shoulder_pan.h5 +0 -0
  168. robotic/rai-robotModels/pr2/meshes/shoulder_pan_color.png +0 -0
  169. robotic/rai-robotModels/pr2/meshes/tilting_hokuyo.h5 +0 -0
  170. robotic/rai-robotModels/pr2/meshes/tilting_hokuyo_color.png +0 -0
  171. robotic/rai-robotModels/pr2/meshes/torso_lift.h5 +0 -0
  172. robotic/rai-robotModels/pr2/meshes/torso_lift_color.png +0 -0
  173. robotic/rai-robotModels/pr2/meshes/upper_arm.h5 +0 -0
  174. robotic/rai-robotModels/pr2/meshes/upper_arm_color.png +0 -0
  175. robotic/rai-robotModels/pr2/meshes/upper_arm_roll.h5 +0 -0
  176. robotic/rai-robotModels/pr2/meshes/upper_arm_roll_color.png +0 -0
  177. robotic/rai-robotModels/pr2/meshes/wheel.h5 +0 -0
  178. robotic/rai-robotModels/pr2/meshes/wheel_color.png +0 -0
  179. robotic/rai-robotModels/pr2/meshes/wrist_color.png +0 -0
  180. robotic/rai-robotModels/pr2/meshes/wrist_flex.h5 +0 -0
  181. robotic/rai-robotModels/pr2/meshes/wrist_roll.h5 +0 -0
  182. robotic/rai-robotModels/pr2/pr2.g +12 -12
  183. robotic/rai-robotModels/pr2/pr2_clean.g +122 -118
  184. robotic/rai-robotModels/pr2/pr2_conv.g +218 -0
  185. robotic/rai-robotModels/pr2/pr2_modifications.g +2 -2
  186. robotic/rai-robotModels/ranger/meshes/ranger_mini3.h5 +0 -0
  187. robotic/rai-robotModels/ranger/meshes/ranger_mini_v3_wheel.h5 +0 -0
  188. robotic/rai-robotModels/ranger/meshes/ranger_mini_v3_wheel_right.h5 +0 -0
  189. robotic/rai-robotModels/ranger/ranger.g +33 -0
  190. robotic/rai-robotModels/ranger/ranger_clean.g +18 -0
  191. robotic/rai-robotModels/ranger/ranger_mini_conv.g +14 -0
  192. robotic/rai-robotModels/robotiq/meshes/robotiq_arg2f_85_base_link.h5 +0 -0
  193. robotic/rai-robotModels/robotiq/meshes/robotiq_arg2f_85_inner_finger.h5 +0 -0
  194. robotic/rai-robotModels/robotiq/meshes/robotiq_arg2f_85_inner_knuckle.h5 +0 -0
  195. robotic/rai-robotModels/robotiq/meshes/robotiq_arg2f_85_outer_finger.h5 +0 -0
  196. robotic/rai-robotModels/robotiq/meshes/robotiq_arg2f_85_outer_knuckle.h5 +0 -0
  197. robotic/rai-robotModels/robotiq/robotiq.g +2 -2
  198. robotic/rai-robotModels/robotiq/robotiq_arg2f_85_model_conv.yml +19 -0
  199. robotic/rai-robotModels/robotiq/robotiq_clean.g +16 -16
  200. robotic/rai-robotModels/scenarios/ballFinger.g +2 -2
  201. robotic/rai-robotModels/scenarios/liftRing.g +2 -2
  202. robotic/rai-robotModels/scenarios/pandaFloatingGripper.g +1 -1
  203. robotic/rai-robotModels/scenarios/pandaSingle.g +1 -1
  204. robotic/rai-robotModels/scenarios/panda_fixRobotiq.g +3 -3
  205. robotic/rai-robotModels/tests/arm.g +18 -19
  206. robotic/rai-robotModels/tests/compound.g +3 -6
  207. robotic/rai-robotModels/ur10/meshes/base.h5 +0 -0
  208. robotic/rai-robotModels/ur10/meshes/forearm.h5 +0 -0
  209. robotic/rai-robotModels/ur10/meshes/shoulder.h5 +0 -0
  210. robotic/rai-robotModels/ur10/meshes/upperarm.h5 +0 -0
  211. robotic/rai-robotModels/ur10/meshes/wrist1.h5 +0 -0
  212. robotic/rai-robotModels/ur10/meshes/wrist2.h5 +0 -0
  213. robotic/rai-robotModels/ur10/meshes/wrist3.h5 +0 -0
  214. robotic/rai-robotModels/ur10/ur10.g +2 -2
  215. robotic/rai-robotModels/ur10/ur10_clean.g +8 -8
  216. robotic/rai-robotModels/ur10/ur10_conv.g +17 -0
  217. robotic/ry-h5info +3 -8
  218. robotic/ry-test +6 -5
  219. robotic/ry-urdfConvert.py +74 -0
  220. robotic/ry-view +28 -6
  221. robotic/src/__init__.py +0 -0
  222. robotic/src/cleanMeshes.py +59 -0
  223. robotic/src/h5_helper.py +46 -0
  224. robotic/src/h5_helper.py~ +42 -0
  225. robotic/src/mesh_helper.py +395 -0
  226. robotic/src/meshlabFilters.mlx +20 -0
  227. robotic/src/mujoco_io.py +242 -0
  228. robotic/src/urdf_io.py +237 -0
  229. robotic/src/yaml_helper.py +29 -0
  230. robotic/version.py +1 -1
  231. {robotic-0.2.8.dev4.data → robotic-0.3.4.dev5.data}/scripts/ry-h5info +3 -8
  232. {robotic-0.2.8.dev4.data → robotic-0.3.4.dev5.data}/scripts/ry-test +6 -5
  233. robotic-0.3.4.dev5.data/scripts/ry-urdfConvert.py +74 -0
  234. robotic-0.3.4.dev5.data/scripts/ry-view +46 -0
  235. {robotic-0.2.8.dev4.dist-info → robotic-0.3.4.dev5.dist-info}/METADATA +20 -23
  236. robotic-0.3.4.dev5.dist-info/RECORD +386 -0
  237. {robotic-0.2.8.dev4.dist-info → robotic-0.3.4.dev5.dist-info}/WHEEL +1 -1
  238. robotic/nlp.py +0 -113
  239. robotic/rai-robotModels/baxter/baxter.g +0 -49
  240. robotic/rai-robotModels/baxter/baxter_clean.g +0 -116
  241. robotic/rai-robotModels/baxter/baxter_clean2.g +0 -205
  242. robotic/rai-robotModels/baxter/baxter_clean3.g +0 -223
  243. robotic/rai-robotModels/baxter/baxter_description/meshes/base/PEDESTAL.ply +0 -0
  244. robotic/rai-robotModels/baxter/baxter_description/meshes/base/pedestal_link_collision.ply +0 -0
  245. robotic/rai-robotModels/baxter/baxter_description/meshes/head/H0.ply +0 -0
  246. robotic/rai-robotModels/baxter/baxter_description/meshes/head/H1.ply +0 -0
  247. robotic/rai-robotModels/baxter/baxter_description/meshes/lower_elbow/E1.ply +0 -0
  248. robotic/rai-robotModels/baxter/baxter_description/meshes/lower_forearm/W1.ply +0 -0
  249. robotic/rai-robotModels/baxter/baxter_description/meshes/lower_shoulder/S1.ply +0 -0
  250. robotic/rai-robotModels/baxter/baxter_description/meshes/torso/base_link.ply +0 -0
  251. robotic/rai-robotModels/baxter/baxter_description/meshes/torso/base_link_collision.ply +0 -0
  252. robotic/rai-robotModels/baxter/baxter_description/meshes/upper_elbow/E0.ply +0 -0
  253. robotic/rai-robotModels/baxter/baxter_description/meshes/upper_forearm/W0.ply +0 -0
  254. robotic/rai-robotModels/baxter/baxter_description/meshes/upper_shoulder/S0.ply +0 -0
  255. robotic/rai-robotModels/baxter/baxter_description/meshes/wrist/W2.ply +0 -0
  256. robotic/rai-robotModels/baxter/baxter_new.g +0 -53
  257. robotic/rai-robotModels/baxter/rethink_ee_description/meshes/electric_gripper/electric_gripper_base.ply +0 -0
  258. robotic/rai-robotModels/baxter/rethink_ee_description/meshes/electric_gripper/fingers/extended_narrow.ply +0 -0
  259. robotic/rai-robotModels/baxter/rethink_ee_description/meshes/electric_gripper/fingers/half_round_tip.ply +0 -0
  260. robotic/rai-robotModels/baxter/rethink_ee_description/meshes/electric_gripper/fingers/paddle_tip.ply +0 -0
  261. robotic/rai-robotModels/baxter/rethink_ee_description/meshes/pneumatic_gripper/pneumatic_gripper_base.ply +0 -0
  262. robotic/rai-robotModels/baxter/rethink_ee_description/meshes/pneumatic_gripper/pneumatic_gripper_w_cup.ply +0 -0
  263. robotic/rai-robotModels/g1/meshes/head_link.ply +0 -0
  264. robotic/rai-robotModels/g1/meshes/left_ankle_pitch_link.ply +0 -0
  265. robotic/rai-robotModels/g1/meshes/left_ankle_roll_link.ply +0 -0
  266. robotic/rai-robotModels/g1/meshes/left_elbow_link.ply +0 -0
  267. robotic/rai-robotModels/g1/meshes/left_hand_index_0_link.ply +0 -0
  268. robotic/rai-robotModels/g1/meshes/left_hand_index_1_link.ply +0 -0
  269. robotic/rai-robotModels/g1/meshes/left_hand_middle_0_link.ply +0 -0
  270. robotic/rai-robotModels/g1/meshes/left_hand_middle_1_link.ply +0 -0
  271. robotic/rai-robotModels/g1/meshes/left_hand_palm_link.ply +0 -0
  272. robotic/rai-robotModels/g1/meshes/left_hand_thumb_0_link.ply +0 -0
  273. robotic/rai-robotModels/g1/meshes/left_hand_thumb_1_link.ply +0 -0
  274. robotic/rai-robotModels/g1/meshes/left_hand_thumb_2_link.ply +0 -0
  275. robotic/rai-robotModels/g1/meshes/left_hip_pitch_link.ply +0 -0
  276. robotic/rai-robotModels/g1/meshes/left_hip_roll_link.ply +0 -0
  277. robotic/rai-robotModels/g1/meshes/left_hip_yaw_link.ply +0 -0
  278. robotic/rai-robotModels/g1/meshes/left_knee_link.ply +0 -0
  279. robotic/rai-robotModels/g1/meshes/left_rubber_hand.ply +0 -0
  280. robotic/rai-robotModels/g1/meshes/left_shoulder_pitch_link.ply +0 -0
  281. robotic/rai-robotModels/g1/meshes/left_shoulder_roll_link.ply +0 -0
  282. robotic/rai-robotModels/g1/meshes/left_shoulder_yaw_link.ply +0 -0
  283. robotic/rai-robotModels/g1/meshes/left_wrist_pitch_link.ply +0 -0
  284. robotic/rai-robotModels/g1/meshes/left_wrist_roll_link.ply +0 -0
  285. robotic/rai-robotModels/g1/meshes/left_wrist_roll_rubber_hand.ply +0 -0
  286. robotic/rai-robotModels/g1/meshes/left_wrist_yaw_link.ply +0 -0
  287. robotic/rai-robotModels/g1/meshes/logo_link.ply +0 -0
  288. robotic/rai-robotModels/g1/meshes/pelvis.ply +0 -0
  289. robotic/rai-robotModels/g1/meshes/pelvis_contour_link.ply +0 -0
  290. robotic/rai-robotModels/g1/meshes/right_ankle_pitch_link.ply +0 -0
  291. robotic/rai-robotModels/g1/meshes/right_ankle_roll_link.ply +0 -0
  292. robotic/rai-robotModels/g1/meshes/right_elbow_link.ply +0 -0
  293. robotic/rai-robotModels/g1/meshes/right_hand_index_0_link.ply +0 -0
  294. robotic/rai-robotModels/g1/meshes/right_hand_index_1_link.ply +0 -0
  295. robotic/rai-robotModels/g1/meshes/right_hand_middle_0_link.ply +0 -0
  296. robotic/rai-robotModels/g1/meshes/right_hand_middle_1_link.ply +0 -0
  297. robotic/rai-robotModels/g1/meshes/right_hand_palm_link.ply +0 -0
  298. robotic/rai-robotModels/g1/meshes/right_hand_thumb_0_link.ply +0 -0
  299. robotic/rai-robotModels/g1/meshes/right_hand_thumb_1_link.ply +0 -0
  300. robotic/rai-robotModels/g1/meshes/right_hand_thumb_2_link.ply +0 -0
  301. robotic/rai-robotModels/g1/meshes/right_hip_pitch_link.ply +0 -0
  302. robotic/rai-robotModels/g1/meshes/right_hip_roll_link.ply +0 -0
  303. robotic/rai-robotModels/g1/meshes/right_hip_yaw_link.ply +0 -0
  304. robotic/rai-robotModels/g1/meshes/right_knee_link.ply +0 -0
  305. robotic/rai-robotModels/g1/meshes/right_rubber_hand.ply +0 -0
  306. robotic/rai-robotModels/g1/meshes/right_shoulder_pitch_link.ply +0 -0
  307. robotic/rai-robotModels/g1/meshes/right_shoulder_roll_link.ply +0 -0
  308. robotic/rai-robotModels/g1/meshes/right_shoulder_yaw_link.ply +0 -0
  309. robotic/rai-robotModels/g1/meshes/right_wrist_pitch_link.ply +0 -0
  310. robotic/rai-robotModels/g1/meshes/right_wrist_roll_link.ply +0 -0
  311. robotic/rai-robotModels/g1/meshes/right_wrist_roll_rubber_hand.ply +0 -0
  312. robotic/rai-robotModels/g1/meshes/right_wrist_yaw_link.ply +0 -0
  313. robotic/rai-robotModels/g1/meshes/torso_constraint_L_link.ply +0 -0
  314. robotic/rai-robotModels/g1/meshes/torso_constraint_L_rod_link.ply +0 -0
  315. robotic/rai-robotModels/g1/meshes/torso_constraint_R_link.ply +0 -0
  316. robotic/rai-robotModels/g1/meshes/torso_constraint_R_rod_link.ply +0 -0
  317. robotic/rai-robotModels/g1/meshes/torso_link.ply +0 -0
  318. robotic/rai-robotModels/g1/meshes/waist_constraint_L.ply +0 -0
  319. robotic/rai-robotModels/g1/meshes/waist_constraint_R.ply +0 -0
  320. robotic/rai-robotModels/g1/meshes/waist_roll_link.ply +0 -0
  321. robotic/rai-robotModels/g1/meshes/waist_support_link.ply +0 -0
  322. robotic/rai-robotModels/g1/meshes/waist_yaw_link.ply +0 -0
  323. robotic/rai-robotModels/panda/franka_description/meshes/collision/finger.stl +0 -0
  324. robotic/rai-robotModels/panda/franka_description/meshes/collision/hand.stl +0 -0
  325. robotic/rai-robotModels/panda/franka_description/meshes/collision/link0.stl +0 -0
  326. robotic/rai-robotModels/panda/franka_description/meshes/collision/link1.stl +0 -0
  327. robotic/rai-robotModels/panda/franka_description/meshes/collision/link2.stl +0 -0
  328. robotic/rai-robotModels/panda/franka_description/meshes/collision/link3.stl +0 -0
  329. robotic/rai-robotModels/panda/franka_description/meshes/collision/link4.stl +0 -0
  330. robotic/rai-robotModels/panda/franka_description/meshes/collision/link5.stl +0 -0
  331. robotic/rai-robotModels/panda/franka_description/meshes/collision/link6.stl +0 -0
  332. robotic/rai-robotModels/panda/franka_description/meshes/collision/link7.stl +0 -0
  333. robotic/rai-robotModels/panda/franka_description/meshes/visual/HOWTO.sh +0 -10
  334. robotic/rai-robotModels/panda/franka_description/meshes/visual/HOWTO2.sh +0 -7
  335. robotic/rai-robotModels/panda/franka_description/meshes/visual/convMeshes.mlx +0 -38
  336. robotic/rai-robotModels/panda/franka_description/meshes/visual/finger.ply +0 -0
  337. robotic/rai-robotModels/panda/franka_description/meshes/visual/hand.ply +0 -0
  338. robotic/rai-robotModels/panda/franka_description/meshes/visual/link0.ply +0 -0
  339. robotic/rai-robotModels/panda/franka_description/meshes/visual/link1.ply +0 -0
  340. robotic/rai-robotModels/panda/franka_description/meshes/visual/link2.ply +0 -0
  341. robotic/rai-robotModels/panda/franka_description/meshes/visual/link3.ply +0 -0
  342. robotic/rai-robotModels/panda/franka_description/meshes/visual/link4.ply +0 -0
  343. robotic/rai-robotModels/panda/franka_description/meshes/visual/link5.ply +0 -0
  344. robotic/rai-robotModels/panda/franka_description/meshes/visual/link6.ply +0 -0
  345. robotic/rai-robotModels/panda/franka_description/meshes/visual/link7.ply +0 -0
  346. robotic/rai-robotModels/panda/franka_description/meshes/visual/script.mlx +0 -28
  347. robotic/rai-robotModels/pr2/pr2_description/meshes/base_v0/base.ply +0 -0
  348. robotic/rai-robotModels/pr2/pr2_description/meshes/base_v0/base_L.ply +0 -0
  349. robotic/rai-robotModels/pr2/pr2_description/meshes/base_v0/caster.ply +0 -0
  350. robotic/rai-robotModels/pr2/pr2_description/meshes/base_v0/caster_L.ply +0 -0
  351. robotic/rai-robotModels/pr2/pr2_description/meshes/base_v0/pr2_wheel.ply +0 -0
  352. robotic/rai-robotModels/pr2/pr2_description/meshes/base_v0/wheel.ply +0 -0
  353. robotic/rai-robotModels/pr2/pr2_description/meshes/forearm_v0/forearm.ply +0 -0
  354. robotic/rai-robotModels/pr2/pr2_description/meshes/forearm_v0/wrist_flex.ply +0 -0
  355. robotic/rai-robotModels/pr2/pr2_description/meshes/forearm_v0/wrist_roll.ply +0 -0
  356. robotic/rai-robotModels/pr2/pr2_description/meshes/forearm_v0/wrist_roll_L.ply +0 -0
  357. robotic/rai-robotModels/pr2/pr2_description/meshes/gripper_v0/gripper_palm.ply +0 -0
  358. robotic/rai-robotModels/pr2/pr2_description/meshes/gripper_v0/l_finger.ply +0 -0
  359. robotic/rai-robotModels/pr2/pr2_description/meshes/gripper_v0/l_finger_tip.ply +0 -0
  360. robotic/rai-robotModels/pr2/pr2_description/meshes/head_v0/head_pan.ply +0 -0
  361. robotic/rai-robotModels/pr2/pr2_description/meshes/head_v0/head_pan_L.ply +0 -0
  362. robotic/rai-robotModels/pr2/pr2_description/meshes/head_v0/head_tilt.ply +0 -0
  363. robotic/rai-robotModels/pr2/pr2_description/meshes/head_v0/head_tilt_L.ply +0 -0
  364. robotic/rai-robotModels/pr2/pr2_description/meshes/shoulder_v0/shoulder_lift.ply +0 -0
  365. robotic/rai-robotModels/pr2/pr2_description/meshes/shoulder_v0/shoulder_pan.ply +0 -0
  366. robotic/rai-robotModels/pr2/pr2_description/meshes/shoulder_v0/shoulder_yaw.ply +0 -0
  367. robotic/rai-robotModels/pr2/pr2_description/meshes/shoulder_v0/upper_arm_roll.ply +0 -0
  368. robotic/rai-robotModels/pr2/pr2_description/meshes/shoulder_v0/upper_arm_roll_L.ply +0 -0
  369. robotic/rai-robotModels/pr2/pr2_description/meshes/tilting_laser_v0/hok_tilt.ply +0 -0
  370. robotic/rai-robotModels/pr2/pr2_description/meshes/tilting_laser_v0/tilting_hokuyo.ply +0 -0
  371. robotic/rai-robotModels/pr2/pr2_description/meshes/tilting_laser_v0/tilting_hokuyo_L.ply +0 -0
  372. robotic/rai-robotModels/pr2/pr2_description/meshes/torso_v0/torso.ply +0 -0
  373. robotic/rai-robotModels/pr2/pr2_description/meshes/torso_v0/torso_lift.ply +0 -0
  374. robotic/rai-robotModels/pr2/pr2_description/meshes/torso_v0/torso_lift_L.ply +0 -0
  375. robotic/rai-robotModels/pr2/pr2_description/meshes/upper_arm_v0/elbow_flex.ply +0 -0
  376. robotic/rai-robotModels/pr2/pr2_description/meshes/upper_arm_v0/forearm_roll.ply +0 -0
  377. robotic/rai-robotModels/pr2/pr2_description/meshes/upper_arm_v0/forearm_roll_L.ply +0 -0
  378. robotic/rai-robotModels/pr2/pr2_description/meshes/upper_arm_v0/upper_arm.ply +0 -0
  379. robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_base_link.ply +0 -0
  380. robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_base_link_x.ply +0 -10
  381. robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_inner_finger.ply +0 -0
  382. robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_inner_knuckle.ply +0 -0
  383. robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_outer_finger.ply +0 -0
  384. robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_outer_knuckle.ply +0 -0
  385. robotic/rai-robotModels/robotiq/meshes/visual/robotiq_arg2f_85_pad.ply +0 -0
  386. robotic/rai-robotModels/robotiq/meshes/visual/robotiq_gripper_coupling.ply +0 -0
  387. robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/Base.ply +0 -0
  388. robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/Forearm.ply +0 -0
  389. robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/Shoulder.ply +0 -0
  390. robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/UpperArm.ply +0 -0
  391. robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/Wrist1.ply +0 -0
  392. robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/Wrist2.ply +0 -0
  393. robotic/rai-robotModels/ur10/ur_description/meshes/ur10/visual/Wrist3.ply +0 -0
  394. robotic/ry-urdf2rai +0 -222
  395. robotic/ry-urdf2yaml +0 -250
  396. robotic-0.2.8.dev4.data/scripts/ry-urdf2rai +0 -222
  397. robotic-0.2.8.dev4.data/scripts/ry-urdf2yaml +0 -250
  398. robotic-0.2.8.dev4.data/scripts/ry-view +0 -24
  399. robotic-0.2.8.dev4.dist-info/RECORD +0 -413
  400. /robotic/include/rai/{Geo → Algo}/Lewiner/LookUpTable.h +0 -0
  401. /robotic/include/rai/Geo/{assimpInterface.h → i_assimp.h} +0 -0
  402. /robotic/include/rai/Kin/{kin_bullet.h → i_Bullet.h} +0 -0
  403. /robotic/include/rai/Kin/{kin_feather.h → i_Feather.h} +0 -0
  404. /robotic/include/rai/Kin/{kin_ode.h → i_Ode.h} +0 -0
  405. /robotic/include/rai/Optim/{opt-ipopt.h → i_Ipopt.h} +0 -0
  406. /robotic/rai-robotModels/robotiq/meshes/{visual/robotiq_ft300.ply → robotiq_ft300.ply} +0 -0
  407. {robotic-0.2.8.dev4.data → robotic-0.3.4.dev5.data}/scripts/ry-bot +0 -0
  408. {robotic-0.2.8.dev4.data → robotic-0.3.4.dev5.data}/scripts/ry-info +0 -0
  409. {robotic-0.2.8.dev4.data → robotic-0.3.4.dev5.data}/scripts/ry-meshTool +0 -0
  410. {robotic-0.2.8.dev4.dist-info → robotic-0.3.4.dev5.dist-info/licenses}/LICENSE +0 -0
  411. {robotic-0.2.8.dev4.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
- d(&d0),
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
- d(&d0),
75
+ _shape(&d0),
77
76
  isReference(a.isReference),
78
77
  M(a.M),
79
78
  special(a.special) {
80
- //if(a.jac) jac = std::move(a.jac);
81
- CHECK_EQ(a.d, &a.d0, "");
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; resetD(); resizeMEM(d0, false); return *this; }
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; resetD(); resizeMEM(d0, true); return *this; }
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; resetD();
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; resetD(); resizeMEM(d0*d1, false); return *this; }
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; resetD(); resizeMEM(d0*d1, true); return *this; }
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
- resetD();
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; resetD(); resizeMEM(d0*d1*d2, false); return *this; }
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; resetD(); resizeMEM(d0*d1*d2, true); return *this; }
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
- resetD();
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; resetD();
169
- uint j;
170
- for(j=0; j<nd && j<3; j++) {(&d0)[j]=dim[j]; }
171
- if(nd>3) { d=new uint[nd]; memmove(d, dim, nd*sizeof(uint)); }
172
- uint64_t S;
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; resetD();
182
- uint j;
183
- for(j=0; j<nd && j<3; j++) {(&d0)[j]=dim[j]; }
184
- if(nd>3) { d=new uint[nd]; memmove(d, dim, nd*sizeof(uint)); }
185
- uint64_t S;
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; resetD();
195
- if(nd>0){
196
- d0=dim[0];
197
- if(nd>1){
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
- resetD();
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; resetD();
237
- if(nd>3) { d=new uint[nd]; memmove(d, a.d, nd*sizeof(uint)); }
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; resetD();
246
- if(nd>3) { d=new uint[nd]; memmove(d, a.d, nd*sizeof(uint)); }
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(!d && k<3) return (&d0)[k]; else return d[k];
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(d && d!=&d0) { delete[] d; d=NULL; }
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>::resetD() {
390
- if(d && d!=&d0) { delete[] d; d=NULL; }
391
- d=&d0;
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> void Array<T>::insColumns(int i, uint k) {
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(d, nd);
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.first, I.second);
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]);
@@ -778,7 +778,7 @@ template<class T> Array<T> Array<T>::operator()(std::pair<int, int> I) const {
778
778
  /// range reference access
779
779
  template<class T> Array<T> Array<T>::operator()(int i, std::pair<int, int> J) const {
780
780
  Array<T> z;
781
- z.referToRange(*this, i, J.first, J.second);
781
+ z.referToRange(*this, i, J);
782
782
  // if(J.size()==2)
783
783
  // else if(J.size()==0) z.referToDim(*this, i);
784
784
  // else if(J.size()==1) z.referToDim(*this, i, J.begin()[0]);
@@ -789,7 +789,7 @@ template<class T> Array<T> Array<T>::operator()(int i, std::pair<int, int> J) co
789
789
  /// range reference access
790
790
  template<class T> Array<T> Array<T>::operator()(int i, int j, std::initializer_list<int> K) const {
791
791
  Array<T> z;
792
- 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]});
793
793
  else if(K.size()==0) z.referToDim(*this, i, j);
794
794
  else if(K.size()==1) z.referToDim(*this, i, j, K.begin()[0]);
795
795
  else HALT("range list needs 0,1, or 2 entries exactly");
@@ -824,8 +824,9 @@ template<class T> Array<T> Array<T>::copy() const { return Array<T>(*this); }
824
824
  /** @brief a sub array of a 1D Array (corresponds to matlab [i:I]); when
825
825
  the upper limit I is -1, it is replaced by the max limit (like
826
826
  [i:]) */
827
- template<class T> Array<T> Array<T>::sub(int i, int I) const {
827
+ template<class T> Array<T> Array<T>::sub(std::pair<int, int> _I) const {
828
828
  CHECK_EQ(nd, 1, "1D range error ");
829
+ int i=_I.first, I=_I.second-1;
829
830
  Array<T> x;
830
831
  if(i<0) i+=d0;
831
832
  if(I<0) I+=d0;
@@ -842,8 +843,9 @@ template<class T> Array<T> Array<T>::sub(int i, int I) const {
842
843
  /** @brief copies a sub array of a 2D Array (corresponds to matlab [i:I, j:J]);
843
844
  when the upper limits I or J are -1, they are replaced by the
844
845
  max limit (like [i:, j:]) */
845
- template<class T> Array<T> Array<T>::sub(int i, int I, int j, int J) const {
846
+ template<class T> Array<T> Array<T>::sub(std::pair<int, int> _I, std::pair<int, int> _J) const {
846
847
  CHECK_EQ(nd, 2, "2D range error ");
848
+ int i=_I.first, I=_I.second-1, j=_J.first, J=_J.second-1;
847
849
  Array<T> x;
848
850
  if(i<0) i+=d0;
849
851
  if(j<0) j+=d1;
@@ -862,8 +864,9 @@ template<class T> Array<T> Array<T>::sub(int i, int I, int j, int J) const {
862
864
  /** @brief copies a sub array of a 3D Array (corresponds to matlab [i:I, j:J]);
863
865
  when the upper limits I or J are -1, they are replaced by the
864
866
  max limit (like [i:, j:]) */
865
- template<class T> Array<T> Array<T>::sub(int i, int I, int j, int J, int k, int K) const {
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 {
866
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;
867
870
  Array<T> x;
868
871
  if(i<0) i+=d0;
869
872
  if(j<0) j+=d1;
@@ -888,8 +891,9 @@ template<class T> Array<T> Array<T>::sub(int i, int I, int j, int J, int k, int
888
891
  runs from i to I (as explained above) while the second index runs
889
892
  over the columns explicitly referred to by cols. (col doesn't have
890
893
  to be ordered or could also contain some columns multiply) */
891
- template<class T> Array<T> Array<T>::sub(int i, int I, Array<uint> cols) const {
894
+ template<class T> Array<T> Array<T>::pick(std::pair<int, int> _I, Array<uint> cols) const {
892
895
  CHECK_EQ(nd, 2, "2D range error ");
896
+ int i=_I.first, I=_I.second-1;
893
897
  Array<T> x;
894
898
  if(i<0) i+=d0;
895
899
  if(I<0) I+=d0;
@@ -899,7 +903,7 @@ template<class T> Array<T> Array<T>::sub(int i, int I, Array<uint> cols) const {
899
903
  return x;
900
904
  }
901
905
 
902
- template<class T> Array<T> Array<T>::sub(Array<uint> elems) const {
906
+ template<class T> Array<T> Array<T>::pick(Array<uint> elems) const {
903
907
  Array<T> x;
904
908
  if(nd==1) {
905
909
  x.resize(elems.N);
@@ -927,7 +931,7 @@ template<class T> Array<T> Array<T>::sub(Array<uint> elems) const {
927
931
  */
928
932
  template<class T>
929
933
  Array<T> Array<T>::row(uint row_index) const {
930
- return sub(row_index, row_index, 0, d1 - 1);
934
+ return sub({row_index, row_index+1},{ 0, d1 - 1+1});
931
935
  }
932
936
 
933
937
  /**
@@ -942,7 +946,7 @@ Array<T> Array<T>::row(uint row_index) const {
942
946
  */
943
947
  template<class T>
944
948
  Array<T> Array<T>::col(uint col_index) const {
945
- 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);
946
950
  }
947
951
 
948
952
  /**
@@ -958,7 +962,7 @@ Array<T> Array<T>::col(uint col_index) const {
958
962
  */
959
963
  template<class T>
960
964
  Array<T> Array<T>::rows(uint start_row, uint end_row) const {
961
- return sub(start_row, end_row - 1, 0, d1 - 1);
965
+ return sub({start_row, end_row - 1+1},{ 0, d1 - 1+1});
962
966
  }
963
967
 
964
968
  /**
@@ -974,7 +978,7 @@ Array<T> Array<T>::rows(uint start_row, uint end_row) const {
974
978
  */
975
979
  template<class T>
976
980
  Array<T> Array<T>::cols(uint start_col, uint end_col) const {
977
- return sub(0, d0 - 1, start_col, end_col - 1);
981
+ return sub({0, d0 - 1+1},{ start_col, end_col - 1+1});
978
982
  }
979
983
 
980
984
  /// makes this array a reference to the C buffer
@@ -1010,6 +1014,10 @@ template<class T> Array<T>& Array<T>::operator=(const Array<T>& a) {
1010
1014
  if(memMove) memmove(p, a.p, sizeT*N);
1011
1015
  else for(uint i=0; i<N; i++) p[i]=a.p[i];
1012
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
+ }
1013
1021
  return *this;
1014
1022
  }
1015
1023
 
@@ -1044,7 +1052,7 @@ template<class T> Array<T> catCol(const Array<Array<T>*>& X) {
1044
1052
  // d1+=x->d1;
1045
1053
  // }
1046
1054
  } else {
1047
- z.resize(d0, d1);
1055
+ z.resize(d0, d1).setZero();
1048
1056
  d1=0;
1049
1057
  for(const Array<T>* x: X) { z.setMatrixBlock(*x, 0, d1); d1+=x->nd==2?x->d1:1; }
1050
1058
  }
@@ -1065,7 +1073,7 @@ template<class T> Array<T> catCol(const Array<Array<T>>& X) {
1065
1073
  }
1066
1074
 
1067
1075
  /// set all entries to same value x [default: don't change dimension]
1068
- template<class T> void Array<T>::setUni(const T& x, int d) {
1076
+ template<class T> void Array<T>::setConst(const T& x, int d) {
1069
1077
  if(d!=-1) resize(d);
1070
1078
  uint i;
1071
1079
  for(i=0; i<N; i++) elem(i)=x;
@@ -1077,7 +1085,9 @@ template<class T> void Array<T>::setId(int d) {
1077
1085
  CHECK(d!=-1 || (nd==2 && d0==d1), "need squared matrix to set to identity");
1078
1086
  if(d!=-1) resize(d, d);
1079
1087
  setZero();
1080
- for(uint i=0; i<d0; i++) operator()(i, i)=(T)1;
1088
+ if constexpr(std::is_scalar_v<T>){
1089
+ for(uint i=0; i<d0; i++) operator()(i, i)=(T)1;
1090
+ }else NIY;
1081
1091
  }
1082
1092
 
1083
1093
  template<class T> void Array<T>::setDiag(const T& x, int d) {
@@ -1114,13 +1124,38 @@ template<class T> void Array<T>::setBlockMatrix(const Array<T>& A, const Array<T
1114
1124
  template<class T> void Array<T>::setBlockMatrix(const Array<T>& A, const Array<T>& B) {
1115
1125
  CHECK(A.nd==2 && B.nd==2, "");
1116
1126
  CHECK(A.d1==B.d1, "");
1117
- resize(A.d0+B.d0, A.d1);
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
+
1118
1139
  setMatrixBlock(A, 0, 0);
1119
1140
  setMatrixBlock(B, A.d0, 0);
1120
1141
  }
1121
1142
 
1122
1143
  /// constructs a vector x=[a, b]
1123
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
+ }
1124
1159
  CHECK(a.nd==1 && b.nd==1, "");
1125
1160
  resize(a.N+b.N);
1126
1161
  setVectorBlock(a, 0); //for(i=0;i<a.N;i++) operator()(i )=a(i);
@@ -1129,6 +1164,13 @@ template<class T> void Array<T>::setBlockVector(const Array<T>& a, const Array<T
1129
1164
 
1130
1165
  /// write the matrix B into 'this' matrix at location lo0, lo1
1131
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
+
1132
1174
  CHECK(!special && !B.special, "");
1133
1175
  CHECK(B.nd==1 || B.nd==2, "");
1134
1176
  if(B.nd==2) {
@@ -1152,18 +1194,29 @@ template<class T> void Array<T>::setVectorBlock(const Array<T>& B, uint lo) {
1152
1194
  CHECK(nd==1 && B.nd==1 && lo+B.N<=N, "");
1153
1195
  uint i;
1154
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
+ }
1155
1204
  }
1156
1205
 
1157
1206
  /// sorted permutation of length \c n
1158
1207
  template<class T> void Array<T>::setStraightPerm(int n) {
1159
1208
  if(n!=-1) resize(n);
1160
- for(uint i=0; i<N; i++) elem(i)=(T)i;
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;
1161
1212
  }
1162
1213
 
1163
1214
  /// reverse sorted permutation of lenth \c N
1164
1215
  template<class T> void Array<T>::setReversePerm(int n) {
1165
1216
  if(n!=-1) resize(n);
1166
- for(uint i=0; i<N; i++) elem(N-1-i)=(T)i;
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;
1167
1220
  }
1168
1221
 
1169
1222
  /// permute all elements randomly
@@ -1187,7 +1240,7 @@ template<class T> Array<T>& Array<T>::setCarray(const T* buffer, uint D0) {
1187
1240
  }
1188
1241
 
1189
1242
  /// 'this' becomes a copy (not reference to!) of the 2D C array
1190
- template<class T> Array<T>& Array<T>::setCarray(const T** buffer, uint D0, uint D1) {
1243
+ template<class T> Array<T>& Array<T>::setCarray(T* const* buffer, uint D0, uint D1) {
1191
1244
  resize(D0, D1);
1192
1245
  uint i, j;
1193
1246
  for(i=0; i<d0; i++) {
@@ -1206,8 +1259,9 @@ template<class T> void Array<T>::referTo(const Array<T>& a) {
1206
1259
  }
1207
1260
 
1208
1261
  /// make this array a subarray reference to \c a
1209
- template<class T> void Array<T>::referToRange(const Array<T>& a, int i_lo, int i_up) {
1262
+ template<class T> void Array<T>::referToRange(const Array<T>& a, std::pair<int, int> I) {
1210
1263
  CHECK_LE(a.nd, 3, "not implemented yet");
1264
+ int i_lo=I.first, i_up=I.second-1;
1211
1265
  if(i_lo<0) i_lo+=a.d0;
1212
1266
  if(i_up<0) i_up+=a.d0;
1213
1267
  if(i_lo>i_up) { clear(); return; }
@@ -1225,9 +1279,10 @@ template<class T> void Array<T>::referToRange(const Array<T>& a, int i_lo, int i
1225
1279
  }
1226
1280
 
1227
1281
  /// make this array a subarray reference to \c a
1228
- template<class T> void Array<T>::referToRange(const Array<T>& a, int i, int j_lo, int j_up) {
1282
+ template<class T> void Array<T>::referToRange(const Array<T>& a, int i, std::pair<int, int> J) {
1229
1283
  CHECK(a.nd>1, "does not make sense");
1230
1284
  CHECK_LE(a.nd, 3, "not implemented yet");
1285
+ int j_lo=J.first, j_up=J.second-1;
1231
1286
  if(i<0) i+=a.d0;
1232
1287
  if(j_lo<0) j_lo+=a.d1;
1233
1288
  if(j_up<0) j_up+=a.d1;
@@ -1244,9 +1299,10 @@ template<class T> void Array<T>::referToRange(const Array<T>& a, int i, int j_lo
1244
1299
  }
1245
1300
 
1246
1301
  /// make this array a subarray reference to \c a
1247
- template<class T> void Array<T>::referToRange(const Array<T>& a, int i, int j, int k_lo, int k_up) {
1302
+ template<class T> void Array<T>::referToRange(const Array<T>& a, int i, int j, std::pair<int, int> K) {
1248
1303
  CHECK(a.nd>2, "does not make sense");
1249
1304
  CHECK_LE(a.nd, 3, "not implemented yet");
1305
+ int k_lo=K.first, k_up=K.second-1;
1250
1306
  if(i<0) i+=a.d0;
1251
1307
  if(j<0) j+=a.d1;
1252
1308
  if(k_lo<0) k_lo+=a.d2;
@@ -1276,8 +1332,8 @@ template<class T> void Array<T>::referToDim(const Array<T>& a, int i) {
1276
1332
  } else if(a.nd>3) {
1277
1333
  uint n=a.N/a.d0;
1278
1334
  referTo(a.p+i*n, n);
1279
- nd=a.nd-1; d0=a.d1; d1=a.d2; d2=a.d[3];
1280
- if(nd>3) { d=new uint[nd]; memmove(d, a.d+1, nd*sizeof(uint)); }
1335
+ nd=a.nd-1; d0=a.d1; d1=a.d2; d2=a._shape[3];
1336
+ resetShape(a._shape+1);
1281
1337
  }
1282
1338
  }
1283
1339
 
@@ -1299,14 +1355,14 @@ template<class T> void Array<T>::referToDim(const Array<T>& a, uint i, uint j, u
1299
1355
  CHECK(i<a.d0 && j<a.d1 && k<a.d2, "SubDim range error (" <<i <<"<" <<a.d0 <<", " <<j <<"<" <<a.d1 <<", " <<k <<"<" <<a.d2 << ")");
1300
1356
 
1301
1357
  if(a.nd==4) {
1302
- referTo(&a(i, j, k), a.d[3]);
1358
+ referTo(&a(i, j, k), a._shape[3]);
1303
1359
  } else if(a.nd==5) {
1304
1360
  NIY;
1305
1361
  // nd=2; d0=a.d[3]; d1=a.d[4]; d2=0; N=d0*d1;
1306
1362
  } else if(a.nd>5) {
1307
1363
  NIY;
1308
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);
1309
- // resetD();
1365
+ // resetShape();
1310
1366
  // if(nd>3) { d=new uint[nd]; memmove(d, a.d+3, nd*sizeof(uint)); }
1311
1367
  }
1312
1368
  // p=a.p+(i*a.N+(j*a.N+(k*a.N/a.d2))/a.d1)/a.d0;
@@ -1319,6 +1375,7 @@ template<class T> void Array<T>::takeOver(Array<T>& a) {
1319
1375
  freeMEM();
1320
1376
  memMove=a.memMove;
1321
1377
  N=a.N; nd=a.nd; d0=a.d0; d1=a.d1; d2=a.d2;
1378
+ resetShape(a._shape);
1322
1379
  p=a.p; M=a.M;
1323
1380
  special=a.special;
1324
1381
  #if 0 //a remains reference on this
@@ -1327,53 +1384,12 @@ template<class T> void Array<T>::takeOver(Array<T>& a) {
1327
1384
  #else //a is cleared
1328
1385
  a.p=NULL;
1329
1386
  a.M=a.N=a.nd=a.d0=a.d1=a.d2=0;
1330
- if(a.d && a.d!=&a.d0) { delete[] a.d; a.d=NULL; }
1387
+ a.resetShape();
1331
1388
  a.special=0;
1332
1389
  a.isReference=false;
1333
1390
  #endif
1334
1391
  }
1335
1392
 
1336
- /** @brief return a `dim'-dimensional grid with `steps' intervals
1337
- filling the range [lo, hi] in each dimension. Note: returned array is
1338
- `flat', rather than grid-shaped. */
1339
- template<class T> Array<T>& Array<T>::setGrid(uint dim, T lo, T hi, uint steps) {
1340
- CHECK(steps, "steps needs to be >0");
1341
- uint i, j, k;
1342
- if(dim==1) {
1343
- resize(steps+1, 1);
1344
- for(i=0; i<d0; i++) elem(i)=lo+(hi-lo)*i/steps;
1345
- return *this;
1346
- }
1347
- if(dim==2) {
1348
- resize(steps+1, steps+1, 2);
1349
- for(i=0; i<d0; i++) for(j=0; j<d1; j++) {
1350
- operator()(i, j, 0)=lo+(hi-lo)*i/steps;
1351
- operator()(i, j, 1)=lo+(hi-lo)*j/steps;
1352
- }
1353
- reshape(d0*d1, 2);
1354
- return *this;
1355
- }
1356
- if(dim==3) {
1357
- resize(uintA{steps+1, steps+1, steps+1, 3});
1358
- T dx = (hi-lo)/steps;
1359
- for(i=0; i<d0; i++) for(j=0; j<d1; j++) {
1360
- T* p = &elem(uintA{i, j, 0, 0});
1361
- for(k=0; k<d2; k++) {
1362
- *(p++) = lo+dx*i;
1363
- *(p++) = lo+dx*j;
1364
- *(p++) = lo+dx*k;
1365
- // elem(uintA{i, j, k, 0}) = lo+dx*i;
1366
- // elem(uintA{i, j, k, 1}) = lo+dx*j;
1367
- // elem(uintA{i, j, k, 2}) = lo+dx*k;
1368
- }
1369
- }
1370
- reshape(d0*d1*d2, 3);
1371
- return *this;
1372
- }
1373
- NIY;
1374
- return *this;
1375
- }
1376
-
1377
1393
  template<class T> T rai::Array<T>::median_nonConst() {
1378
1394
  CHECK_GE(N, 1, "");
1379
1395
  std::nth_element(p, p+N/2, p+N);
@@ -1495,7 +1511,7 @@ template<class T> void Array<T>::permuteInv(const Array<uint>& permutation) {
1495
1511
  template<class T> void Array<T>::permuteRowsInv(const Array<uint>& permutation) {
1496
1512
  CHECK_LE(permutation.N, d0, "array smaller than permutation ("<<N<<"<"<<permutation.N<<")");
1497
1513
  Array<T> b=(*this);
1498
- for(uint i=0; i<d0; i++) operator[](permutation(i))()=b[i];
1514
+ for(uint i=0; i<d0; i++) operator[](permutation(i))=b[i];
1499
1515
  }
1500
1516
 
1501
1517
  /// randomly permute all entries of 'this'
@@ -1528,9 +1544,28 @@ template<class T> void Array<T>::shift(int offset, bool wrapAround) {
1528
1544
 
1529
1545
  //==================================================================================
1530
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
+
1531
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 */
1532
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 {
1533
- CHECK(!special, "");
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
+
1534
1569
  CHECK(!binary || memMove, "binary write works only for memMoveable data");
1535
1570
  uint i, j, k;
1536
1571
  if(!ELEMSEP) ELEMSEP=arrayElemsep;
@@ -1569,15 +1604,19 @@ template<class T> void Array<T>::write(std::ostream& os, const char* ELEMSEP, co
1569
1604
  }
1570
1605
  }
1571
1606
  if(nd>3) {
1572
- CHECK(d && d!=&d0, "");
1607
+ CHECK(_shape && _shape!=&d0, "");
1573
1608
  for(i=0; i<N; i++) {
1574
- if(i && !(i%d[nd-1])) os <<LINESEP;
1575
- if(nd>1 && !(i%(d[nd-2]*d[nd-1]))) os <<LINESEP;
1609
+ if(i && !(i%_shape[nd-1])) os <<LINESEP;
1610
+ if(nd>1 && !(i%(_shape[nd-2]*_shape[nd-1]))) os <<LINESEP;
1576
1611
  os <<(i?ELEMSEP:"") <<elem(i);
1577
1612
  }
1578
1613
  }
1579
1614
  if(BRACKETS[1]) os <<BRACKETS[1];
1580
1615
  }
1616
+
1617
+ if constexpr(std::is_same_v<T, double>){
1618
+ if(jac) os <<" -- JACOBIAN:\n" <<*jac <<endl;
1619
+ }
1581
1620
  }
1582
1621
 
1583
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 */
@@ -1604,7 +1643,9 @@ template<class T> Array<T>& Array<T>::read(std::istream& is) {
1604
1643
  } else { //fast ascii read
1605
1644
  for(uint i=0; i<N; i++) {
1606
1645
  if(is.fail()) PARSERR("could not read " <<i <<"-th element of an array");
1607
- is >>p[i];
1646
+ if constexpr(!std::is_pointer_v<T>){
1647
+ is >>p[i];
1648
+ } else NIY;
1608
1649
  }
1609
1650
  }
1610
1651
  if(expectBracket) {
@@ -1629,7 +1670,9 @@ template<class T> Array<T>& Array<T>::read(std::istream& is) {
1629
1670
  continue;
1630
1671
  }
1631
1672
  if(c!=',') is.putback(c);
1632
- is >>x;
1673
+ if constexpr(!std::is_pointer_v<T>){
1674
+ is >>x;
1675
+ }else NIY;
1633
1676
  if(!is.good()) {
1634
1677
  if(!expectBracket) is.clear(); //ok
1635
1678
  else PARSERR("failed reading ending bracket ]");
@@ -1822,6 +1865,7 @@ template<class T> void writeConsecutiveConstant(std::ostream& os, const Array<T>
1822
1865
 
1823
1866
  /// contatenation of two arrays
1824
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
+
1825
1869
  /// calls Array<T>::read
1826
1870
  template<class T> std::istream& operator>>(std::istream& is, Array<T>& x) { x.read(is); return is; }
1827
1871
 
@@ -1866,4 +1910,114 @@ template<class T> bool operator<(const Array<T>& v, const Array<T>& w) {
1866
1910
  return v.N<w.N;
1867
1911
  }
1868
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
+
1869
2023
  } //namespace