Skip to content

Commit

Permalink
update 3.7.1 candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
tkittel committed Aug 2, 2023
1 parent 3c8296f commit baae36f
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 55 deletions.
27 changes: 22 additions & 5 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
v3.7.1 2023-07-31
v3.7.1 2023-08-02
* Update documentation to reflect availability on PyPI.
* Set a few policies in NCrystalConfig.cmake to make find_package(NCrystal)
work when CMake is new enough, but the downstream CMake project specifies
a very old version in their cmake_minimum_required statement (cf. github
issue #137).
* Set version-based policies in NCrystalConfig.cmake to make
find_package(NCrystal) work when CMake is new enough, but the downstream
CMake project nevertheless specifies a very old version in their
cmake_minimum_required statement (cf. github issue/discussion #137).
* Add NCrystal_LIBRARIES variables for downstream CMake-based projects with
legacy 2.x-style CMake code. If the GEANT4BINDINGS component is enabled,
also set G4NCrystal_LIBDIR, G4NCrystal_INCDIR, G4NCrystal_LIBNAME and
G4NCrystal_LIBRARIES variables, likewise intended for such legacy
projects. Note of course, that usage of such legacy CMake 2.x-style code
is discouraged.
* Include type_traits in NCDefs.hh, to potentially fix some compilation
errors seen in #137.
* Fix several minor bugs in NCrystal Python code which were discovered via
the ruff static code analysis tool.
* Change signature of all 0-argument functions in C-API in ncrystal.h from
f() to f(void), since the first form is apparently deprecated since 30
years and gives issues in clang 14
(cf. https://github.com/madler/zlib/issues/633 and
https://github.com/mctools/dgcode/issues/34).
* For NCrystal builds, change max version in cmake_minimum_required to
3.27.

v3.7.0 2023-07-14
* The main feature of this release is that NCrystal now can be optionally
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# for specifying this maximum value is that it affects the default values of
# cmake policies, depending on which version introduced them.

cmake_minimum_required(VERSION 3.10...3.25)
cmake_minimum_required(VERSION 3.10...3.27)
cmake_policy(SET CMP0054 NEW)

# Respect value of CMAKE_BUILD_TYPE if already defined, otherwise fall back to
Expand Down
2 changes: 1 addition & 1 deletion NCrystal/_miscimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def _expandegrid( egrid, dos ):
if _needsexpand(egrid,dos):
return _np_linspace( egrid[0], egrid[-1], len(dos) )
else:
return np.asfarray(egrid,dtype=float)
return _np.asfarray(egrid,dtype=float)
def integrate( expanded_egrid, dos ):
x,y = expanded_egrid, dos
if not x[0] > 0.0:
Expand Down
1 change: 1 addition & 0 deletions NCrystal/_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

def _ensure_numpy():
if not _np:
from .exceptions import NCException
raise NCException("Numpy not available - array based functionality is unavailable")
return _np

Expand Down
6 changes: 3 additions & 3 deletions NCrystal/cifutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ def lookupAndProduce( cifsrc, *,dynamics, remap):
if hasattr( data_or_file, '__fspath__' ):
pass
elif isinstance( data_or_file, _nc_core.TextData ):
mc = multcreate(td)
mc = multcreate( data_or_file )
contentiterable = data_or_file
fn = td.dataSourceName
fn = data_or_file.dataSourceName
elif isinstance( data_or_file, bytes ) or isinstance( data_or_file, str ):
_ = data_or_file.decode() if isinstance( data_or_file, bytes ) else data_or_file
if '\n' in _ or _.startswith('NCMAT'):
Expand Down Expand Up @@ -1383,7 +1383,7 @@ def _actual_init_gemmicif( cifsrc, *, quiet, mp_apikey, refine_with_spglib, merg
from math import fsum as _math_fsum

result = {}
pos_tolerance = 0.0001;#NB: Best if value matches the one in NCInfoBuilder.cc
pos_tolerance = 0.0001#NB: Best if value matches the one in NCInfoBuilder.cc

from types import MappingProxyType
dict_ro, list_ro = MappingProxyType, tuple
Expand Down
4 changes: 2 additions & 2 deletions NCrystal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def correspondingDynamicInfo(self):
available
"""
if self.__correspDI_wp is not None:
if self.__correspDI_wp == False:
if self.__correspDI_wp is False:
return None
di = self.__correspDI_wp()
nc_assert(di is not None,"AtomInfo.correspondingDynamicInfo can not"
Expand Down Expand Up @@ -775,7 +775,7 @@ def _key( self ):
def correspondingAtomInfo(self):
"""Get corresponding AtomInfo object from the same Info object. Returns None if Info object does not have AtomInfo available"""
if self.__correspAtomInfo_wp is not None:
if self.__correspAtomInfo_wp == False:
if self.__correspAtomInfo_wp is False:
return None
ai = self.__correspAtomInfo_wp()
nc_assert(ai is not None,"DynamicInfo.correspondingAtomInfo can not be used after associated Info object is deleted")
Expand Down
2 changes: 1 addition & 1 deletion NCrystal/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def alpha_limits(E_div_kT,beta):
cb = c + beta
assert cb>=0.0,f'c+beta={cb}, beta={beta}, c={c}'
a = cb + c
b = 2*_np.sqrt( c * cb );
b = 2*_np.sqrt( c * cb )
assert not _np.isinf(a).any()
assert not _np.isinf(b).any()
return max(0.0,a - b), a + b
Expand Down
2 changes: 1 addition & 1 deletion NCrystal/vdos.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ def impl(x):
if v is not None:
return v *unval
if v is None:
raise NCBadInput(f'Invalid threshold string: {s}')
raise NCBadInput(f'Invalid threshold string: {x}')
if hasattr(x,'__len__') and len(x)==2 and isinstance(x[1],str):
_,unitfactor = _parsevdosunit( x[1] )
v = _decodeflt( x[0] )
Expand Down
32 changes: 19 additions & 13 deletions cmake/NCrystalConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
# #
################################################################################

#Set a few policies to hopefully make this work when CMake is new enough, but
#the user have a very old version in their cmake_minimum_required statements
#(cf. github issue #137):
#First make sure our file work when CMake is new enough, but the user have a
#very old version in their cmake_minimum_required statements (cf. github
#discussion/issue #137):
cmake_policy(PUSH)#NB: We POP at the end of this file.
cmake_policy(SET CMP0007 NEW)
cmake_policy(SET CMP0012 NEW)
cmake_policy(SET CMP0057 NEW)
cmake_policy(VERSION 3.3...3.27)

#Export a few directory paths (relocatable):
set( NCrystal_CMAKEDIR "${CMAKE_CURRENT_LIST_DIR}" )
Expand Down Expand Up @@ -84,8 +82,9 @@ unset( _tmpnc_optsvals )
unset( _tmpnc_o )
unset( _tmpnc_v )

#Libname:
#Libname + old school NCrystal_LIBRARIES variable:
set( NCrystal_LIBNAME @NCrystal_LIBNAME@ )
set( NCrystal_LIBRARIES "${NCrystal_LIBDIR}/${NCrystal_LIBNAME}" )

#Various scripts:
if ( NCrystal_OPTION_INSTALL_PY )
Expand Down Expand Up @@ -122,13 +121,20 @@ set( NCrystal_COMPONENT_GEANT4BINDINGS OFF )
if ( NCrystal_OPTION_BUILD_G4HOOKS )
#Build with Geant4 bindings. However, only load these targets (and the Geant4
#dependency) if the GEANT4BINDINGS component was requested.
if ( "GEANT4BINDINGS" IN_LIST NCrystal_FIND_COMPONENTS )
if( NOT TARGET NCrystal::G4NCrystal )
include( CMakeFindDependencyMacro )
find_dependency( Geant4 @Geant4_VERSION@ EXACT REQUIRED )
include( "${NCrystal_CMAKEDIR}/G4NCrystalTargets.cmake" )
if ( NCrystal_FIND_COMPONENTS )#if statements guards against CMP0085-OLD:
if ( "GEANT4BINDINGS" IN_LIST NCrystal_FIND_COMPONENTS )
if( NOT TARGET NCrystal::G4NCrystal )
include( CMakeFindDependencyMacro )
find_dependency( Geant4 @Geant4_VERSION@ EXACT REQUIRED )
include( "${NCrystal_CMAKEDIR}/G4NCrystalTargets.cmake" )
endif()
set( NCrystal_COMPONENT_GEANT4BINDINGS ON )
#A few variables for old-school downstream cmake projects:
set( G4NCrystal_LIBNAME @G4NCrystal_LIBNAME@ )
set( G4NCrystal_LIBDIR "${NCrystal_LIBDIR}" )
set( G4NCrystal_INCDIR "${NCrystal_INCDIR}" )
set( G4NCrystal_LIBRARIES "${NCrystal_LIBRARIES}" "${G4NCrystal_LIBDIR}/${G4NCrystal_LIBNAME}" )
endif()
set( NCrystal_COMPONENT_GEANT4BINDINGS ON )
endif()
else()
if ( NCrystal_FIND_REQUIRED_GEANT4BINDINGS )
Expand Down
4 changes: 2 additions & 2 deletions examples/ncrystal_example_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
#include <stdio.h>
#include <stdlib.h>

double my_randgen() {
double my_randgen(void) {
/* Using rand from stdlib.h for this small example to generate numbers */
/* uniformly in (0,1] (note, this is NOT recommended for scientific work). */
return 1.0-rand() / (RAND_MAX + 1.);
}

int main() {
int main(void) {
/* declarations first (to support ancient pedantic C compilers) */
ncrystal_scatter_t pc, sc;
ncrystal_process_t pc_proc, sc_proc;
Expand Down
1 change: 1 addition & 0 deletions ncrystal_core/include/NCrystal/NCDefs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <tuple>//std::tuple, std::tie
//These we always include - simply because they otherwise have to be included in
//so many places:
#include <type_traits>
#include <string>
#include <vector>
#include <array>
Expand Down
26 changes: 13 additions & 13 deletions ncrystal_core/include/NCrystal/ncrystal.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ extern "C" {

/*If not halting on error, these functions can be used to access information */
/*about errors encountered: */
NCRYSTAL_API int ncrystal_error();/* returns 1 if an error condition occurred. */
NCRYSTAL_API const char * ncrystal_lasterror();/* returns description of last error (NULL if none) */
NCRYSTAL_API const char * ncrystal_lasterrortype();/* returns description of last error (NULL if none) */
NCRYSTAL_API int ncrystal_error(void);/* returns 1 if an error condition occurred. */
NCRYSTAL_API const char * ncrystal_lasterror(void);/* returns description of last error (NULL if none) */
NCRYSTAL_API const char * ncrystal_lasterrortype(void);/* returns description of last error (NULL if none) */
/* TODO: error file/line-no as well? */

NCRYSTAL_API void ncrystal_clearerror();/* clears previous error if any */
NCRYSTAL_API void ncrystal_clearerror(void);/* clears previous error if any */

/*Another option is to provide a custom error handler which will be called on */
/*each error: */
Expand All @@ -418,11 +418,11 @@ extern "C" {
/* threaded usage, the caller should ensure that the function is thread-safe and */
/* returns numbers from different streams in each thread (through suitable usage */
/* of thread_local objects perhaps). */
NCRYSTAL_API void ncrystal_setrandgen( double (*rg)() );
NCRYSTAL_API void ncrystal_setrandgen( double (*rg)(void) );

/* It is also possible to (re) set the RNG to the builtin generator (optionally */
/* by state or integer seed) */
NCRYSTAL_API void ncrystal_setbuiltinrandgen();
NCRYSTAL_API void ncrystal_setbuiltinrandgen(void);
NCRYSTAL_API void ncrystal_setbuiltinrandgen_withseed(unsigned long seed);
NCRYSTAL_API void ncrystal_setbuiltinrandgen_withstate(const char*);

Expand Down Expand Up @@ -466,7 +466,7 @@ extern "C" {

/* Add directory to custom search path or clear custom search path: */
NCRYSTAL_API void ncrystal_add_custom_search_dir( const char * dir );
NCRYSTAL_API void ncrystal_remove_custom_search_dirs();
NCRYSTAL_API void ncrystal_remove_custom_search_dirs(void);

/* Enable/disable standard search mechanisms (all enabled by default). For the */
/* case of ncrystal_enable_stddatalib, provide dir=NULL if you wish to use the */
Expand All @@ -479,7 +479,7 @@ extern "C" {

/* Remove all current data sources (supposedly in order to subsequently enable */
/* sources selectively). This also removes virtual files and caches. */
NCRYSTAL_API void ncrystal_remove_all_data_sources();
NCRYSTAL_API void ncrystal_remove_all_data_sources(void);


/*============================================================================== */
Expand Down Expand Up @@ -525,7 +525,7 @@ extern "C" {

/* Get all (Z,A) values in internal DB (A=0 means natural element). The second */
/* fct accepts two preallocated arrays with length given by the first fct: */
NCRYSTAL_API unsigned ncrystal_atomdatadb_getnentries();
NCRYSTAL_API unsigned ncrystal_atomdatadb_getnentries(void);
NCRYSTAL_API void ncrystal_atomdatadb_getallentries( unsigned* zvals,
unsigned* avals );

Expand All @@ -550,7 +550,7 @@ extern "C" {
NCRYSTAL_API char* ncrystal_normalisecfg( const char * cfgstr );

/* Clear various caches employed inside NCrystal: */
NCRYSTAL_API void ncrystal_clear_caches();
NCRYSTAL_API void ncrystal_clear_caches(void);

/* Get list of plugins. Resulting string list must be deallocated by a call to */
/* ncrystal_dealloc_stringlist by, and contains entries in the format */
Expand Down Expand Up @@ -583,8 +583,8 @@ extern "C" {
#define NCRYSTAL_VERSION_PATCH 1
#define NCRYSTAL_VERSION 3007001 /* (1000000*MAJOR+1000*MINOR+PATCH) */
#define NCRYSTAL_VERSION_STR "3.7.1"
NCRYSTAL_API int ncrystal_version(); /* returns NCRYSTAL_VERSION */
NCRYSTAL_API const char * ncrystal_version_str(); /* returns NCRYSTAL_VERSION_STR */
NCRYSTAL_API int ncrystal_version(void); /* returns NCRYSTAL_VERSION */
NCRYSTAL_API const char * ncrystal_version_str(void); /* returns NCRYSTAL_VERSION_STR */

/* Load raw NCMAT data into JSON structures. Must deallocate with call to */
/* ncrystal_dealloc_string as usual. (WARNING: JSON is incomplete for now!!!!!) */
Expand Down Expand Up @@ -635,7 +635,7 @@ extern "C" {
NCRYSTAL_API double ncrystal_decodecfg_packfact( const char * cfgstr );

/*Obsolete function which now just is an alias for ncrystal_clear_caches above: */
NCRYSTAL_API void ncrystal_clear_info_caches();
NCRYSTAL_API void ncrystal_clear_info_caches(void);

/*Obsolete function. Atom positions are now always available when */
/*ncrystal_info_natominfo returns a value greater than 0: */
Expand Down
26 changes: 13 additions & 13 deletions ncrystal_core/src/ncrystal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,22 @@ void ncrystal_seterrhandler(void (*handler)(char*,char*))
ncc::custom_error_handler = handler;
}

int ncrystal_error()
int ncrystal_error(void)
{
return ncc::waserror;
}

const char * ncrystal_lasterror()
const char * ncrystal_lasterror(void)
{
return ncc::waserror ? ncc::errmsg : 0;
}

const char * ncrystal_lasterrortype()
const char * ncrystal_lasterrortype(void)
{
return ncc::waserror ? ncc::errtype : 0;
}

void ncrystal_clearerror()
void ncrystal_clearerror(void)
{
ncc::waserror = 0;
}
Expand Down Expand Up @@ -1406,14 +1406,14 @@ ncrystal_absorption_t ncrystal_create_absorption( const char * cfgstr )
return {nullptr};
}

void ncrystal_clear_caches()
void ncrystal_clear_caches(void)
{
try {
NC::clearCaches();
} NCCATCH;
}

void ncrystal_clear_info_caches()
void ncrystal_clear_info_caches(void)
{
//deprecated, now simply redirects to ncrystal_clear_caches.
ncrystal_clear_caches();
Expand All @@ -1432,12 +1432,12 @@ int ncrystal_has_factory( const char* name )
return 0;
}

int ncrystal_version()
int ncrystal_version(void)
{
return NCRYSTAL_VERSION;
}

const char * ncrystal_version_str()
const char * ncrystal_version_str(void)
{
return NCRYSTAL_VERSION_STR;
}
Expand Down Expand Up @@ -1685,7 +1685,7 @@ ncrystal_atomdata_t ncrystal_create_atomdata_fromdbstr( const char* name )
return {nullptr};
}

unsigned ncrystal_atomdatadb_getnentries()
unsigned ncrystal_atomdatadb_getnentries(void)
{
try {
return NC::AtomDB::getAllEntriesCount();
Expand Down Expand Up @@ -1768,7 +1768,7 @@ void ncrystal_dealloc_string( char* ss )
delete[] ss;
}

void ncrystal_setrandgen( double (*rg)() )
void ncrystal_setrandgen( double (*rg)(void) )
{
try {
if (rg)
Expand All @@ -1778,7 +1778,7 @@ void ncrystal_setrandgen( double (*rg)() )
} NCCATCH;
}

void ncrystal_setbuiltinrandgen()
void ncrystal_setbuiltinrandgen(void)
{
try {
NC::setDefaultRNG( NC::createBuiltinRNG() );
Expand Down Expand Up @@ -1961,15 +1961,15 @@ void ncrystal_add_custom_search_dir( const char * dir )
} NCCATCH;
}

void ncrystal_remove_all_data_sources()
void ncrystal_remove_all_data_sources(void)
{
try {
NC::DataSources::removeAllDataSources();
} NCCATCH;
}


void ncrystal_remove_custom_search_dirs( )
void ncrystal_remove_custom_search_dirs(void)
{
try {
NC::DataSources::removeCustomSearchDirectories();
Expand Down

0 comments on commit baae36f

Please sign in to comment.