robotic 0.3.4.dev1__cp312-cp312-manylinux2014_x86_64.whl → 0.3.4.dev3__cp312-cp312-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.

Potentially problematic release.


This version of robotic might be problematic. Click here for more details.

Files changed (71) hide show
  1. robotic/_robotic.pyi +43 -15
  2. robotic/_robotic.so +0 -0
  3. robotic/include/rai/Algo/RidgeRegression.h +1 -1
  4. robotic/include/rai/Algo/rungeKutta.h +1 -1
  5. robotic/include/rai/Core/array.h +31 -22
  6. robotic/include/rai/Core/array.ipp +59 -74
  7. robotic/include/rai/Core/arrayDouble.h +29 -25
  8. robotic/include/rai/Core/defines.h +0 -1
  9. robotic/include/rai/Core/thread.h +1 -1
  10. robotic/include/rai/Core/util.h +0 -1
  11. robotic/include/rai/DataGen/shapenetGrasps.h +1 -1
  12. robotic/include/rai/Geo/geo.h +7 -7
  13. robotic/include/rai/Geo/mesh.h +2 -2
  14. robotic/include/rai/Geo/pairCollision.h +42 -42
  15. robotic/include/rai/Geo/signedDistanceFunctions.h +5 -3
  16. robotic/include/rai/KOMO/komo.h +1 -1
  17. robotic/include/rai/Kin/cameraview.h +27 -16
  18. robotic/include/rai/Kin/dof_forceExchange.h +3 -3
  19. robotic/include/rai/Kin/feature.h +1 -1
  20. robotic/include/rai/Kin/frame.h +1 -1
  21. robotic/include/rai/Kin/proxy.h +1 -1
  22. robotic/include/rai/Kin/simulation.h +5 -3
  23. robotic/include/rai/Logic/treeSearchDomain.h +2 -2
  24. robotic/include/rai/Optim/BayesOpt.h +14 -7
  25. robotic/include/rai/Optim/CMA/boundary_transformation.h +73 -0
  26. robotic/include/rai/Optim/CMA/cmaes.h +175 -0
  27. robotic/include/rai/Optim/CMA/cmaes_interface.h +68 -0
  28. robotic/include/rai/Optim/GlobalIterativeNewton.h +7 -3
  29. robotic/include/rai/Optim/NLP.h +15 -1
  30. robotic/include/rai/Optim/NLP_Solver.h +5 -5
  31. robotic/include/rai/Optim/constrained.h +3 -3
  32. robotic/include/rai/Optim/lagrangian.h +6 -5
  33. robotic/include/rai/Optim/m_EvoStrategies.h +113 -0
  34. robotic/include/rai/Optim/{gradient.h → m_Gradient.h} +12 -13
  35. robotic/include/rai/Optim/m_LBFGS.h +21 -0
  36. robotic/include/rai/Optim/m_LeastSquaresZeroOrder.h +34 -13
  37. robotic/include/rai/Optim/m_LocalGreedy.h +31 -0
  38. robotic/include/rai/Optim/m_NelderMead.h +23 -0
  39. robotic/include/rai/Optim/{newton.h → m_Newton.h} +8 -5
  40. robotic/include/rai/Optim/options.h +7 -7
  41. robotic/include/rai/Optim/primalDual.h +9 -5
  42. robotic/include/rai/Optim/testProblems_Opt.h +5 -5
  43. robotic/include/rai/Optim/utils.h +10 -20
  44. robotic/include/rai/Search/TreeSearchNode.h +1 -1
  45. robotic/librai.so +0 -0
  46. robotic/meshTool +0 -0
  47. robotic/version.py +1 -1
  48. {robotic-0.3.4.dev1.dist-info → robotic-0.3.4.dev3.dist-info}/METADATA +1 -1
  49. {robotic-0.3.4.dev1.dist-info → robotic-0.3.4.dev3.dist-info}/RECORD +70 -64
  50. robotic/include/rai/Optim/lbfgs.h +0 -18
  51. /robotic/include/rai/Geo/{assimpInterface.h → i_assimp.h} +0 -0
  52. /robotic/include/rai/Geo/{fclInterface.h → i_fcl.h} +0 -0
  53. /robotic/include/rai/Kin/{kin_bullet.h → i_Bullet.h} +0 -0
  54. /robotic/include/rai/Kin/{kin_feather.h → i_Feather.h} +0 -0
  55. /robotic/include/rai/Kin/{kin_ode.h → i_Ode.h} +0 -0
  56. /robotic/include/rai/Kin/{kin_physx.h → i_Physx.h} +0 -0
  57. /robotic/include/rai/Optim/{opt-ceres.h → i_Ceres.h} +0 -0
  58. /robotic/include/rai/Optim/{opt-ipopt.h → i_Ipopt.h} +0 -0
  59. /robotic/include/rai/Optim/{opt-nlopt.h → i_NLopt.h} +0 -0
  60. /robotic/include/rai/Optim/{liblbfgs.h → liblbfgs/liblbfgs.h} +0 -0
  61. /robotic/include/rai/Optim/{SlackGaussNewton.h → m_SlackGaussNewton.h} +0 -0
  62. {robotic-0.3.4.dev1.data → robotic-0.3.4.dev3.data}/scripts/ry-bot +0 -0
  63. {robotic-0.3.4.dev1.data → robotic-0.3.4.dev3.data}/scripts/ry-h5info +0 -0
  64. {robotic-0.3.4.dev1.data → robotic-0.3.4.dev3.data}/scripts/ry-info +0 -0
  65. {robotic-0.3.4.dev1.data → robotic-0.3.4.dev3.data}/scripts/ry-meshTool +0 -0
  66. {robotic-0.3.4.dev1.data → robotic-0.3.4.dev3.data}/scripts/ry-test +0 -0
  67. {robotic-0.3.4.dev1.data → robotic-0.3.4.dev3.data}/scripts/ry-urdfConvert.py +0 -0
  68. {robotic-0.3.4.dev1.data → robotic-0.3.4.dev3.data}/scripts/ry-view +0 -0
  69. {robotic-0.3.4.dev1.dist-info → robotic-0.3.4.dev3.dist-info}/WHEEL +0 -0
  70. {robotic-0.3.4.dev1.dist-info → robotic-0.3.4.dev3.dist-info}/licenses/LICENSE +0 -0
  71. {robotic-0.3.4.dev1.dist-info → robotic-0.3.4.dev3.dist-info}/top_level.txt +0 -0
