@oazmi/superbuild 0.1.0

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 (118) hide show
  1. package/esm/_dnt.shims.d.ts +2 -0
  2. package/esm/_dnt.shims.d.ts.map +1 -0
  3. package/esm/_dnt.shims.js +57 -0
  4. package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.d.ts +598 -0
  5. package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.d.ts.map +1 -0
  6. package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.js +1 -0
  7. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.d.ts +617 -0
  8. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.d.ts.map +1 -0
  9. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.js +671 -0
  10. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.d.ts +487 -0
  11. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.js +536 -0
  13. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.d.ts +266 -0
  14. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.js +318 -0
  16. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.d.ts +368 -0
  17. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.js +380 -0
  19. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.d.ts +711 -0
  20. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.d.ts.map +1 -0
  21. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.js +1173 -0
  22. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.d.ts +171 -0
  23. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.d.ts.map +1 -0
  24. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.js +308 -0
  25. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.d.ts +10 -0
  26. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.js +10 -0
  28. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.d.ts +168 -0
  29. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.js +236 -0
  31. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.d.ts +90 -0
  32. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.d.ts.map +1 -0
  33. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.js +237 -0
  34. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.d.ts +213 -0
  35. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.d.ts.map +1 -0
  36. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.js +363 -0
  37. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.d.ts +233 -0
  38. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.js +256 -0
  40. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.d.ts +1436 -0
  41. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.d.ts.map +1 -0
  42. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.js +1730 -0
  43. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.d.ts +647 -0
  44. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.d.ts.map +1 -0
  45. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.js +762 -0
  46. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.d.ts +538 -0
  47. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.d.ts.map +1 -0
  48. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.js +626 -0
  49. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.d.ts +734 -0
  50. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.js +764 -0
  52. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.d.ts +137 -0
  53. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.d.ts.map +1 -0
  54. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.js +234 -0
  55. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.d.ts +391 -0
  56. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.d.ts.map +1 -0
  57. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.js +8 -0
  58. package/esm/deps.d.ts +56 -0
  59. package/esm/deps.d.ts.map +1 -0
  60. package/esm/deps.js +37 -0
  61. package/esm/esbuild/metafile.d.ts +90 -0
  62. package/esm/esbuild/metafile.d.ts.map +1 -0
  63. package/esm/esbuild/metafile.js +275 -0
  64. package/esm/esbuild/native.d.ts +95 -0
  65. package/esm/esbuild/native.d.ts.map +1 -0
  66. package/esm/esbuild/native.js +127 -0
  67. package/esm/esbuild/outputfile.d.ts +86 -0
  68. package/esm/esbuild/outputfile.d.ts.map +1 -0
  69. package/esm/esbuild/outputfile.js +221 -0
  70. package/esm/esbuild/strongtypes.d.ts +90 -0
  71. package/esm/esbuild/strongtypes.d.ts.map +1 -0
  72. package/esm/esbuild/strongtypes.js +8 -0
  73. package/esm/esbuild/typedefs.d.ts +121 -0
  74. package/esm/esbuild/typedefs.d.ts.map +1 -0
  75. package/esm/esbuild/typedefs.js +55 -0
  76. package/esm/esbuild/weaktypes.d.ts +46 -0
  77. package/esm/esbuild/weaktypes.d.ts.map +1 -0
  78. package/esm/esbuild/weaktypes.js +8 -0
  79. package/esm/funcdefs.d.ts +89 -0
  80. package/esm/funcdefs.d.ts.map +1 -0
  81. package/esm/funcdefs.js +145 -0
  82. package/esm/mod.d.ts +4 -0
  83. package/esm/mod.d.ts.map +1 -0
  84. package/esm/mod.js +2 -0
  85. package/esm/package.json +3 -0
  86. package/esm/plugins/emissions_driver.d.ts +33 -0
  87. package/esm/plugins/emissions_driver.d.ts.map +1 -0
  88. package/esm/plugins/emissions_driver.js +260 -0
  89. package/esm/plugins/long_build.d.ts +138 -0
  90. package/esm/plugins/long_build.d.ts.map +1 -0
  91. package/esm/plugins/long_build.js +288 -0
  92. package/esm/plugins/native_replica.d.ts +48 -0
  93. package/esm/plugins/native_replica.d.ts.map +1 -0
  94. package/esm/plugins/native_replica.js +122 -0
  95. package/esm/super/build.d.ts +53 -0
  96. package/esm/super/build.d.ts.map +1 -0
  97. package/esm/super/build.js +39 -0
  98. package/esm/super/build_context.d.ts +83 -0
  99. package/esm/super/build_context.d.ts.map +1 -0
  100. package/esm/super/build_context.js +124 -0
  101. package/esm/super/mod.d.ts +12 -0
  102. package/esm/super/mod.d.ts.map +1 -0
  103. package/esm/super/mod.js +9 -0
  104. package/esm/super/plugin.d.ts +23 -0
  105. package/esm/super/plugin.d.ts.map +1 -0
  106. package/esm/super/plugin.js +31 -0
  107. package/esm/super/plugin_build.d.ts +38 -0
  108. package/esm/super/plugin_build.d.ts.map +1 -0
  109. package/esm/super/plugin_build.js +198 -0
  110. package/esm/super/typedefs.d.ts +323 -0
  111. package/esm/super/typedefs.d.ts.map +1 -0
  112. package/esm/super/typedefs.js +10 -0
  113. package/esm/typedefs.d.ts +21 -0
  114. package/esm/typedefs.d.ts.map +1 -0
  115. package/esm/typedefs.js +5 -0
  116. package/license.md +37 -0
  117. package/package.json +88 -0
  118. package/readme.md +181 -0
