Skip to content

Commit 1759542

Browse files
committed
remove commented out old code
1 parent 8d28df7 commit 1759542

File tree

1 file changed

+2
-267
lines changed

1 file changed

+2
-267
lines changed

src_python/ctf/core.pyx

Lines changed: 2 additions & 267 deletions
Original file line numberDiff line numberDiff line change
@@ -379,26 +379,6 @@ cdef class itensor(term):
379379
tsr_copy = tensor(copy=self.tsr)
380380
tsr_copy.set_all(other)
381381
deref((<itensor>self).it) << deref(itensor(tsr_copy,self.string).it)
382-
# if self.dtype == np.float64:
383-
# elif self.dtype == np.float32:
384-
# deref((<itensor>self).it) << <float>other
385-
# elif self.dtype == np.complex128:
386-
# deref((<itensor>self).it) << <double complex>other
387-
# elif self.dtype == np.complex64:
388-
# deref((<itensor>self).it) << <complex>other
389-
# elif self.dtype == np.bool:
390-
# deref((<itensor>self).it) << <bool>other
391-
# elif self.dtype == np.int64:
392-
# deref((<itensor>self).it) << <int64_t>other
393-
# elif self.dtype == np.int32:
394-
# deref((<itensor>self).it) << <int32_t>other
395-
# elif self.dtype == np.int16:
396-
# deref((<itensor>self).it) << <int16_t>other
397-
# elif self.dtype == np.int8:
398-
# deref((<itensor>self).it) << <int8_t>other
399-
# else:
400-
# raise ValueError('CTF PYTHON ERROR: bad dtype')
401-
402382

403383
def __cinit__(self, tensor a, string):
404384
self.it = new Idx_Tensor(a.dt, string.encode())
@@ -2165,44 +2145,13 @@ def dot(tA, tB, out=None):
21652145

21662146
A = astensor(tA)
21672147
B = astensor(tB)
2168-
#elif type(A)==tensor and type(B)!=tensor:
2169-
# ret_dtype = get_np_dtype([A.dtype, type(B)])
21702148

2171-
# if A.dtype == ret_dtype:
2172-
# temp = A
2173-
# else:
2174-
# temp = A.astype(ret_dtype)
2175-
# string = get_num_str(len(A.shape))
2176-
# ret = tensor(A.shape, dtype = ret_dtype)
2177-
# ret.i(string) << B * temp.i(string)
2178-
# return ret
2179-
#elif type(A)!=tensor and type(B)==tensor:
2180-
# ret_dtype = get_np_dtype([type(A), B.dtype])
2181-
2182-
# if ret_dtype == B.dtype:
2183-
# temp = B
2184-
# else:
2185-
# temp = B.astype(ret_dtype)
2186-
# string = get_num_str(len(A.shape))
2187-
# ret = tensor(B.shape, dtype = ret_dtype)
2188-
# ret.i(string) << A * temp.i(string)
2189-
# return ret
2190-
#elif type(A)==tensor and type(B)==tensor:
21912149
return tensordot(A, B, axes=([-1],[0]))
2192-
#else:
2193-
# return tensordot(astensor(A), astensor(B), axes=([-1],[0]))
2194-
# raise ValueError("Wrong Type")
21952150

21962151
def tensordot(tA, tB, axes=2):
21972152
A = astensor(tA)
21982153
B = astensor(tB)
21992154

2200-
# when axes equals integer
2201-
#if type(axes) == int and axes <= 0:
2202-
#ret_shape = A.shape + B.shape
2203-
#C = tensor(ret_shape, dtype = np.float64)
2204-
#C.i("abcdefg") << A.i("abcd") * B.i("efg")
2205-
#return C
22062155
if isinstance(axes, (int, np.integer)):
22072156
if axes > len(A.shape) or axes > len(B.shape):
22082157
raise ValueError("tuple index out of range")
@@ -2520,28 +2469,7 @@ def sum(tensor init_A, axis = None, dtype = None, out = None, keepdims = None):
25202469
return ret.reshape(np.ones(tensor.shape))
25212470
else:
25222471
return ret.read_all()[0]
2523-
#else:
2524-
# since the type is not same, we need another tensor C change the value of A and use C instead of A
2525-
# C = tensor(A.shape, dtype = dtype)
2526-
# A.convert_type(C)
2527-
# ret = tensor(ret_dim, dtype = dtype)
2528-
# ret.i("") << C.i(index_A)
2529-
# return ret
2530-
#else:
2531-
# if A.get_type() == np.bool:
2532-
# # not sure at this one
2533-
# return 0
2534-
# else:
2535-
# if dtype == A.get_type():
2536-
# ret = tensor((1,), dtype = dtype)
2537-
# ret.i("") << A.i(index_A)
2538-
# vals = ret.read([0])
2539-
# return vals[0]
2540-
# else:
2541-
# C = tensor(A.shape, dtype = dtype)
2542-
# A.convert_type(C)
2543-
# ret = tensor((1,), dtype = dtype)
2544-
# ret.i("") << C.i(index_A)
2472+
25452473

25462474
# is the axis is an integer
25472475
if isinstance(axis, (int, np.integer)):
@@ -2873,174 +2801,6 @@ def comp_all(tensor A, axis=None, out=None, keepdims=None):
28732801
if axis is None:
28742802
x = A.bool_sum()
28752803
return x == A.tot_size()
2876-
#if out is not None:
2877-
# if type(out) != np.ndarray:
2878-
# raise ValueError('CTF PYTHON ERROR: output must be an array')
2879-
# if out.shape != () and keepdims == False:
2880-
# raise ValueError('CTF PYTHON ERROR: output parameter has too many dimensions')
2881-
# if keepdims == True:
2882-
# dims_keep = []
2883-
# for i in range(len(A.shape)):
2884-
# dims_keep.append(1)
2885-
# dims_keep = tuple(dims_keep)
2886-
# if out.shape != dims_keep:
2887-
# raise ValueError('CTF PYTHON ERROR: output must match when keepdims = True')
2888-
#B = tensor((1,), dtype=np.bool)
2889-
#index_A = ""
2890-
#if A.get_type() == np.float64:
2891-
# all_helper[double](<ctensor*>(A.dt), <ctensor*>B.dt, index_A.encode(), "".encode())
2892-
#elif A.get_type() == np.int64:
2893-
# all_helper[int64_t](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), "".encode())
2894-
#elif A.get_type() == np.int32:
2895-
# all_helper[int32_t](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), "".encode())
2896-
#elif A.get_type() == np.int16:
2897-
# all_helper[int16_t](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), "".encode())
2898-
#elif A.get_type() == np.int8:
2899-
# all_helper[int8_t](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), "".encode())
2900-
#elif A.get_type() == np.bool:
2901-
# all_helper[bool](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), "".encode())
2902-
#if out is not None:
2903-
# if out.dtype != B.get_type():
2904-
# if keepdims == True:
2905-
# dim_keep = np.ones(len(A.shape),dtype=np.int64)
2906-
# ret = reshape(B,dim_keep)
2907-
# C = tensor((1,), dtype=out.dtype)
2908-
# B.convert_type(C)
2909-
# n, inds, vals = C.read_local()
2910-
# return vals.reshape(out.shape)
2911-
# else:
2912-
# if keepdims == True:
2913-
# dim_keep = np.ones(len(A.shape),dtype=np.int64)
2914-
# ret = reshape(B,dim_keep)
2915-
# return ret
2916-
# n, inds, vals = B.read_local()
2917-
# return vals.reshape(out.shape)
2918-
#if keepdims == True:
2919-
# dim_keep = np.ones(len(A.shape),dtype=np.int64)
2920-
# ret = reshape(B,dim_keep)
2921-
# return ret
2922-
#n, inds, vals = B.read_local()
2923-
#return vals[0]
2924-
2925-
# when the axis is not None
2926-
#dim = A.shape
2927-
#if type(axis) == int:
2928-
# if axis < 0:
2929-
# axis += len(dim)
2930-
# if axis >= len(dim) or axis < 0:
2931-
# raise ValueError("'axis' entry is out of bounds")
2932-
# dim_ret = np.delete(dim, axis)
2933-
# # print(dim_ret)
2934-
# if out is not None:
2935-
# if type(out) != np.ndarray:
2936-
# raise ValueError('CTF PYTHON ERROR: output must be an array')
2937-
# if len(dim_ret) != len(out.shape):
2938-
# raise ValueError('CTF PYTHON ERROR: output parameter dimensions mismatch')
2939-
# for i in range(len(dim_ret)):
2940-
# if dim_ret[i] != out.shape[i]:
2941-
# raise ValueError('CTF PYTHON ERROR: output parameter dimensions mismatch')
2942-
# dim_keep = None
2943-
# if keepdims == True:
2944-
# dim_keep = dim
2945-
# dim_keep[axis] = 1
2946-
# if out is not None:
2947-
# if tuple(dim_keep) != tuple(out.shape):
2948-
# raise ValueError('CTF PYTHON ERROR: output must match when keepdims = True')
2949-
# index_A = ""
2950-
# index_temp = rev_array(index_A)
2951-
# index_B = index_temp[0:axis] + index_temp[axis+1:len(dim)]
2952-
# index_B = rev_array(index_B)
2953-
# # print(index_A, " ", index_B)
2954-
# B = tensor(dim_ret, dtype=np.bool)
2955-
# if A.get_type() == np.float64:
2956-
# all_helper[double](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
2957-
# elif A.get_type() == np.int64:
2958-
# all_helper[int64_t](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
2959-
# elif A.get_type() == np.int32:
2960-
# all_helper[int32_t](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
2961-
# elif A.get_type() == np.int16:
2962-
# all_helper[int16_t](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
2963-
# elif A.get_type() == np.int8:
2964-
# all_helper[int8_t](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
2965-
# elif A.get_type() == np.bool:
2966-
# all_helper[bool](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
2967-
# if out is not None:
2968-
# if out.dtype != B.get_type():
2969-
# if keepdims == True:
2970-
# C = tensor(dim_ret, dtype=out.dtype)
2971-
# B.convert_type(C)
2972-
# return reshape(C, dim_keep)
2973-
# else:
2974-
# C = tensor(dim_ret, dtype=out.dtype)
2975-
# B.convert_type(C)
2976-
# return C
2977-
# if keepdims == True:
2978-
# return reshape(B, dim_keep)
2979-
# return B
2980-
#elif type(axis) == tuple or type(axis) == np.ndarray:
2981-
# axis = np.asarray(axis, dtype=np.int64)
2982-
# dim_keep = None
2983-
# if keepdims == True:
2984-
# dim_keep = dim
2985-
# for i in range(len(axis)):
2986-
# dim_keep[axis[i]] = 1
2987-
# if out is not None:
2988-
# if tuple(dim_keep) != tuple(out.shape):
2989-
# raise ValueError('CTF PYTHON ERROR: output must match when keepdims = True')
2990-
# for i in range(len(axis.shape)):
2991-
# if axis[i] < 0:
2992-
# axis[i] += len(dim)
2993-
# if axis[i] >= len(dim) or axis[i] < 0:
2994-
# raise ValueError("'axis' entry is out of bounds")
2995-
# for i in range(len(axis.shape)):
2996-
# if np.count_nonzero(axis==axis[i]) > 1:
2997-
# raise ValueError("duplicate value in 'axis'")
2998-
# dim_ret = np.delete(dim, axis)
2999-
# if out is not None:
3000-
# if type(out) != np.ndarray:
3001-
# raise ValueError('CTF PYTHON ERROR: output must be an array')
3002-
# if len(dim_ret) != len(out.shape):
3003-
# raise ValueError('CTF PYTHON ERROR: output parameter dimensions mismatch')
3004-
# for i in range(len(dim_ret)):
3005-
# if dim_ret[i] != out.shape[i]:
3006-
# raise ValueError('CTF PYTHON ERROR: output parameter dimensions mismatch')
3007-
# B = tensor(dim_ret, dtype=np.bool)
3008-
# index_A = ""
3009-
# index_temp = rev_array(index_A)
3010-
# index_B = ""
3011-
# for i in range(len(dim)):
3012-
# if i not in axis:
3013-
# index_B += index_temp[i]
3014-
# index_B = rev_array(index_B)
3015-
# # print(" ", index_A, " ", index_B)
3016-
# if A.get_type() == np.float64:
3017-
# all_helper[double](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
3018-
# elif A.get_type() == np.int64:
3019-
# all_helper[int64_t](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
3020-
# elif A.get_type() == np.int32:
3021-
# all_helper[int32_t](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
3022-
# elif A.get_type() == np.int16:
3023-
# all_helper[int16_t](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
3024-
# elif A.get_type() == np.int8:
3025-
# all_helper[int8_t](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
3026-
# elif A.get_type() == np.bool:
3027-
# all_helper[bool](<ctensor*>A.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
3028-
# if out is not None:
3029-
# if out.dtype != B.get_type():
3030-
# if keepdims == True:
3031-
# C = tensor(dim_ret, dtype=out.dtype)
3032-
# B.convert_type(C)
3033-
# return reshape(C, dim_keep)
3034-
# else:
3035-
# C = tensor(dim_ret, dtype=out.dtype)
3036-
# B.convert_type(C)
3037-
# return C
3038-
# if keepdims == True:
3039-
# return reshape(B, dim_keep)
3040-
# return B
3041-
#else:
3042-
# raise ValueError("an integer is required")
3043-
#return None
30442804

30452805
# issues:
30462806
# when the input is numpy array
@@ -3069,15 +2829,7 @@ def transpose(init_A, axes=None):
30692829
if axes[i] < 0:
30702830
raise ValueError("axes too negative for CTF transpose")
30712831

3072-
#all_axes = np.arange(A.ndim)
3073-
#for j in range(A.ndim):
3074-
# if j != i:
3075-
# if axes[j] < 0:
3076-
# raise ValueError("cannot have negative two negative axes for transpose")
3077-
# all_axes[j] = -1
3078-
#for j in range(A.ndim):
3079-
# if all_axes[j] != -1:
3080-
# axes[i] = j
2832+
30812833
axes_list = list(axes)
30822834
for i in range(len(axes)):
30832835
# when any elements of axes is not an integer
@@ -3256,23 +3008,6 @@ def svd(tensor A, rank=None):
32563008
matrix_svd(A.dt, VT.dt, S.dt, U.dt, rank)
32573009
return [U, S, VT]
32583010

3259-
# A = tensor([n, n], dtype=dtype)
3260-
# if dtype == np.float64:
3261-
# A.i("ii") << 1.0
3262-
# else:
3263-
# raise ValueError('CTF PYTHON ERROR: bad dtype')
3264-
# return A
3265-
3266-
#cdef ct f
3267-
#ef int (*cfunction) (double a, double b, double c, void *args)
3268-
#
3269-
#cdef int cfunction_cb(double a, double b, double c, void *args):
3270-
# global f
3271-
# result_from_function = (<object>f)(a, b, c, *<tuple>args)
3272-
# for k in range(fdim):
3273-
# fval[k] = fval_buffer[k]
3274-
# return 0
3275-
32763011

32773012
def match_tensor_types(first, other):
32783013
if isinstance(first, tensor):

0 commit comments

Comments
 (0)