robotic/_robotic.pyi CHANGED
@@ -236,7 +236,7 @@ class CameraView:
236
236
  """
237
237
  constructor
238
238
  """
239
- def computeImageAndDepth(self, config: Config, visualsOnly: bool = True) -> tuple:
239
+ def computeImageAndDepth(self, config: Config, simulateDepthNoise: bool = False, visualsOnly: bool = True) -> tuple:
240
240
  """
241
241
  returns image and depth from a camera sensor; the 'config' argument needs to be the same configuration as in the constructor, but in new state
242
242
  """
@@ -1301,7 +1301,7 @@ class NLP_Solver:
1301
1301
  """
1302
1302
  def setInitialization(self, arg0: arr) -> NLP_Solver:
1303
1303
  ...
1304
- def setOptions(self, verbose: int = 1, stopTolerance: float = 0.01, stopFTolerance: float = -1.0, stopGTolerance: float = -1.0, stopEvals: int = 1000, stopInners: int = 1000, stopOuters: int = 1000, stepMax: float = 0.2, damping: float = 1.0, stepInc: float = 1.5, stepDec: float = 0.5, wolfe: float = 0.01, muInit: float = 1.0, muInc: float = 5.0, muMax: float = 10000.0, muLBInit: float = 0.1, muLBDec: float = 0.2, lambdaMax: float = -1.0) -> NLP_Solver:
1304
+ def setOptions(self, verbose: int = 1, stopTolerance: float = 0.01, stopFTolerance: float = -1.0, stopGTolerance: float = -1.0, stopEvals: int = 1000, stopInners: int = 1000, stopOuters: int = 1000, stopLineSteps: int = 10, stopTinySteps: int = 4, stepInit: float = 1.0, stepMin: float = -1.0, stepMax: float = 0.2, stepInc: float = 1.5, stepDec: float = 0.5, damping: float = 1.0, wolfe: float = 0.01, muInit: float = 1.0, muInc: float = 5.0, muMax: float = 10000.0, muLBInit: float = 0.1, muLBDec: float = 0.2, lambdaMax: float = -1.0, interiorPadding: float = 0.01, boundedNewton: bool = True, finiteDifference: float = -1.0) -> NLP_Solver:
1305
1305
  """
1306
1306
  set solver options
1307
1307
  """
@@ -1457,19 +1457,21 @@ class OptMethod:
1457
1457
 
1458
1458
  none
1459
1459
 
1460
- gradientDescent
1460
+ GradientDescent
1461
1461
 
1462
- rprop
1462
+ Rprop
1463
1463
 
1464
1464
  LBFGS
1465
1465
 
1466
- newton
1466
+ Newton
1467
1467
 
1468
- augmentedLag
1468
+ AugmentedLag
1469
1469
 
1470
- squaredPenalty
1470
+ LogBarrier
1471
1471
 
1472
- logBarrier
1472
+ slackGN_logBarrier
1473
+
1474
+ SquaredPenalty
1473
1475
 
1474
1476
  singleSquaredPenalty
1475
1477
 
@@ -1479,22 +1481,38 @@ class OptMethod:
1479
1481
 
1480
1482
  Ipopt
1481
1483
 
1484
+ slackGN_Ipopt
1485
+
1482
1486
  Ceres
1487
+
1488
+ LSZO
1489
+
1490
+ greedy
1491
+
1492
+ NelderMead
1493
+
1494
+ CMA
1483
1495
  """
