Skip to content

Commit

Permalink
Refactor shape type
Browse files Browse the repository at this point in the history
  • Loading branch information
Pencilcaseman committed Aug 20, 2023
1 parent cbc5807 commit 50f93a7
Show file tree
Hide file tree
Showing 10 changed files with 1,621 additions and 1,619 deletions.
2 changes: 1 addition & 1 deletion librapid/include/librapid/array/array.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LIBRAPID_ARRAY
#define LIBRAPID_ARRAY

#include "sizetype.hpp"
#include "shape.hpp"
#include "strideTools.hpp"
#include "storage.hpp"

Expand Down
1,573 changes: 786 additions & 787 deletions librapid/include/librapid/array/arrayContainer.hpp

Large diffs are not rendered by default.

231 changes: 116 additions & 115 deletions librapid/include/librapid/array/arrayTypeDef.hpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion librapid/include/librapid/array/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace librapid {
public:
using Type = Function<desc, Functor_, Args...>;
using Functor = Functor_;
using ShapeType = Shape<size_t, 32>;
using ShapeType = Shape<LIBRAPID_MAX_ARRAY_DIMS>;
using StrideType = ShapeType;
using Scalar = typename typetraits::TypeInfo<Type>::Scalar;
using Backend = typename typetraits::TypeInfo<Type>::Backend;
Expand Down
144 changes: 72 additions & 72 deletions librapid/include/librapid/array/generalArrayViewToString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,85 @@
#define LIBRAPID_ARRAY_ARRAY_VIEW_STRING_HPP

namespace librapid {
namespace detail {
template<typename ArrayViewType, typename T, typename Char, typename Ctx>
void generalArrayViewToString(const array::GeneralArrayView<ArrayViewType> &view,
const fmt::formatter<T, Char> &formatter, char bracket,
char separator, int64_t indent, Ctx &ctx) {
char bracketCharOpen, bracketCharClose;
namespace detail {
template<typename ArrayViewType, typename T, typename Char, typename Ctx>
void generalArrayViewToString(const array::GeneralArrayView<ArrayViewType> &view,
const fmt::formatter<T, Char> &formatter, char bracket,
char separator, int64_t indent, Ctx &ctx) {
char bracketCharOpen, bracketCharClose;

switch (bracket) {
case 'r':
bracketCharOpen = '(';
bracketCharClose = ')';
break;
case 's':
bracketCharOpen = '[';
bracketCharClose = ']';
break;
case 'c':
bracketCharOpen = '{';
bracketCharClose = '}';
break;
case 'a':
bracketCharOpen = '<';
bracketCharClose = '>';
break;
case 'p':
bracketCharOpen = '|';
bracketCharClose = '|';
break;
default:
bracketCharOpen = '[';
bracketCharClose = ']';
break;
}
switch (bracket) {
case 'r':
bracketCharOpen = '(';
bracketCharClose = ')';
break;
case 's':
bracketCharOpen = '[';
bracketCharClose = ']';
break;
case 'c':
bracketCharOpen = '{';
bracketCharClose = '}';
break;
case 'a':
bracketCharOpen = '<';
bracketCharClose = '>';
break;
case 'p':
bracketCharOpen = '|';
bracketCharClose = '|';
break;
default:
bracketCharOpen = '[';
bracketCharClose = ']';
break;
}

// Separator char is already the correct character
// Separator char is already the correct character

if (view.ndim() == 0) {
formatter.format(view.scalar(0), ctx);
} else if (view.ndim() == 1) {
fmt::format_to(ctx.out(), "{}", bracketCharOpen);
for (int64_t i = 0; i < static_cast<int64_t>(view.shape()[0]); i++) {
formatter.format(view.scalar(i), ctx);
if (i != view.shape()[0] - 1) {
if (separator == ' ') {
fmt::format_to(ctx.out(), " ");
} else {
fmt::format_to(ctx.out(), "{} ", separator);
}
}
}
fmt::format_to(ctx.out(), "{}", bracketCharClose);
} else {
fmt::format_to(ctx.out(), "{}", bracketCharOpen);
for (int64_t i = 0; i < static_cast<int64_t>(view.shape()[0]); i++) {
if (i > 0) fmt::format_to(ctx.out(), "{}", std::string(indent + 1, ' '));
if (view.ndim() == 0) {
formatter.format(view.scalar(0), ctx);
} else if (view.ndim() == 1) {
fmt::format_to(ctx.out(), "{}", bracketCharOpen);
for (int64_t i = 0; i < static_cast<int64_t>(view.shape()[0]); i++) {
formatter.format(view.scalar(i), ctx);
if (i != view.shape()[0] - 1) {
if (separator == ' ') {
fmt::format_to(ctx.out(), " ");
} else {
fmt::format_to(ctx.out(), "{} ", separator);
}
}
}
fmt::format_to(ctx.out(), "{}", bracketCharClose);
} else {
fmt::format_to(ctx.out(), "{}", bracketCharOpen);
for (int64_t i = 0; i < static_cast<int64_t>(view.shape()[0]); i++) {
if (i > 0) fmt::format_to(ctx.out(), "{}", std::string(indent + 1, ' '));
generalArrayViewToString(
view[i], formatter, bracket, separator, indent + 1, ctx);
if (i != view.shape()[0] - 1) {
if (separator == ' ') {
fmt::format_to(ctx.out(), "\n");
} else {
fmt::format_to(ctx.out(), "{}\n", separator);
}
if (view.ndim() > 2) { fmt::format_to(ctx.out(), "\n"); }
}
}
fmt::format_to(ctx.out(), "{}", bracketCharClose);
}
}
} // namespace detail
if (i != view.shape()[0] - 1) {
if (separator == ' ') {
fmt::format_to(ctx.out(), "\n");
} else {
fmt::format_to(ctx.out(), "{}\n", separator);
}
if (view.ndim() > 2) { fmt::format_to(ctx.out(), "\n"); }
}
}
fmt::format_to(ctx.out(), "{}", bracketCharClose);
}
}
} // namespace detail

namespace array {
template<typename ArrayViewType>
template<typename T, typename Char, typename Ctx>
void GeneralArrayView<ArrayViewType>::str(const fmt::formatter<T, Char> &format, char bracket,
char separator, Ctx &ctx) const {
namespace array {
template<typename ArrayViewType>
template<typename T, typename Char, typename Ctx>
void GeneralArrayView<ArrayViewType>::str(const fmt::formatter<T, Char> &format,
char bracket, char separator, Ctx &ctx) const {
detail::generalArrayViewToString(*this, format, bracket, separator, 0, ctx);
}
} // namespace array
}
} // namespace array
} // namespace librapid

#endif // LIBRAPID_ARRAY_ARRAY_VIEW_STRING_HPP
Loading

0 comments on commit 50f93a7

Please sign in to comment.