Skip to content

Commit

Permalink
add missing mutable Array2d::row()
Browse files Browse the repository at this point in the history
  • Loading branch information
wkjarosz committed Dec 26, 2023
1 parent 2bf22e8 commit 6105d21
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 90 deletions.
68 changes: 38 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,59 @@ option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)
# Set a default build configuration (Release)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set(CMAKE_BUILD_TYPE
Release
CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
"MinSizeRel" "RelWithDebInfo")
endif()
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)

# This is useful when compiling with Ninja. When compiling with clang or gcc,
# this will force it to output well-formatted/colored output.
option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." FALSE)
if (${FORCE_COLORED_OUTPUT})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options (-fcolor-diagnostics)
endif ()
endif ()
option(FORCE_COLORED_OUTPUT
"Always produce ANSI-colored output (GNU/Clang only)." FALSE)
if(${FORCE_COLORED_OUTPUT})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-fdiagnostics-color=always)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-fcolor-diagnostics)
endif()
endif()

# Enable folders for projects in Visual Studio
if (CMAKE_GENERATOR MATCHES "Visual Studio")
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()

# Sanitize build environment for static build with C++11
if (MSVC)
if(MSVC)
# Disable annoying secure CRT warnings
add_definitions (/D "_CRT_SECURE_NO_WARNINGS")
add_definitions(/D "_CRT_SECURE_NO_WARNINGS")

# Parallel build on MSVC (all targets)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")

if (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")

# Disable Eigen vectorization for Windows 32 bit builds (issues with unaligned access segfaults)
# Disable Eigen vectorization for Windows 32 bit builds (issues with
# unaligned access segfaults)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DEIGEN_DONT_ALIGN")
endif()

# Static build
set(CompilerFlags
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
Expand All @@ -61,27 +71,25 @@ if(MSVC)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES
"GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-anonymous-struct -Wno-c99-extensions -Wno-nested-anon-types -Wno-deprecated-register")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wno-gnu-anonymous-struct -Wno-c99-extensions -Wno-nested-anon-types -Wno-deprecated-register"
)
endif()
endif()

include_directories(include ${CMAKE_CURRENT_BINARY_DIR})


if(BUILD_SHARED_LIBS)
add_library(galois++ SHARED
src/field.cpp
src/primes.cpp)
add_library(galois++ SHARED src/field.cpp src/primes.cpp)
else()
add_library(galois++ STATIC
src/field.cpp
src/primes.cpp)
add_library(galois++ STATIC src/field.cpp src/primes.cpp)
endif()

set_target_properties(galois++ PROPERTIES CXX_STANDARD 11)

ENABLE_TESTING()
enable_testing()
add_subdirectory(tests)
113 changes: 53 additions & 60 deletions include/galois++/array2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,61 @@ class Array2d
Array2d(); ///< empty array, 0 by 0 elements
Array2d(int sizeX, int sizeY); ///< sizeX by sizeY elements
Array2d(const Array2d &);
Array2d & operator=(const Array2d &);
Array2d &operator=(const Array2d &);
~Array2d();

///@{ \name Element access
T & at(int x, int y); ///< bounds-checked 2d access
const T & at(int x, int y) const; ///< bounds-checked 2d access
T & operator()(int x, int y); ///< unchecked 2d access
const T & operator()(int x, int y) const; ///< unchecked 2d access
T & at(int i); ///< bounds-checked linear access
const T & at(int i) const; ///< bounds-checked linear access
T & operator()(int i); ///< unchecked linear access
const T & operator()(int i) const; ///< unchecked linear access
const T * row(int y) const; ///< pointer to `y`-th row
T &at(int x, int y); ///< bounds-checked 2d access
const T &at(int x, int y) const; ///< bounds-checked 2d access
T &operator()(int x, int y); ///< unchecked 2d access
const T &operator()(int x, int y) const; ///< unchecked 2d access
T &at(int i); ///< bounds-checked linear access
const T &at(int i) const; ///< bounds-checked linear access
T &operator()(int i); ///< unchecked linear access
const T &operator()(int i) const; ///< unchecked linear access
T *row(int y); ///< pointer to `y`-th row
const T *row(int y) const; ///< pointer to `y`-th row
///@}

///@{ \name Dimension sizes
int width() const { return m_sizeX; } ///< size of first dimension
int height() const { return m_sizeY; } ///< size of second dimension
int size() const { return m_sizeX*m_sizeY;}///< total number of elements
int sizeX() const { return m_sizeX; } ///< size of first dimension
int sizeY() const { return m_sizeY; } ///< size of first dimension
int width() const { return m_sizeX; } ///< size of first dimension
int height() const { return m_sizeY; } ///< size of second dimension

int size() const { return m_sizeX * m_sizeY; } ///< total number of elements
int sizeX() const { return m_sizeX; } ///< size of first dimension
int sizeY() const { return m_sizeY; } ///< size of first dimension
///@}

