Skip to content

Commit

Permalink
Last batch of builtins implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
dherre3 committed Jul 23, 2018
1 parent e2f4032 commit 7d538ce
Show file tree
Hide file tree
Showing 67 changed files with 8,988 additions and 1,452 deletions.
2 changes: 2 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[include]
./*.js
109 changes: 109 additions & 0 deletions bin/classes/Runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var MxVector_1 = require("./mxarray/MxVector");
exports.MxVector = MxVector_1.MxVector;
var MxNdArray_1 = require("./mxarray/MxNdArray");
exports.MxNDArray = MxNdArray_1.MxNDArray;
// declare var wi:any;
var MatlabRuntime = /** @class */ (function () {
function MatlabRuntime(wis) {
this.started = false;
this.wi = wis;
this.started = true;
}
MatlabRuntime.prototype.startRuntime = function (wis) {
this.wi = wis;
this.started = true;
};
MatlabRuntime.prototype.checkForStartedRuntime = function () {
if (!this.started) {
throw new Error("Please initialize Matlab Runtime");
}
};
MatlabRuntime.prototype.isRuntimeStarted = function () {
return this.started;
};
MatlabRuntime.prototype.horzcat = function (args) {
return this.concat(2, args);
};
MatlabRuntime.prototype.vertcat = function (args) {
return this.concat(1, args);
};
MatlabRuntime.prototype.concat = function (dim, args) {
var _this = this;
this.checkForStartedRuntime();
var input_vec = this.wi.create_mxvector(args.length, 5);
args.forEach(function (arr, idx) {
_this.wi.set_array_index_i32(input_vec, idx + 1, arr.arr_ptr);
});
return new MxNdArray_1.MxNDArray(this.wi, this.wi.concat(dim, input_vec));
};
MatlabRuntime.prototype.reshape = function (arr, dims) {
return arr.reshape(dims);
};
MatlabRuntime.prototype.colon = function (start, stepEnd, end) {
this.checkForStartedRuntime();
var input_vec;
if (typeof end == "undefined") {
var dim_1 = this.wi.create_mxvector(1);
var dim_2 = this.wi.create_mxvector(1);
input_vec = this.wi.create_mxvector(2, 5);
this.wi.set_array_index_f64(dim_1, 1, start);
this.wi.set_array_index_f64(dim_2, 1, stepEnd);
this.wi.set_array_index_i32(input_vec, 1, dim_1);
this.wi.set_array_index_i32(input_vec, 2, dim_2);
}
else {
var dim_1 = this.wi.create_mxvector(1);
var dim_2 = this.wi.create_mxvector(1);
var dim_3 = this.wi.create_mxvector(1);
input_vec = this.wi.create_mxvector(3, 5);
var param_arr = this.wi.create_mxvector(3, 5);
this.wi.set_array_index_f64(dim_1, 1, start);
this.wi.set_array_index_f64(dim_2, 1, stepEnd);
this.wi.set_array_index_f64(dim_3, 1, end);
this.wi.set_array_index_i32(input_vec, 1, dim_1);
this.wi.set_array_index_i32(input_vec, 2, dim_2);
this.wi.set_array_index_i32(input_vec, 3, dim_3);
}
return new MxNdArray_1.MxNDArray(this.wi, this.wi.colon(input_vec));
};
MatlabRuntime.prototype.size = function (arr) {
this.checkForStartedRuntime();
return arr.size();
};
MatlabRuntime.prototype.numel = function (arr) {
this.checkForStartedRuntime();
return arr.numel();
};
MatlabRuntime.prototype.length = function (arr) {
this.checkForStartedRuntime();
return arr.length();
};
MatlabRuntime.prototype.isrow = function (arr) {
this.checkForStartedRuntime();
return arr.isrow();
};
MatlabRuntime.prototype.iscolumn = function (arr) {
this.checkForStartedRuntime();
return arr.iscolumn();
};
MatlabRuntime.prototype.ismatrix = function (arr) {
this.checkForStartedRuntime();
return arr.ismatrix();
};
MatlabRuntime.prototype.isvector = function (arr) {
this.checkForStartedRuntime();
return arr.isvector();
};
MatlabRuntime.prototype.isempty = function (arr) {
this.checkForStartedRuntime();
return arr.isempty();
};
MatlabRuntime.prototype.clone = function (arr) {
this.checkForStartedRuntime();
return arr.clone();
};
return MatlabRuntime;
}());
exports.MatlabRuntime = MatlabRuntime;
16 changes: 0 additions & 16 deletions bin/classes/mxarray/MxArray.d.ts

This file was deleted.

