Skip to content

Commit

Permalink
transform uses prepareUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Dec 7, 2021
1 parent 953dfdb commit 63ffa81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/xdim.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,19 @@ function iterPoints({ order, sizes, rect = {} }) {
});
}

function transform({ data, fill, from, to, sizes, useLayoutCache = true }) {
function transform({ data, fill = undefined, from, to, sizes, useLayoutCache = true }) {
if (typeof from === "string") from = parse(from, { useLayoutCache });
if (typeof to === "string") to = parse(to, { useLayoutCache });

const { data: out_data } = prepareData({ fill, layout: to, sizes });

const update = prepareUpdate({
useLayoutCache,
data: out_data,
layout: to,
sizes
});

const points = iterPoints({ sizes });

for (point of points) {
Expand All @@ -499,10 +506,7 @@ function transform({ data, fill, from, to, sizes, useLayoutCache = true }) {

// insert into new frame
update({
data: out_data,
layout: to,
point,
sizes,
value
});
}
Expand Down
13 changes: 12 additions & 1 deletion tests/perf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const test = require("flug");
const { prepareData, prepareSelect, select, update, prepareUpdate } = require("../src/xdim");
const { prepareData, prepareSelect, select, update, prepareUpdate, transform } = require("../src/xdim");

const sizes = { a: 4, b: 1e3, c: 1e3 };
const layout = "[a][b][c]";
Expand Down Expand Up @@ -83,3 +83,14 @@ test("perf: prepareUpdate [band][row,column]", ({ eq }) => {
}
console.timeEnd("perf: prepareUpdate [band][row,column]");
});

test("perf: transform [band][row,column] to [row,column,band]", ({ eq }) => {
console.time("perf: transform [band][row,column] to [row,column,band]");
transform({
data,
from: im_layout,
to: "[row,column,band]",
sizes: im_sizes
});
console.timeEnd("perf: transform [band][row,column] to [row,column,band]");
});

0 comments on commit 63ffa81

Please sign in to comment.