Skip to content

Commit 1d2a186

Browse files
committed
Array resize function
1 parent 60a1ba8 commit 1d2a186

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

librapid/include/librapid/array/arrayContainer.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ namespace librapid {
298298
/// \param value The value to write to the array's storage
299299
LIBRAPID_ALWAYS_INLINE void write(size_t index, const Scalar &value);
300300

301+
LIBRAPID_ALWAYS_INLINE ArrayContainer &resize(const ShapeType &shape);
302+
301303
template<typename T>
302304
LIBRAPID_ALWAYS_INLINE ArrayContainer &operator+=(const T &other);
303305

@@ -817,6 +819,19 @@ namespace librapid {
817819
m_storage[index] = value;
818820
}
819821

822+
template<typename ShapeType_, typename StorageType_>
823+
LIBRAPID_ALWAYS_INLINE auto
824+
ArrayContainer<ShapeType_, StorageType_>::resize(const ShapeType &shape)
825+
-> ArrayContainer & {
826+
LIBRAPID_ASSERT(shape.size() == m_size,
827+
"Size of new shape ({}) must equal size of old shape ({})",
828+
shape.size(),
829+
m_size);
830+
m_shape = shape;
831+
m_size = shape.size();
832+
return *this;
833+
}
834+
820835
template<typename ShapeType_, typename StorageType_>
821836
template<typename T>
822837
LIBRAPID_ALWAYS_INLINE auto

librapid/include/librapid/autodiff/dual.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ namespace librapid {
2828
Scalar derivative;
2929

3030
Dual() = default;
31-
explicit Dual(Scalar value) : value(value), derivative(Scalar()) {}
31+
Dual(Scalar value) : value(value), derivative(Scalar()) {}
3232
Dual(Scalar value, Scalar derivative) : value(value), derivative(derivative) {}
3333

3434
template<typename U>
35-
explicit Dual(const Dual<U> &other) : value(other.value), derivative(other.derivative) {}
35+
Dual(const Dual<U> &other) : value(other.value), derivative(other.derivative) {}
3636

3737
template<typename U>
38-
explicit Dual(Dual<U> &&other) :
38+
Dual(Dual<U> &&other) :
3939
value(std::move(other.value)), derivative(std::move(other.derivative)) {}
4040

4141
template<typename U>

0 commit comments

Comments
 (0)