Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/merge.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


# Copyright 2023 NWChemEx-Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2025 NWChemEx-Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

venv/
31 changes: 31 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2021 NWChemEx-Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
header:
license:
spdx-id: Apache-2.0
copyright-owner: NWChemEx-Project

paths-ignore:
- .github/
- docs/Makefile
- docs/build/
- docs/requirements.txt
- cmake/generate_module_docs.cpp.in
- LICENSE
- version.txt
- build/
- .vscode/

comment: never
19 changes: 14 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,41 @@
# limitations under the License.

cmake_minimum_required(VERSION 3.14)
# Downloads common CMake modules used throughout NWChemEx
include(cmake/get_nwx_cmake.cmake)

project(wtf VERSION "1.0.0" LANGUAGES CXX)
include(cmake/disable_in_source_builds.cmake)

set(CMAKE_CXX_STANDARD 20)

# TODO: Make these into proper options
set(BUILD_TESTING TRUE)
set(CMAKE_BUILD_SHARED_LIBS ON)

include(cmake/get_dependencies.cmake)

# Define the documentation target
include(nwx_cxx_api_docs)
nwx_cxx_api_docs("include" "src")

# Build the Library
file(GLOB_RECURSE WTF_HEADER_FILES CONFIGURE_DEPENDS include/wtf/*.hpp)
file(GLOB_RECURSE WTF_SOURCE_FILES CONFIGURE_DEPENDS src/wtf/*.cpp)
add_library(${PROJECT_NAME} ${WTF_SOURCE_FILES})
target_link_libraries(${PROJECT_NAME})
target_include_directories(${PROJECT_NAME}
PUBLIC
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

if(${BUILD_TESTING})
include(CTest)
get_dependencies(catch2)
include(cmake/catch2_tests_from_dir.cmake)
catch2_tests_from_dir(
"unit_test_${PROJECT_NAME}"
tests/unit_tests/wtf
"unit_test_${PROJECT_NAME}"
tests/unit_tests/wtf
${PROJECT_NAME}
)
endif()
endif()
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
<!--
~ Copyright 2025 NWChemEx-Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

# WeaklyTypedFloat (WTF)

This repo is still under heavy development! I am hoping for an alpha release
this week.

The goal of WTF is to provide a small domain-specific language (DSL) that can
be used to unify interfaces involving floating-point types. Using WTF the user
writes their interfaces in terms of "weakly typed" objects like `Float` and
`FloatBuffer`, and determination of the actual floating-point type is deferred
to runtime.
be used to unify interfaces involving floating-point types. Using WTF the user
writes their interfaces in terms of "weakly typed" objects like `Float` and
`FloatBuffer`, and determination of the actual floating-point type is deferred
to runtime.

## Problem Description

Full description (TODO: Add link to the documentation)

Depending on the standard, C++ already natively has a lot of floating-point
Depending on the standard, C++ already natively has a lot of floating-point
types, e.g., `float`, `double`, `long double`, `std::complex<float>`, and
`std::complex<double>`. This is before considering custom floating-point types,
such as those needed for automatic differentiation, or hardware-specific types.
When attempting to maintain interfaces with explicit types (such as is required
for C-style interfaces) this leads to a combinatorial explosion in the number
of interfaces.
for C-style interfaces) this leads to a combinatorial explosion in the number
of interfaces.
18 changes: 16 additions & 2 deletions cmake/dependencies/catch2.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# Copyright 2025 NWChemEx-Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include_guard()
include(FetchContent)

FetchContent_Declare(
catch2
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG "v3.11.0"
)
)
16 changes: 15 additions & 1 deletion cmake/get_dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2025 NWChemEx-Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include_guard()
include(FetchContent)

Expand All @@ -8,4 +22,4 @@ function(get_dependencies)
endforeach()

FetchContent_MakeAvailable(${ARGN})
endfunction()
endfunction()
31 changes: 31 additions & 0 deletions cmake/get_nwx_cmake.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2024 NWChemEx Community
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include_guard()

macro(get_nwx_cmake)
include(FetchContent)
FetchContent_Declare(
nwx_cmake
GIT_REPOSITORY https://github.com/NWChemEx/NWXCMake
)
FetchContent_MakeAvailable(nwx_cmake)
set(
CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${nwx_cmake_SOURCE_DIR}/cmake"
CACHE STRING ""
FORCE
)
endmacro()

get_nwx_cmake()
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = WeaklyTypedFloat
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
20 changes: 19 additions & 1 deletion docs/source/adding_a_new_type.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
.. Copyright 2025 NWChemEx-Project
..
.. Licensed under the Apache License, Version 2.0 (the "License");
.. you may not use this file except in compliance with the License.
.. You may obtain a copy of the License at
..
.. http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.

###############################
Registering a New Type with WTF
###############################

These are notes on how to register a new type with WTF.

.. note::
Expand All @@ -10,4 +28,4 @@ These are notes on how to register a new type with WTF.
Optional steps:

- Specialize Precision
- Ensure implicit conversions are visible to/from your type.
- Ensure implicit conversions are visible to/from your type.
26 changes: 20 additions & 6 deletions docs/source/developer/architecture.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
.. Copyright 2025 NWChemEx-Project
..
.. Licensed under the Apache License, Version 2.0 (the "License");
.. you may not use this file except in compliance with the License.
.. You may obtain a copy of the License at
..
.. http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.

###################
Architecture of WTF
###################
Expand All @@ -9,11 +23,11 @@ FAQs
- There's a lot of repetition between ``FloatHolder`` and ``FloatViewHolder``,
why can't we combine them?

- In hindsight, we could define a class ``FloatHolderAPI<T>`` that is
templated on the type of ``Float`` that will hold it. ``FloatModel`` would
always derive from ``FloatHolderAPI<Float>`` whereas ``FloatViewModel``
would derive from ``FloatHolderAPI<Float>`` or
``FloatHolderAPI<const Float>`` depending on the const-ness of the type
- In hindsight, we could define a class ``FloatHolderAPI<T>`` that is
templated on the type of ``Float`` that will hold it. ``FloatModel`` would
always derive from ``FloatHolderAPI<Float>`` whereas ``FloatViewModel``
would derive from ``FloatHolderAPI<Float>`` or
``FloatHolderAPI<const Float>`` depending on the const-ness of the type
argument to ``FloatViewModel``. The holder classes were already written
when this realization occurred, so it was not worth the effort to refactor
them.
them.
2 changes: 1 addition & 1 deletion docs/source/developer/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Developer Documentation

.. toctree::
:maxdepth: 2
:caption: Contents
:caption: Design and Technical Documents

statement_of_need
scope
Expand Down
22 changes: 12 additions & 10 deletions docs/source/developer/scope.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ erased FP value. In practice users will rarely want to work with a single value
so we will also need to provide a way to work with collections of these values,
of particular note is that users will want to work with collections of these
values that are stored in contiguous memory. To provide an object-oriented API,
it must be possible for the user to grab an element from the collection in a
way that the element is assignable, but still stored in the full collection
(e.g., think of it as a reference or view of the element). Similarly, it must
be possible to grab a sub-collection of the full collection in a way that the
it must be possible for the user to grab an element from the collection in a
way that the element is assignable, but still stored in the full collection
(e.g., think of it as a reference or view of the element). Similarly, it must
be possible to grab a sub-collection of the full collection in a way that the
sub-collection is assignable, but still stored in the full collection. The
latter also enables the user to interface already allocated memory with WTF.

In summary:

- ``wtf::Float`` class that holds a type-erased floating point value. Owns the
underlying value.
underlying value.
- ``wtf::FloatBuffer`` class that acts like it holds a series of ``wtf::Float``
objects, but actually unwraps the underlying type into contiguous memory. Owns
the underlying memory.
the underlying memory.
- ``wtf::FloatView`` class that acts like it is aliasing a ``wtf::Float``
object, but actually wraps a pointer to the raw memory.
- ``wtf::FloatBufferView`` class that acts like an alias to a
``wtf::FloatBuffer`` object, but actually wraps pointer(s) to the contiguous
- ``wtf::FloatBufferView`` class that acts like an alias to a
``wtf::FloatBuffer`` object, but actually wraps pointer(s) to the contiguous
memory.

In practice, we will also need ``const`` versions of the view classes (views
Expand All @@ -67,10 +67,11 @@ Under typical circumstances all C++ objects should provide:
- Copy and move assignment operators.
- Deep copy for objects that own memory. Shallow for those that alias.
- Equality/Inequality operators.

- Exact equality. Good for testing that state is set correctly. Not used for
checking results of numerical calculations (vide infra).

Since these will be numerical types it will also be nice if our objects
Since these will be numerical types it will also be nice if our objects
provided:

- Operations to establish order (e.g., ``<``, ``>``, etc...).
Expand All @@ -93,6 +94,7 @@ Maybe We Support
****************

- Element-wise arithmetic operations (e.g., ``+``, ``-``, ``*``, ``/``).

- Implementing these in a performant manner may require us to use specialized
math libraries, which in turn makes this start to look like linear
algebra.
algebra.
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ working with floating-point (FP) numbers in a type-erased manner.
:caption: Contents

developer/index
adding_a_new_type

.. toctree::
:maxdepth: 2
:caption: APIs:

module_api/index
C++ API <https://nwchemex.github.io/WeaklyTypedFloat/wtf_cxx_api/index.html>
Loading
Loading