Skip to content

Commit eca99b8

Browse files
authored
Merge pull request #60 from CosmoStat/minor
Minor
2 parents 0318132 + 0582917 commit eca99b8

6 files changed

Lines changed: 66 additions & 50 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ endif()
4848
message(STATUS "CMake Build Type: ${CMAKE_BUILD_TYPE}")
4949

5050
# Set RPATH options
51-
set(CMAKE_INSTALL_RPATH "${CMAKE_BINARY_DIR}/lib")
51+
set(CMAKE_BUILD_RPATH "@loader_path/../lib:/usr/lib::/usr/local/lib")
52+
set(CMAKE_INSTALL_RPATH "@loader_path/../lib:/usr/lib::/usr/local/lib")
5253

5354
# ----------------- #
5455
# Find Dependencies #

cmake/BuildFFTW3.cmake

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set(FFTW_CONFIG_FLAGS
2121
--enable-threads
2222
--enable-sse2
2323
--enable-openmp
24+
LDFLAGS="-L/path/to/libomp -lomp"
2425
)
2526

2627
# Download and build FFTW3
@@ -39,4 +40,21 @@ ExternalProject_Add(fftw3_build
3940
# Set FFTW3 variables
4041
set(FFTW3_LIBRARY_DIRS ${CMAKE_BINARY_DIR}/lib/ CACHE INTERNAL "")
4142
set(FFTW3_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/include/ CACHE INTERNAL "")
42-
set(FFTW3_LIBRARIES -lfftw3 -lfftw3f CACHE INTERNAL "")
43+
44+
# Define FFTW3::Float
45+
add_library(FFTW3::Float SHARED IMPORTED GLOBAL)
46+
set_target_properties(FFTW3::Float PROPERTIES
47+
IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/lib/libfftw3f.dylib"
48+
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR}/include"
49+
INTERFACE_LINK_LIBRARIES OpenMP::OpenMP_CXX
50+
)
51+
52+
# Define FFTW3::Double
53+
add_library(FFTW3::Double SHARED IMPORTED GLOBAL)
54+
set_target_properties(FFTW3::Double PROPERTIES
55+
IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/lib/libfftw3.dylib"
56+
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR}/include"
57+
INTERFACE_LINK_LIBRARIES OpenMP::OpenMP_CXX
58+
)
59+
60+

cmake/BuildPybind.cmake

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,27 @@ function(build_pybind_target target libs)
3535
# Extract the target name
3636
get_filename_component(tarname ${target} NAME_WLE)
3737

38-
# Add the target library
39-
add_library(${tarname} SHARED ${target})
38+
if(NOT TARGET ${tarname})
4039

41-
# Link libraries to target
42-
target_link_libraries(${tarname} "${libs}" OpenMP::OpenMP_CXX pybind11::headers)
40+
# Add the target library
41+
add_library(${tarname} SHARED ${target})
4342

44-
# Set system dependend properties
45-
if(APPLE)
46-
set_target_properties(${tarname} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
47-
else(APPLE)
48-
target_link_libraries(${tarname} ${Python_LIBRARIES})
49-
endif(APPLE)
43+
# Link libraries to target
44+
target_link_libraries(${tarname} "${libs}" OpenMP::OpenMP_CXX pybind11::headers)
5045

51-
# Set target prefix and suffix properties
52-
pybind11_extension(${tarname})
53-
pybind11_strip(${tarname})
46+
# Set system dependend properties
47+
if(APPLE)
48+
set_target_properties(${tarname} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
49+
else(APPLE)
50+
target_link_libraries(${tarname} ${Python_LIBRARIES})
51+
endif(APPLE)
5452

55-
# Set the install path for bindings
56-
install(TARGETS ${tarname} DESTINATION ${PYBIND_INSTALL_PATH})
53+
# Set target prefix and suffix properties
54+
pybind11_extension(${tarname})
55+
pybind11_strip(${tarname})
56+
57+
# Set the install path for bindings
58+
install(TARGETS ${tarname} DESTINATION ${PYBIND_INSTALL_PATH})
59+
endif()
5760

5861
endfunction()

src/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,12 @@ if(BUILD_PYBIND)
250250
# Build bindings
251251
build_pybind("${core_libs}" FALSE)
252252
# Note: Uncomment the following line when pymrs issues have been resolved
253-
# if(ONLY_SPARSE)
254-
# build_pybind("${core_libs}" FALSE)
255-
# else()
256-
# set(pybind_deps ${mrs_libs} ${HEALPIX_LIBRARIES} ${core_libs})
257-
# build_pybind("${pybind_deps}" TRUE)
258-
# endif()
259-
253+
if(ONLY_SPARSE)
254+
build_pybind("${core_libs}" FALSE)
255+
else()
256+
set(pybind_deps ${mrs_libs} ${HEALPIX_LIBRARIES} ${core_libs})
257+
build_pybind("${pybind_deps}" TRUE)
258+
endif()
260259
endif()
261260

262261
# ----------#

src/python_binding/alm.hpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ C_ALM::C_ALM(bool verbose)
7676
// (the -1 is used to live one thread to the main process which ensures
7777
// better and more constant performances). - Fabrice Poupon 2013/03/09
7878
#ifdef _OPENMP
79-
if (nb_procs <= 0)
80-
this->nb_procs = omp_get_num_procs() - 1;
81-
else
82-
this->nb_procs = nb_procs;
79+
int np = omp_get_num_procs();
80+
this->nb_procs = (np > 1) ? np - 1 : 1;
8381
omp_set_num_threads(this->nb_procs);
8482
#endif
8583
}
@@ -136,14 +134,13 @@ py::array_t<xcomplex<REAL>> C_ALM::get_tabalm()
136134
{
137135
int Nl=alm.Lmax()+1;
138136
int nelem= Nl*Nl;
139-
auto arr = py::array_t<xcomplex<REAL>>(nelem);
137+
auto arr = py::array_t<xcomplex<REAL>>({Nl, Nl});
140138
auto buffer = arr.request();
141139
xcomplex<REAL> *pointer = (xcomplex<REAL> *) buffer.ptr;
142140

143141
for (int l=0; l <= alm.Lmax(); l++)
144142
for (int m=0; m <= l; m++)
145143
pointer[l + m * Nl] = alm(l,m);
146-
arr.resize({Nl, Nl});
147144
return arr;
148145
}
149146

@@ -164,6 +161,8 @@ void C_ALM::wiener(py::array_t<float>& psn, py::array_t<float>& pss)
164161
int Nl = alm.Lmax()+1;
165162
auto buffer = pss.request();
166163
float *pointer = (float *) buffer.ptr;
164+
Cls.alloc(Nl);
165+
Cln.alloc(Nl);
167166
for (int i=0; i<Nl;i++) Cls(i) = pointer[i];
168167
buffer = psn.request();
169168
pointer = (float *) buffer.ptr;
@@ -179,16 +178,14 @@ py::array_t<float> C_ALM::alm2spec()
179178
PowSpec ps_data;
180179
alm.alm2powspec(ps_data);
181180
int Nl = alm.Lmax()+1;
182-
auto arr = py::array_t<xcomplex<REAL>>(Nl);
181+
py::array_t<REAL> arr(Nl);
183182
auto buffer = arr.request();
184-
xcomplex<REAL> *pointer = (xcomplex<REAL> *) buffer.ptr;
183+
REAL* pointer = (REAL*) buffer.ptr;
185184
for (int l=0; l < Nl; l++)
186185
pointer[l] = ps_data.tt(l);
187186
return arr;
188187
}
189188

190-
// py::array_t<float> alm2powspec();
191-
192189

