RobotCore
1.0
WPILib port to raspberry Pi
Toggle main menu visibility
Loading...
Searching...
No Matches
MatrixProto.java
1
// Copyright (c) FIRST and other WPILib contributors.
2
// Open Source Software; you can modify and/or share it under the terms of
3
// the WPILib BSD license file in the root directory of this project.
4
5
package
org.wpilib.math.linalg.proto;
6
7
import
org.wpilib.math.linalg.MatBuilder;
8
import
org.wpilib.math.linalg.Matrix;
9
import
org.wpilib.math.linalg.proto.detail.ProtobufMatrix;
10
import
org.wpilib.math.util.Nat;
11
import
org.wpilib.math.util.Num;
12
import
org.wpilib.util.protobuf.Protobuf;
13
import
us.hebi.quickbuf.Descriptors.Descriptor;
14
15
public
class
MatrixProto
<R
extends
Num
, C extends
Num
>
16
implements
Protobuf
<Matrix<R, C>, ProtobufMatrix> {
17
private
final
Nat<R>
m_rows;
18
private
final
Nat<C>
m_cols;
19
26
public
MatrixProto
(
Nat<R>
rows,
Nat<C>
cols) {
27
m_rows = rows;
28
m_cols = cols;
29
}
30
31
@Override
32
public
Class<Matrix<R, C>>
getTypeClass
() {
33
@SuppressWarnings(
"unchecked"
)
34
var clazz = (Class<Matrix<R, C>>) (Class<?>)
Matrix
.class;
35
return
clazz;
36
}
37
38
@Override
39
public
Descriptor
getDescriptor
() {
40
return
ProtobufMatrix
.
getDescriptor
();
41
}
42
43
@Override
44
public
ProtobufMatrix
createMessage
() {
45
return
ProtobufMatrix
.
newInstance
();
46
}
47
48
@Override
49
public
Matrix<R, C>
unpack(
ProtobufMatrix
msg) {
50
if
(msg.
getNumRows
() != m_rows.getNum() || msg.
getNumCols
() != m_cols.
getNum
()) {
51
throw
new
IllegalArgumentException(
52
"Tried to unpack msg "
53
+ msg
54
+
" with "
55
+ msg.
getNumRows
()
56
+
" rows and "
57
+ msg.
getNumCols
()
58
+
" columns into Matrix with "
59
+ m_rows.getNum()
60
+
" rows and "
61
+ m_cols.
getNum
()
62
+
" columns"
);
63
}
64
return
MatBuilder
.
fill
(m_rows, m_cols,
Protobuf
.
unpackArray
(msg.
getData
()));
65
}
66
67
@Override
68
public
void
pack(ProtobufMatrix msg, Matrix<R, C> value) {
69
msg.setNumRows(value.getNumRows());
70
msg.setNumCols(value.getNumCols());
71
Protobuf.packArray(msg.getMutableData(), value.getData());
72
}
73
}
org.wpilib.math.linalg.MatBuilder
Definition
MatBuilder.java:13
org.wpilib.math.linalg.MatBuilder.fill
static< R extends Num, C extends Num > Matrix< R, C > fill(Nat< R > rows, Nat< C > cols, double... data)
Definition
MatBuilder.java:29
org.wpilib.math.linalg.Matrix
Definition
Matrix.java:36
org.wpilib.math.linalg.proto.MatrixProto.getDescriptor
Descriptor getDescriptor()
Definition
MatrixProto.java:39
org.wpilib.math.linalg.proto.MatrixProto.MatrixProto
MatrixProto(Nat< R > rows, Nat< C > cols)
Definition
MatrixProto.java:26
org.wpilib.math.linalg.proto.MatrixProto.createMessage
ProtobufMatrix createMessage()
Definition
MatrixProto.java:44
org.wpilib.math.linalg.proto.MatrixProto.getTypeClass
Class< Matrix< R, C > > getTypeClass()
Definition
MatrixProto.java:32
org.wpilib.math.linalg.proto.detail.ProtobufMatrix
Definition
ProtobufMatrix.java:23
org.wpilib.math.linalg.proto.detail.ProtobufMatrix.getNumRows
int getNumRows()
Definition
ProtobufMatrix.java:73
org.wpilib.math.linalg.proto.detail.ProtobufMatrix.getNumCols
int getNumCols()
Definition
ProtobufMatrix.java:110
org.wpilib.math.linalg.proto.detail.ProtobufMatrix.getDescriptor
static Descriptors.Descriptor getDescriptor()
Definition
ProtobufMatrix.java:448
org.wpilib.math.linalg.proto.detail.ProtobufMatrix.newInstance
static ProtobufMatrix newInstance()
Definition
ProtobufMatrix.java:47
org.wpilib.math.linalg.proto.detail.ProtobufMatrix.getData
RepeatedDouble getData()
Definition
ProtobufMatrix.java:153
org.wpilib.math.util.Num
Definition
Num.java:8
org.wpilib.math.util.Nat
Definition
Nat.java:41
org.wpilib.math.util.Nat.getNum
int getNum()
org.wpilib.util.protobuf.Protobuf
Definition
Protobuf.java:32
org.wpilib.util.protobuf.Protobuf.unpackArray
static< T, MessageType extends ProtoMessage< MessageType > > T[] unpackArray(RepeatedMessage< MessageType > msg, Protobuf< T, MessageType > proto)
Definition
Protobuf.java:161
org
wpilib
math
linalg
proto
MatrixProto.java
Generated by
1.18.0