Block介绍(一)基础

VINS-Mono 代码详细解读——基础储备:在线Cam到IMU的外参标定 InitialEXRotation类 本讲还是为了estimator类中最主要的函数processImage()做知识储备。 前面两讲知识储备主要讲了IMU预积分相关的integrationBase类以及图像特征点管理器feature_manager.cpp,本节将对processImage()的相机到IMU的外参矩阵的代码讲解。 processImage()中: 第一步为检测当前输入的image是否为关键帧,f_mana... 阅读详情

一、概述

Block是C级别的语法和运行时特性。Block比较类似C函数,但是Block比之C函数,其灵活性体现在栈内存、堆内存的引用,我们甚至可以将一个Block作为参数传给其他的函数或者Block。

 

二、热身

先看一个比较简单的Block例子:

int multiplier = 7;
int (^myBlock)(int) = ^(int num) {
    return num * multiplier;
};

在这个例子中,myBlock是一个Block变量,它接受一个int类型的参数,返回一个int类型的值。是不是很像C函数?

来,让我们typedef一下

typedef void (^BoolBlock)(BOOL);//一个只接受一个BOOL参数,没有返回值的block
typedef int (^IntBlock)(void);//一个没有参数,返回int的block
typedef BoolBlock (^HugeBlock)(IntBlock);//看看,这个HugeBlock的参数和返回值都是block
 

三、更详细的例子

注意,上面的typedef都还有效~

主动调用一下:
- (void)someMethod
{
    BoolBlock ablock = ^(BOOL bValue) {
        NSLog(@"Bool block!");
    };

    ablock();
}
作为参数返回:
typedef void (^BoolBlock)(BOOL);
- (BoolBlock)foo()
{
    BoolBlock ablock = ^(BOOL bValue) {
        NSLog(@"Bool block!");
    };
    return [[ablock copy] autorelease];//一定要copy,将其复制到堆上,更详细的原理,将在后续章节讲解
}
类的一个成员:
@interface OBJ1 : NSObject
@property (nonatomic, copy)BoolBlock block;//理由同上啊,同学们
@end

OBJ1 *obj1 = ...
obj1.block = ^(BOOL bValue) {
        NSLog(@"Bool block!");
    };
其他函数的参数:
- (void)foo(BoolBlock block)
{
    if (block) {
        block();
    }
}
甚至其他block的参数:
BoolBlock bBlock = ^(BOOL bV){if(Bv){/*do some thing*/}};
HugeBlock hBlock = ^(BoolBlock bB) {bB();};

hBolck(bBlock);
啊,全局变量!:
static int(^maxIntBlock)(int, int) = ^(int a, int b){return a>b?a:b;};
int main()
{
    printf("%d\n", maxIntBlock(2,10));  
    return 0;
}

好了,你知道block大概能怎么用了。

 

四,特殊的标记,__block

如果要在block内修改block外声明的栈变量,那么一定要对该变量加__block标记:

int main()
{
    __block int i = 1024;
    BoolBlock bBlock = ^(BOOL bV) {
        if (bV) {
            i++;//如果没有__block标记,是无法通过编译的。
        }
    };
}

 

好了,基础很快,更详细的内容将用来介绍深入的东西。

DDR5电流三参数IDD/IDDQ/IPP实操解析与产线避坑指南 DRAM芯片功耗测试中,IDD(动态工作电流)、IDDQ(静态待机电流)和IPP(峰值上电电流)是表征其电气健康状态的三大基础物理量。它们分别对应晶体管开关翻转、亚阈值漏电及电源网络瞬态响应等不同层级的半导体物理机制,共同构成JEDEC JESD79-5标准第11章的核心验证体系。理解这三类电流的产生原理,不仅关乎芯片能否通过量产门槛,更直接影响系统级电源完整性、高温稳定性与长期可靠性。在服务器、AI加速卡及车载计算等高负载场景下,微小的IDDQ漂移或IPP尖峰失真,都可能引发蓝屏、热失控甚至冷机启动失败。 阅读详情

相关推荐

深度解读:车辆诊断之DTC的状态位

搞车辆诊断测试的,离不开对DTC的状态位的测试DTC的状态位是8个bit,每个bit代表不同的意思,每个bit置1或者置0都要满足一定的条件初学者,很容易被这个搞得头很大今天我们就来详细拆解一下,扫除你心中的疑惑我们以欠压故障为例进行说明,假设欠压故障(DTC code为EE0468)发生的条件如下:1. 车辆模式(CarModSts1)处于Normal(0)或者Dyno(5)2. 当电源可用性不受限制时,即ElPowerLevel (有和PwrLvlElecSubtyp组成。

帮助100万人颠覆负面潜意识,实现人生蜕变,培养1万名潜意识开发导师 1万+

Materix.block

参考文章:https://blog.csdn.net/qq_27251141/article/details/90442072 这里添加了几处代码注释便于理解 #include <iostream> #include "Eigen/Dense" using namespace std; using namespace Eigen; int main() { MatrixXf m(4,4); m<< 1,2,3,4, 5,6,7,8,

liang_yy的博客 218

通过PXE的方式实现Ubuntu 24.04 自动安装

之前都是通过PXE来自动化安装Redhat系列的,例如:Rocky9、Rocky10、CentOS7、银河麒麟 Kylin-V10、Kylin-V11、OpenEuler 24.03等。现在安装Ubuntu系列的跟红帽的不太一样,所以在这里介绍下。

邢宇宇的博客 1502

VINS-Mono无ROS版本代码阅读(6):联合初始化

初始化的思路为: (1)用SFM求解滑窗内所有帧的位姿,和所有路标点的3D位置。 主要函数:relativePose 和GlobalSFM construct (2)和imu预积分的值对齐,求解重力方向,尺度因子,陀螺仪偏差和每一帧的速度。 前面得到的信息:滑动窗口内所有帧相对于参考帧的RT,滑动窗口内所有观察到的特征点的三维路标(相对于参考帧坐标系) 本文主要阅读:visualInitialAlign部分。 bool Estimator::visualInitialAlign() {

weixin_44754915的博客 662

自动化测试软件设计:C# + VISA 库实现多接口(GPIB/USB)测试仪器控制

本文介绍了如何利用C#和VISA库开发支持多接口的自动化测试软件。VISA库作为标准化API,能够统一控制GPIB、USB等不同接口的测试设备。文章详细阐述了软件设计目标,包括多接口支持、统一控制、自动化脚本执行等功能。重点讲解了C#中VISA库的安装配置,并提供了设备控制类的核心代码实现,涵盖设备连接、命令发送、响应读取等关键操作。通过具体示例展示了GPIB和USB设备的连接方式,并扩展了自动化测试脚本功能。该方案具有高扩展性和维护性,适用于电子设备测试、生产线检测等多种场景,为自动化测试系统开发提供了实

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1724

一文快速教你如何下载国自然模版

5. 成功进入“相关文件查看”页面后,点击左侧的“项目申请文件“,如果你此次申请的是“面上项目”,选择对应的下拉框,找到对应的模版下载即可。6. 🫑们发现,在当前页面点击“青年科学基金项目”,左侧出现的是“原国家杰出青年科学基金项目”。7. 进入下一页后,点击“青年科学基金项目”,便可以在右侧找到🫑们要找的模版啦。2. 成功登陆后,点击1处的“首页”,在首页界面,再点击2处的“项目批准”。8. 点击上图3处的“文件详情”,就可以找到可以下载的模版啦(如下图)。3. 从“项目批准”进入后,点击“管理”。

薰珞婷紫小亭子的博客 2423

Block定义与使用

1.Block是块语法,本质上是匿名函数(也就是没有函数名的方法)。它和函数指针类似。 2.Block定义 int (^myBlock)(int) = ^int(int num1){ return num1 + 2; }; 等号左边 int 代表Block的返回值类型 (^myBlock) ^是块标识符,后边是对象名称 (int) 是参数列表的类型,可以有多个参数,也可以为0个

花色1125的博客 564

[VCS]VCS checkpoint简介以及其在SoC验证加速中的作用

VCS checkpoint是Synopsys VCS提供的快照/恢复机制,可显著加速SoC验证。其核心是在仿真关键节点(如完成初始化后)保存系统状态,后续测试可直接从该点恢复,避免重复执行冗长的初始化阶段(如boot、DDR训练等)。该技术特别适用于多测试用例共享同一初始状态的场景,通过分离初始化与功能验证流程,可提升回归效率3-5倍。需注意处理DPI-C状态同步、版本管理及存储优化等问题,结合UVM和自动化脚本可实现更高效的验证流程。典型应用可节省数百万cycle的重复仿真时间。

元直的博客 793

MatrixXf.block<>()

1

weixin_44916682的博客 479

Open3D 可视化(1)——简单可视化【2026最新版】

简单可视化,博客长期更新,本文最新更新时间为:2026年5月10日。

点云侠的博客 5691

【保姆级教程】基于UNet++&MobileNetv3的语义分割模型从训练到RK3588部署:让边缘AI落地效率提升300%

通过SMP库一键构建encoder_name="mobilenet_v2", # 选择MobileNetv3作为骨干encoder_weights="imagenet", # 加载预训练权重加速收敛in_channels=3, # 输入图像通道数(RGB)classes=29, # Cityscapes数据集类别数activation=None # 输出无激活,便于后续损失计算本教程从“模型设计-训练-转换-边缘部署”全链路拆解了。

FJN110的博客 262

iOS中Block介绍(一)基础

ios开发block的使用指南,以及深入理解block的内存管理,也适用于osx开发。讨论范围:block的使用,内存管理,内部实现。不包含的内容:gc arc下的block内存,block在c++中的使用。 AD:51CTO 网+ 第十二期沙龙:大话数据之美_如何用数据驱动用户体验 一、概述 Block是C级别的语法和运行时特性。Block比较类似C函数

lijunhao2011的博客 510

​网格划分理论:CFD理论67 网格划分-三大理论问题_哔哩哔哩_bilibili传统解释非结构化网格是不对的——计算传热学大叔专题讨论2--CFD网格类型_哔哩哔哩_bilibili

传统解释非结构化网格是不对的——计算传热学大叔。fluent计算理论和离散方法原理视频推荐。

qq_15963745的博客 187

Arduino UNO Q:教育级开发板的工程价值与项目落地指南

Arduino UNO Q 是面向初学者与教育场景优化的AVR开发板,基于ATmega328P主控,集成CH340E USB转串口芯片与高精度LDO稳压电路,显著提升供电稳定性与系统兼容性。其核心价值在于降低硬件入门门槛——通过免驱支持、低纹波电源(<15mVpp)、图形化编程App Lab及结构化Project Guide,将认知负荷聚焦于逻辑设计而非驱动配置或寄存器操作。技术上支撑‘arduino智能小车’‘arduino驱动数码管’等高频实践需求,同时为进阶应用(如结合ESP32实现OTA升级)提供清

weixin_34239169的博客 203

深度学习工具包 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'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('DeepLearnToolbox'));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('state',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'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',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 = 'sigm';%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, 'Too big error');```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('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';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)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';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, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% 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'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 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, 'Too big error');```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('state',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, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',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, 'Too big error');%% ex3 neural net with dropoutrand('state',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, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % 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, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % 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, 'Too big error');%% 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('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % 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, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

上一篇: 把UIView切成任意形状
下一篇: Block介绍(二)内存管理与其他特性
focusjava
博客等级 码龄14年 127粉丝 528原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址