Skip to content

Commit 65cfeb7

Browse files
committed
use long double only on arm mac
1 parent 5b968fc commit 65cfeb7

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

Framework/Muon/src/PhaseQuadMuon.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717

1818
#include "Eigen/Dense"
1919

20+
// Use of a `long double` datatype is required on osx-arm64 to bring the precision of eigen vector-matrix multiplication
21+
// inline with the other operating systems.
22+
#if defined(__APPLE__) && defined(__arm64__)
23+
typedef long double eigenDataType;
24+
#else
25+
typedef double eigenDataType;
26+
#endif
27+
2028
using namespace Mantid::DataObjects;
2129
using namespace Mantid::HistogramData;
2230

@@ -239,7 +247,7 @@ API::MatrixWorkspace_sptr PhaseQuadMuon::squash(const API::MatrixWorkspace_sptr
239247
}
240248
std::vector<bool> emptySpectrum;
241249
emptySpectrum.reserve(nspec);
242-
std::vector<Eigen::Vector<long double, 2>> n0Vectors(nspec);
250+
std::vector<Eigen::Vector<eigenDataType, 2>> n0Vectors(nspec);
243251

244252
// Calculate coefficients aj, bj
245253

@@ -255,21 +263,21 @@ API::MatrixWorkspace_sptr PhaseQuadMuon::squash(const API::MatrixWorkspace_sptr
255263
const double phi = phase->Double(h, phaseIndex);
256264
const double X = n0[h] * asym * cos(phi);
257265
const double Y = n0[h] * asym * sin(phi);
258-
Eigen::Vector<long double, 2> n0vec;
266+
Eigen::Vector<eigenDataType, 2> n0vec;
259267
n0Vectors[h] = {X, Y};
260268
sxx += X * X;
261269
syy += Y * Y;
262270
sxy += X * Y;
263271
} else {
264-
n0Vectors[h] = Eigen::Vector<long double, 2>::Zero();
272+
n0Vectors[h] = Eigen::Vector<eigenDataType, 2>::Zero();
265273
}
266274
}
267275

268-
Eigen::Matrix<long double, 2, 2> muLamMatrix;
276+
Eigen::Matrix<eigenDataType, 2, 2> muLamMatrix;
269277
muLamMatrix << sxx, sxy, sxy, syy;
270-
muLamMatrix = Eigen::PartialPivLU<Eigen::Matrix<long double, 2, 2>>(muLamMatrix).inverse();
278+
muLamMatrix = Eigen::PartialPivLU<Eigen::Matrix<eigenDataType, 2, 2>>(muLamMatrix).inverse();
271279

272-
std::vector<long double> aj(nspec), bj(nspec);
280+
std::vector<eigenDataType> aj(nspec), bj(nspec);
273281
for (size_t h = 0; h < nspec; h++) {
274282
aj[h] = bj[h] = 0;
275283
if (!emptySpectrum[h]) {

Framework/Muon/test/PhaseQuadMuonTest.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,14 @@ class PhaseQuadMuonTestPerformance : public CxxTest::TestSuite {
312312

313313
void setUp() override {
314314
m_loadedData = loadMuonDataset();
315-
phaseQuad = setupAlg(m_loadedData, false);
315+
m_phaseQuad = setupAlg(m_loadedData, false);
316316
}
317317

318318
void tearDown() override { Mantid::API::AnalysisDataService::Instance().remove("outputWs"); }
319319

320-
void testPerformanceWs() { phaseQuad->execute(); }
320+
void testPerformanceWs() { m_phaseQuad->execute(); }
321321

322322
private:
323323
MatrixWorkspace_sptr m_loadedData;
324-
IAlgorithm_sptr phaseQuad;
324+
IAlgorithm_sptr m_phaseQuad;
325325
};

0 commit comments

Comments
 (0)