Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
ctf.core Namespace Reference

Data Structures

class  comm
 
class  contract_term
 
class  itensor
 
class  sum_term
 
class  tensor
 
class  term
 

Functions

def MPI_Stop ()
 
def __cinit__ (self)
 
def __dealloc__ (self)
 
def rank (self)
 
def np (self)
 
def __get__ (self)
 
def scale (self, scl)
 
def __add__ (self, other)
 
def __sub__ (self, other)
 
def __mul__ (first, second)
 
def conv_type (self, dtype)
 
def __repr__ (self)
 
def __lshift__ (self, other)
 
def __cinit__ (self, term, a, term, b)
 
def __cinit__ (self, tensor, a, string)
 
def scl (self, s)
 
def tril (A, k=0)
 
def triu (A, k=0)
 
def real (tensor, A)
 
def imag (tensor, A)
 
def array (A, dtype=None, copy=True, order='K', subok=False, ndmin=0)
 
def diag (A, k=0, sp=False)
 
def spdiag (A, k=0)
 
def diagonal (init_A, offset=0, axis1=0, axis2=1)
 
def trace (init_A, offset=0, axis1=0, axis2=1, dtype=None, out=None)
 
def take (init_A, indices, axis=None, out=None, mode='raise')
 
def copy (tensor, A)
 
def reshape (A, newshape, order='F')
 
def astensor (A, dtype=None, order=None)
 
def dot (tA, tB, out=None)
 
def tensordot (tA, tB, axes=2)
 
def exp (init_x, out=None, where=True, casting='same_kind', order='F', dtype=None, subok=True)
 
def to_nparray (t)
 
def from_nparray (arr)
 
def zeros_like (init_A, dtype=None, order='F')
 
def zeros (shape, dtype=np.float64, order='F')
 
def empty (shape, dtype=np.float64, order='F')
 
def empty_like (A, dtype=None)
 
def sum (tensor, init_A, axis=None, dtype=None, out=None, keepdims=None)
 
def ravel (init_A, order="F")
 
def any (tensor, init_A, axis=None, out=None, keepdims=None)
 
def hstack (in_tup)
 
def vstack (in_tup)
 
def conj (init_A)
 
def all (inA, axis=None, out=None, keepdims=False)
 
def transpose (init_A, axes=None)
 
def ones (shape, dtype=None, order='F')
 
def eye (n, m=None, k=0, dtype=np.float64, sp=False)
 
def identity (n, dtype=np.float64)
 
def speye (n, m=None, k=0, dtype=np.float64)
 
def einsum (subscripts, operands, out=None, dtype=None, order='K', casting='safe')
 
def svd (tensor, A, rank=None)
 
def qr (tensor, A)
 
def vecnorm (A, ord=2)
 
def power (first, second)
 
def abs (initA)
 

Variables

dictionary type_index = {}
 
 SYM = _enum(NS=0, SY=1, AS=2, SH=3)
 
 dim = len(a)
 
 ca = <char*>malloc(dim*sizeof(char))
 
 w
 
 tm
 
 a
 
 b
 
 dtype
 
 tsr
 
 it
 
 string
 

Function Documentation

def ctf.core.__add__ (   self,
  other 
)

Definition at line 337 of file core.pyx.

def ctf.core.__cinit__ (   self)

Definition at line 306 of file core.pyx.

Referenced by ctf.core.__cinit__().

def ctf.core.__cinit__ (   self,
  term,
  a,
  term,
  b 
)

Definition at line 384 of file core.pyx.

References ctf.core.__cinit__().

def ctf.core.__cinit__ (   self,
  tensor,
  a,
  string 
)

Definition at line 452 of file core.pyx.

References ctf.core.__cinit__().

def ctf.core.__dealloc__ (   self)

Definition at line 309 of file core.pyx.

Referenced by ctf.core.__mul__().

def ctf.core.__get__ (   self)

Definition at line 322 of file core.pyx.

def ctf.core.__lshift__ (   self,
  other 
)

Definition at line 369 of file core.pyx.

References ctf.core.astensor().

def ctf.core.__mul__ (   first,
  second 
)

Definition at line 349 of file core.pyx.

References ctf.core.__dealloc__().

def ctf.core.__repr__ (   self)

Definition at line 366 of file core.pyx.

def ctf.core.__sub__ (   self,
  other 
)

Definition at line 342 of file core.pyx.

def ctf.core.abs (   initA)
abs(A)
Calculate the elementwise absolute value of a tensor.

Parameters
----------
A: tensor_like
    Input tensor.

Returns
-------
output: tensor
    A tensor containing the absolute value of each element in input tensor. For complex number :math:`a + bi`, the absolute value is calculated as :math:`\sqrt{a^2 + b^2}`

References
----------

Examples
--------
>>> import ctf
>>> a = ctf.astensor([-2, 3])
array([-2,  3])
>>> abs(a)
array([2, 3])

Definition at line 5440 of file core.pyx.

References ctf.core.astensor().

Referenced by ctf.core.tensor.__abs__(), CTF_int.abs_helper(), CTF_int.char_abs(), permute_multiworld(), CTF.real_norm1(), scalar(), scan_test(), CTF::Set< dtype, is_ord >.Set(), CTF::Set< dtype, is_ord >.set_abs_to_default(), and setup_unstructured().

def ctf.core.all (   inA,
  axis = None,
  out = None,
  keepdims = False 
)
all(A, axis=None, out=None, keepdims = False)
Return whether given an axis elements are True.

Parameters
----------
A: tensor_like
    Input tensor.

axis: None or int, optional
    Currently not supported in CTF Python.

out: tensor, optional
    Currently not supported in CTF Python.

keepdims : bool, optional
    Currently not supported in CTF Python.

Returns
-------
output: tensor_like
    Output tensor or scalar.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([[0, 1], [1, 1]])
>>> ctf.all(a)
False

Definition at line 4795 of file core.pyx.

def ctf.core.any (   tensor,
  init_A,
  axis = None,
  out = None,
  keepdims = None 
)
any(A, axis=None, out=None, keepdims = False)
Return whether given an axis any elements are True.

Parameters
----------
A: tensor_like
    Input tensor.

axis: None or int, optional
    Axis along which logical OR is applied.

out: tensor_like, optional
    Objects which will place the result.

keepdims: bool, optional
    If keepdims is set to True, the reduced axis will remain 1 in shape.

Returns
-------
output: tensor_like
    Output tensor or scalar.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([[0, 0], [1, 1]])
>>> ctf.any(a)
True
>>> ctf.any(a, axis=0)
array([ True,  True])
>>> ctf.any(a, axis=1)
array([False,  True])

Definition at line 4471 of file core.pyx.

References ctf.core.astensor(), and ctf.core.reshape().

def ctf.core.array (   A,
  dtype = None,
  copy = True,
  order = 'K',
  subok = False,
  ndmin = 0 
)
array(A, dtype=None, copy=True, order='K', subok=False, ndmin=0)
Create a tensor.

Parameters
----------
A: tensor_like
    Input tensor like object.

dtype: data-type, optional
    The desired data-type for the tensor. If the dtype is not specified, the dtype will be determined as `np.array()`.

copy: bool, optional
    If copy is true, the object is copied.

order: {‘K’, ‘A’, ‘C’, ‘F’}, optional
    Specify the memory layout for the tensor.

subok: bool, optional
    Currently subok is not supported in `ctf.array()`.

ndmin: int, optional
    Currently ndmin is not supported in `ctf.array()`.

Returns
-------
output: tensor
    A tensor object with specified requirements.

See Also
--------
ctf : ctf.astensor()

Notes
-----
The input of ctf.array() should be tensor or numpy.ndarray

Examples
--------
>>> import ctf
>>> import numpy as np
>>> a = np.array([1, 2, 3.])
array([1., 2., 3.])
>>> b = ctf.array(a)
array([1., 2., 3.])

Definition at line 3079 of file core.pyx.

References ctf.core.astensor().

Referenced by CTF_int.handler().

def ctf.core.astensor (   A,
  dtype = None,
  order = None 
)
astensor(A, dtype = None, order=None)
Convert the input data to tensor.

Parameters
----------
A: tensor_like
    Input data.

dtype: data-type, optional
    Numpy data-type, if it is not specified, the function will return the tensor with same type as `np.asarray` returned ndarray.

order: {‘C’, ‘F’}, optional
    C or Fortran memory order, default is 'F'.

Returns
-------
output: tensor
    A tensor representation of A.

See Also
--------
numpy: numpy.asarray()

Examples
--------
>>> import ctf
>>> a = ctf.astensor([1,2,3])
>>> a
array([1, 2, 3])

Definition at line 3650 of file core.pyx.

Referenced by ctf.core.tensor.__cinit__(), ctf.core.tensor.__iadd__(), ctf.core.tensor.__idiv__(), ctf.core.tensor.__imul__(), ctf.core.tensor.__isub__(), ctf.core.tensor.__itruediv__(), ctf.core.__lshift__(), ctf.core.tensor.__neg__(), ctf.core.tensor.__richcmp__(), ctf.core.tensor.__setitem__(), ctf.core.abs(), ctf.core.any(), ctf.core.array(), ctf.core.conj(), ctf.core.diagonal(), ctf.core.dot(), ctf.core.exp(), ctf.core.from_nparray(), ctf.core.ravel(), ctf.core.sum(), ctf.core.take(), ctf.core.tensordot(), ctf.core.trace(), ctf.core.transpose(), ctf.core.vecnorm(), and ctf.core.zeros_like().

def ctf.core.conj (   init_A)
conj(A)
Return the conjugate tensor A element-wisely.

Parameters
----------
A: tensor_like
    Input tensor.

Returns
-------
output: tensor
    The element-wise complex conjugate of input tensor A. If tensor A is not complex, just return a copy of A.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([2+3j, 3-2j])
array([2.+3.j, 3.-2.j])
>>> ctf.conj(a)
array([2.-3.j, 3.+2.j])

Definition at line 4760 of file core.pyx.

References ctf.core.astensor().

def ctf.core.conv_type (   self,
  dtype 
)

Definition at line 363 of file core.pyx.

Referenced by ctf.core.tensor.__get__(), and ctf.core.MPI_Stop().

def ctf.core.copy (   tensor,
  A 
)
copy(A)
Return a copy of tensor A.

Parameters
----------
A: tensor
    Input tensor.

Returns
-------
output: tensor
    A tensor representation of A.

Examples
--------
>>> a = ctf.astensor([1,2,3])
>>> a
array([1, 2, 3])
>>> b = ctf.copy(a)
>>> b
array([1, 2, 3])
>>> id(a) == id(b)
False

Definition at line 3583 of file core.pyx.

Referenced by CTF_int::algstrct.copy(), CTF::Set< dtype, is_ord >.copy(), CTF::Set< dtype, is_ord >.copy_pairs(), CTF_int::algstrct.has_mul(), CTF_int::algstrct.safecopy(), CTF_int::algstrct.scal(), and CTF_int.seq_csr_to_coo().

def ctf.core.diag (   A,
  k = 0,
  sp = False 
)
diag(A, k=0, sp=False)
Return the diagonal tensor of A.

Parameters
----------
A: tensor_like
    Input tensor with 1-D or 2-D dimensions. If A is 1-D tensor, return a 2-D tensor with A on diagonal.

k: int, optional
    `k=0` is the diagonal. `k<0`, diagnals below the main diagonal. `k>0`, diagonals above the main diagonal.

sp: bool, optional
    If sp is true, the returned tensor is sparse.

Returns
-------
output: tensor
    Diagonal tensor of A.

Notes
-----
When the input tensor is sparse, returned tensor will also be sparse.

