Skip to content

Commit

Permalink
Merge branch 'master' into feature/8116_fltabs_code_tidy
Browse files Browse the repository at this point in the history
Conflicts:
	Code/Mantid/scripts/Inelastic/IndirectAbsCor.py

Refs #8116
  • Loading branch information
Samuel Jackson committed Nov 15, 2013
2 parents 8ea6f97 + a24b9e6 commit 76cecb9
Show file tree
Hide file tree
Showing 73 changed files with 2,197 additions and 1,645 deletions.
4 changes: 2 additions & 2 deletions Code/Mantid/Build/CMake/VersionNumber.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Set the version number here for MantidVersion and the package filenames

set ( VERSION_MAJOR 2 )
set ( VERSION_MINOR 6 )
set ( VERSION_MAJOR 3 )
set ( VERSION_MINOR 0 )

# UNCOMMENT the next 'set' line to 'force' the patch version number to
# a value (instead of using the count coming out of 'git describe')
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ if ( ENABLE_CPACK )
elseif( ${UNIX_CODENAME} STREQUAL "precise" )
set ( CPACK_DEBIAN_PACKAGE_DEPENDS "libboost-date-time1.46.1,libboost-regex1.46.1,libpocofoundation9,libpocoutil9,libpoconet9,libpoconetssl9,libpococrypto9,libpocoxml9,libnexus0 (>= 4.3),python-nxs (>= 4.3),libgsl0ldbl,libqtcore4 (>= 4.2),libqtgui4 (>= 4.2),libqt4-opengl (>= 4.2),libqt4-xml (>= 4.2),libqt4-svg (>= 4.2),libqt4-qt3support (>= 4.2),libqscintilla2-8,libqwt5-qt4,libqwtplot3d-qt4-0" )
set ( CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libopencascade-foundation-6.5.0 (>= 6.5.0),libopencascade-modeling-6.5.0 (>= 6.5.0),libmuparser0debian1,python-numpy,python-sip,python-qt4,libboost-python${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}" )
# scipy, matploitlib & ipython
set ( CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},ipython-qtconsole,python-matplotlib,python-scipy" )
# scipy, matplotlib & ipython
set ( CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},ipython-qtconsole (>= 1.1),python-matplotlib,python-scipy" )
else()
message( WARNING "Mantid does not support packaging of this Ubuntu version: ${UNIX_CODENAME}")
endif()
Expand Down
3 changes: 1 addition & 2 deletions Code/Mantid/Framework/Algorithms/src/SumEventsByLogValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ namespace Algorithms
{
// Find the value of the log at the time of this event
const double logValue = log->getSingleValue( pulseTimes[eventIndex] );
// TODO: Refactor getBinIndex to use a binary search and allow out-of-range values
if ( logValue >= XValues.front() && logValue < XValues.back() )
{
PARALLEL_ATOMIC
Expand All @@ -445,7 +444,7 @@ namespace Algorithms
}
PARALLEL_CHECK_INTERUPT_REGION

// For now, the errors are the sqrt of the counts. TODO: change as part of weighted event handling
// The errors are the sqrt of the counts so long as we don't deal with weighted events.
std::transform( Y.begin(),Y.end(),outputWorkspace->dataE(0).begin(), (double(*)(double)) std::sqrt );

setProperty("OutputWorkspace",outputWorkspace);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Crystal/src/SortPeaksWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace Mantid
sortCriteria.push_back(std::pair<std::string, bool>(columnToSortBy, sortAscending));
outputWS->sort(sortCriteria);
setProperty("OutputWorkspace", outputWS);
} catch (std::invalid_argument& ex)
} catch (std::invalid_argument&)
{
this->g_log.error("Specified ColumnToSortBy does not exist");
throw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
//----------------------------------------------------------------------
#include "MantidCurveFitting/BackgroundFunction.h"

#include <boost/scoped_array.hpp>
#include <boost/shared_ptr.hpp>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_bspline.h>
#include <valarray>

namespace Mantid
{
Expand Down Expand Up @@ -72,7 +71,8 @@ namespace Mantid
void getGSLBreakPoints( std::vector<double>& bp) const;

/// structure used by GSL internally
gsl_bspline_workspace *m_bsplineWorkspace;
boost::shared_ptr<gsl_bspline_workspace> m_bsplineWorkspace;
mutable boost::shared_ptr<gsl_bspline_deriv_workspace> m_bsplineDerivWorkspace;
};

} // namespace CurveFitting
Expand Down
130 changes: 105 additions & 25 deletions Code/Mantid/Framework/CurveFitting/src/BSpline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The parameter names have the form 'yi' where 'y' is letter 'y' and 'i' is the pa
//----------------------------------------------------------------------
#include "MantidCurveFitting/BSpline.h"
#include "MantidCurveFitting/GSLVector.h"
#include "MantidCurveFitting/GSLMatrix.h"
#include "MantidAPI/FunctionFactory.h"

