Python tensorflow.complex128() Examples

The following are 30 code examples of tensorflow.complex128(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tensorflow , or try the search function .
Example #1
Source File: constant_op_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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])) 
Example #2
Source File: tensor_util_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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) 
Example #3
Source File: tensor_util_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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) 
Example #4
Source File: math_grad_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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) 
Example #5
Source File: cwise_ops_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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) 
Example #6
Source File: segment_reduction_ops_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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) 
Example #7
Source File: cwise_ops_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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) 
Example #8
Source File: cwise_ops_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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. 
Example #9
Source File: cast_op_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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 
Example #10
Source File: tfmri.py    From dl-cs with MIT License 6 votes vote down vote up
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 
Example #11
Source File: cast_op_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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) 
Example #12
Source File: constant_op_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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.ones([2, 3])
      self.assertEqual(z.dtype, tf.float32)
      self.assertEqual([2, 3], z.get_shape())
      self.assertAllEqual(z.eval(), np.ones([2, 3]))
      z = tf.ones(tf.shape(d))
      self.assertEqual(z.dtype, tf.float32)
      self.assertEqual([2, 3], z.get_shape())
      self.assertAllEqual(z.eval(), np.ones([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.ones([2, 3], dtype=dtype)
        self.assertEqual(z.dtype, dtype)
        self.assertEqual([2, 3], z.get_shape())
        self.assertAllEqual(z.eval(), np.ones([2, 3]))
        z = tf.ones(tf.shape(d), dtype=dtype)
        self.assertEqual(z.dtype, dtype)
        self.assertEqual([2, 3], z.get_shape())
        self.assertAllEqual(z.eval(), np.ones([2, 3])) 
Example #13
Source File: layers.py    From neuron with GNU General Public License v3.0 6 votes vote down vote up
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:
            ifft = tf.ifft
        elif self.ndims == 2:
            ifft = tf.ifft2d
        else:
            ifft = tf.ifft3d

        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]
        ifft_inputx = ifft(perm_inputx)
        return K.permute_dimensions(ifft_inputx, invert_perm_ndims) 
Example #14
Source File: layers.py    From neuron with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #15
Source File: fifo_queue_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testDtypes(self):
    with self.test_session() as sess:
      dtypes = [tf.float32, tf.float64, tf.int32, tf.uint8, tf.int16, tf.int8,
                tf.int64, tf.bool, tf.complex64, tf.complex128]
      shape = (32, 4, 128)
      q = tf.FIFOQueue(32, dtypes, [shape[1:]] * len(dtypes))

      input_tuple = []
      for dtype in dtypes:
        np_dtype = dtype.as_numpy_dtype
        np_array = np.random.randint(-10, 10, shape)
        if dtype == tf.bool:
          np_array = np_array > 0
        elif dtype in (tf.complex64, tf.complex128):
          np_array = np.sqrt(np_array.astype(np_dtype))
        else:
          np_array = np_array.astype(np_dtype)
        input_tuple.append(np_array)

      q.enqueue_many(input_tuple).run()

      output_tuple_t = q.dequeue_many(32)
      output_tuple = sess.run(output_tuple_t)

      for (input_elem, output_elem) in zip(input_tuple, output_tuple):
        self.assertAllEqual(input_elem, output_elem) 
Example #16
Source File: segment_reduction_ops_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testValues(self):
    dtypes = [tf.float32,
              tf.float64,
              tf.int64,
              tf.int32,
              tf.complex64,
              tf.complex128]

    # Each item is np_op1, np_op2, tf_op
    ops_list = [(np.add, None, tf.segment_sum),
                (self._mean_cum_op, self._mean_reduce_op,
                 tf.segment_mean),
                (np.ndarray.__mul__, None, tf.segment_prod),
                (np.minimum, None, tf.segment_min),
                (np.maximum, None, tf.segment_max)]

    # A subset of ops has been enabled for complex numbers
    complex_ops_list = [(np.add, None, tf.segment_sum),
                        (np.ndarray.__mul__, None, tf.segment_prod)]

    n = 10
    shape = [n, 2]
    indices = [i // 3 for i in range(n)]
    for dtype in dtypes:
      if dtype in (tf.complex64, tf.complex128):
        curr_ops_list = complex_ops_list
      else:
        curr_ops_list = ops_list

      with self.test_session(use_gpu=False):
        tf_x, np_x = self._input(shape, dtype=dtype)
        for np_op1, np_op2, tf_op in curr_ops_list:
          np_ans = self._segmentReduce(indices, np_x, np_op1, np_op2)
          s = tf_op(data=tf_x, segment_ids=indices)
          tf_ans = s.eval()
          self._assertAllClose(indices, np_ans, tf_ans)
          # NOTE(mrry): The static shape inference that computes
          # `tf_ans.shape` can only infer that sizes from dimension 1
          # onwards, because the size of dimension 0 is data-dependent
          # and may therefore vary dynamically.
          self.assertAllEqual(np_ans.shape[1:], tf_ans.shape[1:]) 
Example #17
Source File: constant_op_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testFillComplex128(self):
    np_ans = np.array([[0.15] * 3] * 2).astype(np.complex128)
    self._compare([2, 3], np_ans[0][0], np_ans, use_gpu=False) 
Example #18
Source File: segment_reduction_ops_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testEmptySecondDimension(self):
    dtypes = [np.float32,
              np.float64,
              np.int64,
              np.int32,
              np.complex64,
              np.complex128]
    with self.test_session(use_gpu=self.use_gpu):
      for dtype in dtypes:
        for itype in (np.int32, np.int64):
          data = np.zeros((2, 0), dtype=dtype)
          segment_ids = np.array([0, 1], dtype=itype)
          unsorted = tf.unsorted_segment_sum(data, segment_ids, 2)
          self.assertAllEqual(unsorted.eval(), np.zeros((2, 0), dtype=dtype)) 
Example #19
Source File: tensor_util_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testComplex128(self):
    t = tensor_util.make_tensor_proto((1+2j), dtype=tf.complex128)
    self.assertProtoEquals("""
      dtype: DT_COMPLEX128
      tensor_shape {}
      dcomplex_val: 1
      dcomplex_val: 2
      """, t)
    a = tensor_util.MakeNdarray(t)
    self.assertEquals(np.complex128, a.dtype)
    self.assertAllEqual(np.array(1 + 2j), a) 
Example #20
Source File: constant_op_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testZerosLikeCPU(self):
    for dtype in [tf.float32, tf.float64, tf.int32, tf.uint8, tf.int16, tf.int8,
                  tf.complex64, tf.complex128, tf.int64]:
      self._compareZeros(dtype, False) 
Example #21
Source File: dtypes_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testStringConversion(self):
    self.assertIs(tf.float32, tf.as_dtype("float32"))
    self.assertIs(tf.float64, tf.as_dtype("float64"))
    self.assertIs(tf.int32, tf.as_dtype("int32"))
    self.assertIs(tf.uint8, tf.as_dtype("uint8"))
    self.assertIs(tf.uint16, tf.as_dtype("uint16"))
    self.assertIs(tf.int16, tf.as_dtype("int16"))
    self.assertIs(tf.int8, tf.as_dtype("int8"))
    self.assertIs(tf.string, tf.as_dtype("string"))
    self.assertIs(tf.complex64, tf.as_dtype("complex64"))
    self.assertIs(tf.complex128, tf.as_dtype("complex128"))
    self.assertIs(tf.int64, tf.as_dtype("int64"))
    self.assertIs(tf.bool, tf.as_dtype("bool"))
    self.assertIs(tf.qint8, tf.as_dtype("qint8"))
    self.assertIs(tf.quint8, tf.as_dtype("quint8"))
    self.assertIs(tf.qint32, tf.as_dtype("qint32"))
    self.assertIs(tf.bfloat16, tf.as_dtype("bfloat16"))
    self.assertIs(tf.float32_ref, tf.as_dtype("float32_ref"))
    self.assertIs(tf.float64_ref, tf.as_dtype("float64_ref"))
    self.assertIs(tf.int32_ref, tf.as_dtype("int32_ref"))
    self.assertIs(tf.uint8_ref, tf.as_dtype("uint8_ref"))
    self.assertIs(tf.int16_ref, tf.as_dtype("int16_ref"))
    self.assertIs(tf.int8_ref, tf.as_dtype("int8_ref"))
    self.assertIs(tf.string_ref, tf.as_dtype("string_ref"))
    self.assertIs(tf.complex64_ref, tf.as_dtype("complex64_ref"))
    self.assertIs(tf.complex128_ref, tf.as_dtype("complex128_ref"))
    self.assertIs(tf.int64_ref, tf.as_dtype("int64_ref"))
    self.assertIs(tf.bool_ref, tf.as_dtype("bool_ref"))
    self.assertIs(tf.qint8_ref, tf.as_dtype("qint8_ref"))
    self.assertIs(tf.quint8_ref, tf.as_dtype("quint8_ref"))
    self.assertIs(tf.qint32_ref, tf.as_dtype("qint32_ref"))
    self.assertIs(tf.bfloat16_ref, tf.as_dtype("bfloat16_ref"))
    with self.assertRaises(TypeError):
      tf.as_dtype("not_a_type") 
Example #22
Source File: tensor_util_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testComplexWithImplicitRepeat(self):
    for dtype, np_dtype in [(tf.complex64, np.complex64),
                            (tf.complex128, np.complex128)]:
      t = tensor_util.make_tensor_proto((1+1j), shape=[3, 4],
                                        dtype=dtype)
      a = tensor_util.MakeNdarray(t)
      self.assertAllClose(np.array([[(1+1j), (1+1j), (1+1j), (1+1j)],
                                    [(1+1j), (1+1j), (1+1j), (1+1j)],
                                    [(1+1j), (1+1j), (1+1j), (1+1j)]],
                                   dtype=np_dtype), a) 
Example #23
Source File: dtypes_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testRealDtype(self):
    for dtype in [tf.float32, tf.float64, tf.bool, tf.uint8, tf.int8, tf.int16,
                  tf.int32, tf.int64]:
      self.assertIs(dtype.real_dtype, dtype)
    self.assertIs(tf.complex64.real_dtype, tf.float32)
    self.assertIs(tf.complex128.real_dtype, tf.float64) 
Example #24
Source File: cast_op_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testGradients(self):
    t = [tf.float32, tf.float64, tf.complex64, tf.complex128]
    for src_t in t:
      for dst_t in t:
        with self.test_session():
          x = tf.constant(1.0, src_t)
          z = tf.identity(x)
          y = tf.cast(z, dst_t)
          err = tf.test.compute_gradient_error(x, [], y, [])
          self.assertLess(err, 1e-3) 
Example #25
Source File: dtypes_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testIsInteger(self):
    self.assertEqual(tf.as_dtype("int8").is_integer, True)
    self.assertEqual(tf.as_dtype("int16").is_integer, True)
    self.assertEqual(tf.as_dtype("int32").is_integer, True)
    self.assertEqual(tf.as_dtype("int64").is_integer, True)
    self.assertEqual(tf.as_dtype("uint8").is_integer, True)
    self.assertEqual(tf.as_dtype("uint16").is_integer, True)
    self.assertEqual(tf.as_dtype("complex64").is_integer, False)
    self.assertEqual(tf.as_dtype("complex128").is_integer, False)
    self.assertEqual(tf.as_dtype("float").is_integer, False)
    self.assertEqual(tf.as_dtype("double").is_integer, False)
    self.assertEqual(tf.as_dtype("string").is_integer, False)
    self.assertEqual(tf.as_dtype("bool").is_integer, False)
    self.assertEqual(tf.as_dtype("bfloat16").is_integer, False) 
Example #26
Source File: dtypes_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testIsFloating(self):
    self.assertEqual(tf.as_dtype("int8").is_floating, False)
    self.assertEqual(tf.as_dtype("int16").is_floating, False)
    self.assertEqual(tf.as_dtype("int32").is_floating, False)
    self.assertEqual(tf.as_dtype("int64").is_floating, False)
    self.assertEqual(tf.as_dtype("uint8").is_floating, False)
    self.assertEqual(tf.as_dtype("uint16").is_floating, False)
    self.assertEqual(tf.as_dtype("complex64").is_floating, False)
    self.assertEqual(tf.as_dtype("complex128").is_floating, False)
    self.assertEqual(tf.as_dtype("float32").is_floating, True)
    self.assertEqual(tf.as_dtype("float64").is_floating, True)
    self.assertEqual(tf.as_dtype("string").is_floating, False)
    self.assertEqual(tf.as_dtype("bool").is_floating, False)
    self.assertEqual(tf.as_dtype("bfloat16").is_integer, False) 
Example #27
Source File: dtypes_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testIsComplex(self):
    self.assertEqual(tf.as_dtype("int8").is_complex, False)
    self.assertEqual(tf.as_dtype("int16").is_complex, False)
    self.assertEqual(tf.as_dtype("int32").is_complex, False)
    self.assertEqual(tf.as_dtype("int64").is_complex, False)
    self.assertEqual(tf.as_dtype("uint8").is_complex, False)
    self.assertEqual(tf.as_dtype("uint16").is_complex, False)
    self.assertEqual(tf.as_dtype("complex64").is_complex, True)
    self.assertEqual(tf.as_dtype("complex128").is_complex, True)
    self.assertEqual(tf.as_dtype("float32").is_complex, False)
    self.assertEqual(tf.as_dtype("float64").is_complex, False)
    self.assertEqual(tf.as_dtype("string").is_complex, False)
    self.assertEqual(tf.as_dtype("bool").is_complex, False)
    self.assertEqual(tf.as_dtype("bfloat16").is_integer, False) 
Example #28
Source File: odes_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def test_odeint_all_dtypes(self):
    func = lambda y, t: y
    t = np.linspace(0.0, 1.0, 11)
    for y0_dtype in [tf.float32, tf.float64, tf.complex64, tf.complex128]:
      for t_dtype in [tf.float32, tf.float64]:
        y0 = tf.cast(1.0, y0_dtype)
        y_solved = tf.contrib.integrate.odeint(func, y0, tf.cast(t, t_dtype))
        with self.test_session() as sess:
          y_solved = sess.run(y_solved)
        expected = np.asarray(np.exp(t))
        self.assertAllClose(y_solved, expected, rtol=1e-5)
        self.assertEqual(tf.as_dtype(y_solved.dtype), y0_dtype) 
Example #29
Source File: tfmri.py    From dl-cs with MIT License 5 votes vote down vote up
def complex_to_channels(image,
                        data_format='channels_last',
                        name='complex2channels'):
    """Convert data from complex to channels."""
    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

    if image.dtype is not tf.complex64 and image.dtype is not tf.complex128:
        raise TypeError('Input data must be complex')

    with tf.name_scope(name):
        image_out = tf.concat((tf.real(image), tf.imag(image)), axis_c)
    return image_out 
Example #30
Source File: benchmark_online_wpe.py    From nara_wpe with MIT License 5 votes vote down vote up
def config_iterator():
    return product(
        range(1, 11),
        [5, 10],  # K
        [2, 4, 6],  # num_mics # range(2, 11)
        [512],  # frame_size # 1024
        [tf.complex64],  # dtype # , tf.complex128
        ['/cpu:0']  # device # '/gpu:0'
    )