-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatrix.go
97 lines (69 loc) · 2.22 KB
/
matrix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2018 Ross Merrigan
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package graphblas
import "github.com/rossmerr/graphblas/constraints"
type matrix[T constraints.Type] interface {
MaskLogical
// At returns the value of a matrix element at r-th, c-th
At(r, c int) T
// Set sets the value at r-th, c-th of the matrix
Set(r, c int, value T)
// Update does a At and Set on the matrix element at r-th, c-th
Update(r, c int, f func(T) T)
// ColumnsAt return the columns at c-th
ColumnsAt(c int) VectorLogial[T]
// RowsAt return the rows at r-th
RowsAt(r int) VectorLogial[T]
// RowsAtToArray return the rows at r-th
RowsAtToArray(r int) []T
// Copy copies the matrix
CopyLogical() MatrixLogical[T]
// Enumerate iterates through all non-zero elements, order is not guaranteed
Enumerate() Enumerate[T]
// Transpose swaps the rows and columns
// C ⊕= Aᵀ
Transpose() MatrixLogical[T]
// Equal the two matrices are equal
Equal(m MatrixLogical[T]) bool
// NotEqual the two matrices are not equal
NotEqual(m MatrixLogical[T]) bool
// Size of the matrix
Size() int
// The number of elements in the matrix (non-zero counted for dense matrices)
Values() int
// Clear removes all elements from a matrix
Clear()
}
type MatrixLogical[T constraints.Type] interface {
matrix[T]
}
type MatrixRune interface {
matrix[rune]
}
// Matrix interface
type Matrix[T constraints.Number] interface {
Mask
MatrixLogical[T]
// Copy copies the matrix
Copy() Matrix[T]
// Scalar multiplication of a matrix by alpha
Scalar(alpha T) Matrix[T]
// Multiply multiplies a matrix by another matrix
// C = AB
Multiply(m Matrix[T]) Matrix[T]
// Add addition of a matrix by another matrix
Add(m Matrix[T]) Matrix[T]
// Subtract subtracts one matrix from another matrix
Subtract(m Matrix[T]) Matrix[T]
// Negative the negative of a matrix
Negative() MatrixLogical[T]
// Map iterates and replace each element with the result of applying a function to its value
Map() Map[T]
}
type MatrixCompressed[T constraints.Number] interface {
Matrix[T]
SetReturnPointer(r, c int, value T) (pointer int, start int)
UpdateReturnPointer(r, c int, f func(T) T) (pointer int, start int)
}