See Also
--------
ctf : ctf.diagonal()
      ctf.triu()
      ctf.tril()
      ctf.trace()
      ctf.spdiag()

Examples
--------
>>> import ctf
>>> a = ctf.ones([3,])
>>> ctf.diag(a, k=1)
array([[0., 1., 0., 0.],
       [0., 0., 1., 0.],
       [0., 0., 0., 1.]])
>>> b = ctf.zeros([4,4])
>>> ctf.diag(b)
array([0., 0., 0., 0.])

Definition at line 3141 of file core.pyx.

References ctf.core.einsum().

Referenced by ctf.core.spdiag().

def ctf.core.diagonal (   init_A,
  offset = 0,
  axis1 = 0,
  axis2 = 1 
)
diagonal(A, offset=0, axis1=0, axis2=1)
Return the diagonal of tensor A if A is 2D. If A is a higher order square tensor (same shape for every dimension), return diagonal of tensor determined by axis1=0, axis2=1.

Parameters
----------
A: tensor_like
    Input tensor.

offset: int, optional
    Default is 0 which indicates the main diagonal.

axis1: int, optional
    Default is 0 which indicates the first axis of 2-D tensor where diagonal is taken.

axis2: int, optional
    Default is 1 which indicates the second axis of 2-D tensor where diagonal is taken.

Returns
-------
output: tensor
    Diagonal of input tensor.

Notes
-----
`ctf.diagonal` only supports diagonal of square tensor with order more than 2.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([[1,2,3], [4,5,6], [7,8,9]])
>>> ctf.diagonal(a)
array([1, 5, 9])

Definition at line 3289 of file core.pyx.

References ctf.core.astensor(), and ctf.core.einsum().

Referenced by ctf.core.trace().

def ctf.core.dot (   tA,
  tB,
  out = None 
)
dot(A, B, out=None)
Return the dot product of two tensors A and B.

Parameters
----------
A: tensor_like
    First input tensor.

B: tensor_like
    Second input tensor.

out: tensor
    Currently not supported in CTF Python.

Returns
-------
output: tensor
    Dot product of two tensors.

See Also
--------
numpy: numpy.dot()

Examples
--------
>>> import ctf
>>> a = ctf.astensor([[1,2,3], [4,5,6], [7,8,9]])
>>> b = ctf.astensor([1,1,1])
>>> ctf.dot(a, b)
array([ 6, 15, 24])

Definition at line 3698 of file core.pyx.

References ctf.core.astensor(), and ctf.core.tensordot().

def ctf.core.einsum (   subscripts,
  operands,
  out = None,
  dtype = None,
  order = 'K',
  casting = 'safe' 
)
einsum(subscripts, *operands, out=None, dtype=None, order='K', casting='safe')
Einstein summation on operands.

Parameters
----------
subscripts: str
    Subscripts for summation.

operands: list of tensor
    List of tensors.

out: tensor or None
    If the out is not None, calculated result will stored into out tensor.

dtype: data-type, optional
    Numpy data-type of returned tensor, dtype of returned tensor will be specified by operand tensors.

order: {‘C’, ‘F’, ‘A’, ‘K’}, optional
    Currently not supported by CTF Python.

casting: {‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional
    Currently not supported by CTF Python.

Returns
-------
output: tensor

See Also
--------
numpy : numpy.einsum()

Examples
--------
>>> import ctf
>>> a = ctf.astensor([[1,2,3], [4,5,6], [7,8,9]])
>>> ctf.einsum("ii->i", a)
array([1, 5, 9])

Definition at line 5121 of file core.pyx.

Referenced by ctf.core.diag(), and ctf.core.diagonal().

def ctf.core.empty (   shape,
  dtype = np.float64,
  order = 'F' 
)
empty(shape, dtype=np.float64, order='F')
Return the tensor with specified shape and dtype without initialization. Currently not supported by CTF Python, this function same with the ctf.zeros().

Parameters
----------
shape: int or tuple of int
    Shape of the empty tensor.

dtype: data-type, optional
    Output data-type for the empty tensor.

order: {‘C’, ‘F’}, optional, default: ‘F’
    Currently not support by CTF Python.

Returns
-------
output: tensor_like
    Output tensor.

Examples
--------
>>> import ctf
>>> import numpy as np
>>> a = ctf.empty([3,4], dtype=np.int64)
>>> a
array([[0, 0, 0, 0],
       [0, 0, 0, 0],
       [0, 0, 0, 0]])

Definition at line 4191 of file core.pyx.

References ctf.core.zeros().

Referenced by ctf.core.empty_like().

def ctf.core.empty_like (   A,
  dtype = None 
)
empty_like(A, dtype=None)
Return uninitialized tensor of with same shape and dtype of tensor A. Currently in CTF Python is same with ctf.zero_like.

Parameters
----------
A: tensor_like
    Input tensor where the output tensor shape and dtype defined as.

dtype: data-type, optional
    Output data-type for the empty tensor.

Returns
-------
output: tensor_like
    Output tensor.

See Also
--------
ctf: ctf.zeros_like()

Examples
--------
>>> import ctf
>>> a = ctf.zeros([3,4], dtype=np.int64)
>>> b = ctf.empty_like(a)
>>> b
array([[0, 0, 0, 0],
       [0, 0, 0, 0],
       [0, 0, 0, 0]])

Definition at line 4224 of file core.pyx.

References ctf.core.empty().

def ctf.core.exp (   init_x,
  out = None,
  where = True,
  casting = 'same_kind',
  order = 'F',
  dtype = None,
  subok = True 
)
exp(A, out=None, where=True, casting='same_kind', order='F', dtype=None, subok=True)
Exponential of all elements in input tensor A.

Parameters
----------
A: tensor_like
    Input tensor or tensor like array.

out: tensor, optional
    Crrently not support by CTF Python.

where: array_like, optional
    Crrently not support by CTF Python.

casting: same_kind or unsafe
    Default same_kind.

order: optional
    Crrently not support by CTF Python.

dtype: data-type, optional
    Output data-type for the exp result.

subok: bool
    Crrently not support by CTF Python.

Returns
-------
output: tensor_like
    Output tensor for the exponential.

See Also
--------
numpy: numpy.exp()

Examples
--------
>>> import ctf
>>> a = ctf.astensor([1,2,3])
>>> ctf.exp(a)
array([ 2.71828183,  7.3890561 , 20.08553692])

Definition at line 3954 of file core.pyx.

References ctf.core.astensor().

Referenced by CTF_int::tensor.exp_helper(), omega(), test_dft(), and test_dft_3D().

def ctf.core.eye (   n,
  m = None,
  k = 0,
  dtype = np.float64,
  sp = False 
)
eye(n, m=None, k=0, dtype=np.float64, sp=False)
Return a 2D tensor with ones on the diagonal and zeros elsewhere.

Parameters
----------
n: int
    Number of rows.

m: int, optional
    Number of columns, default set to n.

k: int, optional
    Diagonal index, specify ones on main diagonal, upper diagonal or lower diagonal.

dtype: data-type, optional
    Numpy data-type of returned tensor, default `np.float64`.

sp: bool, optional
    If `true` the returned tensor will be sparse, default `sp=False`.

Returns
-------
output: tensor


Examples
--------
>>> import ctf
>>> e = ctf.eye(3,m=4,k=-1)
>>> e
array([[0., 0., 0., 0.],
       [1., 0., 0., 0.],
       [0., 1., 0., 0.]])

Definition at line 4988 of file core.pyx.

Referenced by ctf.core.identity(), and ctf.core.speye().

def ctf.core.from_nparray (   arr)
from_nparray(A)
Convert the numpy array to tensor.

Parameters
----------
A: ndarray
    Input numpy array.

Returns
-------
output: tensor
    Tensor representation of input numpy array.

See Also
--------
ctf: ctf.astensor()

Examples
--------
>>> import ctf
>>> import numpy as np
>>> a = np.array([1,2,3])
>>> b = ctf.from_nparray(a)
>>> b
array([1, 2, 3])
>>> type(b)
<class 'ctf.core.tensor'>

Definition at line 4087 of file core.pyx.

References ctf.core.astensor().

def ctf.core.hstack (   in_tup)
hstack(in_tup)
Stack the tensor in column-wise.

Parameters
----------
in_tup: tuple of tensors
    Input tensor.

Returns
-------
output: tensor_like
    Output horizontally stacked tensor.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([1,2,3])
>>> b = ctf.astensor([4,5,6])
>>> ctf.hstack((a, b))
array([1, 2, 3, 4, 5, 6])

Definition at line 4709 of file core.pyx.

def ctf.core.identity (   n,
  dtype = np.float64 
)
identity(n, dtype=np.float64)
Return a squared 2-D tensor where the main diagonal contains ones and elsewhere zeros.

Parameters
----------
n: int
    Number of rows.

dtype: data-type, optional
    Numpy data-type of returned tensor, default `np.float64`.

Returns
-------
output: tensor

See Also
--------
ctf : ctf.eye()

Examples
--------
>>> import ctf
>>> a = ctf.identity(3)
>>> a
array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]])

Definition at line 5050 of file core.pyx.

References ctf.core.eye().

def ctf.core.imag (   tensor,
  A 
)
imag(A)
Return the image part of the tensor elementwisely.

Parameters
----------
A: tensor_like
    Input tensor.

Returns
-------
output: tensor
    A tensor with real part of the input tensor.

See Also
--------
numpy : numpy.imag()

Notes
-----
The input should be a CTF tensor.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([1+2j, 3+4j, 5+6j, 7+8j])
>>> a
array([1.+2.j, 3.+4.j, 5.+6.j, 7.+8.j])
>>> ctf.imag(a)
array([2., 4., 6., 8.])

Definition at line 3038 of file core.pyx.

References ctf.core.zeros().

Referenced by omega(), CTF::Set< dtype, is_ord >.print(), test_dft(), and test_dft_3D().

def ctf.core.np (   self)

Definition at line 315 of file core.pyx.

Referenced by CTF_int::CommData.activate(), CTF_int::CommData.all_to_allv(), CTF_int::CommData.allred(), CTF_int::CommData.bcast(), bitonic_sort(), CTF_int.bucket_by_pe(), CTF_int.calc_cnt_displs(), ccsdt_t3_to_t2(), chi(), CTF_int.cmp_sym_perms(), CTF_int::CommData.CommData(), CTF_int.cyclic_reshuffle(), DFT_matrix(), diag_ctr(), diag_sym(), CTF_int::LinModel< nparam >.dump_data(), CTF_int::spctr_replicate.est_time_fp(), CTF_int::ctr_replicate.est_time_fp(), CTF_int::CommData.estimate_allred_time(), CTF_int::CommData.estimate_alltoall_time(), CTF_int::CommData.estimate_alltoallv_time(), CTF_int::CommData.estimate_bcast_time(), CTF_int::CommData.estimate_red_time(), fft(), gemm_4D(), CTF_int.get_len_ordering(), CTF_int.get_phys_topo(), CTF_int.glb_cyclic_reshuffle(), main(), CTF_int.morph_topo(), multi_tsr_sym(), CTF_int::CommData.operator=(), permute_multiworld(), CTF_int::spctr_replicate.print(), CTF_int::tspsum_replicate.print(), CTF_int::tsum_replicate.print(), CTF_int::ctr_replicate.print(), CTF_int::tensor.print_map(), CTF.print_timers(), CTF_int::tensor.read_local(), CTF::Matrix< dtype >.read_mat(), CTF_int::CommData.red(), repack(), scalar(), CTF_int::tensor.scale_diagonals(), scan(), CTF_int::tensor.set_zero(), sparse_permuted_slice(), strassen(), CTF_int.strip_diag(), sy_times_ns(), test_dft(), test_dft_3D(), test_recursive_matmul(), test_subworld_gemm(), trace(), train_all(), twiddle_matrix(), CTF_int::LinModel< nparam >.update(), weigh_4D(), CTF_int.wr_pairs_layout(), CTF::Matrix< dtype >.write_mat(), CTF_int::tensor.zero_out_padding(), and CTF::World.~World().

def ctf.core.ones (   shape,
  dtype = None,
  order = 'F' 
)
ones(shape, dtype = None, order='F')
Return a tensor filled with ones with specified shape and dtype.

Parameters
----------
shape: int or sequence of ints
    Shape of the returned tensor.

dtype: numpy data-type, optional
    The data-type for the tensor.

order: {‘C’, ‘F’}, optional
    Not support by current CTF Python.

Returns
-------
output: tensor
    Tensor with specified shape and dtype.

Examples
--------
>>> import ctf
>>> a = ctf.ones([2, 2])
>>> a
    array([[1., 1.],
          [1., 1.]])

Definition at line 4930 of file core.pyx.

def ctf.core.power (   first,
  second 
)
power(A, B)
Elementwisely raise tensor A to powers from the tensor B.

Parameters
----------
A: tensor_like
    Bases tensor.

B: tensor_like
    Exponents tensor

Returns
-------
output: tensor
    The output tensor containing elementwise bases A raise to exponents of B.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([2., 3])
array([2., 3.])
>>> b = ctf.astensor([2., 3])
array([2., 3.])
>>> ctf.power(a, b)
array([ 4., 27.])

Definition at line 5404 of file core.pyx.

Referenced by ctf.core.tensor.__pow__().

def ctf.core.qr (   tensor,
  A 
)
qr(A)
Compute QR factorization of tensor A.

Parameters
----------
A: tensor_like
    Input tensor 2-D dimensions.

Returns
-------
Q: tensor
    A CTF tensor with 2-D dimensions and orthonormal columns.

R: tensor
    An upper triangular 2-D CTF tensor.

Definition at line 5275 of file core.pyx.

References CTF_int.matrix_qr(), and CTF_int.matrix_qr_cmplx().

def ctf.core.ravel (   init_A,
  order = "F" 
)
ravel(A, order="F")
Return flattened CTF tensor of input tensor A.

Parameters
----------
A: tensor_like
    Input tensor.

order: {‘C’,’F’, ‘A’, ‘K’}, optional
    Currently not support by current CTF Python.

Returns
-------
output: tensor_like
    Flattened tensor.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([1,2,3,4,5,6,7,8]).reshape(2,2,2)
>>> a
array([[[1, 2],
        [3, 4]],
       [[5, 6],
        [7, 8]]])
>>> ctf.ravel(a)
array([1, 2, 3, 4, 5, 6, 7, 8])

Definition at line 4434 of file core.pyx.

References ctf.core.astensor(), and ctf.core.reshape().

def ctf.core.real (   tensor,
  A 
)
real(A)
Return the real part of the tensor elementwisely.

Parameters
----------
A: tensor_like
    Input tensor.

Returns
-------
output: tensor
    A tensor with real part of the input tensor.

See Also
--------
numpy : numpy.real()

Notes
-----
The input should be a CTF tensor.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([1+2j, 3+4j, 5+6j, 7+8j])
>>> a
array([1.+2.j, 3.+4.j, 5.+6.j, 7.+8.j])
>>> ctf.real(a)
array([1., 3., 5., 7.])

Definition at line 2997 of file core.pyx.

Referenced by CTF::Set< dtype, is_ord >.print(), test_dft(), and test_dft_3D().

def ctf.core.reshape (   A,
  newshape,
  order = 'F' 
)
reshape(A, newshape, order='F')
Reshape the input tensor A to new shape.

Parameters
----------
A: tensor_like
    Input tensor.

newshape: tuple of ints or int
    New shape where the input tensor is shaped to.

order: {‘C’, ‘F’}, optional
    Currently not supported by CTF Python.

Returns
-------
output: tensor
    Tensor with new shape of A.

See Also
--------
ctf: ctf.tensor.reshape()

Examples
--------
>>> import ctf
a = ctf.astensor([1,2,3,4])
>>> ctf.reshape(a, (2, 2))
array([[1, 2],
       [3, 4]])

Definition at line 3612 of file core.pyx.

Referenced by ctf.core.any(), ctf.core.ravel(), and ctf.core.take().

def ctf.core.scl (   self,
  s 
)
def ctf.core.spdiag (   A,
  k = 0 
)
spdiag(A, k=0)
Return the sparse diagonal tensor of A.

Parameters
----------
A: tensor_like
    Input tensor with 1-D or 2-D dimensions. If A is 1-D tensor, return a 2-D tensor with A on diagonal.

k: int, optional
    `k=0` is the diagonal. `k<0`, diagnals below the main diagonal. `k>0`, diagonals above the main diagonal.

Returns
-------
output: tensor
    Sparse diagonal tensor of A.

Notes
-----
Same with ctf.diag(A,k,sp=True)

Examples
--------
>>> import ctf
>>> a = ctf.astensor([[1,2,3], [4,5,6], [7,8,9]])
>>> ctf.spdiag(a)
array([1, 5, 9])

Definition at line 3258 of file core.pyx.

References ctf.core.diag().

def ctf.core.speye (   n,
  m = None,
  k = 0,
  dtype = np.float64 
)
speye(n, m=None, k=0, dtype=np.float64)
Return a sparse 2D tensor with ones on the diagonal and zeros elsewhere.

Parameters
----------
n: int
    Number of rows.

m: int, optional
    Number of columns, default set to n.

k: int, optional
    Diagonal index, specify ones on main diagonal, upper diagonal or lower diagonal.

dtype: data-type, optional
    Numpy data-type of returned tensor, default `np.float64`.

Returns
-------
output: tensor

See Also
--------
ctf : ctf.eye()

Examples
--------
>>> import ctf
>>> e = ctf.speye(3,m=4,k=-1)
>>> e
array([[0., 0., 0., 0.],
       [1., 0., 0., 0.],
       [0., 1., 0., 0.]])

Definition at line 5082 of file core.pyx.

References ctf.core.eye().

def ctf.core.sum (   tensor,
  init_A,
  axis = None,
  dtype = None,
  out = None,
  keepdims = None 
)
sum(A, axis = None, dtype = None, out = None, keepdims = None)
Sum of elements in tensor or along specified axis.

Parameters
----------
A: tensor_like
    Input tensor.

axis: None, int or tuple of ints
    Axis or axes where the sum of elements is performed.

dtype: data-type, optional
    Data-type for the output tensor.

out: tensor, optional
    Alternative output tensor.

keepdims: None, bool, optional
    If set to true, axes summed over will remain size one.

Returns
-------
output: tensor_like
    Output tensor.

See Also
--------
numpy: numpy.sum()

Examples
--------
>>> import ctf
>>> a = ctf.ones([3,4], dtype=np.int64)
>>> ctf.sum(a)
12

Definition at line 4261 of file core.pyx.

References ctf.core.astensor().

Referenced by CTF_int::tensor.extract_diag(), readwrite_test(), and ctf.core.trace().

def ctf.core.svd (   tensor,
  A,
  rank = None 
)
svd(A, rank=None)
Compute Single Value Decomposition of tensor A.

Parameters
----------
A: tensor_like
    Input tensor 2-D dimensions.

rank: int or None, optional
    Target rank for SVD, default `k=0`.

Returns
-------
U: tensor
    A unitary CTF tensor with 2-D dimensions.

S: tensor
    A 1-D tensor with singular values.

VT: tensor
    A unitary CTF tensor with 2-D dimensions.

Definition at line 5235 of file core.pyx.

References CTF_int.matrix_svd(), and CTF_int.matrix_svd_cmplx().

def ctf.core.take (   init_A,
  indices,
  axis = None,
  out = None,
  mode = 'raise' 
)
take(A, indices, axis=None, out=None, mode='raise')
Take elements from a tensor along axis.

Parameters
----------
A: tensor_like
    Input tensor.

indices: tensor_like
    Indices of the values wnat to be extracted.

axis: int, optional
    Select values from which axis, default None.

out: tensor
    Currently not supported in CTF Python take().

mode: {‘raise’, ‘wrap’, ‘clip’}, optional
    Currently not supported in CTF Python take().

Returns
-------
output: tensor or scalar
    Elements extracted from the input tensor.

See Also
--------
numpy: numpy.take()

Examples
--------
>>> import ctf
>>> a = ctf.astensor([[1,2,3], [4,5,6], [7,8,9]])
>>> ctf.take(a, [0, 1, 2])
array([1, 2, 3])

Definition at line 3435 of file core.pyx.

References ctf.core.astensor(), and ctf.core.reshape().

def ctf.core.tensordot (   tA,
  tB,
  axes = 2 
)
tensordot(A, B, axes=2)
Return the tensor dot product of two tensors A and B along axes.

Parameters
----------
A: tensor_like
    First input tensor.

B: tensor_like
    Second input tensor.

axes: int or array_like
    Sum over which axes.

Returns
-------
output: tensor
    Tensor dot product of two tensors.

See Also
--------
numpy: numpy.tensordot()

Examples
--------
>>> import ctf
>>> import numpy as np
>>> a = np.arange(60.).reshape(3,4,5)
>>> b = np.arange(24.).reshape(4,3,2)
>>> a = ctf.astensor(a)
>>> b = ctf.astensor(b)
>>> c = ctf.tensordot(a,b, axes=([1,0],[0,1]))
>>> c
array([[4400., 4730.],
       [4532., 4874.],
       [4664., 5018.],
       [4796., 5162.],
       [4928., 5306.]])

Definition at line 3743 of file core.pyx.

References ctf.core.astensor().

Referenced by ctf.core.dot().

def ctf.core.to_nparray (   t)
to_nparray(A)
Convert the tensor to numpy array.

Parameters
----------
A: tensor_like
    Input tensor or tensor like array.

Returns
-------
output: ndarray
    Numpy ndarray representation of tensor like input A.

See Also
--------
numpy: numpy.asarray()

Examples
--------
>>> import ctf
>>> import numpy as np
>>> a = ctf.zeros([3,4])
>>> b = ctf.to_nparray(a)
>>> b
array([[0., 0., 0., 0.],
       [0., 0., 0., 0.],
       [0., 0., 0., 0.]])
>>> type(b)
<class 'numpy.ndarray'>

Definition at line 4050 of file core.pyx.

def ctf.core.trace (   init_A,
  offset = 0,
  axis1 = 0,
  axis2 = 1,
  dtype = None,
  out = None 
)
trace(A, offset=0, axis1=0, axis2=1, dtype=None, out=None)
Return the sum over the diagonal of input tensor.

Parameters
----------
A: tensor_like
    Input tensor.

offset: int, optional
    Default is 0 which indicates the main diagonal.

axis1: int, optional
    Default is 0 which indicates the first axis of 2-D tensor where diagonal is taken.

axis2: int, optional
    Default is 1 which indicates the second axis of 2-D tensor where diagonal is taken.

dtype: data-type, optional
    Numpy data-type, currently not supported in CTF Python trace().

out: tensor
    Currently not supported in CTF Python trace().

Returns
-------
output: tensor or scalar
    Sum along diagonal of input tensor.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([[1,2,3], [4,5,6], [7,8,9]])
>>> ctf.trace(a)
15

Definition at line 3385 of file core.pyx.

References ctf.core.astensor(), ctf.core.diagonal(), and ctf.core.sum().

def ctf.core.transpose (   init_A,
  axes = None 
)
transpose(A, axes=None)
Permute the dimensions of the input tensor.

Parameters
----------
A: tensor_like
    Input tensor.

axes: list of ints, optional
    If axes is None, the dimensions are inversed, otherwise permute the dimensions according to the axes value.

Returns
-------
output: tensor
    Tensor with permuted axes of A.

Examples
--------
>>> import ctf
>>> a = ctf.zeros([3,4,5])
>>> a.shape
(3, 4, 5)
>>> ctf.transpose(a, axes=[0, 2, 1]).shape
(3, 5, 4)
>>> ctf.transpose(a).shape
(5, 4, 3)

Definition at line 4850 of file core.pyx.

References ctf.core.astensor().

Referenced by CTF.get_core_tensor(), get_core_tensor(), get_core_tensor_hooi(), and ctf.core.triu().

def ctf.core.tril (   A,
  k = 0 
)
tril(A, k=0)
Return lower triangle of a CTF tensor.

Parameters
----------
A: tensor_like
    2-D input tensor.

k: int
    Specify last diagonal not zeroed. Default `k=0` which indicates elements under the main diagonal are zeroed.

Returns
-------
output: tensor
    Lower triangular 2-d tensor of input tensor.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([[1,2,3],[4,5,6],[7,8,9]])
>>> ctf.tril(a, k=1)
array([[1, 2, 0],
       [4, 5, 6],
       [7, 8, 9]])

Definition at line 2925 of file core.pyx.

Referenced by ctf.core.triu().

def ctf.core.triu (   A,
  k = 0 
)
triu(A, k=0)
Return upper triangle of a CTF tensor.

Parameters
----------
A: tensor_like
    2-D input tensor.

k: int
    Specify last diagonal not zeroed. Default `k=0` which indicates elements under the main diagonal are zeroed.

Returns
-------
output: tensor
    Upper triangular 2-d tensor of input tensor.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([[1,2,3],[4,5,6],[7,8,9]])
>>> ctf.triu(a, k=-1)
array([[1, 2, 3],
       [4, 5, 6],
       [0, 8, 9]])

Definition at line 2968 of file core.pyx.

References ctf.core.transpose(), and ctf.core.tril().

def ctf.core.vecnorm (   A,
  ord = 2 
)
vecnorm(A, ord=2)
Return norm of tensor A.

Parameters
----------
A: tensor_like
    Input tensor with 1-D or 2-D dimensions. If A is 1-D tensor, return a 2-D tensor with A on diagonal.

ord: {int 1, 2, inf}, optional
    Order of the norm.

Returns
-------
output: tensor
    Norm of tensor A.

Examples
--------
>>> import ctf
>>> import ctf.linalg as la
>>> a = ctf.astensor([3,4.])
>>> la.vecnorm(a)
5.0

Definition at line 5304 of file core.pyx.

References ctf.core.astensor().

def ctf.core.vstack (   in_tup)
vstack(in_tup)
Stack the tensor in row-wise.

Parameters
----------
in_tup: tuple of tensors
    Input tensor.

Returns
-------
output: tensor_like
    Output vertically stacked tensor.

Examples
--------
>>> import ctf
>>> a = ctf.astensor([1,2,3])
>>> b = ctf.astensor([4,5,6])
>>> ctf.vstack((a, b))
array([[1, 2, 3],
       [4, 5, 6]])

Definition at line 4734 of file core.pyx.

def ctf.core.zeros (   shape,
  dtype = np.float64,
  order = 'F' 
)
zeros(shape, dtype=np.float64, order='F')
Return the tensor with specified shape and dtype with all elements filled as zeros.

Parameters
----------
shape: int or tuple of int
    Shape of the empty tensor.

dtype: data-type, optional
    Output data-type for the empty tensor.

order: {‘C’, ‘F’}, optional, default: ‘F’
    Currently not support by CTF Python.

Returns
-------
output: tensor_like
    Output tensor.

Examples
--------
>>> import ctf
>>> import numpy as np
>>> a = ctf.zeros([3,4], dtype=np.int64)
>>> a
array([[0, 0, 0, 0],
       [0, 0, 0, 0],
       [0, 0, 0, 0]])

Definition at line 4157 of file core.pyx.

Referenced by ctf.core.empty(), flatten_block_sparse_matrix(), ctf.core.tensor.imag(), ctf.core.imag(), and ctf.core.zeros_like().

def ctf.core.zeros_like (   init_A,
  dtype = None,
  order = 'F' 
)
zeros_like(A, dtype=None, order='F')
Return the tensor of zeros with same shape and dtype of tensor A.

Parameters
----------
A: tensor_like
    Input tensor where the output tensor shape and dtype defined as.

dtype: data-type, optional
    Output data-type for the empty tensor.

order: {‘C’, ‘F’}, optional, default: ‘F’
    Currently not support by CTF Python.

Returns
-------
output: tensor_like
    Output tensor.

Examples
--------
>>> import ctf
>>> import numpy as np
>>> a = ctf.zeros([3,4], dtype=np.int64)
>>> b = ctf.zeros_like(a)
>>> b
array([[0, 0, 0, 0],
       [0, 0, 0, 0],
       [0, 0, 0, 0]])

Definition at line 4119 of file core.pyx.

References ctf.core.astensor(), and ctf.core.zeros().

Variable Documentation

ctf.core.a

Definition at line 385 of file core.pyx.

