Skip to content

Commit

Permalink
Merge pull request #3 from pauldmccarthy/mnt/conda
Browse files Browse the repository at this point in the history
WIP: Use conda to build FSL projects
  • Loading branch information
mcraig-ibme committed May 11, 2022
2 parents 246b343 + 20f8fcd commit 99c29e6
Show file tree
Hide file tree
Showing 37 changed files with 224 additions and 152 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CVS
*.o
*~
*.a
*.so
.DS_Store
depend.mk
testfabber
Expand Down
92 changes: 61 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,37 @@ include ${FSLCONFDIR}/default.mk

PROJNAME = fabber_core

USRINCFLAGS = -I${INC_NEWMAT} -I${INC_CPROB} -I${INC_BOOST} -DFABBER_SRC_DIR="\"${PWD}\"" -DFABBER_BUILD_DIR="\"${PWD}\""
USRLDFLAGS = -L${LIB_NEWMAT} -L${LIB_PROB} -L/lib64

FSLVERSION= $(shell cat ${FSLDIR}/etc/fslversion | head -c 1)
ifeq ($(FSLVERSION), 5)
NIFTILIB = -lfslio -lniftiio
MATLIB = -lnewmat
else
UNAME := $(shell uname -s)
ifeq ($(UNAME), Linux)
MATLIB = -lopenblas
USRINCFLAGS = -DFABBER_SRC_DIR="\"${PWD}\"" -DFABBER_BUILD_DIR="\"${PWD}\""

# The FSL build system changed
# substantially in FSL 6.0.6
# FSL >= 6.0.6
ifeq (${FSL_GE_606}, true)
LIBS = -lfsl-newimage -lfsl-miscmaths -lfsl-utils \
-lfsl-cprob -lfsl-NewNifti -lfsl-znz -ldl
USRCPPFLAGS += -DFSL_GE_606
# FSL <= 6.0.5
else
ifeq ($(shell uname -s), Linux)
MATLIB := -lopenblas
endif
NIFTILIB = -lNewNifti

USRINCFLAGS += -I${INC_NEWMAT} -I${INC_CPROB} -I${INC_BOOST} \
-I${FSLDIR}/extras/include/armawrap
USRLDFLAGS = -L${LIB_NEWMAT} -L${LIB_CPROB} \
-lnewimage -lmiscmaths -lutils -lcprob \
-lNewNifti ${MATLIB} -lznz -lz -ldl
endif

LIBS = -lnewimage -lmiscmaths -lutils -lprob ${MATLIB} ${NIFTILIB} -lznz -lz -ldl
TESTLIBS = -lgtest -lpthread

#
# Executables
# Executables and libraries provided by this project
#

XFILES = fabber mvntool
XFILES = fabber mvntool
SOFILES = libfsl-fabbercore.so libfsl-fabberexec.so
AFILES = libfabbercore.a libfabberexec.a
SCRIPTS = fabber_var

# Sets of objects separated into logical divisions
Expand Down Expand Up @@ -60,33 +68,55 @@ OBJS = ${BASICOBJS} ${COREOBJS} ${INFERENCEOBJS} ${NOISEOBJS} ${CONFIGOBJS}
#OPTFLAGS = -ggdb -Wall

# Pass Git revision details
GIT_SHA1:=$(shell git describe --dirty)
GIT_DATE:=$(shell git log -1 --format=%ad --date=local)
GIT_SHA1 := $(shell git describe --dirty)
GIT_DATE := $(shell git log -1 --format=%ad --date=local)
CXXFLAGS += -DGIT_SHA1=\"${GIT_SHA1}\" -DGIT_DATE="\"${GIT_DATE}\""

