当前位置:网站首页>Numpy's research imitation 1
Numpy's research imitation 1
2022-06-29 21:43:00 【InfoQ】
struct _u_array {
char *start[2];
int axis_n;
};static size_t
__xd_coord_to_1d_offset(size_t coord[], size_t axes[], int axis_n) {
size_t offset = 0, axis_mulitply;
for (int i=0; i<axis_n; ++i) {
size_t co = coord[i];
axis_mulitply = __axis_mulitply(axes, axis_n, i+1);
offset += co * axis_mulitply;
}
return offset;
}static void
__1d_offset_to_xd_coord( size_t offset, size_t axes[], int axis_n, size_t coord[])
{
size_t div, mod, i, axis_mulitply, middle_value;
middle_value = offset;
for(i=0; i<axis_n-1; ++i) {
axis_mulitply = __axis_mulitply(axes, axis_n, i+1);
div = middle_value / axis_mulitply;
mod = middle_value % axis_mulitply;
coord[i] = div;
middle_value = mod;
}
coord[i] = mod;
return;
}- initialization
/**
* Enter dimension quantity , for example 3 dimension
* Enter each dimension , for example [3, 3, 3]
*/
u_array_t UArray_create(int axis_n, size_t shape[])
{
if (axis_n >= 0) {
u_array_t n_array;
n_array.axis_n = axis_n;
start[0] = __alloc_shape(axis_n, shape);
start[1] = __alloc_data(__axis_mulitply(shape, axis_n, 0));
return n_array;
}
return ua_unable;
}- Load data
u_array_t* UArray_load(u_array_t* arr, vfloat_t data[])
{
size_t size_arr = UA_size(arr);
vfloat_t* ptr = UA_data_ptr(arr);
memcpy(ptr, data, size_arr);
return arr;
}- Access data
float UArray_get(u_array_t* arr, ...)
{
va_list valist;
va_start(valist, arr);
size_t coord[UA_axisn(arr)];
for (int i=0; i<UA_axisn(arr); ++i) {
coord[i] = va_arg(valist, size_t);
}
va_end(valist);
size_t offset = UA_cover_coordinate(arr, coord);
return ((float*)(UA_data_ptr(arr)))[offset];
}
void UArray_set(u_array_t* arr, ...)
{
va_list valist;
va_start(valist, arr);
size_t coord[UA_axisn(arr)];
vfloat_t value;
for (int i=0; i<UA_axisn(arr); ++i) {
coord[i] = va_arg(valist, size_t);
}
value = va_arg(valist, double);
va_end(valist);
size_t offset = UA_cover_coordinate(arr, coord);
((float*)(UA_data_ptr(arr)))[offset] = value;
return;
}int main()
{
// Define a 3 Dimensional ultra_array
u_array_t arr3 = UArray3d(2, 3, 4);
// Fill from 0 To 23 The number of .
UA_arange(&arr3, 2*3*4);
// obtain
float v = UA_get(&arr3, 1, 2, 3);
// v == 23
UA_set(&arr3, 1, 2, 3, 5.5);
v = UA_get(&arr3, 1, 2, 3);
// v == 5.5
return 0;
}边栏推荐
- 小型图书馆项目总结
- Goahead webserver migration
- A keepalived high availability accident made me learn it again!
- Realize inotify and Rsync real-time backup
- Layer 3 loop brought by route Summary - solution experiment
- leetcode:724. Find the central subscript of the array
- Report delivery engineer
- Rsync 建立多目录模块的方法
- Implementing LDAP proxy service with haproxy + keepalive
- How to evaluate iFLYTEK AI translation pen P20 series? Is it worth buying?
猜你喜欢

STL tutorial 6-deque, stack, queue, list container
【云原生实战】KubeSphere实战——多租户系统实战

【ROS进阶篇】第四讲 ROS中的重名问题(节点、话题与参数)

How to judge the quality of conductive slip ring from its appearance

Vipshop product details API interface (item_get- get vipshop product details interface), vipshop details API interface

Live broadcast preview | PostgreSQL kernel Interpretation Series Lecture 1: overview of PostgreSQL system

Verilog realizes serial communication and sends it to the nixie tube

铝板AS/NZS 1530.1 不燃性材料的阻燃测试

VHDL电话计费系统设计

【ROS进阶篇】第三讲 ROS文件系统与分布式通信
随机推荐
Is it safe to open a securities account in Caixue school?
Selection of materials for space conductive disc slip ring
Analysis of the factors affecting the transmission signal of the conductive slip ring
【摸鱼神器】UI库秒变低代码工具——表单篇(一)设计
How can colleges and universities build future oriented smart campus based on cloud native? Full stack cloud native vs traditional technology architecture
My creation anniversary
CORDIC based Signal Processor desgn
THREEJS基础入门
铝板AS/NZS 1530.1 不燃性材料的阻燃测试
Analysis on the true topic of "cost management" by Guangdong second-class cost engineer
Report delivery engineer
Vipshop Keyword Search API interface (item_search- search vipshop commodity API interface by keyword), vipshop API interface
管理人员应具备的基本素质
C. Where‘s the Bishop?
varnish 503 no backend connection – varnish健康检查
[advanced ROS chapter] lesson 2 custom header and source file encapsulation
Verilog realizes serial communication and sends it to the nixie tube
不同系统下的文件层级符号小结
小型圖書館項目總結
Rsync method of establishing multi directory module