当前位置: 首页 > wzjs >正文

东软网站建设网站开发 产品经理

东软网站建设,网站开发 产品经理,怎么做电商赚钱,吕梁网站建设kuyisoToy 语言 本教程,将会借助一个玩具语言来讲解,这个语言我们称其为 Toy。Toy 是一个基于张量的语言,它允许你定义函数,执行一些数学计算,并且打印结果。做这样的设定,是因为我们希望让教程保持简明&#xff…

Toy 语言

   本教程,将会借助一个玩具语言来讲解,这个语言我们称其为 Toy。Toy 是一个基于张量的语言,它允许你定义函数,执行一些数学计算,并且打印结果。做这样的设定,是因为我们希望让教程保持简明;codegen 部分将会限制张量的维度小于等于2,而且Toy中的数据类型都是 64bit 浮点型的,也就是C语言中的double类型。于是,所有的值都隐式定义为double精度的,而且,所有的值都是不变的常量,也就是说,每一个操作的返回值都会是新分配的变量,再就是,重新分配变量是自动化管理的。上述说明已经足够了,没有什么比通读一个示例更有助于理解 MLIR 的目的和方法了。

def main() {# Define a variable `a` with shape <2, 3>, initialized with the literal value.# The shape is inferred from the supplied literal.#定义一个形状为2行3列的变量a,如下字面逐元素初始化。变量的形状通过提供的初始化来推导。var a = [[1, 2, 3], [4, 5, 6]];# b is identical to a, the literal tensor is implicitly reshaped: defining new# variables is the way to reshape tensors (element count must match).#变量b与a是一样的,这个初始化的方式是隐式地变形了:变形张量是通过定义新的变量的方式实现的,但是元素个数必须能对上。var b<2, 3> = [1, 2, 3, 4, 5, 6];# transpose() and print() are the only builtin, the following will transpose# a and b and perform an element-wise multiplication before printing the result.#transpose() 和 print() 函数是唯一内置的函数,接下来将会转置a 和 b,并且逐元素做乘法运算,然后打印结果。print(transpose(a) * transpose(b));
}

类型检查是通过类型推导静态执行的;Toy 语言仅仅要求在必要的时候指定张量的类型。函数是通用的:它们的参数未指定阶数,也就是说,我们知道函数的每个参数是一个张量,但是我们不知道它们的维度。为每一个新发现的调用点的签名,都被特化处理。让我们看一遍之前的示例代码,这次我们增加了一个 用户自定义的函数:

# User defined generic function that operates on unknown shaped arguments.
# 用户自定义的通用函数,它作用在未知形状的参数上
def multiply_transpose(a, b) {return transpose(a) * transpose(b);
}def main() {# Define a variable `a` with shape <2, 3>, initialized with the literal value.var a = [[1, 2, 3], [4, 5, 6]];var b<2, 3> = [1, 2, 3, 4, 5, 6];# This call will specialize `multiply_transpose` with <2, 3> for both# arguments and deduce a return type of <3, 2> in initialization of `c`.# 这个调用将会给函数 multiply_transpose 指定两个形状为2行3列的张量作为参数,并且推导出返回值c的形状为3行2列,按此做初始化。var c = multiply_transpose(a, b);# A second call to `multiply_transpose` with <2, 3> for both arguments will# reuse the previously specialized and inferred version and return <3, 2>.#基本同上var d = multiply_transpose(b, a);# A new call with <3, 2> (instead of <2, 3>) for both dimensions will# trigger another specialization of `multiply_transpose`.# 这里是一个新的调用,入参的形状变为3行2列,而不再是2行3列,这将会触发特化另一新的 multiply_transpose函数的实现。var e = multiply_transpose(c, d);# Finally, calling into `multiply_transpose` with incompatible shapes# (<2, 3> and <3, 2>) will trigger a shape inference error.# 最后,调用对函数 multiply_transpose 做一次参数形状不兼容的调用,这将会触发一个形状推导错误。var f = multiply_transpose(a, c);
}

dump AST

从上边的代码生成的 AST 是相当简单的。这里对它做了转储:

Module:Function Proto 'multiply_transpose' @test/Examples/Toy/Ch1/ast.toy:4:1Params: [a, b]Block {ReturnBinOp: * @test/Examples/Toy/Ch1/ast.toy:5:25Call 'transpose' [ @test/Examples/Toy/Ch1/ast.toy:5:10var: a @test/Examples/Toy/Ch1/ast.toy:5:20]Call 'transpose' [ @test/Examples/Toy/Ch1/ast.toy:5:25var: b @test/Examples/Toy/Ch1/ast.toy:5:35]} // BlockFunction Proto 'main' @test/Examples/Toy/Ch1/ast.toy:8:1Params: []Block {VarDecl a<> @test/Examples/Toy/Ch1/ast.toy:11:3Literal: <2, 3>[ <3>[ 1.000000e+00, 2.000000e+00, 3.000000e+00], <3>[ 4.000000e+00, 5.000000e+00, 6.000000e+00]] @test/Examples/Toy/Ch1/ast.toy:11:11VarDecl b<2, 3> @test/Examples/Toy/Ch1/ast.toy:15:3Literal: <6>[ 1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 5.000000e+00, 6.000000e+00] @test/Examples/Toy/Ch1/ast.toy:15:17VarDecl c<> @test/Examples/Toy/Ch1/ast.toy:19:3Call 'multiply_transpose' [ @test/Examples/Toy/Ch1/ast.toy:19:11var: a @test/Examples/Toy/Ch1/ast.toy:19:30var: b @test/Examples/Toy/Ch1/ast.toy:19:33]VarDecl d<> @test/Examples/Toy/Ch1/ast.toy:22:3Call 'multiply_transpose' [ @test/Examples/Toy/Ch1/ast.toy:22:11var: b @test/Examples/Toy/Ch1/ast.toy:22:30var: a @test/Examples/Toy/Ch1/ast.toy:22:33]VarDecl e<> @test/Examples/Toy/Ch1/ast.toy:25:3Call 'multiply_transpose' [ @test/Examples/Toy/Ch1/ast.toy:25:11var: c @test/Examples/Toy/Ch1/ast.toy:25:30var: d @test/Examples/Toy/Ch1/ast.toy:25:33]VarDecl f<> @test/Examples/Toy/Ch1/ast.toy:28:3Call 'multiply_transpose' [ @test/Examples/Toy/Ch1/ast.toy:28:11var: a @test/Examples/Toy/Ch1/ast.toy:28:30var: c @test/Examples/Toy/Ch1/ast.toy:28:33]} // Block

可以在文件夹 examples/toy/Ch1/ 中的示例代码上重新生成这个AST。请尝试运行:

path/to/BUILD/bin/toyc-ch1 test/Examples/Toy/Ch1/ast.toy -emit=ast


文章转载自:

http://bcby8CIq.hpnbp.cn
http://T28qytYx.hpnbp.cn
http://nykltUm8.hpnbp.cn
http://KejNV2Xr.hpnbp.cn
http://V54OQ1k9.hpnbp.cn
http://byoITo9u.hpnbp.cn
http://hdauUkGS.hpnbp.cn
http://h5QDq4Xr.hpnbp.cn
http://4GpFLW91.hpnbp.cn
http://uFiJnD6n.hpnbp.cn
http://ojbBeCRK.hpnbp.cn
http://hhmO5vu1.hpnbp.cn
http://WyFINkvs.hpnbp.cn
http://ufnPGuf2.hpnbp.cn
http://UV81h0F7.hpnbp.cn
http://DerCKz2l.hpnbp.cn
http://uE3WnG63.hpnbp.cn
http://aTZjIk7e.hpnbp.cn
http://Pcwemw47.hpnbp.cn
http://2AMZ3EzK.hpnbp.cn
http://bB71Lzqn.hpnbp.cn
http://FMbhPzjK.hpnbp.cn
http://bnDUtZKD.hpnbp.cn
http://QGKVJysl.hpnbp.cn
http://DE3UZxDq.hpnbp.cn
http://Zt6wdDwm.hpnbp.cn
http://yRY9k1Oc.hpnbp.cn
http://pHJtg7P9.hpnbp.cn
http://wX1htIhi.hpnbp.cn
http://piRCb2U1.hpnbp.cn
http://www.dtcms.com/wzjs/707309.html

相关文章:

  • 新乡搜狗网站推广工具网页微信版二维码过期怎么办
  • 潮州建设局网站搜索推广策略制定
  • 网店网站怎么做wordpress创建角色
  • 路由器做内部网站服务器wordpress文章排序
  • 网站被收录的过程wordpress 插件机制
  • 18款禁用网站app破解版百度推广自己做网站吗
  • 做京东商城网站做网站 信息集成过程的顺序
  • 临沧市住房和城乡建设网站手机logo在线制作 免费
  • 微信公众号网站开发模板妇女之家网站建设方案
  • 用文本文档做网站长清区网站建设宣传
  • 效果图网站猪八戒在线ps网站
  • 网站建设试卷外链发布工具
  • 做搜狗手机网站优梅州哪里做网站
  • 手机网站建设报价哪个网站是自己销售
  • 有货 那样的网站怎么做海外网络加速器
  • 网站seo优化推广教程wordpress大图简约主题
  • 企业网站asp模板品牌建设存在的问题及建议
  • 山东省住房与建设厅网站首页百度安装下载
  • 建设金融网站哪家好轻量wordpress主题
  • 网站建设项目可行性asp.net做的网站要放到网上空间去_要放哪些文件上去
  • 长沙微信网站开发免费的短视频app大全下载
  • 怎样建一个免费网站网络科技公司实习周记
  • 用网站源码怎么做网站在义乌做电商怎么起步
  • 网站排名top排行榜巢湖网站建设
  • 合适的网站建设明细报价表dw个人网页制作代码
  • 旅游信息网站开发05网数学
  • 怎么搞自己的网站最近一周的时政热点新闻
  • 东莞物流网站设计公司工作职责怎么写
  • 企业网站建设教程视频网站建设与维护培训
  • 做网站竞价还需要推广公司wordpress时光轴主题