NumCpp  2.7.0
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:
46  template<typename dtype>
47  NdArray<dtype> frombuffer(const char* inBufferPtr, uint32 inNumBytes)
48  {
49  if (inNumBytes % sizeof(dtype) != 0)
50  {
51  THROW_INVALID_ARGUMENT_ERROR("inNumBytes % sizeof(dtype) != 0");
52  }
53 
54  const auto numElements = static_cast<uint32>(inNumBytes / sizeof(dtype));
55  return NdArray<dtype>(reinterpret_cast<const dtype*>(inBufferPtr), numElements);
56  }
57 } // 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:47
std::uint32_t uint32
Definition: Types.hpp:40