Skip to content

Commit 681640f

Browse files
committed
Bug fixes and updates
1 parent ec00f4c commit 681640f

File tree

11 files changed

+57
-103
lines changed

11 files changed

+57
-103
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ if (${SKBUILD})
166166
install(TARGETS ${module_name} DESTINATION .)
167167
else()
168168
set(module_name "librapid")
169-
add_library(${module_name} STATIC ${LIBRAPID_SOURCES})
169+
add_library(${module_name} STATIC ${LIBRAPID_SOURCES}
170+
librapid/include/librapid/core/log.hpp)
170171
endif()
171172

172173
# clang-format off

examples/example-array-2.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ auto main() -> int {
1212
std::vector<std::vector<float>> firstData = {{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f, 6.0f}};
1313
std::vector<std::vector<float>> secondData = {{1.0f}, {2.0f}, {3.0f}};
1414

15-
auto firstMatrix = lrc::Array<float>::fromData(firstData);
16-
auto secondMatrix = lrc::Array<float>::fromData(secondData);
15+
auto firstMatrix = lrc::Array<float>(firstData);
16+
auto secondMatrix = lrc::Array<float>(secondData);
1717
auto firstResult = lrc::dot(firstMatrix, secondMatrix);
1818
fmt::print("Left:\n{}\n", firstMatrix);
1919
fmt::print("Right:\n{}\n", secondMatrix);

librapid/bindings/__init__.py

-1
This file was deleted.

librapid/bindings/generators/arrayGenerator.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,19 @@ def generateFunctionsForArray(config):
6767

6868
# Static fromData (n dimensions)
6969
for n in range(1, 9):
70-
cppType = ""
71-
for j in range(n):
72-
cppType += "std::vector<"
73-
cppType += config['scalar'] + ">" * n
70+
cppType = ("std::vector<" * n) + config['scalar'] + (">" * n)
7471

7572
methods.append(
7673
function.Function(
77-
name="fromData",
74+
name="__init__",
7875
args=[
7976
argument.Argument(
8077
name=f"array{n}D",
8178
type=cppType,
8279
const=True,
8380
ref=True,
8481
)
85-
],
86-
static=True,
87-
op=f"""
88-
return {generateCppArrayType(config)}::fromData(array{n}D);
89-
"""
82+
]
9083
)
9184
)
9285