1496
+ AugmentedLag: typing.ClassVar[OptMethod] # value = <OptMethod.AugmentedLag: 5>
1497
+ CMA: typing.ClassVar[OptMethod] # value = <OptMethod.CMA: 18>
1484
1498
  Ceres: typing.ClassVar[OptMethod] # value = <OptMethod.Ceres: 14>
1499
+ GradientDescent: typing.ClassVar[OptMethod] # value = <OptMethod.GradientDescent: 1>
1485
1500
  Ipopt: typing.ClassVar[OptMethod] # value = <OptMethod.Ipopt: 12>
1486
1501
  LBFGS: typing.ClassVar[OptMethod] # value = <OptMethod.LBFGS: 3>
1502
+ LSZO: typing.ClassVar[OptMethod] # value = <OptMethod.LSZO: 15>
1503
+ LogBarrier: typing.ClassVar[OptMethod] # value = <OptMethod.LogBarrier: 6>
1487
1504
  NLopt: typing.ClassVar[OptMethod] # value = <OptMethod.NLopt: 11>
1488
- __members__: typing.ClassVar[dict[str, OptMethod]] # value = {'none': <OptMethod.none: 0>, 'gradientDescent': <OptMethod.gradientDescent: 1>, 'rprop': <OptMethod.rprop: 2>, 'LBFGS': <OptMethod.LBFGS: 3>, 'newton': <OptMethod.newton: 4>, 'augmentedLag': <OptMethod.augmentedLag: 5>, 'squaredPenalty': <OptMethod.squaredPenalty: 8>, 'logBarrier': <OptMethod.logBarrier: 6>, 'singleSquaredPenalty': <OptMethod.singleSquaredPenalty: 9>, 'slackGN': <OptMethod.slackGN: 10>, 'NLopt': <OptMethod.NLopt: 11>, 'Ipopt': <OptMethod.Ipopt: 12>, 'Ceres': <OptMethod.Ceres: 14>}
1489
- augmentedLag: typing.ClassVar[OptMethod] # value = <OptMethod.augmentedLag: 5>
1490
- gradientDescent: typing.ClassVar[OptMethod] # value = <OptMethod.gradientDescent: 1>
1491
- logBarrier: typing.ClassVar[OptMethod] # value = <OptMethod.logBarrier: 6>
1492
- newton: typing.ClassVar[OptMethod] # value = <OptMethod.newton: 4>
1505
+ NelderMead: typing.ClassVar[OptMethod] # value = <OptMethod.NelderMead: 17>
1506
+ Newton: typing.ClassVar[OptMethod] # value = <OptMethod.Newton: 4>
1507
+ Rprop: typing.ClassVar[OptMethod] # value = <OptMethod.Rprop: 2>
1508
+ SquaredPenalty: typing.ClassVar[OptMethod] # value = <OptMethod.SquaredPenalty: 8>
1509
+ __members__: typing.ClassVar[dict[str, OptMethod]] # value = {'none': <OptMethod.none: 0>, 'GradientDescent': <OptMethod.GradientDescent: 1>, 'Rprop': <OptMethod.Rprop: 2>, 'LBFGS': <OptMethod.LBFGS: 3>, 'Newton': <OptMethod.Newton: 4>, 'AugmentedLag': <OptMethod.AugmentedLag: 5>, 'LogBarrier': <OptMethod.LogBarrier: 6>, 'slackGN_logBarrier': <OptMethod.slackGN_logBarrier: 7>, 'SquaredPenalty': <OptMethod.SquaredPenalty: 8>, 'singleSquaredPenalty': <OptMethod.singleSquaredPenalty: 9>, 'slackGN': <OptMethod.slackGN: 10>, 'NLopt': <OptMethod.NLopt: 11>, 'Ipopt': <OptMethod.Ipopt: 12>, 'slackGN_Ipopt': <OptMethod.slackGN_Ipopt: 13>, 'Ceres': <OptMethod.Ceres: 14>, 'LSZO': <OptMethod.LSZO: 15>, 'greedy': <OptMethod.greedy: 16>, 'NelderMead': <OptMethod.NelderMead: 17>, 'CMA': <OptMethod.CMA: 18>}
1510
+ greedy: typing.ClassVar[OptMethod] # value = <OptMethod.greedy: 16>
1493
1511
  none: typing.ClassVar[OptMethod] # value = <OptMethod.none: 0>
