当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.complex128方法代码示例

本文整理汇总了Python中tensorflow.complex128方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.complex128方法的具体用法?Python tensorflow.complex128怎么用?Python tensorflow.complex128使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow的用法示例。


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

示例1: call

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def call(self, inputx):
        
        if not inputx.dtype in [tf.complex64, tf.complex128]:
            print('Warning: inputx is not complex. Converting.', file=sys.stderr)
        
            # if inputx is float, this will assume 0 imag channel
            inputx = tf.cast(inputx, tf.complex64)

        # get the right fft
        if self.ndims == 1:
            fft = tf.fft
        elif self.ndims == 2:
            fft = tf.fft2d
        else:
            fft = tf.fft3d

        perm_dims = [0, self.ndims + 1] + list(range(1, self.ndims + 1))
        invert_perm_ndims = [0] + list(range(2, self.ndims + 2)) + [1]
        
        perm_inputx = K.permute_dimensions(inputx, perm_dims)  # [batch_size, nb_features, *vol_size]
        fft_inputx = fft(perm_inputx)
        return K.permute_dimensions(fft_inputx, invert_perm_ndims) 
开发者ID:adalca,项目名称:neuron,代码行数:24,代码来源:layers.py

示例2: _compareBCast

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def _compareBCast(self, xs, ys, dtype, np_func, tf_func):
    if dtype in (np.complex64, np.complex128):
      x = (1 + np.linspace(0, 2 + 3j, np.prod(xs))).astype(dtype).reshape(xs)
      y = (1 + np.linspace(0, 2 - 2j, np.prod(ys))).astype(dtype).reshape(ys)
    else:
      x = (1 + np.linspace(0, 5, np.prod(xs))).astype(dtype).reshape(xs)
      y = (1 + np.linspace(0, 5, np.prod(ys))).astype(dtype).reshape(ys)
    self._compareCpu(x, y, np_func, tf_func)
    if x.dtype in (np.float16, np.float32, np.float64, np.complex64,
                   np.complex128):
      if tf_func not in (_FLOORDIV, tf.floordiv):
        if x.dtype == np.float16:
          # Compare fp16 theoretical gradients to fp32 numerical gradients,
          # since fp16 numerical gradients are too imprecise unless great
          # care is taken with choosing the inputs and the delta. This is
          # a weaker check (in particular, it does not test the op itself,
          # only its gradient), but it's much better than nothing.
          self._compareGradientX(x, y, np_func, tf_func, np.float)
          self._compareGradientY(x, y, np_func, tf_func, np.float)
        else:
          self._compareGradientX(x, y, np_func, tf_func)
          self._compareGradientY(x, y, np_func, tf_func)
      self._compareGpu(x, y, np_func, tf_func)

  # TODO(josh11b,vrv): Refactor this to use parameterized tests. 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:cwise_ops_test.py

示例3: _testBCastByFunc

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def _testBCastByFunc(self, funcs, xs, ys):
    dtypes = [
        np.float16,
        np.float32,
        np.float64,
        np.int32,
        np.int64,
        np.complex64,
        np.complex128,
    ]
    for dtype in dtypes:
      for (np_func, tf_func) in funcs:
        if (dtype in (np.complex64, np.complex128) and
              tf_func in (_FLOORDIV, tf.floordiv)):
          continue  # floordiv makes no sense for complex numbers
        self._compareBCast(xs, ys, dtype, np_func, tf_func)
        self._compareBCast(ys, xs, dtype, np_func, tf_func) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:cwise_ops_test.py

示例4: testTensorCompareTensor

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def testTensorCompareTensor(self):
    x = np.linspace(-15, 15, 6).reshape(1, 3, 2)
    y = np.linspace(20, -10, 6).reshape(1, 3, 2)
    for t in [np.float16, np.float32, np.float64, np.int32, np.int64]:
      xt = x.astype(t)
      yt = y.astype(t)
      self._compareBoth(xt, yt, np.less, tf.less)
      self._compareBoth(xt, yt, np.less_equal, tf.less_equal)
      self._compareBoth(xt, yt, np.greater, tf.greater)
      self._compareBoth(xt, yt, np.greater_equal, tf.greater_equal)
      self._compareBoth(xt, yt, np.equal, tf.equal)
      self._compareBoth(xt, yt, np.not_equal, tf.not_equal)
    # TODO(zhifengc): complex64 doesn't work on GPU yet.
    for t in [np.complex64, np.complex128]:
      self._compareCpu(x.astype(t), y.astype(t), np.equal, tf.equal)
      self._compareCpu(x.astype(t), y.astype(t), np.not_equal, tf.not_equal) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:cwise_ops_test.py

示例5: _toDataType

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def _toDataType(self, dtype):
    """Returns TensorFlow data type for numpy type."""
    if dtype == np.float32:
      return tf.float32
    elif dtype == np.float64:
      return tf.float64
    elif dtype == np.int32:
      return tf.int32
    elif dtype == np.int64:
      return tf.int64
    elif dtype == np.bool:
      return tf.bool
    elif dtype == np.complex64:
      return tf.complex64
    elif dtype == np.complex128:
      return tf.complex128
    else:
      return None 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:20,代码来源:cast_op_test.py

示例6: _testTypes

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def _testTypes(self, x, use_gpu=False):
    """Tests cast(x) to different tf."""
    if use_gpu:
      type_list = [np.float32, np.float64, np.int64,
                   np.complex64, np.complex128]
    else:
      type_list = [np.float32, np.float64, np.int32,
                   np.int64, np.complex64, np.complex128]
    for from_type in type_list:
      for to_type in type_list:
        self._test(x.astype(from_type), to_type, use_gpu)

    self._test(x.astype(np.bool), np.float32, use_gpu)
    self._test(x.astype(np.uint8), np.float32, use_gpu)
    if not use_gpu:
      self._test(x.astype(np.bool), np.int32, use_gpu)
      self._test(x.astype(np.int32), np.int32, use_gpu) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:cast_op_test.py

示例7: testDtype

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def testDtype(self):
    with self.test_session():
      d = tf.fill([2, 3], 12., name="fill")
      self.assertEqual(d.get_shape(), [2, 3])
      # Test default type for both constant size and dynamic size
      z = tf.zeros([2, 3])
      self.assertEqual(z.dtype, tf.float32)
      self.assertEqual([2, 3], z.get_shape())
      self.assertAllEqual(z.eval(), np.zeros([2, 3]))
      z = tf.zeros(tf.shape(d))
      self.assertEqual(z.dtype, tf.float32)
      self.assertEqual([2, 3], z.get_shape())
      self.assertAllEqual(z.eval(), np.zeros([2, 3]))
      # Test explicit type control
      for dtype in [tf.float32, tf.float64, tf.int32,
                    tf.uint8, tf.int16, tf.int8,
                    tf.complex64, tf.complex128, tf.int64, tf.bool]:
        z = tf.zeros([2, 3], dtype=dtype)
        self.assertEqual(z.dtype, dtype)
        self.assertEqual([2, 3], z.get_shape())
        self.assertAllEqual(z.eval(), np.zeros([2, 3]))
        z = tf.zeros(tf.shape(d), dtype=dtype)
        self.assertEqual(z.dtype, dtype)
        self.assertEqual([2, 3], z.get_shape())
        self.assertAllEqual(z.eval(), np.zeros([2, 3])) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:constant_op_test.py

