linux中的list.h(3)

Linux中List.h文件的分析和应用 本文介绍Linux中List.h文件,此文件中用双向链表实现了多种数据结构,比如队列,堆栈等,短小精湛,值得借鉴。此文件中还有哈希表的应用。 阅读详情

相关博文:
linux中的list.h(1) ——>内核链表简介、list_entry()方法。
linux中的list.h(2) ——>内核链表的创建、LIST_HEAD()方法。

内核链表的增加、删除、遍历

向链表中增加一个节点

真正实现插入的函数:

static inline void __list_add(struct list_head *new,
                              struct list_head *prev,
                              struct list_head *next)
{
        next->prev = new;
        new->next = next;
        new->prev = prev;
        prev->next = new;
}

头插法:在head和head->next之间插入一个新的节点。有利于实现栈。

/**
 * list_add - add a new entry
 * @new: new entry to be added
 * @head: list head to add it after
 *
 * Insert a new entry after the specified head.
 * This is good for implementing stacks.
 */
static inline void list_add(struct list_head *new, struct list_head *head)
{
        __list_add(new, head, head->next);
}

尾插法:在head->prev(双向循环链表中的最后一个节点)和head之间插入一个新的节点。有利于实现队列。

/**
 * list_add_tail - add a new entry
 * @new: new entry to be added
 * @head: list head to add it before
 *
 * Insert a new entry before the specified head.
 * This is useful for implementing queues.
 */
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
        __list_add(new, head->prev, head);
}

假设我们创建一个新的struct fox f,并把它加入到fox_list:
list_add(&f->list,&fox_list);

从链表中删除一个节点

static inline void __list_del(struct list_head * prev, struct list_head * next)
{
        next->prev = prev;
        prev->next = next;
}
/**
 * list_del - deletes entry from list.
 * @entry: the element to delete from the list.
 */

static inline void list_del(struct list_head *entry)
{
        __list_del(entry->prev, entry->next);
}

注意:该函数从链表中删除entry元素,但并不会释放entry或释放包含entry的宿主结构体所占用的内存,该函数仅仅是将entry从链表中移走,所以该函数被调用后,通常还需要再撤销包含entry的数据结构和其中的entry项。

删除我们刚才新添加的struct fox f:
list_del(&f->list)
我们发现这个函数并没有接受fox_list作为输入参数。该函数只是接受一个特定的节点,并修改其前后节点的指针,这样给定的节点就从链表中删除了。

遍历链表

基本方法list_for_each()

#define list_for_each(pos, head) \
        for (pos = (head)->next; pos != (head); pos = pos->next)

该宏使用两个list_head类型的参数,第一个参数用来指向当前项(充当临时变量),第二个参数是需要遍历的链表的以头节点形式存在的list_head。每次遍历时,第一个参数在链表中不断移动指向下一个元素,直到链表中的所有元素都被访问为止。

示例:

struct list_head *p;
list_for_each(p,&fox_list){
    //...
}

不过其实一个指向链表结构(list_head)的指针通常是无用的。我们是将链表塞入了我们的数据结构,即把list_head嵌入对象的数据结构。所有的链表操作是针对链表结构(list_head),而链表的设计者并不知道链表宿主结构体的任何情况。
我们所需要的是一个指向包含list_head的结构体(链表宿主结构体)的指针。
拿前面的struct fox举例子来说明:
我们需要的是指向每个fox的指针,而不是指向fox结构体中list成员的指针。

我们可以使用list_entry()宏来获得包含给定list_head的数据结构。

常用方法list_for_each_entry()

/**
 * list_for_each_entry  -       iterate over list of given type
 * @pos:        the type * to use as a loop cursor.
 * @head:       the head for your list.
 * @member:     the name of the list_head within the struct.
 */
#define list_for_each_entry(pos, head, member)                          \
        for (pos = list_first_entry(head, typeof(*pos), member);        \
             &pos->member != (head);                                    \
             pos = list_next_entry(pos, member))

该宏的三个参数:

  • pos,指向宿主节点的指针(struct fox *f),注意不是linux链表结构体的指针。
  • head,链表结构体组成的链表的链表头指针(&fox_list),注意不是宿主结构体指针。
  • member,宿主结构体中作为链表节点而嵌入的成员名(list)。

pos = list_first_entry(head, typeof(*pos), member)相当于
pos = list_entry((head)->next, typeof(*pos), member)
利用list_entry宏和链表头指针head的next指针域head->next,反推出宿主节点头指针pos。

然后判断pos->member的地址是否等于指向链表头指针head,如果不等,则表示还没有遍历完。

在当前宿主节点遍历完后,将pos指向链表中下一个宿主节点。
pos = list_next_entry(pos, member)就相当于
pos = list_entry((pos)->member.next, typeof(*(pos)), member)