@@ -0,0 +1,266 @@
1
+ /** utility functions for 2d arrays.
2
+ *
3
+ * a 2d array of type `T` is defined as `T[R][C]`, where `R` is the major-axis (axis=0), and `C` is the minor-axis (axis=1).
4
+ * internally, we call the major-axis the row-axis, and the minor-axis the column-axis (or col-axis).
5
+ *
6
+ * @module
7
+ */
8
+ /** a 2D array of cell type `T` */
9
+ export type Array2D<T> = T[][];
10
+ /** alias for a row-major 2D array */
11
+ export type Array2DRowMajor<T> = Array2D<T>;
12
+ /** alias for a column-major 2D array */
13
+ export type Array2DColMajor<T> = Array2D<T>;
14
+ type ShapeOfArray2D_Signatures = {
15
+ <T>(arr2d: Array2DRowMajor<T>): [rows: number, columns: number];
16
+ <T>(arr2d: Array2DColMajor<T>): [columns: number, rows: number];
17
+ <T>(arr2d: Array2D<T>): [major_length: number, minor_length: number];
18
+ };
19
+ /** get the shape of a 2d array as a 2-tuple describing the major-axis's length, and the minor-axis's length.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { assertEquals } from "jsr:@std/assert"
24
+ *
25
+ * const arr2d: Array2DRowMajor<number> = [
26
+ * [1 , 2 , 3 , 4 , 5 ],
27
+ * [6 , 7 , 8 , 9 , 10],
28
+ * [11, 12, 13, 14, 15],
29
+ * ]
30
+ * const [rows, cols] = shapeOfArray2D(arr2d)
31
+ * assertEquals(rows, 3)
32
+ * assertEquals(cols, 5)
33
+ * ```
34
+ */
35
+ export declare const shapeOfArray2D: ShapeOfArray2D_Signatures;
36
+ /** @deprecated this got renamed to {@link shapeOfArray2D | `shapeOfArray2D`} for naming consistency. */
37
+ export declare const Array2DShape: ShapeOfArray2D_Signatures;
38
+ /** create a new row-major 2d array, with provided value or fill function. */
39
+ export declare const newArray2D: <T>(rows: number, cols: number, fill_fn?: T | ((value?: undefined, column_index?: number, column_array?: (T | undefined)[]) => T)) => Array2DRowMajor<T>;
40
+ type TransposeArray2D_Signatures = {
41
+ <T>(arr2d: Array2DRowMajor<T>): Array2DColMajor<T>;
42
+ <T>(arr2d: Array2DColMajor<T>): Array2DRowMajor<T>;
43
+ };
44
+ /** transpose a 2D array (row-major to column-major, or vice versa)
45
+ *
46
+ * @param arr2d the 2D array to be transposed
47
+ * @returns the transposed 2D array
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { assertEquals } from "jsr:@std/assert"
52
+ *
53
+ * const arr2d: Array2DRowMajor<number> = [
54
+ * [1 , 2 , 3 , 4 , 5 ],
55
+ * [6 , 7 , 8 , 9 , 10],
56
+ * [11, 12, 13, 14, 15],
57
+ * ]
58
+ * const arr2d_transposed: Array2DColMajor<number> = transposeArray2D(arr2d)
59
+ * assertEquals(arr2d_transposed, [
60
+ * [1 , 6 , 11],
61
+ * [2 , 7 , 12],
62
+ * [3 , 8 , 13],
63
+ * [4 , 9 , 14],
64
+ * [5 , 10, 15],
65
+ * ])
66
+ * ```
67
+ */
68
+ export declare const transposeArray2D: TransposeArray2D_Signatures;
69
+ /** splice rows of a row-major 2D array and optionally insert new rows at the specified `start` index.
70
+ *
71
+ * @param arr2d the row-major 2D array to be spliced.
72
+ * @param start the row-index at which to start changing the array.
73
+ * @param delete_count the number of rows to remove. if `undefined`, all rows from `start` to the end of the array will be removed.
74
+ * @param insert_items optionally insert row-major based 2D array items the index of `start`.
75
+ * @returns a new row-major 2D array containing the deleted rows.
76
+ *
77
+ * @example
78
+ * delete `1` row from `arr2d` (starting at row-index `1`), and insert `2` new rows in its place.
79
+ *
80
+ * ```ts
81
+ * import { assertEquals } from "jsr:@std/assert"
82
+ *
83
+ * const arr2d: Array2DRowMajor<number> = [
84
+ * [1 , 2 , 3 , 4 , 5 ],
85
+ * [6 , 7 , 8 , 9 , 10],
86
+ * [11, 12, 13, 14, 15],
87
+ * ]
88
+ * const deleted_rows = spliceArray2DMajor(arr2d, 1, 1,
89
+ * [21, 22, 23, 24, 25],
90
+ * [31, 32, 33, 34, 35]
91
+ * )
92
+ * assertEquals(arr2d, [
93
+ * [1 , 2 , 3 , 4 , 5 ],
94
+ * [21, 22, 23, 24, 25],
95
+ * [31, 32, 33, 34, 35],
96
+ * [11, 12, 13, 14, 15],
97
+ * ])
98
+ * assertEquals(deleted_rows, [
99
+ * [6 , 7 , 8 , 9 , 10],
100
+ * ])
101
+ * ```
102
+ */
103
+ export declare const spliceArray2DMajor: <T>(arr2d: Array2DRowMajor<T>, start: number, delete_count?: number, ...insert_items: Array2DRowMajor<T>) => Array2DRowMajor<T>;
104
+ /** splice columns of a row-major 2D array and optionally insert new columns at the specified `start` index.
105
+ *
106
+ * @param arr2d the row-major 2D array to be spliced.
107
+ * @param start the column-index at which to start changing the array.
108
+ * @param delete_count the number of columns to remove. if `undefined`, all columns from `start` to the end of the array will be removed.
109
+ * @param insert_items optionally insert column-major based 2D array items the index of `start`.
110
+ * @returns a new column-major 2D array containing the deleted columns.
111
+ *
112
+ * @example
113
+ * delete `2` columns from `arr2d` (starting at column-index `1`), and insert `5` new columns in its place.
114
+ *
115
+ * ```ts
116
+ * import { assertEquals } from "jsr:@std/assert"
117
+ *
118
+ * const arr2d: Array2DRowMajor<number> = [
119
+ * [1 , 2 , 3 , 4 , 5 ],
120
+ * [6 , 7 , 8 , 9 , 10],
121
+ * [11, 12, 13, 14, 15],
122
+ * ]
123
+ * const deleted_cols = spliceArray2DMinor(arr2d, 1, 2,
124
+ * [21, 31, 41],
125
+ * [22, 32, 42],
126
+ * [23, 33, 43],
127
+ * [24, 34, 44],
128
+ * [25, 35, 45]
129
+ * )
130
+ * assertEquals(arr2d, [
131
+ * [1 , 21, 22, 23, 24, 25, 4 , 5 ],
132
+ * [6 , 31, 32, 33, 34, 35, 9 , 10],
133
+ * [11, 41, 42, 43, 44, 45, 14, 15],
134
+ * ])
135
+ * assertEquals(deleted_cols, [
136
+ * [2 , 7 , 12],
137
+ * [3 , 8 , 13],
138
+ * ])
139
+ * ```
140
+ */
141
+ export declare const spliceArray2DMinor: <T>(arr2d: Array2DRowMajor<T>, start: number, delete_count?: number, ...insert_items: Array2DColMajor<T>) => Array2DColMajor<T>;
142
+ /** mutate and rotate the major-axis of a 2D array by the specified amount to the right.
143
+ *
144
+ * given a row-major 2D array `arr2d`, this function would rotate its rows by the specified `amount`.
145
+ * a positive `amount` would rotate the rows to the right, and a negative `amount` would rotate it to the left.
146
+ *
147
+ * @param arr2d the 2D array to be rotated.
148
+ * @param amount The number of indexes to rotate the major-axis to the right.
149
+ * positive values rotate right, while negative values rotate left.
150
+ * @returns The original array is returned back after the rotation.
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * import { assertEquals } from "jsr:@std/assert"
155
+ *
156
+ * const arr2d: Array2DRowMajor<number> = [
157
+ * [1 , 2 , 3 ],
158
+ * [4 , 5 , 6 ],
159
+ * [7 , 8 , 9 ],
160
+ * [10, 11, 12],
161
+ * [13, 14, 15],
162
+ * ]
163
+ * rotateArray2DMajor(arr2d, 2)
164
+ * assertEquals(arr2d, [
165
+ * [10, 11, 12],
166
+ * [13, 14, 15],
167
+ * [1 , 2 , 3 ],
168
+ * [4 , 5 , 6 ],
169
+ * [7 , 8 , 9 ],
170
+ * ])
171
+ * ```
172
+ */
173
+ export declare const rotateArray2DMajor: <T>(arr2d: Array2DRowMajor<T>, amount: number) => typeof arr2d;
174
+ /** mutate and rotate the minor-axis of a 2D array by the specified amount to the right.
175
+ *
176
+ * given a row-major (and column-minor) 2D array `arr2d`, this function would rotate its columns by the specified `amount`.
177
+ * a positive `amount` would rotate the columns to the right, and a negative `amount` would rotate it to the left.
178
+ *
179
+ * @param arr2d the 2D array to be rotated.
180
+ * @param amount The number of indexes to rotate the minor-axis to the right.
181
+ * positive values rotate right, while negative values rotate left.
182
+ * @returns The original array is returned back after the rotation.
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * import { assertEquals } from "jsr:@std/assert"
187
+ *
188
+ * const arr2d: Array2DRowMajor<number> = [
189
+ * [1 , 2 , 3 , 4 , 5 , 6 ],
190
+ * [7 , 8 , 9 , 10, 11, 12],
191
+ * [13, 14, 15, 16, 17, 18],
192
+ * ]
193
+ * rotateArray2DMinor(arr2d, 2)
194
+ * assertEquals(arr2d, [
195
+ * [5 , 6 , 1 , 2 , 3 , 4 ,],
196
+ * [11, 12, 7 , 8 , 9 , 10,],
197
+ * [17, 18, 13, 14, 15, 16,],
198
+ * ])
199
+ * ```
200
+ */
201
+ export declare const rotateArray2DMinor: <T>(arr2d: Array2DRowMajor<T>, amount: number) => typeof arr2d;
202
+ /** create a mesh grid from major and minor values.
203
+ *
204
+ * given two arrays `major_values` and `minor_values`,
205
+ * this function generates a pair of 2D arrays representing the major-grid and minor-grid.
206
+ * the major-grid contains rows of `major_values`, and the minor-grid contains columns of `minor_values`.
207
+ *
208
+ * @param major_values the values to be used as rows in the major-grid
209
+ * @param minor_values the values to be used as columns in the minor-grid
210
+ * @returns a 2-tuple containing the major-grid and minor-grid as 2D arrays
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * import { assertEquals } from "jsr:@std/assert"
215
+ *
216
+ * const
217
+ * y_values = [1, 2, 3],
218
+ * x_values = [4, 5],
219
+ * [yy_grid, xx_grid] = meshGrid(y_values, x_values)
220
+ * assertEquals(yy_grid, [
221
+ * [1, 1],
222
+ * [2, 2],
223
+ * [3, 3],
224
+ * ])
225
+ * assertEquals(xx_grid, [
226
+ * [4, 5],
227
+ * [4, 5],
228
+ * [4, 5],
229
+ * ])
230
+ * ```
231
+ */
232
+ export declare const meshGrid: <T>(major_values: Array<T>, minor_values: Array<T>) => [major_grid: Array2D<T>, minor_grid: Array2D<T>];
233
+ /** map two arrays to a "field" of 2D array through a mapping function.
234
+ *
235
+ * given a mapping function `map_fn`, and two arrays `x_values` and `y_values`,
236
+ * this function generates a 2D array where each element is the result of applying
237
+ * `map_fn` to the corresponding elements from `x_values` and `y_values`.
238
+ *
239
+ * @param map_fn the mapping function that takes an `x` value from `x_values`
240
+ * and a `y` value from `y_values`, and returns the mapped z_value.
241
+ * @param x_values the values to be used as the major axis (rows) of the resulting 2D array.
242
+ * @param y_values the values to be used as the minor axis (columns) of the resulting 2D array.
243
+ * @returns a 2D array with mapped values from `x_values` and `y_values`
244
+ *
245
+ * @example
246
+ * `z` is a function of `x` and `y` defined by: `z(x, y) = x + y`. <br>
247
+ * to create a 2d grid of `z_values` using `x_values = [1, 2, 3]` and `y_values = [4, 5]`, we do the following:
248
+ *
249
+ * ```ts
250
+ * import { assertEquals } from "jsr:@std/assert"
251
+ *
252
+ * const
253
+ * add = (x: number, y: number) => (x + y),
254
+ * x_values = [1, 2, 3],
255
+ * y_values = [4, 5],
256
+ * z_values = meshMap(add, x_values, y_values)
257
+ * assertEquals(z_values, [
258
+ * [5, 6],
259
+ * [6, 7],
260
+ * [7, 8],
261
+ * ])
262
+ * ```
263
+ */
264
+ export declare const meshMap: <X, Y, Z>(map_fn: (x: X, y: Y) => Z, x_values: Array<X>, y_values: Array<Y>) => Array2D<Z>;
265
+ export {};
266
+ //# sourceMappingURL=array2d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array2d.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAMF,kCAAkC;AAClC,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAA;AAE9B,qCAAqC;AACrC,MAAM,MAAM,eA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,KAAK,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAe7G,CAAA"}
@@ -0,0 +1,318 @@
1
+ /** utility functions for 2d arrays.
2
+ *
3
+ * a 2d array of type `T` is defined as `T[R][C]`, where `R` is the major-axis (axis=0), and `C` is the minor-axis (axis=1).
4
+ * internally, we call the major-axis the row-axis, and the minor-axis the column-axis (or col-axis).
5
+ *
6
+ * @module
7
+ */
8
+ import { max, modulo } from "./numericmethods.js";
9
+ import { isFunction } from "./struct.js";
10
+ /** get the shape of a 2d array as a 2-tuple describing the major-axis's length, and the minor-axis's length.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { assertEquals } from "jsr:@std/assert"
15
+ *
16
+ * const arr2d: Array2DRowMajor<number> = [
17
+ * [1 , 2 , 3 , 4 , 5 ],
18
+ * [6 , 7 , 8 , 9 , 10],
19
+ * [11, 12, 13, 14, 15],
20
+ * ]
21
+ * const [rows, cols] = shapeOfArray2D(arr2d)
22
+ * assertEquals(rows, 3)
23
+ * assertEquals(cols, 5)
24
+ * ```
25
+ */
26
+ export const shapeOfArray2D = (arr2d) => {
27
+ const major_len = arr2d.length, minor_len = arr2d[0]?.length ?? 0;
28
+ return [major_len, minor_len];
29
+ };
30
+ // TODO: deprecate this later on, as I didn't like the inconsistency in function naming, and the CamelCasing, instead of pascalCasing
31
+ /** @deprecated this got renamed to {@link shapeOfArray2D | `shapeOfArray2D`} for naming consistency. */
32
+ export const Array2DShape = shapeOfArray2D;
33
+ /** create a new row-major 2d array, with provided value or fill function. */
34
+ export const newArray2D = (rows, cols, fill_fn) => {
35
+ const col_map_fn = isFunction(fill_fn) ?
36
+ () => Array(cols).fill(undefined).map(fill_fn) :
37
+ () => Array(cols).fill(fill_fn);
38
+ return Array(rows).fill(undefined).map(col_map_fn);
39
+ };
40
+ /** transpose a 2D array (row-major to column-major, or vice versa)
41
+ *
42
+ * @param arr2d the 2D array to be transposed
43
+ * @returns the transposed 2D array
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * import { assertEquals } from "jsr:@std/assert"
48
+ *
49
+ * const arr2d: Array2DRowMajor<number> = [
50
+ * [1 , 2 , 3 , 4 , 5 ],
51
+ * [6 , 7 , 8 , 9 , 10],
52
+ * [11, 12, 13, 14, 15],
53
+ * ]
54
+ * const arr2d_transposed: Array2DColMajor<number> = transposeArray2D(arr2d)
55
+ * assertEquals(arr2d_transposed, [
56
+ * [1 , 6 , 11],
57
+ * [2 , 7 , 12],
58
+ * [3 , 8 , 13],
59
+ * [4 , 9 , 14],
60
+ * [5 , 10, 15],
61
+ * ])
62
+ * ```
63
+ */
64
+ export const transposeArray2D = (arr2d) => {
65
+ const [rows, cols] = shapeOfArray2D(arr2d), arr_transposed = [];
66
+ for (let c = 0; c < cols; c++) {
67
+ arr_transposed[c] = [];
68
+ }
69
+ for (let r = 0; r < rows; r++) {
70
+ for (let c = 0; c < cols; c++) {
71
+ arr_transposed[c][r] = arr2d[r][c];
72
+ }
73
+ }
74
+ return arr_transposed;
75
+ };
76
+ /** splice rows of a row-major 2D array and optionally insert new rows at the specified `start` index.
77
+ *
78
+ * @param arr2d the row-major 2D array to be spliced.
79
+ * @param start the row-index at which to start changing the array.
80
+ * @param delete_count the number of rows to remove. if `undefined`, all rows from `start` to the end of the array will be removed.
81
+ * @param insert_items optionally insert row-major based 2D array items the index of `start`.
82
+ * @returns a new row-major 2D array containing the deleted rows.
83
+ *
84
+ * @example
85
+ * delete `1` row from `arr2d` (starting at row-index `1`), and insert `2` new rows in its place.
86
+ *
87
+ * ```ts
88
+ * import { assertEquals } from "jsr:@std/assert"
89
+ *
90
+ * const arr2d: Array2DRowMajor<number> = [
91
+ * [1 , 2 , 3 , 4 , 5 ],
92
+ * [6 , 7 , 8 , 9 , 10],
93
+ * [11, 12, 13, 14, 15],
94
+ * ]
95
+ * const deleted_rows = spliceArray2DMajor(arr2d, 1, 1,
96
+ * [21, 22, 23, 24, 25],
97
+ * [31, 32, 33, 34, 35]
98
+ * )
99
+ * assertEquals(arr2d, [
100
+ * [1 , 2 , 3 , 4 , 5 ],
101
+ * [21, 22, 23, 24, 25],
102
+ * [31, 32, 33, 34, 35],
103
+ * [11, 12, 13, 14, 15],
104
+ * ])
105
+ * assertEquals(deleted_rows, [
106
+ * [6 , 7 , 8 , 9 , 10],
107
+ * ])
108
+ * ```
109
+ */
110
+ export const spliceArray2DMajor = (arr2d, start, delete_count, ...insert_items) => {
111
+ const [rows, cols] = shapeOfArray2D(arr2d);
112
+ delete_count ??= max(rows - start, 0);
113
+ return arr2d.splice(start, delete_count, ...insert_items);
114
+ };
115
+ /** splice columns of a row-major 2D array and optionally insert new columns at the specified `start` index.
116
+ *
117
+ * @param arr2d the row-major 2D array to be spliced.
118
+ * @param start the column-index at which to start changing the array.
119
+ * @param delete_count the number of columns to remove. if `undefined`, all columns from `start` to the end of the array will be removed.
120
+ * @param insert_items optionally insert column-major based 2D array items the index of `start`.
121
+ * @returns a new column-major 2D array containing the deleted columns.
122
+ *
123
+ * @example
124
+ * delete `2` columns from `arr2d` (starting at column-index `1`), and insert `5` new columns in its place.
125
+ *
126
+ * ```ts
127
+ * import { assertEquals } from "jsr:@std/assert"
128
+ *
129
+ * const arr2d: Array2DRowMajor<number> = [
130
+ * [1 , 2 , 3 , 4 , 5 ],
131
+ * [6 , 7 , 8 , 9 , 10],
132
+ * [11, 12, 13, 14, 15],
133
+ * ]
134
+ * const deleted_cols = spliceArray2DMinor(arr2d, 1, 2,
135
+ * [21, 31, 41],
136
+ * [22, 32, 42],
137
+ * [23, 33, 43],
138
+ * [24, 34, 44],
139
+ * [25, 35, 45]
140
+ * )
141
+ * assertEquals(arr2d, [
142
+ * [1 , 21, 22, 23, 24, 25, 4 , 5 ],
143
+ * [6 , 31, 32, 33, 34, 35, 9 , 10],
144
+ * [11, 41, 42, 43, 44, 45, 14, 15],
145
+ * ])
146
+ * assertEquals(deleted_cols, [
147
+ * [2 , 7 , 12],
148
+ * [3 , 8 , 13],
149
+ * ])
150
+ * ```
151
+ */
152
+ export const spliceArray2DMinor = (arr2d, start, delete_count, ...insert_items) => {
153
+ const [rows, cols] = shapeOfArray2D(arr2d), insert_items_rowwise = insert_items.length > 0 ?
154
+ transposeArray2D(insert_items) :
155
+ Array(rows).fill([]);
156
+ delete_count ??= max(cols - start, 0);
157
+ return transposeArray2D(arr2d.map((row_items, row) => row_items.splice(start, delete_count, ...insert_items_rowwise[row])));
158
+ };
159
+ /** mutate and rotate the major-axis of a 2D array by the specified amount to the right.
160
+ *
161
+ * given a row-major 2D array `arr2d`, this function would rotate its rows by the specified `amount`.
162
+ * a positive `amount` would rotate the rows to the right, and a negative `amount` would rotate it to the left.
163
+ *
164
+ * @param arr2d the 2D array to be rotated.
165
+ * @param amount The number of indexes to rotate the major-axis to the right.
166
+ * positive values rotate right, while negative values rotate left.
167
+ * @returns The original array is returned back after the rotation.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * import { assertEquals } from "jsr:@std/assert"
172
+ *
173
+ * const arr2d: Array2DRowMajor<number> = [
174
+ * [1 , 2 , 3 ],
175
+ * [4 , 5 , 6 ],
176
+ * [7 , 8 , 9 ],
177
+ * [10, 11, 12],
178
+ * [13, 14, 15],
179
+ * ]
180
+ * rotateArray2DMajor(arr2d, 2)
181
+ * assertEquals(arr2d, [
182
+ * [10, 11, 12],
183
+ * [13, 14, 15],
184
+ * [1 , 2 , 3 ],
185
+ * [4 , 5 , 6 ],
186
+ * [7 , 8 , 9 ],
187
+ * ])
188
+ * ```
189
+ */
190
+ export const rotateArray2DMajor = (arr2d, amount) => {
191
+ const [rows, cols] = shapeOfArray2D(arr2d);
192
+ // compute the effective right-rotation amount so that it handles negative values and full rotations
193
+ amount = modulo(amount, rows === 0 ? 1 : rows);
194
+ // there is nothing to rotate if the effective amount is zero
195
+ if (amount === 0) {
196
+ return arr2d;
197
+ }
198
+ const right_removed_rows = spliceArray2DMajor(arr2d, rows - amount, amount);
199
+ spliceArray2DMajor(arr2d, 0, 0, ...right_removed_rows);
200
+ return arr2d;
201
+ };
202
+ /** mutate and rotate the minor-axis of a 2D array by the specified amount to the right.
203
+ *
204
+ * given a row-major (and column-minor) 2D array `arr2d`, this function would rotate its columns by the specified `amount`.
205
+ * a positive `amount` would rotate the columns to the right, and a negative `amount` would rotate it to the left.
206
+ *
207
+ * @param arr2d the 2D array to be rotated.
208
+ * @param amount The number of indexes to rotate the minor-axis to the right.
209
+ * positive values rotate right, while negative values rotate left.
210
+ * @returns The original array is returned back after the rotation.
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * import { assertEquals } from "jsr:@std/assert"
215
+ *
216
+ * const arr2d: Array2DRowMajor<number> = [
217
+ * [1 , 2 , 3 , 4 , 5 , 6 ],
218
+ * [7 , 8 , 9 , 10, 11, 12],
219
+ * [13, 14, 15, 16, 17, 18],
220
+ * ]
221
+ * rotateArray2DMinor(arr2d, 2)
222
+ * assertEquals(arr2d, [
223
+ * [5 , 6 , 1 , 2 , 3 , 4 ,],
224
+ * [11, 12, 7 , 8 , 9 , 10,],
225
+ * [17, 18, 13, 14, 15, 16,],
226
+ * ])
227
+ * ```
228
+ */
229
+ export const rotateArray2DMinor = (arr2d, amount) => {
230
+ const [rows, cols] = shapeOfArray2D(arr2d);
231
+ // compute the effective right-rotation amount so that it handles negative values and full rotations
232
+ amount = modulo(amount, cols === 0 ? 1 : cols);
233
+ // there is nothing to rotate if the effective amount is zero
234
+ if (amount === 0) {
235
+ return arr2d;
236
+ }
237
+ const right_removed_cols = spliceArray2DMinor(arr2d, cols - amount, amount);
238
+ spliceArray2DMinor(arr2d, 0, 0, ...right_removed_cols);
239
+ return arr2d;
240
+ };
241
+ /** create a mesh grid from major and minor values.
242
+ *
243
+ * given two arrays `major_values` and `minor_values`,
244
+ * this function generates a pair of 2D arrays representing the major-grid and minor-grid.
245
+ * the major-grid contains rows of `major_values`, and the minor-grid contains columns of `minor_values`.
246
+ *
247
+ * @param major_values the values to be used as rows in the major-grid
248
+ * @param minor_values the values to be used as columns in the minor-grid
249
+ * @returns a 2-tuple containing the major-grid and minor-grid as 2D arrays
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * import { assertEquals } from "jsr:@std/assert"
254
+ *
255
+ * const
256
+ * y_values = [1, 2, 3],
257
+ * x_values = [4, 5],
258
+ * [yy_grid, xx_grid] = meshGrid(y_values, x_values)
259
+ * assertEquals(yy_grid, [
260
+ * [1, 1],
261
+ * [2, 2],
262
+ * [3, 3],
263
+ * ])
264
+ * assertEquals(xx_grid, [
265
+ * [4, 5],
266
+ * [4, 5],
267
+ * [4, 5],
268
+ * ])
269
+ * ```
270
+ */
271
+ export const meshGrid = (major_values, minor_values) => {
272
+ const
273
+ // axis0_len = major_values.length,
274
+ axis1_len = minor_values.length, major_grid = major_values.map((major_val) => Array(axis1_len).fill(major_val)), minor_grid = major_values.map(() => minor_values.slice());
275
+ return [major_grid, minor_grid];
276
+ };
277
+ /** map two arrays to a "field" of 2D array through a mapping function.
278
+ *
279
+ * given a mapping function `map_fn`, and two arrays `x_values` and `y_values`,
280
+ * this function generates a 2D array where each element is the result of applying
281
+ * `map_fn` to the corresponding elements from `x_values` and `y_values`.
282
+ *
283
+ * @param map_fn the mapping function that takes an `x` value from `x_values`
284
+ * and a `y` value from `y_values`, and returns the mapped z_value.
285
+ * @param x_values the values to be used as the major axis (rows) of the resulting 2D array.
286
+ * @param y_values the values to be used as the minor axis (columns) of the resulting 2D array.
287
+ * @returns a 2D array with mapped values from `x_values` and `y_values`
288
+ *
289
+ * @example
290
+ * `z` is a function of `x` and `y` defined by: `z(x, y) = x + y`. <br>
291
+ * to create a 2d grid of `z_values` using `x_values = [1, 2, 3]` and `y_values = [4, 5]`, we do the following:
292
+ *
293
+ * ```ts
294
+ * import { assertEquals } from "jsr:@std/assert"
295
+ *
296
+ * const
297
+ * add = (x: number, y: number) => (x + y),
298
+ * x_values = [1, 2, 3],
299
+ * y_values = [4, 5],
300
+ * z_values = meshMap(add, x_values, y_values)
301
+ * assertEquals(z_values, [
302
+ * [5, 6],
303
+ * [6, 7],
304
+ * [7, 8],
305
+ * ])
306
+ * ```
307
+ */
308
+ export const meshMap = (map_fn, x_values, y_values) => {
309
+ const axis0_len = x_values.length, axis1_len = y_values.length, z_values = Array(axis0_len).fill(undefined);
310
+ for (let x_idx = 0; x_idx < axis0_len; x_idx++) {
311
+ const row = Array(axis1_len).fill(0), x = x_values[x_idx];
312
+ for (let y_idx = 0; y_idx < axis1_len; y_idx++) {
313
+ row[y_idx] = map_fn(x, y_values[y_idx]);
314
+ }
315
+ z_values[x_idx] = row;
316
+ }
317
+ return z_values;
318
+ };