<commit_before>//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed 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.
//*****************************************************************************

#pragma once

#include <cstring>
#include <sstream>

#include "ngraph/coordinate_diff.hpp"
#include "ngraph/node.hpp"
#include "ngraph/runtime/aligned_buffer.hpp"
#include "ngraph/type/bfloat16.hpp"
#include "ngraph/type/element_type.hpp"
#include "ngraph/util.hpp"

namespace ngraph
{
    namespace op
    {
        /// \brief Class for constants.
        class Constant : public Node
        {
        public:
            NGRAPH_API
            static const std::string type_name;
            const std::string& description() const override { return type_name; }
            /// \brief Constructs a tensor constant.
            ///
            /// \param type The element type of the tensor constant.
            /// \param shape The shape of the tensor constant.
            /// \param values A vector of literals for initializing the tensor constant. The size
            ///        of values must match the size of the shape.
            template <typename T>
            Constant(const element::Type& type, Shape shape, const std::vector<T>& values)
                : m_element_type(type)
                , m_shape(shape)
                , m_data(new runtime::AlignedBuffer(shape_size(m_shape) * m_element_type.size(),
                                                    host_alignment()))
            {
                NODE_VALIDATION_CHECK(
                    this,
                    values.size() == 1 || values.size() == shape_size(m_shape),
                    "Did not get the expected number of literals for a constant of shape ",
                    m_shape,
                    " (got ",
                    values.size(),
                    ", expected ",
                    (shape_size(m_shape) == 1 ? "" : "1 or "),
                    shape_size(m_shape),
                    ").");

                if (values.size() == 1)
                {
                    write_values(std::vector<T>(shape_size(m_shape), values[0]));
                }
                else
                {
                    write_values(values);
                }
                constructor_validate_and_infer_types();
            }

            /// \brief Constructs a tensor constant
            ///        This constructor is mainly to support deserialization of constants.
            ///
            /// \param type The element type of the tensor constant.
            /// \param shape The shape of the tensor constant.
            /// \param values A list of string values to use as the constant data.
            Constant(const element::Type& type, Shape shape, const std::vector<std::string>& values)
                : m_element_type(type)
                , m_shape(shape)
                , m_data(new runtime::AlignedBuffer(shape_size(m_shape) * m_element_type.size(),
                                                    host_alignment()))
            {
                NODE_VALIDATION_CHECK(
                    this,
                    values.size() == shape_size(m_shape) || values.size() == 1,
                    "Did not get the expected number of literals for a constant of shape ",
                    m_shape,
                    " (got ",
                    values.size(),
                    ", expected ",
                    shape_size(m_shape),
                    ".");

                if (type.is_integral())
                {
                    if (type.is_signed())
                    {
                        std::vector<int64_t> dvalues = parse_string<int64_t>(values);
                        if (values.size() == 1 && shape_size(m_shape) != 1)
                        {
                            dvalues = std::vector<int64_t>(shape_size(m_shape), dvalues[0]);
                        }
                        write_values(dvalues);
                    }
                    else
                    {
                        std::vector<uint64_t> dvalues = parse_string<uint64_t>(values);
                        if (values.size() == 1 && shape_size(m_shape) != 1)
                        {
                            dvalues = std::vector<uint64_t>(shape_size(m_shape), dvalues[0]);
                        }
                        write_values(dvalues);
                    }
                }
                else
                {
                    std::vector<double> dvalues = parse_string<double>(values);
                    if (values.size() == 1 && shape_size(m_shape) != 1)
                    {
                        dvalues = std::vector<double>(shape_size(m_shape), dvalues[0]);
                    }
                    write_values(dvalues);
                }
                constructor_validate_and_infer_types();
            }

