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

Simplified form of 2d vector #385

Open
xushiwei opened this issue Jul 2, 2020 · 3 comments
Open

Simplified form of 2d vector #385

xushiwei opened this issue Jul 2, 2020 · 3 comments

Comments

@xushiwei
Copy link
Member

xushiwei commented Jul 2, 2020

a := [[a11, a12, ..., a1N], [a21, a22, ..., a2N], ..., [aM1, aM2, ..., aMN]]

can be:

a := [a11, a12, ..., a1N; a21, a22, ..., a2N; ...; aM1, aM2, ..., aMN]

or:

a := [a11, a12, ..., a1N
a21, a22, ..., a2N
...
aM1, aM2, ..., aMN]
@damonchen
Copy link
Contributor

I think

a := [a11, a12, ..., a1N; a21, a22, ..., a2N; ...; aM1, aM2, ..., aMN]

is better.

we could format the code to multiline when there is ';' by the format tool. so the code will look like below:

a := [a11, a12, ..., a1N;
a21, a22, ..., a2N;
...;
aM1, aM2, ..., aMN;
]

put the ']' in new line, so it will be easy for user to add new row in vector.

@xushiwei
Copy link
Member Author

xushiwei commented Jul 3, 2020

@damonchen
No. In the Go language, token ; can be omitted at line end (\n). So

a := [a11, a12, ..., a1N; a21, a22, ..., a2N; ...; aM1, aM2, ..., aMN]

is equal to

a := [a11, a12, ..., a1N
a21, a22, ..., a2N
...
aM1, aM2, ..., aMN]

Of course, if we allow empty line in 2d vector, it can be

a := [
    a11, a12, ..., a1N
    a21, a22, ..., a2N
    ...
    aM1, aM2, ..., aMN
]

@xushiwei
Copy link
Member Author

xushiwei commented Apr 7, 2024

X := [A..., B..., c1, c2, ..., cN]
Y := [
    A...
    B...
    c1, c2, ..., cN
]
Z := [
    A1..., A2..., a1, a2, ..., aN
    B...
    C1..., C2...
    d1, d2, ..., dM
]

is equivalent to:

X := concat(A, B, [c1, c2, ..., cN])
Y := vconcat(A, B, [c1, c2, ..., cN])
Z := vconcat(
    concat(A1, A2, [a1, a2, ..., aN]),
    B,
    concat(C1, C2),
    [d1, d2, ..., dM])

prototype:

type matrix[T number] struct {
    Data []T
    Row, Col int
}

func matrix[T].icast(v []T) matrix[T] {  // T.icast means `implicit cast of type T`
    return matrix[T]{v, 1, len(v)}
}

func concat[T string](args ...T) T
func concat[T number](args ...[]T) []T
func concat(T number](args ...matrix[T]) matrix[T]

func vconcat[T number](args ...matrix[T]) matrix[T]

For more details about T.icast, see #1847.

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

No branches or pull requests

2 participants