Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()

add_subdirectory(src/Core)
add_subdirectory(src/cil)

cmake_policy(POP)
2 changes: 1 addition & 1 deletion Wrappers/Python/cil/framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Authors:
# CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt

from .cilacc import cilacc
from cil import cilacc
from .acquisition_data import AcquisitionData
from .acquisition_geometry import AcquisitionGeometry, SystemConfiguration
from .data_container import DataContainer
Expand Down
9 changes: 2 additions & 7 deletions Wrappers/Python/cil/framework/cilacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
#
# Authors:
# CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt
import ctypes
from pathlib import Path
import cil.cilacc as cilacc

try:
cilacc_path = next((Path(__file__).parent.parent / 'lib').resolve().glob("*cilacc.*"))
except StopIteration:
raise FileNotFoundError("cilacc library not found")
cilacc = ctypes.cdll.LoadLibrary(str(cilacc_path))
cilacc = cilacc
43 changes: 11 additions & 32 deletions Wrappers/Python/cil/framework/data_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
# Authors:
# CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt
import copy
import ctypes
import warnings
from functools import reduce
from numbers import Number

import numpy

from .cilacc import cilacc
from cil import cilacc
from cil.utilities.multiprocessing import NUM_THREADS


Expand Down Expand Up @@ -636,8 +635,6 @@ def _axpby(self, a, b, y, out, dtype=numpy.float32, num_threads=NUM_THREADS):
:type num_threads: int, optional, default 1/2 CPU of the system
'''

c_float_p = ctypes.POINTER(ctypes.c_float)
c_double_p = ctypes.POINTER(ctypes.c_double)

#convert a and b to numpy arrays and get the reference to the data (length = 1 or ndx.size)
try:
Expand Down Expand Up @@ -676,19 +673,19 @@ def _axpby(self, a, b, y, out, dtype=numpy.float32, num_threads=NUM_THREADS):
ndb = ndb.astype(dtype, casting='same_kind')

if dtype == numpy.float32:
x_p = ndx.ctypes.data_as(c_float_p)
y_p = ndy.ctypes.data_as(c_float_p)
out_p = ndout.ctypes.data_as(c_float_p)
a_p = nda.ctypes.data_as(c_float_p)
b_p = ndb.ctypes.data_as(c_float_p)
x_p = ndx
y_p = ndy
out_p = ndout
a_p = nda
b_p = ndb
f = cilacc.saxpby

elif dtype == numpy.float64:
x_p = ndx.ctypes.data_as(c_double_p)
y_p = ndy.ctypes.data_as(c_double_p)
out_p = ndout.ctypes.data_as(c_double_p)
a_p = nda.ctypes.data_as(c_double_p)
b_p = ndb.ctypes.data_as(c_double_p)
x_p = ndx
y_p = ndy
out_p = ndout
a_p = nda
b_p = ndb
f = cilacc.daxpby

else:
Expand All @@ -698,24 +695,6 @@ def _axpby(self, a, b, y, out, dtype=numpy.float32, num_threads=NUM_THREADS):


# int psaxpby(float * x, float * y, float * out, float a, float b, long size)
cilacc.saxpby.argtypes = [ctypes.POINTER(ctypes.c_float), # pointer to the first array
ctypes.POINTER(ctypes.c_float), # pointer to the second array
ctypes.POINTER(ctypes.c_float), # pointer to the third array
ctypes.POINTER(ctypes.c_float), # pointer to A
ctypes.c_int, # type of type of A selector (int)
ctypes.POINTER(ctypes.c_float), # pointer to B
ctypes.c_int, # type of type of B selector (int)
ctypes.c_longlong, # type of size of first array
ctypes.c_int] # number of threads
cilacc.daxpby.argtypes = [ctypes.POINTER(ctypes.c_double), # pointer to the first array
ctypes.POINTER(ctypes.c_double), # pointer to the second array
ctypes.POINTER(ctypes.c_double), # pointer to the third array
ctypes.POINTER(ctypes.c_double), # type of A (c_double)
ctypes.c_int, # type of type of A selector (int)
ctypes.POINTER(ctypes.c_double), # type of B (c_double)
ctypes.c_int, # type of type of B selector (int)
ctypes.c_longlong, # type of size of first array
ctypes.c_int] # number of threads

if f(x_p, y_p, out_p, a_p, a_vec, b_p, b_vec, ndx.size, num_threads) != 0:
raise RuntimeError('axpby execution failed')
Expand Down
51 changes: 5 additions & 46 deletions Wrappers/Python/cil/optimisation/operators/GradientOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,49 +267,8 @@ def adjoint(self, x, out=None):
tmp += self.FD.adjoint(x.get_item(i))
return tmp

import ctypes

c_float_p = ctypes.POINTER(ctypes.c_float)

cilacc.openMPtest.restypes = ctypes.c_int32
cilacc.openMPtest.argtypes = [ctypes.c_int32]

cilacc.fdiff4D.restype = ctypes.c_int32
cilacc.fdiff4D.argtypes = [ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
ctypes.c_size_t,
ctypes.c_size_t,
ctypes.c_size_t,
ctypes.c_size_t,
ctypes.c_int32,
ctypes.c_int32,
ctypes.c_int32]

cilacc.fdiff3D.restype = ctypes.c_int32
cilacc.fdiff3D.argtypes = [ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
ctypes.c_size_t,
ctypes.c_size_t,
ctypes.c_size_t,
ctypes.c_int32,
ctypes.c_int32,
ctypes.c_int32]

cilacc.fdiff2D.restype = ctypes.c_int32
cilacc.fdiff2D.argtypes = [ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
ctypes.c_size_t,
ctypes.c_size_t,
ctypes.c_int32,
ctypes.c_int32,
ctypes.c_int32]

import cil.cilacc as cilacc

class Gradient_C(LinearOperator):

Expand Down Expand Up @@ -378,7 +337,7 @@ def ndarray_as_c_pointer(ndx):
def direct(self, x, out=None):

ndx = np.asarray(x.as_array(), dtype=np.float32, order='C')
x_p = Gradient_C.ndarray_as_c_pointer(ndx)
x_p = ndx

if out is None:
out = self.range_geometry().allocate(None)
Expand All @@ -391,7 +350,7 @@ def direct(self, x, out=None):
ndout.insert(ind, out.get_item(0).as_array()) #insert channels dc at correct point for channel data

#pass list of all arguments
arg1 = [Gradient_C.ndarray_as_c_pointer(ndout[i]) for i in range(len(ndout))]
arg1 = [ndout[i] for i in range(len(ndout))]
arg2 = [el for el in self.domain_shape]
args = arg1 + arg2 + [self.bnd_cond, 1, self.num_threads]
status = self.fd(x_p, *args)
Expand Down Expand Up @@ -424,7 +383,7 @@ def adjoint(self, x, out=None):
out = self.domain_geometry().allocate(None)

ndout = np.asarray(out.as_array(), dtype=np.float32, order='C')
out_p = Gradient_C.ndarray_as_c_pointer(ndout)
out_p = ndout

if self.split is False:
ndx = [el.as_array() for el in x.containers]
Expand All @@ -437,7 +396,7 @@ def adjoint(self, x, out=None):
if el != 1:
ndx[i]/=el

arg1 = [Gradient_C.ndarray_as_c_pointer(ndx[i]) for i in range(self.ndim)]
arg1 = [ndx[i] for i in range(self.ndim)]
arg2 = [el for el in self.domain_shape]
args = arg1 + arg2 + [self.bnd_cond, 0, self.num_threads]

Expand Down
24 changes: 3 additions & 21 deletions Wrappers/Python/cil/processors/cilacc_binner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
from cil.framework import cilacc

import numpy as np
import ctypes

c_float_p = ctypes.POINTER(ctypes.c_float)
c_size_t_p = ctypes.POINTER(ctypes.c_size_t)

class Binner_IPP(object):

Expand All @@ -48,30 +45,17 @@ def __init__(self, shape_in, shape_out, start_index, binning):

"""

cilacc.Binner_new.argtypes = [c_size_t_p,c_size_t_p,c_size_t_p,c_size_t_p]
cilacc.Binner_new.restype = ctypes.c_void_p

cilacc.Binner_bin.argtypes = [ ctypes.c_void_p, c_float_p,c_float_p]
cilacc.Binner_bin.restype = ctypes.c_int32

cilacc.Binner_delete.argtypes = [ ctypes.c_void_p]
cilacc.Binner_delete.restype = ctypes.c_void_p

shape_in_arr = np.array(shape_in, np.uintp)
shape_out_arr = np.array(shape_out, np.uintp)
start_index_arr = np.array(start_index, np.uintp)
binning_arr = np.array(binning, np.uintp)

shape_in_p = shape_in_arr.ctypes.data_as(c_size_t_p)
shape_out_p = shape_out_arr.ctypes.data_as(c_size_t_p)
ind_start_p = start_index_arr.ctypes.data_as(c_size_t_p)
binning_p = binning_arr.ctypes.data_as(c_size_t_p)

for i in range(4):
if shape_out_p[i] * binning_p[i] + ind_start_p[i] > shape_in_p[i]:
if shape_out_arr[i] * binning_arr[i] + start_index_arr[i] > shape_in_arr[i]:
raise ValueError("Input dimension mismatch on dimension {0}".format(i))

self.obj = cilacc.Binner_new(shape_in_p, shape_out_p, ind_start_p, binning_p)
self.obj = cilacc.Binner_new(shape_in_arr, shape_out_arr, start_index_arr, binning_arr)


def bin(self, array_in, array_binned):
Expand All @@ -88,10 +72,8 @@ def bin(self, array_in, array_binned):
array_binned : ndarray
Must have shape corresponding to shape_out. Data type float32. C ordered, contiguous memory
"""
data_p = array_in.ctypes.data_as(c_float_p)
data_out_p = array_binned.ctypes.data_as(c_float_p)

return cilacc.Binner_bin(self.obj, data_p, data_out_p)
return cilacc.Binner_bin(self.obj, array_in, array_binned)

def __del__(self):
"""This deletes the cilacc Binner object
Expand Down
26 changes: 3 additions & 23 deletions Wrappers/Python/cil/recon/FBP.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,15 @@
from scipy.fft import fftfreq

import numpy as np
import ctypes
from tqdm import tqdm

c_float_p = ctypes.POINTER(ctypes.c_float)
c_double_p = ctypes.POINTER(ctypes.c_double)

try:
cilacc.filter_projections_avh
has_ipp = True
except AttributeError:
has_ipp = False

if has_ipp:
cilacc.filter_projections_avh.argtypes = [ctypes.POINTER(ctypes.c_float), # pointer to the data array
ctypes.POINTER(ctypes.c_float), # pointer to the filter array
ctypes.POINTER(ctypes.c_float), # pointer to the weights array
ctypes.c_int16, #order of the fft
ctypes.c_long, #num_proj
ctypes.c_long, #pix_v
ctypes.c_long] #pix_x

cilacc.filter_projections_vah.argtypes = [ctypes.POINTER(ctypes.c_float), # pointer to the data array
ctypes.POINTER(ctypes.c_float), # pointer to the filter array
ctypes.POINTER(ctypes.c_float), # pointer to the weights array
ctypes.c_int16, #order of the fft
ctypes.c_long, #pix_v
ctypes.c_long, #num_proj
ctypes.c_long] #pix_x

class GenericFilteredBackProjection(Reconstructor):
"""
Abstract Base Class GenericFilteredBackProjection holding common and virtual methods for FBP and FDK
Expand Down Expand Up @@ -314,9 +294,9 @@ def _pre_filtering(self,acquistion_data):
.format(filter_array.size,self.fft_order))

#call ext function
data_ptr = acquistion_data.array.ctypes.data_as(c_float_p)
filter_ptr = filter_array.ctypes.data_as(c_float_p)
weights_ptr = self._weights.ctypes.data_as(c_float_p)
data_ptr = acquistion_data.array
filter_ptr = filter_array
weights_ptr = self._weights

ag = acquistion_data.geometry
if ag.dimension_labels == ('angle','vertical','horizontal'):
Expand Down
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ requires = [
"setuptools>=64",
"setuptools_scm>=8",
"scikit-build-core>=0.10",
#"ipp-devel==2021.12.*", # PyPI conflicts with conda package
"nanobind",
"ipp-devel>=2022.1",
"ipp-static>=2022.1",
"intel-openmp",
]
build-backend = "scikit_build_core.build"

Expand Down Expand Up @@ -62,7 +65,7 @@ dependencies = [
"h5py",
#"ipp==2021.12.*", # PyPI conflicts with conda package
"numba",
"numpy>=1.23",
"numpy>=1.23,<2.0",
"olefile>=0.46",
"pillow",
"pywavelets",
Expand All @@ -76,7 +79,7 @@ plugins = [
#"tomophantom==2.0.0", # [linux] # missing from PyPI
]
gpu = [
"astra-toolbox>=1.9.9.dev5,<=2.1", # [not osx]
"astra-toolbox", # [not osx]
#"tigre>=2.4,<=2.6", # missing from PyPI
]
[dependency-groups]
Expand Down
2 changes: 1 addition & 1 deletion recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL=%PKG_VERSION%
if not "%GIT_DESCRIBE_NUMBER%"=="0" (
set SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL=%PKG_VERSION%.dev%GIT_DESCRIBE_NUMBER%+%GIT_DESCRIBE_HASH%
)
pip install . --no-deps
uv pip install . --no-deps
if errorlevel 1 exit 1
2 changes: 1 addition & 1 deletion recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL="${PKG_VERSION}"
if test "${GIT_DESCRIBE_NUMBER}" != "0"; then
export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL="${PKG_VERSION}.dev${GIT_DESCRIBE_NUMBER}+${GIT_DESCRIBE_HASH}"
fi
pip install . --no-deps -Ccmake.args="${extra_args}"
uv pip install . --no-deps
2 changes: 1 addition & 1 deletion recipe/conda_build_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#creates pairs of versions using zip_keys, lists must be the same length
ipp_version:
- '2021.12'
- '2022.1'
python:
- 3.10
- 3.10
Expand Down
10 changes: 1 addition & 9 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ test:
requirements:
build:
- python
- numpy {{ numpy }}
- pip
- setuptools >=64
- setuptools_scm >=8
- uv
- cmake # [not osx]
- cmake >=3.16 # [osx]
- libgcc-ng # [linux]
Expand All @@ -51,10 +48,6 @@ requirements:
- openmp # [osx]
- vc 14 # [win]
- ninja # [not win]
- ipp-include {{ ipp_version }}
- ipp-devel {{ ipp_version }}
- ipp {{ ipp_version }}
- scikit-build-core >=0.10

run:
- python
Expand All @@ -71,7 +64,6 @@ requirements:
- olefile >=0.46
- pywavelets
- cil-data >=22
- {{ pin_compatible('ipp', min_pin='x.x', max_pin='x.x') }}
- tqdm
- numba

Expand Down
Loading