Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero axis lengths? #731

Closed
nilgoyette opened this issue Sep 25, 2019 · 3 comments
Closed

Zero axis lengths? #731

nilgoyette opened this issue Sep 25, 2019 · 3 comments
Labels

Comments

@nilgoyette
Copy link
Collaborator

While working on ndarray-stats, I discovered that it's possible to have "zero axis lengths".

let arr = Array2::zeros((0, 10));

There's some issues #579, #693 and some panic information about them in the doc, for example fn default: Panics if the product of non-zero axis lengths overflows isize. but I can't find any useful information on them. It seems to me that they're overly-complex empty arrays and that you can do nothing useful with them. I'm probably wrong?

I think it's right to say that nobody will create such an array deliberately so I guess one of the method in ArrayBase can create one? Can someonie explain me why they exist? What's their use-cases?

@bluss
Copy link
Member

bluss commented Sep 26, 2019

I think just like zero-length Vecs and slices appear in various situations, we have these. ArrayBase uses the same model for axes, shapes and strides for all its storage types, so since zero-width slices (views) are naturally occurring when slicing and splitting, we can see such shapes for owned arrays too.

@bluss bluss added the question label Sep 29, 2019
@bluss
Copy link
Member

bluss commented Sep 29, 2019

Just briefly, there are many ways to use tables of numbers in this world, but let's say we have a model with data like this:

+--------+--------+-------+
| weight | length | width |
+--------+--------+-------+
|    7.2 |     40 |    65 |
|      8 |     30 |   180 |
+--------+--------+-------+

We can store it in a n × 3 table for our n observations.

It's a valid situation in the program that we can have 0 observations at any given time. Then we have a matrix of 0 × 3 values:

+--------+--------+-------+
| weight | length | width |
+--------+--------+-------+

The shape of the empty table is important! The 0 × 3 matrix can be split into three columns of 0 entries each etc, which is consistent with the model.

(Table headers "not yet" implemented in ndarray.)

@nilgoyette
Copy link
Collaborator Author

Yeah, ok, that makes sense. I had trouble imagining it for 2D arrays, but I'm perfectly ok with empty 1D array.

Thank you for taking the time to answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants