Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cyclops-community/ctf
Browse files Browse the repository at this point in the history
  • Loading branch information
solomonik committed Aug 30, 2022
2 parents e25b8a6 + ff99cf7 commit c3ca4af
Show file tree
Hide file tree
Showing 13 changed files with 432 additions and 362 deletions.
128 changes: 128 additions & 0 deletions .github/workflows/autotest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Based on Nick Naso's cpp.yml workflow, https://gist.github.com/NickNaso/0d478f1481686d5bcc868cac06620a60

on:
push:
pull_request:
release:

jobs:
build_cpp:
name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- {
name: "Ubuntu_Latest_GCC",
os: ubuntu-latest,
artifact: "ubuntu_gcc.7z",
build_type: "Release",
cc: "gcc",
cxx: "g++",
archiver: "7z a",
}
- {
name: "Ubuntu_GCC_9",
os: ubuntu-latest,
artifact: "ubuntu_gcc9.7z",
build_type: "Release",
cc: "gcc",
cxx: "g++",
archiver: "7z a",
}
- {
name: "macOS Latest Clang",
os: macos-latest,
artifact: "macos_clang.7z",
build_type: "Release",
cc: "clang",
cxx: "clang++",
archiver: "7za a",
}
build_scalapack: [True, False]
steps:
- uses: actions/checkout@v2

- name: Print env
run: |
echo github.event.action: ${{ github.event.action }}
echo github.event_name: ${{ github.event_name }}
echo matrix.config.build_scalapack
echo ${{ matrix.config.build_scalapack }}
- name: Install dependencies on ubuntu
if: startsWith(matrix.config.name, 'Ubuntu')
run: |
sudo apt-get update;
sudo apt install -y g++ gfortran git make libblas-dev liblapack-dev mpich
- name: Install dependencies on macos
if: startsWith(matrix.config.os, 'macos')
run: |
brew install gcc mpich
- name: Configure Cyclops and Build Scalapack
if: matrix.config.build_scalapack
shell: bash
run:
./configure CXXFLAGS="-O0" --build-scalapack

- name: Configure Cyclops without Scalapack
if: ( ! matrix.config.build_scalapack )
shell: bash
run:
./configure CXXFLAGS="-O0"


- name: Build Cyclops
shell: bash
run:
make -j4

- name: Build Tests and Test Cyclops C++
run:
make test

- name: Test Cyclops C++ with 2 MPI processes
if: startsWith(matrix.config.name, 'Ubuntu')
shell: bash
run:
export OMP_NUM_THREADS=1;
make test2


- name: Build Python Install dependencies on ubuntu
if: startsWith(matrix.config.name, 'Ubuntu')
run: |
sudo apt install -y python3-dev virtualenv;
mkdir envs
- name: Build Python Install dependencies on macos
if: startsWith(matrix.config.os, 'macos')
run: |
brew install virtualenv
- name: Create Python virtual environment and install dependencies via pip
run: |
virtualenv -p python3 ./envs/py3env;
source ./envs/py3env/bin/activate;
pip install numpy cython
- name: Build Python library
run:
source ./envs/py3env/bin/activate;
make python

- name: Test Cyclops Python
run:
source ./envs/py3env/bin/activate;
make python_test

- name: Test Cyclops Python with 2 MPI processes
if: startsWith(matrix.config.name, 'Ubuntu')
shell: bash
run:
source ./envs/py3env/bin/activate;
export OMP_NUM_THREADS=1;
make python_test2
57 changes: 0 additions & 57 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pip: $(BDIR)/setup.py $(BDIR)/lib_shared/libctf.so $(PYTHON_SRC_FILES)
cd src_python; \
ln -sf $(BDIR)/setup.py setup.py; \
mkdir -p $(BDIR)/lib_python/ctf && cp ctf/__init__.py $(BDIR)/lib_python/ctf/; \
pip install --force -b $(BDIR)/lib_python/ . --upgrade; \
pip install --force . --upgrade; \
rm setup.py; \
cd ..;

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
## Cyclops Tensor Framework (CTF)
[<img src="https://travis-ci.org/cyclops-community/ctf.svg?branch=master">](https://travis-ci.org/cyclops-community/ctf)

Cyclops is a parallel (distributed-memory) numerical library for multidimensional arrays (tensors) in C++ and Python.

Expand Down
42 changes: 21 additions & 21 deletions src_python/ctf/tensor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ cdef class tensor:
if dtype is float:
dtype = np.float64

if dtype == np.complex:
if dtype == complex:
dtype = np.complex128


Expand All @@ -447,7 +447,7 @@ cdef class tensor:
self.sym = np.asarray([0]*self.ndim)
else:
self.sym = np.asarray(sym)
if self.dtype == np.bool:
if self.dtype == np.bool_:
self.itemsize = 1
else:
self.itemsize = np.dtype(self.dtype).itemsize
Expand Down Expand Up @@ -488,7 +488,7 @@ cdef class tensor:
self.dt = new Tensor[complex64_t](self.ndim, sp, clens, csym, wrld[0], idx.encode(), prl.ip[0], blk.ip[0])
if self.dtype == np.complex128:
self.dt = new Tensor[complex128_t](self.ndim, sp, clens, csym, wrld[0], idx.encode(), prl.ip[0], blk.ip[0])
if self.dtype == np.bool:
if self.dtype == np.bool_:
self.dt = new Tensor[bool](self.ndim, sp, clens, csym, wrld[0], idx.encode(), prl.ip[0], blk.ip[0])
if self.dtype == np.int64:
self.dt = new Tensor[int64_t](self.ndim, sp, clens, csym, wrld[0], idx.encode(), prl.ip[0], blk.ip[0])
Expand All @@ -507,7 +507,7 @@ cdef class tensor:
self.dt = new Tensor[complex64_t](self.ndim, sp, clens, csym)
elif self.dtype == np.complex128:
self.dt = new Tensor[complex128_t](self.ndim, sp, clens, csym)
elif self.dtype == np.bool:
elif self.dtype == np.bool_:
self.dt = new Tensor[bool](self.ndim, sp, clens, csym)
elif self.dtype == np.int64:
self.dt = new Tensor[int64_t](self.ndim, sp, clens, csym)
Expand Down Expand Up @@ -601,7 +601,7 @@ cdef class tensor:
raise ValueError("Universal functions among tensors with different order, i.e. Fortran vs C are not currently supported")
out_order = self.order
out_dtype = ctf.helper._get_np_dtype([self.dtype, other.dtype])
out_dims = np.zeros(np.maximum(self.ndim, other.ndim), dtype=np.int)
out_dims = np.zeros(np.maximum(self.ndim, other.ndim), dtype=int)
out_sp = min(self.sp,other.sp)
out_sym = [SYM.NS]*len(out_dims)
ind_coll = ctf.helper._get_num_str(3*out_dims.size)
Expand Down Expand Up @@ -833,7 +833,7 @@ cdef class tensor:
self.dt.true_divide[int16_t](<ctensor*>self.dt)
elif self.dtype == np.int8:
self.dt.true_divide[int8_t](<ctensor*>self.dt)
elif self.dtype == np.bool:
elif self.dtype == np.bool_:
self.dt.true_divide[bool](<ctensor*>self.dt)

def __matmul__(self, other):
Expand Down Expand Up @@ -1064,7 +1064,7 @@ cdef class tensor:
dims_keep = tuple(dims_keep)
if out.shape != dims_keep:
raise ValueError('CTF PYTHON ERROR: output must match when keepdims = True')
B = tensor((1,), dtype=np.bool)
B = tensor((1,), dtype=np.bool_)
index_A = ctf.helper._get_num_str(self.ndim)
if self.dtype == np.float64:
all_helper[double](<ctensor*>self.dt, <ctensor*>B.dt, index_A.encode(), "".encode())
Expand All @@ -1076,7 +1076,7 @@ cdef class tensor:
all_helper[int16_t](<ctensor*>self.dt, <ctensor*>B.dt, index_A.encode(), "".encode())
elif self.dtype == np.int8:
all_helper[int8_t](<ctensor*>self.dt, <ctensor*>B.dt, index_A.encode(), "".encode())
elif self.dtype == np.bool:
elif self.dtype == np.bool_:
all_helper[bool](<ctensor*>self.dt, <ctensor*>B.dt, index_A.encode(), "".encode())
if out is not None:
if out.dtype != B.get_type():
Expand Down Expand Up @@ -1129,12 +1129,12 @@ cdef class tensor:
index_temp = ctf.helper._rev_array(index_A)
index_B = index_temp[0:axis] + index_temp[axis+1:len(dim)]
index_B = ctf.helper._rev_array(index_B)
B = tensor(dim_ret, dtype=np.bool)
B = tensor(dim_ret, dtype=np.bool_)
if self.dtype == np.float64:
all_helper[double](<ctensor*>self.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
elif self.dtype == np.int64:
all_helper[int64_t](<ctensor*>self.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
elif self.dtype == np.bool:
elif self.dtype == np.bool_:
all_helper[bool](<ctensor*>self.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
elif self.dtype == np.int32:
all_helper[int32_t](<ctensor*>self.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
Expand Down Expand Up @@ -1182,7 +1182,7 @@ cdef class tensor:
for i in range(len(dim_ret)):
if dim_ret[i] is not out.shape[i]:
raise ValueError('CTF PYTHON ERROR: output parameter dimensions mismatch')
B = tensor(dim_ret, dtype=np.bool)
B = tensor(dim_ret, dtype=np.bool_)
index_A = ctf.helper._get_num_str(self.ndim)
index_temp = ctf.helper._rev_array(index_A)
index_B = ""
Expand All @@ -1200,7 +1200,7 @@ cdef class tensor:
all_helper[int16_t](<ctensor*>self.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
elif self.dtype == np.int8:
all_helper[int8_t](<ctensor*>self.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
elif self.dtype == np.bool:
elif self.dtype == np.bool_:
all_helper[bool](<ctensor*>self.dt, <ctensor*>B.dt, index_A.encode(), index_B.encode())
if out is not None:
if out.dtype is not B.get_type():
Expand Down Expand Up @@ -1617,7 +1617,7 @@ cdef class tensor:
if dtype == float:
dtype = np.float64
if str(dtype) == "<class 'bool'>":
dtype = np.bool
dtype = np.bool_
if str(dtype) == "<class 'complex'>":
dtype = np.complex128
B = tensor(self.shape, sp=self.sp, dtype = dtype)
Expand All @@ -1628,10 +1628,10 @@ cdef class tensor:
dtype = np.int64
if dtype == float:
dtype = np.float64
# np.bool doesnot have itemsize
if (self.dtype != np.bool and dtype != np.bool) and self.itemsize > dtype.itemsize:
# np.bool_ doesnot have itemsize
if (self.dtype != np.bool_ and dtype != np.bool_) and self.itemsize > dtype.itemsize:
raise ValueError("Cannot cast array from dtype({0}) to dtype({1}) according to the rule 'safe'".format(self.dtype,dtype))
if dtype == np.bool and self.dtype != np.bool:
if dtype == np.bool_ and self.dtype != np.bool_:
raise ValueError("Cannot cast array from dtype({0}) to dtype({1}) according to the rule 'safe'".format(self.dtype,dtype))
str_self = str(self.dtype)
str_dtype = str(dtype)
Expand Down Expand Up @@ -1670,7 +1670,7 @@ cdef class tensor:
raise ValueError("Cannot cast array from dtype({0}) to dtype({1}) according to the rule 'same_kind'".format(self.dtype,dtype))
if 'complex' in str_self and ('int' in str_dtype or ('float' in str_dtype)):
raise ValueError("Cannot cast array from dtype({0}) to dtype({1}) according to the rule 'same_kind'".format(self.dtype,dtype))
if self.dtype != np.bool and dtype == np.bool:
if self.dtype != np.bool_ and dtype == np.bool_:
raise ValueError("Cannot cast array from dtype({0}) to dtype({1}) according to the rule 'same_kind'".format(self.dtype,dtype))
else:
raise ValueError("casting must be one of 'no', 'equiv', 'safe', 'same_kind', or 'unsafe'")
Expand Down Expand Up @@ -2058,8 +2058,8 @@ cdef class tensor:
# cdef cnp.ndarray buf = np.empty(len(iinds), dtype=np.dtype([('a','i8'),('b',self.dtype)],align=False))
cdef char * alpha
cdef char * beta
# if type is np.bool, assign the st with 1, since bool does not have itemsize in numpy
if self.dtype == np.bool:
# if type is np.bool_, assign the st with 1, since bool does not have itemsize in numpy
if self.dtype == np.bool_:
st = 1
else:
st = self.itemsize
Expand Down Expand Up @@ -2257,7 +2257,7 @@ cdef class tensor:
else:
self.write([],[])
return
if isinstance(value, (np.int, np.float, np.complex, np.number)):
if isinstance(value, (int, float, complex, np.number)):
tval = np.asarray([value],dtype=self.dtype)[0]
else:
tval = ctf.tensor_aux.astensor(value,dtype=self.dtype)
Expand Down Expand Up @@ -2659,7 +2659,7 @@ cdef class tensor:
else:
new_shape.append(b.shape[i])

c = tensor(new_shape, dtype=np.bool, sp=self.sp)
c = tensor(new_shape, dtype=np.bool_, sp=self.sp)
# <
if op == 0:
c.dt.elementwise_smaller(<ctensor*>self.dt,<ctensor*>b.dt)
Expand Down
Loading

0 comments on commit c3ca4af

Please sign in to comment.