# Targets
clean:
${RM} -f /tmp/fslgrot *.o mvn_tool/*.o *.a *.so *.exe core depend.mk fabber_test

# FSL >=606 uses dynamic linking
ifeq (${FSL_GE_606}, true)

all: ${XFILES} libfabbercore.a libfabberexec.a
all: ${XFILES} ${SOFILES}

clean:
${RM} -f /tmp/fslgrot *.o mvn_tool/*.o *.a *.exe core depend.mk fabber_test
# Dynamically linked libraries are compiled for FSL >= 606
libfsl-fabbercore.so : ${OBJS}
${CXX} ${CXXFLAGS} -shared -o $@ $^ ${LDFLAGS}

mvntool: ${OBJS} mvn_tool/mvntool.o rundata_newimage.o
${CXX} ${CXXFLAGS} ${LDFLAGS} -o $@ ${OBJS} mvn_tool/mvntool.o rundata_newimage.o ${LIBS}
libfsl-fabberexec.so : ${EXECOBJS} | libfsl-fabbercore.so
${CXX} ${CXXFLAGS} -shared -o $@ $^ -lfsl-fabbercore ${LDFLAGS}

mvntool: mvn_tool/mvntool.o rundata_newimage.o | libfsl-fabbercore.so
${CXX} ${CXXFLAGS} -o $@ $^ -lfsl-fabbercore ${LDFLAGS}

# Build a fabber exectuable, this will have nothing but the generic models so it not practically useful for data analysis
fabber: ${OBJS} ${EXECOBJS} ${CLIENTOBJS}
${CXX} ${CXXFLAGS} ${LDFLAGS} -o $@ ${OBJS} ${EXECOBJS} ${CLIENTOBJS} ${LIBS}
fabber: ${CLIENTOBJS} | libfsl-fabberexec.so libfsl-fabbercore.so
${CXX} ${CXXFLAGS} -o $@ $^ -lfsl-fabberexec -lfsl-fabbercore ${LDFLAGS}

# Unit tests
test: ${CLIENTOBJS} ${TESTOBJS} | libfsl-fabberexec.so libfsl-fabbercore.so
${CXX} ${CXXFLAGS} -o fabber_test $^ -lfsl-fabberexec -lfsl-fabbercore ${LDFLAGS} ${TESTLIBS}

# FSL <=605 uses static linking
else

all: ${XFILES} ${AFILES}

# Library build
libfabbercore.a : ${OBJS}
${AR} -r $@ ${OBJS}
${AR} -r $@ $^

libfabberexec.a : ${EXECOBJS}
${AR} -r $@ ${EXECOBJS}
libfabberexec.a : ${EXECOBJS}
${AR} -r $@ $^

mvntool: ${OBJS} mvn_tool/mvntool.o rundata_newimage.o
${CXX} ${CXXFLAGS} -o $@ $^ ${LDFLAGS}

fabber: ${OBJS} ${EXECOBJS} ${CLIENTOBJS}
${CXX} ${CXXFLAGS} -o $@ $^ ${LDFLAGS}

# Unit tests
test: ${OBJS} ${EXECOBJS} ${CLIENTOBJS} ${TESTOBJS}
${CXX} ${CXXFLAGS} ${LDFLAGS} ${TESTINC} -o fabber_test ${OBJS} ${EXECOBJS} ${TESTOBJS} ${LIBS} ${TESTLIBS}
${CXX} ${CXXFLAGS} -o fabber_test $^ ${LDFLAGS} ${TESTLIBS}
endif

# DO NOT DELETE
2 changes: 1 addition & 1 deletion covariance_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "easylog.h"
#include "rundata.h"

#include <newmat.h>
#include "armawrap/newmat.h"

#include <map>
#include <math.h>
Expand Down
2 changes: 1 addition & 1 deletion covariance_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "easylog.h"

#include "newmat.h"
#include "armawrap/newmat.h"

#include <map>
#include <string>
Expand Down
15 changes: 8 additions & 7 deletions dist_mvn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
#include "tools.h"

#include <math.h>
#include <newmatio.h>
#include "armawrap/newmat.h"

using fabber::read_matrix_file;
using namespace std;
using namespace NEWMAT;

// Constructors
Expand Down Expand Up @@ -66,9 +67,9 @@ MVNDist::MVNDist(const MVNDist &from1, const MVNDist &from2)
// Always duplicate the covariances (even if this means some recalculation)
// Otherwise if we use precisions.i(), zeros won't stay exactly zero
covariance = 0;
for (int row=1; row <= from1.m_size; row++)
for (int row=1; row <= from1.m_size; row++)
{
for (int col=1; col <= from1.m_size; col++)
for (int col=1; col <= from1.m_size; col++)
{
try
{
Expand All @@ -80,9 +81,9 @@ MVNDist::MVNDist(const MVNDist &from1, const MVNDist &from2)
}
}
}
for (int row=1; row <= from2.m_size; row++)
for (int row=1; row <= from2.m_size; row++)
{
for (int col=1; col <= from2.m_size; col++)
for (int col=1; col <= from2.m_size; col++)
{
try
{
Expand Down Expand Up @@ -417,9 +418,9 @@ void MVNDist::Save(const vector<MVNDist *> &mvns, const string &filename, Fabber
// required by NIFTI_INTENT_SYMMATRIX
ColumnVector cov(nCov);
int idx=1;
for (int row=1; row <=nParams; row++)
for (int row=1; row <=nParams; row++)
{
for (int col=1; col<=row; col++)
for (int col=1; col<=row; col++)
{
cov(idx++) = mvns.at(vox - 1)->GetCovariance()(row, col);
}
Expand Down
6 changes: 3 additions & 3 deletions dist_mvn.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "easylog.h"
#include "rundata.h"

#include <newmat.h>
#include "armawrap/newmat.h"
#include <ostream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -68,7 +68,7 @@ class MVNDist : public Loggable
*
* @param mvns One MVN for each voxel
*/
static void Save(const vector<MVNDist *> &mvns, const string &filename, FabberRunData &data);
static void Save(const std::vector<MVNDist *> &mvns, const std::string &filename, FabberRunData &data);

/**
* Default constructor
Expand Down Expand Up @@ -96,7 +96,7 @@ class MVNDist : public Loggable
/**
* Create from matrix file (VEST or ASCII)
*/
MVNDist(const string filename, EasyLog *log = 0);
MVNDist(const std::string filename, EasyLog *log = 0);

/**
* Copy using a subset of another MVN distribution's parameters
Expand Down
9 changes: 4 additions & 5 deletions examples/fwdmodel_exp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "fabber_core/fwdmodel.h"

#include "newmat.h"
#include "armawrap/newmat.h"

#include <string>
#include <vector>
Expand All @@ -22,10 +22,10 @@ class ExpFwdModel : public FwdModel {
void GetOptions(std::vector<OptionSpec> &opts) const;

void Initialize(FabberRunData &args);
void EvaluateModel(const NEWMAT::ColumnVector &params,
NEWMAT::ColumnVector &result,
void EvaluateModel(const NEWMAT::ColumnVector &params,
NEWMAT::ColumnVector &result,
const std::string &key="") const;

void InitVoxelPosterior(MVNDist &posterior) const;

protected:
Expand All @@ -36,4 +36,3 @@ class ExpFwdModel : public FwdModel {
double m_dt;
static FactoryRegistration<FwdModelFactory, ExpFwdModel> registration;
};

6 changes: 3 additions & 3 deletions fabber_capi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "rundata_array.h"
#include "setup.h"

#include "newmat.h"
#include "armawrap/newmat.h"

#include <sstream>
#include <stdexcept>
Expand Down Expand Up @@ -477,7 +477,7 @@ int fabber_get_model_param_descs(void *fab, unsigned int out_bufsize, char *out_
for (iter = params.begin(); iter != params.end(); ++iter)
{
out << iter->name << " " << iter->desc;
if (iter->units != "")
if (iter->units != "")
{
out << " (units: " << iter->units << ")";
}
Expand Down Expand Up @@ -581,7 +581,7 @@ int fabber_model_evaluate_output(void *fab, unsigned int n_params, float *params
{
p_vec(i + 1) = params[i];
}
for (unsigned int i=0; i < n_ts; i++)
for (unsigned int i=0; i < n_ts; i++)
{
if (indata)
data_vec(i + 1) = indata[i];
Expand Down
15 changes: 10 additions & 5 deletions fabber_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "version.h"
#include "tools.h"

#include "armawrap/newmat.h"

#include <exception>
#include <iostream>
#include <map>
Expand All @@ -26,6 +28,9 @@

using namespace std;

using NEWMAT::Matrix;
using NEWMAT::ColumnVector;

/**
* Print version information.
*/
Expand Down Expand Up @@ -154,7 +159,7 @@ int execute(int argc, char **argv)

return 0;
}
else if (params->GetBool("listparams"))
else if (params->GetBool("listparams"))
{
string model = params->GetStringDefault("model", "");
std::auto_ptr<FwdModel> fwd_model(FwdModel::NewFromName(model));
Expand All @@ -172,7 +177,7 @@ int execute(int argc, char **argv)

return 0;
}
else if (params->GetBool("descparams"))
else if (params->GetBool("descparams"))
{
string model = params->GetStringDefault("model", "");
std::auto_ptr<FwdModel> fwd_model(FwdModel::NewFromName(model));
Expand All @@ -186,7 +191,7 @@ int execute(int argc, char **argv)
for (iter = model_params.begin(); iter != model_params.end(); ++iter)
{
cout << iter->name << " " << iter->desc;
if (iter->units != "")
if (iter->units != "")
{
cout << " (units: " << iter->units << ")";
}
Expand All @@ -195,7 +200,7 @@ int execute(int argc, char **argv)

return 0;
}
else if (params->GetBool("listoutputs"))
else if (params->GetBool("listoutputs"))
{
string model = params->GetStringDefault("model", "");
std::auto_ptr<FwdModel> fwd_model(FwdModel::NewFromName(model));
Expand All @@ -213,7 +218,7 @@ int execute(int argc, char **argv)

return 0;
}
else if (params->HaveKey("evaluate"))
else if (params->HaveKey("evaluate"))
{
string model = params->GetStringDefault("model", "");
std::auto_ptr<FwdModel> fwd_model(FwdModel::NewFromName(model));
Expand Down
2 changes: 1 addition & 1 deletion fwdmodel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "rundata.h"
#include "transforms.h"

#include <newmatio.h>
#include "armawrap/newmat.h"

#include <memory>
#include <sstream>
Expand Down
6 changes: 3 additions & 3 deletions fwdmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "factories.h"
#include "transforms.h"

#include <newmat.h>
#include "armawrap/newmat.h"

#include <string>
#include <vector>
Expand All @@ -23,9 +23,9 @@
*/
struct Parameter
{
Parameter(unsigned int idx, std::string name="",
Parameter(unsigned int idx, std::string name="",
DistParams prior=DistParams(0, 1),
DistParams post=DistParams(0, 1),
DistParams post=DistParams(0, 1),
char prior_type='N',
const Transform *transform=TRANSFORM_IDENTITY(),
std::string desc="", std::string units="")
Expand Down
2 changes: 1 addition & 1 deletion fwdmodel_linear.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "tools.h"
#include "version.h"

#include <newmatio.h>
#include "armawrap/newmat.h"

#include <iostream>
#include <stdexcept>
Expand Down
2 changes: 1 addition & 1 deletion fwdmodel_linear.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "fwdmodel.h"

#include <newmat.h>
#include "armawrap/newmat.h"

#include <string>
#include <vector>
Expand Down

0 comments on commit 99c29e6

Please sign in to comment.