Skip to content

[Runtime] ShapeTuple.Product and ShapeTuple Printing#15652

Merged
tqchen merged 1 commit intoapache:unityfrom
junrushao:feature/2023-09-01/shape-tuple-utils
Sep 2, 2023
Merged

[Runtime] ShapeTuple.Product and ShapeTuple Printing#15652
tqchen merged 1 commit intoapache:unityfrom
junrushao:feature/2023-09-01/shape-tuple-utils

Conversation

@junrushao
Copy link
Copy Markdown
Member

@junrushao junrushao commented Sep 1, 2023

This PR adds two convenient methods for ShapeTuple.

// Returns the number of elements in the shape,
// i.e. the product of all dimensions
ShapeTupleObj::index_type ShapeTupleObj::Product();

// Printing method for shape
std::ostream& operator<<(std::ostream& os, const ShapeTuple& shape);

@junrushao junrushao marked this pull request as ready for review September 1, 2023 10:27
@junrushao junrushao force-pushed the feature/2023-09-01/shape-tuple-utils branch from 8e25ad0 to ce99f01 Compare September 1, 2023 10:28
junrushao added a commit to junrushao/tvm that referenced this pull request Sep 1, 2023
)

This commit adds two convenient methods for `ShapeTuple`.

```C++
// Returns the number of elements in the shape,
// i.e. the product of all dimensions
ShapeTupleObj::index_type Sh)apeTupleObj::Numel() const;

// Printing method for shape
std::ostream& operator<<(std::ostream& os, const ShapeTuple& shape);
```
@junrushao junrushao force-pushed the feature/2023-09-01/shape-tuple-utils branch from ce99f01 to d43c852 Compare September 1, 2023 10:46
@junrushao
Copy link
Copy Markdown
Member Author

CC: @tqchen

junrushao added a commit to junrushao/tvm that referenced this pull request Sep 1, 2023
)

This commit adds two convenient methods for `ShapeTuple`.

```C++
// Returns the number of elements in the shape,
// i.e. the product of all dimensions
ShapeTupleObj::index_type ShapeTupleObj::Numel() const;

// Printing method for shape
std::ostream& operator<<(std::ostream& os, const ShapeTuple& shape);
```
uint64_t size;

/*! \brief Get number of elements in the shape */
index_type Numel() const;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to dig a bit about related APIs. How about Product? the product of the shape values

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both torch and matlab uses “numel”, and numpy uses “size” but we have already used this word for a different meaning

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numel makes sense for an array api. e.g. array.numel. Just not sure if it is right to use it for shape.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about NumElements()?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I don't have strong opinion to use Product. It's just numel is a well-known convention, but Product is a newly-invented word with ambiguity, but I don't have strong opinion.

This PR adds two convenient methods for `ShapeTuple`.

```C++
// Returns the number of elements in the shape,
// i.e. the product of all dimensions
ShapeTupleObj::index_type ShapeTupleObj::Product();

// Printing method for shape
std::ostream& operator<<(std::ostream& os, const ShapeTuple& shape);
```
@junrushao junrushao force-pushed the feature/2023-09-01/shape-tuple-utils branch from d43c852 to 50fd5f7 Compare September 2, 2023 06:01
@junrushao junrushao changed the title [Runtime] Add ShapeTupleObj::Numel and ShapeTuple Printing [Runtime] ShapeTuple.Product and ShapeTuple Printing Sep 2, 2023
junrushao added a commit to junrushao/tvm that referenced this pull request Sep 2, 2023
This PR adds two convenient methods for `ShapeTuple`.

```C++
// Returns the number of elements in the shape,
// i.e. the product of all dimensions
ShapeTupleObj::index_type ShapeTupleObj::Product();

// Printing method for shape
std::ostream& operator<<(std::ostream& os, const ShapeTuple& shape);
```
junrushao added a commit to junrushao/tvm that referenced this pull request Sep 2, 2023
This PR adds two convenient methods for `ShapeTuple`.

```C++
// Returns the number of elements in the shape,
// i.e. the product of all dimensions
ShapeTupleObj::index_type ShapeTupleObj::Product();

// Printing method for shape
std::ostream& operator<<(std::ostream& os, const ShapeTuple& shape);
```
junrushao added a commit to junrushao/tvm that referenced this pull request Sep 2, 2023
This PR adds two convenient methods for `ShapeTuple`.

```C++
// Returns the number of elements in the shape,
// i.e. the product of all dimensions
ShapeTupleObj::index_type ShapeTupleObj::Product();

// Printing method for shape
std::ostream& operator<<(std::ostream& os, const ShapeTuple& shape);
```
@tqchen tqchen merged commit c604012 into apache:unity Sep 2, 2023
tqchen pushed a commit that referenced this pull request Sep 2, 2023
* [Runtime] ShapeTuple.Product and ShapeTuple Printing (#15652)

This PR adds two convenient methods for `ShapeTuple`.

```C++
// Returns the number of elements in the shape,
// i.e. the product of all dimensions
ShapeTupleObj::index_type ShapeTupleObj::Product();

// Printing method for shape
std::ostream& operator<<(std::ostream& os, const ShapeTuple& shape);
```

* [Disco] Add `Scatter-From-Worker0`

This PR introduces an API:

```C++
void ScatterFromWorker0(Optional<NDArray> send, NDArray recv);
```

This mimics the MPI-style scattering primitive that divides NDArray
`send` into chunks, and send them to each worker's NDArray `recv`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants