coker 0.3.3__py3-none-any.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 (57) hide show
  1. coker/__init__.py +20 -0
  2. coker/algebra/__init__.py +6 -0
  3. coker/algebra/dimensions.py +127 -0
  4. coker/algebra/exceptions.py +6 -0
  5. coker/algebra/factories.py +8 -0
  6. coker/algebra/helpers.py +8 -0
  7. coker/algebra/kernel.py +653 -0
  8. coker/algebra/ops.py +376 -0
  9. coker/algebra/tensor.py +91 -0
  10. coker/backends/__init__.py +14 -0
  11. coker/backends/backend.py +136 -0
  12. coker/backends/casadi/__init__.py +232 -0
  13. coker/backends/casadi/casadi.py +213 -0
  14. coker/backends/casadi/optimiser.py +108 -0
  15. coker/backends/casadi/variational_solver.py +513 -0
  16. coker/backends/coker/__init__.py +1 -0
  17. coker/backends/coker/ast_preprocessing.py +193 -0
  18. coker/backends/coker/ast_rewriting.py +90 -0
  19. coker/backends/coker/core.py +193 -0
  20. coker/backends/coker/layers.py +197 -0
  21. coker/backends/coker/memory.py +10 -0
  22. coker/backends/coker/op_impl.py +85 -0
  23. coker/backends/coker/sparse_tensor.py +509 -0
  24. coker/backends/coker/tensor_contants.py +25 -0
  25. coker/backends/coker/weights.py +369 -0
  26. coker/backends/evaluator.py +70 -0
  27. coker/backends/jax/__init__.py +160 -0
  28. coker/backends/jax/optimiser.py +0 -0
  29. coker/backends/numpy/__init__.py +1 -0
  30. coker/backends/numpy/core.py +370 -0
  31. coker/dynamics/__init__.py +3 -0
  32. coker/dynamics/dynamical_system.py +234 -0
  33. coker/dynamics/transcription_helpers.py +396 -0
  34. coker/dynamics/types.py +360 -0
  35. coker/helpers.py +8 -0
  36. coker/toolkits/__init__.py +0 -0
  37. coker/toolkits/codesign/__init__.py +149 -0
  38. coker/toolkits/kinematics/__init__.py +1 -0
  39. coker/toolkits/kinematics/mujoco.py +107 -0
  40. coker/toolkits/kinematics/rigid_body.py +543 -0
  41. coker/toolkits/kinematics/visualiser.py +182 -0
  42. coker/toolkits/spatial/__init__.py +2 -0
  43. coker/toolkits/spatial/algebra.py +559 -0
  44. coker/toolkits/spatial/types.py +9 -0
  45. coker/toolkits/spatial/unit_quaternion.py +96 -0
  46. coker/toolkits/system_modelling/__init__.py +1 -0
  47. coker/toolkits/system_modelling/api.py +25 -0
  48. coker/toolkits/system_modelling/modelling/__init__.py +358 -0
  49. coker/toolkits/system_modelling/modelling/coker_abc.py +8 -0
  50. coker/toolkits/system_modelling/projects/__init__.py +100 -0
  51. coker/toolkits/system_modelling/std_lib/__init__.py +1 -0
  52. coker/toolkits/system_modelling/std_lib/common/__init__.py +1 -0
  53. coker/toolkits/system_modelling/std_lib/common/signal_processing.py +118 -0
  54. coker-0.3.3.dist-info/METADATA +25 -0
  55. coker-0.3.3.dist-info/RECORD +57 -0
  56. coker-0.3.3.dist-info/WHEEL +4 -0
  57. coker-0.3.3.dist-info/licenses/LICENSE.txt +373 -0
