• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python special_math_ops.einsum函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.python.ops.special_math_ops.einsum函数的典型用法代码示例。如果您正苦于以下问题:Python einsum函数的具体用法?Python einsum怎么用?Python einsum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了einsum函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: call

 def call(self, inputs, states):
   prev_output = states[0]
   h = special_math_ops.einsum('bij,ijkl->bkl', inputs, self.kernel)
   h += array_ops.expand_dims(self.bias, axis=0)
   output = h + special_math_ops.einsum('bij,ijkl->bkl', prev_output,
                                        self.recurring_kernel)
   return output, [output]
开发者ID:ZhangXinNan,项目名称:tensorflow,代码行数:7,代码来源:recurrent_test.py


示例2: test_input_is_placeholder

  def test_input_is_placeholder(self):
    with ops.Graph().as_default():
      m0 = array_ops.placeholder(dtypes.int32, shape=(1, None))
      m1 = array_ops.placeholder(dtypes.int32, shape=(None, 1))
      out = special_math_ops.einsum('ij,jk->ik', m0, m1)
      with session.Session() as sess:
        feed_dict = {
            m0: [[1, 2, 3]],
            m1: [[2], [1], [1]],
        }
        np.testing.assert_almost_equal(
            [[7]], sess.run(out, feed_dict=feed_dict))

    with ops.Graph().as_default():
      m0 = array_ops.placeholder(dtypes.int32, shape=(None, 3))
      m1 = array_ops.placeholder(dtypes.int32, shape=(3,))
      out = special_math_ops.einsum('ij,j->i', m0, m1)
      with session.Session() as sess:
        feed_dict = {
            m0: [[1, 2, 3]],
            m1: [2, 1, 1],
        }
        np.testing.assert_almost_equal([7], sess.run(out, feed_dict=feed_dict))

    # Tests for placeholders which have two or more None values
    with ops.Graph().as_default():
      m0 = array_ops.placeholder(dtypes.int32, shape=(None, None, 2))
      m1 = array_ops.placeholder(dtypes.int32, shape=(2, 1))
      out = special_math_ops.einsum('ijk,kl->ijl', m0, m1)
      with session.Session() as sess:
        feed_dict = {
            m0: [[[1,2]]],
            m1: [[3], [2]],
        }
        np.testing.assert_almost_equal(
            [[[7]]], sess.run(out, feed_dict=feed_dict))

    with ops.Graph().as_default():
      m0 = array_ops.placeholder(dtypes.int32, shape=(2, 1))
      m1 = array_ops.placeholder(dtypes.int32, shape=(None, None, 2))
      out = special_math_ops.einsum('kl,ijk->ijl', m0, m1)
      with session.Session() as sess:
        feed_dict = {
            m0: [[3], [2]],
            m1: [[[1,2]]],
        }
        np.testing.assert_almost_equal(
            [[[7]]], sess.run(out, feed_dict=feed_dict))

    with ops.Graph().as_default():
      m0 = array_ops.placeholder(dtypes.int32, shape=(None, None, 2))
      m1 = array_ops.placeholder(dtypes.int32, shape=(2,))
      out = special_math_ops.einsum('ijk,k->ij', m0, m1)
      with session.Session() as sess:
        feed_dict = {
            m0: [[[1, 2]]],
            m1: [3, 2],
        }
        np.testing.assert_almost_equal(
            [[7]], sess.run(out, feed_dict=feed_dict))
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:60,代码来源:special_math_ops_test.py


示例3: _convdiag_sum_of_squares

 def _convdiag_sum_of_squares(self, patches, outputs_grad):
   # This computes the sum of the squares of the per-training-case "gradients".
   # It does this simply by computing a giant tensor containing all of these,
   # doing an entry-wise square, and them summing along the batch dimension.
   case_wise_gradients = special_math_ops.einsum("bijk,bijl->bkl", patches,
                                                 outputs_grad)
   return math_ops.reduce_sum(math_ops.square(case_wise_gradients), axis=0)
开发者ID:alexsax,项目名称:tensorflow,代码行数:7,代码来源:fisher_factors.py


示例4: test_invalid_keyword_arguments

 def test_invalid_keyword_arguments(self):
   m0 = array_ops.placeholder(dtypes.int32, shape=(1, None))
   m1 = array_ops.placeholder(dtypes.int32, shape=(None, 1))
   with self.assertRaisesRegexp(TypeError,
       'invalid keyword arguments for this function: invalid1, invalid2'):
     _ = special_math_ops.einsum('ij,jk->ik', m0, m1, name="name",
                                 invalid1="value1", invalid2="value2")
开发者ID:Lin-jipeng,项目名称:tensorflow,代码行数:7,代码来源:special_math_ops_test.py


示例5: run_test

  def run_test(self, axes, expanded_axes=None):
    expanded_axes = expanded_axes if expanded_axes is not None else axes
    all_axes = {ax: np.random.randint(4, 12)
                for ax in expanded_axes if ax.isalpha()}

    input_vals = []
    input_axes, _, _ = axes.partition('->')

    for idx in input_axes.split(','):
      shape = [all_axes[ax] for ax in idx if ax.isalpha()]
      input_vals.append(np.random.random(shape))

    input_tensors = [constant_op.constant(val) for val in input_vals]
    output_tensor = special_math_ops.einsum(axes, *input_tensors)

    with self.session(use_gpu=True):
      output_value = self.evaluate(output_tensor)

    correct_value = 0
    if axes == 'ijji':
      output = math_ops.trace(*input_tensors)
      correct_value = self.evaluate(output)
    else:
      correct_value = np.einsum(axes, *input_vals)
    err = np.abs(correct_value - output_value).max()
    self.assertLess(err, 1e-8)
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:26,代码来源:special_math_ops_test.py


