@tensorflow/tfjs-core
Version:
Hardware-accelerated JavaScript library for machine intelligence
85 lines (84 loc) • 2.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var environment_1 = require("./environment");
var backend_cpu_1 = require("./kernels/backend_cpu");
var backend_webgl_1 = require("./kernels/backend_webgl");
function describeWithFlags(name, constraints, tests) {
var envFeatures = TEST_ENV_FEATURES.filter(function (f) {
return Object.keys(constraints).every(function (key) {
return constraints[key] === f[key];
});
});
envFeatures.forEach(function (features) {
var testName = name + ' ' + JSON.stringify(features);
executeTests(testName, tests, features);
});
}
exports.describeWithFlags = describeWithFlags;
var BEFORE_ALL = function (features) {
environment_1.ENV.registerBackend('test-webgl', function () { return new backend_webgl_1.MathBackendWebGL(); });
environment_1.ENV.registerBackend('test-cpu', function () { return new backend_cpu_1.MathBackendCPU(); });
};
var AFTER_ALL = function (features) {
environment_1.ENV.removeBackend('test-webgl');
environment_1.ENV.removeBackend('test-cpu');
};
var BEFORE_EACH = function (features) { };
var AFTER_EACH = function (features) { };
var TEST_ENV_FEATURES = [
{
'BACKEND': 'test-webgl',
'WEBGL_FLOAT_TEXTURE_ENABLED': true,
'WEBGL_VERSION': 1
},
{
'BACKEND': 'test-webgl',
'WEBGL_FLOAT_TEXTURE_ENABLED': true,
'WEBGL_VERSION': 2
},
{ 'BACKEND': 'test-cpu' }
];
function setBeforeAll(f) {
BEFORE_ALL = f;
}
exports.setBeforeAll = setBeforeAll;
function setAfterAll(f) {
AFTER_ALL = f;
}
exports.setAfterAll = setAfterAll;
function setBeforeEach(f) {
BEFORE_EACH = f;
}
exports.setBeforeEach = setBeforeEach;
function setAfterEach(f) {
AFTER_EACH = f;
}
exports.setAfterEach = setAfterEach;
function setTestEnvFeatures(features) {
TEST_ENV_FEATURES = features;
}
exports.setTestEnvFeatures = setTestEnvFeatures;
function executeTests(testName, tests, features) {
describe(testName, function () {
beforeAll(function () {
environment_1.ENV.setFeatures(features);
BEFORE_ALL(features);
});
beforeEach(function () {
BEFORE_EACH(features);
if (features && features.BACKEND != null) {
environment_1.Environment.setBackend(features.BACKEND);
}
environment_1.ENV.engine.startScope();
});
afterEach(function () {
environment_1.ENV.engine.endScope(null);
AFTER_EACH(features);
});
afterAll(function () {
AFTER_ALL(features);
environment_1.ENV.reset();
});
tests();
});
}