            /// \brief Constructs a tensor constant with the same initialization value copied across
            //         the tensor. This constructor is to support deserialization of constants.
            ///
            /// \param type The element type of the tensor constant.
            /// \param shape The shape of the tensor constant.
            /// \param data A void* to constant data.
            Constant(const element::Type& type, const Shape& shape, const void* data)
                : m_element_type(type)
                , m_shape(shape)
                , m_data(nullptr)
            {<commit_msg>no_fork : Remove allocation for empty vector (#3544)<commit_after>//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed 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.
//*****************************************************************************

#pragma once

#include <cstring>
#include <sstream>

#include "ngraph/coordinate_diff.hpp"
#include "ngraph/node.hpp"
#include "ngraph/runtime/aligned_buffer.hpp"
#include "ngraph/type/bfloat16.hpp"
#include "ngraph/type/element_type.hpp"
#include "ngraph/util.hpp"

namespace ngraph
{
    namespace op
    {
        /// \brief Class for constants.
        class Constant : public Node
        {
        public:
            NGRAPH_API
            static const std::string type_name;
            const std::string& description() const override { return type_name; }
            /// \brief Constructs a tensor constant.
            ///
            /// \param type The element type of the tensor constant.
            /// \param shape The shape of the tensor constant.
            /// \param values A vector of literals for initializing the tensor constant. The size
            ///        of values must match the size of the shape.
            template <typename T>
            Constant(const element::Type& type, Shape shape, const std::vector<T>& values)
                : m_element_type(type)
                , m_shape(shape)
                , m_data(new runtime::AlignedBuffer(shape_size(m_shape) * m_element_type.size(),
                                                    host_alignment()))
            {
                NODE_VALIDATION_CHECK(
                    this,
                    values.size() == 1 || values.size() == shape_size(m_shape),
                    "Did not get the expected number of literals for a constant of shape ",
                    m_shape,
                    " (got ",
                    values.size(),
                    ", expected ",
                    (shape_size(m_shape) == 1 ? "" : "1 or "),
                    shape_size(m_shape),
                    ").");

                if (values.size() == 1)
                {
                    write_values(std::vector<T>(shape_size(m_shape), values[0]));
                }
                else
                {
                    write_values(values);
                }
                constructor_validate_and_infer_types();
            }

            /// \brief Constructs a tensor constant
            ///        This constructor is mainly to support deserialization of constants.
            ///
            /// \param type The element type of the tensor constant.
            /// \param shape The shape of the tensor constant.
            /// \param values A list of string values to use as the constant data.
            Constant(const element::Type& type, Shape shape, const std::vector<std::string>& values)
                : m_element_type(type)
                , m_shape(shape)
                , m_data(new runtime::AlignedBuffer(shape_size(m_shape) * m_element_type.size(),
                                                    host_alignment()))
            {
                NODE_VALIDATION_CHECK(
                    this,
                    values.size() == shape_size(m_shape) || values.size() == 1,
                    "Did not get the expected number of literals for a constant of shape ",
                    m_shape,
                    " (got ",
                    values.size(),
                    ", expected ",
                    shape_size(m_shape),
                    ".");
                if (values.size())
                {
                    if (type.is_integral())
                    {
                        if (type.is_signed())
                        {
                            std::vector<int64_t> dvalues = parse_string<int64_t>(values);
                            if (values.size() == 1 && shape_size(m_shape) != 1)
                            {
                                dvalues = std::vector<int64_t>(shape_size(m_shape), dvalues[0]);
                            }
                            write_values(dvalues);
                        }
                        else
                        {
                            std::vector<uint64_t> dvalues = parse_string<uint64_t>(values);
                            if (values.size() == 1 && shape_size(m_shape) != 1)
                            {
                                dvalues = std::vector<uint64_t>(shape_size(m_shape), dvalues[0]);
                            }
                            write_values(dvalues);
                        }
                    }
                    else
                    {
                        std::vector<double> dvalues = parse_string<double>(values);
                        if (values.size() == 1 && shape_size(m_shape) != 1)
                        {
                            dvalues = std::vector<double>(shape_size(m_shape), dvalues[0]);
                        }
                        write_values(dvalues);
                    }
                }
                constructor_validate_and_infer_types();
            }

            /// \brief Constructs a tensor constant with the same initialization value copied across
            //         the tensor. This constructor is to support deserialization of constants.
            ///
            /// \param type The element type of the tensor constant.
            /// \param shape The shape of the tensor constant.
            /// \param data A void* to constant data.
            Constant(const element::Type& type, const Shape& shape, const void* data)
                : m_element_type(type)
                , m_shape(shape)
                , m_data(nullptr)
            {
{'fraction_non_alphanumeric': 0.11682657421591551, 'fraction_numerical': 0.00693380633717649, 'mean_word_length': 1.32895230942546, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4091317', 'n_tokens_mistral': 3033, 'n_tokens_neox': 2800, 'n_words': 820}