Skip to content

Commit 60a1ba8

Browse files
committed
subshape QOL
1 parent 222dd32 commit 60a1ba8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

librapid/include/librapid/array/shape.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ namespace librapid {
128128
/// \param start Starting index
129129
/// \param end Ending index
130130
/// \return Subshape
131-
LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE auto subshape(DimType start, DimType end) const
132-
-> Shape;
131+
LIBRAPID_NODISCARD LIBRAPID_ALWAYS_INLINE auto subshape(DimType start = -1,
132+
DimType end = -1) const -> Shape;
133133

134134
/// Return the number of elements the Shape object represents
135135
/// \return Number of elements
@@ -377,6 +377,9 @@ namespace librapid {
377377
LIBRAPID_NODISCARD auto Shape::ndim() const -> DimType { return m_dims; }
378378

379379
LIBRAPID_NODISCARD auto Shape::subshape(DimType start, DimType end) const -> Shape {
380+
if (start < 0) start = 0;
381+
if (end < 0) end = m_dims;
382+
380383
LIBRAPID_ASSERT_WITH_EXCEPTION(std::range_error,
381384
start <= end,
382385
"Start index ({}) must not be greater than end index ({})",

0 commit comments

Comments
 (0)