librapid/bindings/generators/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
boilerplate = textwrap.dedent(f"""
1111
#pragma once
1212
13-
#ifndef LIBRAPID_DEBUG
13+
#ifndef LIBRAPID_DEBUG
1414
#define LIBRAPID_DEBUG
1515
#endif
1616

librapid/bindings/python/__init__.py

-1
This file was deleted.

librapid/include/librapid/array/arrayContainer.hpp

+10-27
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,19 @@ namespace librapid {
9898
/// Default constructor
9999
ArrayContainer();
100100

101-
template<typename T>
102-
LIBRAPID_ALWAYS_INLINE ArrayContainer(const std::initializer_list<T> &data);
101+
// template<typename T>
102+
// LIBRAPID_ALWAYS_INLINE ArrayContainer(const std::initializer_list<T> &data);
103103

104-
template<typename T>
105-
explicit LIBRAPID_ALWAYS_INLINE ArrayContainer(const std::vector<T> &data);
104+
// template<typename T>
105+
// explicit LIBRAPID_ALWAYS_INLINE ArrayContainer(const std::vector<T> &data);
106106

107107
// clang-format off
108108
#define SINIT(SUB_TYPE) std::initializer_list<SUB_TYPE>
109109
#define SVEC(SUB_TYPE) std::vector<SUB_TYPE>
110110

111-
#define ARRAY_FROM_DATA_DEF(TYPE_INIT, TYPE_VEC) \
112-
LIBRAPID_NODISCARD static LIBRAPID_ALWAYS_INLINE auto fromData(const TYPE_INIT &data) \
113-
-> ArrayContainer; \
114-
LIBRAPID_NODISCARD static LIBRAPID_ALWAYS_INLINE auto fromData(const TYPE_VEC &data) \
115-
-> ArrayContainer
111+
#define ARRAY_FROM_DATA_DEF(TYPE_INIT, TYPE_VEC) \
112+
LIBRAPID_ALWAYS_INLINE ArrayContainer(const TYPE_INIT & data); \
113+
explicit LIBRAPID_ALWAYS_INLINE ArrayContainer(const TYPE_VEC &data) ;
116114

117115
ARRAY_FROM_DATA_DEF(SINIT(Scalar), SVEC(Scalar));
118116
ARRAY_FROM_DATA_DEF(SINIT(SINIT(Scalar)), SVEC(SVEC(Scalar)));
@@ -359,20 +357,6 @@ namespace librapid {
359357
LIBRAPID_ALWAYS_INLINE ArrayContainer<ShapeType_, StorageType_>::ArrayContainer() :
360358
m_shape(StorageType_::template defaultShape<ShapeType_>()), m_size(0) {}
361359

362-
template<typename ShapeType_, typename StorageType_>
363-
template<typename T>
364-
LIBRAPID_ALWAYS_INLINE ArrayContainer<ShapeType_, StorageType_>::ArrayContainer(
365-
const std::initializer_list<T> &data) :
366-
m_shape({data.size()}),
367-
m_size(data.size()), m_storage(StorageType::fromData(data)) {}
368-
369-
template<typename ShapeType_, typename StorageType_>
370-
template<typename T>
371-
LIBRAPID_ALWAYS_INLINE
372-
ArrayContainer<ShapeType_, StorageType_>::ArrayContainer(const std::vector<T> &data) :
373-
m_shape({data.size()}),
374-
m_size(data.size()), m_storage(StorageType::fromData(data)) {}
375-
376360
template<typename ShapeType_, typename StorageType_>
377361
LIBRAPID_ALWAYS_INLINE
378362
ArrayContainer<ShapeType_, StorageType_>::ArrayContainer(const Shape &shape) :
@@ -913,10 +897,9 @@ namespace librapid {
913897

914898
template<typename ShapeType_, typename StorageType_>
915899
template<typename T, typename Char, size_t N, typename Ctx>
916-
LIBRAPID_ALWAYS_INLINE void
917-
ArrayContainer<ShapeType_, StorageType_>::str(const fmt::formatter<T, Char> &format,
918-
char bracket, char separator,
919-
const char (&formatString)[N], Ctx &ctx) const {
900+
LIBRAPID_ALWAYS_INLINE void ArrayContainer<ShapeType_, StorageType_>::str(
901+
const fmt::formatter<T, Char> &format, char bracket, char separator,
902+
const char (&formatString)[N], Ctx &ctx) const {
920903
createGeneralArrayView(*this).str(format, bracket, separator, formatString, ctx);
921904
}
922905
} // namespace array

librapid/include/librapid/array/arrayFromData.hpp

+33-27
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
#ifndef LIBRAPID_ARRAY_FROM_DATA_HPP
22
#define LIBRAPID_ARRAY_FROM_DATA_HPP
33

4-
namespace librapid {
4+
namespace librapid::array {
55
template<typename ShapeType, typename StorageType>
6-
LIBRAPID_ALWAYS_INLINE auto array::ArrayContainer<ShapeType, StorageType>::fromData(
7-
const std::initializer_list<Scalar> &data) -> ArrayContainer {
8-
static_assert(!std::is_same_v<ShapeType, MatrixShape>,
9-
"Cannot create a matrix from a 1D array");
6+
LIBRAPID_ALWAYS_INLINE
7+
ArrayContainer<ShapeType, StorageType>::ArrayContainer(
8+
const std::initializer_list<Scalar> &data) :
9+
m_shape({data.size()}),
10+
m_size(data.size()), m_storage(StorageType::fromData(data)) {
1011
LIBRAPID_ASSERT(data.size() > 0, "Array must have at least one element");
11-
return ArrayContainer(data);
1212
}
1313

1414
template<typename ShapeType, typename StorageType>
15-
LIBRAPID_ALWAYS_INLINE auto
16-
array::ArrayContainer<ShapeType, StorageType>::fromData(const std::vector<Scalar> &data)
17-
-> ArrayContainer {
18-
static_assert(!std::is_same_v<ShapeType, MatrixShape>,
19-
"Cannot create a matrix from a 1D array");
15+
LIBRAPID_ALWAYS_INLINE ArrayContainer<ShapeType, StorageType>::ArrayContainer::ArrayContainer(
16+
const std::vector<Scalar> &data) :
17+
m_shape({data.size()}),
18+
m_size(data.size()), m_storage(StorageType::fromData(data)) {
2019
LIBRAPID_ASSERT(data.size() > 0, "Array must have at least one element");
21-
return ArrayContainer(data);
2220
}
2321

2422
template<typename ShapeType, typename StorageType>
25-
LIBRAPID_ALWAYS_INLINE auto array::ArrayContainer<ShapeType, StorageType>::fromData(
26-
const std::initializer_list<std::initializer_list<Scalar>> &data) -> ArrayContainer {
23+
LIBRAPID_ALWAYS_INLINE ArrayContainer<ShapeType, StorageType>::ArrayContainer(
24+
const std::initializer_list<std::initializer_list<Scalar>> &data) {
2725
LIBRAPID_ASSERT(data.size() > 0, "Cannot create a zero-sized array");
2826

2927
if constexpr (std::is_same_v<ShapeType, MatrixShape>) {
@@ -36,7 +34,9 @@ namespace librapid {
3634
res(i, j) = data.begin()[i].begin()[j];
3735
}
3836
}
39-
return res;
37+
38+
// return res;
39+
*this = res;
4040
} else {
4141
auto newShape = ShapeType({data.size(), data.begin()->size()});
4242
#if defined(LIBRAPID_ENABLE_ASSERT)
@@ -47,14 +47,16 @@ namespace librapid {
4747
#endif
4848
auto res = ArrayContainer(newShape);
4949
int64_t index = 0;
50-
for (const auto &item : data) res[index++] = fromData(item);
51-
return res;
50+
for (const auto &item : data) res[index++] = ArrayContainer(item);
51+
52+
// return res;
53+
*this = res;
5254
}
5355
}
5456

5557
template<typename ShapeType, typename StorageType>
56-
LIBRAPID_ALWAYS_INLINE auto array::ArrayContainer<ShapeType, StorageType>::fromData(
57-
const std::vector<std::vector<Scalar>> &data) -> ArrayContainer {
58+
LIBRAPID_ALWAYS_INLINE ArrayContainer<ShapeType, StorageType>::ArrayContainer(
59+
const std::vector<std::vector<Scalar>> &data) {
5860
LIBRAPID_ASSERT(data.size() > 0, "Cannot create a zero-sized array");
5961

6062
if constexpr (std::is_same_v<ShapeType, MatrixShape>) {
@@ -65,7 +67,9 @@ namespace librapid {
6567
"Arrays must have consistent shapes");
6668
for (size_t j = 0; j < data[i].size(); ++j) { res(i, j) = data[i][j]; }
6769
}
68-
return res;
70+
71+
// return res;
72+
*this = res;
6973
} else {
7074
auto newShape = ShapeType({data.size(), data.begin()->size()});
7175
#if defined(LIBRAPID_ENABLE_ASSERT)
@@ -76,19 +80,21 @@ namespace librapid {
7680
#endif
7781
auto res = ArrayContainer(newShape);
7882
int64_t index = 0;
79-
for (const auto &item : data) res[index++] = fromData(item);
80-
return res;
83+
for (const auto &item : data) res[index++] = ArrayContainer(item);
84+
85+
// return res;
86+
*this = res;
8187
}
8288
}
8389

8490
#define HIGHER_DIMENSIONAL_FROM_DATA(TYPE) \
8591
template<typename ShapeType, typename StorageType> \
86-
LIBRAPID_ALWAYS_INLINE auto array::ArrayContainer<ShapeType, StorageType>::fromData( \
87-
const TYPE &data) -> ArrayContainer { \
92+
LIBRAPID_ALWAYS_INLINE ArrayContainer<ShapeType, StorageType>::ArrayContainer( \
93+
const TYPE &data) { \
8894
LIBRAPID_ASSERT(data.size() > 0, "Cannot create a zero-sized array"); \
8995
std::vector<ArrayContainer> tmp(data.size()); \
9096
int64_t index = 0; \
91-
for (const auto &item : data) tmp[index++] = std::move(fromData(item)); \
97+
for (const auto &item : data) tmp[index++] = std::move(ArrayContainer(item)); \
9298
auto zeroShape = tmp[0].shape(); \
9399
for (int64_t i = 0; i < data.size(); ++i) \
94100
LIBRAPID_ASSERT(tmp[i].shape().operator==(zeroShape), \
@@ -98,7 +104,7 @@ namespace librapid {
98104
for (size_t i = 0; i < zeroShape.ndim(); ++i) { newShape[i + 1] = zeroShape[i]; } \
99105
auto res = Array<Scalar, Backend>(newShape); \
100106
for (int64_t i = 0; i < data.size(); ++i) res[i] = tmp[i]; \
101-
return res; \
107+
*this = res; \
102108
}
103109

104110
#define SINIT(SUB_TYPE) std::initializer_list<SUB_TYPE>
@@ -120,6 +126,6 @@ namespace librapid {
120126

121127
#undef SINIT
122128
#undef HIGHER_DIMENSIONAL_FROM_DATA
123-
} // namespace librapid
129+
} // namespace librapid::array
124130

125131
#endif // LIBRAPID_ARRAY_FROM_DATA_HPP

librapid/include/librapid/math/complex.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
# include <arm64_neon.h>
2121
#endif
2222

23-
#define REQUIRE_SCALAR(T) typename std::enable_if_t<std::is_scalar_v<T>, T> = 0
23+
#define REQUIRE_SCALAR(T) \
24+
typename std::enable_if_t<::librapid::typetraits::TypeInfo<T>::type == \
25+
::librapid::detail::LibRapidType::Scalar, \
26+
int> = 0
2427

2528
namespace librapid {
2629
namespace detail {

pyproject.toml

-30
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,6 @@ cmake.args = ["-DCMAKE_BUILD_TYPE=Release"]
1919

2020
ninja.make-fallback = true
2121

22-
sdist.exclude = [
23-
"CMakeLists.txt",
24-
"cmake",
25-
"CMakeFiles",
26-
"build",
27-
"dist",
28-
"librapid/vendor",
29-
"*.h",
30-
"*.c",
31-
"*.hpp",
32-
"*.cpp",
33-
"*.tcc",
34-
"*.cxx",
35-
"*.cu",
36-
"*.cuh",
37-
"*.cl",
38-
"*.so",
39-
"*.dylib",
40-
"*.dll",
41-
"*.doc",
42-
"*.tgz",
43-
"*.md",
44-
"*.yml",
45-
"*.yaml",
46-
"*.in",
47-
"*.rst",
48-
"*.sh",
49-
"*.html"
50-
]
51-
5222
sdist.cmake = true
5323

5424
[project]

test/test-arrayConstructors.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ using CUDA = lrc::backend::CUDA;
7575
/* Due to the way the code works, if this passes for a 3D array, it *must* pass for all \
7676
* other dimensions */ \
7777
auto testI = \
78-
lrc::Array<SCALAR, BACKEND>::fromData(InitList({{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}})); \
78+
lrc::Array<SCALAR, BACKEND>(InitList({{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}})); \
7979
REQUIRE(fmt::format("{}", testI) == \
8080
fmt::format("[[[{} {}]\n [{} {}]]\n\n [[{} {}]\n [{} {}]]]", \
8181
SCALAR(1), \
@@ -88,7 +88,7 @@ using CUDA = lrc::backend::CUDA;
8888
SCALAR(8))); \
8989
\
9090
auto testJ = \
91-
lrc::Array<SCALAR, BACKEND>::fromData(Vec({{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}})); \
91+
lrc::Array<SCALAR, BACKEND>(Vec({{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}})); \
9292
REQUIRE(fmt::format("{}", testJ) == \
9393
fmt::format("[[[{} {}]\n [{} {}]]\n\n [[{} {}]\n [{} {}]]]", \
9494
SCALAR(1), \

0 commit comments

Comments
 (0)