示例8: testValues

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def testValues(self):
    dtypes = [tf.float32,
              tf.float64,
              tf.int64,
              tf.int32,
              tf.complex64,
              tf.complex128]
    indices_flat = np.array([0, 4, 0, 8, 3, 8, 4, 7, 7, 3])
    num_segments = 12
    for indices in indices_flat, indices_flat.reshape(5, 2):
      shape = indices.shape + (2,)
      for dtype in dtypes:
        with self.test_session(use_gpu=self.use_gpu):
          tf_x, np_x = self._input(shape, dtype=dtype)
          np_ans = self._segmentReduce(indices,
                                       np_x,
                                       np.add,
                                       op2=None,
                                       num_out_rows=num_segments)
          s = tf.unsorted_segment_sum(data=tf_x,
                                      segment_ids=indices,
                                      num_segments=num_segments)
          tf_ans = s.eval()
        self._assertAllClose(indices, np_ans, tf_ans)
        self.assertShapeEqual(np_ans, s) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:segment_reduction_ops_test.py

示例9: _testGrad

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def _testGrad(self, shape, dtype=None, max_error=None, bias=None, sigma=None):
    np.random.seed(7)
    if dtype in (tf.complex64, tf.complex128):
      value = tf.complex(self._biasedRandN(shape, bias=bias, sigma=sigma),
                         self._biasedRandN(shape, bias=bias, sigma=sigma))
    else:
      value = tf.convert_to_tensor(self._biasedRandN(shape, bias=bias),
                                   dtype=dtype)

    with self.test_session(use_gpu=True):
      if dtype in (tf.complex64, tf.complex128):
        output = tf.complex_abs(value)
      else:
        output = tf.abs(value)
      error = tf.test.compute_gradient_error(
          value, shape, output, output.get_shape().as_list())
    self.assertLess(error, max_error) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:math_grad_test.py

示例10: testComplex128N

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def testComplex128N(self):
    t = tensor_util.make_tensor_proto([(1+2j), (3+4j), (5+6j)], shape=[1, 3],
                                      dtype=tf.complex128)
    self.assertProtoEquals("""
      dtype: DT_COMPLEX128
      tensor_shape { dim { size: 1 } dim { size: 3 } }
      dcomplex_val: 1
      dcomplex_val: 2
      dcomplex_val: 3
      dcomplex_val: 4
      dcomplex_val: 5
      dcomplex_val: 6
      """, t)
    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.complex128, a.dtype)
    self.assertAllEqual(np.array([[(1+2j), (3+4j), (5+6j)]]), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:tensor_util_test.py

示例11: testComplex128NpArray

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def testComplex128NpArray(self):
    t = tensor_util.make_tensor_proto(
        np.array([[(1+2j), (3+4j)], [(5+6j), (7+8j)]]), dtype=tf.complex128)
    # scomplex_val are real_0, imag_0, real_1, imag_1, ...
    self.assertProtoEquals("""
      dtype: DT_COMPLEX128
      tensor_shape { dim { size: 2 } dim { size: 2 } }
      dcomplex_val: 1
      dcomplex_val: 2
      dcomplex_val: 3
      dcomplex_val: 4
      dcomplex_val: 5
      dcomplex_val: 6
      dcomplex_val: 7
      dcomplex_val: 8
      """, t)
    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.complex128, a.dtype)
    self.assertAllEqual(np.array([[(1+2j), (3+4j)], [(5+6j), (7+8j)]]), a) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:tensor_util_test.py

示例12: channels_to_complex

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def channels_to_complex(image,
                        data_format='channels_last',
                        name='channels2complex'):
    """Convert data from channels to complex."""
    if len(image.shape) != 3 and len(image.shape) != 4:
        raise TypeError('Input data must be have 3 or 4 dimensions')

    axis_c = -1 if data_format == 'channels_last' else -3
    shape_c = image.shape[axis_c].value

    if shape_c and (shape_c % 2 != 0):
        raise TypeError(
            'Number of channels (%d) must be divisible by 2' % shape_c)
    if image.dtype is tf.complex64 or image.dtype is tf.complex128:
        raise TypeError('Input data cannot be complex')

    with tf.name_scope(name):
        image_real, image_imag = tf.split(image, 2, axis=axis_c)
        image_out = tf.complex(image_real, image_imag)
    return image_out 
开发者ID:MRSRL,项目名称:dl-cs,代码行数:22,代码来源:tfmri.py

示例13: args_check

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def args_check(cls, node, **kwargs):
    supported_dtype = [
        tf.bfloat16, tf.half, tf.float32, tf.float64, tf.uint8, tf.uint16,
        tf.int8, tf.int16, tf.int32, tf.int64, tf.complex64, tf.complex128
    ]
    x = kwargs["tensor_dict"][node.inputs[0]]
    if x.dtype not in supported_dtype:
      exception.OP_UNSUPPORTED_EXCEPT(
          "CumSum input in " + str(x.dtype) + " which", "Tensorflow") 
开发者ID:onnx,项目名称:onnx-tensorflow,代码行数:11,代码来源:cumsum.py

示例14: args_check

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def args_check(cls, node, **kwargs):
    supported_dtype = [
        tf.bfloat16, tf.half, tf.float32, tf.float64, tf.uint8, tf.int8,
        tf.int16, tf.int32, tf.int64, tf.complex64, tf.quint8, tf.qint8,
        tf.qint32, tf.string, tf.bool, tf.complex128
    ]
    x = kwargs["tensor_dict"][node.inputs[0]]
    if x.dtype not in supported_dtype:
      exception.OP_UNSUPPORTED_EXCEPT(
          "Equal inputs in " + str(x.dtype) + " which", "Tensorflow") 
开发者ID:onnx,项目名称:onnx-tensorflow,代码行数:12,代码来源:equal.py

示例15: test_cast

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import complex128 [as 别名]
def test_cast(self):
    if legacy_onnx_pre_ver(1, 2) or legacy_opset_pre_ver(6):
      test_cases = [("FLOAT", tf.float32), ("UINT8", tf.uint8),
                    ("INT8", tf.int8),
                    ("UINT16", tf.uint16), ("INT16", tf.int16),
                    ("INT32", tf.int32), ("INT64", tf.int64), ("BOOL", tf.bool),
                    ("FLOAT16", tf.float16), ("DOUBLE", tf.float64),
                    ("COMPLEX64", tf.complex64), ("COMPLEX128", tf.complex128)]
    else:
      test_cases = [(TensorProto.FLOAT, tf.float32),
                    (TensorProto.UINT8, tf.uint8), (TensorProto.INT8, tf.int8),
                    (TensorProto.UINT16, tf.uint16),
                    (TensorProto.INT16, tf.int16),
                    (TensorProto.INT32, tf.int32),
                    (TensorProto.INT64, tf.int64), (TensorProto.BOOL, tf.bool),
                    (TensorProto.FLOAT16, tf.float16),
                    (TensorProto.DOUBLE, tf.float64),
                    (TensorProto.COMPLEX64, tf.complex64),
                    (TensorProto.COMPLEX128, tf.complex128)]
      if not legacy_opset_pre_ver(9):
        test_cases.append((TensorProto.STRING, tf.string))
    for ty, tf_type in test_cases:
      node_def = helper.make_node("Cast", ["input"], ["output"], to=ty)
      vector = [2, 3]
      output = run_node(node_def, [vector])
      np.testing.assert_equal(output["output"].dtype, tf_type)

    if not legacy_opset_pre_ver(9):
      test_cases2 = [(TensorProto.FLOAT, tf.float32),
                     (TensorProto.INT32, tf.int32),
                     (TensorProto.INT64, tf.int64),
                     (TensorProto.DOUBLE, tf.float64)]
      for ty, tf_type in test_cases2:
        node_def = helper.make_node("Cast", ["input"], ["output"], to=ty)
        vector = ['2', '3']
        output = run_node(node_def, [vector])
        np.testing.assert_equal(output["output"].dtype, tf_type) 
开发者ID:onnx,项目名称:onnx-tensorflow,代码行数:39,代码来源:test_node.py


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