[Feature] Shape function to replace rows and columns - #147
Open
Sir-NoChill wants to merge 1 commit into
Open
Sir-NoChill wants to merge 1 commit into
Sir-NoChill wants to merge 1 commit into
Conversation
This branch implements a change to the gazprea specification eliminating the following functions: - `length()` - `rows()` - `columns()` And replaces them with a generic function that works for arbitrary ranks: `shape()`. The goal is to have a generic way to query any 'shaped' entity in gazprea without needing to case on the exact rank and type. The signature: ```gazprea function shape(T shaped) returns integer[*]; ``` The function takes as arguments an n-d array or vector and returns the longest contiguous static shape of the shaped element. For example: ```gazprea integer[1][2][3] a; shape(a) -> std_output; // prints '[1 2 3]' integer[*] b = [[1, 2], [3, 4]]; shape(b) -> std_output; // prints '[2 2]' vector<integer[2][3]> c; c.append([[2, 3, 4], [4, 6, 8]]); shape(c) -> std_output; //prints '[1 2 3]' vector<vector<integer[*]>> d = [[[1, 2]]]; shape(d) -> std_output; // prints '[1]', vectors // generally cannot look inside other vectors to determine // shape, since multiple vectors could lead to a ragged // array, which is not efficiently expressible in this // format ``` docs(gazprea): clarify shape() semantics for nested collections Add explicit examples and documentation clarifying that shape() reports only the immediate collection's dimensions, not nested element types: - shape(vector<integer[2][3]>) returns [length], not [length, 2, 3] - shape(vector<integer>[3][2]) returns [3, 2], the array extents - To query element shapes, index first then call shape: shape(a[0][0]) This simplifies the implementation and clarifies the contract: shape() returns the dimensions of what you pass it, nothing more. Nested dimensions are accessed by indexing into the collection.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR obliterates the length, rows and columns functions in favour of a generic 'shape' function that returns the shape of an array/vector type. It does not cross vector boundaries, so vectors always return their flat shape. It returns the full descriptor of statically shaped arrays, so
shape(integer[2][3][4]) = [2 3 4]; // yes, that is invalid. Assume a variable of that type. This makes the runtime a bit cleaner and more aligned to what we currently have working for us.