Google Summer of Code: C++ Modernizer Improvements

Speedtree学习笔记(案例)——拥有多种材质的植物如何导入使用(以草为例) 注:Speedtree无论保存还是导入模型其存储路径不可有中文。 第一步拆分草的模型 根据所需的材质去拆分(例:假若草的果实,茎秆和叶子是不同的材质那么就需拆分为三份;假若画的全部颜色及材质一样就没有必要去拆分模型) 第二步导入草的模型 在Mesh面板中依次导入草的模型——Do nothing additional right now 第三步扩大草的生长区域范围(可省略)... 阅读详情

Monday, November 18, 2013

Google Summer of Code: C++ Modernizer Improvements

Google Summer of Code (GSoC) offers students stipends to participate in open source projects during the summer. This year, I was accepted to work on the , a project formerly known as the , driven by a team at Intel. The goals of the tool are to modernize C++ code by using the new features of new C++ standards in order to improve maintainability, readability and compile time and runtime performance. The project was featured in the April blog post “” and has been evolving since, both in terms of architecture and features.

This article presents the improvements made to the tool in the last few months, which include my work from this summer for GSoC. For a complete overview of the tool and how to install it, please visit the documentation: http://clang.llvm.org/extra/clang-modernize.html#getting-started. For a demonstration of the tool you can take a look at the Going Native 2013 talk given by Chandler Carruth: The Care and Feeding of C++'s Dragons. clang-modernize is featured starting at ~33min.

Transform all Files That Make up a Translation Unit

A major improvement since the last version is the ability to transform every file that composes a translation unit not only the main source file. This means headers also get transformed if they need to be which makes the modernizer more useful.

To avoid changing files that shouldn’t be changed, e.g. system headers or headers for third-party libraries, there are a few options to control which files should be transformed:

  • -include Takes a comma-separated list of paths allowed to be transformed. All files within the entire directory tree rooted at each given path are marked as modifiable. For safety, the default behaviour is that no extra files will be transformed.
  • -exclude Takes a comma-separated list of paths forbidden to be transformed. Can be used to prune out subtrees from included directory trees.
  • -include-from and -exclude-from Respectively equivalent to -include and -exclude but takes a filename as argument instead of a comma-separated list of paths. The file should contain one path per line.

Example, assuming a directory hierarchy of:

  • src/foo.cpp
  • include/foo.h
  • lib/third-party.h

to transform both foo.cpp and foo.h but leave third-party.h as is, you can use one of the following commands:

clang-modernize -include=include/ src/foo.cpp -- -std=c++11 -I include/ -I lib/

clang-modernize -include=. -exclude=lib/ src/foo.cpp -- -std=c++11 -I include/ -I lib/

The Transforms

Right now there is a total of 6 transforms, two of which are new:

  1. Add-Override Transform
    Adds the ‘override’ specifier to overriden member functions.
  2. Loop Convert Transform
    Makes use of for-ranged based loop.
  3. Pass-By-Value Transform [new]
    Replaces const-ref parameters that would benefit from using the pass-by-value idiom.
  4. Replace Auto-Ptr Transform [new]
    Replaces uses of the deprecated std::auto_ptr by std::unique_ptr.
  5. Use-Auto Transform
    Makes use of the auto type specifier in variable declarations.
  6. Use-Nullptr Transform
    Replaces null literals and macros by nullptr where applicable.

Improvement to Add-Override

Since the last article in April, the Add-Override Transform has been improved to handle user-defined macros. Some projects, like LLVM, use a macro that expands to the ‘override’ specifier for backward compatibility with non-C++11-compliant compilers. clang-modernize can detect those macros and use them instead of the ‘override’ identifier.

The command line switch to enable this functionality is -override-macros.

Example:

 clang-modernize -override-macros foo.cpp

Before

#define LLVM_OVERRIDE override

struct A {
  virtual void foo();
};

struct B : A {
  virtual void foo();
};

After

 #define LLVM_OVERRIDE override


struct A {
  virtual void foo();
};

struct B : A {
  virtual void foo() LLVM_OVERRIDE;
};

Improvement to Use-Nullptr

This transform has also been improved to handle user-defined macros that behave like NULL. The user specifies which macros can be replaced by nullptr by using the command line switch -user-null-macros=.

Example:

clang-modernize -user-null-macros=MY_NULL bar.cpp

Before:

 #define MY_NULL 0

void bar() {
  int *p = MY_NULL;
}

After:

#define MY_NULL 0

void bar() {
  int *p = nullptr;
}

New Transform: Replace Auto-Ptr

This transform was a result of GSoC work. The transform replaces uses of std::auto_ptr``std::unique_ptr``std::move()

Before:

 #include <memory>

void steal(std::auto_ptr<int> x);

void foo(int i) {
  std::auto_ptr<int> p(new int(i));

  steal(p);
}

After:

 #include <memory>

void steal(std::unique_ptr<int> x);

void foo(int i) {
  std::unique_ptr<int> p(new int(i));

  steal(std::move(p));
}

New Transform: Pass-By-Value

Also a product of GSoC this transform makes use of move semantics added in C++11 to avoid a copy for functions that accept types that have move constructors by const reference. By changing to pass-by-value semantics, a copy can be avoided if an rvalue argument is provided. For lvalue arguments, the number of copies remains unchanged.

The transform is currently limited to constructor parameters that are copied into class fields.

Example:

clang-modernize pass-by-value.cpp

Before:

#include <string>

class A {
public:
  A(const std::string &Copied,
    const std::string &ReadOnly)
    : Copied(Copied),
      ReadOnly(ReadOnly) {}

private:
  std::string Copied;
  const std::string &ReadOnly;
};

After:

 #include <string>
#include <utility>

class A {
public:
  A(std::string Copied,
    const std::string &ReadOnly)
    : Copied(std::move(Copied)),
      ReadOnly(ReadOnly) {}

private:
  std::string Copied;
  const std::string &ReadOnly;
};

std::move() is a library function declared in ``. If need be, this header is added by clang-modernize.

There is a lot of room for improvement in this transform. Other situations that are safe to transform likely exist. Contributions are most welcomed in this area!

Usability Improvements

We also worked hard on improving the overall usability of the modernizer. Invoking the modernizer now requires fewer arguments since most of the time the arguments can be inferred.

  • If no compilation database or flags are provided, -std=c++11 is assumed.
  • All transforms are enabled by default.
  • Files don’t need to be explicitly listed if a compilation database is provided. The modernizer will get files from the compilation database. Use -include to choose which ones.

Two new features were also added.

  1. Automatically reformat code affected by transforms using LibFormat.
  2. A new command line switch to choose transforms to apply based on compiler support.

Reformatting Transformed Code

LibFormat is the library used behind the scenes by , a tool to format C, C++ and Obj-C code. uses this library as well to reformat transformed code. When enabled with -format, the default style is LLVM. The -style option can control the style in a way identical to clang-format.

Example:

format.cpp

#include <iostream>
#include <vector>

void f(const std::vector<int> &my_container) {
  for (std::vector<int>::const_iterator I = my_container.begin(),
                                        E = my_container.end();
       I != E; ++I) {
    std::cout << *I << std::endl;
  }
}

Without reformatting :


#include <iostream>
#include <vector>

void f(const std::vector<int> &my_container) {
  for (auto I = my_container.begin(),
                                        E = my_container.end();
       I != E; ++I) {
    std::cout << *I << std::endl;
  }
}

With reformatting


#include <iostream>
#include <vector>

void f(const std::vector<int> &my_container) {
  for (auto I = my_container.begin(), E = my_container.end(); I != E; ++I) {
    std::cout << *I << std::endl;
  }
}

For more information about this option, take a look at the documentation: Formatting Command Line Options.

Choosing Transforms based on Compiler Support

Another useful command-line switch is: -for-compilers. This option enables all transforms the given compilers support.

As an example, imagine that your project dropped a dependency to a “legacy” version of a compiler. You can automagically modernize your code to the new minimum versions of the compilers you want to support:

To support Clang >= 3.1, GCC >= 4.6 and MSVC 11:

clang-modernize -format -for-compilers=clang-3.1,gcc-4.6,msvc-11 foo.cpp

For more information about this option and to see which transforms are available for each compilers, please read the documentation.

What’s next?

The ability to transform many translation units in parallel will arrive very soon. Think of clang-modernize -j as in make and ninja. Modernization of large code bases will become much faster as a result.

More transforms are coming down the pipe as well as improvements to existing transforms such as the pass-by-value transform.

We will continue fixing bugs and adding new features. Our backlog is publically available: https://cpp11-migrate.atlassian.net/secure/RapidBoard.jspa?rapidView=1&view=planning

Get involved!

Interested by the tool? Found a bug? Have an idea of a transform that can be useful to others? The project is Open Source and contributions are most welcomed!

The modernizer has its own bug and project tracker. If you want to file or fix a bug just go to: https://cpp11-migrate.atlassian.net

A few other addresses to keep in mind:

Final word

Finally I want to thank my mentor Edwin Vane and his team at Intel, Tareq Siraj and Ariel Bernal, for the great support they provided me. Also thanks to the LLVM community and Google Summer of Code team for giving me this opportunity to work on the C++ Modernizer this summer.

– Guillaume Papin

Posted by Unknown at 4:12 AM

Labels: C++, Clang, GSoC, modernizer

No comments:

New comments are not allowed.

【科研绘图】【数据拟合曲线】:附Origin详细画图流程 拟合曲线图 阅读详情

相关推荐

高效低功耗设计:PMOS电子开关在墨水屏与ADC采样电路中的创新应用

本文深入探讨了PMOS电子开关在低功耗设计中的创新应用,特别是在墨水屏和ADC采样电路中的关键作用。通过详细分析PMOS的导通机制和近乎零静态功耗特性,展示了其在待机低功耗场景下的显著优势,并提供了实用的电路设计技巧和元器件选型建议,帮助工程师实现极致的功耗优化。

weixin_29193359的博客 168

在windows下使用llvm+clang

clang是FreeBSD和Mac下C/C++语言的默认编译器。如果你在苹果下做过开发,那么应该对它很熟悉。 这套工具链有很多优点: 代码很新,架构优良。错误信息更友好。静态检查功能更强大。版权限制小,易于自定义模块来扩展它的功能。背后有Apple和Google这两家商业公司的大力支持。比如XCode现在只支持clang而不支持gcc。支持JIT。这使得C/C++可以像java那样半编译半

xyjikl 7494

将一维数据(序列)转化为二维数据(图像)的方法汇总GAFS, MTF, Recurrence plot,STFT

虽然深度学习方法(1D CNN, RNN, LSTM 等)可以直接处理一维数据,但是当前的深度学习方法主要还是处理二维结构数据的,特别是在计算机视觉CV以及自然语言处理NLP领域,各种各样的方法层出不穷。因此,如果能够将一维序列数据转化为二维(图像)数据, 则可以直接结合CV以及NLP领域的方法,是不是很有趣! GAF, GASF, GADF, MTF, Recurrence Plot, STFT, 短时傅里叶变换

MasterQKK 5万+

clang-tidy 使用

1. 安装clang-tidy和clang编译工具 sudo apt install clang-tidy clang(ubuntu 16.04默认安装的是3.8版本) sudo apt install clang-tidy-6.0 clang-6.0(ubuntu 16.04 apt最高可安装6.0版本) 多版本可使用update-alternatives来管理 2. 简单使用 查看所有可...

xiaoou的博客 1万+

C# Log4Net不输出日志的解决方法

log4net是一个流行的 .NET 日志框架,用于记录应用程序的日志信息。如果你在使用log4net。

精通搬砖,资深技术砖家,在软件开发,人工智能,设备开发等领域都有研究。商业合作&交流学习可私信联系。 1266

Microchip Studio 7.0 从下载到项目调试:AVR开发者的完整入门指南(附常见问题解决)

本文为AVR开发者提供了Microchip Studio 7.0从下载安装到项目调试的完整入门指南。详细介绍了如何获取安装包、创建第一个AVR工程项目,并配置编译与调试环境。同时,文章重点解决了开发过程中常见的编译错误和仿真问题,帮助开发者快速上手并高效使用这一官方集成开发环境。

joy55的博客 340

llvm+clang的安装(使用cmake)

llvm+clang的安装(使用cmake)1.下载码源首先先安装svn,用来checkout llvm的码源aptitude install subversion然后checkout llvm的码源: 1.1 Checkout LLVM checkout的是llvm项目的主要代码cd where-you-want-llvm-to-live svn co http://llvm.org/svn/

wicky的博客 1万+

g2o&PCL 四阶多项式拟合

g2o&PCL 四阶多项式拟合

dayuhaitang1的博客 144

clang-tidy使用总结

clang-tidy使用总结clang-tidy静态扫描c++代码一:如何在centos7上安装clang-tidy二:如何使用clang-tidy clang-tidy静态扫描c++代码 这篇文章主要讲了以下几点: 1,如何在centos7上安装clang-tidy 2,如何使用clang-tidy 3,如何将clang-tidy结合blade对整个项目进行静态扫描 一:如何在centos7上安...

ypshowm的博客 1万+

4、机器人建模、规划与控制及运动学知识解析

本博客深入解析了机器人建模、规划与控制的核心内容,涵盖运动学与动力学的基本原理,并结合典型应用场景探讨了移动机器人与操作器的控制策略。同时,博客还介绍了机器人技术的发展趋势及其在工业和服务领域的广泛应用。

desk3的博客 128

Apollo Planning2.0决策规划算法代码详细解析 (1):环境搭建

1、官方提供连接:git clone https://github.com/ApolloAuto/application-pnc.git。此外,也更新了dreamview对pnc的支持,使得调试更加方便。apollo开源团队近期更新了planning版本,对代码进行了一定程度上的重构。(2)进入docker,并编译整个工程:./apollo.sh build_dbg。下载项目环境后使用aem进行环境配置;2、有一定基础建议直接拉取最新代码,自己手动进行编译。(1)环境安装: ./dev_start.sh。

自动驾驶Player的博客 1843

Google Summer of Code: C++ Modernizer Improvements----Monday, November 18, 2013

原文地址:http://blog.llvm.org/2013/11/google-summer-of-code-c-modernizer.html Google Summer of Code (GSoC) offers students stipends to participate in open source projects during the summer. This year,

SHINING的博客 1678

博途PLC如何建立与笔记本电脑端的连接?(新手必会)

对S7-1500PLC下载硬件组态或程序,需要建立PC与PLC的连接。 由于S7-1500CPU都具有PN端口,因此建立PC与S7-1500PLC的连接通常使用工业以太网来实现。 1.使用网线连接PC-PLC 使用网线,一端连接PC的以太网卡端口,另一端连接S7-1500CPU的PN端口。 2.设置本机IP地址 2.1 确认本机要设置的IP地址段 本机IP地址要和PLC程序组态IP地址段前三位保持一致,后一位使用组态中没有用到的IP地址段。如下图所示。 那么看了这个图片应该就知道了,地址应该设置成192.

weixin_42430971的博客 1万+

C++中值传递(pass-by-value)和引用传递(pass-by-reference)

1.pass-by-value的情况: 缺省情况C++以pass-by-value(继承C的方式)传递对象至(或来自)函数。函数参数都是以实际参数的复件为初值,调用端所获得的也是函数返回值的一个复件,复件由对象的拷贝构造函数产出,可能使pass-by-value成为耗时的操作。 2.耗时的原因 类的对象作为函数参数时,如果使用值传递,要先拷贝一份实参的副本,需要调用类的拷贝构造函数,函...

WHU_Fan的博客 2168

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

llvm编译器实战教程第二版_LLVM编译器实战教程

出版者的话译者序前言关于作者关于审稿人第1章 构建和安装LLVM 11.1 了解LLVM版本 11.2 获取预构建包 21.2.1 获取官方预构建二进制文件 21.2.2 使用软件包管理器 31.3 从源代码构建 41.3.1 系统要求 41.3.2 获取源代码 41.3.3 构建和安装LLVM 51.3.4 Windows和Microsoft Visual Studio 10...

weixin_29000119的博客 2460

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

C++ 高效编程:pass-by-value(值传递)与pass-by-reference(引用传递)

C++在定义函数传参时,常用pass-by-value(值传递)与pass-by-reference(引用传递)两种形式,两种参数传递具体实现方式为: 值传递(pass-by-value) 值传递(passl-by-value)过程中,在堆栈中开辟了形参内存空间,并调用拷贝构造函数把实参值复制给形参,从而成为了实参的一个副本。值传递的特点是被调函数对形式参数的任何操作都是作为局部变量进行,不会影响主调函数的实参变量的值,且实参到形参传值过程中调用了拷贝构造函数。 例: #include <i

great_emperor_的博客 3815

深度学习工具包 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")

方法参数中pass by reference(传引用)和 pass by value(传值)的区别

如果你把㆒个名为foo的对象作为参数传给某个函数,那么「对参数赋值」意味改变foo,使它引用(参考、指涉、指向)另㆒个对象。如果你在「被传入对象」身㆖进行什么操作,那没问题,我也总是这样干。我只针对「foo 被改而指向(引用)完全不同的另㆒个对象」这种情况来讨论: void aMethod(Object foo) {     foo.modifyInSomeWay(); // th

Ivan Yu 3240

c语言:文件操作2+预准备 编译 汇编 链接 运行

1.2 文件缓冲区(缓冲区分文件缓冲区,内存缓冲区,两个是不一样的,但是都是对于输入输出才有)fp = fopen(“test.txt”, “r”);二、编译与运行(翻译环境 / 运行环境)2.2 链接做的五件事(顺序不能倒)一句话记:键盘输入缓冲区 →。一、文件 I/O(磁盘文件)2.3 比较发生在哪个阶段。三、最容易混:两套缓冲区。

Code_Solitude的博客 388

C语言条件宏定义导致的隐藏bug

同一个宏定义可能在不同的.o文件中表示不同的值,而且因为宏定义是在预编译阶段的文本替换,所以 连接时即便相同的宏定义值不同也无法发现错误。代码在运行时这个数组的实际分配长度就是10,但是在IAR仿真时,监视到的数组长度是20,这是IAR仿真功能的bug。运行代码可以看到同一个宏在不同的.c文件打印值不一样,这是因为条件宏的条件对不同c文件的可见性不一样。不同的c语言编译器在这个问题上结果是一样的。但是,IAR在仿真时会出现仿真看到的数组长度为20,但是实际长度为10的情况。

qq_40438388的博客 50

Effective STL 条款 01:慎重选择容器类型

容器选型是结构性决策,应优先考虑访问模式、增删位置与失效规则。需随机访问或尾部增删时首选 vector;头尾操作选 deque;按键查找用 set/map;中间频繁插入且元素大、拷贝贵时才考虑 list。vector 默认最优,因连续内存提升缓存效率,兼容 C 接口,且多数场景性能领先。避免凭直觉选型,务必结合真实数据量测试,接口一旦暴露即成契约,换容器成本高昂。

软件科学-郝学胜 506

eventpp: 一款纯 Header-Only的高性能C++事件库

eventpp是一款纯Header-Only、零依赖的高性能C++事件库,支持C++11及以上,兼容多平台。核心组件包括CallbackList(同步信号槽)、EventDispatcher(事件分发)和EventQueue(异步队列),均提供线程安全机制与优异性能。通过模板策略可灵活配置线程安全级别,支持多生产者-多消费者模式及批量优化。虽原生不支持返回值聚合,但可通过输出参数、forEach遍历或promise/future等方案实现。适用于解耦组件、跨线程通信等场景,是Qt信号槽的轻量高效替代,尤其在

红军不怕远征难,万水千山只等闲 338

PaddleOCR与PyQt 界面综合案例

本项目基于PaddleOCR与PyQt5实现流水线标签实时识别系统,通过摄像头采集画面,结合置信度过滤(≥0.7)、正则格式筛选及三帧投票策略,有效降低单帧误识别,提升结果稳定性。系统采用模块化设计,实现“采集—识别—标注—统计”全流程可视化,界面简洁,响应实时,具备良好可扩展性,适用于工业场景中的自动化标签识别需求。

2302_80153357的博客 417

滤波是什么:限幅、滑动平均、中位值、一阶低通怎么选?嵌入式传感器滤波算法原理与C源码

滑动平均、中位值、一阶低通——名字有一长串,选错一个,控制环就可能开始振荡。为什么"平滑"和"滞后"是同一件事?为什么有的滤波越调越玄,问题却根本不在信号里?动手之前,先回答三个问题。

Lxx_Zw的博客 308

C++高性能日志库spdlog实战指南:从入门到异步编码实战

SpdLog是一款高性能、跨平台的C++11日志库,采用Header-Only设计,支持异步日志、多线程安全、彩色输出及文件滚动等特性。其架构基于Logger/Sink/Formatter三层模型,灵活可扩展。通过fmt风格格式化与自定义Pattern,实现高效安全的日志输出。支持多种Sink,可轻松集成至项目中,广泛应用于高性能服务开发。

程序员与背包客_CoderZ 192
上一篇: Extensible Metadata in LLVM IR
下一篇: Instruction Relationship Framework in LLVM
「已注销」
博客等级 码龄11年 2粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值