23public final class ProtobufMatrix extends ProtoMessage<ProtobufMatrix> implements Cloneable {
24 private static final long serialVersionUID = 0L;
39 private final RepeatedDouble data = RepeatedDouble.newEmptyInstance();
41 private ProtobufMatrix() {
48 return new ProtobufMatrix();
56 return (bitField0_ & 0x00000001) != 0;
64 bitField0_ &= ~0x00000001;
83 bitField0_ |= 0x00000001;
93 return (bitField0_ & 0x00000002) != 0;
101 bitField0_ &= ~0x00000002;
120 bitField0_ |= 0x00000002;
130 return (bitField0_ & 0x00000004) != 0;
138 bitField0_ &= ~0x00000004;
167 bitField0_ |= 0x00000004;
176 public ProtobufMatrix
addData(
final double value) {
177 bitField0_ |= 0x00000004;
188 bitField0_ |= 0x00000004;
195 cachedSize = other.cachedSize;
196 if ((bitField0_ | other.bitField0_) != 0) {
197 bitField0_ = other.bitField0_;
198 numRows = other.numRows;
199 numCols = other.numCols;
200 data.copyFrom(other.data);
206 public ProtobufMatrix mergeFrom(
final ProtobufMatrix other) {
207 if (other.isEmpty()) {
211 if (other.hasNumRows()) {
212 setNumRows(other.numRows);
214 if (other.hasNumCols()) {
215 setNumCols(other.numCols);
217 if (other.hasData()) {
218 getMutableData().addAll(other.data);
248 public boolean equals(Object o) {
256 return bitField0_ == other.bitField0_
257 && (!hasNumRows() || numRows == other.numRows)
258 && (!hasNumCols() || numCols == other.numCols)
259 && (!hasData() || data.equals(other.data));
263 public void writeTo(
final ProtoSink output)
throws IOException {
264 if ((bitField0_ & 0x00000001) != 0) {
265 output.writeRawByte((
byte) 8);
266 output.writeUInt32NoTag(numRows);
268 if ((bitField0_ & 0x00000002) != 0) {
269 output.writeRawByte((
byte) 16);
270 output.writeUInt32NoTag(numCols);
272 if ((bitField0_ & 0x00000004) != 0) {
273 for (
int i = 0; i < data.length(); i++) {
274 output.writeRawByte((
byte) 25);
275 output.writeDoubleNoTag(data.array()[i]);
281 protected int computeSerializedSize() {
283 if ((bitField0_ & 0x00000001) != 0) {
284 size += 1 + ProtoSink.computeUInt32SizeNoTag(numRows);
286 if ((bitField0_ & 0x00000002) != 0) {
287 size += 1 + ProtoSink.computeUInt32SizeNoTag(numCols);
289 if ((bitField0_ & 0x00000004) != 0) {
290 size += (1 + 8) * data.length();
296 @SuppressWarnings(
"fallthrough")
297 public
ProtobufMatrix mergeFrom(final ProtoSource input) throws IOException {
299 int tag = input.readTag();
304 numRows = input.readUInt32();
305 bitField0_ |= 0x00000001;
306 tag = input.readTag();
313 numCols = input.readUInt32();
314 bitField0_ |= 0x00000002;
315 tag = input.readTag();
322 input.readPackedDouble(data);
323 bitField0_ |= 0x00000004;
324 tag = input.readTag();
333 if (!input.skipField(tag)) {
336 tag = input.readTag();
341 tag = input.readRepeatedDouble(data, tag);
342 bitField0_ |= 0x00000004;
350 public void writeTo(
final JsonSink output)
throws IOException {
351 output.beginObject();
352 if ((bitField0_ & 0x00000001) != 0) {
353 output.writeUInt32(FieldNames.numRows, numRows);
355 if ((bitField0_ & 0x00000002) != 0) {
356 output.writeUInt32(FieldNames.numCols, numCols);
358 if ((bitField0_ & 0x00000004) != 0) {
359 output.writeRepeatedDouble(FieldNames.data, data);
365 public ProtobufMatrix mergeFrom(
final JsonSource input)
throws IOException {
366 if (!input.beginObject()) {
369 while (!input.isAtEnd()) {
370 switch (input.readFieldHash()) {
373 if (input.isAtField(FieldNames.numRows)) {
374 if (!input.trySkipNullValue()) {
375 numRows = input.readUInt32();
376 bitField0_ |= 0x00000001;
379 input.skipUnknownField();
385 if (input.isAtField(FieldNames.numCols)) {
386 if (!input.trySkipNullValue()) {
387 numCols = input.readUInt32();
388 bitField0_ |= 0x00000002;
391 input.skipUnknownField();
396 if (input.isAtField(FieldNames.data)) {
397 if (!input.trySkipNullValue()) {
398 input.readRepeatedDouble(data);
399 bitField0_ |= 0x00000004;
402 input.skipUnknownField();
407 input.skipUnknownField();
422 public boolean isEmpty() {
423 return ((bitField0_) == 0);
426 public static ProtobufMatrix parseFrom(
final byte[] data)
throws InvalidProtocolBufferException {
427 return ProtoMessage.mergeFrom(
new ProtobufMatrix(), data).checkInitialized();
430 public static ProtobufMatrix parseFrom(
final ProtoSource input)
throws IOException {
431 return ProtoMessage.mergeFrom(
new ProtobufMatrix(), input).checkInitialized();
434 public static ProtobufMatrix parseFrom(
final JsonSource input)
throws IOException {
435 return ProtoMessage.mergeFrom(
new ProtobufMatrix(), input).checkInitialized();
456 public ProtobufMatrix create() {
457 return ProtobufMatrix.newInstance();
464 static class FieldNames {
465 static final FieldName numRows = FieldName.forField(
"numRows",
"num_rows");
467 static final FieldName numCols = FieldName.forField(
"numCols",
"num_cols");
469 static final FieldName data = FieldName.forField(
"data");