#include <boost/lexical_cast.hpp>
Expand All @@ -28,10 +29,30 @@ namespace Mantid

DECLARE_FUNCTION(BSpline)

namespace
{
// shared pointer deleter for bspline workspace
struct ReleaseBSplineWorkspace
{
void operator()(gsl_bspline_workspace* ws)
{
gsl_bspline_free( ws );
}
};
// shared pointer deleter for bspline derivative workspace
struct ReleaseBSplineDerivativeWorkspace
{
void operator()(gsl_bspline_deriv_workspace* ws)
{
gsl_bspline_deriv_free( ws );
}
};
}

/**
* Constructor
*/
BSpline::BSpline():m_bsplineWorkspace(NULL)
BSpline::BSpline():m_bsplineWorkspace(),m_bsplineDerivWorkspace()
{
const size_t nbreak = 10;
declareAttribute( "Uniform", Attribute( true ));
Expand All @@ -44,14 +65,14 @@ namespace Mantid

resetGSLObjects();
resetParameters();
resetKnots();
}

/**
* Destructor
*/
BSpline::~BSpline()
{
gsl_bspline_free( m_bsplineWorkspace );
}

/** Execute the function
Expand All @@ -66,6 +87,12 @@ namespace Mantid
GSLVector B(np);
double startX = getAttribute("StartX").asDouble();
double endX = getAttribute("EndX").asDouble();

if ( startX >= endX )
{
throw std::invalid_argument("BSpline: EndX must be greater than StartX.");
}

for(size_t i = 0; i < nData; ++i)
{
double x = xValues[i];
Expand All @@ -75,7 +102,7 @@ namespace Mantid
}
else
{
gsl_bspline_eval(x, B.gsl(), m_bsplineWorkspace);
gsl_bspline_eval(x, B.gsl(), m_bsplineWorkspace.get());
double val = 0.0;
for(size_t j = 0; j < np; ++j)
{
Expand All @@ -96,10 +123,44 @@ namespace Mantid
*/
void BSpline::derivative1D(double* out, const double* xValues, size_t nData, const size_t order) const
{
UNUSED_ARG(out);
UNUSED_ARG(xValues);
UNUSED_ARG(nData);
UNUSED_ARG(order);

int splineOrder = getAttribute("Order").asInt();
size_t k = static_cast<size_t>(splineOrder);
if ( !m_bsplineDerivWorkspace )
{
gsl_bspline_deriv_workspace *ws = gsl_bspline_deriv_alloc( k );
m_bsplineDerivWorkspace = boost::shared_ptr<gsl_bspline_deriv_workspace>( ws, ReleaseBSplineDerivativeWorkspace() );
}

GSLMatrix B(k, order+1);
double startX = getAttribute("StartX").asDouble();
double endX = getAttribute("EndX").asDouble();

if ( startX >= endX )
{
throw std::invalid_argument("BSpline: EndX must be greater than StartX.");
}

for(size_t i = 0; i < nData; ++i)
{
double x = xValues[i];
if ( x < startX || x > endX )
{
out[i] = 0.0;
}
else
{
size_t jstart(0);
size_t jend(0);
gsl_bspline_deriv_eval_nonzero(x, order, B.gsl(), &jstart, &jend, m_bsplineWorkspace.get(), m_bsplineDerivWorkspace.get());
double val = 0.0;
for(size_t j = jstart; j <= jend; ++j)
{
val += getParameter(j) * B.get(j-jstart,order);
}
out[i] = val;
}
}
}

/** Set an attribute for the function
Expand All @@ -117,15 +178,11 @@ namespace Mantid
{
resetKnots();
}
else if ( attName == "NBreak" )
{
resetGSLObjects();
resetParameters();
}
else if ( attName == "Order" )
else if ( attName == "NBreak" || attName == "Order" )
{
resetGSLObjects();
resetParameters();
resetKnots();
}

}
Expand All @@ -150,13 +207,19 @@ namespace Mantid
*/
void BSpline::resetGSLObjects()
{
if ( m_bsplineWorkspace != NULL )
{
gsl_bspline_free( m_bsplineWorkspace );
}
int order = getAttribute("Order").asInt();
int nbreak = getAttribute("NBreak").asInt();
m_bsplineWorkspace = gsl_bspline_alloc ( static_cast<size_t>(order), static_cast<size_t>(nbreak) );
if ( order <= 0 )
{
throw std::invalid_argument("BSpline: Order must be greater than zero.");
}
if ( nbreak < 2 )
{
throw std::invalid_argument("BSpline: NBreak must be at least 2.");
}
gsl_bspline_workspace *ws = gsl_bspline_alloc ( static_cast<size_t>(order), static_cast<size_t>(nbreak) );
m_bsplineWorkspace = boost::shared_ptr<gsl_bspline_workspace>( ws, ReleaseBSplineWorkspace() );
m_bsplineDerivWorkspace.reset();
}

/**
Expand All @@ -168,14 +231,13 @@ namespace Mantid
{
clearAllParameters();
}
size_t np = gsl_bspline_ncoeffs( m_bsplineWorkspace );
size_t np = gsl_bspline_ncoeffs( m_bsplineWorkspace.get() );
for(size_t i = 0; i < np; ++i)
{
std::string pname = "A" + boost::lexical_cast<std::string>( i );
declareParameter( pname );
}

resetKnots();
}

/**
Expand All @@ -191,19 +253,37 @@ namespace Mantid
// create uniform knots in the interval [StartX, EndX]
double startX = getAttribute("StartX").asDouble();
double endX = getAttribute("EndX").asDouble();
gsl_bspline_knots_uniform( startX, endX, m_bsplineWorkspace );
gsl_bspline_knots_uniform( startX, endX, m_bsplineWorkspace.get() );
getGSLBreakPoints( breakPoints );
storeAttributeValue( "BreakPoints", Attribute(breakPoints) );
}
else
{
// set the break points from BreakPoints vector attribute, update other attributes
breakPoints = getAttribute( "BreakPoints" ).asVector();
// check that points are in ascending order
double prev = breakPoints[0];
for(size_t i = 1; i < breakPoints.size(); ++i)
{
double next = breakPoints[i];
if ( next <= prev )
{
throw std::invalid_argument("BreakPoints must be in ascending order.");
}
prev = next;
}
int nbreaks = getAttribute( "NBreak" ).asInt();
// if number of break points change do necessary updates
if ( static_cast<size_t>(nbreaks) != breakPoints.size() )
{
storeAttributeValue("NBreak", Attribute(static_cast<int>(breakPoints.size())) );
resetGSLObjects();
resetParameters();
}
GSLVector bp = breakPoints;
gsl_bspline_knots( bp.gsl(), m_bsplineWorkspace );
gsl_bspline_knots( bp.gsl(), m_bsplineWorkspace.get() );
storeAttributeValue( "StartX", Attribute(breakPoints.front()) );
storeAttributeValue( "EndX", Attribute(breakPoints.back()) );
storeAttributeValue( "NBreak", Attribute( static_cast<int>(breakPoints.size()) ) );
}
}

Expand All @@ -213,11 +293,11 @@ namespace Mantid
*/
void BSpline::getGSLBreakPoints(std::vector<double> &bp) const
{
size_t n = gsl_bspline_nbreak( m_bsplineWorkspace );
size_t n = gsl_bspline_nbreak( m_bsplineWorkspace.get() );
bp.resize( n );
for(size_t i = 0; i < n; ++i)
{
bp[i] = gsl_bspline_breakpoint( i, m_bsplineWorkspace );
bp[i] = gsl_bspline_breakpoint( i, m_bsplineWorkspace.get() );
}
}

Expand Down

0 comments on commit 76cecb9

Please sign in to comment.