Skip to content

Inline function constructors of ndarray-pack module #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ logs
results

npm-debug.log
package-lock.json
node_modules/*
16 changes: 0 additions & 16 deletions build.js

This file was deleted.

88 changes: 87 additions & 1 deletion doConvert.js
Original file line number Diff line number Diff line change
@@ -1 +1,87 @@
module.exports=require('cwise-compiler')({"args":["array","scalar","index"],"pre":{"body":"{}","args":[],"thisVars":[],"localVars":[]},"body":{"body":"{\nvar _inline_1_v=_inline_1_arg1_,_inline_1_i\nfor(_inline_1_i=0;_inline_1_i<_inline_1_arg2_.length-1;++_inline_1_i) {\n_inline_1_v=_inline_1_v[_inline_1_arg2_[_inline_1_i]]\n}\n_inline_1_arg0_=_inline_1_v[_inline_1_arg2_[_inline_1_arg2_.length-1]]\n}","args":[{"name":"_inline_1_arg0_","lvalue":true,"rvalue":false,"count":1},{"name":"_inline_1_arg1_","lvalue":false,"rvalue":true,"count":1},{"name":"_inline_1_arg2_","lvalue":false,"rvalue":true,"count":4}],"thisVars":[],"localVars":["_inline_1_i","_inline_1_v"]},"post":{"body":"{}","args":[],"thisVars":[],"localVars":[]},"funcName":"convert","blockSize":64})
"use strict"

function CwiseOp() {
return function (SS, a0, t0, p0, Y0) {
var s0 = SS[0],
s1 = SS[1],
s2 = SS[2],
t0p0 = t0[0],
t0p1 = t0[1],
t0p2 = t0[2],
index = [0, 0, 0];
p0 |= 0;
var i0 = 0,
i1 = 0,
i2 = 0,
d0s0 = t0p2,
d0s1 = t0p1 - s2 * t0p2,
d0s2 = t0p0 - s1 * t0p1;
for (i2 = 0; i2 < s0; ++i2) {
for (i1 = 0; i1 < s1; ++i1) {
for (i0 = 0; i0 < s2; ++i0) {
{
var _inline_1_v = Y0,
_inline_1_i;
for (
_inline_1_i = 0;
_inline_1_i < index.length - 1;
++_inline_1_i
) {
_inline_1_v = _inline_1_v[index[_inline_1_i]];
}
a0[p0] = _inline_1_v[index[index.length - 1]];
}
p0 += d0s0;
++index[2];
}
p0 += d0s1;
index[2] -= s2;
++index[1];
}
p0 += d0s2;
index[1] -= s1;
++index[0];
}
};
}

//Generates a cwise operator
function generateCWiseOp() {
return CwiseOp()
}

var compile = generateCWiseOp

function thunk(compile) {
var CACHED = {};
return function convert_cwise_thunk(array0, scalar1) {
var t0 = array0.dtype,
r0 = array0.order,
type = [t0, r0.join()].join(),
proc = CACHED[type];
if (!proc) {
CACHED[type] = proc = compile([t0, r0]);
}
return proc(
array0.shape.slice(0),
array0.data,
array0.stride,
array0.offset | 0,
scalar1
);
};
}

function createThunk(proc) {
return thunk(compile.bind(undefined, proc))
}

function compileCwise(user_args) {
return createThunk({
funcName: user_args.funcName
})
}

module.exports = compileCwise({
funcName: "convert"
});
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
"test": "test"
},
"dependencies": {
"cwise-compiler": "^1.1.2",
"ndarray": "^1.0.13"
},
"devDependencies": {
"tap": "~0.4.2",
"cwise-bake": "0.0.0"
},
"scripts": {
"test": "tap test/*.js",
"build": "node build.js > doConvert.js"
"test": "tap test/*.js"
},
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

require("tap").test("ndarray-pack", function(t) {

var x = [[1, 0, 1],
var x = [[[1, 0, 1],
[0, 1, 1],
[0, 0, 1],
[1, 0, 0]]
[1, 0, 0]]]

var y = require("../convert.js")(x)

for(var i=0; i<4; ++i) {
for(var j=0; j<3; ++j) {
t.equals(y.get(i,j), x[i][j])
t.equals(y.get(0,i,j), x[0][i][j])
}
}

var x = [[[1, 2]], [[3,4]], [[5,6]]]
var y = require("../convert.js")(x)

Expand Down