"test/vscode:/vscode.git/clone" did not exist on "ca8d02abd520194bc0d182d62aeb39d9496ca91d"
Commit 57511a21 authored by mei-ye's avatar mei-ye
Browse files

merge

parents 1bba7124 66bb6eb1
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <migraph/argument.hpp> #include <migraph/argument.hpp>
#include <migraph/tensor_view.hpp> #include <migraph/tensor_view.hpp>
#include <migraph/raw_data.hpp> #include <migraph/raw_data.hpp>
#include <migraph/make_shared_array.hpp>
#include <memory> #include <memory>
...@@ -20,7 +21,7 @@ struct literal : raw_data<literal> ...@@ -20,7 +21,7 @@ struct literal : raw_data<literal>
literal() {} literal() {}
template <class T> template <class T>
literal(T x) : buffer(std::make_unique<char[]>(sizeof(T))), m_shape(shape::get_type<T>{}) literal(T x) : buffer(make_shared_array<char>(sizeof(T))), m_shape(shape::get_type<T>{})
{ {
static_assert(std::is_trivial<T>{}, "Literals can only be trivial types"); static_assert(std::is_trivial<T>{}, "Literals can only be trivial types");
*(reinterpret_cast<T*>(buffer.get())) = x; *(reinterpret_cast<T*>(buffer.get())) = x;
...@@ -28,7 +29,7 @@ struct literal : raw_data<literal> ...@@ -28,7 +29,7 @@ struct literal : raw_data<literal>
template <class T> template <class T>
literal(const shape& s, const std::vector<T>& x) literal(const shape& s, const std::vector<T>& x)
: buffer(std::make_unique<char[]>(s.bytes())), m_shape(s) : buffer(make_shared_array<char>(s.bytes())), m_shape(s)
{ {
static_assert(std::is_trivial<T>{}, "Literals can only be trivial types"); static_assert(std::is_trivial<T>{}, "Literals can only be trivial types");
fill(x.begin(), x.end()); fill(x.begin(), x.end());
...@@ -36,7 +37,7 @@ struct literal : raw_data<literal> ...@@ -36,7 +37,7 @@ struct literal : raw_data<literal>
template <class T> template <class T>
literal(const shape& s, const std::initializer_list<T>& x) literal(const shape& s, const std::initializer_list<T>& x)
: buffer(std::make_unique<char[]>(s.bytes())), m_shape(s) : buffer(make_shared_array<char>(s.bytes())), m_shape(s)
{ {
static_assert(std::is_trivial<T>{}, "Literals can only be trivial types"); static_assert(std::is_trivial<T>{}, "Literals can only be trivial types");
fill(x.begin(), x.end()); fill(x.begin(), x.end());
...@@ -44,12 +45,12 @@ struct literal : raw_data<literal> ...@@ -44,12 +45,12 @@ struct literal : raw_data<literal>
template <class Iterator> template <class Iterator>
literal(const shape& s, Iterator start, Iterator end) literal(const shape& s, Iterator start, Iterator end)
: buffer(std::make_unique<char[]>(s.bytes())), m_shape(s) : buffer(make_shared_array<char>(s.bytes())), m_shape(s)
{ {
fill(start, end); fill(start, end);
} }
literal(const shape& s, const char* x) : buffer(std::make_unique<char[]>(s.bytes())), m_shape(s) literal(const shape& s, const char* x) : buffer(make_shared_array<char>(s.bytes())), m_shape(s)
{ {
std::copy(x, x + s.bytes(), buffer.get()); std::copy(x, x + s.bytes(), buffer.get());
} }
......
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_MAKE_SHARED_ARRAY_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_MAKE_SHARED_ARRAY_HPP
#include <memory>
namespace migraph {
template <typename T>
std::shared_ptr<T> make_shared_array(size_t size)
{
return std::shared_ptr<T>(new T[size], std::default_delete<T[]>());
}
} // namespace migraph
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment