使用BOOST_PROTO_DEFINE_OPERATORS对std::vector进行表达式原型化的示例

C/C++ 专栏收录该内容
¥59.90 ¥99.00
167篇文章

使用BOOST_PROTO_DEFINE_OPERATORS对std::vector进行表达式原型化的示例

BOOST.PROTO是一个用于生成表达式模板库的Boost库。 BOOST_PROTO_DEFINE_OPERATORS宏可以定义为给定类型的操作符。本文将展示如何使用BOOST_PROTO_DEFINE_OPERATORS宏使std::vector<>成为可重载运算符的表达式。

在本例中,我们将编写一个简单的程序,其目的是获取两个向量并将它们相加。

首先,我们需要包含所需的头文件:

#include <boost/proto/proto.hpp>
#include <boost/mpl/vector.hpp>
#include <vector>
#include <iostream>

然后,我们需要定义一个向量类型,这个类型将继承自std::vector,并将其注册到PROTO之中。具体来说,我们需要定义一个表达式节点,其中包含基础类型std::vector<>和我们定义的操作符。

namespace mpl = boost::mpl;
namespace proto = boost::proto;

using namespace proto::placeholders;

// 定义表达式节点
struct VectorExpr :
    proto::or_<
        proto::terminal<std::vector<_>>,
        proto::plus<VectorExp
使用BOOST_PROTO_DEFINE_OPERATORS宏来原型化表达式的示例:使用std::vector和std::list作为非原型类型。 本文将演示如何使用BOOST_PROTO_DEFINE_OPERATORS宏来原型化表达式,并使用std::vector和std::list作为非原型类型的示例。在上述示例程序中,我们创建了两个std::vector对象vec1和vec2,以及一个std::list对象list1。然后,我们使用表达式模板将这些对象组合成一个表达式,并对表达式进行求值。使用BOOST_PROTO_DEFINE_OPERATORS宏来原型化表达式的示例:使用std::vector和std::list作为非原型类型。 阅读详情

相关推荐

使用BOOST_PROTO_DEFINE_OPERATORS对表达式进行原型化的示例:使用std::vector<>作为非原型类型

BOOST_PROTO_DEFINE_OPERATORS是Boost.Proto的一个宏,用于定义操作符,使得我们能够对自定义表达式进行更自然的语法操作。在这个示例中,我们将使用BOOST_PROTO_DEFINE_OPERATORS来将std::vector作为非原型类型,以便对表达式进行原型化。通过BOOST_PROTO_DEFINE_OPERATORS宏和自定义的非原型类型,我们可以方便地扩展Boost.Proto库,使其支持我们自定义的类型和操作符。在上面的代码中,我们定义了一个名为。

JieLun_C的博客 114

使用 BOOST_PROTO_DEFINE_OPERATORS 使用非原型类型 std::vector<> 对表达式进行原型化的示例

使用 BOOST_PROTO_DEFINE_OPERATORS 使用非原型类型 std::vector<> 对表达式进行原型化的示例实现功能C++实现代码 实现功能 使用 BOOST_PROTO_DEFINE_OPERATORS 使用非原型类型 std::vector<> 对表达式进行原型化的示例 C++实现代码 #include <vector> #include <iostream> #include <stdexcept> #include

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

BOOST_PROTO_DEFINE_OPERATORS宏使用 std::vector<> 和 std::list 非原型类型来原型化表达式的示例

BOOST_PROTO_DEFINE_OPERATORS宏使用 std::vector<> 和 std::list 非原型类型来原型化表达式的示例实现功能C++实现代码 实现功能 BOOST_PROTO_DEFINE_OPERATORS宏使用 std::vector<> 和 std::list 非原型类型来原型化表达式的示例 C++实现代码 #include <list> #include <cmath> #include <vector> #in

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

使用BOOST_PROTO_DEFINE_OPERATORS宏定义表达式模板是C++编程中的一项重要技术

