Skip to content

Commit

Permalink
length returns now int and not size_t. dim returns now a const obj. E…
Browse files Browse the repository at this point in the history
…xtractDataType for borrow added.
  • Loading branch information
Konrad1991 committed May 28, 2024
1 parent e9f197d commit 36baa4c
Show file tree
Hide file tree
Showing 5 changed files with 1,957 additions and 1,407 deletions.
8 changes: 8 additions & 0 deletions include/etr_bits/Core/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ struct ExtractDataType<const Buffer<T, R, Trait>> {
using RetType = T const;
};

template <typename T, typename Trait> struct ExtractDataType<Borrow<T, Trait>> {
using RetType = T;
};
template <typename T, typename Trait>
struct ExtractDataType<const Borrow<T, Trait>> {
using RetType = T const;
};

template <typename Trait = DoubleTrait> struct doubleWrapper {
using TypeTrait = Trait;
using Type = DoubleTrait;
Expand Down
8 changes: 4 additions & 4 deletions include/etr_bits/Helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ inline std::size_t length(T inp) {

template <typename T>
requires IsVec<T>
inline auto length(T &inp) {
inline int length(T &inp) {
return inp.size();
}

template <typename T>
requires IsVec<T>
inline auto length(const T &&inp) {
inline int length(const T &&inp) {
return inp.size();
}

Expand All @@ -105,7 +105,7 @@ inline auto dim(T inp) {

template <typename T>
requires(IsRVec<T> || IsSubVec<T> || OperationVec<T>)
inline auto dim(const T &inp) {
inline const auto dim(const T &inp) {
ass(inp.im(), "dim can only be called with matrix");
Vec<int> ret(SI{2});
ret[0] = inp.nr();
Expand All @@ -115,7 +115,7 @@ inline auto dim(const T &inp) {

template <typename T>
requires IsVec<T>
inline auto dim(T &inp) {
inline const auto dim(T &inp) {
ass(inp.im(), "dim can only be called with matrix");
Vec<int> ret(SI{2});
ret[0] = inp.nr();
Expand Down
4 changes: 2 additions & 2 deletions include/etr_bits/Subsetting/at.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace etr {
template <typename T, typename R>
requires(IsRVec<T> || IsSubVec<T> ||
OperationVec<T> && std::is_arithmetic_v<R>)
inline auto at(T &&inp, R i) {
inline auto at(const T &inp, R i) {
if constexpr (std::is_integral_v<R>) {
return inp[i];
} else if constexpr (std::is_floating_point_v<R>) {
Expand Down Expand Up @@ -95,7 +95,7 @@ template <typename T, typename R, typename C>
requires(IsRVec<T> || IsSubVec<T> ||
OperationVec<T> && std::is_arithmetic_v<R> &&
std::is_arithmetic_v<C>)
inline auto at(T &&inp, R r, C c) {
inline auto at(const T &inp, R r, C c) {
ass(inp.im() == true, "Input is not a matrix!");
if constexpr (std::is_integral_v<R> && std::is_integral_v<C>) {
r--;
Expand Down
21 changes: 21 additions & 0 deletions tests/Borrow_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,30 @@ void test_borrow() {
}
delete[] ptr;
}
// NOTE: test Borrow with other functions
{
// TODO: add more tests
std::string s = "BorrowWithOtherFcts: ";
double *ptr = new double[10];
BorrowPtr bp(ptr, 10);
Vec<double> res = coca(1, 2, 3, bp);
ass(res.size() == 13, s + "coca");
delete[] ptr;
}
}

int main(int argc, char *argv[]) {
test_borrow();
Vec<double> ret;
ret = etr::vector_numeric(etr::i2d(20));
printTAST<decltype(subset(ret, 1))>();
ret(1) =
1; // TODO: int works. Implement the same call stack for double and bool
ret(coca(6, 2, 3)) = coca(1.2, 1.2, 1.2);
// ret(1) = 1.2;
// etr::subset(ret, 1) = etr::i2d(1);
// TODO: this is a problam. Check that each class: Buffer, Borrow,
// BorrowSEXP etc. can be assigned with the result of anither class
print(ret);
return 0;
}
Loading

0 comments on commit 36baa4c

Please sign in to comment.