Open xushiwei opened 4 years ago
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.
@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
]
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 https://github.com/goplus/gop/issues/1847.
can be:
or: