Skip to content

  • 体验新版
    • 正在加载...
  • 登录
  • PaddlePaddle
  • Paddle
  • 合并请求
  • !24018

P
Paddle
  • 项目概览

PaddlePaddle / Paddle
接近 2 年 前同步成功

通知 2323
Star 20933
Fork 5424
  • 代码
    • 文件
    • 提交
    • 分支
    • Tags
    • 贡献者
    • 分支图
    • Diff
  • Issue 1423
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 543
  • Wiki 0
    • Wiki
  • 分析
    • 仓库
    • DevOps
  • 项目成员
  • Pages
P
Paddle
  • 项目概览
    • 项目概览
    • 详情
    • 发布
  • 仓库
    • 仓库
    • 文件
    • 提交
    • 分支
    • 标签
    • 贡献者
    • 分支图
    • 比较
  • Issue 1,423
    • Issue 1,423
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 543
    • 合并请求 543
  • Pages
  • 分析
    • 分析
    • 仓库分析
    • DevOps
  • Wiki 0
    • Wiki
  • 成员
    • 成员
  • 收起侧边栏
  • 动态
  • 分支图
  • 创建新Issue
  • 提交
  • Issue看板

Init complex number neural network !24018

  • Report abuse
!24018 已合并 4月 20, 2020 由 saxon_zh@saxon_zh 创建
#<User:0x00007ff7b40f1ca8>
  • 概览 2
  • 提交 6
  • 变更 10

Created by: kuke

This pull request tries to define the way to implement a complex number neural network in PaddlePaddle.

Major changes and features:

  • Add a new class ComplexVariable to hold complex numbers, and expose frequently used attributes name, shape and dtype for it;
  • Support methods to_variable(), .numpy() and print() to make sure that ComplexVariable has the same interaction experience as the Variable defined on real number.
  • Users can also visit the members and methods of the real or imaginary part of ComplexVariable seperately as a common Variable.
  • Lay down API rules. Users only need to change the prefix of APIs from paddle to paddle.complex to build a complex number model, as the new added layers for element-wise complex number add/sub/mul/div demonstrated.

The usage (only support DyGraph at present):

>>> import numpy as np
>>> import paddle
>>> import paddle.fluid.dygraph as dg
>>> a = np.array([[1.0+1.0j, 2.0+1.0j], [3.0+1.0j, 4.0+1.0j]])
>>> b = np.array([[1.0+1.0j, 1.0+1.0j]])
>>> c = np.array([[1.0, 2.0], [3.0, 4.0]])
>>> with dg.guard():
...     x = dg.to_variable(a, "complex_x")
...     y = dg.to_variable(b)
...     z = dg.to_variable(c)
...     out = paddle.complex.elementwise_add(x, y)
...     print(out)
...
REAL: name tmp_1, dtype: VarType.FP64 shape: [2L, 2L] 	lod: {}
	dim: 2, 2
	layout: NCHW
	dtype: double
	data: [2 3 4 5]
IMAG: name tmp_2, dtype: VarType.FP64 shape: [2L, 2L] 	lod: {}
	dim: 2, 2
	layout: NCHW
	dtype: double
	data: [2 2 2 2]

>>> print(type(z), type(out))
(<class 'paddle.fluid.core_avx.VarBase'>, <class 'paddle.fluid.framework.ComplexVariable'>)
>>> print(out.numpy())
[[2.+2.j 3.+2.j]
 [4.+2.j 5.+2.j]]
>>> out.name
{'real': u'tmp_1', 'imag': u'tmp_2'}
>>> out.name = "out"
>>> out.name
{'real': u'out.real', 'imag': u'out.imag'}
>>> out.real.name = "new_name"
>>> out.name
{'real': u'new_name', 'imag': u'out.imag'}
>>> out.dtype
'complex128'
>>> out.shape
[2L, 2L]
>>> out.real.stop_gradient = True
>>> out.imag.stop_gradient = False
>>> out.real.stop_gradient
True
>>> out.imag.stop_gradient
False
指派人
分配到
审核者
Request review from
无
里程碑
无
分配里程碑
工时统计
标识: paddlepaddle/Paddle!24018
Source branch: github/fork/kuke/init_complex
渝ICP备2023009037号

京公网安备11010502055752号

网络110报警服务 Powered by GitLab CE v13.7
开源知识
Git 入门 Pro Git 电子书 在线学 Git
Markdown 基础入门 IT 技术知识开源图谱
帮助
使用手册 反馈建议 博客
《GitCode 隐私声明》 《GitCode 服务条款》 关于GitCode
Powered by GitLab CE v13.7