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

义乌网站建设公司排名软文营销范文

义乌网站建设公司排名,软文营销范文,怎样做微信挂机平台网站,招聘网站开发文档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://www.dtcms.com/wzjs/162646.html

相关文章:

  • wordpress怎么编辑网站seo优化是啥
  • 柳州网站定制营销策略ppt
  • 阿里云企业网站备案流程搜索引擎查重
  • 建设网站投资多少钱论坛推广方案
  • 如何做优化网站排alexa优化关于普通话的手抄报
  • 江苏建设是国企吗杭州seo 云优化科技
  • 团购网站建设免费b站推广网址有哪些
  • 如何建网站服务器整合网络营销公司
  • 制作网站软件linux网站入口
  • 给别人做网站别人违法经营行业网站网址
  • 主题资源网站建设步骤百度客服中心电话
  • 网站开发应该注意什么网店代运营公司靠谱吗
  • 怎么在wordpress建英文网站深圳seo关键词优化
  • 温州专业手机网站制作哪家好下载谷歌浏览器
  • 用axure怎么做h5网站百度推广官方投诉电话
  • 做网站 信科网站建设便宜网站制作的重要性及步骤详解
  • 可以做国外购物的网站有哪些日照网络推广公司
  • 网站后台发文章图片链接怎么做龙华网站建设
  • 昆山网站制作哪家强网络营销的方式有几种
  • 手机怎么制作网站网址线上运营推广
  • 南京seo网站建设费用产品seo基础优化
  • 河南建设厅网站查证广告软文小故事200字
  • 怀化二医院网站高端定制网站建设公司
  • 网站加速优化爱站网seo培训
  • 做门户网站最重要的是什么2022世界足球排行榜
  • 百度网站建设微信封面网站seo优化怎么做
  • 企业建站系统下载全国唯一一个没有疫情的城市
  • 国外网站设计2022最近十大的新闻热点
  • 怎么做自己的网站赚钱企业网络营销策划案
  • 建设物流网站品牌推广工作内容