1494
- rprop: typing.ClassVar[OptMethod] # value = <OptMethod.rprop: 2>
1495
1512
  singleSquaredPenalty: typing.ClassVar[OptMethod] # value = <OptMethod.singleSquaredPenalty: 9>
1496
1513
  slackGN: typing.ClassVar[OptMethod] # value = <OptMethod.slackGN: 10>
1497
- squaredPenalty: typing.ClassVar[OptMethod] # value = <OptMethod.squaredPenalty: 8>
1514
+ slackGN_Ipopt: typing.ClassVar[OptMethod] # value = <OptMethod.slackGN_Ipopt: 13>
1515
+ slackGN_logBarrier: typing.ClassVar[OptMethod] # value = <OptMethod.slackGN_logBarrier: 7>
1498
1516
  @staticmethod
1499
1517
  def _pybind11_conduit_v1_(*args, **kwargs):
1500
1518
  ...
@@ -1612,12 +1630,18 @@ class RRT_PathFinder:
1612
1630
  """
1613
1631
  only after setProblem
1614
1632
  """
1633
+ def setOptions(self, verbose: int = 0, stepsize: float = 0.1, subsamples: int = 4, maxIters: int = 5000, p_connect: float = 0.5, collisionTolerance: float = 0.0001, useBroadCollisions: bool = True) -> RRT_PathFinder:
1634
+ """
1635
+ set solver options
1636
+ """
1615
1637
  def setProblem(self, Configuration: Config) -> None:
1616
1638
  ...
1617
1639
  def setStartGoal(self, starts: arr, goals: arr) -> None:
1618
1640
  ...
1619
1641
  def solve(self, verbose: int = 1) -> SolverReturn:
1620
1642
  ...
1643
+ def view(self, pause: bool, message: str = None, play: bool = False) -> None:
1644
+ ...
1621
1645
  class ST:
1622
1646
  """
1623
1647
  Members:
@@ -1921,6 +1945,10 @@ class Simulation:
1921
1945
  ...
1922
1946
  def selectSensor(self, sensorName: str) -> ...:
1923
1947
  ...
1948
+ def setSimulateDepthNoise(self, _setSimulateDepthNoise: bool) -> None:
1949
+ """
1950
+ specify (boolean) on whether to simulate noise
1951
+ """
1924
1952
  def setSplineRef(self, path: arr, times: arr, append: bool = True) -> None:
1925
1953
  """
1926
1954
  set the spline reference to generate motion
robotic/_robotic.so CHANGED
Binary file
@@ -74,7 +74,7 @@ struct KernelRidgeRegression {
74
74
  arr evaluate(const arr& X, arr& bayesSigma2=NoArr); ///< returns f(x) and \s^2(x) for a set of points X
75
75
 
76
76
  double evaluate(const arr& x, arr& df_x, arr& H, double plusSigma, bool onlySigma); ///< returns f(x) + coeff*\sigma(x) and its gradient and Hessian
77
- shared_ptr<ScalarFunction> getF(double plusSigma);
77
+ ScalarFunction getF(double plusSigma);
78
78
  };
79
79
 
