dolphindb 3.0.39 → 3.0.40

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.
package/README.zh.md CHANGED
@@ -64,20 +64,23 @@ https://www.npmjs.com/package/dolphindb
64
64
 
65
65
  ##### 1. 安装
66
66
 
67
- 1.1. 在机器上安装最新版的 Node.js 及浏览器。
68
- - windows: https://nodejs.org/en/download/current/
69
- - linux: https://github.com/nodesource/distributions?tab=readme-ov-file#debian-and-ubuntu-based-distributions
67
+ 1.1. 在机器上安装最新版的 Node.js 及浏览器。
68
+ - windows: https://nodejs.org/en/download/prebuilt-installer/current
69
+ - linux: https://github.com/nodesource/distributions?tab=readme-ov-file#debian-and-ubuntu-based-distributions
70
+
70
71
  1.2. (可选)使用以下命令创建新项目。如果已有项目,可跳过此步。
71
- ```bash
72
- mkdir dolphindb-example
73
- cd dolphindb-example
74
- npm init --yes
75
- ```
72
+ ```bash
73
+ mkdir dolphindb-example
74
+ cd dolphindb-example
75
+ npm init --yes
76
+ ```
77
+
76
78
  1.3. 用编辑器打开 package.json 文件,在 `"main": "./index.js"` 下方加入一行 "type": "module", 这样能够启用 ECMAScript modules,在后面代码中可以使用 `import { DDB } from 'dolphindb'` 导入 npm 包。
79
+
77
80
  1.4. 在项目中安装 npm 包。
78
- ```bash
79
- npm install dolphindb
80
- ```
81
+ ```bash
82
+ npm install dolphindb
83
+ ```
81
84
 
82
85
  ##### 2. 使用
83
86
 
package/browser.d.ts CHANGED
@@ -330,7 +330,7 @@ export declare class DdbObj<TValue extends DdbValue = DdbValue> {
330
330
  pack(): Uint8Array;
331
331
  static pack_vector_body(value: DdbVectorValue, type: DdbType, length: number): ArrayBufferView[];
332
332
  /** 将 DdbObj 转换为 js 原生数据类型
333
- - 标量对应 number, bigint 或者字符串
333
+ - 标量对应 number, bigint 或者字符串 (其中时间类型转换为常用的字符串表示)
334
334
  - 数组对应 js 原生数组
335
335
  - 表格对应 DdbTableData
336
336
  - 矩阵对应 DdbMatrixData
package/browser.js CHANGED
@@ -1068,6 +1068,38 @@ export class DdbObj {
1068
1068
  ...DdbObj.pack_vector_body(data, this.type, this.rows * this.cols)
1069
1069
  ];
1070
1070
  }
1071
+ case DdbForm.tensor: {
1072
+ const { le, value } = this;
1073
+ const { tensor_type, device_type, tensor_flags, dimensions, shape, strides, preserve_value, elem_count, data } = value;
1074
+ // 计算总的字节长度
1075
+ const totalLength = 10 + dimensions * 8 * 2 + 8 + 8 + data.length; // 12 字节元数据 + 维度信息 + 保留值和元素数量 + 数据部分
1076
+ const buffer = new ArrayBuffer(totalLength);
1077
+ const dv = new DataView(buffer);
1078
+ const uint8Array = new Uint8Array(buffer);
1079
+ // 写入元数据
1080
+ // uint8Array[0] = type;
1081
+ // uint8Array[1] = form;
1082
+ uint8Array[0] = tensor_type;
1083
+ uint8Array[1] = device_type;
1084
+ dv.setUint32(2, tensor_flags, le);
1085
+ dv.setInt32(6, dimensions, le);
1086
+ // 写入形状和步长
1087
+ const shapeStart = 10;
1088
+ const stridesStart = shapeStart + dimensions * 8;
1089
+ for (let d = 0; d < dimensions; d++) {
1090
+ dv.setBigInt64(shapeStart + d * 8, BigInt(shape[d]), le);
1091
+ dv.setBigInt64(stridesStart + d * 8, BigInt(strides[d]), le);
1092
+ }
1093
+ // 写入保留值和元素数量
1094
+ const preserveValueStart = stridesStart + dimensions * 8;
1095
+ dv.setBigInt64(preserveValueStart, preserve_value, le);
1096
+ const storageStart = preserveValueStart + 8;
1097
+ dv.setBigInt64(storageStart, BigInt(elem_count), le);
1098
+ // 写入数据
1099
+ const dataStart = storageStart + 8;
1100
+ uint8Array.set(data, dataStart);
1101
+ return [uint8Array];
1102
+ }
1071
1103
  default:
1072
1104
  throw new Error(t('vector {{type}} 暂不支持序列化', { type: get_type_name(type) }));
1073
1105
  }