Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
bvals -> buffer
  • Loading branch information
jonmmease committed Nov 28, 2020
commit 5079fc79aa9a3f573d910bd534b8cce70fe42ebf
10 changes: 5 additions & 5 deletions src/lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ exports.decodeTypedArraySpec = function(v) {
v = coerceTypedArraySpec(v);
var T = typedArrays[v.dtype];
var buffer;
if(v.bvals.constructor === ArrayBuffer) {
if(v.buffer.constructor === ArrayBuffer) {
// Already an ArrayBuffer
buffer = v.bvals;
buffer = v.buffer;
} else {
// Decode, assuming a string
buffer = b64.decode(v.bvals);
buffer = b64.decode(v.buffer);
}

// Check if 1d shape. If so, we're done
Expand Down Expand Up @@ -143,7 +143,7 @@ exports.decodeTypedArraySpec = function(v) {

function isTypedArraySpec(v) {
// Assume v has not passed through
return isPlainObject(v) && typedArrays[v.dtype] && v.bvals && (
return isPlainObject(v) && typedArrays[v.dtype] && v.buffer && (
Number.isInteger(v.shape) ||
(isArrayOrTypedArray(v.shape) &&
v.shape.length > 0 &&
Expand All @@ -154,7 +154,7 @@ exports.isTypedArraySpec = isTypedArraySpec;

function coerceTypedArraySpec(v) {
// Assume isTypedArraySpec passed
var coerced = {dtype: v.dtype, bvals: v.bvals};
var coerced = {dtype: v.dtype, buffer: v.buffer};

// Normalize shape to a list
if(Number.isInteger(v.shape)) {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports.valObjectMeta = {
'The value could be an {array}',
'noting that typed arrays (e.g. Float32Array) are also supported.',
'It could also be an object in the form of',
'v: {, dtype: \'float32\', bvals: [/* ... */]}, shape: [dim0 (, dim1, (dim3))]',
'v: {, dtype: \'float32\', buffer: [/* ... */]}, shape: [dim0 (, dim1, (dim3))]',
'otherwise, it would be ignored.'
].join(' '),
requiredOpts: [],
Expand All @@ -50,7 +50,7 @@ exports.valObjectMeta = {
var uid = propOut.obj.uid;
var module = propOut.obj._module;

if(v.bvals.constructor === ArrayBuffer || !uid || !module) {
if(v.buffer.constructor === ArrayBuffer || !uid || !module) {
// Already an ArrayBuffer
// decoding is cheap
propOut.set(decodeTypedArraySpec(v));
Expand All @@ -59,11 +59,11 @@ exports.valObjectMeta = {
var cache = module._b64BufferCache || {};

// Check cache
var cachedBuffer = ((cache[uid] || {})[prop] || {})[v.bvals];
var cachedBuffer = ((cache[uid] || {})[prop] || {})[v.buffer];
if(cachedBuffer !== undefined) {
// Use cached array buffer instead of base64 encoded
// string
v.bvals = cachedBuffer;
v.buffer = cachedBuffer;
propOut.set(decodeTypedArraySpec(v));
} else {
// Not in so cache decode
Expand All @@ -76,7 +76,7 @@ exports.valObjectMeta = {
// Clear any prior cache value (only store one per
// trace property
cache[uid][prop] = {};
cache[uid][prop][v.bvals] = decoded.buffer;
cache[uid][prop][v.buffer] = decoded.buffer;
module._b64BufferCache = cache;
}
}
Expand Down