80
80
  struct KernelLogisticRegression {
@@ -14,7 +14,7 @@ namespace rai {
14
14
 
15
15
  //----- Runge-Kutta
16
16
  /// standard Runge-Kutta 4
17
- void rk4(arr& x, const arr& x0, const fct& f, double dt);
17
+ void rk4(arr& x, const arr& x0, VectorFunction f, double dt);
18
18
  /// same for second order diff equation
19
19
  //void rk4dd(arr& x1, arr& v1, const arr& x0, const arr& v0,
20
20
  // void (*ddf)(arr& xdd, const arr& x, const arr& v),
@@ -67,7 +67,7 @@ template<class T> struct Array {
67
67
  uint N; ///< number of elements
68
68
  uint nd; ///< number of dimensions
69
69
  uint d0, d1, d2; ///< 0th, 1st, 2nd dim
70
- uint* d; ///< pointer to dimensions (for nd<=3 points to d0)
70
+ uint* _shape; ///< pointer to dimensions (for nd<=3 points to d0)
71
71
  bool isReference; ///< true if this refers to memory of another array
72
72
  uint M; ///< memory allocated (>=N)
73
73
  SpecialArray* special=0; ///< auxiliary data, e.g. if this is a sparse matrics, depends on special type
@@ -95,24 +95,30 @@ template<class T> struct Array {
95
95
  Array<T>& operator=(const Array<T>& a);
96
96
 
97
97
  /// @name iterators
98
- struct iterator {
99
- using reference = T&;
100
- T* p;
101
- T& operator()() { return *p; } //access to value by user
102
- void operator++() { p++; }
103
- reference operator*() { return *p; } //in for(auto& it:array.enumerated()) it is assigned to *iterator
104
- friend bool operator!=(const iterator& i, const iterator& j) { return i.p!=j.p; }
105
- T& operator->() { return *p; }
106
- };
107
- struct const_iterator {
108
- using reference = const T&;
109
- const T* p;
110
- const T& operator()() { return *p; } //access to value by user
111
- void operator++() { p++; }
112
- reference operator*() { return *p; } //in for(auto& it:array.enumerated()) it is assigned to *iterator
113
- friend bool operator!=(const const_iterator& i, const const_iterator& j) { return i.p!=j.p; }
114
- const T& operator->() { return *p; }
115
- };
98
+ using iterator = T*;
99
+ using const_iterator = const T*;
100
+ // struct iterator {
101
+ // using reference = T&;
102
+ // T* p;
103
+ // T& operator()() { return *p; } //access to value by user
104
+ // void operator++() { p++; }
105
+ // reference operator*() { return *p; } //in for(auto& it:array.enumerated()) it is assigned to *iterator
106
+ // friend bool operator!=(const iterator& i, const iterator& j) { return i.p!=j.p; }
107
+ // friend long int operator-(const iterator& i, const iterator& j) { return (long int)(i.p-j.p); }
108
+ // friend iterator operator+(const iterator& i, int j) { return iterator{i.p+j}; }
109
+ // friend iterator operator-(const iterator& i, int j) { return iterator{i.p-j}; }
110
+ // friend reference operator*(const iterator& i, int j) { return i.p[j]; }
111
+ // T& operator->() { return *p; }
112
+ // };
113
+ // struct const_iterator {
114
+ // using reference = const T&;
115
+ // const T* p;
116
+ // const T& operator()() { return *p; } //access to value by user
117
+ // void operator++() { p++; }
118
+ // reference operator*() { return *p; } //in for(auto& it:array.enumerated()) it is assigned to *iterator
119
+ // friend bool operator!=(const const_iterator& i, const const_iterator& j) { return i.p!=j.p; }
120
+ // const T& operator->() { return *p; }
121
+ // };
116
122
 
117
123
  iterator begin() { return iterator{p}; }
118
124
  const_iterator begin() const { return const_iterator{p}; }
@@ -304,7 +310,7 @@ template<class T> struct Array {
304
310
  void resizeMEM(uint n, bool copy, int Mforce=-1);
305
311
  void reserveMEM(uint Mforce) { resizeMEM(N, true, Mforce); if(!nd) nd=1; }
306
312
  void freeMEM();
307
- void resetD();
313
+ void resetShape(uint* dim=0);
308
314
 
309
315
  /// @name serialization
310
316
  uint serial_size();
@@ -329,6 +335,7 @@ template<class T> void operator+=(Array<T>& x, const T& y);
329
335
  template<class T> void operator-=(Array<T>& x, const Array<T>& y);
330
336
  template<class T> void operator-=(Array<T>& x, const T& y);
331
337
  template<class T> void operator*=(Array<T>& x, const T& y);
338
+ template<class T> void operator/=(Array<T>& x, const T& y);
332
339
 
333
340
  template<class T> Array<T> operator+(const Array<T>& y, const Array<T>& z) { Array<T> x(y); x+=z; return x; }
334
341
  template<class T> Array<T> operator+(const Array<T>& y, T z) { Array<T> x(y); x+=z; return x; }
@@ -447,8 +454,8 @@ template<class T> Array<T> catCol(const rai::Array<T>& a, const rai::Array<T>& b
447
454
  namespace rai {
448
455
  template<class T, class S> void resizeAs(Array<T>& x, const Array<S>& a) {
449
456
  x.nd=a.nd; x.d0=a.d0; x.d1=a.d1; x.d2=a.d2;
450
- x.resetD();
451
- if(x.nd>3) { x.d=new uint[x.nd]; memmove(x.d, a.d, x.nd*sizeof(uint)); }
457
+ x.resetShape();
458
+ if(x.nd>3) { x._shape=new uint[x.nd]; memmove(x._shape, a._shape, x.nd*sizeof(uint)); }
452
459
  x.resizeMEM(a.N, false);
453
460
  }
454
461
  template<class T, class S> void resizeCopyAs(Array<T>& x, const Array<S>& a);
@@ -679,6 +686,8 @@ namespace rai {
679
686
  uint product(const uintA& x);
680
687
  template<class T> T& min(const Array<T>& x);
681
688
  template<class T> T& max(const Array<T>& x);
689
+ template<class T> std::tuple<T&,uint> min_arg(const Array<T>& x);
690
+ template<class T> std::tuple<T&,uint> max_arg(const Array<T>& x);
682
691
  uint sum(const uintA& x);
683
692
  float sum(const floatA& x);
684
693
  template<class T> Array<T> integral(const Array<T>& x);
@@ -41,7 +41,7 @@ template<class T> Array<T>::Array()
41
41
  N(0),
42
42
  nd(0),
43
43
  d0(0), d1(0), d2(0),
44
- d(&d0),
44
+ _shape(&d0),
45
45
  isReference(false),
46
46
  M(0),
47
47
  special(0) {
@@ -72,17 +72,18 @@ template<class T> Array<T>::Array(Array<T>&& a)
72
72
  N(a.N),
73
73
  nd(a.nd),
74
74
  d0(a.d0), d1(a.d1), d2(a.d2),
75
- d(&d0),
75
+ _shape(&d0),
76
76
  isReference(a.isReference),
77
77
  M(a.M),
78
78
  special(a.special) {
79
79
  if constexpr(std::is_same_v<T, double>){
80
80
  if(a.jac) jac = std::move(a.jac);
81
81
  }
82
- // CHECK_EQ(a.d, &a.d0, "NIY for larger tensors");
83
- if(a.d!=&a.d0) { d=a.d; a.d=&a.d0; }
82
+ // CHECK_EQ(a.shape, &a.d0, "NIY for larger tensors");
83
+ if(a._shape!=&a.d0) { _shape=a._shape; a._shape=&a.d0; }
84
84
  a.p=NULL;
85
85
  a.N=a.nd=a.d0=a.d1=a.d2=0;
86
+ a.resetShape();
86
87
  a.isReference=false;
87
88
  a.special=NULL;
88
89
  }
@@ -109,7 +110,7 @@ template<class T> Array<T>::~Array() {
109
110
  clear();
110
111
  #else //faster (leaves members non-zeroed..)
111
112
  if(special) { delete special; special=NULL; }
112
- if(d!=&d0) { delete[] d; }
113
+ if(_shape!=&d0) { delete[] _shape; }
113
114
  if(M) {
114
115
  globalMemoryTotal -= M*sizeT;
115
116
  if(memMove==1) free(p); else delete[] p;
@@ -125,57 +126,56 @@ template<class T> Array<T>& Array<T>::clear() {
125
126
  }
126
127
 
127
128
  /// resize 1D array, discard the previous contents
128
- 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; }
129
130
 
130
131
  /// resize but copy the previous contents
131
- 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; }
132
133
 
133
134
  /// reshape the dimensionality (e.g. from 2D to 1D); throw an error if this actually requires to resize the memory
134
135
  template<class T> Array<T>& Array<T>::reshape(int D0) {
135
136
  if(D0<0) D0=N;
136
137
  CHECK_EQ((int)N, D0, "reshape must preserve total memory size");
137
- nd=1; d0=D0; d1=d2=0; resetD();
138
+ nd=1; d0=D0; d1=d2=0; resetShape();
138
139
  return *this;
139
140
  }
140
141
 
141
142
  /// same for 2D ...
142
- 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; }
143
144
 
144
145
  /// ...
145
- 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; }
146
147
 
147
148
  /// ...
148
149
  template<class T> Array<T>& Array<T>::reshape(int D0, int D1) {
149
150
  if(D0<0) D0=N/D1; else if(D1<0) D1=N/D0;
150
151
  CHECK_EQ((int)N, D0*D1, "reshape must preserve total memory size");
151
152
  nd=2; d0=D0; d1=D1; d2=0;
152
- resetD();
153
+ resetShape();
153
154
  return *this;
154
155
  }
155
156
 
156
157
  /// same for 3D ...
157
- 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; }
158
159
 
159
160
  /// ...
160
- 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; }
161
162
 
162
163
  /// ...
163
164
  template<class T> Array<T>& Array<T>::reshape(int D0, int D1, int D2) {
164
165
  if(D0<0) D0=N/(D1*D2); else if(D1<0) D1=N/(D0*D2); else if(D2<0) D2=N/(D0*D1);
165
166
  CHECK_EQ((int)N, D0*D1*D2, "reshape must preserve total memory size");
166
167
  nd=3; d0=D0; d1=D1; d2=D2;
167
- resetD();
168
+ resetShape();
168
169
  return *this;
169
170
  }
170
171
 
171
172
  /// resize to multi-dimensional tensor
172
173
  template<class T> Array<T>& Array<T>::resize(uint ND, uint* dim) {
173
- nd=ND; d0=d1=d2=0; resetD();
174
- uint j;
175
- for(j=0; j<nd && j<3; j++) {(&d0)[j]=dim[j]; }
176
- if(nd>3) { d=new uint[nd]; memmove(d, dim, nd*sizeof(uint)); }
177
- uint64_t S;
178
- 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];
179
179
  if(S>=(1ull <<32)) HALT("Array #elements " <<(S>>30) <<"G is >= 2^32");
180
180
  resizeMEM((uint)S, false);
181
181
  return *this;
@@ -183,12 +183,11 @@ template<class T> Array<T>& Array<T>::resize(uint ND, uint* dim) {
183
183
 
184
184
  /// resize to multi-dimensional tensor
185
185
  template<class T> Array<T>& Array<T>::resizeCopy(uint ND, uint* dim) {
186
- nd=ND; d0=d1=d2=0; resetD();
187
- uint j;
188
- for(j=0; j<nd && j<3; j++) {(&d0)[j]=dim[j]; }
189
- if(nd>3) { d=new uint[nd]; memmove(d, dim, nd*sizeof(uint)); }
190
- uint64_t S;
191
- 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];
192
191
  if(S>=(1ull <<32)) HALT("Array #elements " <<(S>>30) <<"G is >= 2^32");
193
192
  resizeMEM((uint)S, true);
194
193
  return *this;
@@ -196,19 +195,10 @@ template<class T> Array<T>& Array<T>::resizeCopy(uint ND, uint* dim) {
196
195
 
197
196
  /// resize to multi-dimensional tensor
198
197
  template<class T> Array<T>& Array<T>::reshape(uint ND, uint* dim) {
199
- nd=ND; d0=d1=d2=0; resetD();
200
- if(nd>0){
201
- d0=dim[0];
202
- if(nd>1){
203
- d1=dim[1];
204
- if(nd>2){
205
- d2=dim[2];
206
- if(nd>3) { d=new uint[nd]; memmove(d, dim, nd*sizeof(uint)); }
207
- }
208
- }
209
- }
210
- //for(uint j=0; j<nd && j<3; j++) {(&d0)[j]=dim[j]; }
211
- 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);
212
202
  for(uint j=0; j<nd; j++) S*=dim[j];
213
203
  CHECK_EQ(N, S, "reshape must preserve total memory size");
214
204
  return *this;
@@ -229,8 +219,7 @@ template<class T> Array<T>& Array<T>::resizeAs(const Array<T>& a) {
229
219
  CHECK(this!=&a, "never do this!!!");
230
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)");
231
221
  nd=a.nd; d0=a.d0; d1=a.d1; d2=a.d2;
232
- resetD();
233
- if(nd>3) { d=new uint[nd]; memmove(d, a.d, nd*sizeof(uint)); }
222
+ resetShape(a._shape);
234
223
  resizeMEM(a.N, false);
235
224
  return *this;
236
225
  }
@@ -238,8 +227,8 @@ template<class T> Array<T>& Array<T>::resizeAs(const Array<T>& a) {
238
227
  /// make it the same size as \c a and copy previous content
239
228
  template<class T> Array<T>& Array<T>::resizeCopyAs(const Array<T>& a) {
240
229
  CHECK(this!=&a, "never do this!!!");
241
- nd=a.nd; d0=a.d0; d1=a.d1; d2=a.d2; resetD();
242
- 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);
243
232
  resizeMEM(a.N, true);
244
233
  return *this;
245
234
  }
@@ -247,15 +236,15 @@ template<class T> Array<T>& Array<T>::resizeCopyAs(const Array<T>& a) {
247
236
  template<class T> Array<T>& Array<T>::reshapeAs(const Array<T>& a) {
248
237
  CHECK(this!=&a, "never do this!!!");
249
238
  CHECK_EQ(N, a.N, "reshape must preserve total memory size");
250
- nd=a.nd; d0=a.d0; d1=a.d1; d2=a.d2; resetD();
251
- if(nd>3) { d=new uint[nd]; memmove(d, a.d, nd*sizeof(uint)); }
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
@@ -688,7 +680,7 @@ template<class T> void Array<T>::resizeDim(uint k, uint dk) {
688
680
  /// return a uint-Array that contains (acutally refers to) the dimensions of 'this'
689
681
  template<class T> Array<uint> Array<T>::dim() const {
690
682
  Array<uint> dims;
691
- dims.setCarray(d, nd);
683
+ dims.setCarray(_shape, nd);
692
684
  return dims;
693
685
  }
694
686
 
@@ -1340,8 +1332,8 @@ template<class T> void Array<T>::referToDim(const Array<T>& a, int i) {
1340
1332
  } else if(a.nd>3) {
1341
1333
  uint n=a.N/a.d0;
1342
1334
  referTo(a.p+i*n, n);
1343
- nd=a.nd-1; d0=a.d1; d1=a.d2; d2=a.d[3];
1344
- 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);
1345
1337
  }
1346
1338
  }
1347
1339
 
@@ -1363,14 +1355,14 @@ template<class T> void Array<T>::referToDim(const Array<T>& a, uint i, uint j, u
1363
1355
  CHECK(i<a.d0 && j<a.d1 && k<a.d2, "SubDim range error (" <<i <<"<" <<a.d0 <<", " <<j <<"<" <<a.d1 <<", " <<k <<"<" <<a.d2 << ")");
1364
1356
 
1365
1357
  if(a.nd==4) {
1366
- referTo(&a(i, j, k), a.d[3]);
1358
+ referTo(&a(i, j, k), a._shape[3]);
1367
1359
  } else if(a.nd==5) {
1368
1360
  NIY;
1369
1361
  // nd=2; d0=a.d[3]; d1=a.d[4]; d2=0; N=d0*d1;
1370
1362
  } else if(a.nd>5) {
1371
1363
  NIY;
1372
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);
1373
- // resetD();
1365
+ // resetShape();
1374
1366
  // if(nd>3) { d=new uint[nd]; memmove(d, a.d+3, nd*sizeof(uint)); }
1375
1367
  }
1376
1368
  // p=a.p+(i*a.N+(j*a.N+(k*a.N/a.d2))/a.d1)/a.d0;
@@ -1383,6 +1375,7 @@ template<class T> void Array<T>::takeOver(Array<T>& a) {
1383
1375
  freeMEM();
1384
1376
  memMove=a.memMove;
1385
1377
  N=a.N; nd=a.nd; d0=a.d0; d1=a.d1; d2=a.d2;
1378
+ resetShape(a._shape);
1386
1379
  p=a.p; M=a.M;
1387
1380
  special=a.special;
1388
1381
  #if 0 //a remains reference on this
@@ -1391,7 +1384,7 @@ template<class T> void Array<T>::takeOver(Array<T>& a) {
1391
1384
  #else //a is cleared
1392
1385
  a.p=NULL;
1393
1386
  a.M=a.N=a.nd=a.d0=a.d1=a.d2=0;
1394
- if(a.d && a.d!=&a.d0) { delete[] a.d; a.d=NULL; }
1387
+ a.resetShape();
1395
1388
  a.special=0;
1396
1389
  a.isReference=false;
1397
1390
  #endif
@@ -1611,10 +1604,10 @@ template<class T> void Array<T>::write(std::ostream& os, const char* ELEMSEP, co
1611
1604
  }
1612
1605
  }
1613
1606
  if(nd>3) {
1614
- CHECK(d && d!=&d0, "");
1607
+ CHECK(_shape && _shape!=&d0, "");
1615
1608
  for(i=0; i<N; i++) {
1616
- if(i && !(i%d[nd-1])) os <<LINESEP;
1617
- 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;
1618
1611
  os <<(i?ELEMSEP:"") <<elem(i);
1619
1612
  }
1620
1613
  }
@@ -1951,15 +1944,9 @@ template<class T> void operator+=(Array<T>& x, const Array<T>& y) {
1951
1944
  else x.J() = *y.jac;
1952
1945
  }
1953
1946
  }
1954
- // CHECK_EQ(x.N, y.N, "update operator on different array dimensions (" <<x.N <<", " <<y.N <<")");
1955
- // T* xp=x.p, *xstop=xp+x.N;
1956
- // const T* yp=y.p;
1957
- // for(; xp!=xstop; xp++, yp++) *xp += *yp;
1958
1947
  }
1959
1948
  template<class T> void operator+=(Array<T>& x, const T& y) {
1960
1949
  UpdateOperator_MS(+=);
1961
- // T* xp=x.p, *xstop=xp+x.N;
1962
- // for(; xp!=xstop; xp++) *xp += y;
1963
1950
  }
1964
1951
  template<class T> void operator-=(Array<T>& x, const Array<T>& y) {
1965
1952
  UpdateOperator_MM(-=);
@@ -1969,23 +1956,21 @@ template<class T> void operator-=(Array<T>& x, const Array<T>& y) {
1969
1956
  else x.J() = -(*y.jac);
1970
1957
  }
1971
1958
  }
1972
- // CHECK_EQ(x.N, y.N, "update operator on different array dimensions (" <<x.N <<", " <<y.N <<")");
1973
- // T* xp=x.p, *xstop=xp+x.N;
1974
- // const T* yp=y.p;
1975
- // for(; xp!=xstop; xp++, yp++) *xp -= *yp;
1976
1959
  }
1977
1960
  template<class T> void operator-=(Array<T>& x, const T& y) {
1978
1961
  UpdateOperator_MS(-=);
1979
- // T* xp=x.p, *xstop=xp+x.N;
1980
- // for(; xp!=xstop; xp++) *xp -= y;
1981
1962
  }
1982
1963
  template<class T> void operator*=(Array<T>& x, const T& y) {
1983
1964
  if constexpr(std::is_same_v<T, double>){
1984
1965
  if(x.jac) *x.jac *= y;
1985
1966
  }
1986
1967
  UpdateOperator_MS(*=);
1987
- // T* xp=x.p, *xstop=xp+x.N;
1988
- // for(; xp!=xstop; xp++) *xp *= y;
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(/=);
1989
1974
  }
1990
1975
 
1991
1976
  #undef UpdateOperator_MM