coker/__init__.py ADDED
@@ -0,0 +1,20 @@
1
+ from coker.algebra.kernel import (
2
+ Tape,
3
+ Tracer,
4
+ Function,
5
+ function,
6
+ scalar_types,
7
+ normalise,
8
+ get_projection,
9
+ )
10
+ from coker.algebra.dimensions import (
11
+ Dimension,
12
+ VectorSpace,
13
+ Scalar,
14
+ FunctionSpace,
15
+ Element,
16
+ )
17
+ from coker.algebra.ops import OP, Noop
18
+ from coker.algebra.tensor import SymbolicVector
19
+
20
+ from coker.algebra.factories import zeros
@@ -0,0 +1,6 @@
1
+ from coker.algebra.tensor import SymbolicVector
2
+ from coker.algebra.dimensions import Dimension
3
+ from coker.algebra.ops import OP
4
+
5
+ from coker.algebra.helpers import is_scalar
6
+ from coker.algebra.factories import zeros
@@ -0,0 +1,127 @@
1
+ import dataclasses
2
+ from typing import List, Optional, Tuple, Union
3
+
4
+
5
+ @dataclasses.dataclass
6
+ class VectorSpace:
7
+ name: str
8
+ dimension: Union[int, Tuple[int, ...]]
9
+
10
+
11
+ @dataclasses.dataclass
12
+ class Scalar:
13
+ name: str
14
+
15
+
16
+ class Dimension:
17
+ def __init__(self, tuple_or_none):
18
+
19
+ if isinstance(tuple_or_none, int):
20
+ tuple_or_none = (tuple_or_none,)
21
+
22
+ assert tuple_or_none is None or isinstance(tuple_or_none, tuple)
23
+ self.dim = tuple_or_none
24
+
25
+ def flat(self):
26
+ d = 1
27
+ if self.dim is not None:
28
+ for d_i in self.dim:
29
+ d *= d_i
30
+ return d
31
+
32
+ def to_space(self, name) -> Union[Scalar, VectorSpace]:
33
+ if self.is_scalar():
34
+ return Scalar(name)
35
+ return VectorSpace(name, self.dim)
36
+
37
+ def index_iterator(self, row_major=False):
38
+
39
+ if not self.dim:
40
+ return (0,)
41
+
42
+ mods = []
43
+
44
+ count = 1
45
+ iterator = reversed(self.dim) if row_major else iter(self.dim)
46
+
47
+ for d in iterator:
48
+ count = d * count
49
+ mods.insert(0, count)
50
+
51
+ for i in range(count):
52
+ yield tuple(i % m for m in mods)
53
+
54
+ def __eq__(self, other):
55
+ return self.dim == other.dim
56
+
57
+ def is_scalar(self):
58
+ return self.dim is None
59
+
60
+ def is_vector(self):
61
+ return self.dim is not None and len(self.dim) == 1
62
+
63
+ def is_covector(self):
64
+ return not self.is_scalar() and len(self.dim) == 2 and self.dim[0] == 1
65
+
66
+ def is_matrix(self):
67
+ return not self.is_scalar() and len(self.dim) == 2 and self.dim[0] > 1
68
+
69
+ def is_multilinear_map(self):
70
+ return isinstance(self.dim, tuple) and len(self.dim) > 2
71
+
72
+ def __iter__(self):
73
+ return iter(self.dim)
74
+
75
+ def __repr__(self):
76
+ if self.dim is None:
77
+ return "R"
78
+
79
+ return repr(self.dim)
80
+
81
+ @property
82
+ def shape(self):
83
+ if self.dim is None:
84
+ return (1,)
85
+ return self.dim
86
+
87
+
88
+ @dataclasses.dataclass
89
+ class FunctionSpace:
90
+ name: str
91
+ arguments: List[Scalar | VectorSpace]
92
+ output: List[Scalar | VectorSpace]
93
+ signature: Optional[Tuple[int]] = None
94
+ """Optional list of integers, specifying the degree of differentiability for each argument. Defaults to infinite (i.e. smooth function)."""
95
+
96
+ def input_dimensions(self):
97
+ return [
98
+ (
99
+ Dimension(None)
100
+ if isinstance(arg, Scalar)
101
+ else Dimension(arg.dimension)
102
+ )
103
+ for arg in self.arguments
104
+ ]
105
+
106
+ def output_dimensions(self):
107
+ if self.output is None:
108
+ return (None,)
109
+ return [
110
+ (
111
+ Dimension(None)
112
+ if isinstance(out, Scalar)
113
+ else Dimension(out.dimension)
114
+ )
115
+ for out in self.output
116
+ ]
117
+
118
+ def is_scalar(self):
119
+ return (
120
+ len(self.output_dimensions()) == 1
121
+ and self.output_dimensions()[0].is_scalar()
122
+ )
123
+
124
+
125
+ @dataclasses.dataclass
126
+ class Element:
127
+ parent: VectorSpace
@@ -0,0 +1,6 @@
1
+ class InvalidArgument(Exception):
2
+ pass
3
+
4
+
5
+ class InvalidShape(InvalidArgument):
6
+ pass
@@ -0,0 +1,8 @@
1
+ import numpy as np
2
+ from coker.algebra.kernel import TraceContext
3
+
4
+
5
+ def zeros(shape: tuple):
6
+ tape = TraceContext.get_local_tape()
7
+ assert tape is not None
8
+ return tape.insert_value(np.zeros(shape))
@@ -0,0 +1,8 @@
1
+ from typing import Union
2
+ import numpy as np
3
+
4
+
5
+ def is_scalar(x: Union[int, float, np.ndarray]):
6
+ if isinstance(x, np.ndarray):
7
+ return all(s_i == 1 for s_i in x.shape)
8
+ return isinstance(x, (int, float))