|
LMMC
Lamina Mathematic core
|
N-D 稠密张量数据结构、收缩与视图. 更多...
结构体 | |
| struct | lmmc_tensor_nd_t |
| N-D 张量结构. 更多... | |
宏定义 | |
| #define | LMMC_TENSOR_MAX_NDIM 8 |
| 支持的最大张量维度. | |
函数 | |
| lmmc_status_t | lmmc_tensor_nd_create (size_t ndim, const size_t *dims, lmmc_tensor_nd_t *out) |
| 创建 N-D 张量,行优先连续存储,元素初始化为零. | |
| lmmc_status_t | lmmc_tensor_nd_get (const lmmc_tensor_nd_t *t, const size_t *idx, lmmc_real_t *out) |
| 读取 N-D 张量元素. | |
| lmmc_status_t | lmmc_tensor_nd_set (lmmc_tensor_nd_t *t, const size_t *idx, lmmc_real_t value) |
| 写入 N-D 张量元素. | |
| lmmc_status_t | lmmc_tensor_nd_permute (const lmmc_tensor_nd_t *in, const size_t *perm, lmmc_tensor_nd_t *out) |
| 按指定轴顺序置换张量,生成独立数据副本(转置的推广)。 | |
| lmmc_status_t | lmmc_tensor_nd_contract (const lmmc_tensor_nd_t *a, const lmmc_tensor_nd_t *b, const size_t *axes_a, const size_t *axes_b, size_t naxes, lmmc_tensor_nd_t *out) |
| 张量收缩:沿匹配轴对求和. | |
| lmmc_status_t | lmmc_tensor_nd_mode_n_product (const lmmc_tensor_nd_t *t, const lmmc_mat_t *mat, size_t mode, lmmc_tensor_nd_t *out) |
| 模-n 乘积:沿指定模与矩阵收缩. | |
| lmmc_status_t | lmmc_tensor_nd_reshape_view (const lmmc_tensor_nd_t *src, size_t new_ndim, const size_t *new_dims, lmmc_tensor_nd_t *out_view) |
| 零拷贝重塑 N-D 张量,返回共享缓冲区的非拥有视图。 | |
| void | lmmc_tensor_nd_destroy (lmmc_tensor_nd_t *t) |
| 销毁 N-D 张量(仅当 owns_data 为 1 时释放缓冲区). | |
N-D 稠密张量数据结构、收缩与视图.
在文件 tensor_nd.h 中定义.
| struct lmmc_tensor_nd_t |
N-D 张量结构.
支持 1 至 LMMC_TENSOR_MAX_NDIM 维的张量. 通过 reshape_view 等得到的视图共享底层缓冲区且 owns_data == 0 .
在文件 tensor_nd.h 第 25 行定义.
| 成员变量 | ||
|---|---|---|
| size_t | ndim |
维度数(1..LMMC_TENSOR_MAX_NDIM). |
| size_t | dims[LMMC_TENSOR_MAX_NDIM] |
各维大小(仅前 ndim 个有效). |
| size_t | strides[LMMC_TENSOR_MAX_NDIM] |
各维步距(仅前 ndim 个有效). |
| lmmc_real_t * | data |
数据缓冲区. |
| int | owns_data |
是否拥有缓冲区所有权. |
| #define LMMC_TENSOR_MAX_NDIM 8 |
支持的最大张量维度.
在文件 tensor_nd.h 第 17 行定义.
被这些函数引用 lmmc_tensor_nd_contract(), lmmc_tensor_nd_mode_n_product() , 以及 lmmc_tensor_nd_permute().
| lmmc_status_t lmmc_tensor_nd_create | ( | size_t | ndim, |
| const size_t * | dims, | ||
| lmmc_tensor_nd_t * | out ) |
创建 N-D 张量,行优先连续存储,元素初始化为零.
分配 dims[0] x dims[1] x ... x dims[ndim-1] 个元素的连续缓冲区, 并设置行优先步距.输出张量的 owns_data 为 1.
| [in] | ndim | 维度数,范围 [1, LMMC_TENSOR_MAX_NDIM]. |
| [in] | dims | 各维大小数组,长度 ndim ,每个元素须 >= 1;可指向 out->dims. |
| [out] | out | 输出张量结构体(调用方提供存储). |
在文件 tensor_nd_storage.c 第 9 行定义.
被这些函数引用 lmmc_tensor3_create() , 以及 lmmc_tensor_nd_create().
| lmmc_status_t lmmc_tensor_nd_get | ( | const lmmc_tensor_nd_t * | t, |
| const size_t * | idx, | ||
| lmmc_real_t * | out ) |
读取 N-D 张量元素.
在文件 tensor_nd_storage.c 第 13 行定义.
引用了 lmmc_tensor_nd_t::data, lmmc_tensor_nd_t::dims, LMMC_REAL_SET, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_tensor_nd_get(), lmmc_tensor_nd_t::ndim , 以及 lmmc_tensor_nd_t::strides.
被这些函数引用 lmmc_tensor_nd_get().
| lmmc_status_t lmmc_tensor_nd_set | ( | lmmc_tensor_nd_t * | t, |
| const size_t * | idx, | ||
| lmmc_real_t | value ) |
写入 N-D 张量元素.
在文件 tensor_nd_storage.c 第 32 行定义.
引用了 lmmc_tensor_nd_t::data, lmmc_tensor_nd_t::dims, LMMC_REAL_SET, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_tensor_nd_set(), lmmc_tensor_nd_t::ndim , 以及 lmmc_tensor_nd_t::strides.
被这些函数引用 lmmc_tensor_nd_set().
| lmmc_status_t lmmc_tensor_nd_permute | ( | const lmmc_tensor_nd_t * | in, |
| const size_t * | perm, | ||
| lmmc_tensor_nd_t * | out ) |
按指定轴顺序置换张量,生成独立数据副本(转置的推广)。
例如 perm={1,0,2} 交换前两个轴;输出 owns_data == 1。
| [in] | in | 输入张量. |
| [in] | perm | 置换数组,长度 in->ndim,为 [0, ndim) 的排列. |
| [out] | out | 输出张量结构体(调用方提供存储). |
在文件 tensor_nd_views.c 第 42 行定义.
引用了 LMMC_STATUS_OK, LMMC_TENSOR_MAX_NDIM, lmmc_tensor_nd_permute() , 以及 lmmc_tensor_nd_t::ndim.
被这些函数引用 lmmc_tensor_nd_permute().
| lmmc_status_t lmmc_tensor_nd_contract | ( | const lmmc_tensor_nd_t * | a, |
| const lmmc_tensor_nd_t * | b, | ||
| const size_t * | axes_a, | ||
| const size_t * | axes_b, | ||
| size_t | naxes, | ||
| lmmc_tensor_nd_t * | out ) |
张量收缩:沿匹配轴对求和.
在文件 tensor_nd_products.c 第 196 行定义.
引用了 lmmc_tensor_nd_contraction_t::axes_a, lmmc_tensor_nd_contraction_t::axes_b, LMMC_STATUS_OK, LMMC_TENSOR_MAX_NDIM, lmmc_tensor_nd_contract() , 以及 lmmc_tensor_nd_contraction_t::naxes.
被这些函数引用 lmmc_tensor_nd_contract().
| lmmc_status_t lmmc_tensor_nd_mode_n_product | ( | const lmmc_tensor_nd_t * | t, |
| const lmmc_mat_t * | mat, | ||
| size_t | mode, | ||
| lmmc_tensor_nd_t * | out ) |
模-n 乘积:沿指定模与矩阵收缩.
在文件 tensor_nd_products.c 第 282 行定义.
引用了 lmmc_tensor_nd_t::dims, LMMC_STATUS_OK, LMMC_TENSOR_MAX_NDIM, lmmc_tensor_nd_mode_n_product(), lmmc_tensor_nd_t::ndim , 以及 lmmc_mat_t::rows.
被这些函数引用 lmmc_tensor_nd_mode_n_product().
| lmmc_status_t lmmc_tensor_nd_reshape_view | ( | const lmmc_tensor_nd_t * | src, |
| size_t | new_ndim, | ||
| const size_t * | new_dims, | ||
| lmmc_tensor_nd_t * | out_view ) |
零拷贝重塑 N-D 张量,返回共享缓冲区的非拥有视图。
源张量须为行优先连续存储,新旧形状的元素总数须相同。 输出 owns_data == 0,视图须在源张量销毁前使用。
| [in] | src | 源张量(必须为连续存储). |
| [in] | new_ndim | 新维度数,范围 [1, LMMC_TENSOR_MAX_NDIM]. |
| [in] | new_dims | 新各维大小数组,长度 new_ndim;可指向 out_view->dims. |
| [out] | out_view | 输出视图结构体;不可与拥有数据的 src 为同一对象. |
形状数组可与 out_view 别名;读取全部输入元数据后再写入输出。
在文件 tensor_nd_views.c 第 97 行定义.
引用了 lmmc_tensor_nd_t::data, lmmc_tensor_nd_t::dims, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_tensor_nd_reshape_view(), lmmc_tensor_nd_t::ndim, lmmc_tensor_nd_t::owns_data , 以及 lmmc_tensor_nd_t::strides.
被这些函数引用 lmmc_tensor3_reshape_view() , 以及 lmmc_tensor_nd_reshape_view().
| void lmmc_tensor_nd_destroy | ( | lmmc_tensor_nd_t * | t | ) |
销毁 N-D 张量(仅当 owns_data 为 1 时释放缓冲区).
在文件 tensor_nd_storage.c 第 51 行定义.
引用了 lmmc_tensor_nd_t::data, lmmc_tensor_nd_t::dims, lmmc_memory_free(), LMMC_REAL_CLEAR, LMMC_STATUS_OK, lmmc_tensor_nd_destroy(), lmmc_tensor_nd_t::ndim, lmmc_tensor_nd_t::owns_data , 以及 lmmc_tensor_nd_t::strides.
被这些函数引用 lmmc_tensor_nd_destroy().