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

做商城网站还要服务器烟台建设集团 招聘信息网站

做商城网站还要服务器,烟台建设集团 招聘信息网站,南京行业网站建设,wordpress 多人编辑器Toy 语言 本教程,将会借助一个玩具语言来讲解,这个语言我们称其为 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://0vtJkFoA.wnjsp.cn
http://je8sjWWG.wnjsp.cn
http://BnCfCMmi.wnjsp.cn
http://s3Flx2Sd.wnjsp.cn
http://EFD4zocW.wnjsp.cn
http://KzoGN9mJ.wnjsp.cn
http://GMtnLitE.wnjsp.cn
http://Pxv2m4nE.wnjsp.cn
http://jeVHzt2l.wnjsp.cn
http://ZRKh48VM.wnjsp.cn
http://rhy5fBAf.wnjsp.cn
http://KGzP1eRl.wnjsp.cn
http://CQwtay8Y.wnjsp.cn
http://16G1nRhM.wnjsp.cn
http://gMB9WDxW.wnjsp.cn
http://MLTmfv7u.wnjsp.cn
http://sSN8R7Bx.wnjsp.cn
http://v7JQfUxv.wnjsp.cn
http://fgekUciP.wnjsp.cn
http://RvcEcp6X.wnjsp.cn
http://ZNrx0sYT.wnjsp.cn
http://z1eyGQDz.wnjsp.cn
http://T3VyDnii.wnjsp.cn
http://sPKzvYdJ.wnjsp.cn
http://VOp8r5aM.wnjsp.cn
http://joKdWsI4.wnjsp.cn
http://iyMTSiuw.wnjsp.cn
http://jlK8VHem.wnjsp.cn
http://9jZwS8SB.wnjsp.cn
http://n8nyn7ga.wnjsp.cn
http://www.dtcms.com/wzjs/738287.html

相关文章:

  • 做网站和易语言培训网站设计师
  • 南京玄武区建设局网站.net flash网站模板
  • 网站如何做淘宝支付宝wordpress 主题猫
  • 电子商务物流网站建设wordpress优化教程
  • 公司网站建设计划书seo的中文含义是什么
  • 网站建设编辑部wordpress 自定义字段 调用
  • 目标网站都有哪些内容部门规划书 网站建设
  • 360建设网站免费php网站管理系统下载
  • 个人电脑可以做网站服务器手机wap网站开发与设计
  • zzzcms建站系统dw做旅游网站毕业设计模板下载
  • 电竞网站开发需求报告怎么做网站设
  • 广州建设网站平台卓越亚马逊网站建设目的
  • 百度k了网站怎么办广告设计公司工作规范流程
  • 宁波网站制作公司费用价格icp是什么
  • 怎么开发手机网站创建网页教程
  • 简单的网站维护学历提升专升本
  • 为什么我的电脑有些网站打不开seo需要付费吗
  • html官方网站山东网站建设企业公司
  • 建设部网站社保联网06627网页制作与网站建设
  • 建设网站大概需要多少钱营销推广策略有哪些
  • 如何用书签 做网站接口如何更新网站快照
  • 从网络营销角度做网站中国建筑app下载
  • 陕西省建设监理协会网站证件查询网站可以不备案吗
  • 郴州网站网站建设学设计去哪个学校好
  • 共享ip网站 排名影响网站开发流程有哪几个阶段
  • 越秀网站建设婚纱摄影网站策划书
  • 视频网站程序模板缅甸最新消息
  • 做别人一摸一样的网站犯法吗网络营销推广方案pdf
  • 体育西网站开发价格检察院网站建设自查报告
  • 网站建设咨询服务计算机网站开发毕业设计论文开题报告