示例:

struct fox *f;
list_for_each_entry(f, &fox_list, list){
    //...
}
/**
 * list_first_entry - get the first element from a list
 * @ptr:        the list head to take the element from.
 * @type:       the type of the struct this is embedded in.
 * @member:     the name of the list_head within the struct.
 *
 * Note, that list is expected to be not empty.
 */
#define list_first_entry(ptr, type, member) \
        list_entry((ptr)->next, type, member)
/**
 * list_next_entry - get the next element in list
 * @pos:        the type * to cursor
 * @member:     the name of the list_head within the struct.
 */
#define list_next_entry(pos, member) \
        list_entry((pos)->member.next, typeof(*(pos)), member)

用户态下使用内核链表

list.h

#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H

struct list_head {
    struct list_head *next, *prev;
};


#define LIST_HEAD_INIT(name) { &(name), &(name) }

#define LIST_HEAD(name) \
        struct list_head name = LIST_HEAD_INIT(name)

static inline void INIT_LIST_HEAD(struct list_head *list)
{
        list->next = list;
        list->prev = list;
}

static inline void __list_add(struct list_head *new,
                              struct list_head *prev,
                              struct list_head *next)
{
        next->prev = new;
        new->next = next;
        new->prev = prev;
        prev->next = new;
}

static inline void list_add(struct list_head *new, struct list_head *head)
{
        __list_add(new, head, head->next);
}

static inline void __list_del(struct list_head * prev, struct list_head * next)
{
        next->prev = prev;
        prev->next = next;
}

static inline void list_del(struct list_head *entry)
{
        __list_del(entry->prev, entry->next);
}

#ifdef __compiler_offsetof
#define offsetof(TYPE, MEMBER)  __compiler_offsetof(TYPE, MEMBER)
#else
#define offsetof(TYPE, MEMBER)  ((size_t)&((TYPE *)0)->MEMBER)
#endif

#define container_of(ptr, type, member) ({                      \
        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
        (type *)( (char *)__mptr - offsetof(type,member) );})


#define list_entry(ptr, type, member) \
        container_of(ptr, type, member)

#define list_first_entry(ptr, type, member) \
    list_entry((ptr)->next, type, member)

#define list_next_entry(pos, member) \
    list_entry((pos)->member.next, typeof(*(pos)), member)


#define list_for_each_entry(pos, head, member)              \
    for (pos = list_first_entry(head, typeof(*pos), member);    \
         &pos->member != (head);                    \
         pos = list_next_entry(pos, member))


#endif

list_study.c


#include <stdio.h>
#include <stdlib.h>
#include "list.h"
struct fox{
    unsigned int weight;
    int is_cute;
    struct list_head list;
};
int main()
{
    struct fox *red_fox;
    red_fox=(struct fox*)malloc(sizeof(struct fox));
    red_fox->weight=6;
    red_fox->is_cute=0;
    INIT_LIST_HEAD(&red_fox->list);
    printf("red_fox:\t%p\t%p\t%p\n",&red_fox->list,
                         (red_fox->list).next,
                         (red_fox->list).prev);

    printf("\t\t%p\t%d\t%d\n",&red_fox->list, red_fox->weight, red_fox->is_cute);

    struct fox *write_fox;
    write_fox=(struct fox*)malloc(sizeof(struct fox));
    write_fox->weight=7;
    write_fox->is_cute=-1;
    INIT_LIST_HEAD(&write_fox->list);
    printf("write_fox:\t%p\t%p\t%p\n",&write_fox->list,
                         (write_fox->list).next,
                         (write_fox->list).prev);

    printf("\t\t%p\t%d\t%d\n",&write_fox->list, write_fox->weight, write_fox->is_cute);
    //链表头
    LIST_HEAD(fox_list);
    //添加
    list_add(&(red_fox->list),&fox_list);
    list_add(&(write_fox->list),&fox_list);

    struct fox *pos;
    //遍历
    list_for_each_entry(pos,&fox_list,list){
        printf("%p\t%d\t%d\n",&pos->list, pos->weight, pos->is_cute);
    }
    //删除
    list_del(&(red_fox->list));
    free(red_fox);
    list_del(&(write_fox->list));
    free(write_fox);
    list_for_each_entry(pos,&fox_list,list){
        printf("%p\t%d\t%d\n",&pos->list, pos->weight, pos->is_cute);
    }
    return 0;
}
list 移植与基本使用 阅读详情

相关推荐

linux内核中的list.h文件中哈希表的分析

一、背景     本篇文章将先从对哈希表的基本介绍开始,然后分析linux内核(3.10.0版)中的list.h文件中的哈希表。 二、简述哈希表     根据设定的哈希函数H(key)和处理冲突的方法将一组关键字映像到一个有限的连续的地址集上,并以关键字在地址集中的“像”作为记录在表中的存储位置,这种表便称为哈希表。     上面这一段是从一本教材中摘抄出来的对哈希表的一段描述。    

hty46565的博客 2960

【数据结构】list.h 常用函数实现详解

本文介绍了 list.h 的函数实现,对如何使用 list.h 有一定帮助。

wkd_007的博客 2365

Linux内核源码list.h解读

#list.h源码阅读 此文章是我阅读list.h后的一些见解,有问题且理解不到位的地方希望大家批评指正。 本次我们阅读的内核版本为4.18.7 在Linux内核中,list.h是内核为了方便使用链表而自己建立的链表头文件。 以__开头的是指内核函数。 ##链表 ##宏定义 除了调用其它头文件外,首先看到的是两个宏定义。 #define LIST_HEAD_INIT(name) { &amp;amp;...

weixin_43122409的博客 3934

【数据结构】list.h 详细使用教程 -- 附带例子代码

介绍list.h 的详细用法,并给出例子代码

wkd_007的博客 1994

【Linux高级编译】Linux内核的list.h的高效应用----单向链表和双向链表的实现

Linux内核中,有个非常经典的链表实现,你了解过它的实现吗?

一个专注于嵌入式IoT领域的架构师,深耕IoT领域多年,深度掌握IoT领域的相关技术栈,包括但不限于RTOS内核的实现及其移植、硬件驱动移植开发、网络通讯协议开发、编译构建原理及其实现、底层汇编及编译原理、编译优化及代码重构、嵌入式IoT系统的架构设计等。 10万+

Python xlwings报错解决:从‘NoneType‘到完美运行WPS表格的完整指南

本文深入解析了使用Python xlwings库自动化WPS表格时遇到的经典'NoneType'报错(AttributeError: 'NoneType' object has no attribute 'apps')的根源与解决方案。核心在于pywin32版本与WPS的兼容性问题,文章提供了从版本降级、依赖管理到构建健壮自动化环境的完整实战指南,帮助开发者彻底解决兼容性难题,实现稳定运行。

n4o5p6q7r的博客 303

linux——list.h

*linux中的头文件list.h 在Linux的源码中有一个自己为建立链表而写的链表头文件,以后可以直接调用里面的函数来使用链表。 list.h在linux中的路径为/usr/src/kernels/include/linux。不同的版本可能不一样。 list.h中有两个宏定义:#define LIST_HEAD_INIT(name) {&(name),&(name)} #define LI

sinat_34467747的博客 7516

【实战指南】RF-DETR目标检测全流程:从数据准备到工业部署

本文详细介绍了RF-DETR目标检测模型的全流程应用,从数据准备、模型训练到工业部署。RF-DETR作为基于Transformer的先进模型,在COCO基准测试中表现优异,推理速度超越YOLOv8,特别适合工业场景。文章还提供了数据标注、COCO格式转换、超参数调优及边缘设备部署的实用技巧,帮助开发者高效实现目标检测任务。

weixin_29081101的博客 420

Linux内核数据结构之链表list.h

Linux-3.5版本下的list.h注释翻译加详细分析

weixin_37977062的博客 450

超声波测距的15度魔法:HC-SR04测量角度特性在机器人避障中的实战技巧

本文深入探讨了HC-SR04超声波测距模块在机器人避障中的15度测量角度特性及其应用技巧。通过分析15度角的工程意义、多模块阵列设计、狭小空间优化方案及温度补偿技术,帮助开发者提升机器人环境感知能力。文章特别强调了HC-SR04模块在低成本避障方案中的核心优势与实战优化策略。

weixin_29172963的博客 430

PHP实现SM2算法(附完整源码)

PHP实现SM2算法(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 4022

第五学 linux内核中最基本的数据组织方式——list.h分析(3)

这节给出一个内核态的使用双链表的例子,在我们写内核态helloworld的时候就说过,它是我们编写内核模块的模板,这里你可以再加深一下这个概念的理解。用的都是以上边介绍过的一些函数,嘿嘿,看起来也并不是很难的样子。 #include

bcs_01的专栏 836

【Proteus仿真】基于74LS148+74LS279+74LS48的四路抢答器

【Proteus仿真】基于74LS148+74LS279+74LS48的四路抢答器

perseverance51博客 8833

使用linux 内核中代码之--list

为什么80%的码农都做不了架构师?>>> ...

weixin_34138255的博客 103

YOLOv8 | 损失函数改进,最新提出的Shape-IoU,有效涨点

作为检测器定位分支的重要组成,边框回归损失在目标检测任务中发挥巨大作用。现有的边框回归方法,通常考虑了GT框与预测框之间的几何关系,通过使用边框间的相对位置与相对形状等计算损失,而忽略了边框其自身的形状与尺度等固有属性对边框回归的影响。为了弥补现有研究的不足,本文提出聚焦边框自身形状与尺度的边框回归方法。首先我们对边框回归特性进行分析,得出边框自身形状因素与尺度因素会对回归结果产生影响。

kay_545 1913

RT-DETR算法优化改进:轻量级上采样CARAFE算子 | 注意力机制大作战

上采样操作CARAFE,具有感受野大、内容感知、轻量级、计算速度快等优点,引入RT-DETR二次创新;1)代替Upsample进行使用;

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 1265

Linux内核中的list.h浅谈

[十月往昔]——Linux内核中的list.h浅谈 为什么要叫做“十月往昔”呢,是为了纪念我的原博客。 不知道为什么,突然想来一个新的开始——而那个博客存活至今刚好十个月,也有十个月里的文档。 十月往昔,总有一些觉得珍贵的,所以搬迁到这里来。 而这篇文章是在09.04.10里写的。 Jason Lee   ————————————–cut-line /*------------

JasonLee的专栏 5828

【推荐100个unity插件】Animator 的替代品?—— Animancer Pro插件的使用介绍

Animancer与Unity Animator对比及使用指南 摘要: 本文对比了Animancer与Unity官方Animator的核心差异,分析了Animancer的优势特点。Animancer采用代码驱动模式,相比Animator的状态机系统更灵活高效,支持实时调试、动态混合和深度逻辑集成。文章详细介绍了Animancer的快速使用方法,包括动画播放、切换和触发机制,并区分了免费版与专业版的功能差异。适合需要高效动画开发、复杂交互逻辑的中小项目,为开发者提供了一种现代化的动画解决方案。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 2434

MTK 自有相机框架 camera适配

MTK 自有相机框架 camera适配,以gc08a3为例

jamecer的博客 280

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

linux内核list.h头文件分析(七)——list.h应用

自己把list.h源文件的代码一下部分做了手脚,下次如果在你的程序当中有用到list或者是hlist的时候,你就可以把我修改之后的内容复制一下,命名为list.h,然后在你的用户程序中写着这么一句#include "list.h"这样的话,你就可以很好的对内核链表进行使用了。改动的地方(代码中的红色部分):1)#define LIST_POISON1  (void *) 0x0#define LI

sunjiangangok的博客 1839

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

linux中的list.h(2)

linux内核中链表的创建linux内核中的双链表操作非常经典。为了加深对代码的理解,我将在用户态下对里面的内容进行一些实现。 注意list.h是在内核态中用的,在用户态直接#include <linux/list.h>是不行的。不过,虽然list.h是内核代码中的头文件,但我们可以把它移植到用户空间使用。相关博文: linux中的list.h(1) ——>linux内核中链表简介,list

_今已亭亭如盖矣 1575

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Linux 中list.h使用实例和坑

​ list.h是Linux内核中,为了提供统一的链表操作,减少结构体的额外开支提供的链表操作。list.h中定义的链表了一个双向循环链表,和一个哈希表。内含实际例子 ​

monkeyzh123的专栏 3244

Linux 内核链表 list.h 的使用

C 语言本身并不自带集合(Collection)工具,当我们需要把结构体(struct)实例串联起来时,就需要在结构体内声明指向下一实例的指针,构成所谓的“链表”。而为了实现对链表的操作,我们需要另外实现一系列的函数,例如添加、删除、搜索、复制等等。而利用 Kernel 源代码中自带的 list.h,则可以方便地实现任意类型结构体的串联。 编程需求 假设我有一个表示学生资料的结构体: #d...

springcity2014的博客 1032

linux内核学习中-- 史上最全 linux通用链表“list.h”详解

最近几天在学习linux内核,接触到“list.h”文件,学习了几天,在这里做一下总结。也在网上学习了很多前人的工作。好像大家的工作都比较零散,每个人都是仅仅解释了某几个函数。为了以后大家学习方便,,在这里我将所有的函数以及头文件通通解释下,算是比较全面的总结吧!。希望对大家今后的学习有用,也望大家对里面的错误和缺点指出。 下面,我开始了。  第一段,我就不多解释了,大家应该能看懂,重点在后面

ggxxkkll的专栏 9424

Linux 内核的 list.h

内核 list.h 的源码+一个例子+简要解析

yong1585855343的博客 491

linux中的list

目录 队列的操作,相关函数 宏、函数分析 定义、初始化list_head的方法 list_entry(ptr, type, member) list_for_each_entry(pos, head, member) 队列的操作,相关函数 INIT_LIST_HEAD(); LIST_HEAD_INIT(); list_add_tail(); list_del()...

IT利刃出鞘的博客 1219
上一篇: linux中的list.h(2)
_IanXiao
博客等级 码龄12年 84粉丝 241原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值