IOS开发之宏的深度学习
- //This defines PI
- #define M_PI 3.14159265358979323846264338327950288
- #define M_PI 3.14159265358979323846264338327950288
- double r = 10.0;
- double circlePerimeter = 2 * M_PI * r;
- // => double circlePerimeter = 2 * 3.14159265358979323846264338327950288 * r;
- printf("Pi is %0.7f",M_PI);
- //Pi is 3.1415927
- //A simple function-like macro
- #define SELF(x) x
- NSString *name = @"Macro Rookie";
- NSLog(@"Hello %@",SELF(name));
- // => NSLog(@"Hello %@",name);
- // => Hello Macro Rookie
- #define PLUS(x,y) x + y
- printf("%d",PLUS(3,2));
- // => printf("%d",3 + 2);
- // => 5
- //Version 1.0
- #define MIN(A,B) A < B ? A : B
- int a = MIN(1,2);
- // => int a = 1 < 2 ? 1 : 2;
- printf("%d",a);
- // => 1
- int a = 2 * MIN(3, 4);
- printf("%d",a);
- // => 4
- int a = 2 * MIN(3, 4);
- // => int a = 2 * 3 < 4 ? 3 : 4;
- // => int a = 6 < 4 ? 3 : 4;
- // => int a = 4;
- //Version 2.0
- #define MIN(A,B) (A < B ? A : B)
- int a = MIN(3, 4 < 5 ? 4 : 5);
- printf("%d",a);
- // => 4
- int a = MIN(3, 4 < 5 ? 4 : 5);
- // => int a = (3 < 4 < 5 ? 4 : 5 ? 3 : 4 < 5 ? 4 : 5); //希望你还记得运算符优先级
- // => int a = ((3 < (4 < 5 ? 4 : 5) ? 3 : 4) < 5 ? 4 : 5); //为了您不太纠结,我给这个式子加上了括号
- // => int a = ((3 < 4 ? 3 : 4) < 5 ? 4 : 5)
- // => int a = (3 < 5 ? 4 : 5)
- // => int a = 4
- //Version 3.0
- #define MIN(A,B) ((A) < (B) ? (A) : (B))
- float a = 1.0f;
- float b = MIN(a++, 1.5f);
- printf("a=%f, b=%f",a,b);
- // => a=3.000000, b=2.000000
- float a = 1.0f;
- float b = MIN(a++, 1.5f);
- // => float b = ((a++) < (1.5f) ? (a++) : (1.5f))
- int a = ({
- int b = 1;
- int c = 2;
- b + c;
- });
- // => a is 3
- //GNUC MIN
- #define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
- //CLANG MIN
- #define __NSX_PASTE__(A,B) A##B
- #define MIN(A,B) __NSMIN_IMPL__(A,B,__COUNTER__)
- #define __NSMIN_IMPL__(A,B,L) ({ __typeof__(A) __NSX_PASTE__(__a,L) = (A); __typeof__(B) __NSX_PASTE__(__b,L) = (B); (__NSX_PASTE__(__a,L) < __NSX_PASTE__(__b,L)) ? __NSX_PASTE__(__a,L) : __NSX_PASTE__(__b,L); })
- #define __NSX_PASTE__(A,B) A##B
- #define MIN(A,B) __NSMIN_IMPL__(A,B,__COUNTER__)
- #define __NSMIN_IMPL__(A,B,L) ({ __typeof__(A) __NSX_PASTE__(__a,L) = (A); \
- __typeof__(B) __NSX_PASTE__(__b,L) = (B); \
- (__NSX_PASTE__(__a,L) < __NSX_PASTE__(__b,L)) ? __NSX_PASTE__(__a,L) : __NSX_PASTE__(__b,L); \
- })
- NSArray *array = @[@"Hello", @"My", @"Macro"];
- NSLog (@"The array is %@", array);
- 2014-01-20 11:22:11.835 TestProject[23061:70b] The array is (
- Hello,
- My,
- Macro
- )
- //A better version of NSLog
- #define NSLog(format, ...) do { \
- fprintf(stderr, "<%s : %d> %s\n", \
- [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], \
- __LINE__, __func__); \
- (NSLog)((format), ##__VA_ARGS__); \
- fprintf(stderr, "-------\n"); \
- } while (0)
- //A wrong version of NSLog
- #define NSLog(format, ...) fprintf(stderr, "<%s : %d> %s\n", \
- [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], \
- __LINE__, __func__); \
- (NSLog)((format), ##__VA_ARGS__); \
- fprintf(stderr, "-------\n");
- if (errorHappend)
- NSLog(@"Oops, error happened");
- if (errorHappend)
- fprintf((stderr, "<%s : %d> %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __func__);
- (NSLog)((format), ##__VA_ARGS__); //I will expand this later
- fprintf(stderr, "-------\n");
- //Another wrong version of NSLog
- #define NSLog(format, ...) {
- fprintf(stderr, "<%s : %d> %s\n", \
- [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], \
- __LINE__, __func__); \
- (NSLog)((format), ##__VA_ARGS__); \
- fprintf(stderr, "-------\n"); \
- }
- //I am sorry if you don't like { in the same like. But I am a fan of this style :P
- if (errorHappend) {
- fprintf((stderr, "<%s : %d> %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __func__);
- (NSLog)((format), ##__VA_ARGS__);
- fprintf(stderr, "-------\n");
- };
- if (errorHappend)
- NSLog(@"Oops, error happened");
- else
- //Yep, no error, I am happy~ :)
- if (errorHappend) {
- fprintf((stderr, "<%s : %d> %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __func__);
- (NSLog)((format), ##__VA_ARGS__);
- fprintf(stderr, "-------\n");
- }; else {
- //Yep, no error, I am happy~ :)
- }
- if (errorHappend)
- do {
- fprintf((stderr, "<%s : %d> %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __func__);
- (NSLog)((format), ##__VA_ARGS__);
- fprintf(stderr, "-------\n");
- } while (0);
- else {
- //Yep, no error, I am really happy~ :)
- }
- [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __func__);
- -------
- <AppDelegate.m : 46> -[AppDelegate application:didFinishLaunchingWithOptions:]
- 2014-01-20 16:44:25.480 TestProject[30466:70b] The array is (
- Hello,
- My,
- Macro
- )
- -------
- NSLog(@"Hello");
- => do {
- fprintf((stderr, "<%s : %d> %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __func__);
- (NSLog)((@"Hello"), );
- fprintf(stderr, "-------\n");
- } while (0);
- #define NSLogRect(rect) NSLog(@"%s x:%.4f, y:%.4f, w:%.4f, h:%.4f", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)
- #define NSLogSize(size) NSLog(@"%s w:%.4f, h:%.4f", #size, size.width, size.height)
- #define NSLogPoint(point) NSLog(@"%s x:%.4f, y:%.4f", #point, point.x, point.y)
- #define XCTAssertTrue(expression, format...) \
- _XCTPrimitiveAssertTrue(expression, ## format)
- #define _XCTPrimitiveAssertTrue(expression, format...) \
- ({ \
- @try { \
- BOOL _evaluatedExpression = !!(expression); \
- if (!_evaluatedExpression) { \
- _XCTRegisterFailure(_XCTFailureDescription(_XCTAssertion_True, 0, @#expression),format); \
- } \
- } \
- @catch (id exception) { \
- _XCTRegisterFailure(_XCTFailureDescription(_XCTAssertion_True, 1, @#expression, [exception reason]),format); \
- }\
- })
- //调用 RACSignal是类的名字
- RACSignal *signal = [RACObserve(self, currentLocation)];
- //以下开始是宏定义
- //rac_valuesForKeyPath:observer:是方法名
- #define RACObserve(TARGET, KEYPATH) \
- [(id)(TARGET) rac_valuesForKeyPath:@keypath(TARGET, KEYPATH) observer:self]
- #define keypath(...) \
- metamacro_if_eq(1, metamacro_argcount(__VA_ARGS__))(keypath1(__VA_ARGS__))(keypath2(__VA_ARGS__))
- //这个宏在取得keypath的同时在编译期间判断keypath是否存在,避免误写
- //您可以先不用介意这里面的巫术..
- #define keypath1(PATH) \
- (((void)(NO && ((void)PATH, NO)), strchr(# PATH, '.') + 1))
- #define keypath2(OBJ, PATH) \
- (((void)(NO && ((void)OBJ.PATH, NO)), # PATH))
- //A和B是否相等,若相等则展开为后面的第一项,否则展开为后面的第二项
- //eg. metamacro_if_eq(0, 0)(true)(false) => true
- // metamacro_if_eq(0, 1)(true)(false) => false
- #define metamacro_if_eq(A, B) \
- metamacro_concat(metamacro_if_eq, A)(B)
- #define metamacro_if_eq1(VALUE) metamacro_if_eq0(metamacro_dec(VALUE))
- #define metamacro_if_eq0(VALUE) \
- metamacro_concat(metamacro_if_eq0_, VALUE)
- #define metamacro_if_eq0_1(...) metamacro_expand_
- #define metamacro_expand_(...) __VA_ARGS__
- #define metamacro_argcount(...) \
- metamacro_at(20, __VA_ARGS__, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
- #define metamacro_at(N, ...) \
- metamacro_concat(metamacro_at, N)(__VA_ARGS__)
- #define metamacro_concat(A, B) \
- metamacro_concat_(A, B)
- #define metamacro_concat_(A, B) A ## B
- #define metamacro_at2(_0, _1, ...) metamacro_head(__VA_ARGS__)
- #define metamacro_at20(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, ...) metamacro_head(__VA_ARGS__)
- #define metamacro_head(...) \
- metamacro_head_(__VA_ARGS__, 0)
- #define metamacro_head_(FIRST, ...) FIRST
- #define metamacro_dec(VAL) \
- metamacro_at(VAL, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19)
IOS开发之宏的深度学习相关推荐
- 从代码设计到应用开发,入坑深度学习看这本书就够了
深度学习(Deep Learning)是机器学习中一种基于对数据进行表征学习的方法.近年来,深度学习已经在科技界.工业界日益广泛地应用.随着全球各领域多样化数据的极速积累和计算资源的成熟化商业服务,深 ...
- #今日论文推荐# 中国矿大团队,开发集成多尺度深度学习模型,用于 RNA 甲基化位点预测
#今日论文推荐# 中国矿大团队,开发集成多尺度深度学习模型,用于 RNA 甲基化位点预测 研究表明,通过转录后 RNA 修饰进行的表观转录组调控,对于所有种类的 RNA 都是必不可少的.准确识别 RN ...
- 开发实战:基于深度学习+maven+SSM+EasyUI的高校共享汽车管理系统(一)
基于深度学习+maven+SSM+EasyUI的高校共享汽车管理系统 1.项目简介 在现在,共享汽车在中国各地方开始热起来,于是本人想做一个基于maven+SSM+EasyUI的高校共享汽车管理系统, ...
- 【iOS开发】—— SDWebImage源码学习(未完)
文章目录 什么是SDWebImage? sd_setImageWithURL调用关系 步骤一 步骤三 步骤四 步骤五 步骤六 下载步骤 UIImageView+ WebCache UIView+ We ...
- iOS开发-由浅至深学习block
作者:Sindri的小巢(简书) 关于block 在iOS 4.0之后,block横空出世,它本身封装了一段代码并将这段代码当做变量,通过block()的方式进行回调.这不免让我们想到在C函数中,我们 ...
- iOS开发之《英语词汇学习》
导语: 如果你已经加入了iOS攻城狮队伍,那么我们由衷地祝贺您正式成为一名终身学习的程序猿:有人觉得这句话有些儿夸张,但等你亲身体会了就明白其中的滋味.下面是整理的一些阅读开发文档所需要用到的词汇,分 ...
- ios开发ios9新特性关键字学习:泛型,逆变,协变,__kindof
一:如何去学习?都去学习什么? 1:学习优秀项目的设计思想,多问几个为什么,为什么要这么设计,这么设计的好处是什么,还能不能在优化 ,如何应用到自己的项目中 2:学习优秀项目的代码风格,代码的封装设计 ...
- iOS开发(2)UILabel学习
相信所有学习ios的人,都应该是从UILabel这个空间开始的. UILabel是一个文本控件. //创建uilabel对象 UILabel *lable = [[UILabelalloc] init ...
- 1.5 训练/开发/测试集划分-深度学习第三课《结构化机器学习项目》-Stanford吴恩达教授
←上一篇 ↓↑ 下一篇→ 1.4 满足和优化指标 回到目录 1.6 开发集合测试集的大小 训练/开发/测试集划分 (Train/Dev/Test Distribution) 设立训练集,开发集和测试集 ...
- RK3399开发板AI人工智能深度学习之TensorFlow 测试
硬件平台:迅为-RK3399开发板 系统:ubuntu 项目:TensorFlow 测试 配套资料在网盘资料的"iTOP-3399 开发资料汇总(不含光盘内容)\08_iTOP-3399 开 ...
最新文章
- Xamarin Android设置界面提示类型错误
- HTML5 进阶系列:indexedDB 数据库
- linux上git克隆命令,Git clone命令用法
- ksoap2-android Project
- html select下拉菜单长度过长不出滚动条问题解决办法
- 物理层下面的传输媒体
- 手动更新windows补丁
- linux给文件夹图标,Linux 如何在启动器中自定义图标
- linux suse11 sp3安装,SUSE Linux Enterprise Server 11 SP3安装教程详解
- Vasya the Hipster
- 从十七年蝉谈起——hashtable的表格大小为什么要选择质数
- 我见过最“骚”的代码注释!神兽版都来了
- api 二次 开发 禅道_禅道 Rest API 开发
- YOLOV5dataset.py代码注释与解析
- 98大水灾,各国各地区对我国的捐助一览表
- 巨头卡位物联网 纷纷瞄准家庭网关设备
- Java学习之注解(五)Android循序渐进实现高逼格自定义ViewBinder
- Java数组初始化长度
- ccs读取dat文件c语言程序,CCS中dat文件的格式
- 简单python项目实例-python实战项目