// TensorRawData
-var TensorRawData = function() {
+var TensorRawData = function(data, size, shape) {
Object.defineProperties(this, {
data: {
enumerable: true,
- get: function() {
- throw new WebAPIException(WebAPIException.ABORT_ERR, 'Not implemented');
- }
+ writable: false,
+ value: data
},
size: {
enumerable: true,
- get: function() {
- throw new WebAPIException(WebAPIException.ABORT_ERR, 'Not implemented');
- }
+ writable: false,
+ value: size
},
shape: {
enumerable: true,
- get: function() {
- throw new WebAPIException(WebAPIException.ABORT_ERR, 'Not implemented');
- }
+ writable: false,
+ value: shape
}
});
};
return Uint8Array;
}
+function _CheckIfArrayHasOnlyNumbersAndThrow(array, arrayName) {
+ if (xwalk.utils.type.isNullOrUndefined(array)) {
+ return;
+ }
+
+ array.forEach(function(d) {
+ if (Number.isInteger(d) == false) {
+ throw new WebAPIException(
+ WebAPIException.TYPE_MISMATCH_ERR,
+ arrayName + ' array has to contain only integers'
+ );
+ }
+ });
+}
+
// TensorsData
var _ValidTensorsDataIds = new Set();
'Invalid parameter: index is undefined'
);
}
- // TODO: validate location and size - will be done in future commit
+
+ _CheckIfArrayHasOnlyNumbersAndThrow(args.location, 'location');
+ _CheckIfArrayHasOnlyNumbersAndThrow(args.size, 'size');
var callArgs = {
tensorsDataId: this._id,
// TODO: modify StringToArray to accept also float types, not only int
var data = privUtils_.StringToArray(result.buffer, Uint8Array);
var ArrayType = _GetBufferTypeFromTensorType(result.type);
- // TODO: return TensorRawData
- return new ArrayType(data.buffer);
+ var shape = result.shape;
+ return new TensorRawData(new ArrayType(data.buffer), data.byteLength, shape);
};
var TensorsDataSetTensorRawDataExceptions = [
}
var buffer = ValidateBufferForTensorsData(this, argsIndex.index, arguments[1]);
- // TODO: validate location and size - will be done in future commit
+ _CheckIfArrayHasOnlyNumbersAndThrow(argsLocSize.location, 'location');
+ _CheckIfArrayHasOnlyNumbersAndThrow(argsLocSize.size, 'size');
// TODO: modify ArrayToString to accept also float types, not only int
var encodedData = privUtils_.ArrayToString(new Uint8Array(buffer.buffer));
}
]);
- args.dimensions.forEach(function(d) {
- if (Number.isInteger(d) == false) {
- throw new WebAPIException(
- WebAPIException.TYPE_MISMATCH_ERR,
- 'dimensions array has to contain only integers'
- );
- }
- });
+ _CheckIfArrayHasOnlyNumbersAndThrow(args.dimensions, 'dimensions');
var callArgs = {
name: args.name,
}
]);
- args.dimensions.forEach(function(d) {
- if (Number.isInteger(d) == false) {
- throw new WebAPIException(
- WebAPIException.TYPE_MISMATCH_ERR,
- 'dimensions array has to contain only integers'
- );
- }
- });
+ _CheckIfArrayHasOnlyNumbersAndThrow(args.dimensions, 'dimensions');
var callArgs = {
index: args.index,
const std::string kBuffer = "buffer";
const std::string kSize = "size";
const std::string kLocation = "location";
+const std::string kShape = "shape";
} // namespace
using namespace common;
common::encode_binary_in_string(out_data, out[kBuffer].get<std::string>());
out[kType] = picojson::value(raw_data.type_str);
+ picojson::array shape = picojson::array{};
+ for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ shape.push_back(picojson::value{static_cast<double>(raw_data.shape[i])});
+ }
+ out[kShape] = picojson::value{shape};
ReportSuccess(out);
}
}
// TODO: add support for location and size - will be done in future commit
- PlatformResult result =
- types::TensorTypeEnum.getName(this->GetTensorType(index), &tensor_raw_data->type_str);
+ // Dimensions of whole tensor
+ unsigned int dim[ML_TENSOR_RANK_LIMIT];
+ PlatformResult result = tensors_info_->NativeGetTensorDimensions(index, dim);
+ if (!result) {
+ return result;
+ }
+
+ for (int i = 0; i < ML_TENSOR_RANK_LIMIT; i++) {
+ tensor_raw_data->shape[i] = dim[i];
+ }
+
+ result = types::TensorTypeEnum.getName(this->GetTensorType(index), &tensor_raw_data->type_str);
if (!result) {
return result;
}