Referenced by CTF_int.abs_helper(), CTF_int.all_helper(), CTF_int.any_helper(), apsp(), bitonic_sort(), bivar_function(), bivar_transform(), btwn_cnt(), btwn_cnt_fast(), btwn_cnt_naive(), cadd(), CTF_int.coalesce_bwd(), CTF_int::tensor.compare_elementwise(), conj(), CTF_int.conj_helper(), CTF_int::tensor.conv_type(), CTF_int.default_abs(), CTF_int.default_addinv(), CTF_int.default_max(), CTF_int.default_max_lim(), CTF_int.default_min(), CTF_int.default_min_lim(), endomorphism_cust(), CTF_int::tensor.exp_helper(), f2(), fdbl(), fft(), fquad(), CTF_int.gcd(), get_cpath_monoid(), CTF_int.get_imag(), CTF_int::algstrct.get_key(), CTF_int.get_len_ordering(), get_mpath_semiring(), CTF::Monoid_Kernel< dtype_C, g >.get_MPI_Op(), CTF_int.get_real(), CTF_int::algstrct.has_mul(), CTF_int.inc_tot_mem_used(), CTF_int::int1.int1(), CTF_int::int2.int2(), CTF_int::tensor.larger_equal_than(), CTF_int::tensor.larger_than(), mfunc(), mis2(), neural(), CTF_int::tensor.not_equals(), grp.op1(), grp.op2(), CTF_int.pow_helper(), CTF::Set< dtype, is_ord >.print(), CTF.real_norm1(), rec_scan(), CTF_int.seq_coo_to_csr(), CTF_int.set_imag(), CTF_int.set_real(), CTF_int::tensor.smaller_equal_than(), CTF_int::tensor.smaller_than(), CTF_int.sp_read(), CTF_int.sp_write(), spectral(), CTF_int.spspsum(), sssp(), CTF_int.sum_bool_tsr(), test_ao_mo_transf(), test_dft(), test_mis(), test_mis2(), test_qr(), test_svd(), train_dns_vec_mat(), train_off_vec_mat(), train_sps_vec_mat(), CTF_int::tensor.true_divide(), univar_function(), and vcycle().

ctf.core.ca = <char*>malloc(dim*sizeof(char))

Definition at line 262 of file core.pyx.

ctf.core.dtype

Definition at line 387 of file core.pyx.

Referenced by CTF_int.abs_helper(), CTF::Monoid_Kernel< dtype_C, g >.accum(), CTF::Monoid< dtype, is_ord >.add(), CTF::Group< dtype, is_ord >.addinv(), CTF::Ring< dtype, is_ord >.addinv(), CTF_int.all_helper(), CTF::Set< dtype, is_ord >.alloc(), CTF_int.any_helper(), CTF::Endomorphism< dtype_A >.apply_f(), CTF::Monoid< dtype, is_ord >.axpy(), bench_ao_mo_transf(), CTF_int.char_abs(), CTF_int::tensor.compare_elementwise(), CTF::Set< dtype, is_ord >.coo_to_csr(), CTF::Set< dtype, is_ord >.copy(), CTF::Set< dtype, is_ord >.csr_to_coo(), CTF::Set< dtype, is_ord >.dealloc(), CTF_int.default_abs(), CTF_int.default_max_lim(), CTF_int.default_min_lim(), CTF_int.default_mxpy(), CTF.fill_random_base(), CTF::Tensor< dtype >.fill_sp_random(), CTF.fill_sp_random_base(), CTF_int.gemm_batch(), CTF_int.get_default_maddop(), CTF_int.get_default_mdtype(), CTF_int.get_grp_ptrs(), CTF_int.get_imag(), CTF_int.get_len_ordering(), CTF::Tensor< dtype >.get_local_data(), CTF::Tensor< dtype >.get_mapped_data(), CTF::Monoid_Kernel< dtype_C, g >.get_MPI_Op(), CTF::Tensor< dtype >.get_raw_data(), CTF_int.get_real(), CTF::Scalar< dtype >.get_val(), CTF::Monoid< dtype, is_ord >.init(), CTF::Set< dtype, is_ord >.init(), CTF::Monoid_Kernel< dtype_C, g >.init_shell(), CTF::Set< dtype, is_ord >.init_shell(), CTF_int::tensor.larger_equal_than(), CTF_int::tensor.larger_than(), CTF::Set< dtype, is_ord >.max(), CTF::Set< dtype, is_ord >.min(), CTF::Monoid_Kernel< dtype_C, g >.Monoid_Kernel(), CTF_int.muladd_csrmm(), CTF::Tensor< dtype >.norm_infty(), CTF_int::tensor.not_equals(), CTF::Sparse_Tensor< dtype >.operator dtype *(), CTF::Sparse_Tensor< dtype >.operator+=(), CTF::Sparse_Tensor< dtype >.operator-=(), CTF::Sparse_Tensor< dtype >.operator=(), CTF_int.parse_sparse_tensor_data(), CTF_int.pow_helper(), CTF::Matrix< dtype >.print_matrix(), CTF::Matrix< dtype >.qr(), CTF::Tensor< dtype >.read_local(), CTF::Matrix< dtype >.read_mat(), CTF.read_sparse_from_file_base(), CTF.real_norm1(), rec_scan(), CTF::Tensor< dtype >.reduce(), CTF::Group< dtype, is_ord >.safeaddinv(), CTF::Ring< dtype, is_ord >.safeaddinv(), CTF::Scalar< dtype >.Scalar(), CTF::Semiring< dtype, is_ord >.Semiring(), CTF_int.seq_coo_to_csr(), CTF_int.seq_csr_to_coo(), CTF::Set< dtype, is_ord >.set(), CTF_int.set_imag(), CTF::Set< dtype, is_ord >.set_pair(), CTF_int.set_real(), CTF::Scalar< dtype >.set_val(), CTF::Tensor< dtype >.slice(), CTF_int::tensor.smaller_equal_than(), CTF_int::tensor.smaller_than(), CTF::Sparse_Tensor< dtype >.Sparse_Tensor(), CTF::Tensor< dtype >.sparsify(), CTF_int::summation.sum_tensors(), CTF::Matrix< dtype >.svd(), CTF::Tensor< dtype >.Tensor(), CTF_int::tensor.true_divide(), and CTF::Matrix< dtype >.write_mat().

ctf.core.SYM = _enum(NS=0, SY=1, AS=2, SH=3)

Definition at line 238 of file core.pyx.

ctf.core.tm

Definition at line 327 of file core.pyx.

dictionary ctf.core.type_index = {}

Definition at line 41 of file core.pyx.