void resize(int sizeX, int sizeY); ///< Resize to `sizeX` x `sizeY`
void reset(const T& value = T(0)); ///< Set all elements to `value`
void operator=(const T&); ///< Set all elements to `value`
void resize(int sizeX, int sizeY); ///< Resize to `sizeX` x `sizeY`
void reset(const T &value = T(0)); ///< Set all elements to `value`
void operator=(const T &); ///< Set all elements to `value`

protected:
std::vector<T> m_data; ///< the data
int m_sizeX; ///< size of first dimension
int m_sizeY; ///< size of second dimension
std::vector<T> m_data; ///< the data
int m_sizeX; ///< size of first dimension
int m_sizeY; ///< size of second dimension
};


template <typename T>
inline Array2d<T>::Array2d():
m_data(0), m_sizeX(0), m_sizeY(0)
inline Array2d<T>::Array2d() : m_data(0), m_sizeX(0), m_sizeY(0)
{
// empty
}


template <typename T>
inline Array2d<T>::Array2d(int sizeX, int sizeY):
m_data(sizeX * sizeY), m_sizeX(sizeX), m_sizeY(sizeY)
inline Array2d<T>::Array2d(int sizeX, int sizeY) : m_data(sizeX * sizeY), m_sizeX(sizeX), m_sizeY(sizeY)
{
// empty
}


template<class T>
Array2d<T>::Array2d(const Array2d<T> & other)
: m_data(other.m_data), m_sizeX(other.m_sizeX), m_sizeY(other.m_sizeY)
template <class T>
Array2d<T>::Array2d(const Array2d<T> &other)
: m_data(other.m_data), m_sizeX(other.m_sizeX), m_sizeY(other.m_sizeY)
{
}


template<class T>
Array2d<T>& Array2d<T>::operator=(const Array2d<T>& other)
template <class T>
Array2d<T> &Array2d<T>::operator=(const Array2d<T> &other)
{
m_sizeX = other.m_sizeX;
m_sizeY = other.m_sizeY;
Expand All @@ -88,63 +83,65 @@ inline Array2d<T>::~Array2d()
// empty
}


template <typename T>
inline T & Array2d<T>::operator()(int x, int y)
inline T &Array2d<T>::operator()(int x, int y)
{
return m_data[y*m_sizeX + x];
return m_data[y * m_sizeX + x];
}

template <typename T>
inline const T & Array2d<T>::operator()(int x, int y) const
inline const T &Array2d<T>::operator()(int x, int y) const
{
return m_data[y*m_sizeX + x];
return m_data[y * m_sizeX + x];
}

template <typename T>
inline T & Array2d<T>::at(int x, int y)
inline T &Array2d<T>::at(int x, int y)
{
return m_data.at(y*m_sizeX + x);
return m_data.at(y * m_sizeX + x);
}

template <typename T>
inline const T & Array2d<T>::at(int x, int y) const
inline const T &Array2d<T>::at(int x, int y) const
{
return m_data.at(y*m_sizeX + x);
return m_data.at(y * m_sizeX + x);
}


template <typename T>
inline T & Array2d<T>::operator()(int i)
inline T &Array2d<T>::operator()(int i)
{
return m_data[i];
}

template <typename T>
inline const T & Array2d<T>::operator()(int i) const
inline const T &Array2d<T>::operator()(int i) const
{
return m_data[i];
}

template <typename T>
inline T & Array2d<T>::at(int i)
inline T &Array2d<T>::at(int i)
{
return m_data.at(i);
}

template <typename T>
inline const T & Array2d<T>::at(int i) const
inline const T &Array2d<T>::at(int i) const
{
return m_data.at(i);
}


template <typename T>
inline const T * Array2d<T>::row(int y) const
inline T *Array2d<T>::row(int y)
{
return &m_data[y*m_sizeX];
return &m_data[y * m_sizeX];
}

template <typename T>
inline const T *Array2d<T>::row(int y) const
{
return &m_data[y * m_sizeX];
}

template <typename T>
inline void Array2d<T>::resize(int sizeX, int sizeY)
Expand All @@ -157,20 +154,16 @@ inline void Array2d<T>::resize(int sizeX, int sizeY)
m_sizeY = sizeY;
}


template <typename T>
inline void Array2d<T>::reset(const T& value)
inline void Array2d<T>::reset(const T &value)
{
int size = m_sizeX*m_sizeY;
int size = m_sizeX * m_sizeY;
for (int i = 0; i < size; i++)
m_data[i] = value;
}


template <typename T>
inline void Array2d<T>::operator=(const T& value)
inline void Array2d<T>::operator=(const T &value)
{
reset(value);
}


0 comments on commit 6105d21

Please sign in to comment.