111 changes: 76 additions & 35 deletions bin/classes/mxarray/MxArray.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,80 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
class MxArray {
getContents() {
return new Float64Array(this.wi.mem, this.arr_ptr, this.numel());
var MxObject_1 = require("./MxObject");
var MxArray = /** @class */ (function (_super) {
__extends(MxArray, _super);
function MxArray() {
return _super !== null && _super.apply(this, arguments) || this;
}
set_index(ind, val) {
return this.wi.set_array_index_f64(this.arr_ptr, ind, val);
}
get_index(ind) {
return this.wi.get_array_index_f64(this.arr_ptr, ind);
}
numel() {
return this.wi.numel(this.arr_ptr);
}
ndims() {
return this.wi.ndims(this.arr_ptr);
}
length() {
return this.wi.length(this.arr_ptr);
}
isrow() {
return this.wi.isrow(this.arr_ptr) === 1;
}
iscolumn() {
return this.wi.isvector(this.arr_ptr) === 1;
}
ismatrix() {
return this.wi.ismatrix(this.arr_ptr) === 1;
}
isvector() {
return this.wi.isvector(this.arr_ptr) === 1;
}
isempty() {
return this.wi.isempty(this.arr_ptr) === 1;
}
}
MxArray.prototype.set_index = function (ind, val) {
if (ind === void 0) { ind = -1; }
if (val === void 0) { val = NaN; }
return this._wi.set_array_index_f64(this._arr_ptr, ind, val);
};
MxArray.prototype.get_index = function (ind) {
if (ind === void 0) { ind = -1; }
return this._wi.get_array_index_f64(this._arr_ptr, ind);
};
MxArray.prototype.get_indices = function (indices) {
var _this = this;
var indices_arr_ptr = this._wi.create_mxvector(indices.length, 5); // Create mxvector with int type
indices.forEach(function (dimArr, indDim) {
var index_arr_ptr = _this._wi.create_mxvector(dimArr.length);
dimArr.forEach(function (val, indVal) {
_this._wi.set_array_index_f64(index_arr_ptr, indVal + 1, val);
});
_this._wi.set_array_index_i32(indices_arr_ptr, indDim + 1, index_arr_ptr);
});
return this._wi.get_f64(this._arr_ptr, indices_arr_ptr);
};
MxArray.prototype.get = function (indices) {
if (typeof indices === 'number') {
return this._wi.get_array_index_f64(this._arr_ptr, indices);
}
else if (indices.length === 1 && indices[0].length == 1) {
return this._wi.get_array_index_f64(this._arr_ptr, indices[0][0]);
}
else {
return this.get_indices(indices);
}
};
MxArray.prototype.set = function (indices, values) {
if (indices.length == 0 && values.length == 0) {
return this._wi.clone(this._arr_ptr);
}
else if (indices.length === 1 && indices[0].length == 1 && values.length == 1) {
this._wi.set_array_index_f64(this._arr_ptr, indices[0][0], values[0]);
}
else {
this.set_indices(indices, values);
}
};
MxArray.prototype.set_indices = function (indices, values) {
var _this = this;
var indices_arr_ptr = this._wi.create_mxvector(indices.length, 5); // Create mxvector with int type
indices.forEach(function (dimArr, indDim) {
var index_arr_ptr = _this._wi.create_mxvector(dimArr.length);
_this._wi.set_array_index_i32(indices_arr_ptr, indDim + 1, index_arr_ptr);
dimArr.forEach(function (val, indVal) {
_this._wi.set_array_index_f64(index_arr_ptr, indVal + 1, val);
});
});
var indices_val_arr_ptr = this._wi.create_mxvector(values.length);
values.forEach(function (val, ind) {
_this._wi.set_array_index_f64(indices_val_arr_ptr, ind + 1, val);
});
this._wi.set_f64(this._arr_ptr, indices_arr_ptr, indices_val_arr_ptr);
};
return MxArray;
}(MxObject_1.MxObject));
exports.MxArray = MxArray;
//# sourceMappingURL=MxArray.js.map
1 change: 0 additions & 1 deletion bin/classes/mxarray/MxArray.js.map

This file was deleted.

8 changes: 0 additions & 8 deletions bin/classes/mxarray/MxArrayWrapper.d.ts

This file was deleted.

45 changes: 0 additions & 45 deletions bin/classes/mxarray/MxArrayWrapper.js

This file was deleted.

1 change: 0 additions & 1 deletion bin/classes/mxarray/MxArrayWrapper.js.map

This file was deleted.

Loading

0 comments on commit 7d538ce

Please sign in to comment.