Skip to content

Commit

Permalink
Merge pull request #70 from lsst/tickets/DM-45939
Browse files Browse the repository at this point in the history
DM-45939: Use std namespace for cstdint types
  • Loading branch information
mwittgen authored Aug 26, 2024
2 parents 4daecf7 + e04220b commit 9a700aa
Show file tree
Hide file tree
Showing 33 changed files with 560 additions and 554 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
Expand All @@ -27,6 +27,7 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "setup.cfg"
allow-prereleases: true

- name: Build and install
run: |
Expand Down Expand Up @@ -73,7 +74,7 @@ jobs:
needs: [build_and_test]
if: startsWith(github.ref, 'refs/tags/')
env:
CIBW_BUILD: "cp3{8,9,10,11,12}-{manylinux_x86_64,manylinux_aarch64,macosx_arm64,macosx_x86_64}"
CIBW_BUILD: "cp3{8,9,10,11,12,13}-{manylinux_x86_64,manylinux_aarch64,macosx_arm64,macosx_x86_64}"
CIBW_ARCHS_MACOS: "x86_64 arm64"
# use line below to enable aarch64 builds
# CIBW_ARCHS_LINUX: "auto aarch64"
Expand Down
23 changes: 11 additions & 12 deletions include/lsst/sphgeom/BigInteger.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
/// \file
/// \brief This file declares a class for arbitrary precision integers.

#include <stdint.h>
#include <cstring>
#include <stdexcept>

#include <cstdint>

