kopia lustrzana https://github.com/backface/turtlestitch
refactored list.crossproduct() to avoid JS stack overflows
rodzic
81ad8de5d7
commit
1b72285310
|
@ -9,7 +9,10 @@
|
||||||
* **Documentation Updates:**
|
* **Documentation Updates:**
|
||||||
* updated manual (e.g. p.20) with hyper-semantics of ITEM OF, thanks Brian
|
* updated manual (e.g. p.20) with hyper-semantics of ITEM OF, thanks Brian
|
||||||
|
|
||||||
### 2021-02-06
|
### 2021-02-09
|
||||||
|
* lists: refactored matrix ops to avoid JS stack overflows
|
||||||
|
|
||||||
|
### 2021-02-08
|
||||||
* lists, objects, threads: new RESHAPE primitive
|
* lists, objects, threads: new RESHAPE primitive
|
||||||
* lists: added internal naive (recursive) version of CROSSPRODUCT
|
* lists: added internal naive (recursive) version of CROSSPRODUCT
|
||||||
* lists: added TRANSPOSE for higher dimensions, thanks, Brian!
|
* lists: added TRANSPOSE for higher dimensions, thanks, Brian!
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<script src="src/symbols.js?version=2020-10-07"></script>
|
<script src="src/symbols.js?version=2020-10-07"></script>
|
||||||
<script src="src/widgets.js?version=2021-01-05"></script>
|
<script src="src/widgets.js?version=2021-01-05"></script>
|
||||||
<script src="src/blocks.js?version=2021-02-08"></script>
|
<script src="src/blocks.js?version=2021-02-08"></script>
|
||||||
<script src="src/threads.js?version=2021-02-08"></script>
|
<script src="src/threads.js?version=2021-02-09"></script>
|
||||||
<script src="src/objects.js?version=2021-02-08"></script>
|
<script src="src/objects.js?version=2021-02-08"></script>
|
||||||
<script src="src/gui.js?version=2021-02-04"></script>
|
<script src="src/gui.js?version=2021-02-04"></script>
|
||||||
<script src="src/paint.js?version=2020-05-17"></script>
|
<script src="src/paint.js?version=2020-05-17"></script>
|
||||||
|
|
32
src/lists.js
32
src/lists.js
|
@ -63,7 +63,7 @@ MorphicPreferences, TableDialogMorph, SpriteBubbleMorph, SpeechBubbleMorph,
|
||||||
TableFrameMorph, TableMorph, Variable, isSnapObject, Costume, contains, detect,
|
TableFrameMorph, TableMorph, Variable, isSnapObject, Costume, contains, detect,
|
||||||
ZERO, WHITE*/
|
ZERO, WHITE*/
|
||||||
|
|
||||||
modules.lists = '2021-February-08';
|
modules.lists = '2021-February-09';
|
||||||
|
|
||||||
var List;
|
var List;
|
||||||
var ListWatcherMorph;
|
var ListWatcherMorph;
|
||||||
|
@ -544,7 +544,8 @@ List.prototype.getDimension = function (rank = 0) {
|
||||||
};
|
};
|
||||||
|
|
||||||
List.prototype.width = function () {
|
List.prototype.width = function () {
|
||||||
// private - answer the maximum length of my direct sub-lists (columns), if any
|
// private - answer the maximum length of my direct sub-lists (columns),
|
||||||
|
// if any
|
||||||
var i, item,
|
var i, item,
|
||||||
width = 0,
|
width = 0,
|
||||||
len = this.length();
|
len = this.length();
|
||||||
|
@ -660,14 +661,27 @@ List.prototype.crossproduct = function () {
|
||||||
// expects myself to be a list of lists.
|
// expects myself to be a list of lists.
|
||||||
// answers a new list of all possible tuples
|
// answers a new list of all possible tuples
|
||||||
// with one item from each of my sublists
|
// with one item from each of my sublists
|
||||||
if (this.isEmpty()) {
|
var result = new List(),
|
||||||
return new List([new List()]);
|
len = this.length(),
|
||||||
|
lengths = this.map(each => each.length()),
|
||||||
|
size = lengths.itemsArray().reduce((a, b) => a * b),
|
||||||
|
i, k, row, factor;
|
||||||
|
|
||||||
|
for (i = 1; i <= size; i += 1) {
|
||||||
|
row = new List();
|
||||||
|
factor = 1;
|
||||||
|
for (k = 1; k <= len; k += 1) {
|
||||||
|
row.add(
|
||||||
|
this.at(k).at(
|
||||||
|
((Math.ceil(i / ((size / lengths.at(k)) * factor)) - 1) %
|
||||||
|
lengths.at(k)) + 1
|
||||||
|
)
|
||||||
|
);
|
||||||
|
factor /= lengths.at(k);
|
||||||
|
}
|
||||||
|
result.add(row);
|
||||||
}
|
}
|
||||||
return this.at(1).map(
|
return result;
|
||||||
first => this.cdr().crossproduct().map(
|
|
||||||
each => this.cons(first, each)
|
|
||||||
)
|
|
||||||
).flatten();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
List.prototype.strideTranspose = function () {
|
List.prototype.strideTranspose = function () {
|
||||||
|
|
Ładowanie…
Reference in New Issue