Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
barne856 committed Dec 24, 2023
1 parent 719c474 commit ddca3c8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include(Catch)
## Create the tests
add_executable(tests tests/tests.cpp)
add_executable(sample tests/sample.cpp)
add_executable(sample1 tests/samples/sample1.cpp)
add_library(squint)
target_sources(squint PUBLIC FILE_SET CXX_MODULES FILES
src/dimension.cpp
Expand All @@ -35,6 +36,7 @@ target_sources(squint PUBLIC FILE_SET CXX_MODULES FILES
)
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain squint)
target_link_libraries(sample PRIVATE squint)
target_link_libraries(sample1 PRIVATE squint)
if(USE_MKL)
# Set to your MKL directory path, you can source /opt/intel/oneapi/setvars.sh to set the environment variable MKLROOT
# you probably need to source this or else you could get OpenMP not found errors
Expand Down
4 changes: 4 additions & 0 deletions notes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
TODO: use multidimensional subscript operator to retrun value type when indexing to a scalar instead of tensor of shape 1
TODO: quantities should be templated instead of length and length_f use length<double> and length<float>
TODO: literal subscript are not needed - remove. e.g. _m, _yd, etc...

Math - Tensor Quantities (TQ)
Units
Linalg (Scalars, Vectors, Matrices)
Expand Down
4 changes: 2 additions & 2 deletions src/quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ template <typename T, dimensional D> class quantity {
requires(tensorial<S> && std::is_same<quantity, typename S::value_type>::value)
constexpr quantity(const S &other) : _elem(other.data()[0]._elem) {}
constexpr quantity(const quantity &other) : _elem(other._elem) {}
// implicit conversion from value type only if dimensionless
explicit(!std::is_same<D, dimensions::dimensionless>::value) constexpr quantity(const T &other) : _elem(other) {}
// implicit conversion from value type
constexpr quantity(const T &other) : _elem(other) {}
operator const T &() const
requires(std::is_same<D, dimensions::dimensionless>::value)
{
Expand Down
24 changes: 24 additions & 0 deletions tests/samples/sample1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <typeinfo>
#include <cassert>
#include <vector>
import squint;


int main(){
using position3d = squint::tensor<squint::quantities::length, 3>;
using time = squint::quantities::time;
using velocity = squint::quantities::velocity;
const auto dt = time{0.1};
std::vector<position3d> points{{1, 2, 3}};
for (auto &p : points)
{
std::cout << p << "\n";
const auto v = p / dt;
for (const velocity& vi : v)
{
std::cout << vi.as_fps() << "\n";
}
}
return 0;
}

0 comments on commit ddca3c8

Please sign in to comment.