RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
MatrixStruct.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
5package org.wpilib.math.linalg.struct;
6
7import java.nio.ByteBuffer;
8import org.wpilib.math.linalg.MatBuilder;
9import org.wpilib.math.linalg.Matrix;
10import org.wpilib.math.util.Nat;
11import org.wpilib.math.util.Num;
12import org.wpilib.util.struct.Struct;
13
14public final class MatrixStruct<R extends Num, C extends Num> implements Struct<Matrix<R, C>> {
15 private final Nat<R> m_rows;
16 private final Nat<C> m_cols;
17
24 public MatrixStruct(Nat<R> rows, Nat<C> cols) {
25 m_rows = rows;
26 m_cols = cols;
27 }
28
29 @Override
30 public Class<Matrix<R, C>> getTypeClass() {
31 @SuppressWarnings("unchecked")
32 var clazz = (Class<Matrix<R, C>>) (Class<?>) Matrix.class;
33 return clazz;
34 }
35
36 @Override
37 public String getTypeName() {
38 return "Matrix__" + m_rows.getNum() + "_" + m_cols.getNum();
39 }
40
41 @Override
42 public int getSize() {
43 return DOUBLE_SIZE * m_rows.getNum() * m_cols.getNum();
44 }
45
46 @Override
47 public String getSchema() {
48 return "double data[" + (m_rows.getNum() * m_cols.getNum()) + "]";
49 }
50
51 @Override
52 public Matrix<R, C> unpack(ByteBuffer bb) {
53 return MatBuilder.fill(
54 m_rows, m_cols, Struct.unpackDoubleArray(bb, m_rows.getNum() * m_cols.getNum()));
55 }
56
57 @Override
58 public void pack(ByteBuffer bb, Matrix<R, C> value) {
59 Struct.packArray(bb, value.getData());
60 }
61}
static< R extends Num, C extends Num > Matrix< R, C > fill(Nat< R > rows, Nat< C > cols, double... data)
MatrixStruct(Nat< R > rows, Nat< C > cols)
Matrix< R, C > unpack(ByteBuffer bb)
static< T > void packArray(ByteBuffer bb, T[] arr, Struct< T > struct)
Definition Struct.java:175
static double[] unpackDoubleArray(ByteBuffer bb, int size)
Definition Struct.java:157