You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/12/09 12:57:31 UTC

[GitHub] [arrow] pitrou commented on a change in pull request #6302: ARROW-7633: [C++][CI] Create fuzz targets for tensors and sparse tensors

pitrou commented on a change in pull request #6302:
URL: https://github.com/apache/arrow/pull/6302#discussion_r539279606



##########
File path: cpp/src/arrow/ipc/test_common.h
##########
@@ -161,6 +162,11 @@ Status MakeUuid(std::shared_ptr<RecordBatch>* out);
 ARROW_TESTING_EXPORT
 Status MakeDictExtension(std::shared_ptr<RecordBatch>* out);
 
+ARROW_TESTING_EXPORT
+Status MakeRandomTensor(const std::shared_ptr<DataType>& type,
+                        const std::vector<int64_t>& shape, bool row_major_p,
+                        std::shared_ptr<Tensor>* out, uint32_t seed = 0);

Review comment:
       Two things:
   1) Why not put this in `arrow/testing/random.h`?
   2) Return `Result<Tensor>` instead?

##########
File path: cpp/src/arrow/ipc/generate_tensor_fuzz_corpus.cc
##########
@@ -0,0 +1,132 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// A command line executable that generates a bunch of valid IPC files
+// containing example tensors.  Those are used as fuzzing seeds to make
+// fuzzing more efficient.
+
+#include <cstdlib>
+#include <iostream>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/io/file.h"
+#include "arrow/io/memory.h"
+#include "arrow/ipc/test_common.h"
+#include "arrow/ipc/writer.h"
+#include "arrow/result.h"
+#include "arrow/tensor.h"
+#include "arrow/util/io_util.h"
+
+namespace arrow {
+namespace ipc {
+
+using ::arrow::internal::PlatformFilename;
+
+Result<PlatformFilename> PrepareDirectory(const std::string& dir) {
+  ARROW_ASSIGN_OR_RAISE(auto dir_fn, PlatformFilename::FromString(dir));
+  RETURN_NOT_OK(::arrow::internal::CreateDir(dir_fn));
+  return std::move(dir_fn);
+}
+
+Result<std::shared_ptr<Buffer>> MakeSerializedBuffer(
+    std::function<Status(const std::shared_ptr<io::BufferOutputStream>&)> fn) {
+  ARROW_ASSIGN_OR_RAISE(auto sink, io::BufferOutputStream::Create(1024));
+  RETURN_NOT_OK(fn(sink));
+  return sink->Finish();
+}
+
+Result<std::shared_ptr<Buffer>> SerializeTensor(const std::shared_ptr<Tensor>& tensor) {
+  return MakeSerializedBuffer(
+      [&](const std::shared_ptr<io::BufferOutputStream>& sink) -> Status {
+        int32_t metadata_length;
+        int64_t body_length;
+        return ipc::WriteTensor(*tensor, sink.get(), &metadata_length, &body_length);
+      });
+}
+
+Result<std::vector<std::shared_ptr<Tensor>>> Tensors() {
+  std::vector<std::shared_ptr<Tensor>> tensors;
+  std::shared_ptr<Tensor> tensor;
+  std::vector<int64_t> shape = {5, 3, 7};
+  std::shared_ptr<DataType> types[] = {int8(),  int16(),  int32(),  int64(),
+                                       uint8(), uint16(), uint32(), uint64()};
+  uint32_t seed = 0;
+  for (auto type : types) {
+    RETURN_NOT_OK(test::MakeRandomTensor(type, shape, true, &tensor, seed++));

Review comment:
       It's not obvious what `true` is for. Can you add a comment, e.g. `/*xxx=*/true`?

##########
File path: cpp/src/arrow/ipc/metadata_internal.cc
##########
@@ -1334,17 +1334,22 @@ Status GetTensorMetadata(const Buffer& metadata, std::shared_ptr<DataType>* type
     return Status::IOError("Header-type of flatbuffer-encoded Message is not Tensor.");
   }
 
-  int ndim = static_cast<int>(tensor->shape()->size());
+  auto ndim = tensor->shape()->size();

Review comment:
       Use `int64_t` perhaps?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org