nv-facutil-slct-ta 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +98 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -390,6 +390,100 @@ const ele_tbrief_to_tacls = (t)=>ELE_TBRIEF_TO_TACLS[t];
390
390
  const tacls_to_ele_tbrief = (Cls)=>TACLS_TO_ELE_TBRIEF.get(Cls);
391
391
 
392
392
 
393
+ const max_tacls = (...Clss) => {
394
+ let max = Clss[0];
395
+ for (let i = 1; i < Clss.length; i++) {
396
+ let c = Clss[i];
397
+ if (c.BYTES_PER_ELEMENT > max.BYTES_PER_ELEMENT) {
398
+ max = c;
399
+ }
400
+ }
401
+ return max;
402
+ };
403
+
404
+ const min_tacls = (...Clss) => {
405
+ let min = Clss[0];
406
+ for (let i = 1; i < Clss.length; i++) {
407
+ let c = Clss[i];
408
+ if (c.BYTES_PER_ELEMENT < min.BYTES_PER_ELEMENT) {
409
+ min = c;
410
+ }
411
+ }
412
+ return min;
413
+ };
414
+
415
+ const read_dv_with_cls = (dv, Cls, offset, little_endian = true) => {
416
+ if (Cls === Uint8Array) {
417
+ return dv.getUint8(offset);
418
+ } else if (Cls === Int8Array) {
419
+ return dv.getInt8(offset);
420
+
421
+ } else if (Cls === Uint16Array) {
422
+ return dv.getUint16(offset, little_endian);
423
+ } else if (Cls === Int16Array) {
424
+ return dv.getInt16(offset, little_endian);
425
+
426
+ } else if (Cls === Uint32Array) {
427
+ return dv.getUint32(offset, little_endian);
428
+ } else if (Cls === Int32Array) {
429
+ return dv.getInt32(offset, little_endian);
430
+
431
+ } else if (Cls === Float32Array) {
432
+ return dv.getFloat32(offset, little_endian);
433
+ } else if (Cls === Float64Array) {
434
+ return dv.getFloat64(offset, little_endian);
435
+
436
+ } else if (Cls === BigUint64Array) {
437
+ return dv.getBigUint64(offset, little_endian);
438
+ } else if (Cls === BigInt64Array) {
439
+ return dv.getBigInt64(offset, little_endian);
440
+
441
+ } else if (globalThis.Float16Array && Cls === Float16Array) {
442
+ const u16 = dv.getUint16(offset, little_endian);
443
+ return f16_to_f32(u16);
444
+
445
+ } else {
446
+ throw new Error("Unsupported TypedArray class");
447
+ }
448
+ };
449
+
450
+
451
+ const write_dv_with_cls = (dv, Cls, offset, value, little_endian = true) => {
452
+ if (Cls === Uint8Array) {
453
+ dv.setUint8(offset, value);
454
+ } else if (Cls === Int8Array) {
455
+ dv.setInt8(offset, value);
456
+
457
+ } else if (Cls === Uint16Array) {
458
+ dv.setUint16(offset, value, little_endian);
459
+ } else if (Cls === Int16Array) {
460
+ dv.setInt16(offset, value, little_endian);
461
+
462
+ } else if (Cls === Uint32Array) {
463
+ dv.setUint32(offset, value, little_endian);
464
+ } else if (Cls === Int32Array) {
465
+ dv.setInt32(offset, value, little_endian);
466
+
467
+ } else if (Cls === Float32Array) {
468
+ dv.setFloat32(offset, value, little_endian);
469
+ } else if (Cls === Float64Array) {
470
+ dv.setFloat64(offset, value, little_endian);
471
+
472
+ } else if (Cls === BigUint64Array) {
473
+ dv.setBigUint64(offset, value, little_endian);
474
+ } else if (Cls === BigInt64Array) {
475
+ dv.setBigInt64(offset, value, little_endian);
476
+
477
+ } else if (globalThis.Float16Array && Cls === Float16Array) {
478
+ const u16 = f32_to_f16(value);
479
+ dv.setUint16(offset, u16, little_endian);
480
+
481
+ } else {
482
+ throw new Error("Unsupported TypedArray class");
483
+ }
484
+ };
485
+
486
+
393
487
  module.exports = {
394
488
  tcate,
395
489
  ////
@@ -441,4 +535,8 @@ module.exports = {
441
535
  ////
442
536
  ele_tbrief_to_tacls,
443
537
  tacls_to_ele_tbrief,
538
+ ////
539
+ min_tacls,max_tacls,
540
+ read_dv_with_cls,
541
+ write_dv_with_cls,
444
542
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nv-facutil-slct-ta",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"