193190
/*
194191

src/python_binding/mrs.hpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ MRS::MRS(bool verbose)
9595

9696
// Destructor
9797
MRS::~MRS(){
98-
mr_initialized=False;
99-
nb_procs=0;
100-
Verbose=False;
98+
mr_initialized=False;
99+
nb_procs=0;
100+
Verbose=False;
101101
}
102102

103103
// int MRS::get_lmax(int & Lmax, int Nside, float ZeroPadding)
@@ -122,7 +122,7 @@ void MRS::alloc(int Nside, int Nscale, int LmaxIn, int ALM_iter, bool Verb)
122122
float ZeroPadding=0.;
123123
int LM=LmaxIn;
124124
int Lmax = mrs_get_lmax (LM, Nside, ZeroPadding);
125-
cout << "ALLOC: " << Nside << " " << Nscale << " " << LmaxIn << " " << ALM_iter << endl;
125+
// cout << "ALLOC: " << Nside << " " << Nscale << " " << LmaxIn << " " << ALM_iter << endl;
126126
WT.wt_alloc(Nside, Nscale, Lmax, nested); // DEF_MRS_ORDERING);
127127
WT.ALM_iter = ALM_iter;
128128
if (Verb) Verbose=Verb;
@@ -133,14 +133,11 @@ void MRS::alloc(int Nside, int Nscale, int LmaxIn, int ALM_iter, bool Verb)
133133
py::array_t<float> MRS::uwt(py::array_t<float>& arr, int Ns)
134134
{
135135
Verbose=True;
136-
cout << "Input arr.ndim() = " << arr.ndim() << " " << arr.shape(0) << endl;
136+
// cout << "Input arr.ndim() = " << arr.ndim() << " " << arr.shape(0) << endl;
137137
if (arr.ndim() != 1)
138138
throw std::runtime_error("Input should be 1-D NumPy array");
139139

140-
141-
cout << "OK" << endl;
142-
exit(-1);
143-
140+
// cout << "OK" << endl;
144141

145142
auto buffer = arr.request();
146143
float *pointer = (float *) buffer.ptr;
@@ -156,7 +153,7 @@ py::array_t<float> MRS::uwt(py::array_t<float>& arr, int Ns)
156153
throw std::runtime_error("Input map has not expected nside.");
157154
}
158155

159-
cout << "alloc ok. Nside = " << Nside << " " << Ns << ", Npix = " << Npix << endl;
156+
// cout << "alloc ok. Nside = " << Nside << " " << Ns << ", Npix = " << Npix << endl;
160157

161158
// Copy the numpy array into a healpix map
162159
Hdmap Map;
@@ -168,27 +165,28 @@ py::array_t<float> MRS::uwt(py::array_t<float>& arr, int Ns)
168165

169166
// Wavelet transform
170167
WT.transform(Map);
171-
cout << "transform ok. " << endl;
168+
// cout << "transform ok. " << endl;
172169

173170
// Recopy to numpy array
174-
auto arr1 = py::array_t<float>(Npix*WT.nscale());
171+
auto arr1 = py::array_t<float>({WT.nscale(), Npix});
175172
auto buf1 = arr1.request();
176-
pointer = (float *) buf1.ptr;
173+
pointer = static_cast<float*>(buf1.ptr);
174+
177175
for(int s=0; s < WT.nscale(); s++)
178176
for (int i=0; i<Npix; i++)
179177
{
180178
pointer[i + s * Npix] = WT.WTTrans(i,s);
181179
}
182-
cout << "copy ok. Npix =" << Npix << endl;
180+
// cout << "copy ok. Npix =" << Npix << endl;
183181

184-
arr1.resize({WT.nscale(), Npix});
185-
cout << "resize dim = " << arr1.ndim() << " " << arr1.shape(1)<< " " << arr1.shape(0) << endl;
186182
return arr1;
187183

188184
}
189185

190186
py::array_t<float> MRS::get_tabnorm()
191187
{
188+
int n = WT.TabNorm.nx();
189+
if (n <= 0) throw std::runtime_error("TabNorm has invalid size");
192190
auto arr1 = py::array_t<float>(WT.TabNorm.nx());
193191
auto buf1 = arr1.request();
194192
float *pointer = (float *) buf1.ptr;

0 commit comments

Comments
 (0)