可以看到,代码中最重要的部分是定义了表达式模板和表达式树节点。而针对于这个宏的使用方法,本文将会给大家提供一个示例,展示如何使用std::vector和std::list这两种非原型类型来原型化表达式。在主函数中,我们首先定义一个使用vector类型存储的向量和一个使用list类型存储的向量。总之,本文提供的示例代码展示了如何使用std::vector和std::list这两种非原型类型来原型化表达式。本文中的示例代码将使用表达式模板来计算一个向量的长度,并将结果存储在一个list容器中。

Meta_C的博客 149

Mapbox.Vectors:使用protobuf-net和C#的Mapbox矢量格式的解码器

Mapbox.Vectors 使用protobuf-net和C#的mapbox矢量格式的解码器。 对于规格检查: 在C#中解码mapbox矢量切片的第一个步骤。 目前仅包含.proto生成的代码和对test-tile进行解码的简单unittest。

SpringBoot和Vue非遗工坊课程预约与作品展销平台源码

包含前后端源码、SQL初始化脚本和启动说明。JDK 17、Spring Boot、Vue;默认H2演示数据库。

西周BC797年世界历史地图矢量文件SHP格式.zip

本资源为《西周BC797年世界历史地图矢量文件SHP格式》压缩包,文件大小约 24.82 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

研一脑电小白日记 之 EEGLAB预处理实战指南

本文为脑电研究新手提供了一份详尽的EEGLAB预处理实战指南。从MATLAB与EEGLAB环境搭建、使用NeuracleEEGFileReader插件导入BDF格式数据开始,逐步讲解了电极定位、滤波、降采样、ICA去伪迹等核心步骤,旨在帮助初学者高效完成脑电数据预处理,为后续分析奠定坚实基础。

weixin_29230649的博客 573

告别Qt Creator?手把手教你用VSCode+MinGW调试QT项目(附完整launch.json配置)

本文详细介绍了如何在VSCode中配置完整的QT开发环境,特别是针对使用MinGW编译器的用户。从环境搭建到调试配置,包括生成.pro文件、Makefile,以及配置task.json和launch.json文件,帮助开发者高效调试QT项目。

weixin_27180827的博客 192

树莓派34/100 - Pico读取MPU6050加速度和陀螺仪传感器数据

树莓派Pico连接MPU-6050模块(三轴陀螺仪+三轴加速度),读取运动姿态数据。

申龙斌的程序人生 5099

25、压电泵致动器变形计算与测量及转弯腔射流特性的有限元分析

本文围绕压电泵致动器的变形计算与测量以及转弯腔射流特性的有限元分析展开研究。通过建立有限元模型和抛物线拟合方法,对压电泵致动器的位移和变形体积进行了详细计算,并探讨了其对传感器性能的影响。同时,利用ANSYS软件对转弯腔在不同角速率输入下的射流特性进行了仿真分析,揭示了流场分布随角速率变化的规律。研究成果为压电流体角速率传感器的设计优化提供了理论依据和技术支持。

ooo22的博客 130

红火蚁巢穴AI智能识别,提供方案与思路!

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值 。

**My Coding Family** 1052

AutosarMCAL开发——基于EB MCU驱动

本文为博主个人学习总结记录,如有不正,欢迎指正。

qq_45583706的博客 925

【nnUNetv2进阶】三、nnUNetv2 自定义网络-发paper必会

对于很多朋友来说,找到nnunet的网络结构位置的代码可能比较困难,因为nnunet的网络结构从else:代码中没有网络结构的类名,那么使用的网络是哪个呢?打开预处理后的数据集中的nnUNetPlans.json文件,如下图,configurations里面有2d、3d_fullres等,这些表示nnunet的模型,下面的network_class_name指的就是训练使用的模型结构,一般都是PlainConvUNet。

AI爱好者的博客,分享计算机领域相关知识 8769

MIPI D-PHY TX 一致性测试实例解析 Part 03

本文之前,已经讨论了MIPI D-PHY TX的1.3.x和1.4.x的测试项,1.5.x的测试项相对较少,主要是用于时钟和数据通道相关的时序测量

一只豌豆象的博客 5207

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

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

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

上一篇: “boost::is_straight_line_drawing测试程序示例“
下一篇: GDCM库中EnumeratedValues类的测试程序
普通网友
博客等级 码龄4年 1009粉丝 1545原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值