NumCpp  2.5.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
frombuffer.hpp
Go to the documentation of this file.
1 #pragma once
29 
31 #include "NumCpp/Core/Types.hpp"
32 #include "NumCpp/NdArray.hpp"
33 
34 namespace nc
35 {
36  //============================================================================
37  // Method Description:
47  template<typename dtype>
48  NdArray<dtype> frombuffer(const char* inBufferPtr, uint32 inNumBytes)
49  {
50  if (inNumBytes % sizeof(dtype) != 0)
51  {
52  THROW_INVALID_ARGUMENT_ERROR("inNumBytes % sizeof(dtype) != 0");
53  }
54 
55  const auto numElements = static_cast<uint32>(inNumBytes / sizeof(dtype));
56  return NdArray<dtype>(reinterpret_cast<const dtype*>(inBufferPtr), numElements);
57  }
58 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
Definition: Coordinate.hpp:45
NdArray< dtype > frombuffer(const char *inBufferPtr, uint32 inNumBytes)
Definition: frombuffer.hpp:48
std::uint32_t uint32
Definition: Types.hpp:40