namespace lsst {
namespace sphgeom {
Expand All @@ -53,7 +52,7 @@ class BigInteger {
public:
/// This constructor creates a zero-valued integer with the given digit
/// array.
BigInteger(uint32_t * digits, unsigned capacity) :
BigInteger(std::uint32_t * digits, unsigned capacity) :
_digits(digits),
_capacity(capacity),
_size(0),
Expand All @@ -65,7 +64,7 @@ class BigInteger {
_checkCapacity(b._size);
_sign = b._sign;
_size = b._size;
std::memcpy(_digits, b._digits, sizeof(uint32_t) * b._size);
std::memcpy(_digits, b._digits, sizeof(std::uint32_t) * b._size);
}
return *this;
}
Expand All @@ -82,26 +81,26 @@ class BigInteger {
unsigned getCapacity() const { return _capacity; }

/// `getDigits` returns the underlying digit array.
uint32_t const * getDigits() const { return _digits; }
std::uint32_t const * getDigits() const { return _digits; }

/// `setToZero` sets this integer to zero.
void setToZero() { _sign = 0; _size = 0; }

/// `setTo` sets this integer to the given signed 64 bit integer value.
void setTo(int64_t x) {
void setTo(std::int64_t x) {
if (x < 0) {
setTo(static_cast<uint64_t>(-x));
setTo(static_cast<std::uint64_t>(-x));
_sign = -1;
} else {
setTo(static_cast<uint64_t>(x));
setTo(static_cast<std::uint64_t>(x));
}
}

/// `setTo` sets this integer to the given unsigned 64 bit integer value.
void setTo(uint64_t x) {
void setTo(std::uint64_t x) {
_checkCapacity(2);
_digits[0] = static_cast<uint32_t>(x);
_digits[1] = static_cast<uint32_t>(x >> 32);
_digits[0] = static_cast<std::uint32_t>(x);
_digits[1] = static_cast<std::uint32_t>(x >> 32);
_size = (_digits[1] == 0) ? (_digits[0] != 0) : 2;
_sign = (_size != 0);
}
Expand Down Expand Up @@ -129,7 +128,7 @@ class BigInteger {
}
}

uint32_t * _digits; // Unowned
std::uint32_t * _digits; // Unowned
unsigned _capacity;
unsigned _size;
int _sign;
Expand Down
9 changes: 5 additions & 4 deletions include/lsst/sphgeom/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
/// longitude/latitude angle boxes on the unit sphere.

#include <iosfwd>
#include <cstdint>

#include "AngleInterval.h"
#include "LonLat.h"
Expand All @@ -60,7 +61,7 @@ namespace sphgeom {
/// - Box::allLongitudes().contains(b.getLon())
class Box : public Region {
public:
static constexpr uint8_t TYPE_CODE = 'b';
static constexpr std::uint8_t TYPE_CODE = 'b';

// Factory functions
static Box fromDegrees(double lon1, double lat1, double lon2, double lat2) {
Expand Down Expand Up @@ -340,14 +341,14 @@ class Box : public Region {
Relationship relate(ConvexPolygon const &) const override;
Relationship relate(Ellipse const &) const override;

std::vector<uint8_t> encode() const override;
std::vector<std::uint8_t> encode() const override;

///@{
/// `decode` deserializes a Box from a byte string produced by encode.
static std::unique_ptr<Box> decode(std::vector<uint8_t> const & s) {
static std::unique_ptr<Box> decode(std::vector<std::uint8_t> const & s) {
return decode(s.data(), s.size());
}
static std::unique_ptr<Box> decode(uint8_t const * buffer, size_t n);
static std::unique_ptr<Box> decode(std::uint8_t const * buffer, size_t n);
///@}

private:
Expand Down
64 changes: 32 additions & 32 deletions include/lsst/sphgeom/Chunker.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
/// \brief This file declares a class for partitioning the sky into chunks
/// and sub-chunks.

#include <stdint.h>
#include <vector>
#include <cstdint>

#include "Angle.h"
#include "Box.h"
Expand All @@ -48,8 +48,8 @@ namespace sphgeom {
///
/// TODO(smm): implement a more memory efficient representation than this.
struct SubChunks {
int32_t chunkId;
std::vector<int32_t> subChunkIds;
std::int32_t chunkId;
std::vector<std::int32_t> subChunkIds;

SubChunks() : chunkId(-1) {}

Expand All @@ -72,8 +72,8 @@ struct SubChunks {
/// subchunks.
class Chunker {
public:
Chunker(int32_t numStripes,
int32_t numSubStripesPerStripe);
Chunker(std::int32_t numStripes,
std::int32_t numSubStripesPerStripe);

bool operator==(Chunker const & c) const {
return _numStripes == c._numStripes &&
Expand All @@ -87,53 +87,53 @@ class Chunker {

/// `getNumStripes` returns the number of fixed-height latitude intervals
/// in the sky subdivision.
int32_t getNumStripes() const {
std::int32_t getNumStripes() const {
return _numStripes;
}

/// `getNumSubStripesPerStripe` returns the number of fixed-height latitude
/// sub-intervals in each stripe.
int32_t getNumSubStripesPerStripe() const {
std::int32_t getNumSubStripesPerStripe() const {
return _numSubStripesPerStripe;
}

/// `getChunksIntersecting` returns all the chunks that potentially
/// intersect the given region.
std::vector<int32_t> getChunksIntersecting(Region const & r) const;
std::vector<std::int32_t> getChunksIntersecting(Region const & r) const;

/// `getSubChunksIntersecting` returns all the sub-chunks that potentially
/// intersect the given region.
std::vector<SubChunks> getSubChunksIntersecting(Region const & r) const;

/// `getAllChunks` returns the complete set of chunk IDs for the unit
/// sphere.
std::vector<int32_t> getAllChunks() const;
std::vector<std::int32_t> getAllChunks() const;

/// `getAllSubChunks` returns the complete set of sub-chunk IDs
/// for the given chunk.
std::vector<int32_t> getAllSubChunks(int32_t chunkId) const;
std::vector<std::int32_t> getAllSubChunks(std::int32_t chunkId) const;

/// Return 'true' if the specified chunk number is valid
bool valid(int32_t chunkId) const;
bool valid(std::int32_t chunkId) const;

Box getChunkBoundingBox(int32_t stripe, int32_t chunk) const;
Box getSubChunkBoundingBox(int32_t subStripe, int32_t subChunk) const;
Box getChunkBoundingBox(std::int32_t stripe, std::int32_t chunk) const;
Box getSubChunkBoundingBox(std::int32_t subStripe, std::int32_t subChunk) const;

/// Return the stripe for the specified chunkId
int32_t getStripe(int32_t chunkId) const {
std::int32_t getStripe(std::int32_t chunkId) const {
return chunkId / (2 * _numStripes);
}

/// Return the chunk for the given chunkId and stripe
int32_t getChunk(int32_t chunkId, int32_t stripe) const {
std::int32_t getChunk(std::int32_t chunkId, std::int32_t stripe) const {
return chunkId - stripe*2*_numStripes;
}

private:
struct Stripe {
Angle chunkWidth;
int32_t numChunksPerStripe;
int32_t numSubChunksPerChunk;
std::int32_t numChunksPerStripe;
std::int32_t numSubChunksPerChunk;

Stripe() :
chunkWidth(0),
Expand All @@ -144,35 +144,35 @@ class Chunker {

struct SubStripe {
Angle subChunkWidth;
int32_t numSubChunksPerChunk;
std::int32_t numSubChunksPerChunk;

SubStripe() : subChunkWidth(), numSubChunksPerChunk(0) {}
};

int32_t _getChunkId(int32_t stripe, int32_t chunk) const {
std::int32_t _getChunkId(std::int32_t stripe, std::int32_t chunk) const {
return stripe * 2 * _numStripes + chunk;
}

int32_t _getSubChunkId(int32_t stripe, int32_t subStripe,
int32_t chunk, int32_t subChunk) const {
int32_t y = subStripe - stripe * _numSubStripesPerStripe;
int32_t x = subChunk -
std::int32_t _getSubChunkId(std::int32_t stripe, std::int32_t subStripe,
std::int32_t chunk, std::int32_t subChunk) const {
std::int32_t y = subStripe - stripe * _numSubStripesPerStripe;
std::int32_t x = subChunk -
chunk * _subStripes[subStripe].numSubChunksPerChunk;
return y * _maxSubChunksPerSubStripeChunk + x;
}

void _getSubChunks(std::vector<SubChunks> & subChunks,
Region const & r,
NormalizedAngleInterval const & lon,
int32_t stripe,
int32_t chunk,
int32_t minSS,
int32_t maxSS) const;

int32_t _numStripes;
int32_t _numSubStripesPerStripe;
int32_t _numSubStripes;
int32_t _maxSubChunksPerSubStripeChunk;
std::int32_t stripe,
std::int32_t chunk,
std::int32_t minSS,
std::int32_t maxSS) const;

std::int32_t _numStripes;
std::int32_t _numSubStripesPerStripe;
std::int32_t _numSubStripes;
std::int32_t _maxSubChunksPerSubStripeChunk;
Angle _subStripeHeight;
std::vector<Stripe> _stripes;
std::vector<SubStripe> _subStripes;
Expand Down
9 changes: 5 additions & 4 deletions include/lsst/sphgeom/Circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
/// regions on the unit sphere.

#include <iosfwd>
#include <cstdint>

#include "Region.h"
#include "UnitVector3d.h"
Expand All @@ -52,7 +53,7 @@ namespace sphgeom {
/// angles.
class Circle : public Region {
public:
static constexpr uint8_t TYPE_CODE = 'c';
static constexpr std::uint8_t TYPE_CODE = 'c';

static Circle empty() { return Circle(); }

Expand Down Expand Up @@ -251,14 +252,14 @@ class Circle : public Region {
Relationship relate(ConvexPolygon const &) const override;
Relationship relate(Ellipse const &) const override;

std::vector<uint8_t> encode() const override;
std::vector<std::uint8_t> encode() const override;

///@{
/// `decode` deserializes a Circle from a byte string produced by encode.
static std::unique_ptr<Circle> decode(std::vector<uint8_t> const & s) {
static std::unique_ptr<Circle> decode(std::vector<std::uint8_t> const & s) {
return decode(s.data(), s.size());
}
static std::unique_ptr<Circle> decode(uint8_t const * buffer, size_t n);
static std::unique_ptr<Circle> decode(std::uint8_t const * buffer, size_t n);
///@}

private:
Expand Down
21 changes: 11 additions & 10 deletions include/lsst/sphgeom/CompoundRegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <iosfwd>
#include <iterator>
#include <array>
#include <cstdint>

#include "Region.h"
#include "UnitVector3d.h"
Expand Down Expand Up @@ -82,10 +83,10 @@ class CompoundRegion : public Region {
///@{
/// `decode` deserializes a CompoundRegion from a byte string produced by
/// encode.
static std::unique_ptr<CompoundRegion> decode(std::vector<uint8_t> const &s) {
static std::unique_ptr<CompoundRegion> decode(std::vector<std::uint8_t> const &s) {
return decode(s.data(), s.size());
}
static std::unique_ptr<CompoundRegion> decode(uint8_t const *buffer, size_t n);
static std::unique_ptr<CompoundRegion> decode(std::uint8_t const *buffer, size_t n);
///@}

protected:
Expand All @@ -107,7 +108,7 @@ class CompoundRegion : public Region {
/// nested operand regions and combining the results.
class UnionRegion : public CompoundRegion {
public:
static constexpr uint8_t TYPE_CODE = 'u';
static constexpr std::uint8_t TYPE_CODE = 'u';

using CompoundRegion::CompoundRegion;

Expand All @@ -119,15 +120,15 @@ class UnionRegion : public CompoundRegion {
using Region::contains;
bool contains(UnitVector3d const &v) const override;
Relationship relate(Region const &r) const override;
std::vector<uint8_t> encode() const override { return _encode(TYPE_CODE); }
std::vector<std::uint8_t> encode() const override { return _encode(TYPE_CODE); }

///@{
/// `decode` deserializes a UnionRegion from a byte string produced by
/// encode.
static std::unique_ptr<UnionRegion> decode(std::vector<uint8_t> const &s) {
static std::unique_ptr<UnionRegion> decode(std::vector<std::uint8_t> const &s) {
return decode(s.data(), s.size());
}
static std::unique_ptr<UnionRegion> decode(uint8_t const *buffer, size_t n) {
static std::unique_ptr<UnionRegion> decode(std::uint8_t const *buffer, size_t n) {
return std::make_unique<UnionRegion>(_decode(TYPE_CODE, buffer, n));
}
///@}
Expand All @@ -140,7 +141,7 @@ class UnionRegion : public CompoundRegion {
/// its nested operand regions and combining the results.
class IntersectionRegion : public CompoundRegion {
public:
static constexpr uint8_t TYPE_CODE = 'i';
static constexpr std::uint8_t TYPE_CODE = 'i';

using CompoundRegion::CompoundRegion;

Expand All @@ -152,15 +153,15 @@ class IntersectionRegion : public CompoundRegion {
using Region::contains;
bool contains(UnitVector3d const &v) const override;
Relationship relate(Region const &r) const override;
std::vector<uint8_t> encode() const override { return _encode(TYPE_CODE); }
std::vector<std::uint8_t> encode() const override { return _encode(TYPE_CODE); }

///@{
/// `decode` deserializes a IntersetionRegion from a byte string produced
/// by encode.
static std::unique_ptr<IntersectionRegion> decode(std::vector<uint8_t> const &s) {
static std::unique_ptr<IntersectionRegion> decode(std::vector<std::uint8_t> const &s) {
return decode(s.data(), s.size());
}
static std::unique_ptr<IntersectionRegion> decode(uint8_t const *buffer, size_t n) {
static std::unique_ptr<IntersectionRegion> decode(std::uint8_t const *buffer, size_t n) {
return std::make_unique<IntersectionRegion>(_decode(TYPE_CODE, buffer, n));
}
///@}
Expand Down
Loading

0 comments on commit 9a700aa

Please sign in to comment.