gemini-code-assist[bot] commented on code in PR #64:
URL: https://github.com/apache/tvm-ffi/pull/64#discussion_r2384160769
##########
include/tvm/ffi/container/shape.h:
##########
@@ -36,6 +36,67 @@
namespace tvm {
namespace ffi {
+/*!
+ * \brief Lightweight view non-owning class for shape.
+ */
+class ShapeView {
+ public:
+ /*! \brief Default constructor. */
+ ShapeView() : cell_{nullptr, 0} {}
+ /*! \brief Copy constructor. */
+ ShapeView(const ShapeView& other) = default;
+ /*! \brief Copy assignment operator. */
+ ShapeView& operator=(const ShapeView& other) = default;
+ /*! \brief Move constructor. */
+ ShapeView(ShapeView&& other) = default;
+ /*! \brief Move assignment operator. */
+ ShapeView& operator=(ShapeView&& other) = default;
+ /*! \brief Constructor from data and size. */
+ ShapeView(const int64_t* data, size_t size) : cell_{data, size} {}
+ /*! \brief Get the data pointer. */
+ const int64_t* data() const { return cell_.data; }
+ /*! \brief Get the size of the shape. */
+ size_t size() const { return cell_.size; }
+
+ /*! \brief Get the product of the shape. */
+ int64_t Product() const {
+ int64_t product = 1;
+ for (size_t i = 0; i < cell_.size; ++i) {
+ product *= cell_.data[i];
+ }
+ return product;
+ }
+
+ /*! \brief Get the i-th element of the shape. */
+ int64_t operator[](size_t idx) const { return cell_.data[idx]; }
+
+ /*! \return Whether shape tuple is empty */
+ bool empty() const { return size() == 0; }
+
+ /*! \return The first element of the shape tuple */
+ int64_t front() const { return this->at(0); }
+
+ /*! \return The last element of the shape tuple */
+ int64_t back() const { return this->at(this->size() - 1); }
+
+ /*! \return begin iterator */
+ const int64_t* begin() const { return cell_.data; }
+
+ /*! \return end iterator */
+ const int64_t* end() const { return cell_.data + cell_.size; }
+
+ /*! \brief Get the i-th element of the shape. */
+ int64_t at(size_t idx) const {
+ if (idx >= this->size()) {
+ TVM_FFI_THROW(IndexError) << "indexing " << idx << " on a Shape of size
" << this->size();
Review Comment:

For better clarity and consistency, the error message should refer to
`ShapeView` instead of `Shape`, as this method is part of the `ShapeView` class.
```c
TVM_FFI_THROW(IndexError) << "indexing " << idx << " on a ShapeView of
size " << this->size();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]