Skip to content

Commit

Permalink
Merge pull request #15 from lsst/tickets/DM-5879
Browse files Browse the repository at this point in the history
DM-5879 Remove use of Boost smart pointers throughout the Science Pipelines
  • Loading branch information
Pim Schellart authored and Pim Schellart committed May 4, 2016
2 parents 248d50c + 1d71e9d commit a59151e
Show file tree
Hide file tree
Showing 24 changed files with 167 additions and 167 deletions.
28 changes: 14 additions & 14 deletions examples/pixelAccess.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Eigen/Core"
#include "boost/shared_ptr.hpp"
#include <memory>
#include "boost/timer.hpp"

#include "lsst/afw/geom.h"
Expand Down Expand Up @@ -36,16 +36,16 @@ Eigen::MatrixXd test(afwImage::Image<ImageT> varianceEstimate,

if (cswitch == 3) {
/* a list of images - in diffim each one of these is associated with a basis function */
std::vector<boost::shared_ptr<Eigen::VectorXd> > imageList(nParameters);
typename std::vector<boost::shared_ptr<Eigen::VectorXd> >::iterator eiter = imageList.begin();
std::vector<std::shared_ptr<Eigen::VectorXd> > imageList(nParameters);
typename std::vector<std::shared_ptr<Eigen::VectorXd> >::iterator eiter = imageList.begin();
afwImage::Image<ImageT> cimage(varianceEstimate.getDimensions());
for (int i = 1; eiter != imageList.end(); ++eiter, ++i) {
cimage = i; /* give it a value */
Eigen::MatrixXd cMat = diffim::imageToEigenMatrix(cimage).block(startRow, startCol,
endRow-startRow,
endCol-startCol);
cMat.resize(cMat.rows()*cMat.cols(), 1);
boost::shared_ptr<Eigen::VectorXd> vMat (new Eigen::VectorXd(cMat.col(0)));
std::shared_ptr<Eigen::VectorXd> vMat (new Eigen::VectorXd(cMat.col(0)));
*eiter = vMat;
}

Expand All @@ -58,8 +58,8 @@ Eigen::MatrixXd test(afwImage::Image<ImageT> varianceEstimate,
Eigen::VectorXd eigeniVarianceV = eigeniVarianceM.col(0);

Eigen::MatrixXd cMat(eigeniVarianceV.size(), nParameters);
typename std::vector<boost::shared_ptr<Eigen::VectorXd> >::iterator eiterj = imageList.begin();
typename std::vector<boost::shared_ptr<Eigen::VectorXd> >::iterator eiterE = imageList.end();
typename std::vector<std::shared_ptr<Eigen::VectorXd> >::iterator eiterj = imageList.begin();
typename std::vector<std::shared_ptr<Eigen::VectorXd> >::iterator eiterE = imageList.end();
for (unsigned int kidxj = 0; eiterj != eiterE; eiterj++, kidxj++) {
cMat.block(0, kidxj, eigeniVarianceV.size(), 1) =
Eigen::MatrixXd(**eiterj).block(0, 0, eigeniVarianceV.size(), 1);
Expand All @@ -75,8 +75,8 @@ Eigen::MatrixXd test(afwImage::Image<ImageT> varianceEstimate,
}
else if (cswitch == 2) {
/* a list of images - in diffim each one of these is associated with a basis function */
std::vector<boost::shared_ptr<Eigen::VectorXd> > imageList(nParameters);
typename std::vector<boost::shared_ptr<Eigen::VectorXd> >::iterator eiter = imageList.begin();
std::vector<std::shared_ptr<Eigen::VectorXd> > imageList(nParameters);
typename std::vector<std::shared_ptr<Eigen::VectorXd> >::iterator eiter = imageList.begin();
afwImage::Image<ImageT> cimage(varianceEstimate.getDimensions());
for (int i = 1; eiter != imageList.end(); ++eiter, ++i) {
cimage = i; /* give it a value */
Expand All @@ -85,7 +85,7 @@ Eigen::MatrixXd test(afwImage::Image<ImageT> varianceEstimate,
endRow-startRow,
endCol-startCol);
cMat.resize(cMat.rows()*cMat.cols(), 1);
boost::shared_ptr<Eigen::VectorXd> vMat (new Eigen::VectorXd(cMat.col(0)));
std::shared_ptr<Eigen::VectorXd> vMat (new Eigen::VectorXd(cMat.col(0)));
*eiter = vMat;
}

Expand All @@ -97,12 +97,12 @@ Eigen::MatrixXd test(afwImage::Image<ImageT> varianceEstimate,
eigeniVarianceM.resize(eigeniVarianceM.rows()*eigeniVarianceM.cols(), 1);
Eigen::VectorXd eigeniVarianceV = eigeniVarianceM.col(0);

typename std::vector<boost::shared_ptr<Eigen::VectorXd> >::iterator eiteri = imageList.begin();
typename std::vector<boost::shared_ptr<Eigen::VectorXd> >::iterator eiterE = imageList.end();
typename std::vector<std::shared_ptr<Eigen::VectorXd> >::iterator eiteri = imageList.begin();
typename std::vector<std::shared_ptr<Eigen::VectorXd> >::iterator eiterE = imageList.end();
for (unsigned int kidxi = 0; eiteri != eiterE; eiteri++, kidxi++) {
Eigen::VectorXd eiteriDotiVariance = ((*eiteri)->array() * eigeniVarianceV.array()).matrix();

typename std::vector<boost::shared_ptr<Eigen::VectorXd> >::iterator eiterj = eiteri;
typename std::vector<std::shared_ptr<Eigen::VectorXd> >::iterator eiterj = eiteri;
for (unsigned int kidxj = kidxi; eiterj != eiterE; eiterj++, kidxj++) {
mMat(kidxi, kidxj) = (eiteriDotiVariance.array() * (**eiterj).array()).sum();
mMat(kidxj, kidxi) = mMat(kidxi, kidxj);
Expand All @@ -113,8 +113,8 @@ Eigen::MatrixXd test(afwImage::Image<ImageT> varianceEstimate,
else {

/* a list of images - in diffim each one of these is associated with a basis function */
std::vector<boost::shared_ptr<afwImage::Image<ImageT> > > imageList(nParameters);
typename std::vector<boost::shared_ptr<afwImage::Image<ImageT> > >::iterator citer=imageList.begin();
std::vector<std::shared_ptr<afwImage::Image<ImageT> > > imageList(nParameters);
typename std::vector<std::shared_ptr<afwImage::Image<ImageT> > >::iterator citer=imageList.begin();
for (int i = 1; citer != imageList.end(); ++citer, ++i) {
*citer = typename afwImage::Image<ImageT>::Ptr(
new afwImage::Image<ImageT>(varianceEstimate.getDimensions())
Expand Down
4 changes: 2 additions & 2 deletions include/lsst/ip/diffim/AssessSpatialKernelVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace detail {
class AssessSpatialKernelVisitor : public lsst::afw::math::CandidateVisitor {
typedef lsst::afw::image::MaskedImage<PixelT> MaskedImageT;
public:
typedef boost::shared_ptr<AssessSpatialKernelVisitor<PixelT> > Ptr;
typedef std::shared_ptr<AssessSpatialKernelVisitor<PixelT> > Ptr;

AssessSpatialKernelVisitor(
lsst::afw::math::LinearCombinationKernel::Ptr spatialKernel, ///< Spatially varying kernel
Expand Down Expand Up @@ -56,7 +56,7 @@ namespace detail {
};

template<typename PixelT>
boost::shared_ptr<AssessSpatialKernelVisitor<PixelT> >
std::shared_ptr<AssessSpatialKernelVisitor<PixelT> >
makeAssessSpatialKernelVisitor(
lsst::afw::math::LinearCombinationKernel::Ptr spatialKernel,
lsst::afw::math::Kernel::SpatialFunctionPtr spatialBackground,
Expand Down
8 changes: 4 additions & 4 deletions include/lsst/ip/diffim/BasisLists.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef LSST_IP_DIFFIM_BASISSETS_H
#define LSST_IP_DIFFIM_BASISSETS_H

#include "boost/shared_ptr.hpp"
#include <memory>

#include "Eigen/Core"

Expand Down Expand Up @@ -48,7 +48,7 @@ namespace diffim {
* @note Calls either makeForwardDifferenceMatrix or
* makeCentralDifferenceMatrix based on the policy file.
*/
boost::shared_ptr<Eigen::MatrixXd> makeRegularizationMatrix(
std::shared_ptr<Eigen::MatrixXd> makeRegularizationMatrix(
lsst::pex::policy::Policy policy
);

Expand All @@ -63,7 +63,7 @@ namespace diffim {
*
* @ingroup ip_diffim
*/
boost::shared_ptr<Eigen::MatrixXd> makeForwardDifferenceMatrix(
std::shared_ptr<Eigen::MatrixXd> makeForwardDifferenceMatrix(
int width,
int height,
std::vector<int> const& orders,
Expand All @@ -82,7 +82,7 @@ namespace diffim {
*
* @ingroup ip_diffim
*/
boost::shared_ptr<Eigen::MatrixXd> makeCentralDifferenceMatrix(
std::shared_ptr<Eigen::MatrixXd> makeCentralDifferenceMatrix(
int width,
int height,
int stencil,
Expand Down
14 changes: 7 additions & 7 deletions include/lsst/ip/diffim/BuildSingleKernelVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef LSST_IP_DIFFIM_BUILDSINGLEKERNELVISITOR_H
#define LSST_IP_DIFFIM_BUILDSINGLEKERNELVISITOR_H

#include "boost/shared_ptr.hpp"
#include <memory>

#include "lsst/afw/image.h"
#include "lsst/afw/math.h"
Expand All @@ -30,7 +30,7 @@ namespace detail {
class BuildSingleKernelVisitor : public lsst::afw::math::CandidateVisitor {
typedef lsst::afw::image::MaskedImage<PixelT> MaskedImageT;
public:
typedef boost::shared_ptr<BuildSingleKernelVisitor<PixelT> > Ptr;
typedef std::shared_ptr<BuildSingleKernelVisitor<PixelT> > Ptr;

BuildSingleKernelVisitor(
lsst::afw::math::KernelList const& basisList,
Expand All @@ -39,7 +39,7 @@ namespace detail {
BuildSingleKernelVisitor(
lsst::afw::math::KernelList const& basisList,
lsst::pex::policy::Policy const& policy,
boost::shared_ptr<Eigen::MatrixXd> hMat
std::shared_ptr<Eigen::MatrixXd> hMat
);
virtual ~BuildSingleKernelVisitor() {};

Expand All @@ -61,7 +61,7 @@ namespace detail {
private:
lsst::afw::math::KernelList const _basisList; ///< Basis set
lsst::pex::policy::Policy _policy; ///< Policy controlling behavior
boost::shared_ptr<Eigen::MatrixXd> _hMat; ///< Regularization matrix
std::shared_ptr<Eigen::MatrixXd> _hMat; ///< Regularization matrix
ImageStatistics<PixelT> _imstats; ///< To calculate statistics of difference image
bool _skipBuilt; ///< Skip over built candidates during processCandidate()
int _nRejected; ///< Number of candidates rejected during processCandidate()
Expand All @@ -73,7 +73,7 @@ namespace detail {
};

template<typename PixelT>
boost::shared_ptr<BuildSingleKernelVisitor<PixelT> >
std::shared_ptr<BuildSingleKernelVisitor<PixelT> >
makeBuildSingleKernelVisitor(
lsst::afw::math::KernelList const& basisList,
lsst::pex::policy::Policy const& policy
Expand All @@ -85,11 +85,11 @@ namespace detail {
}

template<typename PixelT>
boost::shared_ptr<BuildSingleKernelVisitor<PixelT> >
std::shared_ptr<BuildSingleKernelVisitor<PixelT> >
makeBuildSingleKernelVisitor(
lsst::afw::math::KernelList const& basisList,
lsst::pex::policy::Policy const& policy,
boost::shared_ptr<Eigen::MatrixXd> hMat
std::shared_ptr<Eigen::MatrixXd> hMat
) {

return typename BuildSingleKernelVisitor<PixelT>::Ptr(
Expand Down
8 changes: 4 additions & 4 deletions include/lsst/ip/diffim/BuildSpatialKernelVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace detail {
template<typename PixelT>
class BuildSpatialKernelVisitor : public lsst::afw::math::CandidateVisitor {
public:
typedef boost::shared_ptr<BuildSpatialKernelVisitor<PixelT> > Ptr;
typedef std::shared_ptr<BuildSpatialKernelVisitor<PixelT> > Ptr;

BuildSpatialKernelVisitor(
lsst::afw::math::KernelList const& basisList, ///< Basis functions
Expand All @@ -40,18 +40,18 @@ namespace detail {

void solveLinearEquation();

inline boost::shared_ptr<SpatialKernelSolution> getKernelSolution() {return _kernelSolution;}
inline std::shared_ptr<SpatialKernelSolution> getKernelSolution() {return _kernelSolution;}

std::pair<lsst::afw::math::LinearCombinationKernel::Ptr,
lsst::afw::math::Kernel::SpatialFunctionPtr> getSolutionPair();

private:
boost::shared_ptr<SpatialKernelSolution> _kernelSolution;
std::shared_ptr<SpatialKernelSolution> _kernelSolution;
int _nCandidates; ///< Number of candidates visited
};

template<typename PixelT>
boost::shared_ptr<BuildSpatialKernelVisitor<PixelT> >
std::shared_ptr<BuildSpatialKernelVisitor<PixelT> >
makeBuildSpatialKernelVisitor(
lsst::afw::math::KernelList const& basisList,
lsst::afw::geom::Box2I const& regionBBox,
Expand Down
4 changes: 2 additions & 2 deletions include/lsst/ip/diffim/ImageStatistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define LSST_IP_DIFFIM_IMAGESTATISTICS_H

#include <limits>
#include "boost/shared_ptr.hpp"
#include <memory>
#include "lsst/afw/image.h"
#include "lsst/pex/policy/Policy.h"
#include "lsst/pex/logging/Trace.h"
Expand All @@ -57,7 +57,7 @@ namespace diffim {
template <typename PixelT>
class ImageStatistics {
public:
typedef boost::shared_ptr<ImageStatistics> Ptr;
typedef std::shared_ptr<ImageStatistics> Ptr;
typedef typename lsst::afw::image::MaskedImage<PixelT>::x_iterator x_iterator;

ImageStatistics(lsst::pex::policy::Policy const& policy) :
Expand Down
34 changes: 17 additions & 17 deletions include/lsst/ip/diffim/KernelCandidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef LSST_IP_DIFFIM_KERNELCANDIDATE_H
#define LSST_IP_DIFFIM_KERNELCANDIDATE_H

#include "boost/shared_ptr.hpp"
#include <memory>
#include "Eigen/Core"

#include "lsst/afw/math.h"
Expand Down Expand Up @@ -45,10 +45,10 @@ namespace diffim {
using afw::math::SpatialCellImageCandidate<afw::math::Kernel::Pixel>::_image;

public:
typedef boost::shared_ptr<KernelCandidate> Ptr;
typedef boost::shared_ptr<afw::image::MaskedImage<PixelT> > MaskedImagePtr;
typedef boost::shared_ptr<afw::image::Image<afw::image::VariancePixel> > VariancePtr;
typedef boost::shared_ptr<afw::table::SourceRecord> SourcePtr;
typedef std::shared_ptr<KernelCandidate> Ptr;
typedef std::shared_ptr<afw::image::MaskedImage<PixelT> > MaskedImagePtr;
typedef std::shared_ptr<afw::image::Image<afw::image::VariancePixel> > VariancePtr;
typedef std::shared_ptr<afw::table::SourceRecord> SourcePtr;

enum CandidateSwitch {
ORIG = 0,
Expand Down Expand Up @@ -112,7 +112,7 @@ namespace diffim {
double getKsum(CandidateSwitch cand) const;
PTR(ImageT) getKernelImage(CandidateSwitch cand) const;
CONST_PTR(ImageT) getImage() const; // For SpatialCellImageCandidate
boost::shared_ptr<StaticKernelSolution<PixelT> > getKernelSolution(CandidateSwitch cand) const;
std::shared_ptr<StaticKernelSolution<PixelT> > getKernelSolution(CandidateSwitch cand) const;

/**
* @brief Calculate associated difference image using internal solutions
Expand Down Expand Up @@ -183,7 +183,7 @@ namespace diffim {
);
void build(
afw::math::KernelList const& basisList,
boost::shared_ptr<Eigen::MatrixXd> hMat
std::shared_ptr<Eigen::MatrixXd> hMat
);

private:
Expand All @@ -198,13 +198,13 @@ namespace diffim {
bool _fitForBackground;

/* best single raw kernel */
boost::shared_ptr<StaticKernelSolution<PixelT> > _kernelSolutionOrig; ///< Original basis solution
std::shared_ptr<StaticKernelSolution<PixelT> > _kernelSolutionOrig; ///< Original basis solution

/* with Pca basis */
boost::shared_ptr<StaticKernelSolution<PixelT> > _kernelSolutionPca; ///< Most recent solution
std::shared_ptr<StaticKernelSolution<PixelT> > _kernelSolutionPca; ///< Most recent solution

void _buildKernelSolution(afw::math::KernelList const& basisList,
boost::shared_ptr<Eigen::MatrixXd> hMat);
std::shared_ptr<Eigen::MatrixXd> hMat);
};


Expand All @@ -220,11 +220,11 @@ namespace diffim {
* @ingroup ip_diffim
*/
template <typename PixelT>
boost::shared_ptr<KernelCandidate<PixelT> >
std::shared_ptr<KernelCandidate<PixelT> >
makeKernelCandidate(float const xCenter,
float const yCenter,
boost::shared_ptr<afw::image::MaskedImage<PixelT> > const& templateMaskedImage,
boost::shared_ptr<afw::image::MaskedImage<PixelT> > const& scienceMaskedImage,
std::shared_ptr<afw::image::MaskedImage<PixelT> > const& templateMaskedImage,
std::shared_ptr<afw::image::MaskedImage<PixelT> > const& scienceMaskedImage,
pex::policy::Policy const& policy){

return typename KernelCandidate<PixelT>::Ptr(new KernelCandidate<PixelT>(xCenter, yCenter,
Expand All @@ -245,10 +245,10 @@ namespace diffim {
* @ingroup ip_diffim
*/
template <typename PixelT>
boost::shared_ptr<KernelCandidate<PixelT> >
makeKernelCandidate(boost::shared_ptr<afw::table::SourceRecord> const & source,
boost::shared_ptr<afw::image::MaskedImage<PixelT> > const& templateMaskedImage,
boost::shared_ptr<afw::image::MaskedImage<PixelT> > const& scienceMaskedImage,
std::shared_ptr<KernelCandidate<PixelT> >
makeKernelCandidate(std::shared_ptr<afw::table::SourceRecord> const & source,
std::shared_ptr<afw::image::MaskedImage<PixelT> > const& templateMaskedImage,
std::shared_ptr<afw::image::MaskedImage<PixelT> > const& scienceMaskedImage,
pex::policy::Policy const& policy){

return typename KernelCandidate<PixelT>::Ptr(new KernelCandidate<PixelT>(source,
Expand Down
4 changes: 2 additions & 2 deletions include/lsst/ip/diffim/KernelCandidateDetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace diffim {
template <typename PixelT>
class KernelCandidateDetection {
public:
typedef boost::shared_ptr<KernelCandidateDetection> Ptr;
typedef boost::shared_ptr<lsst::afw::image::MaskedImage<PixelT> > MaskedImagePtr;
typedef std::shared_ptr<KernelCandidateDetection> Ptr;
typedef std::shared_ptr<lsst::afw::image::MaskedImage<PixelT> > MaskedImagePtr;

KernelCandidateDetection(lsst::pex::policy::Policy const& policy);

Expand Down
12 changes: 6 additions & 6 deletions include/lsst/ip/diffim/KernelPca.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace detail {
class KernelPca : public lsst::afw::image::ImagePca<ImageT> {
typedef typename lsst::afw::image::ImagePca<ImageT> Super; ///< Base class
public:
typedef typename boost::shared_ptr<KernelPca<ImageT> > Ptr;
typedef typename std::shared_ptr<KernelPca<ImageT> > Ptr;
using lsst::afw::image::ImagePca<ImageT>::getEigenImages;
using lsst::afw::image::ImagePca<ImageT>::getEigenValues;
using lsst::afw::image::ImagePca<ImageT>::addImage;
Expand All @@ -40,23 +40,23 @@ namespace detail {
class KernelPcaVisitor : public lsst::afw::math::CandidateVisitor {
public:
typedef lsst::afw::image::Image<lsst::afw::math::Kernel::Pixel> ImageT;
typedef boost::shared_ptr<KernelPcaVisitor<PixelT> > Ptr;
typedef std::shared_ptr<KernelPcaVisitor<PixelT> > Ptr;

KernelPcaVisitor(boost::shared_ptr<KernelPca<ImageT> > imagePca);
KernelPcaVisitor(std::shared_ptr<KernelPca<ImageT> > imagePca);
virtual ~KernelPcaVisitor() {};

lsst::afw::math::KernelList getEigenKernels();
void processCandidate(lsst::afw::math::SpatialCellCandidate *candidate);
void subtractMean();
PTR(ImageT) returnMean() {return _mean;}
private:
boost::shared_ptr<KernelPca<ImageT> > _imagePca; ///< Structure to fill with images
std::shared_ptr<KernelPca<ImageT> > _imagePca; ///< Structure to fill with images
PTR(ImageT) _mean; ///< Mean image calculated before Pca
};

template<typename PixelT>
boost::shared_ptr<KernelPcaVisitor<PixelT> >
makeKernelPcaVisitor(boost::shared_ptr<KernelPca<typename KernelPcaVisitor<PixelT>::ImageT> > imagePca) {
std::shared_ptr<KernelPcaVisitor<PixelT> >
makeKernelPcaVisitor(std::shared_ptr<KernelPca<typename KernelPcaVisitor<PixelT>::ImageT> > imagePca) {
return typename KernelPcaVisitor<PixelT>::Ptr(new KernelPcaVisitor<PixelT>(imagePca));
};

Expand Down

0 comments on commit a59151e

Please sign in to comment.