示例6: test_dim_mismatch

 def test_dim_mismatch(self):
   for axes, input_shapes in self.dim_mismatch_cases:
     inputs = [
         array_ops.placeholder(dtypes.float32, shape=shape)
         for shape in input_shapes
     ]
     with self.assertRaises(ValueError):
       _ = special_math_ops.einsum(axes, *inputs)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:8,代码来源:special_math_ops_test.py


示例7: test_invalid

 def test_invalid(self):
   for axes in self.invalid_cases:
     inputs = [
         array_ops.placeholder(dtypes.float32, shape=(3, 4)),
         array_ops.placeholder(dtypes.float32, shape=(3, 4)),
     ]
     with self.assertRaises(ValueError):
       _ = special_math_ops.einsum(axes, *inputs)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:8,代码来源:special_math_ops_test.py


示例8: test_input_is_placeholder

  def test_input_is_placeholder(self):
    with ops.Graph().as_default():
      m0 = array_ops.placeholder(dtypes.int32, shape=(1, None))
      m1 = array_ops.placeholder(dtypes.int32, shape=(None, 1))
      out = special_math_ops.einsum('ij,jk->ik', m0, m1)
      with session.Session() as sess:
        feed_dict = {
            m0: [[1, 2, 3]],
            m1: [[2], [1], [1]],
        }
        np.testing.assert_almost_equal(
            [[7]], sess.run(out, feed_dict=feed_dict))

    with ops.Graph().as_default():
      m0 = array_ops.placeholder(dtypes.int32, shape=(None, 3))
      m1 = array_ops.placeholder(dtypes.int32, shape=(3,))
      out = special_math_ops.einsum('ij,j->i', m0, m1)
      with session.Session() as sess:
        feed_dict = {
            m0: [[1, 2, 3]],
            m1: [2, 1, 1],
        }
        np.testing.assert_almost_equal([7], sess.run(out, feed_dict=feed_dict))
开发者ID:Y-owen,项目名称:tensorflow,代码行数:23,代码来源:special_math_ops_test.py


示例9: call

  def call(self, inputs, states):
    # inputs should be in [(batch, input_1), (batch, input_2, input_3)]
    # state should be in shape [(batch, unit_1), (batch, unit_2, unit_3)]
    flatten_inputs = nest.flatten(inputs)
    s1, s2 = states

    output_1 = math_ops.matmul(flatten_inputs[0], self.kernel_1)
    output_2_3 = special_math_ops.einsum('bij,ijkl->bkl', flatten_inputs[1],
                                         self.kernel_2_3)
    state_1 = s1 + output_1
    state_2_3 = s2 + output_2_3

    output = [output_1, output_2_3]
    new_states = NestedState(s1=state_1, s2=state_2_3)

    return output, new_states
开发者ID:becster,项目名称:tensorflow,代码行数:16,代码来源:recurrent_test.py


示例10: run_test

  def run_test(self, axes):
    all_axes = {ax: np.random.randint(4, 12) for ax in axes if ax.isalpha()}

    input_vals = []
    input_axes, _, _ = axes.partition('->')

    for idx in input_axes.split(','):
      shape = [all_axes[ax] for ax in idx]
      input_vals.append(np.random.random(shape))

    input_tensors = [constant_op.constant(val) for val in input_vals]
    output_tensor = special_math_ops.einsum(axes, *input_tensors)

    with self.test_session(use_gpu=True):
      output_value = output_tensor.eval()

    correct_value = np.einsum(axes, *input_vals)

    err = np.abs(correct_value - output_value).max()
    print(axes, err)
    assert err < 1e-8
开发者ID:ChengYuXiang,项目名称:tensorflow,代码行数:21,代码来源:special_math_ops_test.py


示例11: test_repeated_axis_single_input

 def test_repeated_axis_single_input(self):
   x = array_ops.placeholder(dtypes.float32, shape=[2, 2])
   with self.assertRaises(ValueError):
     _ = special_math_ops.einsum('ii->', x)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:4,代码来源:special_math_ops_test.py


示例12: test_ellipses_with_unknown_input_dim

 def test_ellipses_with_unknown_input_dim(self):
   with ops.Graph().as_default():
     m0 = array_ops.placeholder(dtypes.float32)
     m1 = array_ops.placeholder_with_default([[3, 2]], shape=(None, 2))
     with self.assertRaises(ValueError):
       _ = special_math_ops.einsum('...jkl,...j->...kl', m0, m1)
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:6,代码来源:special_math_ops_test.py


示例13: test_multiple_ellipses

 def test_multiple_ellipses(self):
   m0 = array_ops.placeholder_with_default([[[[1, 2]], [[2, 1]]]],
                                           shape=(None, 2, None, 2))
   m1 = array_ops.placeholder_with_default([[3, 2]], shape=(None, 2))
   out = special_math_ops.einsum('...jkl,...j->...kl', m0, m1)
   self.assertAllClose([[[7, 8]]], self.evaluate(out))
开发者ID:adit-chandra,项目名称:tensorflow,代码行数:6,代码来源:special_math_ops_test.py



注:本文中的tensorflow.python.ops.special_math_ops.einsum函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python special_math_ops.lbeta函数代码示例发布时间:2022-05-27
下一篇:
Python sparse_ops.sparse_to_indicator函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap