1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-06-17 15:27:06 +01:00

update license and if guards

This commit is contained in:
Luchang Jin
2016-10-12 15:21:46 -04:00
parent 8afcc8fb8b
commit c39ec3b607
3 changed files with 33 additions and 14 deletions

View File

@ -5,7 +5,7 @@
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
@ -19,7 +19,8 @@
// Code within namespace sha256 are from Stephan Brumme.
// see http://create.stephan-brumme.com/disclaimer.html
#pragma once
#ifndef RNG_STATE_RNG_STATE_H
#define RNG_STATE_RNG_STATE_H
#include "show.h"
@ -126,10 +127,9 @@ inline void splitTwoUint32(uint32_t& a, uint32_t& b, const uint64_t x)
assert(x == patchTwoUint32(a, b));
}
inline void exportRngState(std::vector<uint32_t>& v, const RngState& rs)
inline void exportRngState(uint32_t* v, const RngState& rs)
{
assert(22 == RNG_STATE_NUM_OF_INT32);
v.resize(RNG_STATE_NUM_OF_INT32);
splitTwoUint32(v[0], v[1], rs.numBytes);
for (int i = 0; i < 8; ++i) {
v[2 + i] = rs.hash[i];
@ -144,9 +144,8 @@ inline void exportRngState(std::vector<uint32_t>& v, const RngState& rs)
v[21] = rs.gaussianAvail;
}
inline void importRngState(RngState& rs, const std::vector<uint32_t>& v)
inline void importRngState(RngState& rs, const uint32_t* v)
{
assert(RNG_STATE_NUM_OF_INT32 == v.size());
assert(22 == RNG_STATE_NUM_OF_INT32);
rs.numBytes = patchTwoUint32(v[0], v[1]);
for (int i = 0; i < 8; ++i) {
@ -156,12 +155,24 @@ inline void importRngState(RngState& rs, const std::vector<uint32_t>& v)
for (int i = 0; i < 3; ++i) {
rs.cache[i] = patchTwoUint32(v[12 + i * 2], v[12 + i * 2 + 1]);
}
uint64_t* p = (uint64_t*)&rs.gaussian;
*p = patchTwoUint32(v[18], v[19]);
uint64_t g = patchTwoUint32(v[18], v[19]);
rs.gaussian = reinterpret_cast<double&>(g);
rs.cacheAvail = v[20];
rs.gaussianAvail = v[21];
}
inline void exportRngState(std::vector<uint32_t>& v, const RngState& rs)
{
v.resize(RNG_STATE_NUM_OF_INT32);
exportRngState(v.data(), rs);
}
inline void importRngState(RngState& rs, const std::vector<uint32_t>& v)
{
assert(RNG_STATE_NUM_OF_INT32 == v.size());
importRngState(rs, v.data());
}
inline std::ostream& operator<<(std::ostream& os, const RngState& rs)
{
std::vector<uint32_t> v(RNG_STATE_NUM_OF_INT32);
@ -568,3 +579,5 @@ inline double gRandGen(RngState& rs, const double sigma, const double center)
#ifdef CURRENT_DEFAULT_NAMESPACE_NAME
}
#endif
#endif

View File

@ -5,7 +5,7 @@
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
@ -16,7 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#ifndef RNG_STATE_SHOW_H
#define RNG_STATE_SHOW_H
#include <sstream>
#include <string>
@ -105,12 +106,12 @@ T& reads(T& x, const std::string& str)
return x;
}
void fdisplay(FILE* fp, const std::string& str)
inline void fdisplay(FILE* fp, const std::string& str)
{
fprintf(fp, "%s", str.c_str());
}
void fdisplayln(FILE* fp, const std::string& str)
inline void fdisplayln(FILE* fp, const std::string& str)
{
fprintf(fp, "%s\n", str.c_str());
}
@ -118,3 +119,5 @@ void fdisplayln(FILE* fp, const std::string& str)
#ifdef CURRENT_DEFAULT_NAMESPACE_NAME
}
#endif
#endif

View File

@ -5,7 +5,7 @@
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
@ -16,7 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#ifndef RNG_STATE_SPRNG_SHA256_H
#define RNG_STATE_SPRNG_SHA256_H
#include "rng-state.h"
@ -108,3 +109,5 @@ inline bool operator==(const SprngSha256& ss1, const SprngSha256& ss2)
#ifdef CURRENT_DEFAULT_NAMESPACE_NAME
}
#endif
#endif