hexsha
stringlengths
40
40
size
int64
7
1.05M
ext
stringclasses
13 values
lang
stringclasses
1 value
max_stars_repo_path
stringlengths
4
269
max_stars_repo_name
stringlengths
5
108
max_stars_repo_head_hexsha
stringlengths
40
40
max_stars_repo_licenses
listlengths
1
9
max_stars_count
int64
1
191k
max_stars_repo_stars_event_min_datetime
stringlengths
24
24
max_stars_repo_stars_event_max_datetime
stringlengths
24
24
max_issues_repo_path
stringlengths
4
269
max_issues_repo_name
stringlengths
5
116
max_issues_repo_head_hexsha
stringlengths
40
40
max_issues_repo_licenses
listlengths
1
9
max_issues_count
int64
1
67k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
4
269
max_forks_repo_name
stringlengths
5
116
max_forks_repo_head_hexsha
stringlengths
40
40
max_forks_repo_licenses
listlengths
1
9
max_forks_count
int64
1
105k
max_forks_repo_forks_event_min_datetime
stringlengths
24
24
max_forks_repo_forks_event_max_datetime
stringlengths
24
24
content
stringlengths
7
1.05M
avg_line_length
float64
1.21
330k
max_line_length
int64
6
990k
alphanum_fraction
float64
0.01
0.99
author_id
stringlengths
2
40
ab02d39d6b68c4af06fc1427a4f339961cd54097
1,120
hpp
C++
willow/include/popart/popx/op/basesortx.hpp
gglin001/popart
3225214343f6d98550b6620e809a3544e8bcbfc6
[ "MIT" ]
61
2020-07-06T17:11:46.000Z
2022-03-12T14:42:51.000Z
willow/include/popart/popx/op/basesortx.hpp
gglin001/popart
3225214343f6d98550b6620e809a3544e8bcbfc6
[ "MIT" ]
1
2021-02-25T01:30:29.000Z
2021-11-09T11:13:14.000Z
willow/include/popart/popx/op/basesortx.hpp
gglin001/popart
3225214343f6d98550b6620e809a3544e8bcbfc6
[ "MIT" ]
6
2020-07-15T12:33:13.000Z
2021-11-07T06:55:00.000Z
// Copyright (c) 2019 Graphcore Ltd. All rights reserved. #ifndef GUARD_NEURALNET_BASESORTX_HPP #define GUARD_NEURALNET_BASESORTX_HPP #include <popart/names.hpp> #include <popart/popx/popopx.hpp> namespace popart { namespace popx { struct FullSortResult { FullSortResult(snap::Tensor indices_, snap::Tensor values_, int axis_) : indices(indices_), values(values_), axis(axis_) {} snap::Tensor indices; snap::Tensor values; int axis; }; class BaseSortOpx : public PopOpx { public: BaseSortOpx(Op *, Devicex *); snap::Tensor createInputTensor(InIndex index, const poplar::DebugNameAndId &dnai) const final; InputCreatorType getInputCreatorType(InIndex index) const final; std::set<TensorId> mustExistBeforeCreate(InIndex index0) const final; protected: // sorted values, and indices of sorted values FullSortResult growFullSortResult(snap::program::Sequence &prog) const; // indices of sorted values snap::Tensor growIndicesSort(snap::program::Sequence &prog) const; // axis to sort on unsigned axis; }; } // namespace popx } // namespace popart #endif
23.829787
73
0.736607
gglin001
ab0d02a9b6ab1bdaeeee0cde50d0d4e433aed821
2,913
cc
C++
src/transforms/identity.cc
Samsung/veles.sound_feature_extraction-
56b7c5d3816d092c72a874ca236e889fe843e6cd
[ "Apache-2.0" ]
31
2015-11-10T06:06:47.000Z
2021-02-28T04:54:17.000Z
src/transforms/identity.cc
Samsung/veles.sound_feature_extraction-
56b7c5d3816d092c72a874ca236e889fe843e6cd
[ "Apache-2.0" ]
null
null
null
src/transforms/identity.cc
Samsung/veles.sound_feature_extraction-
56b7c5d3816d092c72a874ca236e889fe843e6cd
[ "Apache-2.0" ]
17
2015-08-08T20:28:49.000Z
2021-04-15T01:03:47.000Z
/*! @file identity.cc * @brief Just copies the input. * @author Markovtsev Vadim <v.markovtsev@samsung.com> * @version 1.0 * * @section Notes * This code partially conforms to <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml">Google C++ Style Guide</a>. * * @section Copyright * Copyright © 2013 Samsung R&D Institute Russia * * @section License * 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. */ #include "src/transforms/identity.h" #include "src/transform_registry.h" namespace sound_feature_extraction { namespace transforms { constexpr const char* Identity::kName; Identity::Identity() : input_format_(std::make_shared<IdentityFormat>()), output_format_(std::make_shared<IdentityFormat>()) { } const std::string& Identity::Name() const noexcept { static const std::string name(kName); return name; } const std::string& Identity::Description() const noexcept { static const std::string desc("Copy the input to output."); return desc; } const std::shared_ptr<BufferFormat> Identity::InputFormat() const noexcept { return input_format_; } size_t Identity::SetInputFormat(const std::shared_ptr<BufferFormat>& format, size_t buffersCount) { input_format_ = format; output_format_ = format; return buffersCount; } const std::shared_ptr<BufferFormat> Identity::OutputFormat() const noexcept { return output_format_; } void Identity::Initialize() const { } void Identity::Do(const Buffers& in, Buffers* out) const noexcept { *out = in; } std::shared_ptr<Buffers> Identity::CreateOutputBuffers( size_t count, void* reusedMemory) const noexcept { return std::make_shared<Buffers>(output_format_, count, reusedMemory); } const SupportedParametersMap& Identity::SupportedParameters() const noexcept { static const SupportedParametersMap sp; return sp; } const ParametersMap& Identity::GetParameters() const noexcept { static const ParametersMap p; return p; } void Identity::SetParameters( const ParametersMap&) { } REGISTER_TRANSFORM(Identity); } // namespace transforms } // namespace sound_feature_extraction
28.841584
136
0.734638
Samsung
ab0d86246024ed20f7a2fe9fc57e9814b50dbd40
1,464
cpp
C++
1679.cpp
Valarr/Uri
807de771b14b0e60d44b23835ad9ee7423c83471
[ "MIT" ]
null
null
null
1679.cpp
Valarr/Uri
807de771b14b0e60d44b23835ad9ee7423c83471
[ "MIT" ]
null
null
null
1679.cpp
Valarr/Uri
807de771b14b0e60d44b23835ad9ee7423c83471
[ "MIT" ]
null
null
null
#include <bits/stdc++.h> using namespace std; int main() { double mass_water, mass_ice, temp_water, temp_ice, mass; double energy, temp, ice_energy, water_energy; double toIce, transition, toWater; scanf("%lf %lf %lf %lf", &mass_water, &mass_ice, &temp_water, &temp_ice); while ((mass_water != 0) || (mass_ice != 0) || temp_water != 0 || temp_ice != 0) { //calcular energia do gelo ice_energy = 2.09*mass_ice*(temp_ice + 30); //calcular energia da agua water_energy = (4.19*mass_water*temp_water) + (335 * mass_water) + (2.09*mass_water * 30); // energia de 0 até temp // energia total do sistema, com base em -30ºC energy = ice_energy + water_energy; mass = mass_water + mass_ice; toIce = 2.09 * mass * 30; transition = 335 * mass; toWater = 4.19 * mass * 100; if (toIce >= energy) // quer dizer que tudo ta congelado { temp = - 30 + 30*(energy/toIce); printf("%.1lf g of ice and 0.0 g of water at %.1lf C\n",mass, temp); } else if ((toIce + transition) >= energy) { energy -= toIce; mass_ice = mass*(1 - (energy / transition)); mass_water = mass*(energy / transition); printf("%.1lf g of ice and %.1lf g of water at 0.0 C\n", mass_ice, mass_water); } else { energy -= toIce + transition; temp = 100 * (energy/toWater); printf("0.0 g of ice and %.1lf g of water at %.1lf C\n", mass, temp); } scanf("%lf %lf %lf %lf", &mass_water, &mass_ice, &temp_water, &temp_ice); } return 0; }
30.5
117
0.633197
Valarr
ab0e97ba3daf998018a2c7e9bd98757c07e985ba
84
cpp
C++
engine/backends/vulkan/libs/vk_mem_alloc_impl.cpp
Apache-HB/Benzene
0909370eeb09682f4af871b4c0d74b497963bfc8
[ "MIT" ]
null
null
null
engine/backends/vulkan/libs/vk_mem_alloc_impl.cpp
Apache-HB/Benzene
0909370eeb09682f4af871b4c0d74b497963bfc8
[ "MIT" ]
null
null
null
engine/backends/vulkan/libs/vk_mem_alloc_impl.cpp
Apache-HB/Benzene
0909370eeb09682f4af871b4c0d74b497963bfc8
[ "MIT" ]
1
2020-04-12T18:52:20.000Z
2020-04-12T18:52:20.000Z
#define VMA_IMPLEMENTATION #define VMA_HPP_NAMESPACE vma #include "vk_mem_alloc.hpp"
28
29
0.857143
Apache-HB
ab0ea9f2184bf1ca70f9204e317aa78c204e3eee
5,099
cc
C++
ui/gfx/geometry/matrix3_f.cc
sarang-apps/darshan_browser
173649bb8a7c656dc60784d19e7bb73e07c20daa
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
null
null
null
ui/gfx/geometry/matrix3_f.cc
sarang-apps/darshan_browser
173649bb8a7c656dc60784d19e7bb73e07c20daa
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
null
null
null
ui/gfx/geometry/matrix3_f.cc
sarang-apps/darshan_browser
173649bb8a7c656dc60784d19e7bb73e07c20daa
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
null
null
null
// Copyright (c) 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/gfx/geometry/matrix3_f.h" #include <algorithm> #include <cmath> #include <limits> #include "base/numerics/math_constants.h" #include "base/strings/stringprintf.h" namespace { // This is only to make accessing indices self-explanatory. enum MatrixCoordinates { M00, M01, M02, M10, M11, M12, M20, M21, M22, M_END }; template<typename T> double Determinant3x3(T data[M_END]) { // This routine is separated from the Matrix3F::Determinant because in // computing inverse we do want higher precision afforded by the explicit // use of 'double'. return static_cast<double>(data[M00]) * ( static_cast<double>(data[M11]) * data[M22] - static_cast<double>(data[M12]) * data[M21]) + static_cast<double>(data[M01]) * ( static_cast<double>(data[M12]) * data[M20] - static_cast<double>(data[M10]) * data[M22]) + static_cast<double>(data[M02]) * ( static_cast<double>(data[M10]) * data[M21] - static_cast<double>(data[M11]) * data[M20]); } } // namespace namespace gfx { Matrix3F::Matrix3F() { } Matrix3F::~Matrix3F() { } // static Matrix3F Matrix3F::Zeros() { Matrix3F matrix; matrix.set(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); return matrix; } // static Matrix3F Matrix3F::Ones() { Matrix3F matrix; matrix.set(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); return matrix; } // static Matrix3F Matrix3F::Identity() { Matrix3F matrix; matrix.set(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f); return matrix; } // static Matrix3F Matrix3F::FromOuterProduct(const Vector3dF& a, const Vector3dF& bt) { Matrix3F matrix; matrix.set(a.x() * bt.x(), a.x() * bt.y(), a.x() * bt.z(), a.y() * bt.x(), a.y() * bt.y(), a.y() * bt.z(), a.z() * bt.x(), a.z() * bt.y(), a.z() * bt.z()); return matrix; } bool Matrix3F::IsEqual(const Matrix3F& rhs) const { return 0 == memcmp(data_, rhs.data_, sizeof(data_)); } bool Matrix3F::IsNear(const Matrix3F& rhs, float precision) const { DCHECK(precision >= 0); for (int i = 0; i < M_END; ++i) { if (std::abs(data_[i] - rhs.data_[i]) > precision) return false; } return true; } Matrix3F Matrix3F::Add(const Matrix3F& rhs) const { Matrix3F result; for (int i = 0; i < M_END; ++i) result.data_[i] = data_[i] + rhs.data_[i]; return result; } Matrix3F Matrix3F::Subtract(const Matrix3F& rhs) const { Matrix3F result; for (int i = 0; i < M_END; ++i) result.data_[i] = data_[i] - rhs.data_[i]; return result; } Matrix3F Matrix3F::Inverse() const { Matrix3F inverse = Matrix3F::Zeros(); double determinant = Determinant3x3(data_); if (std::numeric_limits<float>::epsilon() > std::abs(determinant)) return inverse; // Singular matrix. Return Zeros(). inverse.set( static_cast<float>((data_[M11] * data_[M22] - data_[M12] * data_[M21]) / determinant), static_cast<float>((data_[M02] * data_[M21] - data_[M01] * data_[M22]) / determinant), static_cast<float>((data_[M01] * data_[M12] - data_[M02] * data_[M11]) / determinant), static_cast<float>((data_[M12] * data_[M20] - data_[M10] * data_[M22]) / determinant), static_cast<float>((data_[M00] * data_[M22] - data_[M02] * data_[M20]) / determinant), static_cast<float>((data_[M02] * data_[M10] - data_[M00] * data_[M12]) / determinant), static_cast<float>((data_[M10] * data_[M21] - data_[M11] * data_[M20]) / determinant), static_cast<float>((data_[M01] * data_[M20] - data_[M00] * data_[M21]) / determinant), static_cast<float>((data_[M00] * data_[M11] - data_[M01] * data_[M10]) / determinant)); return inverse; } Matrix3F Matrix3F::Transpose() const { Matrix3F transpose; transpose.set(data_[M00], data_[M10], data_[M20], data_[M01], data_[M11], data_[M21], data_[M02], data_[M12], data_[M22]); return transpose; } float Matrix3F::Determinant() const { return static_cast<float>(Determinant3x3(data_)); } Matrix3F MatrixProduct(const Matrix3F& lhs, const Matrix3F& rhs) { Matrix3F result = Matrix3F::Zeros(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { result.set(i, j, DotProduct(lhs.get_row(i), rhs.get_column(j))); } } return result; } Vector3dF MatrixProduct(const Matrix3F& lhs, const Vector3dF& rhs) { return Vector3dF(DotProduct(lhs.get_row(0), rhs), DotProduct(lhs.get_row(1), rhs), DotProduct(lhs.get_row(2), rhs)); } std::string Matrix3F::ToString() const { return base::StringPrintf( "[[%+0.4f, %+0.4f, %+0.4f]," " [%+0.4f, %+0.4f, %+0.4f]," " [%+0.4f, %+0.4f, %+0.4f]]", data_[M00], data_[M01], data_[M02], data_[M10], data_[M11], data_[M12], data_[M20], data_[M21], data_[M22]); } } // namespace gfx
28.486034
78
0.61365
sarang-apps
ab0eaecf5f6d794032345318a7df1c5a43406c11
194
cpp
C++
Second Year (2013-2014)/AP8/TP1/src/Exo5.cpp
tompo-andri/IUT
0b0c2d1c572858c552b711d15410e513f6ad848c
[ "MIT" ]
1
2015-04-29T01:08:47.000Z
2015-04-29T01:08:47.000Z
Second Year (2013-2014)/AP8/TP1/src/Exo5.cpp
tompo-andri/IUT
0b0c2d1c572858c552b711d15410e513f6ad848c
[ "MIT" ]
null
null
null
Second Year (2013-2014)/AP8/TP1/src/Exo5.cpp
tompo-andri/IUT
0b0c2d1c572858c552b711d15410e513f6ad848c
[ "MIT" ]
null
null
null
//Include its Exo5.h #include "Exo5.h" /** * The main method, here it'll just display "Ca marche!" */ int main() { //Redirect the output to the displays cout << "Coucou! Tu veux ... \n"; }
17.636364
56
0.623711
tompo-andri
ab101573c1620ad335809ee1c7f27afdeab4d3d8
596
cpp
C++
Project1/Collision.cpp
RyunosukeKawakami/SlimeHunter
bf9c496fefc59bb68756249400ac9cba253597be
[ "IJG", "Unlicense" ]
null
null
null
Project1/Collision.cpp
RyunosukeKawakami/SlimeHunter
bf9c496fefc59bb68756249400ac9cba253597be
[ "IJG", "Unlicense" ]
null
null
null
Project1/Collision.cpp
RyunosukeKawakami/SlimeHunter
bf9c496fefc59bb68756249400ac9cba253597be
[ "IJG", "Unlicense" ]
null
null
null
#include "Collision.h" Collision::Collision() { } Collision::~Collision() { } bool Collision::Main(Point a, Point b) { if (Distance(a,b)) return Temp(a,b); else return false; } bool Collision::Distance(Point a, Point b) { bool x; bool y; x = a.x - 32 * 4 < b.x < a.x + 32 * 4; y = a.y - 32 * 4 < b.y < a.y + 32 * 4; if (x == true && y == true) return true; else return false; } bool Collision::Temp(Point a, Point b) { bool x; bool y; x = a.x2 >= b.x && a.x <= b.x2; y = a.y2 >= b.y && a.y <= b.y2; if (x == true && y == true) return true; else return false; }
12.956522
42
0.545302
RyunosukeKawakami
ab10bd5c0732e1722c4006bc273db064da6a9182
17,330
cc
C++
third_party/blink/renderer/core/html/forms/html_select_element_test.cc
zipated/src
2b8388091c71e442910a21ada3d97ae8bc1845d3
[ "BSD-3-Clause" ]
2,151
2020-04-18T07:31:17.000Z
2022-03-31T08:39:18.000Z
third_party/blink/renderer/core/html/forms/html_select_element_test.cc
cangulcan/src
2b8388091c71e442910a21ada3d97ae8bc1845d3
[ "BSD-3-Clause" ]
395
2020-04-18T08:22:18.000Z
2021-12-08T13:04:49.000Z
third_party/blink/renderer/core/html/forms/html_select_element_test.cc
cangulcan/src
2b8388091c71e442910a21ada3d97ae8bc1845d3
[ "BSD-3-Clause" ]
338
2020-04-18T08:03:10.000Z
2022-03-29T12:33:22.000Z
// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "third_party/blink/renderer/core/html/forms/html_select_element.h" #include <memory> #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/frame/local_frame_view.h" #include "third_party/blink/renderer/core/html/forms/form_controller.h" #include "third_party/blink/renderer/core/html/forms/html_form_element.h" #include "third_party/blink/renderer/core/testing/page_test_base.h" namespace blink { class HTMLSelectElementTest : public PageTestBase { protected: void SetUp() override; }; void HTMLSelectElementTest::SetUp() { PageTestBase::SetUp(); GetDocument().SetMimeType("text/html"); } TEST_F(HTMLSelectElementTest, SaveRestoreSelectSingleFormControlState) { SetHtmlInnerHTML( "<!DOCTYPE HTML><select id='sel'>" "<option value='111' id='0'>111</option>" "<option value='222'>222</option>" "<option value='111' selected id='2'>!666</option>" "<option value='999'>999</option></select>"); Element* element = GetElementById("sel"); HTMLFormControlElementWithState* select = ToHTMLSelectElement(element); HTMLOptionElement* opt0 = ToHTMLOptionElement(GetElementById("0")); HTMLOptionElement* opt2 = ToHTMLOptionElement(GetElementById("2")); // Save the select element state, and then restore again. // Test passes if the restored state is not changed. EXPECT_EQ(2, ToHTMLSelectElement(element)->selectedIndex()); EXPECT_FALSE(opt0->Selected()); EXPECT_TRUE(opt2->Selected()); FormControlState select_state = select->SaveFormControlState(); EXPECT_EQ(2U, select_state.ValueSize()); // Clear the selected state, to be restored by restoreFormControlState. ToHTMLSelectElement(select)->setSelectedIndex(-1); ASSERT_FALSE(opt2->Selected()); // Restore select->RestoreFormControlState(select_state); EXPECT_EQ(2, ToHTMLSelectElement(element)->selectedIndex()); EXPECT_FALSE(opt0->Selected()); EXPECT_TRUE(opt2->Selected()); } TEST_F(HTMLSelectElementTest, SaveRestoreSelectMultipleFormControlState) { SetHtmlInnerHTML( "<!DOCTYPE HTML><select id='sel' multiple>" "<option value='111' id='0'>111</option>" "<option value='222'>222</option>" "<option value='111' selected id='2'>!666</option>" "<option value='999' selected id='3'>999</option></select>"); HTMLFormControlElementWithState* select = ToHTMLSelectElement(GetElementById("sel")); HTMLOptionElement* opt0 = ToHTMLOptionElement(GetElementById("0")); HTMLOptionElement* opt2 = ToHTMLOptionElement(GetElementById("2")); HTMLOptionElement* opt3 = ToHTMLOptionElement(GetElementById("3")); // Save the select element state, and then restore again. // Test passes if the selected options are not changed. EXPECT_FALSE(opt0->Selected()); EXPECT_TRUE(opt2->Selected()); EXPECT_TRUE(opt3->Selected()); FormControlState select_state = select->SaveFormControlState(); EXPECT_EQ(4U, select_state.ValueSize()); // Clear the selected state, to be restored by restoreFormControlState. opt2->SetSelected(false); opt3->SetSelected(false); ASSERT_FALSE(opt2->Selected()); ASSERT_FALSE(opt3->Selected()); // Restore select->RestoreFormControlState(select_state); EXPECT_FALSE(opt0->Selected()); EXPECT_TRUE(opt2->Selected()); EXPECT_TRUE(opt3->Selected()); } TEST_F(HTMLSelectElementTest, RestoreUnmatchedFormControlState) { // We had a bug that selectedOption() and m_lastOnChangeOption were // mismatched in optionToBeShown(). It happened when // restoreFormControlState() couldn't find matched OPTIONs. // crbug.com/627833. SetHtmlInnerHTML(R"HTML( <select id='sel'> <option selected>Default</option> <option id='2'>222</option> </select> )HTML"); Element* element = GetElementById("sel"); HTMLFormControlElementWithState* select = ToHTMLSelectElement(element); HTMLOptionElement* opt2 = ToHTMLOptionElement(GetElementById("2")); ToHTMLSelectElement(element)->setSelectedIndex(1); // Save the current state. FormControlState select_state = select->SaveFormControlState(); EXPECT_EQ(2U, select_state.ValueSize()); // Reset the status. select->Reset(); ASSERT_FALSE(opt2->Selected()); element->RemoveChild(opt2); // Restore select->RestoreFormControlState(select_state); EXPECT_EQ(-1, ToHTMLSelectElement(element)->selectedIndex()); EXPECT_EQ(nullptr, ToHTMLSelectElement(element)->OptionToBeShown()); } TEST_F(HTMLSelectElementTest, VisibleBoundsInVisualViewport) { SetHtmlInnerHTML( "<select style='position:fixed; top:12.3px; height:24px; " "-webkit-appearance:none;'><option>o1</select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); ASSERT_NE(select, nullptr); IntRect bounds = select->VisibleBoundsInVisualViewport(); EXPECT_EQ(24, bounds.Height()); } TEST_F(HTMLSelectElementTest, PopupIsVisible) { SetHtmlInnerHTML("<select><option>o1</option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); ASSERT_NE(select, nullptr); EXPECT_FALSE(select->PopupIsVisible()); select->ShowPopup(); EXPECT_TRUE(select->PopupIsVisible()); GetDocument().Shutdown(); EXPECT_FALSE(select->PopupIsVisible()); } TEST_F(HTMLSelectElementTest, FirstSelectableOption) { { SetHtmlInnerHTML("<select></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ(nullptr, select->FirstSelectableOption()); } { SetHtmlInnerHTML( "<select><option id=o1></option><option id=o2></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o1", select->FirstSelectableOption()->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><option id=o1 disabled></option><option " "id=o2></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o2", select->FirstSelectableOption()->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><option id=o1 style='display:none'></option><option " "id=o2></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o2", select->FirstSelectableOption()->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><optgroup><option id=o1></option><option " "id=o2></option></optgroup></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o1", select->FirstSelectableOption()->FastGetAttribute( HTMLNames::idAttr)); } } TEST_F(HTMLSelectElementTest, LastSelectableOption) { { SetHtmlInnerHTML("<select></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ(nullptr, select->LastSelectableOption()); } { SetHtmlInnerHTML( "<select><option id=o1></option><option id=o2></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o2", select->LastSelectableOption()->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><option id=o1></option><option id=o2 " "disabled></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o1", select->LastSelectableOption()->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><option id=o1></option><option id=o2 " "style='display:none'></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o1", select->LastSelectableOption()->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><optgroup><option id=o1></option><option " "id=o2></option></optgroup></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o2", select->LastSelectableOption()->FastGetAttribute( HTMLNames::idAttr)); } } TEST_F(HTMLSelectElementTest, NextSelectableOption) { { SetHtmlInnerHTML("<select></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ(nullptr, select->NextSelectableOption(nullptr)); } { SetHtmlInnerHTML( "<select><option id=o1></option><option id=o2></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o1", select->NextSelectableOption(nullptr)->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><option id=o1 disabled></option><option " "id=o2></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o2", select->NextSelectableOption(nullptr)->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><option id=o1 style='display:none'></option><option " "id=o2></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o2", select->NextSelectableOption(nullptr)->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><optgroup><option id=o1></option><option " "id=o2></option></optgroup></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o1", select->NextSelectableOption(nullptr)->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><option id=o1></option><option id=o2></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); HTMLOptionElement* option = ToHTMLOptionElement(GetElementById("o1")); EXPECT_EQ("o2", select->NextSelectableOption(option)->FastGetAttribute( HTMLNames::idAttr)); EXPECT_EQ(nullptr, select->NextSelectableOption( ToHTMLOptionElement(GetElementById("o2")))); } { SetHtmlInnerHTML( "<select><option id=o1></option><optgroup><option " "id=o2></option></optgroup></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); HTMLOptionElement* option = ToHTMLOptionElement(GetElementById("o1")); EXPECT_EQ("o2", select->NextSelectableOption(option)->FastGetAttribute( HTMLNames::idAttr)); } } TEST_F(HTMLSelectElementTest, PreviousSelectableOption) { { SetHtmlInnerHTML("<select></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ(nullptr, select->PreviousSelectableOption(nullptr)); } { SetHtmlInnerHTML( "<select><option id=o1></option><option id=o2></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o2", select->PreviousSelectableOption(nullptr)->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><option id=o1></option><option id=o2 " "disabled></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o1", select->PreviousSelectableOption(nullptr)->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><option id=o1></option><option id=o2 " "style='display:none'></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o1", select->PreviousSelectableOption(nullptr)->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><optgroup><option id=o1></option><option " "id=o2></option></optgroup></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); EXPECT_EQ("o2", select->PreviousSelectableOption(nullptr)->FastGetAttribute( HTMLNames::idAttr)); } { SetHtmlInnerHTML( "<select><option id=o1></option><option id=o2></option></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); HTMLOptionElement* option = ToHTMLOptionElement(GetElementById("o2")); EXPECT_EQ("o1", select->PreviousSelectableOption(option)->FastGetAttribute( HTMLNames::idAttr)); EXPECT_EQ(nullptr, select->PreviousSelectableOption( ToHTMLOptionElement(GetElementById("o1")))); } { SetHtmlInnerHTML( "<select><option id=o1></option><optgroup><option " "id=o2></option></optgroup></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); HTMLOptionElement* option = ToHTMLOptionElement(GetElementById("o2")); EXPECT_EQ("o1", select->PreviousSelectableOption(option)->FastGetAttribute( HTMLNames::idAttr)); } } TEST_F(HTMLSelectElementTest, ActiveSelectionEndAfterOptionRemoval) { SetHtmlInnerHTML( "<select><optgroup><option selected>o1</option></optgroup></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); HTMLOptionElement* option = ToHTMLOptionElement(select->firstChild()->firstChild()); EXPECT_EQ(1, select->ActiveSelectionEndListIndex()); select->firstChild()->removeChild(option); EXPECT_EQ(-1, select->ActiveSelectionEndListIndex()); select->AppendChild(option); EXPECT_EQ(1, select->ActiveSelectionEndListIndex()); } TEST_F(HTMLSelectElementTest, DefaultToolTip) { SetHtmlInnerHTML( "<select size=4><option value=" ">Placeholder</option><optgroup><option>o2</option></optgroup></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); Element* option = ToElement(select->firstChild()); Element* optgroup = ToElement(option->nextSibling()); EXPECT_EQ(String(), select->DefaultToolTip()) << "defaultToolTip for SELECT without FORM and without required " "attribute should return null string."; EXPECT_EQ(select->DefaultToolTip(), option->DefaultToolTip()); EXPECT_EQ(select->DefaultToolTip(), optgroup->DefaultToolTip()); select->SetBooleanAttribute(HTMLNames::requiredAttr, true); EXPECT_EQ("<<ValidationValueMissingForSelect>>", select->DefaultToolTip()) << "defaultToolTip for SELECT without FORM and with required attribute " "should return a valueMissing message."; EXPECT_EQ(select->DefaultToolTip(), option->DefaultToolTip()); EXPECT_EQ(select->DefaultToolTip(), optgroup->DefaultToolTip()); HTMLFormElement* form = HTMLFormElement::Create(GetDocument()); GetDocument().body()->AppendChild(form); form->AppendChild(select); EXPECT_EQ("<<ValidationValueMissingForSelect>>", select->DefaultToolTip()) << "defaultToolTip for SELECT with FORM and required attribute should " "return a valueMissing message."; EXPECT_EQ(select->DefaultToolTip(), option->DefaultToolTip()); EXPECT_EQ(select->DefaultToolTip(), optgroup->DefaultToolTip()); form->SetBooleanAttribute(HTMLNames::novalidateAttr, true); EXPECT_EQ(String(), select->DefaultToolTip()) << "defaultToolTip for SELECT with FORM[novalidate] and required " "attribute should return null string."; EXPECT_EQ(select->DefaultToolTip(), option->DefaultToolTip()); EXPECT_EQ(select->DefaultToolTip(), optgroup->DefaultToolTip()); option->remove(); optgroup->remove(); EXPECT_EQ(String(), option->DefaultToolTip()); EXPECT_EQ(String(), optgroup->DefaultToolTip()); } TEST_F(HTMLSelectElementTest, SetRecalcListItemsByOptgroupRemoval) { SetHtmlInnerHTML( "<select><optgroup><option>sub1</option><option>sub2</option></" "optgroup></select>"); HTMLSelectElement* select = ToHTMLSelectElement(GetDocument().body()->firstChild()); select->SetInnerHTMLFromString(""); // PASS if setInnerHTML didn't have a check failure. } TEST_F(HTMLSelectElementTest, ScrollToOptionAfterLayoutCrash) { // crbug.com/737447 // This test passes if no crash. SetHtmlInnerHTML(R"HTML( <style>*:checked { position:fixed; }</style> <select multiple><<option>o1</option><option selected>o2</option></select> )HTML"); } } // namespace blink
38.769575
80
0.683843
zipated
ab123d3b8e48d022e5d60dace108b07dc6866392
2,382
cc
C++
CondTools/DQM/src/DQMSummarySourceHandler.cc
nistefan/cmssw
ea13af97f7f2117a4f590a5e654e06ecd9825a5b
[ "Apache-2.0" ]
3
2018-08-24T19:10:26.000Z
2019-02-19T11:45:32.000Z
CondTools/DQM/src/DQMSummarySourceHandler.cc
nistefan/cmssw
ea13af97f7f2117a4f590a5e654e06ecd9825a5b
[ "Apache-2.0" ]
3
2018-08-23T13:40:24.000Z
2019-12-05T21:16:03.000Z
CondTools/DQM/src/DQMSummarySourceHandler.cc
nistefan/cmssw
ea13af97f7f2117a4f590a5e654e06ecd9825a5b
[ "Apache-2.0" ]
5
2018-08-21T16:37:52.000Z
2020-01-09T13:33:17.000Z
#include "CondTools/DQM/interface/DQMSummarySourceHandler.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ParameterSetfwd.h" #include "CondTools/DQM/interface/DQMSummaryReader.h" #include <iostream> #include <string> #include <vector> namespace popcon { DQMSummarySourceHandler::DQMSummarySourceHandler(const edm::ParameterSet & pset): m_name(pset.getUntrackedParameter<std::string>("name","DQMSummarySourceHandler")), m_since(pset.getUntrackedParameter<unsigned long long>("firstSince",1)), m_user(pset.getUntrackedParameter<std::string>("OnlineDBUser","CMS_DQM_SUMMARY")), m_pass(pset.getUntrackedParameter<std::string>("OnlineDBPass","****")) { m_connectionString = "oracle://cms_omds_lb/CMS_DQM_SUMMARY"; } DQMSummarySourceHandler::~DQMSummarySourceHandler() {} void DQMSummarySourceHandler::getNewObjects() { //check what is already inside of the database edm::LogInfo("DQMSummarySourceHandler") << "------- " << m_name << " -> getNewObjects\n" << "got offlineInfo " << tagInfo().name << ", size " << tagInfo().size << ", last object valid since " << tagInfo().lastInterval.first << " token " << tagInfo().lastPayloadToken << std::endl; edm::LogInfo("DQMSummarySourceHandler") << " ------ last entry info regarding the payload (if existing): " << logDBEntry().usertext << "; last record with the correct tag (if existing) has been written in the db: " << logDBEntry().destinationDB << std::endl; if (tagInfo().size > 0) { Ref payload = lastPayload(); edm::LogInfo("DQMSummarySourceHandler") << "size of last payload " << payload->m_summary.size() << std::endl; } std::cout << "runnumber/first since = " << m_since << std::endl; DQMSummary * dqmSummary = new DQMSummary; DQMSummaryReader dqmSummaryReader(m_connectionString, m_user, m_pass); *dqmSummary = dqmSummaryReader.readData("SUMMARYCONTENT", m_since); m_to_transfer.push_back(std::make_pair((DQMSummary*)dqmSummary,m_since)); edm::LogInfo("DQMSummarySourceHandler") << "------- " << m_name << " - > getNewObjects" << std::endl; } std::string DQMSummarySourceHandler::id() const {return m_name;} }
47.64
111
0.677162
nistefan
ab1321bb924c0c4163be90d2c196ba4de3f9fa17
1,572
cpp
C++
src/platform/opengl/graphics_gl_context.cpp
104-Berlin/usk-graphics
537dd48aa354b18b68424120a3aa64a246fefaf6
[ "MIT" ]
null
null
null
src/platform/opengl/graphics_gl_context.cpp
104-Berlin/usk-graphics
537dd48aa354b18b68424120a3aa64a246fefaf6
[ "MIT" ]
null
null
null
src/platform/opengl/graphics_gl_context.cpp
104-Berlin/usk-graphics
537dd48aa354b18b68424120a3aa64a246fefaf6
[ "MIT" ]
null
null
null
#include "graphics_opengl.h" using namespace GL; void GLContext::Init(void* initData) { if (!initData) { printf("Please provide the GLADloadproc to the OpenGL context init"); return; } int gladStatus = gladLoadGLLoader((GLADloadproc)initData); printf("Glad Init Status: %d\n", gladStatus); printf("%s\n", glGetString(GL_VERSION)); EnableDepthTest(true); } void GLContext::Clear(float r, float g, float b, unsigned char GCLEAROPTIONS) { GLuint clearOption = 0; clearOption |= GCLEAROPTIONS & GCLEAROPTION_COLOR_BUFFER ? GL_COLOR_BUFFER_BIT : 0; clearOption |= GCLEAROPTIONS & GCLEAROPTION_DEPTH_BUFFER ? GL_DEPTH_BUFFER_BIT : 0; clearOption |= GCLEAROPTIONS & GCLEAROPTION_STENCIL_BUFFER ? GL_STENCIL_BUFFER_BIT : 0; clearOption |= GCLEAROPTIONS & GCLEAROPTION_ACCUM_BUFFER ? GL_ACCUM_BUFFER_BIT : 0; glCall(glClearColor(r, g, b, 1)); glCall(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); } void GLContext::EnableDepthTest(bool enable) { glCall(glDisable(GL_SCISSOR_TEST)); if (fDepthTestEnabled) { glCall(glEnable(GL_DEPTH_TEST)); } else { glCall(glDisable(GL_DEPTH_TEST)); } } void GLContext::DrawElements(size_t count, Graphics::GIndexType indexType, Graphics::GDrawMode drawMode) { glCall(glDrawElements(DrawModeToOpenGLMode(drawMode), count, IndexTypeToOpenGLType(indexType), NULL)); } void GLContext::DrawArrays(size_t start, size_t count, Graphics::GDrawMode drawMode) { glCall(glDrawArrays(DrawModeToOpenGLMode(drawMode), start, count)); }
32.75
106
0.73028
104-Berlin
ab1b41fc425059e49a59526fcc3ee6e4b776a49b
28,467
cxx
C++
src/libserver/symcache/symcache_impl.cxx
msuslu/rspamd
95764f816a9e1251a755c6edad339637345cfe28
[ "Apache-2.0" ]
null
null
null
src/libserver/symcache/symcache_impl.cxx
msuslu/rspamd
95764f816a9e1251a755c6edad339637345cfe28
[ "Apache-2.0" ]
null
null
null
src/libserver/symcache/symcache_impl.cxx
msuslu/rspamd
95764f816a9e1251a755c6edad339637345cfe28
[ "Apache-2.0" ]
null
null
null
/*- * Copyright 2022 Vsevolod Stakhov * * 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. */ #include "lua/lua_common.h" #include "symcache_internal.hxx" #include "symcache_item.hxx" #include "symcache_runtime.hxx" #include "unix-std.h" #include "libutil/cxx/locked_file.hxx" #include "fmt/core.h" #include "contrib/t1ha/t1ha.h" #include <cmath> namespace rspamd::symcache { INIT_LOG_MODULE_PUBLIC(symcache) auto symcache::init() -> bool { auto res = true; reload_time = cfg->cache_reload_time; if (cfg->cache_filename != nullptr) { res = load_items(); } /* Deal with the delayed dependencies */ for (const auto &delayed_dep: *delayed_deps) { auto virt_item = get_item_by_name(delayed_dep.from, false); auto real_item = get_item_by_name(delayed_dep.from, true); if (virt_item == nullptr || real_item == nullptr) { msg_err_cache("cannot register delayed dependency between %s and %s: " "%s is missing", delayed_dep.from.data(), delayed_dep.to.data(), delayed_dep.from.data()); } else { msg_debug_cache("delayed between %s(%d:%d) -> %s", delayed_dep.from.data(), real_item->id, virt_item->id, delayed_dep.to.data()); add_dependency(real_item->id, delayed_dep.to, virt_item != real_item ? virt_item->id : -1); } } /* Remove delayed dependencies, as they are no longer needed at this point */ delayed_deps.reset(); /* Deal with the delayed conditions */ for (const auto &delayed_cond: *delayed_conditions) { auto it = get_item_by_name_mut(delayed_cond.sym, true); if (it == nullptr) { msg_err_cache ( "cannot register delayed condition for %s", delayed_cond.sym.c_str()); luaL_unref(delayed_cond.L, LUA_REGISTRYINDEX, delayed_cond.cbref); } else { if (!it->add_condition(delayed_cond.L, delayed_cond.cbref)) { msg_err_cache ( "cannot register delayed condition for %s: virtual parent; qed", delayed_cond.sym.c_str()); g_abort(); } } } delayed_conditions.reset(); for (auto &it: items_by_id) { it->process_deps(*this); } /* Sorting stuff */ auto postfilters_cmp = [](const auto &it1, const auto &it2) -> int { if (it1->priority > it2->priority) { return 1; } else if (it1->priority == it2->priority) { return 0; } return -1; }; auto prefilters_cmp = [](const auto &it1, const auto &it2) -> int { if (it1->priority > it2->priority) { return -1; } else if (it1->priority == it2->priority) { return 0; } return 1; }; std::stable_sort(std::begin(connfilters), std::end(connfilters), prefilters_cmp); std::stable_sort(std::begin(prefilters), std::end(prefilters), prefilters_cmp); std::stable_sort(std::begin(postfilters), std::end(postfilters), postfilters_cmp); std::stable_sort(std::begin(idempotent), std::end(idempotent), postfilters_cmp); resort(); /* Connect metric symbols with symcache symbols */ if (cfg->symbols) { g_hash_table_foreach(cfg->symbols, symcache::metric_connect_cb, (void *) this); } return res; } auto symcache::load_items() -> bool { auto cached_map = util::raii_mmaped_locked_file::mmap_shared(cfg->cache_filename, O_RDONLY, PROT_READ); if (!cached_map.has_value()) { msg_info_cache("%s", cached_map.error().c_str()); return false; } if (cached_map->get_size() < (gint) sizeof(symcache_header)) { msg_info_cache("cannot use file %s, truncated: %z", cfg->cache_filename, errno, strerror(errno)); return false; } const auto *hdr = (struct symcache_header *) cached_map->get_map(); if (memcmp(hdr->magic, symcache_magic, sizeof(symcache_magic)) != 0) { msg_info_cache("cannot use file %s, bad magic", cfg->cache_filename); return false; } auto *parser = ucl_parser_new(0); const auto *p = (const std::uint8_t *) (hdr + 1); if (!ucl_parser_add_chunk(parser, p, cached_map->get_size() - sizeof(*hdr))) { msg_info_cache ("cannot use file %s, cannot parse: %s", cfg->cache_filename, ucl_parser_get_error(parser)); ucl_parser_free(parser); return false; } auto *top = ucl_parser_get_object(parser); ucl_parser_free(parser); if (top == nullptr || ucl_object_type(top) != UCL_OBJECT) { msg_info_cache ("cannot use file %s, bad object", cfg->cache_filename); ucl_object_unref(top); return false; } auto it = ucl_object_iterate_new(top); const ucl_object_t *cur; while ((cur = ucl_object_iterate_safe(it, true)) != nullptr) { auto item_it = items_by_symbol.find(ucl_object_key(cur)); if (item_it != items_by_symbol.end()) { auto item = item_it->second; /* Copy saved info */ /* * XXX: don't save or load weight, it should be obtained from the * metric */ #if 0 elt = ucl_object_lookup (cur, "weight"); if (elt) { w = ucl_object_todouble (elt); if (w != 0) { item->weight = w; } } #endif const auto *elt = ucl_object_lookup(cur, "time"); if (elt) { item->st->avg_time = ucl_object_todouble(elt); } elt = ucl_object_lookup(cur, "count"); if (elt) { item->st->total_hits = ucl_object_toint(elt); item->last_count = item->st->total_hits; } elt = ucl_object_lookup(cur, "frequency"); if (elt && ucl_object_type(elt) == UCL_OBJECT) { const ucl_object_t *freq_elt; freq_elt = ucl_object_lookup(elt, "avg"); if (freq_elt) { item->st->avg_frequency = ucl_object_todouble(freq_elt); } freq_elt = ucl_object_lookup(elt, "stddev"); if (freq_elt) { item->st->stddev_frequency = ucl_object_todouble(freq_elt); } } if (item->is_virtual() && !item->is_ghost()) { const auto &parent = item->get_parent(*this); if (parent) { if (parent->st->weight < item->st->weight) { parent->st->weight = item->st->weight; } } /* * We maintain avg_time for virtual symbols equal to the * parent item avg_time */ item->st->avg_time = parent->st->avg_time; } total_weight += fabs(item->st->weight); total_hits += item->st->total_hits; } } ucl_object_iterate_free(it); ucl_object_unref(top); return true; } template<typename T> static constexpr auto round_to_hundreds(T x) { return (::floor(x) * 100.0) / 100.0; } bool symcache::save_items() const { if (cfg->cache_filename == nullptr) { return false; } auto file_sink = util::raii_file_sink::create(cfg->cache_filename, O_WRONLY | O_TRUNC, 00644); if (!file_sink.has_value()) { if (errno == EEXIST) { /* Some other process is already writing data, give up silently */ return false; } msg_err_cache("%s", file_sink.error().c_str()); return false; } struct symcache_header hdr; memset(&hdr, 0, sizeof(hdr)); memcpy(hdr.magic, symcache_magic, sizeof(symcache_magic)); if (write(file_sink->get_fd(), &hdr, sizeof(hdr)) == -1) { msg_err_cache("cannot write to file %s, error %d, %s", cfg->cache_filename, errno, strerror(errno)); return false; } auto *top = ucl_object_typed_new(UCL_OBJECT); for (const auto &it: items_by_symbol) { auto item = it.second; auto elt = ucl_object_typed_new(UCL_OBJECT); ucl_object_insert_key(elt, ucl_object_fromdouble(round_to_hundreds(item->st->weight)), "weight", 0, false); ucl_object_insert_key(elt, ucl_object_fromdouble(round_to_hundreds(item->st->time_counter.mean)), "time", 0, false); ucl_object_insert_key(elt, ucl_object_fromint(item->st->total_hits), "count", 0, false); auto *freq = ucl_object_typed_new(UCL_OBJECT); ucl_object_insert_key(freq, ucl_object_fromdouble(round_to_hundreds(item->st->frequency_counter.mean)), "avg", 0, false); ucl_object_insert_key(freq, ucl_object_fromdouble(round_to_hundreds(item->st->frequency_counter.stddev)), "stddev", 0, false); ucl_object_insert_key(elt, freq, "frequency", 0, false); ucl_object_insert_key(top, elt, it.first.data(), 0, true); } auto fp = fdopen(file_sink->get_fd(), "a"); auto *efunc = ucl_object_emit_file_funcs(fp); auto ret = ucl_object_emit_full(top, UCL_EMIT_JSON_COMPACT, efunc, nullptr); ucl_object_emit_funcs_free(efunc); ucl_object_unref(top); fclose(fp); return ret; } auto symcache::metric_connect_cb(void *k, void *v, void *ud) -> void { auto *cache = (symcache *) ud; const auto *sym = (const char *) k; auto *s = (struct rspamd_symbol *) v; auto weight = *s->weight_ptr; auto *item = cache->get_item_by_name_mut(sym, false); if (item) { item->st->weight = weight; s->cache_item = (void *) item; } } auto symcache::get_item_by_id(int id, bool resolve_parent) const -> const cache_item * { if (id < 0 || id >= items_by_id.size()) { msg_err_cache("internal error: requested item with id %d, when we have just %d items in the cache", id, (int) items_by_id.size()); return nullptr; } auto &ret = items_by_id[id]; if (!ret) { msg_err_cache("internal error: requested item with id %d but it is empty; qed", id); return nullptr; } if (resolve_parent && ret->is_virtual()) { return ret->get_parent(*this); } return ret.get(); } auto symcache::get_item_by_name(std::string_view name, bool resolve_parent) const -> const cache_item * { auto it = items_by_symbol.find(name); if (it == items_by_symbol.end()) { return nullptr; } if (resolve_parent && it->second->is_virtual()) { return it->second->get_parent(*this); } return it->second.get(); } auto symcache::get_item_by_name_mut(std::string_view name, bool resolve_parent) const -> cache_item * { auto it = items_by_symbol.find(name); if (it == items_by_symbol.end()) { return nullptr; } if (resolve_parent && it->second->is_virtual()) { return (cache_item *) it->second->get_parent(*this); } return it->second.get(); } auto symcache::add_dependency(int id_from, std::string_view to, int virtual_id_from) -> void { g_assert (id_from >= 0 && id_from < (gint) items_by_id.size()); const auto &source = items_by_id[id_from]; g_assert (source.get() != nullptr); source->deps.emplace_back(cache_item_ptr{nullptr}, std::string(to), id_from, -1); if (virtual_id_from >= 0) { g_assert (virtual_id_from < (gint) items_by_id.size()); /* We need that for settings id propagation */ const auto &vsource = items_by_id[virtual_id_from]; g_assert (vsource.get() != nullptr); vsource->deps.emplace_back(cache_item_ptr{nullptr}, std::string(to), -1, virtual_id_from); } } auto symcache::resort() -> void { auto ord = std::make_shared<order_generation>(filters.size(), cur_order_gen); for (auto &it: filters) { if (it) { total_hits += it->st->total_hits; it->order = 0; ord->d.emplace_back(it); } } enum class tsort_mask { PERM, TEMP }; constexpr auto tsort_unmask = [](cache_item *it) -> auto { return (it->order & ~((1u << 31) | (1u << 30))); }; /* Recursive topological sort helper */ const auto tsort_visit = [&](cache_item *it, unsigned cur_order, auto &&rec) { constexpr auto tsort_mark = [](cache_item *it, tsort_mask how) { switch (how) { case tsort_mask::PERM: it->order |= (1u << 31); break; case tsort_mask::TEMP: it->order |= (1u << 30); break; } }; constexpr auto tsort_is_marked = [](cache_item *it, tsort_mask how) { switch (how) { case tsort_mask::PERM: return (it->order & (1u << 31)); case tsort_mask::TEMP: return (it->order & (1u << 30)); } return 100500u; /* Because fuck compilers, that's why */ }; if (tsort_is_marked(it, tsort_mask::PERM)) { if (cur_order > tsort_unmask(it)) { /* Need to recalculate the whole chain */ it->order = cur_order; /* That also removes all masking */ } else { /* We are fine, stop DFS */ return; } } else if (tsort_is_marked(it, tsort_mask::TEMP)) { msg_err_cache("cyclic dependencies found when checking '%s'!", it->symbol.c_str()); return; } tsort_mark(it, tsort_mask::TEMP); msg_debug_cache("visiting node: %s (%d)", it->symbol.c_str(), cur_order); for (const auto &dep: it->deps) { msg_debug_cache ("visiting dep: %s (%d)", dep.item->symbol.c_str(), cur_order + 1); rec(dep.item.get(), cur_order + 1, rec); } it->order = cur_order; tsort_mark(it, tsort_mask::PERM); }; /* * Topological sort */ total_hits = 0; auto used_items = ord->d.size(); for (const auto &it: ord->d) { if (it->order == 0) { tsort_visit(it.get(), 0, tsort_visit); } } /* Main sorting comparator */ constexpr auto score_functor = [](auto w, auto f, auto t) -> auto { auto time_alpha = 1.0, weight_alpha = 0.1, freq_alpha = 0.01; return ((w > 0.0 ? w : weight_alpha) * (f > 0.0 ? f : freq_alpha) / (t > time_alpha ? t : time_alpha)); }; auto cache_order_cmp = [&](const auto &it1, const auto &it2) -> auto { auto o1 = tsort_unmask(it1.get()), o2 = tsort_unmask(it2.get()); double w1 = 0., w2 = 0.; if (o1 == o2) { /* No topological order */ if (it1->priority == it2->priority) { auto avg_freq = ((double) total_hits / used_items); auto avg_weight = (total_weight / used_items); auto f1 = (double) it1->st->total_hits / avg_freq; auto f2 = (double) it2->st->total_hits / avg_freq; auto weight1 = std::fabs(it1->st->weight) / avg_weight; auto weight2 = std::fabs(it2->st->weight) / avg_weight; auto t1 = it1->st->avg_time; auto t2 = it2->st->avg_time; w1 = score_functor(weight1, f1, t1); w2 = score_functor(weight2, f2, t2); } else { /* Strict sorting */ w1 = std::abs(it1->priority); w2 = std::abs(it2->priority); } } else { w1 = o1; w2 = o2; } if (w2 > w1) { return 1; } else if (w2 < w1) { return -1; } return 0; }; std::stable_sort(std::begin(ord->d), std::end(ord->d), cache_order_cmp); /* * Here lives some ugly legacy! * We have several filters classes, connfilters, prefilters, filters... etc * * Our order is meaningful merely for filters, but we have to add other classes * to understand if those symbols are checked or disabled. * We can disable symbols for almost everything but not for virtual symbols. * The rule of thumb is that if a symbol has explicit parent, then it is a * virtual symbol that follows it's special rules */ /* * We enrich ord with all other symbol types without any sorting, * as it is done in another place */ constexpr auto append_items_vec = [](const auto &vec, auto &out) { for (const auto &it: vec) { if (it) { out.emplace_back(it); } } }; append_items_vec(connfilters, ord->d); append_items_vec(prefilters, ord->d); append_items_vec(postfilters, ord->d); append_items_vec(idempotent, ord->d); append_items_vec(composites, ord->d); append_items_vec(classifiers, ord->d); /* After sorting is done, we can assign all elements in the by_symbol hash */ for (auto i = 0; i < ord->size(); i++) { const auto &it = ord->d[i]; ord->by_symbol[it->get_name()] = i; ord->by_cache_id[it->id] = i; } /* Finally set the current order */ std::swap(ord, items_by_order); } auto symcache::add_symbol_with_callback(std::string_view name, int priority, symbol_func_t func, void *user_data, enum rspamd_symbol_type flags_and_type) -> int { auto real_type_pair_maybe = item_type_from_c(flags_and_type); if (!real_type_pair_maybe.has_value()) { msg_err_cache("incompatible flags when adding %s: %s", name.data(), real_type_pair_maybe.error().c_str()); return -1; } auto real_type_pair = real_type_pair_maybe.value(); if (real_type_pair.first != symcache_item_type::FILTER) { real_type_pair.second |= SYMBOL_TYPE_NOSTAT; } if (real_type_pair.second & (SYMBOL_TYPE_GHOST | SYMBOL_TYPE_CALLBACK)) { real_type_pair.second |= SYMBOL_TYPE_NOSTAT; } if (real_type_pair.first == symcache_item_type::VIRTUAL) { msg_err_cache("trying to add virtual symbol %s as real (no parent)", name.data()); return -1; } if ((real_type_pair.second & SYMBOL_TYPE_FINE) && priority == 0) { /* Adjust priority for negative weighted symbols */ priority = 1; } std::string static_string_name; if (name.empty()) { static_string_name = fmt::format("AUTO_{}", (void *) func); } else { static_string_name = name; } if (items_by_symbol.contains(static_string_name)) { msg_err_cache("duplicate symbol name: %s", static_string_name.data()); return -1; } auto id = items_by_id.size(); auto item = cache_item::create_with_function(static_pool, id, std::move(static_string_name), priority, func, user_data, real_type_pair.first, real_type_pair.second); items_by_symbol[item->get_name()] = item; get_item_specific_vector(*item).push_back(item); items_by_id.push_back(item); if (!(real_type_pair.second & SYMBOL_TYPE_NOSTAT)) { cksum = t1ha(name.data(), name.size(), cksum); stats_symbols_count++; } return id; } auto symcache::add_virtual_symbol(std::string_view name, int parent_id, enum rspamd_symbol_type flags_and_type) -> int { if (name.empty()) { msg_err_cache("cannot register a virtual symbol with no name; qed"); return -1; } auto real_type_pair_maybe = item_type_from_c(flags_and_type); if (!real_type_pair_maybe.has_value()) { msg_err_cache("incompatible flags when adding %s: %s", name.data(), real_type_pair_maybe.error().c_str()); return -1; } auto real_type_pair = real_type_pair_maybe.value(); if (items_by_symbol.contains(name)) { msg_err_cache("duplicate symbol name: %s", name.data()); return -1; } auto id = items_by_id.size(); auto item = cache_item::create_with_virtual(static_pool, id, std::string{name}, parent_id, real_type_pair.first, real_type_pair.second); items_by_symbol[item->get_name()] = item; get_item_specific_vector(*item).push_back(item); items_by_id.push_back(item); return id; } auto symcache::set_peak_cb(int cbref) -> void { if (peak_cb != -1) { luaL_unref(L, LUA_REGISTRYINDEX, peak_cb); } peak_cb = cbref; msg_info_cache("registered peak callback"); } auto symcache::add_delayed_condition(std::string_view sym, int cbref) -> void { delayed_conditions->emplace_back(sym, cbref, (lua_State *) cfg->lua_state); } auto symcache::validate(bool strict) -> bool { total_weight = 1.0; for (auto &pair: items_by_symbol) { auto &item = pair.second; auto ghost = item->st->weight == 0 ? true : false; auto skipped = !ghost; if (item->is_scoreable() && g_hash_table_lookup(cfg->symbols, item->symbol.c_str()) == nullptr) { if (!std::isnan(cfg->unknown_weight)) { item->st->weight = cfg->unknown_weight; auto *s = rspamd_mempool_alloc0_type(static_pool, struct rspamd_symbol); /* Legit as we actually never modify this data */ s->name = (char *) item->symbol.c_str(); s->weight_ptr = &item->st->weight; g_hash_table_insert(cfg->symbols, (void *) s->name, (void *) s); msg_info_cache ("adding unknown symbol %s with weight: %.2f", item->symbol.c_str(), cfg->unknown_weight); ghost = false; skipped = false; } else { skipped = true; } } else { skipped = false; } if (!ghost && skipped) { if (!(item->flags & SYMBOL_TYPE_SKIPPED)) { item->flags |= SYMBOL_TYPE_SKIPPED; msg_warn_cache("symbol %s has no score registered, skip its check", item->symbol.c_str()); } } if (ghost) { msg_debug_cache ("symbol %s is registered as ghost symbol, it won't be inserted " "to any metric", item->symbol.c_str()); } if (item->st->weight < 0 && item->priority == 0) { item->priority++; } if (item->is_virtual()) { if (!(item->flags & SYMBOL_TYPE_GHOST)) { auto *parent = const_cast<cache_item *>(item->get_parent(*this)); if (parent == nullptr) { item->resolve_parent(*this); parent = const_cast<cache_item *>(item->get_parent(*this)); } if (::fabs(parent->st->weight) < ::fabs(item->st->weight)) { parent->st->weight = item->st->weight; } auto p1 = ::abs(item->priority); auto p2 = ::abs(parent->priority); if (p1 != p2) { parent->priority = MAX(p1, p2); item->priority = parent->priority; } } } total_weight += fabs(item->st->weight); } /* Now check each metric item and find corresponding symbol in a cache */ auto ret = true; GHashTableIter it; void *k, *v; g_hash_table_iter_init(&it, cfg->symbols); while (g_hash_table_iter_next(&it, &k, &v)) { auto ignore_symbol = false; auto sym_def = (struct rspamd_symbol *) v; if (sym_def && (sym_def->flags & (RSPAMD_SYMBOL_FLAG_IGNORE_METRIC | RSPAMD_SYMBOL_FLAG_DISABLED))) { ignore_symbol = true; } if (!ignore_symbol) { if (!items_by_symbol.contains((const char *) k)) { msg_warn_cache ( "symbol '%s' has its score defined but there is no " "corresponding rule registered", k); if (strict) { ret = FALSE; } } } else if (sym_def->flags & RSPAMD_SYMBOL_FLAG_DISABLED) { auto item = get_item_by_name_mut((const char *) k, false); if (item) { item->enabled = FALSE; } } } return ret; } auto symcache::counters() const -> ucl_object_t * { auto *top = ucl_object_typed_new(UCL_ARRAY); constexpr const auto round_float = [](const auto x, const int digits) -> auto { const auto power10 = ::pow(10, digits); return (::floor(x * power10) / power10); }; for (auto &pair: items_by_symbol) { auto &item = pair.second; auto symbol = pair.first; auto *obj = ucl_object_typed_new(UCL_OBJECT); ucl_object_insert_key(obj, ucl_object_fromlstring(symbol.data(), symbol.size()), "symbol", 0, false); if (item->is_virtual()) { if (!(item->flags & SYMBOL_TYPE_GHOST)) { const auto *parent = item->get_parent(*this); ucl_object_insert_key(obj, ucl_object_fromdouble(round_float(item->st->weight, 3)), "weight", 0, false); ucl_object_insert_key(obj, ucl_object_fromdouble(round_float(parent->st->avg_frequency, 3)), "frequency", 0, false); ucl_object_insert_key(obj, ucl_object_fromint(parent->st->total_hits), "hits", 0, false); ucl_object_insert_key(obj, ucl_object_fromdouble(round_float(parent->st->avg_time, 3)), "time", 0, false); } else { ucl_object_insert_key(obj, ucl_object_fromdouble(round_float(item->st->weight, 3)), "weight", 0, false); ucl_object_insert_key(obj, ucl_object_fromdouble(0.0), "frequency", 0, false); ucl_object_insert_key(obj, ucl_object_fromdouble(0.0), "hits", 0, false); ucl_object_insert_key(obj, ucl_object_fromdouble(0.0), "time", 0, false); } } else { ucl_object_insert_key(obj, ucl_object_fromdouble(round_float(item->st->weight, 3)), "weight", 0, false); ucl_object_insert_key(obj, ucl_object_fromdouble(round_float(item->st->avg_frequency, 3)), "frequency", 0, false); ucl_object_insert_key(obj, ucl_object_fromint(item->st->total_hits), "hits", 0, false); ucl_object_insert_key(obj, ucl_object_fromdouble(round_float(item->st->avg_time, 3)), "time", 0, false); } ucl_array_append(top, obj); } return top; } auto symcache::periodic_resort(struct ev_loop *ev_loop, double cur_time, double last_resort) -> void { for (const auto &item: filters) { if (item->update_counters_check_peak(L, ev_loop, cur_time, last_resort)) { auto cur_value = (item->st->total_hits - item->last_count) / (cur_time - last_resort); auto cur_err = (item->st->avg_frequency - cur_value); cur_err *= cur_err; msg_debug_cache ("peak found for %s is %.2f, avg: %.2f, " "stddev: %.2f, error: %.2f, peaks: %d", item->symbol.c_str(), cur_value, item->st->avg_frequency, item->st->stddev_frequency, cur_err, item->frequency_peaks); if (peak_cb != -1) { struct ev_loop **pbase; lua_rawgeti(L, LUA_REGISTRYINDEX, peak_cb); pbase = (struct ev_loop **) lua_newuserdata(L, sizeof(*pbase)); *pbase = ev_loop; rspamd_lua_setclass(L, "rspamd{ev_base}", -1); lua_pushlstring(L, item->symbol.c_str(), item->symbol.size()); lua_pushnumber(L, item->st->avg_frequency); lua_pushnumber(L, ::sqrt(item->st->stddev_frequency)); lua_pushnumber(L, cur_value); lua_pushnumber(L, cur_err); if (lua_pcall(L, 6, 0, 0) != 0) { msg_info_cache ("call to peak function for %s failed: %s", item->symbol.c_str(), lua_tostring(L, -1)); lua_pop (L, 1); } } } } } symcache::~symcache() { if (peak_cb != -1) { luaL_unref(L, LUA_REGISTRYINDEX, peak_cb); } } auto symcache::maybe_resort() -> bool { if (items_by_order->generation_id != cur_order_gen) { /* * Cache has been modified, need to resort it */ msg_info_cache("symbols cache has been modified since last check:" " old id: %ud, new id: %ud", items_by_order->generation_id, cur_order_gen); resort(); return true; } return false; } auto symcache::get_item_specific_vector(const cache_item &it) -> symcache::items_ptr_vec & { switch (it.get_type()) { case symcache_item_type::CONNFILTER: return connfilters; case symcache_item_type::FILTER: return filters; case symcache_item_type::IDEMPOTENT: return idempotent; case symcache_item_type::PREFILTER: return prefilters; case symcache_item_type::POSTFILTER: return postfilters; case symcache_item_type::COMPOSITE: return composites; case symcache_item_type::CLASSIFIER: return classifiers; case symcache_item_type::VIRTUAL: return virtual_symbols; } RSPAMD_UNREACHABLE; } auto symcache::process_settings_elt(struct rspamd_config_settings_elt *elt) -> void { auto id = elt->id; if (elt->symbols_disabled) { /* Process denied symbols */ ucl_object_iter_t iter = nullptr; const ucl_object_t *cur; while ((cur = ucl_object_iterate(elt->symbols_disabled, &iter, true)) != NULL) { const auto *sym = ucl_object_key(cur); auto *item = get_item_by_name_mut(sym, false); if (item != nullptr) { if (item->is_virtual()) { /* * Virtual symbols are special: * we ignore them in symcache but prevent them from being * inserted. */ item->forbidden_ids.add_id(id, static_pool); msg_debug_cache("deny virtual symbol %s for settings %ud (%s); " "parent can still be executed", sym, id, elt->name); } else { /* Normal symbol, disable it */ item->forbidden_ids.add_id(id, static_pool); msg_debug_cache ("deny symbol %s for settings %ud (%s)", sym, id, elt->name); } } else { msg_warn_cache ("cannot find a symbol to disable %s " "when processing settings %ud (%s)", sym, id, elt->name); } } } if (elt->symbols_enabled) { ucl_object_iter_t iter = nullptr; const ucl_object_t *cur; while ((cur = ucl_object_iterate (elt->symbols_enabled, &iter, true)) != nullptr) { /* Here, we resolve parent and explicitly allow it */ const auto *sym = ucl_object_key(cur); auto *item = get_item_by_name_mut(sym, false); if (item != nullptr) { if (item->is_virtual()) { if (!(item->flags & SYMBOL_TYPE_GHOST)) { auto *parent = get_item_by_name_mut(sym, true); if (parent) { if (elt->symbols_disabled && ucl_object_lookup(elt->symbols_disabled, parent->symbol.data())) { msg_err_cache ("conflict in %s: cannot enable disabled symbol %s, " "wanted to enable symbol %s", elt->name, parent->symbol.data(), sym); continue; } parent->exec_only_ids.add_id(id, static_pool); msg_debug_cache ("allow just execution of symbol %s for settings %ud (%s)", parent->symbol.data(), id, elt->name); } } /* Ignore ghosts */ } item->allowed_ids.add_id(id, static_pool); msg_debug_cache ("allow execution of symbol %s for settings %ud (%s)", sym, id, elt->name); } else { msg_warn_cache ("cannot find a symbol to enable %s " "when processing settings %ud (%s)", sym, id, elt->name); } } } } }
26.779868
118
0.661503
msuslu
ab1b8301418a0b1b6cbae42c16a3be59a6e4bb84
5,425
cc
C++
Project2/core/utils/process_utils.cc
AndrewSpano/Systems-Programming
a26834072a324a1e0e251afa8c799bc937291e42
[ "MIT" ]
2
2021-08-05T19:10:27.000Z
2021-08-06T14:51:50.000Z
Project2/core/utils/process_utils.cc
AndrewSpano/Systems-Programming
a26834072a324a1e0e251afa8c799bc937291e42
[ "MIT" ]
null
null
null
Project2/core/utils/process_utils.cc
AndrewSpano/Systems-Programming
a26834072a324a1e0e251afa8c799bc937291e42
[ "MIT" ]
null
null
null
#include <cstring> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <poll.h> #include <dirent.h> #include <csignal> #include "../../include/utils/process_utils.hpp" #include "../../include/utils/parsing.hpp" void process_utils::travel_monitor::_create_pipe(char** named_pipe, const char* type, const size_t & id) { *named_pipe = new char[40]; sprintf(*named_pipe, "pipes/%s_%lu", type, id); if (mkfifo(*named_pipe, 0666) < 0) { perror("mkfifo() failed in process_utils::_create_pipe()"); exit(-1); } } void process_utils::travel_monitor::create_pipes(structures::CommunicationPipes* pipes, const uint16_t & num_monitors) { for (size_t i = 0; i < num_monitors; i++) { _create_pipe(&pipes[i].input, "input", i); _create_pipe(&pipes[i].output, "output", i); } } void process_utils::travel_monitor::_free_and_delete_pipe(const char* named_pipe) { if (unlink(named_pipe) < 0) { perror("unlink() failed in process_utils::_free_and_delete_pipe()"); exit(-1); } delete[] named_pipe; } void process_utils::travel_monitor::free_and_delete_pipes(structures::CommunicationPipes* pipes, const uint16_t & num_monitors) { for (size_t i = 0; i < num_monitors; i++) { _free_and_delete_pipe(pipes[i].input); _free_and_delete_pipe(pipes[i].output); } } void process_utils::travel_monitor::open_all_pipes(const structures::CommunicationPipes* pipes, int comm_fds[], const mode_t & input_perms, int data_fds[], const mode_t & output_perms, const uint16_t & num_monitors) { for (size_t i = 0; i < num_monitors; i++) { comm_fds[i] = open(pipes[i].input, input_perms); data_fds[i] = open(pipes[i].output, output_perms); } } void process_utils::travel_monitor::close_all_pipes(const int comm_fds[], const int data_fds[], const uint16_t & num_monitors) { for (size_t i = 0; i < num_monitors; i++) { close(comm_fds[i]); close(data_fds[i]); } } void process_utils::travel_monitor::_create_monitor(pid_t monitor_pids[], structures::CommunicationPipes* pipes, const size_t & position) { monitor_pids[position] = fork(); if (monitor_pids[position] < 0) { perror("fork() failed in process_utils::_create_monitor()"); exit(-1); } else if (monitor_pids[position] == 0) { const char* const argv[] = {"bin/Monitor", "-i", pipes[position].output, "-o", pipes[position].input, NULL}; execvp(argv[0], const_cast<char* const*>(argv)); perror("execvp() failed in process_utils::create_monitors()"); exit(-1); } } void process_utils::travel_monitor::create_monitors(pid_t monitor_pids[], structures::CommunicationPipes* pipes, const u_int16_t & num_monitors) { for (size_t i = 0; i < num_monitors; i++) process_utils::travel_monitor::_create_monitor(monitor_pids, pipes, i); } void process_utils::travel_monitor::kill_minitors_and_wait(pid_t monitor_pids[], travelMonitorIndex* tm_index) { size_t active_monitors = (tm_index->input->num_monitors <= tm_index->num_countries) ? tm_index->input->num_monitors : tm_index->num_countries; tm_index->has_sent_sigkill = true; for (size_t i = 0; i < active_monitors; i++) kill(monitor_pids[i], SIGKILL); int returnStatus; while (wait(&returnStatus) > 0); } void process_utils::travel_monitor::cleanup(travelMonitorIndex* tm_index, structures::CommunicationPipes* pipes, pid_t* monitor_pids) { process_utils::travel_monitor::free_and_delete_pipes(pipes, tm_index->input->num_monitors); delete[] monitor_pids; delete[] pipes; delete tm_index; } int process_utils::travel_monitor::ready_fd(struct pollfd fdarr[], size_t num_fds) { for (size_t i = 0; i < num_fds; i++) if (fdarr[i].revents == POLLIN || fdarr[i].revents == (POLLIN | POLLHUP)) return i; return -1; } int process_utils::travel_monitor::dead_monitor(pid_t* monitor_pids, const pid_t & terminated_process, const size_t & num_monitors) { for (size_t i = 0; i < num_monitors; i++) if (monitor_pids[i] == terminated_process) return i; return -1; } void process_utils::monitor::parse_countries(MonitorIndex* m_index, const std::string & root_dir, ErrorHandler & handler) { for (size_t country_id = 0; country_id < m_index->num_countries; country_id++) { std::string* country = &(m_index->countries[country_id]); char country_dir_path[256] = {0}; sprintf(country_dir_path, "%s/%s", root_dir.c_str(), country->c_str()); struct dirent **namelist; int num_files = scandir(country_dir_path, &namelist, NULL, alphasort); for (size_t i = 0; i < num_files; i++) { if (strcmp(namelist[i]->d_name, ".") && strcmp(namelist[i]->d_name, "..")) { std::string* filename = new std::string(namelist[i]->d_name); char path[256]; sprintf(path, "%s/%s", country_dir_path, filename->c_str()); parsing::dataset::parse_country_dataset(country, path, m_index, handler); m_index->files_per_country[country_id]->insert(filename); } free(namelist[i]); } free(namelist); } }
31.178161
146
0.646267
AndrewSpano
ab1dc4e6454038b4ccff155e208246910064f794
574
cpp
C++
Lab4/Integrals/Integrals/PolynomialThirdDegree.cpp
ladaegorova18/CalculationMethods
7b1967cbaf0d6d6a8e744e99160f41138d40fe52
[ "Apache-2.0" ]
1
2021-09-01T20:24:35.000Z
2021-09-01T20:24:35.000Z
Lab4/Integrals/Integrals/PolynomialThirdDegree.cpp
ladaegorova18/CalculationMethods
7b1967cbaf0d6d6a8e744e99160f41138d40fe52
[ "Apache-2.0" ]
null
null
null
Lab4/Integrals/Integrals/PolynomialThirdDegree.cpp
ladaegorova18/CalculationMethods
7b1967cbaf0d6d6a8e744e99160f41138d40fe52
[ "Apache-2.0" ]
null
null
null
#include "PolynomialThirdDegree.h" #include <cmath> double PolynomialThirdDegree::func(double x) { return pow(x, 3) * (-17) + 0.3 * pow(x, 2) - x + 5; } double PolynomialThirdDegree::integral(double x) { return pow(x, 4) * (-4.25) + pow(x, 3) * 0.1 - pow(x, 2) / 2 + 5 * x; } double PolynomialThirdDegree::derivative(double x) { return -54 * pow(x, 2) + 0.6 * x - 1; } double PolynomialThirdDegree::sndDerivative(double x) { return -108 * x + 0.6; } double PolynomialThirdDegree::fourthDerivative(double x) { return 0.0; }
21.259259
75
0.609756
ladaegorova18
ab1e8e2ac93fd1c6f85770db9e0c6fde10217450
27,604
hh
C++
dune/fem/oseen/modeldefault.hh
renemilk/DUNE-FEM-Oseen
2cc2a1a70f81469f13a2330be285960a13f78fdf
[ "BSD-2-Clause" ]
null
null
null
dune/fem/oseen/modeldefault.hh
renemilk/DUNE-FEM-Oseen
2cc2a1a70f81469f13a2330be285960a13f78fdf
[ "BSD-2-Clause" ]
null
null
null
dune/fem/oseen/modeldefault.hh
renemilk/DUNE-FEM-Oseen
2cc2a1a70f81469f13a2330be285960a13f78fdf
[ "BSD-2-Clause" ]
null
null
null
#ifndef MODELDEFAULT_HH #define MODELDEFAULT_HH #include <dune/common/fvector.hh> #include <dune/fem/function/adaptivefunction/adaptivefunction.hh> #include <dune/fem/space/dgspace.hh> #include <dune/fem/oseen/functionspacewrapper.hh> #include <dune/fem/oseen/boundaryinfo.hh> #include <dune/fem/oseen/stab_coeff.hh> #ifndef NLOG #include <dune/stuff/common/print.hh> #include <dune/stuff/common/logging.hh> #endif #include <dune/stuff/common/misc.hh> #include <algorithm> // include this file after all other includes because some of them might undef // the macros we want to use #include <dune/common/bartonnackmanifcheck.hh> #include "modelinterface.hh" namespace Dune { /** * \brief A default implementation of a discrete stokes model. * * Implements the fluxes needed for the LDG method * (see Dune::DiscreteOseenModelInterface for details).\n * The fluxes \f$\hat{u}_{\sigma}\f$, \f$\hat{\sigma}\f$, * \f$\hat{p}\f$ and \f$\hat{u}_{p}\f$ are implemented as proposed in * B. Cockburn, G. Kanschat, D. Schötzau, C. Schwab: <EM>Local * Discontinuous Galerkin Methodsfor the Stokes System</EM> (2000).\n\n * To use this model, a user has to implement the analytical force * \f$f\f$ and the dirichlet data \f$g_{D}\f$ as a Dune::Fem::Function * (only the method evaluate( arg, ret ) is needed) and specify the * types of this functions as template arguments for the traits class * DiscreteOseenModelDefaultTraits.\n * * <b>Notation:</b> Given simplices \f$T_{+}\f$ and * \f$T_{-}\f$ and a face \f$\varepsilon\f$ between them, the values * of a function \f$u\f$ on the face \f$\varepsilon\f$ are denoted by \f$u^{+}\f$, * if seen from \f$T_{+}\f$ and \f$u^{-}\f$, if seen from \f$T_{-}\f$. * The outer normals of \f$T_{+,-}\f$ in a given point on * the face \f$\varepsilon\f$ are denoted by \f$n_{+,-}\f$, * accordingly.\n * * We define the <b>mean values</b>\n * - \f$\{\{p\}\}\in R\f$ for a \f$p\in R\f$ as * \f[ * \{\{p\}\}:=\frac{1}{2}\left(p^{+}+p^{-}\right), * \f] * - \f$\{\{u\}\}\in R^{d}\f$ for a \f$u\in R^{d}\f$ as * \f[ * \{\{u\}\}:=\frac{1}{2}\left(u^{+}+u^{-}\right), * \f] * - \f$\{\{\sigma\}\}\in R^{d\times d}\f$ for a \f$\sigma\in R^{d\times d}\f$ as * \f[ * \{\{\sigma\}\}:=\frac{1}{2}\left(\sigma^{+}+\sigma^{-}\right) * \f] * * and the <b>jumps</b>\n * - \f$\left[\left[p\right]\right]\in R^{d}\f$ for a \f$p\in R\f$ as * \f[ * \left[\left[p\right]\right]:=p^{+}n^{+}+p^{-}n^{-}, * \f] * - \f$\left[\left[u\right]\right]\in R\f$ for a \f$u\in R^{d}\f$ as * \f[ * \left[\left[u\right]\right]:=u^{+}\cdot n^{+}+u^{-}\cdot n^{-}, * \f] * - \f$\underline{\left[\left[u\right]\right]}\in R^{d\times d}\f$ for a \f$u\in R^{d}\f$ as * \f[ * \underline{\left[\left[u\right]\right]}:=u^{+}\otimes n^{+}+u^{-}\otimes n^{-}, * \f] * - \f$\left[\left[\sigma\right]\right]\in R^{d}\f$ for a \f$\sigma\in R^{d\times d}\f$ as * \f[ * \left[\left[\sigma\right]\right]:=\sigma^{+}\cdot n^{+}+\sigma^{-}\cdot n^{-}. * \f] * * We also denote by \f$\mathcal{E}_{D}\f$ the set of those faces * \f$\varepsilon\f$ that lie on the boundary \f$\partial\Omega\f$ and * by \f$\mathcal{E}_{I}\f$ those which are inside \f$\Omega\f$.\n * For a detailed definition of this notation see B. Cockburn, G. Kanschat, D. Schötzau, C. Schwab: <EM>Local * Discontinuous Galerkin Methodsfor the Stokes System</EM> (2000), again.\n * * <b>Attention:</b> For reasons of simplicity the assumtion \f$n^{-}=-1\cdot n^{+}\f$ is used. * This may be not true for nonconforming grids.\n * * With this notation at hand the fluxes can de described as * - \f$\hat{u}_{\sigma}:\Omega\rightarrow R^{d}\f$ for an inner face * \f[ * \hat{u}_{\sigma}(u):=\{\{u\}\}-\underline{\left[\left[u\right]\right]}\cdot C_{12}\quad\quad\varepsilon\in\mathcal{E}_{I}, * \f] * - \f$\hat{u}_{\sigma}:\Omega\rightarrow R^{d}\f$ for a boundary face * \f[ * \hat{u}_{\sigma}(u):=g_{D}\quad\quad\varepsilon\in\mathcal{E}_{D}, * \f] * - \f$\hat{\sigma}:\Omega\rightarrow R^{d\times d}\f$ for an inner face * \f[ * \hat{\sigma}(u,\sigma):=\{\{\sigma\}\}-C_{11}\underline{\left[\left[u\right]\right]}-\left[\left[\sigma\right]\right]\otimes C_{12}\quad\quad\varepsilon\in\mathcal{E}_{I}, * \f] * - \f$\hat{\sigma}:\Omega\rightarrow R^{d\times d}\f$ for a boundary face * \f[ * \hat{\sigma}(u,\sigma):=\sigma^{+}-C_{11}\left(u^{+}-g_{D}\right)\otimes n^{+}\quad\quad\varepsilon\in\mathcal{E}_{D}, * \f] * - \f$\hat{p}:\Omega\rightarrow R\f$ for an inner face * \f[ * \hat{p}(p):=\{\{p\}\}-D_{12}\left[\left[p\right]\right]\quad\quad\varepsilon\in\mathcal{E}_{I}, * \f] * - \f$\hat{p}:\Omega\rightarrow R\f$ for a boundary face * \f[ * \hat{p}(p):=p^{+}\quad\quad\varepsilon\in\mathcal{E}_{D}, * \f] * - \f$\hat{u}_{p}:\Omega\rightarrow R^{d}\f$ for an inner face * \f[ * \hat{u}_{p}(u,p):=\{\{u\}\}+D_{11}\left[\left[p\right]\right]+D_{12}\left[\left[u\right]\right]\quad\quad\varepsilon\in\mathcal{E}_{I}, * \f] * - \f$\hat{u}_{p}:\Omega\rightarrow R^{d}\f$ for a boundary face * \f[ * \hat{u}_{p}(u,p):=g_{D}\quad\quad\varepsilon\in\mathcal{E}_{D}, * \f] * * where \f$C_{11},\;\;D_{11}\in R\f$ are the stability coefficients * and \f$C_{12},\;\;D_{12}\in R^{d}\f$ are the coefficients * concerning efficiency and accuracy.\n * * These fluxes are then decomposed into several numerical fluxes (see * Dune::DiscreteOseenModelInterface for details):\n * * \f {tabular} {l||l} * on $\mathcal{E}_{I}$ & on $\mathcal{E}_{I}$ \\ * \hline\hline * $\boldsymbol{\hat{u}_{\sigma}^{U^{+}}(u)} := \frac{1}{2} u + \left( u \otimes n^{+} \right) \cdot C_{12}$ * & $\boldsymbol{\hat{u}_{\sigma}^{U^{+}}(u)} := 0$ \\ * $\boldsymbol{\hat{u}_{\sigma}^{U^{-}}(u)} := \frac{1}{2} u + \left( u \otimes n^{-} \right) \cdot C_{12}$ * & $\boldsymbol{\hat{u}_{\sigma}^{RHS}} := g_{D}$ \\ * \hline * $\boldsymbol{\hat{u}_{p}^{U^{+}}(u)} := \frac{1}{2} u + D_{12} u \cdot n^{+}$ * & $\boldsymbol{\hat{u}_{p}^{U^{+}}(u)} := 0$ \\ * $\boldsymbol{\hat{u}_{p}^{U^{-}}(u)} := \frac{1}{2} u + D_{12} u \cdot n^{-}$ * & $\quad$ \\ * $\boldsymbol{\hat{u}_{p}^{P^{+}}(p)} := D_{11} p n^{+}$ * & $\boldsymbol{\hat{u}_{p}^{P^{+}}(p)} := 0$ \\ * $\boldsymbol{\hat{u}_{p}^{P^{-}}(p)} := D_{11} p n^{-}$ * & $\boldsymbol{\hat{u}_{p}^{RHS}} := g_{D}$\\ * \hline * $\boldsymbol{\hat{p}^{P^{+}}(p)} := \frac{1}{2} p - p D_{12} \cdot n^{+}$ * & $\boldsymbol{\hat{p}^{P^{+}}(p)} := p$ \\ * $\boldsymbol{\hat{p}^{P^{-}}(p)} := \frac{1}{2} p - p D_{12} \cdot n^{-}$ * & $\boldsymbol{\hat{p}^{RHS}} := 0$ \\ * \hline * $\boldsymbol{\hat{\sigma}^{U^{+}}(u)} := -C_{11} u \otimes n^{+}$ * & $\boldsymbol{\hat{\sigma}^{U^{+}}(u)} := -C_{11} u \otimes n^{+}$ \\ * $\boldsymbol{\hat{\sigma}^{U^{-}}(u)} := -C_{11} u \otimes n^{-}$ * & $\quad$ \\ * $\boldsymbol{\hat{\sigma}^{\sigma^{+}}(u)} := \frac{1}{2} \sigma - \left( \sigma \cdot n^{+} \right)$ * & $\boldsymbol{\hat{\sigma}^{\sigma^{+}}(u)} := \sigma$ \\ * $\boldsymbol{\hat{\sigma}^{\sigma^{-}}(u)} := \frac{1}{2} \sigma - \left( \sigma \cdot n^{-} \right)$ * & $\boldsymbol{\hat{\sigma}^{RHS}} := -C_{11} g_{D} \otimes n^{+}$ * \f} * * The implementation is as follows:\n * * - \f$\hat{u}_{\sigma}(u):\Omega\rightarrow R^{d}\f$\n * - for inner faces * - \f$\hat{u}_{\sigma}^{U^{+}}\f$ and * \f$\hat{u}_{\sigma}^{U^{-}}\f$ are implemented in * velocitySigmaFlux() (const IntersectionIteratorType& it, const * double time, const FaceDomainType& x, const Side side, const * VelocityRangeType& u, VelocityRangeType& uReturn), where * <b>side</b> determines, whether \f$\hat{u}_{\sigma}^{U^{+}}\f$ * (side=inside) or \f$\hat{u}_{\sigma}^{U^{-}}\f$ * (side=outside) is returned * - for faces on the boundary of \f$\Omega\f$ * - \f$\hat{u}_{\sigma}^{U^{+}}\f$ is implemented in * velocitySigmaBoundaryFlux() ( const IntersectionIteratorType& * it, const double time, const FaceDomainType& x, * const VelocityRangeType& <b>u</b>, VelocityRangeType& * <b>uReturn</b> ) * - \f$\hat{u}_{\sigma}^{RHS}\f$ is implemented in * velocitySigmaBoundaryFlux() ( const IntersectionIteratorType& * it, const double time, const FaceDomainType& x, * VelocityRangeType& <b>rhsReturn</b> ) * - \f$\hat{u}_{p}(u,p):\Omega\rightarrow R^{d}\f$\n * - for inner faces * - \f$\hat{u}_{p}^{U^{+}}\f$ and \f$\hat{u}_{p}^{U^{-}}\f$ are * implemented in velocityPressureFlux() ( const * IntersectionIteratorType& it, const double time, const * FaceDomainType& x, const Side side, const VelocityRangeType& * <b>u</b>, VelocityRangeType& <b>uReturn</b> ), where * <b>side</b> determines, whether \f$\hat{u}_{p}^{U^{+}}\f$ * (side=inside) or \f$\hat{u}_{p}^{U^{-}}\f$ * (side=outside) is returned * - \f$\hat{u}_{p}^{P^{+}}\f$ and \f$\hat{u}_{p}^{P^{+}}\f$ are * implemented by velocityPressureFlux() ( const * IntersectionIteratorType& it, const double time, const * FaceDomainType& x, const Side side, const PressureRangeType& * <b>p</b>, VelocityRangeType& <b>pReturn</b> ), where * <b>side</b> determines, whether \f$\hat{u}_{p}^{P^{+}}\f$ * (side=inside) or \f$\hat{u}_{p}^{P^{+}}\f$ * (side=outside) is returned * - for faces on the boundary of \f$\Omega\f$ * - \f$\hat{u}_{p}^{U^{+}}\f$ is implemented in * velocityPressureBoundaryFlux() ( const * IntersectionIteratorType& it, const double time, const * FaceDomainType& x, const VelocityRangeType& <b>u</b>, * VelocityRangeType& <b>uReturn</b> ) * - \f$\hat{u}_{p}^{P^{+}}\f$ is implemented in * velocityPressureBoundaryFlux() ( const * IntersectionIteratorType& it, const double time, const * FaceDomainType& x, const PressureRangeType& <b>p</b>, * VelocityRangeType& <b>pReturn</b> ) * - \f$\hat{u}_{p}^{RHS}\f$ is implemented in * velocityPressureBoundaryFlux() ( const * IntersectionIteratorType& it, const double time, const * FaceDomainType& x, VelocityRangeType& <b>rhsReturn</b> ) * - \f$\hat{p}(p):\Omega\rightarrow R\f$\n * - for inner faces * - \f$\hat{p}^{P^{+}}\f$ and \f$\hat{p}^{P^{-}}\f$ are * implemented in pressureFlux() ( const * IntersectionIteratorType& it, const double time, const * FaceDomainType& x, const Side side, const PressureRangeType& * p, PressureRangeType& pReturn ), where * <b>side</b> determines, whether \f$\hat{p}^{P^{+}}\f$ * (side=inside) or \f$\hat{p}^{P^{-}}\f$ * (side=outside) is returned * - for faces on the boundary of \f$\Omega\f$ * - \f$\hat{p}^{P^{+}}\f$ is implemented in pressureBoundaryFlux() ( * const IntersectionIteratorType& it, const double time, const * FaceDomainType& x, const PressureRangeType& <b>p</b>, * PressureRangeType& <b>pReturn</b> ) * - \f$\hat{p}^{RHS}\f$ is implemented in pressureBoundaryFlux() ( * const IntersectionIteratorType& it, const double time, const * FaceDomainType& x, PressureRangeType& <b>rhsReturn</b> ) * - \f$\hat{\sigma}(u,\sigma):\Omega\rightarrow R^{d\times d}\f$\n * - for inner faces * - \f$\hat{\sigma}^{U^{+}}\f$ and \f$\hat{\sigma}^{U^{-}}\f$ are * implemented in sigmaFlux() ( const IntersectionIteratorType& * it, const double time, const FaceDomainType& x, const Side * side, const VelocityRangeType& <b>u</b>, SigmaRangeType& * <b>uReturn</b> ), where * <b>side</b> determines, whether \f$\hat{\sigma}^{U^{+}}\f$ * (side=inside) or \f$\hat{\sigma}^{U^{-}}\f$ * (side=outside) is returned * - \f$\hat{\sigma}^{\sigma^{+}}\f$ and * \f$\hat{\sigma}^{\sigma^{-}}\f$ are implemented in sigmaFlux() * ( const IntersectionIteratorType& it, const double time, const * FaceDomainType& x, const Side side, const SigmaRangeType& * <b>sigma</b>, SigmaRangeType& <b>sigmaReturn</b> ), where * <b>side</b> determines, whether * \f$\hat{\sigma}^{\sigma^{+}}\f$ (side=inside) or * \f$\hat{\sigma}^{\sigma^{-}}\f$ (side=outside) is returned * - for faces on the boundary of \f$\Omega\f$ * - \f$\hat{\sigma}^{U^{+}}\f$ is implemented in * sigmaBoundaryFlux() ( const IntersectionIteratorType& it, * const double time, const FaceDomainType& x, const * VelocityRangeType& <b>u</b>, SigmaRangeType& <b>uReturn</b> ) * - \f$\hat{\sigma}^{\sigma^{+}}\f$ is implemented in * sigmaBoundaryFlux() ( const IntersectionIteratorType& it, * const double time, const FaceDomainType& x, const * SigmaRangeType& <b>sigma</b>, SigmaRangeType& * <b>sigmaReturn</b> ) * - \f$\hat{\sigma}^{RHS}\f$ is implemented in sigmaBoundaryFlux() * ( const IntersectionIteratorType& it, const double time, const * FaceDomainType& x, SigmaRangeType& <b>rhsReturn</b> ) **/ template < class DiscreteOseenModelTraitsImp > class DiscreteOseenModelDefault : public DiscreteOseenModelInterface< DiscreteOseenModelTraitsImp > { private: //! interface class typedef DiscreteOseenModelInterface< DiscreteOseenModelTraitsImp > BaseType; //! \copydoc Dune::DiscreteOseenModelInterface::IntersectionIteratorType typedef typename BaseType::IntersectionIteratorType IntersectionIteratorType; public: //! \copydoc Dune::DiscreteOseenModelInterface::VolumeQuadratureType typedef typename BaseType::VolumeQuadratureType VolumeQuadratureType; //! \copydoc Dune::DiscreteOseenModelInterface::FaceQuadratureType typedef typename BaseType::FaceQuadratureType FaceQuadratureType; //! \copydoc Dune::DiscreteOseenModelInterface::DiscreteOseenFunctionSpaceWrapperType typedef typename BaseType::DiscreteOseenFunctionSpaceWrapperType DiscreteOseenFunctionSpaceWrapperType; //! \copydoc Dune::DiscreteOseenModelInterface::DiscreteOseenFunctionSpaceWrapperType typedef typename BaseType::DiscreteOseenFunctionWrapperType DiscreteOseenFunctionWrapperType; //! \copydoc Dune::DiscreteOseenModelInterface::DiscreteSigmaFunctionType typedef typename BaseType::DiscreteSigmaFunctionType DiscreteSigmaFunctionType; //! \copydoc Dune::DiscreteOseenModelInterface::sigmaSpaceOrder static const int sigmaSpaceOrder = BaseType::sigmaSpaceOrder; //! \copydoc Dune::DiscreteOseenModelInterface::velocitySpaceOrder static const int velocitySpaceOrder = BaseType::velocitySpaceOrder; //! \copydoc Dune::DiscreteOseenModelInterface::pressureSpaceOrder static const int pressureSpaceOrder = BaseType::pressureSpaceOrder; //! type of analytical force (usually Dune::Fem::Function) typedef typename BaseType::AnalyticalForceType AnalyticalForceType; private: //! Vector type of the velocity's discrete function space's range typedef typename BaseType::VelocityRangeType VelocityRangeType; //! Matrix type of the sigma's discrete function space's range typedef typename BaseType::SigmaRangeType SigmaRangeType; //! Vector type of the pressure's discrete function space's range typedef typename BaseType::PressureRangeType PressureRangeType; //! type of analytical dirichlet data (usually Dune::Fem::Function) typedef typename BaseType::AnalyticalDirichletDataType AnalyticalDirichletDataType; public: //! \copydoc Dune::DiscreteOseenModelInterface::Side typedef enum BaseType::Side Side; /** * \brief constructor * * sets the coefficients and analytical data * \param[in] C_11 * \f$C_{11}\in R\f$ * \param[in] C_12 * \f$C_{12}\in R^{d}\f$ * \param[in] D_11 * \f$D_{11}\in R\f$ * \param[in] D_12 * \f$D_{12}\in R^{d}\f$ * \param[in] force * analytical force * \param[in] dirichletData * analytical dirichlet data * \param[in] viscosity * viscosity of the fluid **/ DiscreteOseenModelDefault( const StabilizationCoefficients stab_coeff_in, const AnalyticalForceType force_in, const AnalyticalDirichletDataType dirichletData_in, const double viscosity_in = 1.0, const double alpha_in = 0.0, const double convection_scaling_in = 1.0, const double pressure_gradient_scaling_in = 1.0 ) : viscosity_( viscosity_in ), alpha_( alpha_in ), convection_scaling_( convection_scaling_in ), pressure_gradient_scaling_( pressure_gradient_scaling_in ), stabil_coeff_( stab_coeff_in ), force_( force_in ), dirichletData_( dirichletData_in ) { // if ( !isGeneralized() ) { // if ( ( alpha_ < 0.0 ) || ( alpha_ > 0.0 ) ) { // assert( !"isGeneralized() returns false, but alpha is not zero!" ); // } // } } /** * \brief destructor * * does nothing **/ virtual ~DiscreteOseenModelDefault() {} const StabilizationCoefficients& getStabilizationCoefficients() const { return stabil_coeff_; } /** * \brief returns true * * since problem has a \f$\hat{u}_{\sigma}\f$ contribution * \return true **/ bool hasVelocitySigmaFlux() const { return true; } /** * \brief returns true * * since problem has a \f$\hat{u}_{p}\f$ contribution * \return true **/ bool hasVelocityPressureFlux() const { return true; } /** * \brief returns true * * since problem has a \f$\hat{p}\f$ contribution * \return true **/ bool hasPressureFlux() const { return true; } /** * \brief returns true * * since problem has a \f$\hat{\sigma}\f$ contribution * \return true **/ bool hasSigmaFlux() const { return true; } /** * \brief returns true * * since problem has a \f$f\f$ contribution * \return true **/ bool hasForce() const { return true; } /** * \brief Implementation of \f$f\f$. * * Evaluates the analytical force given by the constructor * * \tparam DomainType * domain type in entity (codim 0) * \param[in] time * global time * \param[in] x * point to evaluate at (in world coordinates) * \param[out] forceReturn * value of \f$f\f$ in \f$x\f$ **/ template < class DomainType > void force( const double /*time*/, const DomainType& x, VelocityRangeType& forceReturn ) const { force_.evaluate( x, forceReturn ); } template < class IntersectionType, class DomainType > void dirichletData( const IntersectionType& intIt, const double /*time*/, const DomainType& x, VelocityRangeType& dirichletDataReturn ) const { assert( ( !intIt.neighbor() && intIt.boundary() ) || !"this intersection does not lie on the boundary" ); dirichletData_.evaluate( x, dirichletDataReturn, intIt ); } /** * \brief Returns the viscosity \f$\mu\f$ of the fluid. * \return \f$\mu\f$ **/ double viscosity() const { return viscosity_; } /** * \brief constant for generalized stokes * * \todo doc **/ double alpha() const { return alpha_; } bool isGeneralized() const { return false; } //! ZAF double convection_scaling() const { return convection_scaling_; } //! ZAF double pressure_gradient_scaling() const { return pressure_gradient_scaling_; } const AnalyticalForceType& forceF() const { return force_; } private: const double viscosity_; const double alpha_; const double convection_scaling_; const double pressure_gradient_scaling_; StabilizationCoefficients stabil_coeff_; const AnalyticalForceType force_; const AnalyticalDirichletDataType dirichletData_; /** * \brief dyadic product * * Implements \f$\left(arg_{1} \otimes arg_{2}\right)_{i,j}:={arg_{1}}_{i} {arg_{2}}_{j}\f$ **/ SigmaRangeType dyadicProduct( const VelocityRangeType& arg1, const VelocityRangeType& arg2 ) const { SigmaRangeType ret( 0.0 ); typedef typename SigmaRangeType::RowIterator MatrixRowIteratorType; typedef typename VelocityRangeType::ConstIterator ConstVectorIteratorType; typedef typename VelocityRangeType::Iterator VectorIteratorType; MatrixRowIteratorType rItEnd = ret.end(); ConstVectorIteratorType arg1It = arg1.begin(); for ( MatrixRowIteratorType rIt = ret.begin(); rIt != rItEnd; ++rIt ) { ConstVectorIteratorType arg2It = arg2.begin(); VectorIteratorType vItEnd = rIt->end(); for ( VectorIteratorType vIt = rIt->begin(); vIt != vItEnd; ++vIt ) { *vIt = *arg1It * *arg2It; ++arg2It; } ++arg1It; } } //! avoid code duplication by doing calculations for C_1X and D_1X here template < class LocalPoint > double getStabScalar( const LocalPoint& /*x*/ , const IntersectionIteratorType& it, const std::string coeffName ) const { const StabilizationCoefficients::PowerType power = stabil_coeff_.Power ( coeffName ); const StabilizationCoefficients::FactorType factor = stabil_coeff_.Factor ( coeffName ); if ( power == StabilizationCoefficients::invalid_power ) { return 0.0; } // return std::pow( it.geometry().integrationElement( x ), param ); return factor * std::pow( getLenghtOfIntersection( *it ), power ); } }; } // end of namespace Dune /** Copyright (c) 2012, Felix Albrecht, Rene Milk * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation are those * of the authors and should not be interpreted as representing official policies, * either expressed or implied, of the FreeBSD Project. **/ #endif // MODELDEFAULT_HH
45.104575
191
0.528438
renemilk
ab20485e646e88acf9173125f322bcfdf5889021
1,228
cpp
C++
src/Shaders/SunShader.cpp
jaafersheriff/Clouds
00de0a33f6e6fe43c3287de5cba9228c70693110
[ "MIT" ]
6
2019-06-30T20:20:52.000Z
2022-01-07T06:31:18.000Z
src/Shaders/SunShader.cpp
jaafersheriff/Clouds
00de0a33f6e6fe43c3287de5cba9228c70693110
[ "MIT" ]
null
null
null
src/Shaders/SunShader.cpp
jaafersheriff/Clouds
00de0a33f6e6fe43c3287de5cba9228c70693110
[ "MIT" ]
3
2020-10-08T16:37:07.000Z
2022-01-07T06:31:22.000Z
#include "SunShader.hpp" #include "Sun.hpp" #include "Camera.hpp" #include "Library.hpp" void SunShader::render() { /* Bind shader */ bind(); /* Bind sun params */ loadVector(getUniform("center"), Sun::position); loadVector(getUniform("innerColor"), Sun::innerColor); loadFloat(getUniform("innerRadius"), Sun::innerRadius); loadVector(getUniform("outerColor"), Sun::outerColor); loadFloat(getUniform("outerRadius"), Sun::outerRadius); /* Bind projeciton, view, inverse view matrices */ loadMatrix(getUniform("P"), &Camera::getP()); loadMatrix(getUniform("V"), &Camera::getV()); glm::mat4 Vi = Camera::getV(); Vi[3][0] = Vi[3][1] = Vi[3][2] = 0.f; Vi = glm::transpose(Vi); loadMatrix(getUniform("Vi"), &Vi); /* Bind mesh */ /* VAO */ CHECK_GL_CALL(glBindVertexArray(Library::quad->vaoId)); /* M */ glm::mat4 M = glm::mat4(1.f); M *= glm::translate(glm::mat4(1.f), Sun::position); M *= glm::scale(glm::mat4(1.f), glm::vec3(Sun::outerRadius)); loadMatrix(getUniform("M"), &M); /* Draw */ CHECK_GL_CALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); /* Clean up */ CHECK_GL_CALL(glBindVertexArray(0)); unbind(); }
27.909091
65
0.614821
jaafersheriff
ab21554e50c831173b7ce7242a133a06b6c51146
2,438
cpp
C++
Sample/Sample_WebSocketSvr/timer/TimerMgr.cpp
sherry0319/YTSvrLib
5dda75aba927c4bf5c6a727592660bfc2619a063
[ "MIT" ]
61
2016-10-13T09:24:31.000Z
2022-03-26T09:59:34.000Z
Sample/Sample_WebSocketSvr/timer/TimerMgr.cpp
sherry0319/YTSvrLib
5dda75aba927c4bf5c6a727592660bfc2619a063
[ "MIT" ]
3
2018-05-15T10:42:22.000Z
2021-07-02T01:38:08.000Z
Sample/Sample_WebSocketSvr/timer/TimerMgr.cpp
sherry0319/YTSvrLib
5dda75aba927c4bf5c6a727592660bfc2619a063
[ "MIT" ]
36
2016-12-28T04:54:41.000Z
2021-12-15T06:02:56.000Z
#include "stdafx.h" #include "TimerMgr.h" void CTimerMgr::SetEvent() { YTSvrLib::CServerApplication::GetInstance()->SetEvent(EAppEvent::eAppTimerMgrOnTimer); } CTimerMgr::CTimerMgr(void) { m_tNow = time32(); SYSTEMTIME st; GetLocalTime(&st); m_nToday = st.wYear * 10000 + st.wMonth * 100 + st.wDay; m_wCurday = st.wDay; m_wCurHour = st.wHour; m_wCurDayOfWeek = st.wDayOfWeek; st.wHour = 0; st.wMinute = 0; st.wSecond = 0; st.wMilliseconds = 0; m_tTodayZero = SystemTimeToTime_t(&st); m_tTimeZone = GetLocalTimeZone(); m_nTomorrow = CalcTomorrowYYYYMMDD(); m_tNextHour = (m_tNow / 3600 + 1) * 3600; m_tNext5Minute = (m_tNow / 300 + 1) * 300; m_tNext10Minute = (m_tNow / 600 + 1) * 600; m_tNextLegion10Minute = m_tNow + 600; m_tNextMinute = (m_tNow / 60 + 1) * 60; m_tNext15Minute = m_tNow + 900; m_tNext30Sec = m_tNow + 30; m_tNext10Sec = m_tNow + 10; LOG("TM_Init Now=%d TodayZero=%d LocalTimeZoneSeconds=%d", m_tNow, m_tTodayZero, m_tTimeZone); } CTimerMgr::~CTimerMgr(void) { } void CTimerMgr::OnTimerCheckQueue() { m_tNow = time32(); CheckTimer((DOUBLE) m_tNow); if (m_tNow >= m_tNext10Sec) { CServerParser::GetInstance()->CheckSvrSocket(); m_tNext10Sec += 10; char szTitle[127] = { 0 }; _snprintf_s(szTitle, 127, "WSGatewaySvr=P[%d] L[%d] Online Client=%d ...", CConfig::GetInstance()->m_nPublicSvrID, CConfig::GetInstance()->m_nLocalSvrID, CPkgParser::GetInstance()->GetCurClientCount()); SetConsoleTitleA(szTitle); } if (m_tNow >= m_tNextMinute) { m_tNextMinute += 60; if (m_tNow >= m_tNext5Minute) { m_tNext5Minute += 300; } if (m_tNow >= m_tNext10Minute) { SYSTEMTIME st; GetLocalTime(&st); if (m_tNow >= m_tNextHour) { if (st.wHour != m_wCurHour) { m_wCurHour = st.wHour; if (st.wDay != m_wCurday) { m_wCurday = st.wDay; m_wCurDayOfWeek = st.wDayOfWeek; m_nToday = st.wYear * 10000 + st.wMonth * 100 + st.wDay; m_nTomorrow = CalcTomorrowYYYYMMDD(); } ReOpenLogFile(); LOG("Timer New Day=%d Hour=%d", m_wCurday, m_wCurHour); } m_tNextHour += 3600; ArrangeTimer(); }//if( tNow >= m_tNextHour ) m_tNext10Minute += 600; } //if( tNow >= m_tNext10Minute ) CPkgParser::GetInstance()->CheckIdleSocket(m_tNow); }//if( m_tNow >= m_tNextMinute ) } void CTimerMgr::OnTimer(YTSvrLib::LPSTimerInfo pTimer) { } DOUBLE CTimerMgr::GetNearTime() { return (DOUBLE) m_tNextHour; }
23.669903
204
0.669811
sherry0319
ab27843e229041bce81786310cdefe9370255e88
2,065
cc
C++
components/sync/engine/attachments/fake_attachment_uploader_unittest.cc
metux/chromium-deb
3c08e9b89a1b6f95f103a61ff4f528dbcd57fc42
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
null
null
null
components/sync/engine/attachments/fake_attachment_uploader_unittest.cc
metux/chromium-deb
3c08e9b89a1b6f95f103a61ff4f528dbcd57fc42
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
null
null
null
components/sync/engine/attachments/fake_attachment_uploader_unittest.cc
metux/chromium-deb
3c08e9b89a1b6f95f103a61ff4f528dbcd57fc42
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
null
null
null
// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "components/sync/engine/attachments/fake_attachment_uploader.h" #include "base/bind.h" #include "base/memory/ref_counted.h" #include "base/memory/ref_counted_memory.h" #include "base/message_loop/message_loop.h" #include "base/run_loop.h" #include "components/sync/model/attachments/attachment.h" #include "testing/gtest/include/gtest/gtest.h" namespace syncer { namespace { const char kAttachmentData[] = "some data"; } // namespace class FakeAttachmentUploaderTest : public testing::Test { protected: void SetUp() override { upload_callback_count = 0; upload_callback = base::Bind(&FakeAttachmentUploaderTest::Increment, base::Unretained(this), &upload_callback_count); } base::MessageLoop message_loop; FakeAttachmentUploader uploader; int upload_callback_count; AttachmentUploader::UploadCallback upload_callback; private: void Increment(int* success_count, const AttachmentUploader::UploadResult& result, const AttachmentId& ignored) { if (result == AttachmentUploader::UPLOAD_SUCCESS) { ++(*success_count); } } }; // Call upload attachment several times, see that the supplied callback is // invoked the same number of times with a result of SUCCESS. TEST_F(FakeAttachmentUploaderTest, UploadAttachment) { scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString); some_data->data() = kAttachmentData; Attachment attachment1 = Attachment::Create(some_data); Attachment attachment2 = Attachment::Create(some_data); Attachment attachment3 = Attachment::Create(some_data); uploader.UploadAttachment(attachment1, upload_callback); uploader.UploadAttachment(attachment2, upload_callback); uploader.UploadAttachment(attachment3, upload_callback); base::RunLoop().RunUntilIdle(); EXPECT_EQ(upload_callback_count, 3); } } // namespace syncer
33.306452
78
0.753027
metux
ab28d35b02607fcbbed2179e99d9c1e8ed5f9d3a
3,160
cpp
C++
code/utils/xrDXT/tga.cpp
Rikoshet-234/xray-oxygen
eaac3fa4780639152684f3251b8b4452abb8e439
[ "Apache-2.0" ]
7
2018-03-27T12:36:07.000Z
2020-06-26T11:31:52.000Z
code/utils/xrDXT/tga.cpp
Rikoshet-234/xray-oxygen
eaac3fa4780639152684f3251b8b4452abb8e439
[ "Apache-2.0" ]
2
2018-05-26T23:17:14.000Z
2019-04-14T18:33:27.000Z
code/utils/xrDXT/tga.cpp
Rikoshet-234/xray-oxygen
eaac3fa4780639152684f3251b8b4452abb8e439
[ "Apache-2.0" ]
5
2020-10-18T11:55:26.000Z
2022-03-28T07:21:35.000Z
// file: targasaver.cpp #include "stdafx.h" #pragma hdrstop #include "tga.h" void tga_save(LPCSTR name, u32 w, u32 h, void* data, BOOL alpha) { TGAdesc tga; tga.data = data; tga.format = alpha ? IMG_32B : IMG_24B; tga.height = h; tga.width = w; tga.scanlength = w * 4; int hf = _open(name, O_CREAT | O_WRONLY | O_BINARY, S_IREAD | S_IWRITE); tga.maketga(hf); _close(hf); } void TGAdesc::maketga(IWriter& fs) { R_ASSERT(data); R_ASSERT(width); R_ASSERT(height); tgaHeader hdr = {0}; hdr.tgaImgType = 2; hdr.tgaImgSpec.tgaXSize = u16(width); hdr.tgaImgSpec.tgaYSize = u16(height); if (format == IMG_24B) { hdr.tgaImgSpec.tgaDepth = 24; hdr.tgaImgSpec.tgaImgDesc = 32; // flip } else { hdr.tgaImgSpec.tgaDepth = 32; hdr.tgaImgSpec.tgaImgDesc = 0x0f | 32; // flip } fs.w(&hdr, sizeof(hdr)); if (format == IMG_24B) { BYTE ab_buffer[4] = { 0, 0, 0, 0 }; int real_sl = ((width * 3)) & 3; int ab_size = real_sl ? 4 - real_sl : 0; for (int j = 0; j<height; j++) { BYTE *p = (LPBYTE)data + scanlength*j; for (int i = 0; i < width; i++) { BYTE buffer[3] = { p[0], p[1], p[2] }; fs.w(buffer, 3); p += 4; } if (ab_size) { fs.w(ab_buffer, ab_size); } } } else { if (width * 4 == scanlength) { fs.w(data, width*height * 4); } else { // bad pitch, it seems :( for (int j = 0; j < height; j++) { BYTE *p = (LPBYTE)data + scanlength*j; for (int i = 0; i < width; i++) { BYTE buffer[4] = { p[0], p[1], p[2], p[3] }; fs.w(buffer, 4); p += 4; } } } } } void TGAdesc::maketga(int hf) { R_ASSERT(data); R_ASSERT(width); R_ASSERT(height); tgaHeader hdr = {0}; hdr.tgaImgType = 2; hdr.tgaImgSpec.tgaXSize = u16(width); hdr.tgaImgSpec.tgaYSize = u16(height); if (format == IMG_24B) { hdr.tgaImgSpec.tgaDepth = 24; hdr.tgaImgSpec.tgaImgDesc = 32; // flip } else { hdr.tgaImgSpec.tgaDepth = 32; hdr.tgaImgSpec.tgaImgDesc = 0x0f | 32; // flip } _write(hf, &hdr, sizeof(hdr)); if (format == IMG_24B) { BYTE ab_buffer[4] = { 0, 0, 0, 0 }; int real_sl = ((width * 3)) & 3; int ab_size = real_sl ? 4 - real_sl : 0; for (int j = 0; j < height; j++) { BYTE* p = (LPBYTE)data + scanlength*j; for (int i = 0; i < width; i++) { BYTE buffer[3] = { p[0], p[1], p[2] }; _write(hf, buffer, 3); p += 4; } if (ab_size) { _write(hf, ab_buffer, ab_size); } } } else { _write(hf, data, width*height * 4); } }
24.6875
76
0.446835
Rikoshet-234
ab2a947c4fe40048966908ab4adeff4b8919ae28
1,370
cpp
C++
Implementations/12 - Graphs Hard (4)/12.4 - Tarjan BCC.cpp
wangdongx/USACO
b920acd85e1d1e633333b14b424026a4dfe42234
[ "MIT" ]
null
null
null
Implementations/12 - Graphs Hard (4)/12.4 - Tarjan BCC.cpp
wangdongx/USACO
b920acd85e1d1e633333b14b424026a4dfe42234
[ "MIT" ]
null
null
null
Implementations/12 - Graphs Hard (4)/12.4 - Tarjan BCC.cpp
wangdongx/USACO
b920acd85e1d1e633333b14b424026a4dfe42234
[ "MIT" ]
null
null
null
/** * Description: computes biconnected components * Source: GeeksForGeeks (corrected) * Verification: USACO December 2017, Push a Box * https://pastebin.com/yUWuzTH8 */ template<int SZ> struct BCC { int N; vpi adj[SZ], ed; void addEdge(int u, int v) { adj[u].pb({v,sz(ed)}), adj[v].pb({u,sz(ed)}); ed.pb({u,v}); } int ti = 0, disc[SZ]; vi st; vector<vi> fin; int bcc(int u, int p = -1) { // return lowest disc disc[u] = ++ti; int low = disc[u]; int child = 0; trav(i,adj[u]) if (i.s != p) if (!disc[i.f]) { child ++; st.pb(i.s); int LOW = bcc(i.f,i.s); ckmin(low,LOW); // disc[u] < LOW -> bridge if (disc[u] <= LOW) { // if (p != -1 || child > 1) -> u is articulation point vi tmp; while (st.back() != i.s) tmp.pb(st.back()), st.pop_back(); tmp.pb(st.back()), st.pop_back(); fin.pb(tmp); } } else if (disc[i.f] < disc[u]) { ckmin(low,disc[i.f]); st.pb(i.s); } return low; } void init(int _N) { N = _N; FOR(i,1,N+1) disc[i] = 0; FOR(i,1,N+1) if (!disc[i]) bcc(i); // st should be empty after each iteration } };
29.148936
86
0.439416
wangdongx
ab2d34a412149658399468c2f7aae2a8c7815f5f
926
cpp
C++
3641/7910679_AC_16MS_144K.cpp
vandreas19/POJ_sol
4895764ab800e8c2c4b2334a562dec2f07fa243e
[ "MIT" ]
18
2017-08-14T07:34:42.000Z
2022-01-29T14:20:29.000Z
3641/7910679_AC_16MS_144K.cpp
pinepara/poj_solutions
4895764ab800e8c2c4b2334a562dec2f07fa243e
[ "MIT" ]
null
null
null
3641/7910679_AC_16MS_144K.cpp
pinepara/poj_solutions
4895764ab800e8c2c4b2334a562dec2f07fa243e
[ "MIT" ]
14
2016-12-21T23:37:22.000Z
2021-07-24T09:38:57.000Z
#define _CRT_SECURE_NO_WARNINGS #include<cstdio> int powMod(int base,int exp,int mod){ __int64 powRemainder[32],pos=0,remainder=1; for(int pos=0;exp;pos++){ if(pos==0) powRemainder[pos]=base%mod; else powRemainder[pos]=(powRemainder[pos-1]*powRemainder[pos-1])%mod; if(exp&1) remainder=(remainder*powRemainder[pos])%mod; exp>>=1; } return (int)remainder; } bool isPrime(int n){ int primes[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; for(int i=0;i<25 && primes[i]<n;i++){ int a=powMod(primes[i],n-1,n); if(a!=1) return false; } return true; } bool isPseudoprime(int base,int exp){ if(powMod(base,exp,exp)!=base%exp) return false; return !isPrime(exp); } int main(){ int exp,base; while(true){ scanf("%d%d",&exp,&base); if(!exp && !base) return 0; printf(isPseudoprime(base,exp)?"yes\n":"no\n"); } }
21.534884
90
0.62095
vandreas19
ab2de24b4d3597ccc2b3ed3814f695e7fa7a0315
9,051
cpp
C++
OpenGL/src/Layers/Implementation/AdvancedLayer.cpp
scooper/OpenGL
605bc9210013e27df320de8b6bdc10522d09142d
[ "Apache-2.0" ]
null
null
null
OpenGL/src/Layers/Implementation/AdvancedLayer.cpp
scooper/OpenGL
605bc9210013e27df320de8b6bdc10522d09142d
[ "Apache-2.0" ]
null
null
null
OpenGL/src/Layers/Implementation/AdvancedLayer.cpp
scooper/OpenGL
605bc9210013e27df320de8b6bdc10522d09142d
[ "Apache-2.0" ]
null
null
null
#include "AdvancedLayer.h" #include "Util/Logger.h" #include <string> #include <imgui.h> float AdvancedLayer::m_CubeVertices[] = { // positions // texture coords -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.5f, 1.0f, 0.0f, -0.5f, 0.5f, -0.5f, 1.0f, 1.0f, -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, -0.5f, 0.5f, -0.5f, 0.0f, 1.0f }; float AdvancedLayer::m_QuadVertices[] = { // positions // texCoords -1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f }; AdvancedLayer::AdvancedLayer(GLFWwindow* window) : Layer(window, "Advanced OpenGL") { } AdvancedLayer::~AdvancedLayer() { } void AdvancedLayer::OnActivate() { m_FrameShader = new Shader("D:/Projects/OpenGL/OpenGL/res/Advanced/FramebufferShaders/framebuffer_vs.glsl", "D:/Projects/OpenGL/OpenGL/res/Advanced/FramebufferShaders/framebuffer_fs.glsl"); m_ScreenShader = new Shader("D:/Projects/OpenGL/OpenGL/res/Advanced/FramebufferShaders/screen_vs.glsl", "D:/Projects/OpenGL/OpenGL/res/Advanced/FramebufferShaders/screen_fs.glsl"); int width, height; glfwGetWindowSize(m_Window, &width, &height); m_Camera = new FlyCamera(ProjectionParameters{ width, height, CameraProjection::PERSPECTIVE }, glm::vec3(0.0f, 0.0f, 3.0f)); m_LastX = width / 2; m_LastY = height / 2; m_Container = Texture::Create(GL_TEXTURE_2D, "D:/Projects/OpenGL/OpenGL/res/LightingTutorial/container-diffuse-map.png", true); // VBO unsigned int VBO; glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(m_CubeVertices), m_CubeVertices, GL_STATIC_DRAW); // container/box glGenVertexArrays(1, &m_BoxVAO); glBindVertexArray(m_BoxVAO); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float))); glEnableVertexAttribArray(1); // screen quad unsigned int quadVBO; glGenVertexArrays(1, &m_QuadVAO); glGenBuffers(1, &quadVBO); glBindVertexArray(m_QuadVAO); glBindBuffer(GL_ARRAY_BUFFER, quadVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(m_QuadVertices), &m_QuadVertices, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float))); // framebuffer glGenFramebuffers(1, &m_FBO); glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); glGenTextures(1, &m_texColourBufferRBO); glBindTexture(GL_TEXTURE_2D, m_texColourBufferRBO); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texColourBufferRBO, 0); glGenRenderbuffers(1, &m_depthStencilRBO); glBindRenderbuffer(GL_RENDERBUFFER, m_depthStencilRBO); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilRBO); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) LOG_ERROR("Framebuffer is not complete"); // TODO: complete the framebuffers tutorial } void AdvancedLayer::OnDeactivate() { glDeleteVertexArrays(1, &m_BoxVAO); glDeleteFramebuffers(1, &m_FBO); delete m_ScreenShader; delete m_FrameShader; delete m_Camera; Shader::Reset(); glBindVertexArray(0); glBindFramebuffer(GL_FRAMEBUFFER, 0); } void AdvancedLayer::OnMouseEvent(double xpos, double ypos) { if (m_MouseMode) { float xoffset = xpos - m_LastX; float yoffset = m_LastY - ypos; // reversed since y-coordinates go from bottom to top m_Camera->MouseInput(xoffset, yoffset); } m_LastX = xpos; m_LastY = ypos; } void AdvancedLayer::OnWindowResize(int width, int height) { // resize framebuffer texture buffer and render buffer object (stencil and depth) glBindRenderbuffer(GL_RENDERBUFFER, m_depthStencilRBO); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); glBindTexture(GL_TEXTURE_2D, m_texColourBufferRBO); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); // update projection matrix m_Camera->UpdateProjectionMatrix(width, height); } void AdvancedLayer::ProcessKeyEvent() { // mouse mode on or off if (glfwGetMouseButton(m_Window, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS) { m_MouseMode = true; glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); } if (glfwGetKey(m_Window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { m_MouseMode = false; glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } if (glfwGetKey(m_Window, GLFW_KEY_W) == GLFW_PRESS) m_Camera->KeyInput(TranslateDirection::FORWARDS, m_DeltaTime); if (glfwGetKey(m_Window, GLFW_KEY_S) == GLFW_PRESS) m_Camera->KeyInput(TranslateDirection::BACKWARDS, m_DeltaTime); if (glfwGetKey(m_Window, GLFW_KEY_A) == GLFW_PRESS) m_Camera->KeyInput(TranslateDirection::LEFT, m_DeltaTime); if (glfwGetKey(m_Window, GLFW_KEY_D) == GLFW_PRESS) m_Camera->KeyInput(TranslateDirection::RIGHT, m_DeltaTime); } void AdvancedLayer::Update(float deltaTime) { m_DeltaTime = deltaTime; ProcessKeyEvent(); glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); glEnable(GL_DEPTH_TEST); glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_FrameShader->Use(); Texture::Activate(0); glm::mat4 model = glm::mat4(1.0f); glm::mat4 vp = m_Camera->GetViewProjectionMatrix(); glm::mat4 mvp = vp * model; m_FrameShader->SetUniform<glm::mat4&>("mvp", mvp); glBindVertexArray(m_BoxVAO); Texture::Bind(m_Container); glDrawArrays(GL_TRIANGLES, 0, 36); glBindFramebuffer(GL_FRAMEBUFFER, 0); glDisable(GL_DEPTH_TEST); // clear all relevant buffers glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); m_ScreenShader->Use(); for(int i = 0; i < 9; i++) { auto index = std::to_string(i); m_ScreenShader->SetUniform("kernel[" + index + "]", m_Kernel[i]); }; m_ScreenShader->SetUniform("greyscale", m_Greyscale); glBindVertexArray(m_QuadVAO); glBindTexture(GL_TEXTURE_2D, m_texColourBufferRBO); glDrawArrays(GL_TRIANGLES, 0, 6); } void AdvancedLayer::ImGuiDisplay() { ImGui::Text("Kernel Array"); ImGui::Columns(3, NULL); ImGui::Separator(); // kernel controls float* ptr = &m_Kernel[0]; for (int i = 0; i < m_Kernel.size(); i++) { // we want the kernel to be displayed from left to right if (i != 0) ImGui::NextColumn(); ImGui::InputFloat(("i=" + std::to_string(i)).c_str(), ptr, 0.1f, 0.5f, "%.1f"); ptr++; } ImGui::Separator(); ImGui::Columns(1); ImGui::Text("Preset Kernels"); ImGui::NewLine(); ImGui::SameLine(); // buttons to load a preset kernel that demonstrates some concept if (ImGui::Button("Edge Kernel")) m_Kernel = Kernel_Edge; ImGui::SameLine(); if (ImGui::Button("Blur Kernel")) m_Kernel = Kernel_Blur; ImGui::Separator(); ImGui::Text("Options"); ImGui::Checkbox("Greyscale", &m_Greyscale); }
31.427083
131
0.644459
scooper
ab2f04f03e6344cf0d37c1baef64b27216010a03
2,629
cpp
C++
cpp/04/ex03/MateriaSource.cpp
maxdesalle/libft
8845656e1f5cc1fec052cf97fc8f5839b2b590a8
[ "Unlicense" ]
3
2021-01-06T13:50:12.000Z
2022-02-28T09:16:15.000Z
cpp/04/ex03/MateriaSource.cpp
maxdesalle/libft
8845656e1f5cc1fec052cf97fc8f5839b2b590a8
[ "Unlicense" ]
null
null
null
cpp/04/ex03/MateriaSource.cpp
maxdesalle/libft
8845656e1f5cc1fec052cf97fc8f5839b2b590a8
[ "Unlicense" ]
1
2020-11-23T12:58:18.000Z
2020-11-23T12:58:18.000Z
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* MateriaSource.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maxdesalle <mdesalle@student.s19.be> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/18 17:31:46 by maxdesall #+# #+# */ /* Updated: 2021/10/18 19:46:09 by maxdesall ### ########.fr */ /* */ /* ************************************************************************** */ #include "MateriaSource.hpp" MateriaSource::MateriaSource(void) { int i; for (i = 0; i < 4; i += 1) _inventory[i] = nullptr; std::cout << "MateriaSource was constructed!"; std::cout << std::endl; } MateriaSource::~MateriaSource(void) { int i; for (i = 0; i < 4; i += 1) { if (_inventory[i]) delete _inventory[i]; } std::cout << "MateriaSource was destructed!"; std::cout << std::endl; } MateriaSource::MateriaSource(MateriaSource const &ref) { int i; for (i = 0; i < 4; i += 1) { if (ref._inventory[i]) _inventory[i] = ref._inventory[i]->clone(); } std::cout << "MateriaSource was copy constructed!"; std::cout << std::endl; } MateriaSource &MateriaSource::operator=(MateriaSource const &ref) { int i; for (i = 0; i < 4; i += 1) { if (_inventory[i]) delete _inventory[i]; if (ref._inventory[i]) _inventory[i] = ref._inventory[i]->clone(); } return (*this); } void MateriaSource::learnMateria(AMateria *m) { int i; for (i = 0; _inventory[i] != nullptr && i < 4; i += 1) {} if (i == 4) { std::cout << "Nope, you can't learn more than 4 Materia"; std::cout << std::endl; return ; } _inventory[i] = m; std::cout << m->getType() << " learned something!"; std::cout << std::endl; } AMateria *MateriaSource::createMateria(std::string const &type) { int i; int indicator; indicator = 0; for (i = 0; _inventory[i] != nullptr && i < 4; i += 1) { if (_inventory[i]->getType() == type) { std::cout << _inventory[i]->getType() << " was created!"; std::cout << std::endl; indicator = 1; break ; } } if (indicator == 1) return (_inventory[i])->clone(); else { std::cout << type << " is unknown!"; std::cout << std::endl; return (nullptr); } }
24.570093
80
0.435527
maxdesalle
ab2f502ac0c07ce17c4542ab792fb032089b2abd
8,339
cpp
C++
src/cache/node/node_manager.cpp
EmanuelHerrendorf/mapping-core
d28d85547e8ed08df37dad1da142594d3f07a366
[ "MIT" ]
null
null
null
src/cache/node/node_manager.cpp
EmanuelHerrendorf/mapping-core
d28d85547e8ed08df37dad1da142594d3f07a366
[ "MIT" ]
10
2018-03-02T13:58:32.000Z
2020-06-05T11:12:42.000Z
src/cache/node/node_manager.cpp
EmanuelHerrendorf/mapping-core
d28d85547e8ed08df37dad1da142594d3f07a366
[ "MIT" ]
3
2018-02-26T14:01:43.000Z
2019-12-09T10:03:17.000Z
/* * util.cpp * * Created on: 03.12.2015 * Author: mika */ #include "cache/node/node_manager.h" #include "cache/node/manager/local_manager.h" #include "cache/node/manager/remote_manager.h" #include "cache/node/manager/hybrid_manager.h" #include "cache/node/puzzle_util.h" #include "cache/priv/connection.h" #include "datatypes/raster.h" #include "datatypes/pointcollection.h" #include "datatypes/linecollection.h" #include "datatypes/polygoncollection.h" #include "datatypes/plot.h" #include "util/log.h" //////////////////////////////////////////////////////////// // // ActiveQueryStats // //////////////////////////////////////////////////////////// void ActiveQueryStats::add_single_local_hit() { std::lock_guard<std::mutex> g(mtx); single_local_hits++; } void ActiveQueryStats::add_multi_local_hit() { std::lock_guard<std::mutex> g(mtx); multi_local_hits++; } void ActiveQueryStats::add_multi_local_partial() { std::lock_guard<std::mutex> g(mtx); multi_local_partials++; } void ActiveQueryStats::add_single_remote_hit() { std::lock_guard<std::mutex> g(mtx); single_remote_hits++; } void ActiveQueryStats::add_multi_remote_hit() { std::lock_guard<std::mutex> g(mtx); multi_remote_hits++; } void ActiveQueryStats::add_multi_remote_partial() { std::lock_guard<std::mutex> g(mtx); multi_remote_partials++; } void ActiveQueryStats::add_miss() { std::lock_guard<std::mutex> g(mtx); misses++; } void ActiveQueryStats::add_result_bytes(uint64_t bytes) { std::lock_guard<std::mutex> g(mtx); result_bytes+=bytes; } void ActiveQueryStats::add_lost_put() { std::lock_guard<std::mutex> g(mtx); lost_puts++; } QueryStats ActiveQueryStats::get() const { std::lock_guard<std::mutex> g(mtx); return QueryStats(*this); } void ActiveQueryStats::add_query(double ratio) { std::lock_guard<std::mutex> g(mtx); QueryStats::add_query(ratio); } QueryStats ActiveQueryStats::get_and_reset() { std::lock_guard<std::mutex> g(mtx); auto res = QueryStats(*this); reset(); return res; } //////////////////////////////////////////////////////////// // // WorkerContext // //////////////////////////////////////////////////////////// WorkerContext::WorkerContext() : puzzling(0), index_connection(nullptr) { } BlockingConnection& WorkerContext::get_index_connection() const { if ( index_connection == nullptr ) throw IllegalStateException("No index-connection configured for this thread"); return *index_connection; } void WorkerContext::set_index_connection(BlockingConnection *con) { index_connection = con; } //////////////////////////////////////////////////////////// // // NodeCacheWrapper // //////////////////////////////////////////////////////////// template<typename T> NodeCacheWrapper<T>::NodeCacheWrapper( NodeCacheManager &mgr, size_t size, CacheType type ) : mgr(mgr), cache(type,size) { } template<typename T> std::shared_ptr<const NodeCacheEntry<T>> NodeCacheWrapper<T>::get(const NodeCacheKey &key) const { Log::debug("Getting item from local cache. Key: %s", key.to_string().c_str()); return cache.get(key); } template<typename T> QueryStats NodeCacheWrapper<T>::get_and_reset_query_stats() { return stats.get_and_reset(); } template<typename T> CacheType NodeCacheWrapper<T>::get_type() const { return cache.type; } template<typename T> CacheCube NodeCacheWrapper<T>::get_bounds(const T& item, const QueryRectangle& rect) const { return CacheCube(item); } template<> CacheCube NodeCacheWrapper<GenericPlot>::get_bounds(const GenericPlot& item, const QueryRectangle& rect) const { return CacheCube(rect); } template<> CacheCube NodeCacheWrapper<ProvenanceCollection>::get_bounds(const ProvenanceCollection& item, const QueryRectangle& rect) const { return CacheCube(rect); } //////////////////////////////////////////////////////////// // // NodeCacheManager // //////////////////////////////////////////////////////////// thread_local WorkerContext NodeCacheManager::context; NodeCacheManager::NodeCacheManager( const std::string &strategy, std::unique_ptr<NodeCacheWrapper<GenericRaster>> raster_wrapper, std::unique_ptr<NodeCacheWrapper<PointCollection>> point_wrapper, std::unique_ptr<NodeCacheWrapper<LineCollection>> line_wrapper, std::unique_ptr<NodeCacheWrapper<PolygonCollection>> polygon_wrapper, std::unique_ptr<NodeCacheWrapper<GenericPlot>> plot_wrapper, std::unique_ptr<NodeCacheWrapper<ProvenanceCollection>> provenance_wrapper) : raster_wrapper( std::move(raster_wrapper) ), point_wrapper( std::move(point_wrapper) ), line_wrapper( std::move(line_wrapper) ), polygon_wrapper( std::move(polygon_wrapper) ), plot_wrapper( std::move(plot_wrapper) ), provenance_wrapper( std::move(provenance_wrapper) ), strategy( CachingStrategy::by_name(strategy)), my_port(0) { } NodeCacheWrapper<GenericRaster>& NodeCacheManager::get_raster_cache() { return *raster_wrapper; } NodeCacheWrapper<PointCollection>& NodeCacheManager::get_point_cache() { return *point_wrapper; } NodeCacheWrapper<LineCollection>& NodeCacheManager::get_line_cache() { return *line_wrapper; } NodeCacheWrapper<PolygonCollection>& NodeCacheManager::get_polygon_cache() { return *polygon_wrapper; } NodeCacheWrapper<GenericPlot>& NodeCacheManager::get_plot_cache() { return *plot_wrapper; } NodeCacheWrapper<ProvenanceCollection>& NodeCacheManager::get_provenance_cache() { return *provenance_wrapper; } std::unique_ptr<NodeCacheManager> NodeCacheManager::from_config( const NodeConfig &config ) { std::string mgrlc; mgrlc.resize(config.mgr_impl.size()); std::transform(config.mgr_impl.cbegin(),config.mgr_impl.cend(),mgrlc.begin(),::tolower); if ( mgrlc == "remote" ) return std::make_unique<RemoteCacheManager>(config.caching_strategy, config.raster_size, config.point_size, config.line_size, config.polygon_size, config.plot_size, config.provenance_size); else if ( mgrlc == "local" ) return std::make_unique<LocalCacheManager>(config.caching_strategy, config.local_replacement, config.raster_size, config.point_size, config.line_size, config.polygon_size, config.plot_size, config.provenance_size); else if ( mgrlc == "hybrid" ) return std::make_unique<HybridCacheManager>(config.caching_strategy, config.raster_size, config.point_size, config.line_size, config.polygon_size, config.plot_size, config.provenance_size); else throw ArgumentException(concat("Unknown manager impl: ", config.mgr_impl)); } void NodeCacheManager::set_self_port(uint32_t port) { my_port = port; } void NodeCacheManager::set_self_host(const std::string& host) { my_host = host; } NodeHandshake NodeCacheManager::create_handshake() const { std::vector<CacheHandshake> hs { raster_wrapper->cache.get_all(), point_wrapper->cache.get_all(), line_wrapper->cache.get_all(), polygon_wrapper->cache.get_all(), plot_wrapper->cache.get_all() }; return NodeHandshake(my_port, std::move(hs) ); } NodeStats NodeCacheManager::get_stats_delta() const { QueryStats qs; qs += raster_wrapper->get_and_reset_query_stats(); qs += point_wrapper->get_and_reset_query_stats(); qs += line_wrapper->get_and_reset_query_stats(); qs += polygon_wrapper->get_and_reset_query_stats(); qs += plot_wrapper->get_and_reset_query_stats(); cumulated_stats += qs; std::vector<CacheStats> stats { raster_wrapper->cache.get_stats(), point_wrapper->cache.get_stats(), line_wrapper->cache.get_stats(), polygon_wrapper->cache.get_stats(), plot_wrapper->cache.get_stats() }; return NodeStats( qs, std::move(stats) ); } QueryStats NodeCacheManager::get_cumulated_query_stats() const { return cumulated_stats; } WorkerContext& NodeCacheManager::get_worker_context() { return NodeCacheManager::context; } const CachingStrategy& NodeCacheManager::get_strategy() const { return *strategy; } template class NodeCacheWrapper<GenericRaster>; template class NodeCacheWrapper<PointCollection>; template class NodeCacheWrapper<LineCollection>; template class NodeCacheWrapper<PolygonCollection>; template class NodeCacheWrapper<GenericPlot> ; template class NodeCacheWrapper<ProvenanceCollection> ; bool WorkerContext::is_puzzling() const { return puzzling > 0; } int WorkerContext::get_puzzle_depth() const { return puzzling; } PuzzleGuard::PuzzleGuard(WorkerContext& ctx) : ctx(ctx) { ctx.puzzling++; } PuzzleGuard::~PuzzleGuard() { ctx.puzzling--; }
27.796667
216
0.725507
EmanuelHerrendorf
ab331fda242d58cf18c60d4a93da44cb915de399
13,487
hpp
C++
kernel/src/simulationTools/D1MinusLinearOSI.hpp
BuildJet/siconos
5e9c95806f0a01d62ab564ffb1d9d50c2dc32ef0
[ "Apache-2.0" ]
137
2015-06-16T15:55:28.000Z
2022-03-26T06:01:59.000Z
kernel/src/simulationTools/D1MinusLinearOSI.hpp
BuildJet/siconos
5e9c95806f0a01d62ab564ffb1d9d50c2dc32ef0
[ "Apache-2.0" ]
381
2015-09-22T15:31:08.000Z
2022-02-14T09:05:23.000Z
kernel/src/simulationTools/D1MinusLinearOSI.hpp
BuildJet/siconos
5e9c95806f0a01d62ab564ffb1d9d50c2dc32ef0
[ "Apache-2.0" ]
30
2015-08-06T22:57:51.000Z
2022-03-02T20:30:20.000Z
/* Siconos is a program dedicated to modeling, simulation and control * of non smooth dynamical systems. * * Copyright 2021 INRIA. * * 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. */ /*!\file * D1MinusLinearOSI Time-Integrator for Dynamical Systems * T. Schindler, V. Acary */ #ifndef D1MINUSLINEAR_H #define D1MINUSLINEAR_H #ifdef DEBUG_D1MINUSLINEAR //#define DEBUG_MESSAGES #endif #include "OneStepIntegrator.hpp" #include "SimpleMatrix.hpp" /** Time-Integrator for Dynamical Systems * * Reference: * * Timestepping schemes for nonsmooth dynamics based on discontinuous Galerkin methods: * Definition and outlook * Thorsten Schindler; Vincent Acary * Mathematics and Computers in Simulation, * Elsevier, 2014, 95, pp. 180-199 * * A D1MinusLinearOSI instance is defined by the list of concerned dynamical systems. * * Main functions: * * - computeFreeState(): computes xfree (or vfree), dynamical systems * state without taking non-smooth part into account \n * * - updateState(): computes x(q,v), the complete dynamical systems * states. * * * \section sec_D1MinusLinear_implementation Some details on the implementation * * \subsection sec_D1MinusLinear_implementation_various Various implementations at various levels. * * To be completed * * The (lower-case) lambda vector that corresponds to the (non-impulsive) contact forces are computed * for the closed contact with vanishing relative velocity (the number of the index set depends on the type of D1minulinear) * The result, stored in lambda(2) and p(2) is computed by solving * (*allOSNS)[SICONOS_OSNSP_TS_VELOCITY + 1] * at different specific time * * The impact equation are solved at the velocity level as in MoreauJeanOSI using * lambda(1) and p(1). The number of the index set depends on the type of D1minulinear * * * \subsection sec_D1MinusLinear_implementation_halfAcc HalfExplicitAccelerationLevel * * The (lower-case) lambda \f$\lambda\f$ that corresponds to the (non-impulsive) contact * forces are computed at the acceleration level for the closed contact with vanishing * relative velocity (indexSet2) * * The problem, solved for lambda(2) and p(2) (*allOSNS)[SICONOS_OSNSP_TS_VELOCITY + 1] * is solved at time told for \f$\lambda^+_{k}\f$ and time t for \f$\lambda^-_{k+1}\f$ * * The problem, solved for lambda(1) and p(1) (*allOSNS)[SICONOS_OSNSP_TS_VELOCITY + 1] * is solved at time t for \f$Lambda_{k+1}\f$. * * We use four index sets to compute the multipliers: * <ul> * <li> indexSet0 is the set of all constraints </li> * <li> indexSet1 is the set of closed constraints (computed with \f$ q_{k,1} \f$) </li> * <li> indexSet2 is the set of closed constraints and vanishing velocities (computed with \f$q_{k,1}\f$ and \f$v_{k,1}\f$ ) </li> * <li> indexSet3 is the set of the constraints that have been closed within the time--step (computed with \f$q_{k,0}\f$ and \f$q_{k,1}\f$ ) </li> * </ul> * * \f[ * \begin{cases} * v_{k,0} = \mbox{vold} \\ * q_{k,0} = \mbox{qold} \\ * F^+_{k} = \mbox{F(told,qold,vold)} \\ * v_{k,1} = v_{k,0} + h M^{-1}_k (P^+_{2,k}+F^+_{k}) \\[2mm] * q_{k,1} = q_{k,0} + \frac{h}{2} (v_{k,0} + v_{k,1}) \\[2mm] * F^-_{k+1} = F(t^{-}_{k+1},q_{k,1},v_{k,1}) \\[2mm] * R_{free} = - \frac{h}{2} M^{-1}_k (P^+_{2,k}+F^+_{k}) - \frac{h}{2} M^{-1}_{k+1} (P^-_{2,k+1}+F^-_{k+1}) \\[2mm] * \end{cases} * \f] * * \subsection sec_D1MinusLinear_implementation_halfVel HalfExplicitVelocityLevel * * */ const double DEFAULT_TOL_D1MINUS = 1e-8; class D1MinusLinearOSI : public OneStepIntegrator { public : protected: /** nslaw effects */ struct _NSLEffectOnFreeOutput : public SiconosVisitor { using SiconosVisitor::visit; OneStepNSProblem* _osnsp; SP::Interaction _inter; InteractionProperties& _interProp; _NSLEffectOnFreeOutput(OneStepNSProblem *p, SP::Interaction inter, InteractionProperties& interProp) : _osnsp(p), _inter(inter), _interProp(interProp) {}; void visit(const NewtonImpactNSL& nslaw); void visit(const EqualityConditionNSL& nslaw) { ; } }; //friend struct _NSLEffectOnFreeOutput; bool _isThereImpactInTheTimeStep ; unsigned int _typeOfD1MinusLinearOSI; public: /** Switching variable for various versions of D1MinusLinear */ enum ListOfTypeOfD1MinusLinearOSI {halfexplicit_acceleration_level, halfexplicit_acceleration_level_full, explicit_velocity_level, halfexplicit_velocity_level, numberOfTypeOfD1MinusLinearOSI }; enum D1MinusLinearOSI_ds_workVector_id {RESIDU_FREE, FREE, FREE_TDG, WORK_LENGTH}; enum D1MinusLinearOSI_interaction_workVector_id{OSNSP_RHS, WORK_INTERACTION_LENGTH}; enum D1MinusLinearOSI_workBlockVector_id{xfree, BLOCK_WORK_LENGTH}; /** basic constructor */ D1MinusLinearOSI(); /** Constructor with type of D1MinusLinear * \param type unsigned int that specifies the type of D1MinusLinear * D1MinusLinearOSI::halfexplicit_acceleration_level, * D1MinusLinearOSI::halfexplicit_acceleration_level_full, * D1MinusLinearOSI::explicit_velocity_level, * D1MinusLinearOSI::halfexplicit_velocity_level, * D1MinusLinearOSI::numberOfTypeOfD1MinusLinearOSI */ D1MinusLinearOSI(unsigned int type); /** destructor */ virtual ~D1MinusLinearOSI() {}; /** Set the type of the D1MinusLinear * \param type the type to set * D1MinusLinearOSI::halfexplicit_acceleration_level, * D1MinusLinearOSI::halfexplicit_acceleration_level_full, * D1MinusLinearOSI::explicit_velocity_level, * D1MinusLinearOSI::halfexplicit_velocity_level, * D1MinusLinearOSI::numberOfTypeOfD1MinusLinearOSI */ void setTypeOfD1MinusLinearOSI(unsigned int type); /** get the type of the D1MinusLinear * \return unsigned int type the type to set * D1MinusLinearOSI::halfexplicit_acceleration_level, * D1MinusLinearOSI::halfexplicit_acceleration_level_full, * D1MinusLinearOSI::explicit_velocity_level, * D1MinusLinearOSI::halfexplicit_velocity_level, * D1MinusLinearOSI::numberOfTypeOfD1MinusLinearOSI */ unsigned int typeOfD1MinusLinearOSI() { return _typeOfD1MinusLinearOSI; }; /** get the number of index sets required for the simulation * \return unsigned int */ unsigned int numberOfIndexSets() const; /** initialization of the D1MinusLinearOSI integrator; for linear time * invariant systems, we compute time invariant operator */ virtual void initialize_nonsmooth_problems(); /** initialization of the work vectors and matrices (properties) related to * one dynamical system on the graph and needed by the osi * \param t time of initialization * \param ds the dynamical system */ void initializeWorkVectorsForDS( double t, SP::DynamicalSystem ds); /** initialization of the work vectors and matrices (properties) related to * one interaction on the graph and needed by the osi * \param inter the interaction * \param interProp the properties on the graph * \param DSG the dynamical systems graph */ void initializeWorkVectorsForInteraction(Interaction &inter, InteractionProperties& interProp, DynamicalSystemsGraph & DSG); /** return the maximum of all norms for the residus of DS * \post{ds->residuFree will be calculated, ds->q() contains new position, ds->velocity contains predicted velocity} * \return double */ virtual double computeResidu(); /** return the maximum of all norms for the residus of DS for the type explicit_acceleration_level * \post{ds->residuFree will be calculated, ds->q() contains new position, ds->velocity contains predicted velocity} * \return double */ virtual double computeResiduHalfExplicitAccelerationLevel(); /** return the maximum of all norms for the residus of DS for the type explicit_acceleration_level_full * \post{ds->residuFree will be calculated, ds->q() contains new position, ds->velocity contains predicted velocity} * \return double */ virtual double computeResiduHalfExplicitAccelerationLevelFull(); /** return the maximum of all norms for the residus of DS for the type explicit_acceleration_level_full * \post{ds->residuFree will be calculated, ds->q() contains new position, ds->velocity contains predicted velocity} * \return double */ virtual double computeResiduHalfExplicitVelocityLevel(); /** integrates the Dynamical System linked to this integrator without taking non-smooth effects into account * \post{ds->velocity contains predicted velocity} */ virtual void computeFreeState(); /** integrates the Interaction linked to this integrator, without taking non-smooth effects into account * \param vertex_inter of the interaction graph * \param osnsp pointer to OneStepNSProblem */ virtual void computeFreeOutput(InteractionsGraph::VDescriptor& vertex_inter, OneStepNSProblem* osnsp); /** integrates the Interaction linked to this integrator, without taking non-smooth effects into account * \param vertex_inter of the interaction graph * \param osnsp pointer to OneStepNSProblem */ virtual void computeFreeOutputHalfExplicitAccelerationLevel(InteractionsGraph::VDescriptor& vertex_inter, OneStepNSProblem* osnsp); /** integrates the Interaction linked to this integrator, without taking non-smooth effects into account * \param vertex_inter of the interaction graph * \param osnsp pointer to OneStepNSProblem */ virtual void computeFreeOutputHalfExplicitVelocityLevel(InteractionsGraph::VDescriptor& vertex_inter, OneStepNSProblem* osnsp); /** integrate the system, between tinit and tend (->iout=true), with possible stop at tout (->iout=false) * \param ti initial time * \param tf end time * \param t real end time * \param flag useless flag (for D1MinusLinearOSI, used in LsodarOSI) */ virtual void integrate(double& ti, double& tf, double& t , int& flag) { THROW_EXCEPTION("D1MinusLinearOSI::integrate - not implemented!"); } /** updates the state of the Dynamical Systems * \param level level of interest for the dynamics: not used at the time * \post{ds->velocity contains new velocity} */ virtual void updateState(const unsigned int level); /** Apply the rule to one Interaction to known if is it should be included * in the IndexSet of level i * \param inter the involved interaction * \param i the index set level * \return a boolean if it needs to be added or not */ virtual bool addInteractionInIndexSet(SP::Interaction inter, unsigned int i); /** Apply the rule to one Interaction to known if is it should be removed * in the IndexSet of level i * \param inter the involved interaction * \param i the index set level * \return a boolean if it needs to be removed or not */ virtual bool removeInteractionFromIndexSet(SP::Interaction inter, unsigned int i); /** Apply the rule to one Interaction to known if is it should be included * in the IndexSet of level i * \param inter the involved interaction * \param i the index set level * \return a boolean if it needs to be added or not */ virtual bool addInteractionInIndexSetHalfExplicitAccelerationLevel(SP::Interaction inter, unsigned int i); /** Apply the rule to one Interaction to known if is it should be removed * in the IndexSet of level i * \param inter the involved interaction * \param i the index set level * \return a boolean if it needs to be removed or not */ virtual bool removeInteractionFromIndexSetHalfExplicitAccelerationLevel(SP::Interaction inter, unsigned int i); /** Apply the rule to one Interaction to known if is it should be included * in the IndexSet of level i * \param inter the involved interaction * \param i the index set level * \return a boolean if it needs to be added or not */ virtual bool addInteractionInIndexSetHalfExplicitVelocityLevel(SP::Interaction inter, unsigned int i); /** Apply the rule to one Interaction to known if is it should be removed * in the IndexSet of level i * \param inter the involved interaction * \param i the index set level * \return a boolean if it needs to be removed or not */ virtual bool removeInteractionFromIndexSetHalfExplicitVelocityLevel(SP::Interaction inter, unsigned int i); /** displays the data of the D1MinusLinearOSI's integrator */ virtual void display() { THROW_EXCEPTION("D1MinusLinearOSI::display - not implemented!"); } /** preparations for Newton iteration * \param time time */ virtual void prepareNewtonIteration(double time) { THROW_EXCEPTION("D1MinusLinearOSI::prepareNewtonIteration - not implemented!"); } /** visitors hook */ ACCEPT_STD_VISITORS(); }; #endif // D1MINUSLINEAR_H
37.052198
148
0.724031
BuildJet
ab33ae2ba1db21e870773b128a0ab5647796cae6
3,916
hpp
C++
include/Org/BouncyCastle/Crypto/Parameters/ParametersWithID.hpp
Fernthedev/BeatSaber-Quest-Codegen
716e4ff3f8608f7ed5b83e2af3be805f69e26d9e
[ "Unlicense" ]
null
null
null
include/Org/BouncyCastle/Crypto/Parameters/ParametersWithID.hpp
Fernthedev/BeatSaber-Quest-Codegen
716e4ff3f8608f7ed5b83e2af3be805f69e26d9e
[ "Unlicense" ]
null
null
null
include/Org/BouncyCastle/Crypto/Parameters/ParametersWithID.hpp
Fernthedev/BeatSaber-Quest-Codegen
716e4ff3f8608f7ed5b83e2af3be805f69e26d9e
[ "Unlicense" ]
null
null
null
// Autogenerated from CppHeaderCreator // Created by Sc2ad // ========================================================================= #pragma once // Begin includes #include "extern/beatsaber-hook/shared/utils/typedefs.h" #include "extern/beatsaber-hook/shared/utils/byref.hpp" // Completed includes // Begin forward declares // Forward declaring namespace: Org::BouncyCastle::Crypto namespace Org::BouncyCastle::Crypto { // Forward declaring type: ICipherParameters class ICipherParameters; } // Completed forward declares // Type namespace: Org.BouncyCastle.Crypto.Parameters namespace Org::BouncyCastle::Crypto::Parameters { // Size: 0x20 #pragma pack(push, 1) // Autogenerated type: Org.BouncyCastle.Crypto.Parameters.ParametersWithID // [TokenAttribute] Offset: FFFFFFFF class ParametersWithID : public ::Il2CppObject { public: // private readonly Org.BouncyCastle.Crypto.ICipherParameters parameters // Size: 0x8 // Offset: 0x10 Org::BouncyCastle::Crypto::ICipherParameters* parameters; // Field size check static_assert(sizeof(Org::BouncyCastle::Crypto::ICipherParameters*) == 0x8); // private readonly System.Byte[] id // Size: 0x8 // Offset: 0x18 ::Array<uint8_t>* id; // Field size check static_assert(sizeof(::Array<uint8_t>*) == 0x8); // Creating value type constructor for type: ParametersWithID ParametersWithID(Org::BouncyCastle::Crypto::ICipherParameters* parameters_ = {}, ::Array<uint8_t>* id_ = {}) noexcept : parameters{parameters_}, id{id_} {} // Get instance field reference: private readonly Org.BouncyCastle.Crypto.ICipherParameters parameters Org::BouncyCastle::Crypto::ICipherParameters*& dyn_parameters(); // Get instance field reference: private readonly System.Byte[] id ::Array<uint8_t>*& dyn_id(); // public Org.BouncyCastle.Crypto.ICipherParameters get_Parameters() // Offset: 0x127A9AC Org::BouncyCastle::Crypto::ICipherParameters* get_Parameters(); // public System.Byte[] GetID() // Offset: 0x127A9A4 ::Array<uint8_t>* GetID(); }; // Org.BouncyCastle.Crypto.Parameters.ParametersWithID #pragma pack(pop) static check_size<sizeof(ParametersWithID), 24 + sizeof(::Array<uint8_t>*)> __Org_BouncyCastle_Crypto_Parameters_ParametersWithIDSizeCheck; static_assert(sizeof(ParametersWithID) == 0x20); } #include "extern/beatsaber-hook/shared/utils/il2cpp-type-check.hpp" DEFINE_IL2CPP_ARG_TYPE(Org::BouncyCastle::Crypto::Parameters::ParametersWithID*, "Org.BouncyCastle.Crypto.Parameters", "ParametersWithID"); #include "extern/beatsaber-hook/shared/utils/il2cpp-utils-methods.hpp" // Writing MetadataGetter for method: Org::BouncyCastle::Crypto::Parameters::ParametersWithID::get_Parameters // Il2CppName: get_Parameters template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<Org::BouncyCastle::Crypto::ICipherParameters* (Org::BouncyCastle::Crypto::Parameters::ParametersWithID::*)()>(&Org::BouncyCastle::Crypto::Parameters::ParametersWithID::get_Parameters)> { static const MethodInfo* get() { return ::il2cpp_utils::FindMethod(classof(Org::BouncyCastle::Crypto::Parameters::ParametersWithID*), "get_Parameters", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{}); } }; // Writing MetadataGetter for method: Org::BouncyCastle::Crypto::Parameters::ParametersWithID::GetID // Il2CppName: GetID template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<::Array<uint8_t>* (Org::BouncyCastle::Crypto::Parameters::ParametersWithID::*)()>(&Org::BouncyCastle::Crypto::Parameters::ParametersWithID::GetID)> { static const MethodInfo* get() { return ::il2cpp_utils::FindMethod(classof(Org::BouncyCastle::Crypto::Parameters::ParametersWithID*), "GetID", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{}); } };
54.388889
256
0.723698
Fernthedev
ab33eec088a46ee0ba96860a4c03413737042503
5,877
cpp
C++
Computing-IV/psx/original.cpp
DulceWRLD/College
9b94868514f461c97121d72ea0855f72ca95e798
[ "MIT" ]
2
2021-08-21T01:25:50.000Z
2021-12-10T06:51:46.000Z
Computing-IV/psx/original.cpp
DulceWRLD/College
9b94868514f461c97121d72ea0855f72ca95e798
[ "MIT" ]
null
null
null
Computing-IV/psx/original.cpp
DulceWRLD/College
9b94868514f461c97121d72ea0855f72ca95e798
[ "MIT" ]
6
2021-03-14T22:21:23.000Z
2022-03-29T15:30:58.000Z
/* * Copyright 2015 Jason Downing * */ #include "original.hpp" // Seed the rand function for random colors - uses current time to do so unsigned int seed = time(NULL); /* * Inital coordinates of the circle will be: * 1) set the origin to be radius, radius - this makes it so that the circle's center for * transforming / moving / etc is its middle point. * 2) set the position to be the center of the screen */ // Constructor with just the depth as a parameter Original::Original(int depth, int size) { // Set the inital depth _depth = depth; // Set the Window size _size = size; // Set the inital radius. _radius = size/3.0; // Create a new circle; _circle = new Original(_radius - 10, _depth - 1, size); } // Constructor with coordinates - recusive Original::Original(float radius, int depth, int size) { // When depth is less than 0, the recusion is done. if (depth < 0) { _circle = NULL; return; } // Set member variables _depth = depth; _radius = radius; _size = size; // Create a new circle; _circle = new Original(_radius - 10, _depth - 1, size); return; } // Destructor Original::~Original() { if (_circle != NULL) { delete _circle; } } // Draw method void Original::draw(sf::RenderTarget& target, sf::RenderStates states) const { std::cout << "_depth is: " << _depth << std::endl; std::cout << "_Radius is: " << _radius << std::endl; // First circle sf::CircleShape shape(_radius); shape.setOrigin(_radius, _radius); shape.setPosition(_size/2, _size/2); shape.setPointCount(100000); // Make a random number between 1 and 19 // That means there will be 19 different colors flashing! int random_number = rand_r(&seed) % 19 + 1; // Color object sf::Color color(0, 0, 0, 255); switch (random_number) { case 1: // Red Color shape.setFillColor(sf::Color::Red); break; case 2: // Orange Color color.r = 255; color.g = 128; color.b = 0; shape.setFillColor(color); break; case 3: // Yellow Color shape.setFillColor(sf::Color::Yellow); break; case 4: // Green shape.setFillColor(sf::Color::Green); break; case 5: // Magenta shape.setFillColor(sf::Color::Magenta); break; case 6: // Cyan shape.setFillColor(sf::Color::Cyan); break; case 7: // Purple color.r = 127; color.g = 0; color.b = 255; shape.setFillColor(color); break; case 8: // Pink color.r = 255; color.g = 0; color.b = 255; shape.setFillColor(color); break; case 9: // Dark Orange color.r = 204; color.g = 102; color.b = 0; shape.setFillColor(color); break; case 10: // Dark Blue color.r = 0; color.g = 0; color.b = 102; shape.setFillColor(color); break; case 11: // Dark Purple color.r = 255; color.g = 0; color.b = 0; shape.setFillColor(color); break; case 12: // Dark Green color.r = 0; color.g = 51; color.b = 0; shape.setFillColor(color); break; case 13: // Gold color.r = 102; color.g = 102; color.b = 0; shape.setFillColor(color); break; case 14: // Lime Green color.r = 51; color.g = 255; color.b = 51; shape.setFillColor(color); break; case 15: // Lime Green color.r = 51; color.g = 255; color.b = 51; shape.setFillColor(color); break; case 16: // Light Orange color.r = 255; color.g = 153; color.b = 51; shape.setFillColor(color); break; case 17: // Light Yellow color.r = 255; color.g = 255; color.b = 51; shape.setFillColor(color); break; case 18: // Light Blue color.r = 51; color.g = 255; color.b = 255; shape.setFillColor(color); break; case 19: // Light Red color.r = 255; color.g = 0; color.b = 0; shape.setFillColor(color); break; default: break; } /* * Colors to use * I generated these using: * http://www.rapidtables.com/web/color/RGB_Color.htm * I then used the Color() constructor which takes a Red, Green, Blue int for setting * custom colors. * * "Standard colors" * Red -> sf::Color::Color(255, 0, 0) * Orange -> sf::Color::Color(255, 128, 0) * Yellow -> sf::Color::Color(255, 255, 51) * Green -> sf::Color::Color(0, 153, 0) * Blue -> sf::Color::Color(0, 0, 255) * Purple -> sf::Color::Color(127, 0, 255) * Pink -> sf::Color::Color(255, 0, 255) * * "Dark colors" * Dark Orange: sf::Color::Color(204, 102, 0) * Dark Blue: sf::Color::Color(0, 0, 102) * Dark Purple: sf::Color::Color(255, 0, 0) * Dark Green: sf::Color::Color(0, 51, 0) * Gold: sf::Color::Color(102, 102, 0) * * "Light colors" * Lime Green: sf::Color::Color(51, 255, 51) * Light Orange: sf::Color::Color(255, 153, 51) * Light Yellow: sf::Color::Color(255, 255, 51) * Light Blue: sf::Color::Color(51, 255, 255s) * Light Blue: sf::Color::Color(51, 153, 255) * Light Purple: sf::Color::Color(153, 51, 255) * Light Red: sf::Color::Color(255, 0, 0) * */ // Draw this circle target.draw(shape); // Recusive calls if (_circle != NULL) { _circle->draw(target, states); } }
22.093985
90
0.531223
DulceWRLD
ab3410522fc87d1f7a0ea580c6711dcac8d7fbf2
21,103
cpp
C++
src/tests/functional/inference_engine/transformations/common_optimizations/hswish_fusion_test.cpp
kurylo/openvino
4da0941cd2e8f9829875e60df73d3cd01f820b9c
[ "Apache-2.0" ]
1,127
2018-10-15T14:36:58.000Z
2020-04-20T09:29:44.000Z
src/tests/functional/inference_engine/transformations/common_optimizations/hswish_fusion_test.cpp
kurylo/openvino
4da0941cd2e8f9829875e60df73d3cd01f820b9c
[ "Apache-2.0" ]
439
2018-10-20T04:40:35.000Z
2020-04-19T05:56:25.000Z
src/tests/functional/inference_engine/transformations/common_optimizations/hswish_fusion_test.cpp
kurylo/openvino
4da0941cd2e8f9829875e60df73d3cd01f820b9c
[ "Apache-2.0" ]
414
2018-10-17T05:53:46.000Z
2020-04-16T17:29:53.000Z
// Copyright (C) 2018-2022 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // #include <gtest/gtest.h> #include <string> #include <memory> #include <ngraph/function.hpp> #include <ngraph/opsets/opset7.hpp> #include <ngraph/pass/manager.hpp> #include "transformations/common_optimizations/hsigmoid_fusion.hpp" #include <transformations/common_optimizations/hswish_fusion.hpp> #include <transformations/init_node_info.hpp> #include <transformations/utils/utils.hpp> #include "common_test_utils/ngraph_test_utils.hpp" using namespace testing; TEST_F(TransformationTestsF, HSwishFusionWithReluDivF16) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto relu = std::make_shared<ngraph::opset7::Relu>(add); auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant); auto mul = std::make_shared<ngraph::opset7::Multiply>(input, min); auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); auto div = std::make_shared<ngraph::opset7::Divide>(mul, div_constant); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); manager.register_pass<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto hswish = std::make_shared<ngraph::opset7::HSwish>(input); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } } TEST_F(TransformationTestsF, HSwishFusionWithReluDivF32) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f32, ngraph::Shape{}); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {3.0}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto relu = std::make_shared<ngraph::opset7::Relu>(add); auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0}); auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant); auto mul = std::make_shared<ngraph::opset7::Multiply>(input, min); auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f32, ngraph::Shape{}, {6.0}); auto div = std::make_shared<ngraph::opset7::Divide>(mul, div_constant); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); manager.register_pass<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f32, ngraph::Shape{}); auto hswish = std::make_shared<ngraph::opset7::HSwish>(input); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } } TEST_F(TransformationTestsF, HSwishFusionWithReluMul) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto relu = std::make_shared<ngraph::opset7::Relu>(add); auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant); auto mul_first = std::make_shared<ngraph::opset7::Multiply>(input, min); auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.1666666716}); auto mul_second = std::make_shared<ngraph::opset7::Multiply>(mul_first, mul_constant); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); manager.register_pass<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto hswish = std::make_shared<ngraph::opset7::HSwish>(input); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } } TEST_F(TransformationTestsF, HSwishFusionWithoutRelu) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); auto max = std::make_shared<ngraph::opset7::Maximum>(add, max_constant); auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); auto min = std::make_shared<ngraph::opset7::Minimum>(max, min_constant); auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant); auto mul = std::make_shared<ngraph::opset7::Multiply>(input, div); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); auto gr = manager.register_pass<ngraph::pass::GraphRewrite>(); gr->add_matcher<ngraph::pass::HSigmoidFusion>(); gr->add_matcher<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto hswish = std::make_shared<ngraph::opset7::HSwish>(input); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } } TEST_F(TransformationTestsF, HSwishFusionWithClampMul) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto clamp = std::make_shared<ngraph::opset7::Clamp>(add, 0.0f, 6.0f); auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {1.0 / 6.0}); auto mul_first = std::make_shared<ngraph::opset7::Multiply>(clamp, mul_constant); auto mul_second = std::make_shared<ngraph::opset7::Multiply>(input, mul_first); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); auto gr = manager.register_pass<ngraph::pass::GraphRewrite>(); gr->add_matcher<ngraph::pass::HSigmoidFusion>(); gr->add_matcher<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto hswish = std::make_shared<ngraph::opset7::HSwish>(input); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } } TEST_F(TransformationTestsF, HSwishFusionWithClampDiv) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto clamp = std::make_shared<ngraph::opset7::Clamp>(add, 0.0f, 6.0f); auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); auto div = std::make_shared<ngraph::opset7::Divide>(clamp, div_constant); auto mul = std::make_shared<ngraph::opset7::Multiply>(input, div); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); auto gr = manager.register_pass<ngraph::pass::GraphRewrite>(); gr->add_matcher<ngraph::pass::HSigmoidFusion>(); gr->add_matcher<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto hswish = std::make_shared<ngraph::opset7::HSwish>(input); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } } TEST_F(TransformationTestsF, HSwishFusionWithReluMulWrongConstValue) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto relu = std::make_shared<ngraph::opset7::Relu>(add); auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant); auto mul_first = std::make_shared<ngraph::opset7::Multiply>(input, min); auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167}); auto mul_second = std::make_shared<ngraph::opset7::Multiply>(mul_first, mul_constant); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); manager.register_pass<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto relu = std::make_shared<ngraph::opset7::Relu>(add); auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant); auto mul_first = std::make_shared<ngraph::opset7::Multiply>(input, min); auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.167}); auto mul_second = std::make_shared<ngraph::opset7::Multiply>(mul_first, mul_constant); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); } } TEST_F(TransformationTestsF, HSwishFusionWithReluDivWrongConstValue) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::Shape{}); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto relu = std::make_shared<ngraph::opset7::Relu>(add); auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant); auto mul = std::make_shared<ngraph::opset7::Multiply>(input, min); auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.1}); auto div = std::make_shared<ngraph::opset7::Divide>(mul, div_constant); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); manager.register_pass<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::Shape{}); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.01}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto relu = std::make_shared<ngraph::opset7::Relu>(add); auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); auto min = std::make_shared<ngraph::opset7::Minimum>(relu, min_constant); auto mul = std::make_shared<ngraph::opset7::Multiply>(input, min); auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.0}); auto div = std::make_shared<ngraph::opset7::Divide>(mul, div_constant); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{div}, ngraph::ParameterVector{input}); } } TEST_F(TransformationTestsF, HSwishFusionWithoutReluWrongConstValue) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22}); auto max = std::make_shared<ngraph::opset7::Maximum>(add, max_constant); auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01}); auto min = std::make_shared<ngraph::opset7::Minimum>(max, min_constant); auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant); auto mul = std::make_shared<ngraph::opset7::Multiply>(input, div); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); auto gr = manager.register_pass<ngraph::pass::GraphRewrite>(); gr->add_matcher<ngraph::pass::HSigmoidFusion>(); gr->add_matcher<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto max_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.22}); auto max = std::make_shared<ngraph::opset7::Maximum>(add, max_constant); auto min_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.01}); auto min = std::make_shared<ngraph::opset7::Minimum>(max, min_constant); auto div_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.002}); auto div = std::make_shared<ngraph::opset7::Divide>(min, div_constant); auto mul = std::make_shared<ngraph::opset7::Multiply>(input, div); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); } } TEST_F(TransformationTestsF, HSwishFusionWithClampWrongConstValue) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto clamp = std::make_shared<ngraph::opset7::Clamp>(add, 0.11f, 6.02f); auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15}); auto mul_first = std::make_shared<ngraph::opset7::Multiply>(clamp, mul_constant); auto mul_second = std::make_shared<ngraph::opset7::Multiply>(input, mul_first); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); auto gr = manager.register_pass<ngraph::pass::GraphRewrite>(); gr->add_matcher<ngraph::pass::HSigmoidFusion>(); gr->add_matcher<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto clamp = std::make_shared<ngraph::opset7::Clamp>(add, 0.11f, 6.02f); auto mul_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {0.98 / 6.15}); auto mul_first = std::make_shared<ngraph::opset7::Multiply>(clamp, mul_constant); auto mul_second = std::make_shared<ngraph::opset7::Multiply>(input, mul_first); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul_second}, ngraph::ParameterVector{input}); } } TEST_F(TransformationTestsF, HSwishFusionWithHSigmoidMul) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto hsigmoid = std::make_shared<ngraph::opset7::HSigmoid>(input); auto mul = std::make_shared<ngraph::opset7::Multiply>(input, hsigmoid); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); manager.register_pass<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto hswish = std::make_shared<ngraph::opset7::HSwish>(input); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{hswish}, ngraph::ParameterVector{input}); } } TEST_F(TransformationTestsF, HSwishFusionWithClamp) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.0}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto clamp = std::make_shared<ngraph::opset7::Clamp>(add, 0.0f, 6.0f); auto mul = std::make_shared<ngraph::opset7::Multiply>(input, clamp); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); auto gr = manager.register_pass<ngraph::pass::GraphRewrite>(); gr->add_matcher<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto hswish = std::make_shared<ngraph::opset7::HSwish>(input); auto mul_const = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {6.0}); auto mul = std::make_shared<ngraph::opset7::Multiply>(hswish, mul_const); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); } } TEST_F(TransformationTestsF, HSwishFusionWithClampWithWrongConstant) { { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto clamp = std::make_shared<ngraph::opset7::Clamp>(add, 0.11f, 6.32f); auto mul = std::make_shared<ngraph::opset7::Multiply>(input, clamp); function = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); auto gr = manager.register_pass<ngraph::pass::GraphRewrite>(); gr->add_matcher<ngraph::pass::HSwishFusion>(); } { auto input = std::make_shared<ngraph::opset7::Parameter>(ngraph::element::f16, ngraph::PartialShape::dynamic(1)); auto add_constant = ngraph::opset7::Constant::create(ngraph::element::f16, ngraph::Shape{}, {3.11}); auto add = std::make_shared<ngraph::opset7::Add>(input, add_constant); auto clamp = std::make_shared<ngraph::opset7::Clamp>(add, 0.11f, 6.32f); auto mul = std::make_shared<ngraph::opset7::Multiply>(input, clamp); function_ref = std::make_shared<ngraph::Function>(ngraph::NodeVector{mul}, ngraph::ParameterVector{input}); } }
56.728495
122
0.679524
kurylo
ab3540c6933bd0de3a05adaa2555f5a21fd6cf53
500
hpp
C++
TE2502/src/graphics/transfer_queue.hpp
ferthu/TE2502
de801f886713c0b2ef3ce6aa1e41e3fd9a58483e
[ "MIT" ]
null
null
null
TE2502/src/graphics/transfer_queue.hpp
ferthu/TE2502
de801f886713c0b2ef3ce6aa1e41e3fd9a58483e
[ "MIT" ]
null
null
null
TE2502/src/graphics/transfer_queue.hpp
ferthu/TE2502
de801f886713c0b2ef3ce6aa1e41e3fd9a58483e
[ "MIT" ]
null
null
null
#pragma once #include "queue.hpp" class VulkanContext; // Represents a hardware queue used for transfer commands class TransferQueue : public Queue { public: TransferQueue() {}; TransferQueue(VulkanContext& context, VkCommandPool command_pool, VkQueue queue); virtual ~TransferQueue(); TransferQueue(TransferQueue&& other); TransferQueue& operator=(TransferQueue&& other); private: // Move other into this void move_from(TransferQueue&& other); // Destroys object void destroy(); };
19.230769
82
0.756
ferthu
ab371356e252e5df75a4272d3ee0d18590b4a4ef
14,767
cc
C++
systems/trajectory_optimization/dircon_opt_constraints.cc
Nanda-Kishore-V/dairlib-1
7ffd43bb559408bc96bd590992aab52d42dfba16
[ "BSD-3-Clause" ]
1
2019-08-29T17:46:19.000Z
2019-08-29T17:46:19.000Z
systems/trajectory_optimization/dircon_opt_constraints.cc
Nanda-Kishore-V/dairlib
7ffd43bb559408bc96bd590992aab52d42dfba16
[ "BSD-3-Clause" ]
null
null
null
systems/trajectory_optimization/dircon_opt_constraints.cc
Nanda-Kishore-V/dairlib
7ffd43bb559408bc96bd590992aab52d42dfba16
[ "BSD-3-Clause" ]
null
null
null
#include "dircon_opt_constraints.h" #include <cstddef> #include <stdexcept> #include <utility> #include <vector> #include "drake/math/autodiff.h" #include "drake/math/autodiff_gradient.h" #include "multibody/multibody_utils.h" namespace dairlib { namespace systems { namespace trajectory_optimization { using drake::multibody::MultibodyPlant; using drake::systems::Context; using drake::solvers::Binding; using drake::solvers::Constraint; using drake::solvers::MathematicalProgram; using drake::solvers::VectorXDecisionVariable; using drake::AutoDiffVecXd; using drake::AutoDiffXd; using drake::math::initializeAutoDiff; using drake::math::autoDiffToValueMatrix; using drake::VectorX; using drake::MatrixX; using Eigen::VectorXd; using Eigen::MatrixXd; template <typename T> DirconAbstractConstraint<T>::DirconAbstractConstraint(int num_constraints, int num_vars, const VectorXd& lb, const VectorXd& ub, const std::string& description) : Constraint(num_constraints, num_vars, lb, ub, description) { } template <> void DirconAbstractConstraint<double>::DoEval( const Eigen::Ref<const Eigen::VectorXd>& x, Eigen::VectorXd* y) const { EvaluateConstraint(x, y); } template <> void DirconAbstractConstraint<AutoDiffXd>::DoEval( const Eigen::Ref<const Eigen::VectorXd>& x, Eigen::VectorXd* y) const { AutoDiffVecXd y_t; EvaluateConstraint(initializeAutoDiff(x), &y_t); *y = autoDiffToValueMatrix(y_t); } template <typename T> void DirconAbstractConstraint<T>::DoEval( const Eigen::Ref<const VectorX<drake::symbolic::Variable>>& x, VectorX<drake::symbolic::Expression>* y) const { throw std::logic_error( "DirconAbstractConstraint does not support symbolic evaluation."); } template <> void DirconAbstractConstraint<AutoDiffXd>::DoEval( const Eigen::Ref<const AutoDiffVecXd>& x, AutoDiffVecXd* y) const { EvaluateConstraint(x,y); } template <> void DirconAbstractConstraint<double>::DoEval( const Eigen::Ref<const AutoDiffVecXd>& x, AutoDiffVecXd* y) const { // forward differencing double dx = 1e-8; VectorXd x_val = autoDiffToValueMatrix(x); VectorXd y0,yi; EvaluateConstraint(x_val,&y0); MatrixXd dy = MatrixXd(y0.size(),x_val.size()); for (int i=0; i < x_val.size(); i++) { x_val(i) += dx; EvaluateConstraint(x_val,&yi); x_val(i) -= dx; dy.col(i) = (yi - y0)/dx; } drake::math::initializeAutoDiffGivenGradientMatrix(y0, dy, *y); // // central differencing // double dx = 1e-8; // VectorXd x_val = autoDiffToValueMatrix(x); // VectorXd y0,yi; // EvaluateConstraint(x_val,y0); // MatrixXd dy = MatrixXd(y0.size(),x_val.size()); // for (int i=0; i < x_val.size(); i++) { // x_val(i) -= dx/2; // EvaluateConstraint(x_val,y0); // x_val(i) += dx; // EvaluateConstraint(x_val,yi); // x_val(i) -= dx/2; // dy.col(i) = (yi - y0)/dx; // } // EvaluateConstraint(x_val,y0); // initializeAutoDiffGivenGradientMatrix(y0, dy, y); } template <typename T> DirconDynamicConstraint<T>::DirconDynamicConstraint( const MultibodyPlant<T>& plant, DirconKinematicDataSet<T>& constraints) : DirconDynamicConstraint(plant, constraints, plant.num_positions(), plant.num_velocities(), plant.num_actuators(), constraints.countConstraints()) {} template <typename T> DirconDynamicConstraint<T>::DirconDynamicConstraint( const MultibodyPlant<T>& plant, DirconKinematicDataSet<T>& constraints, int num_positions, int num_velocities, int num_inputs, int num_kinematic_constraints) : DirconAbstractConstraint<T>(num_positions + num_velocities, 1 + 2 *(num_positions+ num_velocities) + (2 * num_inputs) + (4 * num_kinematic_constraints), Eigen::VectorXd::Zero(num_positions + num_velocities), Eigen::VectorXd::Zero(num_positions + num_velocities)), plant_(plant), constraints_(&constraints), num_states_{num_positions+num_velocities}, num_inputs_{num_inputs}, num_kinematic_constraints_{num_kinematic_constraints}, num_positions_{num_positions}, num_velocities_{num_velocities} {} // The format of the input to the eval() function is the // tuple { timestep, state 0, state 1, input 0, input 1, force 0, force 1}, // which has a total length of 1 + 2*num_states + 2*num_inputs + dim*num_constraints. template <typename T> void DirconDynamicConstraint<T>::EvaluateConstraint( const Eigen::Ref<const VectorX<T>>& x, VectorX<T>* y) const { DRAKE_ASSERT(x.size() == 1 + (2 * num_states_) + (2 * num_inputs_) + 4*(num_kinematic_constraints_)); // Extract our input variables: // h - current time (knot) value // x0, x1 state vector at time steps k, k+1 // u0, u1 input vector at time steps k, k+1 const T h = x(0); const VectorX<T> x0 = x.segment(1, num_states_); const VectorX<T> x1 = x.segment(1 + num_states_, num_states_); const VectorX<T> u0 = x.segment(1 + (2 * num_states_), num_inputs_); const VectorX<T> u1 = x.segment(1 + (2 * num_states_) + num_inputs_, num_inputs_); const VectorX<T> l0 = x.segment(1 + 2 * (num_states_ + num_inputs_), num_kinematic_constraints_); const VectorX<T> l1 = x.segment(1 + 2 * (num_states_ + num_inputs_) + num_kinematic_constraints_, num_kinematic_constraints_); const VectorX<T> lc = x.segment(1 + 2 * (num_states_ + num_inputs_) + 2*num_kinematic_constraints_, num_kinematic_constraints_); const VectorX<T> vc = x.segment(1 + 2 * (num_states_ + num_inputs_) + 3*num_kinematic_constraints_, num_kinematic_constraints_); auto context0 = multibody::createContext(plant_, x0, u0); constraints_->updateData(*context0, l0); const VectorX<T> xdot0 = constraints_->getXDot(); auto context1 = multibody::createContext(plant_, x1, u1); constraints_->updateData(*context1, l1); const VectorX<T> xdot1 = constraints_->getXDot(); // Cubic interpolation to get xcol and xdotcol. const VectorX<T> xcol = 0.5 * (x0 + x1) + h / 8 * (xdot0 - xdot1); const VectorX<T> xdotcol = -1.5 * (x0 - x1) / h - .25 * (xdot0 + xdot1); const VectorX<T> ucol = 0.5 * (u0 + u1); auto contextcol = multibody::createContext(plant_, xcol, ucol); constraints_->updateData(*contextcol, lc); auto g = constraints_->getXDot(); g.head(num_positions_) += constraints_->getJ().transpose()*vc; *y = xdotcol - g; } template <typename T> Binding<Constraint> AddDirconConstraint( std::shared_ptr<DirconDynamicConstraint<T>> constraint, const Eigen::Ref<const VectorXDecisionVariable>& timestep, const Eigen::Ref<const VectorXDecisionVariable>& state, const Eigen::Ref<const VectorXDecisionVariable>& next_state, const Eigen::Ref<const VectorXDecisionVariable>& input, const Eigen::Ref<const VectorXDecisionVariable>& next_input, const Eigen::Ref<const VectorXDecisionVariable>& force, const Eigen::Ref<const VectorXDecisionVariable>& next_force, const Eigen::Ref<const VectorXDecisionVariable>& collocation_force, const Eigen::Ref<const VectorXDecisionVariable>& collocation_position_slack, MathematicalProgram* prog) { DRAKE_DEMAND(timestep.size() == 1); DRAKE_DEMAND(state.size() == constraint->num_states()); DRAKE_DEMAND(next_state.size() == constraint->num_states()); DRAKE_DEMAND(input.size() == constraint->num_inputs()); DRAKE_DEMAND(next_input.size() == constraint->num_inputs()); DRAKE_DEMAND(force.size() == constraint->num_kinematic_constraints()); DRAKE_DEMAND(next_force.size() == constraint->num_kinematic_constraints()); DRAKE_DEMAND(collocation_force.size() == constraint->num_kinematic_constraints()); DRAKE_DEMAND(collocation_position_slack.size() == constraint->num_kinematic_constraints()); return prog->AddConstraint(constraint, {timestep, state, next_state, input, next_input, force, next_force, collocation_force, collocation_position_slack}); } template <typename T> DirconKinematicConstraint<T>::DirconKinematicConstraint( const MultibodyPlant<T>& plant, DirconKinematicDataSet<T>& constraints, DirconKinConstraintType type) : DirconKinematicConstraint(plant, constraints, std::vector<bool>(constraints.countConstraints(), false), type, plant.num_positions(), plant.num_velocities(), plant.num_actuators(), constraints.countConstraints()) {} template <typename T> DirconKinematicConstraint<T>::DirconKinematicConstraint( const MultibodyPlant<T>& plant, DirconKinematicDataSet<T>& constraints, std::vector<bool> is_constraint_relative, DirconKinConstraintType type) : DirconKinematicConstraint(plant, constraints, is_constraint_relative, type, plant.num_positions(), plant.num_velocities(), plant.num_actuators(), constraints.countConstraints()) {} template <typename T> DirconKinematicConstraint<T>::DirconKinematicConstraint( const MultibodyPlant<T>& plant, DirconKinematicDataSet<T>& constraints, std::vector<bool> is_constraint_relative, DirconKinConstraintType type, int num_positions, int num_velocities, int num_inputs, int num_kinematic_constraints) : DirconAbstractConstraint<T>(type*num_kinematic_constraints, num_positions + num_velocities + num_inputs + num_kinematic_constraints + std::count(is_constraint_relative.begin(), is_constraint_relative.end(), true), VectorXd::Zero(type*num_kinematic_constraints), VectorXd::Zero(type*num_kinematic_constraints)), plant_(plant), constraints_(&constraints), num_states_{num_positions+num_velocities}, num_inputs_{num_inputs}, num_kinematic_constraints_{num_kinematic_constraints}, num_positions_{num_positions}, num_velocities_{num_velocities}, type_{type}, is_constraint_relative_{is_constraint_relative}, n_relative_{static_cast<int>(std::count(is_constraint_relative.begin(), is_constraint_relative.end(), true))} { relative_map_ = MatrixXd::Zero(num_kinematic_constraints_, n_relative_); int j = 0; for (int i=0; i < num_kinematic_constraints_; i++) { if (is_constraint_relative_[i]) { relative_map_(i, j) = 1; j++; } } } template <typename T> void DirconKinematicConstraint<T>::EvaluateConstraint( const Eigen::Ref<const VectorX<T>>& x, VectorX<T>* y) const { DRAKE_ASSERT(x.size() == num_states_ + num_inputs_ + num_kinematic_constraints_ + n_relative_); // Extract our input variables: // h - current time (knot) value // x0, x1 state vector at time steps k, k+1 // u0, u1 input vector at time steps k, k+1 const VectorX<T> state = x.segment(0, num_states_); const VectorX<T> input = x.segment(num_states_, num_inputs_); const VectorX<T> force = x.segment(num_states_ + num_inputs_, num_kinematic_constraints_); const VectorX<T> offset = x.segment(num_states_ + num_inputs_ + num_kinematic_constraints_, n_relative_); auto context = multibody::createContext(plant_, state, input); constraints_->updateData(*context, force); switch (type_) { case kAll: *y = VectorX<T>(3*num_kinematic_constraints_); *y << constraints_->getC() + relative_map_*offset, constraints_->getCDot(), constraints_->getCDDot(); break; case kAccelAndVel: *y = VectorX<T>(2*num_kinematic_constraints_); *y << constraints_->getCDot(), constraints_->getCDDot(); break; case kAccelOnly: *y = VectorX<T>(1*num_kinematic_constraints_); *y << constraints_->getCDDot(); break; } } template <typename T> DirconImpactConstraint<T>::DirconImpactConstraint( const MultibodyPlant<T>& plant, DirconKinematicDataSet<T>& constraints) : DirconImpactConstraint(plant, constraints, plant.num_positions(), plant.num_velocities(), constraints.countConstraints()) {} template <typename T> DirconImpactConstraint<T>::DirconImpactConstraint( const MultibodyPlant<T>& plant, DirconKinematicDataSet<T>& constraints, int num_positions, int num_velocities, int num_kinematic_constraints) : DirconAbstractConstraint<T>(num_velocities, num_positions + 2*num_velocities + num_kinematic_constraints, VectorXd::Zero(num_velocities), VectorXd::Zero(num_velocities)), plant_(plant), constraints_(&constraints), num_states_{num_positions+num_velocities}, num_kinematic_constraints_{num_kinematic_constraints}, num_positions_{num_positions}, num_velocities_{num_velocities} {} // The format of the input to the eval() function is the // tuple { state 0, impulse, velocity 1}, template <typename T> void DirconImpactConstraint<T>::EvaluateConstraint( const Eigen::Ref<const VectorX<T>>& x, VectorX<T>* y) const { DRAKE_ASSERT(x.size() == 2 * num_velocities_ + num_positions_ + num_kinematic_constraints_); // Extract our input variables: // x0, state vector at time k^- // impulse, impulsive force at impact // v1, post-impact velocity at time k^+ const VectorX<T> x0 = x.segment(0, num_states_); const VectorX<T> impulse = x.segment(num_states_, num_kinematic_constraints_); const VectorX<T> v1 = x.segment(num_states_ + num_kinematic_constraints_, num_velocities_); const VectorX<T> v0 = x0.tail(num_velocities_); // vp = vm + M^{-1}*J^T*Lambda const VectorX<T> u = VectorXd::Zero(plant_.num_actuators()).template cast<T>(); auto context = multibody::createContext(plant_, x0, u); constraints_->updateData(*context, impulse); MatrixX<T> M(num_velocities_, num_velocities_); plant_.CalcMassMatrixViaInverseDynamics(*context, &M); *y = M*(v1 - v0) - constraints_->getJ().transpose()*impulse; } // Explicitly instantiates on the most common scalar types. template class DirconDynamicConstraint<double>; template class DirconDynamicConstraint<AutoDiffXd>; template class DirconKinematicConstraint<double>; template class DirconKinematicConstraint<AutoDiffXd>; template class DirconImpactConstraint<double>; template class DirconImpactConstraint<AutoDiffXd>; } // namespace trajectory_optimization } // namespace systems } // namespace dairlib
41.248603
88
0.689646
Nanda-Kishore-V
ab38c6989f1e7876b85b36d27381a598adf9c48e
3,778
cpp
C++
spearmint/spearmint.cpp
chopralab/spear
d45ffc907ab1730789413dd04afb347a26f35154
[ "BSD-3-Clause" ]
2
2019-07-28T07:57:02.000Z
2019-10-28T13:58:37.000Z
spearmint/spearmint.cpp
chopralab/spear
d45ffc907ab1730789413dd04afb347a26f35154
[ "BSD-3-Clause" ]
null
null
null
spearmint/spearmint.cpp
chopralab/spear
d45ffc907ab1730789413dd04afb347a26f35154
[ "BSD-3-Clause" ]
null
null
null
#include <memory> #include "spearmint.h" #include "chemfiles/Trajectory.hpp" #include "spear/Molecule.hpp" #include "spear/Grid.hpp" #include "spear/ScoringFunction.hpp" #include "spear/atomtypes/IDATM.hpp" #include "spear/scoringfunctions/Bernard12.hpp" std::unique_ptr<Spear::Molecule> receptor; std::unique_ptr<Spear::Molecule> ligand; std::unique_ptr<Spear::ScoringFunction> score; std::unique_ptr<Spear::Grid> gridrec; static thread_local std::string error_string = ""; const char* spear_get_error() { auto cstring = error_string.c_str(); char* copy = new char[error_string.size() + 1]; strcpy(copy, cstring); return copy; } void set_error(const std::string& error) { error_string = "[Spearmint] " + error; } uint64_t get_atom_positions(const Spear::Molecule& mol, float* pos) { try { size_t current = 0; for (auto& rpos : mol.positions()) { pos[current * 3 + 0] = static_cast<float>(rpos[0]); pos[current * 3 + 1] = static_cast<float>(rpos[1]); pos[current * 3 + 2] = static_cast<float>(rpos[2]); current++; } return 1; } catch (std::exception& e) { set_error(std::string("Error creating atom arrays: ") + e.what()); return 0; } } uint64_t get_bonds(Spear::Molecule& mol, size_t* bonds) { try { size_t i = 0; auto& bos = mol.topology().bond_orders(); for (auto& a : mol.topology().bonds()) { bonds[i * 3 + 0] = a[0]; bonds[i * 3 + 1] = a[1]; bonds[i * 3 + 2] = static_cast<size_t>(bos[i]); ++i; } return 1; } catch (std::exception& e) { set_error(std::string("Error setting bond arrays: ") + e.what()); return 0; } } uint64_t set_positions(Spear::Molecule& mol, const float* positions) { auto size = mol.size(); std::vector<Eigen::Vector3d> posvector; posvector.reserve(size / 3); for (size_t i = 0; i < size; ++i) { posvector.emplace_back( positions[i * 3 + 0], positions[i * 3 + 1], positions[i * 3 + 2] ); } mol.set_positions(std::move(posvector)); return 1; } uint64_t spear_initialize_scoring(const char* data_dir) { if (ligand == nullptr || receptor == nullptr) { set_error("You must initialize ligand and receptor first"); return 0; } try { auto atomtype_name = receptor->add_atomtype<Spear::IDATM>(Spear::AtomType::GEOMETRY); auto atomtype_name2 = ligand->add_atomtype<Spear::IDATM>(Spear::AtomType::GEOMETRY); receptor->atomtype(atomtype_name); ligand->atomtype(atomtype_name); std::ifstream csd_distrib((std::string(data_dir) + "/csd_distributions.dat").c_str()); if (!csd_distrib) { set_error("Could not open distribution file."); return 0; } Spear::AtomicDistributions atomic_distrib = Spear::read_atomic_distributions<Spear::IDATM>(csd_distrib); using Spear::Bernard12; auto options = Bernard12::Options(Bernard12::RADIAL | Bernard12::MEAN | Bernard12::COMPLETE); score = std::make_unique<Bernard12>(options, 15.0, atomic_distrib, atomtype_name); } catch (const std::exception& e) { set_error(std::string("Error in loading ligand ") + e.what()); return 0; } return 1; } float spear_calculate_score() { if (ligand == nullptr || receptor == nullptr) { set_error("You must initialize ligand and receptor first"); return 0.000; } if (score == nullptr) { set_error("You must run initialize_score first."); return 0.000; } return static_cast<float>(score->score(*gridrec, *receptor, *ligand)); }
29.515625
112
0.607729
chopralab
ab391aac421287f42bebd88419157837554be526
6,131
cpp
C++
TAO/orbsvcs/orbsvcs/IFRService/ArrayDef_i.cpp
cflowe/ACE
5ff60b41adbe1772372d1a43bcc1f2726ff8f810
[ "DOC" ]
36
2015-01-10T07:27:33.000Z
2022-03-07T03:32:08.000Z
TAO/orbsvcs/orbsvcs/IFRService/ArrayDef_i.cpp
cflowe/ACE
5ff60b41adbe1772372d1a43bcc1f2726ff8f810
[ "DOC" ]
2
2018-08-13T07:30:51.000Z
2019-02-25T03:04:31.000Z
TAO/orbsvcs/orbsvcs/IFRService/ArrayDef_i.cpp
cflowe/ACE
5ff60b41adbe1772372d1a43bcc1f2726ff8f810
[ "DOC" ]
38
2015-01-08T14:12:06.000Z
2022-01-19T08:33:00.000Z
// $Id: ArrayDef_i.cpp 91682 2010-09-09 07:20:23Z johnnyw $ #include "orbsvcs/IFRService/ArrayDef_i.h" #include "orbsvcs/IFRService/Repository_i.h" #include "orbsvcs/IFRService/IFR_Service_Utils.h" #include "ace/Auto_Ptr.h" #include "ace/SString.h" TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_ArrayDef_i::TAO_ArrayDef_i (TAO_Repository_i *repo) : TAO_IRObject_i (repo), TAO_IDLType_i (repo) { } TAO_ArrayDef_i::~TAO_ArrayDef_i (void) { } CORBA::DefinitionKind TAO_ArrayDef_i::def_kind (void) { return CORBA::dk_Array; } void TAO_ArrayDef_i::destroy (void) { TAO_IFR_WRITE_GUARD; this->update_key (); this->destroy_i (); } void TAO_ArrayDef_i::destroy_i (void) { // Only if it is (w)string, fixed, array or sequence. this->destroy_element_type (); ACE_TString name; this->repo_->config ()->get_string_value (this->section_key_, "name", name); this->repo_->config ()->remove_section (this->repo_->arrays_key (), name.c_str (), 0); } CORBA::TypeCode_ptr TAO_ArrayDef_i::type (void) { TAO_IFR_READ_GUARD_RETURN (CORBA::TypeCode::_nil ()); this->update_key (); return this->type_i (); } CORBA::TypeCode_ptr TAO_ArrayDef_i::type_i (void) { // Store the current array's section key. ACE_Configuration_Section_Key key_holder = this->section_key_; CORBA::TypeCode_var element_typecode = this->element_type_i (); // If this array contains another nested array (an array of an array // or an array of a struct that has a member array etc.) at some // level, the above call will have changed the array section key so // we have to replace it with the original value we stored above. this->section_key (key_holder); CORBA::ULong length = this->length_i (); return this->repo_->tc_factory ()->create_array_tc ( length, element_typecode.in () ); } CORBA::ULong TAO_ArrayDef_i::length (void) { TAO_IFR_READ_GUARD_RETURN (0); this->update_key (); return this->length_i (); } CORBA::ULong TAO_ArrayDef_i::length_i (void) { u_int length = 0; this->repo_->config ()->get_integer_value (this->section_key_, "length", length); return static_cast<CORBA::ULong> (length); } void TAO_ArrayDef_i::length (CORBA::ULong length) { TAO_IFR_WRITE_GUARD; this->update_key (); this->length_i (length); } void TAO_ArrayDef_i::length_i (CORBA::ULong length) { this->repo_->config ()->set_integer_value (this->section_key_, "length", length); } CORBA::TypeCode_ptr TAO_ArrayDef_i::element_type (void) { TAO_IFR_READ_GUARD_RETURN (CORBA::TypeCode::_nil ()); this->update_key (); return this->element_type_i (); } CORBA::TypeCode_ptr TAO_ArrayDef_i::element_type_i (void) { ACE_TString element_path; this->repo_->config ()->get_string_value (this->section_key_, "element_path", element_path); TAO_IDLType_i *impl = TAO_IFR_Service_Utils::path_to_idltype (element_path, this->repo_); return impl->type_i (); } CORBA::IDLType_ptr TAO_ArrayDef_i::element_type_def (void) { TAO_IFR_READ_GUARD_RETURN (CORBA::IDLType::_nil ()); this->update_key (); return this->element_type_def_i (); } CORBA::IDLType_ptr TAO_ArrayDef_i::element_type_def_i (void) { ACE_TString element_path; this->repo_->config ()->get_string_value (this->section_key_, "element_path", element_path); CORBA::Object_var obj = TAO_IFR_Service_Utils::path_to_ir_object (element_path, this->repo_); return CORBA::IDLType::_narrow (obj.in ()); } void TAO_ArrayDef_i::element_type_def (CORBA::IDLType_ptr element_type_def) { TAO_IFR_WRITE_GUARD; this->update_key (); this->element_type_def_i (element_type_def); } void TAO_ArrayDef_i::element_type_def_i (CORBA::IDLType_ptr element_type_def) { this->destroy_element_type (); char *new_element_path = TAO_IFR_Service_Utils::reference_to_path (element_type_def); this->repo_->config ()->set_string_value (this->section_key_, "element_path", new_element_path); } void TAO_ArrayDef_i::destroy_element_type ( ) { ACE_TString element_path; this->repo_->config ()->get_string_value (this->section_key_, "element_path", element_path); ACE_Configuration_Section_Key element_key; this->repo_->config ()->expand_path (this->repo_->root_key (), element_path, element_key, 0); u_int kind = 0; this->repo_->config ()->get_integer_value (element_key, ACE_TEXT("def_kind"), kind); CORBA::DefinitionKind def_kind = TAO_IFR_Service_Utils::path_to_def_kind (element_path, this->repo_); switch (def_kind) { // These exist only as our elements, so the type should // be destroyed when we are destroyed, or when our element type // is mutated. case CORBA::dk_String: case CORBA::dk_Wstring: case CORBA::dk_Fixed: case CORBA::dk_Array: case CORBA::dk_Sequence: { TAO_IDLType_i *impl = this->repo_->select_idltype (def_kind); impl->section_key (element_key); impl->destroy_i (); break; } default: break; } } TAO_END_VERSIONED_NAMESPACE_DECL
24.922764
72
0.586527
cflowe
ab3ee2e3345c79f948d9427138aafa7cfbfd64f3
5,207
cc
C++
src/pybind/matrix/kaldi_matrix_pybind.cc
aadps/kaldi
cd351bb31c98f9d540c409478cbf2c5fef1853ca
[ "Apache-2.0" ]
null
null
null
src/pybind/matrix/kaldi_matrix_pybind.cc
aadps/kaldi
cd351bb31c98f9d540c409478cbf2c5fef1853ca
[ "Apache-2.0" ]
null
null
null
src/pybind/matrix/kaldi_matrix_pybind.cc
aadps/kaldi
cd351bb31c98f9d540c409478cbf2c5fef1853ca
[ "Apache-2.0" ]
null
null
null
// pybind/matrix/kaldi_matrix_pybind.cc // Copyright 2019 Daniel Povey // 2019 Dongji Gao // 2019 Mobvoi AI Lab, Beijing, China (author: Fangjun Kuang) // See ../../../COPYING for clarification regarding multiple authors // // 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 // // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, // MERCHANTABLITY OR NON-INFRINGEMENT. // See the Apache 2 License for the specific language governing permissions and // limitations under the License. #include "matrix/kaldi_matrix_pybind.h" #include "dlpack/dlpack_pybind.h" #include "matrix/kaldi-matrix.h" using namespace kaldi; void pybind_kaldi_matrix(py::module& m) { py::class_<MatrixBase<float>, std::unique_ptr<MatrixBase<float>, py::nodelete>>( m, "FloatMatrixBase", "Base class which provides matrix operations not involving resizing\n" "or allocation. Classes Matrix and SubMatrix inherit from it and take " "care of allocation and resizing.") .def("NumRows", &MatrixBase<float>::NumRows, "Return number of rows") .def("NumCols", &MatrixBase<float>::NumCols, "Return number of columns") .def("Stride", &MatrixBase<float>::Stride, "Return stride") .def("__repr__", [](const MatrixBase<float>& b) -> std::string { std::ostringstream str; b.Write(str, false); return str.str(); }) .def("__getitem__", [](const MatrixBase<float>& m, std::pair<ssize_t, ssize_t> i) { return m(i.first, i.second); }) .def("__setitem__", [](MatrixBase<float>& m, std::pair<ssize_t, ssize_t> i, float v) { m(i.first, i.second) = v; }) .def("numpy", [](py::object obj) { auto* m = obj.cast<MatrixBase<float>*>(); return py::array_t<float>( {m->NumRows(), m->NumCols()}, // shape {sizeof(float) * m->Stride(), sizeof(float)}, // stride in bytes m->Data(), // ptr obj); // it will increase the reference count of **this** matrix }); py::class_<Matrix<float>, MatrixBase<float>>(m, "FloatMatrix", pybind11::buffer_protocol()) .def_buffer([](const Matrix<float>& m) -> pybind11::buffer_info { return pybind11::buffer_info( (void*)m.Data(), // pointer to buffer sizeof(float), // size of one scalar pybind11::format_descriptor<float>::format(), 2, // num-axes {m.NumRows(), m.NumCols()}, // buffer dimensions {sizeof(float) * m.Stride(), sizeof(float)}); // stride for each index (in chars) }) .def(py::init<>()) .def(py::init<const MatrixIndexT, const MatrixIndexT, MatrixResizeType, MatrixStrideType>(), py::arg("row"), py::arg("col"), py::arg("resize_type") = kSetZero, py::arg("stride_type") = kDefaultStride) .def(py::init<const MatrixBase<float>&, MatrixTransposeType>(), py::arg("M"), py::arg("trans") = kNoTrans) .def("Read", &Matrix<float>::Read, "allows resizing", py::arg("is"), py::arg("binary"), py::arg("add") = false) .def("Write", &Matrix<float>::Write, py::arg("out"), py::arg("binary")) .def("to_dlpack", [](py::object obj) { return MatrixToDLPack(&obj); }); py::class_<SubMatrix<float>, MatrixBase<float>>(m, "FloatSubMatrix") .def(py::init([](py::buffer b) { py::buffer_info info = b.request(); if (info.format != py::format_descriptor<float>::format()) { KALDI_ERR << "Expected format: " << py::format_descriptor<float>::format() << "\n" << "Current format: " << info.format; } if (info.ndim != 2) { KALDI_ERR << "Expected dim: 2\n" << "Current dim: " << info.ndim; } // numpy is row major by default, so we use strides[0] return new SubMatrix<float>(reinterpret_cast<float*>(info.ptr), info.shape[0], info.shape[1], info.strides[0] / sizeof(float)); })); py::class_<DLPackSubMatrix<float>, SubMatrix<float>>(m, "DLPackFloatSubMatrix") .def("from_dlpack", [](py::capsule* capsule) { return SubMatrixFromDLPack(capsule); }, py::return_value_policy::take_ownership); py::class_<Matrix<double>, std::unique_ptr<Matrix<double>, py::nodelete>>( m, "DoubleMatrix", "This bind is only for internal use, e.g. by OnlineCmvnState.") .def(py::init<const Matrix<float>&>(), py::arg("src")); }
44.887931
79
0.568273
aadps
ab41678ebf9fc75067453305997eaecf12b40c09
2,351
cpp
C++
lib/host/wasi_crypto/signature/signature.cpp
sonder-joker/WasmEdge
3a522b4e242af1870bdd963f631fc8308b53bad7
[ "Apache-2.0" ]
null
null
null
lib/host/wasi_crypto/signature/signature.cpp
sonder-joker/WasmEdge
3a522b4e242af1870bdd963f631fc8308b53bad7
[ "Apache-2.0" ]
null
null
null
lib/host/wasi_crypto/signature/signature.cpp
sonder-joker/WasmEdge
3a522b4e242af1870bdd963f631fc8308b53bad7
[ "Apache-2.0" ]
null
null
null
// SPDX-License-Identifier: Apache-2.0 #include "host/wasi_crypto/signature/signature.h" #include "host/wasi_crypto/signature/ecdsa.h" #include "host/wasi_crypto/signature/eddsa.h" #include "host/wasi_crypto/signature/rsa.h" namespace WasmEdge { namespace Host { namespace WASICrypto { namespace Signatures { WasiCryptoExpect<std::unique_ptr<Signature>> Signature::import(SignatureAlgorithm Alg, Span<const uint8_t> Encoded, __wasi_signature_encoding_e_t Encoding) { switch (Alg) { case SignatureAlgorithm::ECDSA_P256_SHA256: return EcdsaP256::Signature::import(Encoded, Encoding); case SignatureAlgorithm::ECDSA_K256_SHA256: return EcdsaK256::Signature::import(Encoded, Encoding); case SignatureAlgorithm::Ed25519: return EddsaSignature::import(Encoded, Encoding); case SignatureAlgorithm::RSA_PKCS1_2048_SHA256: return RsaPkcs12048SHA256::Signature::import(Encoded, Encoding); case SignatureAlgorithm::RSA_PKCS1_2048_SHA384: return RsaPkcs12048SHA384::Signature::import(Encoded, Encoding); case SignatureAlgorithm::RSA_PKCS1_2048_SHA512: return RsaPkcs12048SHA512::Signature::import(Encoded, Encoding); case SignatureAlgorithm::RSA_PKCS1_3072_SHA384: return RsaPkcs13072SHA384::Signature::import(Encoded, Encoding); case SignatureAlgorithm::RSA_PKCS1_3072_SHA512: return RsaPkcs13072SHA512::Signature::import(Encoded, Encoding); case SignatureAlgorithm::RSA_PKCS1_4096_SHA512: return RsaPkcs14096SHA512::Signature::import(Encoded, Encoding); case SignatureAlgorithm::RSA_PSS_2048_SHA256: return RsaPss2048SHA256::Signature::import(Encoded, Encoding); case SignatureAlgorithm::RSA_PSS_2048_SHA384: return RsaPss2048SHA384::Signature::import(Encoded, Encoding); case SignatureAlgorithm::RSA_PSS_2048_SHA512: return RsaPss2048SHA512::Signature::import(Encoded, Encoding); case SignatureAlgorithm::RSA_PSS_3072_SHA384: return RsaPss3072SHA384::Signature::import(Encoded, Encoding); case SignatureAlgorithm::RSA_PSS_3072_SHA512: return RsaPss3072SHA512::Signature::import(Encoded, Encoding); case SignatureAlgorithm::RSA_PSS_4096_SHA512: return RsaPss4096SHA512::Signature::import(Encoded, Encoding); default: assumingUnreachable(); } } } // namespace Signatures } // namespace WASICrypto } // namespace Host } // namespace WasmEdge
42.745455
70
0.792003
sonder-joker
ab41be26b1679bddb4179f28ff8e34468424d58f
7,340
hpp
C++
libraries/db/include/graphene/db/object_database.hpp
VinChain/VINchain-blockchain
c52ec3bf67c6d4700bbaf5ec903185d31a2d63ec
[ "MIT" ]
15
2018-04-13T18:40:35.000Z
2021-03-17T00:11:00.000Z
libraries/db/include/graphene/db/object_database.hpp
VinChain/VINchain-blockchain
c52ec3bf67c6d4700bbaf5ec903185d31a2d63ec
[ "MIT" ]
null
null
null
libraries/db/include/graphene/db/object_database.hpp
VinChain/VINchain-blockchain
c52ec3bf67c6d4700bbaf5ec903185d31a2d63ec
[ "MIT" ]
3
2018-05-15T18:38:53.000Z
2022-01-14T18:36:04.000Z
/* * Copyright (c) 2015 Cryptonomex, Inc., and contributors. * * The MIT License * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #pragma once #include <graphene/db/object.hpp> #include <graphene/db/index.hpp> #include <graphene/db/undo_database.hpp> #include <fc/log/logger.hpp> #include <map> namespace graphene { namespace db { /** * @class object_database * @brief maintains a set of indexed objects that can be modified with multi-level rollback support */ class object_database { public: object_database(); ~object_database(); void reset_indexes() { _index.clear(); _index.resize(255); } void open(const fc::path &data_dir); /** * Saves the complete state of the object_database to disk, this could take a while */ void flush(); void wipe(const fc::path &data_dir); // remove from disk void close(); template<typename T, typename F> const T &create(F &&constructor) { auto &idx = get_mutable_index<T>(); return static_cast<const T &>( idx.create([&](object &o) { assert(dynamic_cast<T *>(&o)); constructor(static_cast<T &>(o)); })); } ///These methods are used to retrieve indexes on the object_database. All public index accessors are const-access only. /// @{ template<typename IndexType> const IndexType &get_index_type() const { static_assert(std::is_base_of<index, IndexType>::value, "Type must be an index type"); return static_cast<const IndexType &>( get_index(IndexType::object_type::space_id, IndexType::object_type::type_id)); } template<typename T> const index &get_index() const { return get_index(T::space_id, T::type_id); } const index &get_index(uint8_t space_id, uint8_t type_id) const; const index &get_index(object_id_type id) const { return get_index(id.space(), id.type()); } /// @} const object &get_object(object_id_type id) const; const object *find_object(object_id_type id) const; /// These methods are mutators of the object_database. You must use these methods to make changes to the object_database, /// in order to maintain proper undo history. ///@{ const object &insert(object &&obj) { return get_mutable_index(obj.id).insert(std::move(obj)); } void remove(const object &obj) { get_mutable_index(obj.id).remove(obj); } template<typename T, typename Lambda> void modify(const T &obj, const Lambda &m) { get_mutable_index(obj.id).modify(obj, m); } ///@} template<typename T> static const T &cast(const object &obj) { assert(nullptr != dynamic_cast<const T *>(&obj)); return static_cast<const T &>(obj); } template<typename T> static T &cast(object &obj) { assert(nullptr != dynamic_cast<T *>(&obj)); return static_cast<T &>(obj); } template<typename T> const T &get(object_id_type id) const { const object &obj = get_object(id); assert(nullptr != dynamic_cast<const T *>(&obj)); return static_cast<const T &>(obj); } template<typename T> const T *find(object_id_type id) const { const object *obj = find_object(id); assert(!obj || nullptr != dynamic_cast<const T *>(obj)); return static_cast<const T *>(obj); } template<uint8_t SpaceID, uint8_t TypeID, typename T> const T *find(object_id <SpaceID, TypeID, T> id) const { return find<T>(id); } template<uint8_t SpaceID, uint8_t TypeID, typename T> const T &get(object_id <SpaceID, TypeID, T> id) const { return get<T>(id); } template<typename IndexType> IndexType *add_index() { typedef typename IndexType::object_type ObjectType; if (_index[ObjectType::space_id].size() <= ObjectType::type_id) _index[ObjectType::space_id].resize(255); assert(!_index[ObjectType::space_id][ObjectType::type_id]); unique_ptr <index> indexptr(new IndexType(*this)); _index[ObjectType::space_id][ObjectType::type_id] = std::move(indexptr); return static_cast<IndexType *>(_index[ObjectType::space_id][ObjectType::type_id].get()); } void pop_undo(); fc::path get_data_dir() const { return _data_dir; } /** public for testing purposes only... should be private in practice. */ undo_database _undo_db; protected: template<typename IndexType> IndexType &get_mutable_index_type() { static_assert(std::is_base_of<index, IndexType>::value, "Type must be an index type"); return static_cast<IndexType &>( get_mutable_index(IndexType::object_type::space_id, IndexType::object_type::type_id)); } template<typename T> index &get_mutable_index() { return get_mutable_index(T::space_id, T::type_id); } index &get_mutable_index(object_id_type id) { return get_mutable_index(id.space(), id.type()); } index &get_mutable_index(uint8_t space_id, uint8_t type_id); private: friend class base_primary_index; friend class undo_database; void save_undo(const object &obj); void save_undo_add(const object &obj); void save_undo_remove(const object &obj); fc::path _data_dir; vector <vector<unique_ptr < index>> > _index; }; } } // graphene::db
38.229167
133
0.585014
VinChain
ab488b7d6dc9bdadb6a4ca8e1ab2c6ff291ff485
3,435
cpp
C++
algorithms/kernel/neural_networks/layers/loss_layer/loss_layer_forward.cpp
masdevas/daal
d48d27fac50907cb47a620d9e2ce1595f466a703
[ "Apache-2.0" ]
null
null
null
algorithms/kernel/neural_networks/layers/loss_layer/loss_layer_forward.cpp
masdevas/daal
d48d27fac50907cb47a620d9e2ce1595f466a703
[ "Apache-2.0" ]
null
null
null
algorithms/kernel/neural_networks/layers/loss_layer/loss_layer_forward.cpp
masdevas/daal
d48d27fac50907cb47a620d9e2ce1595f466a703
[ "Apache-2.0" ]
1
2018-11-09T15:59:50.000Z
2018-11-09T15:59:50.000Z
/* file: loss_layer_forward.cpp */ /******************************************************************************* * Copyright 2014-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. *******************************************************************************/ /* //++ // Implementation of loss calculation algorithm and types methods. //-- */ #include "loss_layer_forward_types.h" #include "daal_strings.h" namespace daal { namespace algorithms { namespace neural_networks { namespace layers { namespace loss { namespace forward { namespace interface1 { /** Default constructor */ Input::Input(size_t nElements) : layers::forward::Input(nElements) {}; /** * Returns input Tensor of the loss layer algorithm * \param[in] id Identifier of the input tensor * \return %Input tensor that corresponds to the given identifier */ data_management::TensorPtr Input::get(forward::InputId id) const { return services::staticPointerCast<data_management::Tensor, data_management::SerializationIface>(Argument::get(id)); } /** * Sets input for the loss layer algorithm * \param[in] id Identifier of the input object * \param[in] ptr Pointer to the object */ void Input::set(InputId id, const data_management::TensorPtr &ptr) { Argument::set(id, ptr); } /** * Returns dimensions of weights tensor * \return Dimensions of weights tensor */ const services::Collection<size_t> Input::getWeightsSizes(const layers::Parameter *parameter) const { return services::Collection<size_t>(); } /** * Returns dimensions of biases tensor * \return Dimensions of biases tensor */ const services::Collection<size_t> Input::getBiasesSizes(const layers::Parameter *parameter) const { return services::Collection<size_t>(); } /** Default constructor */ Result::Result() : layers::forward::Result() {}; /** * Checks the result of the forward loss layer * \param[in] input %Input object for the loss layer * \param[in] par %Parameter of the loss layer * \param[in] method Computation method */ services::Status Result::check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *par, int method) const { const Input *in = static_cast<const Input *>(input); services::Status s; DAAL_CHECK_STATUS(s, data_management::checkTensor(in->get(layers::forward::data).get(), dataStr())); DAAL_CHECK_STATUS(s, data_management::checkTensor(get(layers::forward::value).get(), valueStr())); return s; } /** * Returns dimensions of value tensor * \return Dimensions of value tensor */ const services::Collection<size_t> Result::getValueSize(const services::Collection<size_t> &inputSize, const daal::algorithms::Parameter *par, const int method) const { return inputSize; } }// namespace interface1 }// namespace forward }// namespace loss }// namespace layers }// namespace neural_networks }// namespace algorithms }// namespace daal
29.110169
126
0.695197
masdevas
ab4994f0e23f2fbb64696a459f7c5ccaf9491818
10,507
cpp
C++
arrus/core/devices/us4r/us4oem/Us4OEMFactoryImplTest.cpp
us4useu/arrus
10487b09f556e327ddb1bec28fbaccf3b8b08064
[ "BSL-1.0", "MIT" ]
11
2021-02-04T19:56:08.000Z
2022-02-18T09:41:51.000Z
arrus/core/devices/us4r/us4oem/Us4OEMFactoryImplTest.cpp
us4useu/arrus
10487b09f556e327ddb1bec28fbaccf3b8b08064
[ "BSL-1.0", "MIT" ]
60
2020-11-06T04:59:06.000Z
2022-03-12T17:39:06.000Z
arrus/core/devices/us4r/us4oem/Us4OEMFactoryImplTest.cpp
us4useu/arrus
10487b09f556e327ddb1bec28fbaccf3b8b08064
[ "BSL-1.0", "MIT" ]
4
2021-07-22T16:13:06.000Z
2021-12-13T08:53:31.000Z
#include <gtest/gtest.h> #include <gmock/gmock.h> #include <ius4oem.h> #include "arrus/core/common/tests.h" #include "arrus/core/devices/us4r/us4oem/Us4OEMFactoryImpl.h" #include "arrus/core/devices/us4r/us4oem/tests/CommonSettings.h" #include "arrus/core/devices/us4r/tests/MockIUs4OEM.h" #include "arrus/common/logging/impl/Logging.h" namespace { using namespace arrus; using namespace arrus::devices; using namespace us4r::afe58jd18; using ::testing::_; using ::testing::FloatEq; using ::testing::Eq; using ::testing::Pointwise; using ::testing::InSequence; using ::testing::Lt; using ::testing::Gt; // Below default parameters should be conformant with CommonSettings.h struct ExpectedUs4RParameters { PGA_GAIN pgaGain = PGA_GAIN::PGA_GAIN_30dB; LNA_GAIN_GBL lnaGain = LNA_GAIN_GBL::LNA_GAIN_GBL_24dB; DIG_TGC_ATTENUATION dtgcAttValue = DIG_TGC_ATTENUATION::DIG_TGC_ATTENUATION_42dB; EN_DIG_TGC dtgcAttEnabled = EN_DIG_TGC::EN_DIG_TGC_EN; RxSettings::TGCCurve tgcSamplesNormalized = getRange<float>(0.4, 0.65, 0.0125); bool tgcEnabled = true; LPF_PROG lpfCutoff = LPF_PROG::LPF_PROG_10MHz; GBL_ACTIVE_TERM activeTerminationValue = GBL_ACTIVE_TERM::GBL_ACTIVE_TERM_50; ACTIVE_TERM_EN activeTerminationEnabled = ACTIVE_TERM_EN::ACTIVE_TERM_EN; }; class Us4OEMFactorySimpleParametersTest : public testing::TestWithParam<std::pair<TestUs4OEMSettings, ExpectedUs4RParameters>> { }; TEST_P(Us4OEMFactorySimpleParametersTest, VerifyUs4OEMFactorySimpleParameters) { std::unique_ptr<IUs4OEM> ius4oem = std::make_unique<::testing::NiceMock<MockIUs4OEM>>(); ExpectedUs4RParameters us4rParameters = GetParam().second; EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetPGAGain(us4rParameters.pgaGain)); EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetLNAGain(us4rParameters.lnaGain)); EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetDTGC(us4rParameters.dtgcAttEnabled, us4rParameters.dtgcAttValue)); EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetLPFCutoff(us4rParameters.lpfCutoff)); EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetActiveTermination(us4rParameters.activeTerminationEnabled, us4rParameters.activeTerminationValue)); Us4OEMFactoryImpl factory; factory.getUs4OEM(0, ius4oem, GetParam().first.getUs4OEMSettings()); } INSTANTIATE_TEST_CASE_P (Us4OEMFactorySetsSimpleIUs4OEMProperties, Us4OEMFactorySimpleParametersTest, testing::Values( std::pair{ARRUS_STRUCT_INIT_LIST(TestUs4OEMSettings, (x.dtgcAttenuation=42, x.tgcSamples={})), ExpectedUs4RParameters{}}, std::pair{ARRUS_STRUCT_INIT_LIST(TestUs4OEMSettings, (x.pgaGain=24, x.dtgcAttenuation=42, x.tgcSamples={})), ARRUS_STRUCT_INIT_LIST(ExpectedUs4RParameters, (x.pgaGain=PGA_GAIN::PGA_GAIN_24dB))}, std::pair{ARRUS_STRUCT_INIT_LIST(TestUs4OEMSettings, (x.lnaGain=12, x.dtgcAttenuation=42, x.tgcSamples={})), ARRUS_STRUCT_INIT_LIST(ExpectedUs4RParameters, (x.lnaGain=LNA_GAIN_GBL::LNA_GAIN_GBL_12dB))}, std::pair{ARRUS_STRUCT_INIT_LIST(TestUs4OEMSettings, (x.lpfCutoff=(int)15e6, x.dtgcAttenuation=42, x.tgcSamples={})), ARRUS_STRUCT_INIT_LIST(ExpectedUs4RParameters, (x.lpfCutoff=LPF_PROG::LPF_PROG_15MHz))} )); class Us4OEMFactoryOptionalParametersTest : public testing::TestWithParam<std::pair<TestUs4OEMSettings, ExpectedUs4RParameters>> { }; TEST_P(Us4OEMFactoryOptionalParametersTest, VerifyUs4OEMFactoryOptionalParameters) { std::unique_ptr<IUs4OEM> ius4oem = std::make_unique<::testing::NiceMock<MockIUs4OEM>>(); ExpectedUs4RParameters us4rParameters = GetParam().second; if(GetParam().first.dtgcAttenuation.has_value()) { // NO disable EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetDTGC(EN_DIG_TGC::EN_DIG_TGC_DIS, _)).Times(0); EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetDTGC(EN_DIG_TGC::EN_DIG_TGC_EN, us4rParameters.dtgcAttValue)); } else { // NO enable EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetDTGC(EN_DIG_TGC::EN_DIG_TGC_EN, _)).Times(0); EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetDTGC(EN_DIG_TGC::EN_DIG_TGC_DIS, _)); } if(GetParam().first.activeTermination.has_value()) { // NO disable EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetActiveTermination(ACTIVE_TERM_EN::ACTIVE_TERM_DIS, us4rParameters.activeTerminationValue)) .Times(0); EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetActiveTermination(ACTIVE_TERM_EN::ACTIVE_TERM_EN, us4rParameters.activeTerminationValue)); } else { // NO enable EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetActiveTermination(ACTIVE_TERM_EN::ACTIVE_TERM_EN, _)).Times(0); EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetActiveTermination(ACTIVE_TERM_EN::ACTIVE_TERM_DIS, _)); } Us4OEMFactoryImpl factory; factory.getUs4OEM(0, ius4oem, GetParam().first.getUs4OEMSettings()); } INSTANTIATE_TEST_CASE_P (Us4OEMFactorySetsOptionalIUs4OEMProperties, Us4OEMFactoryOptionalParametersTest, testing::Values( std::pair{ARRUS_STRUCT_INIT_LIST(TestUs4OEMSettings, (x.dtgcAttenuation=0, x.tgcSamples={})), ARRUS_STRUCT_INIT_LIST(ExpectedUs4RParameters, (x.dtgcAttValue=DIG_TGC_ATTENUATION::DIG_TGC_ATTENUATION_0dB))}, std::pair{ARRUS_STRUCT_INIT_LIST(TestUs4OEMSettings, (x.dtgcAttenuation={})), ExpectedUs4RParameters{}}, // Any value is accepted std::pair{ARRUS_STRUCT_INIT_LIST(TestUs4OEMSettings, (x.activeTermination=200, x.tgcSamples={})), ARRUS_STRUCT_INIT_LIST(ExpectedUs4RParameters, (x.activeTerminationValue=GBL_ACTIVE_TERM::GBL_ACTIVE_TERM_200))}, std::pair{ARRUS_STRUCT_INIT_LIST(TestUs4OEMSettings, (x.activeTermination={})), ExpectedUs4RParameters{}} )); class Us4OEMFactoryTGCSamplesTest : public testing::TestWithParam<std::pair<TestUs4OEMSettings, ExpectedUs4RParameters>> { }; TEST_P(Us4OEMFactoryTGCSamplesTest, VerifyUs4OEMFactorySimpleParameters) { std::unique_ptr<IUs4OEM> ius4oem = std::make_unique<::testing::NiceMock<MockIUs4OEM>>(); ExpectedUs4RParameters us4rParameters = GetParam().second; RxSettings::TGCCurve tgcCurve = GetParam().first.getUs4OEMSettings().getRxSettings().getTgcSamples(); if(tgcCurve.empty()) { // NO TGC enable EXPECT_CALL(GET_MOCK_PTR(ius4oem), TGCEnable()).Times(0); } else { EXPECT_CALL(GET_MOCK_PTR(ius4oem), TGCEnable()); // NO TGC disable EXPECT_CALL(GET_MOCK_PTR(ius4oem), TGCDisable()).Times(0); EXPECT_CALL(GET_MOCK_PTR(ius4oem), TGCSetSamples(Pointwise(FloatEq(), us4rParameters.tgcSamplesNormalized), _)); } Us4OEMFactoryImpl factory; factory.getUs4OEM(0, ius4oem, GetParam().first.getUs4OEMSettings()); } INSTANTIATE_TEST_CASE_P (Us4OEMFactorySetsTGCSettings, Us4OEMFactoryTGCSamplesTest, testing::Values( // NO TGC std::pair{ARRUS_STRUCT_INIT_LIST(TestUs4OEMSettings, (x.tgcSamples={})), ExpectedUs4RParameters{}}, // TGC samples set std::pair{ARRUS_STRUCT_INIT_LIST(TestUs4OEMSettings, ( x.pgaGain=30, x.lnaGain=24, x.tgcSamples={30, 35, 40}, x.isApplyCharacteristic=false)), ARRUS_STRUCT_INIT_LIST(ExpectedUs4RParameters, (x.tgcSamplesNormalized={0.4, 0.525, 0.65}))} )); // Mappings. TEST(Us4OEMFactoryTest, WorksForConsistentMapping) { // Given std::unique_ptr<IUs4OEM> ius4oem = std::make_unique<::testing::NiceMock<MockIUs4OEM>>(); // Mapping includes groups of 32 channel, each has the same permutation std::vector<uint8_t> channelMapping = getRange<uint8_t>(0, 128, 1); for(int i = 0; i < 4; ++i) { std::swap(channelMapping[i * 32], channelMapping[(i + 1) * 32 - 1]); } TestUs4OEMSettings cfg; cfg.channelMapping = std::vector<ChannelIdx>( std::begin(channelMapping), std::end(channelMapping)); Us4OEMFactoryImpl factory; // Expect EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetRxChannelMapping(_, _)).Times(0); EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetRxChannelMapping( std::vector<uint8_t>( std::begin(channelMapping), std::begin(channelMapping) + 32), 0)) .Times(1); // Run factory.getUs4OEM(0, ius4oem, cfg.getUs4OEMSettings()); } TEST(Us4OEMFactoryTest, WorksForInconsistentMapping) { // Given std::unique_ptr<IUs4OEM> ius4oem = std::make_unique<::testing::NiceMock<MockIUs4OEM>>(); // Mapping includes groups of 32 channel, each has the same permutation std::vector<uint8_t> channelMapping = getRange<uint8_t>(0, 128, 1); for(int i = 0; i < 2; ++i) { std::swap(channelMapping[i * 32], channelMapping[(i + 1) * 32 - 1]); } for(int i = 2; i < 4; ++i) { std::swap(channelMapping[i * 32 + 1], channelMapping[(i + 1) * 32 - 2]); } TestUs4OEMSettings cfg; cfg.channelMapping = std::vector<ChannelIdx>( std::begin(channelMapping), std::end(channelMapping)); Us4OEMFactoryImpl factory; // Expect EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetRxChannelMapping(_, _)).Times(0); // Run factory.getUs4OEM(0, ius4oem, cfg.getUs4OEMSettings()); } // Tx channel mapping TEST(Us4OEMFactoryTest, WorksForTxChannelMapping) { // Given std::unique_ptr<IUs4OEM> ius4oem = std::make_unique<::testing::NiceMock<MockIUs4OEM>>(); std::vector<ChannelIdx> channelMapping = getRange<ChannelIdx>(0, 128, 1); TestUs4OEMSettings cfg; cfg.channelMapping = channelMapping; Us4OEMFactoryImpl factory; // Expect { InSequence seq; for(ChannelIdx i = 0; i < Us4OEMImpl::N_TX_CHANNELS; ++i) { EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetTxChannelMapping(i, channelMapping[i])); } } // No other calls should be made EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetTxChannelMapping(Lt(0), _)) .Times(0); EXPECT_CALL(GET_MOCK_PTR(ius4oem), SetTxChannelMapping(Gt(127), _)) .Times(0); // Run factory.getUs4OEM(0, ius4oem, cfg.getUs4OEMSettings()); } } int main(int argc, char **argv) { ARRUS_INIT_TEST_LOG(arrus::Logging); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
42.196787
130
0.696488
us4useu
ab4ad0701b8784476901667af4898b4831043630
2,728
hpp
C++
include/gba/util/tiles.hpp
felixjones/gba-hpp
66c84e2261c9a2d8e678e8cefb4f43f8c1c13cf3
[ "Zlib" ]
5
2022-03-12T19:16:58.000Z
2022-03-24T20:35:45.000Z
include/gba/util/tiles.hpp
felixjones/gba-hpp
66c84e2261c9a2d8e678e8cefb4f43f8c1c13cf3
[ "Zlib" ]
null
null
null
include/gba/util/tiles.hpp
felixjones/gba-hpp
66c84e2261c9a2d8e678e8cefb4f43f8c1c13cf3
[ "Zlib" ]
null
null
null
/* =============================================================================== Copyright (C) 2022 gba-hpp contributors For conditions of distribution and use, see copyright notice in LICENSE.md =============================================================================== */ #ifndef GBAXX_UTIL_TILES_HPP #define GBAXX_UTIL_TILES_HPP #include <array> #include <cstddef> #include <gba/vectype.hpp> #include <gba/util/array_traits.hpp> #include <gba/util/byte_array.hpp> namespace gba::util { namespace detail { consteval auto tile_next_row(auto x) noexcept { return (x + 7) & -8; } template <std::size_t Bits> requires IsPowerOfTwo<Bits> && (Bits <= 8) consteval auto make_tile(const ArrayOf<char> auto& palette, const ArrayOf<char> auto& bitmap) noexcept { constexpr auto palLen = util::array_size<decltype(palette)> - 1; // Exclude null byte static_assert(palLen <= (1u << Bits)); std::size_t len = 0; std::array<std::byte, 8 * 8> tile{}; for (const auto& pixel : bitmap) { if (pixel == 0) { break; } if (pixel == '\n') { len = detail::tile_next_row(len); continue; } for (std::size_t i = 0; i < palLen; ++i) { if (palette[i] == 0) { break; } if (palette[i] == pixel) { tile[len++] = std::byte(i); break; } } } if constexpr (Bits == 8) { return tile; } const auto steps = 8u / Bits; std::array<std::byte, Bits * 8> data{}; for (std::size_t i = 0; i < data.size(); ++i) { std::byte accum{}; for (std::size_t j = 0; j < steps; ++j) { accum |= tile[i * steps + j] << (j * Bits); } data[i] = accum; } return data; } } // namespace detail consteval auto make_tile_1bpp(const ArrayOf<char> auto& palette, const ArrayOf<char> auto& bitmap) noexcept { return detail::make_tile<1>(palette, bitmap); } consteval auto make_tile_2bpp(const ArrayOf<char> auto& palette, const ArrayOf<char> auto& bitmap) noexcept { return detail::make_tile<2>(palette, bitmap); } consteval auto make_tile_4bpp(const ArrayOf<char> auto& palette, const ArrayOf<char> auto& bitmap) noexcept { return detail::make_tile<4>(palette, bitmap); } consteval auto make_tile_8bpp(const ArrayOf<char> auto& palette, const ArrayOf<char> auto& bitmap) noexcept { return detail::make_tile<8>(palette, bitmap); } } // namespace gba::util #endif // define GBAXX_UTIL_TILES_HPP
28.715789
109
0.533358
felixjones
ab4eb62f71ac3f2af1500cc72b368bf6b982cb62
659
cpp
C++
samples/dnnMmodFaceLandmarkDetection/src/dnnMmodFaceLandmarkDetectionApp.cpp
kino-dome/Cinder-dlib
79601367cd6761566911ce6a0ea33b45507359b9
[ "BSD-2-Clause" ]
1
2019-03-07T09:12:32.000Z
2019-03-07T09:12:32.000Z
samples/dnnMmodFaceLandmarkDetection/src/dnnMmodFaceLandmarkDetectionApp.cpp
kino-dome/Cinder-dlib
79601367cd6761566911ce6a0ea33b45507359b9
[ "BSD-2-Clause" ]
null
null
null
samples/dnnMmodFaceLandmarkDetection/src/dnnMmodFaceLandmarkDetectionApp.cpp
kino-dome/Cinder-dlib
79601367cd6761566911ce6a0ea33b45507359b9
[ "BSD-2-Clause" ]
null
null
null
#include "cinder/app/App.h" #include "cinder/app/RendererGl.h" #include "cinder/gl/gl.h" using namespace ci; using namespace ci::app; using namespace std; class dnnMmodFaceLandmarkDetectionApp : public App { public: void setup() override; void mouseDown( MouseEvent event ) override; void update() override; void draw() override; }; void dnnMmodFaceLandmarkDetectionApp::setup() { } void dnnMmodFaceLandmarkDetectionApp::mouseDown( MouseEvent event ) { } void dnnMmodFaceLandmarkDetectionApp::update() { } void dnnMmodFaceLandmarkDetectionApp::draw() { gl::clear( Color( 0, 0, 0 ) ); } CINDER_APP( dnnMmodFaceLandmarkDetectionApp, RendererGl )
18.828571
67
0.758725
kino-dome
ab503cf1985127b70b5978ccc29657a9d3ccb5a8
4,913
cpp
C++
SysInfo/CpuModelNumber.cpp
eyalfishler/CrystalCPUID
eb6692e2b563351ecdf7f8f247a4f71dc6456738
[ "BSD-2-Clause" ]
19
2016-02-19T02:14:16.000Z
2021-01-25T23:57:13.000Z
SysInfo/CpuModelNumber.cpp
eyalfishler/CrystalCPUID
eb6692e2b563351ecdf7f8f247a4f71dc6456738
[ "BSD-2-Clause" ]
1
2018-10-26T03:28:23.000Z
2018-10-27T03:32:03.000Z
SysInfo/CpuModelNumber.cpp
eyalfishler/CrystalCPUID
eb6692e2b563351ecdf7f8f247a4f71dc6456738
[ "BSD-2-Clause" ]
10
2015-06-01T03:39:34.000Z
2020-07-19T01:40:04.000Z
/*---------------------------------------------------------------------------*/ // Author : hiyohiyo // Mail : hiyohiyo@crystalmark.info // Web : http://crystalmark.info/ // License : The modified BSD license // // Copyright 2007 hiyohiyo, All rights reserved. /*---------------------------------------------------------------------------*/ #include "CpuInfo.h" /* ////////////////////////////////////////////////////////////////////// // Set Model Number for Pentium 4/D / Celeron D (P4 core) ////////////////////////////////////////////////////////////////////// void CCpuInfo::SetModelNumberP4() { } ////////////////////////////////////////////////////////////////////// // Set Model Number for Pentium M / Celeron M (P6 core) ////////////////////////////////////////////////////////////////////// void CCpuInfo::SetModelNumberP6() { } ////////////////////////////////////////////////////////////////////// // Set Model Number for Core/Core 2 ////////////////////////////////////////////////////////////////////// void CCpuInfo::SetModelNumberCore2() { if(PhysicalCoreNum == 4){ if(ClockOri == 2400.00){ wsprintf(ModelNumber, " Q6600"); }else if(ClockOri == 2666.66){ wsprintf(ModelNumber, " Q6700"); } }else if(PhysicalCoreNum == 2){ }else{ } } */ ////////////////////////////////////////////////////////////////////// // Set Model Number for K8 ////////////////////////////////////////////////////////////////////// void CCpuInfo::SetModelNumberK8() { if(ModelEx >=4){ if(SocketID == 0x0){ // Socket S1g1 switch(BrandID) { case 0x2: if(PhysicalCoreNum == 2){ wsprintf(ModelNumber, " TL-%d", 29 + BrandIDNN); }else{ wsprintf(ModelNumber, " MK-%d", 29 + BrandIDNN); } break; case 0x3: break; default: break; } }else if(SocketID == 0x1){ // Socket F switch(BrandID) { case 0x1: wsprintf(ModelNumber, " 22%d", -1 + BrandIDNN); if(PwrLmt == 0x6){ strcat(ModelNumber, " HE"); }else if(PwrLmt == 0xC){ strcat(ModelNumber, " SE"); } break; case 0x4: wsprintf(ModelNumber, " 82%d", -1 + BrandIDNN); if(PwrLmt == 0x6){ strcat(ModelNumber, " HE"); }else if(PwrLmt == 0xC){ strcat(ModelNumber, " SE"); } break; default: break; } }else{ // if(SocketID == 0x3) Socket AM2 switch(BrandID) { case 0x1: wsprintf(ModelNumber, " 12%d", -1 + BrandIDNN); if(PwrLmt == 0x6){ // undefined strcat(ModelNumber, " HE"); }else if(PwrLmt == 0xC){ strcat(ModelNumber, " SE"); } break; case 0x4: // Athlon 64, Athlon 64 X2 if(BrandIDNN < 9){ // < Athlon 64 X2 3400+ BrandIDNN += 32; // bit15 = 1 } wsprintf(ModelNumber, " %d00+", 15 + CmpCap * 10 + BrandIDNN); break; case 0x6: // Sempron wsprintf(ModelNumber, " %d00+", 15 + CmpCap * 10 + BrandIDNN); break; case 0x5: // Athlon 64 FX wsprintf(ModelNumber, "-%d", 57 + BrandIDNN); break; default: strcpy(NameSysInfo, "Engineering Sample"); break; } } return ; } switch(BrandID) { case 0: break; case 0x6: if(MultiplierOri == 14.0){ wsprintf(ModelNumber, "-62"); }else if(MultiplierOri == 13.0){ wsprintf(ModelNumber, "-60"); }else{ wsprintf(ModelNumber, ""); } break; /* Type XX */ case 0x4: case 0x5: case 0x8: case 0x9: case 0x1D: case 0x1E: case 0x20: wsprintf(ModelNumber, " %d00+", BrandIDNN + 22); break; case 0xA: case 0xB: wsprintf(ModelNumber, "-%d", BrandIDNN + 22); break; /* Type YY */ case 0xC: case 0xD: case 0xE: case 0xF: wsprintf(ModelNumber, " 1%d", 2 * BrandIDNN + 38); break; case 0x10: case 0x11: case 0x12: case 0x13: wsprintf(ModelNumber, " 2%d", 2 * BrandIDNN + 38); break; case 0x14: case 0x15: case 0x16: case 0x17: wsprintf(ModelNumber, " 8%d", 2 * BrandIDNN + 38); break; /* Type EE */ case 0x18: wsprintf(ModelNumber, " %d00+", BrandIDNN + 9); break; /* Type TT */ case 0x21: case 0x22: case 0x23: case 0x26: wsprintf(ModelNumber, " %d00+", BrandIDNN + 24); break; /* Type ZZ */ case 0x24: wsprintf(ModelNumber, "-%d", BrandIDNN + 24); break; /* Type RR */ case 0x29: case 0x2C: case 0x2D: case 0x2E: case 0x2F: case 0x38: wsprintf(ModelNumber, " 1%d", 5 * BrandIDNN + 45); break; case 0x2A: case 0x30: case 0x31: case 0x32: case 0x33: case 0x39: wsprintf(ModelNumber, " 2%d", 5 * BrandIDNN + 45); break; case 0x2B: case 0x34: case 0x35: case 0x36: case 0x37: case 0x3A: wsprintf(ModelNumber, " 8%d", 5 * BrandIDNN + 45); break; default: wsprintf(ModelNumber, ""); break; } }
22.536697
80
0.478526
eyalfishler
ab51f1443d5a6f07c13a4eb20e865dac61498b50
20,766
cpp
C++
qhexview.cpp
xmikula/QHexView
ac74ab5aee8c43b4b0701496b86d8a02c898edf4
[ "MIT" ]
null
null
null
qhexview.cpp
xmikula/QHexView
ac74ab5aee8c43b4b0701496b86d8a02c898edf4
[ "MIT" ]
null
null
null
qhexview.cpp
xmikula/QHexView
ac74ab5aee8c43b4b0701496b86d8a02c898edf4
[ "MIT" ]
null
null
null
#include "qhexview.h" #include "document/buffer/qmemorybuffer.h" #include <QApplication> #include <QDebug> #include <QFontDatabase> #include <QHelpEvent> #include <QPaintEvent> #include <QPainter> #include <QScrollBar> #include <QToolTip> #include <cmath> #define CURSOR_BLINK_INTERVAL 500 // ms #define DOCUMENT_WHEEL_LINES 10 QHexView::QHexView (QWidget *parent) : QAbstractScrollArea (parent), m_document (nullptr), m_renderer (nullptr), m_readonly (false) { QFont f = QFontDatabase::systemFont (QFontDatabase::FixedFont); if (f.styleHint () != QFont::TypeWriter) { f.setFamily ("Monospace"); // Force Monospaced font f.setStyleHint (QFont::TypeWriter); } this->setFont (f); this->setFocusPolicy (Qt::StrongFocus); this->setMouseTracking (true); this->verticalScrollBar ()->setSingleStep (1); this->verticalScrollBar ()->setPageStep (1); m_blinktimer = new QTimer (this); m_blinktimer->setInterval (CURSOR_BLINK_INTERVAL); connect (m_blinktimer, &QTimer::timeout, this, &QHexView::blinkCursor); this->setDocument ( QHexDocument::fromMemory<QMemoryBuffer> (QByteArray (), this)); } QHexDocument * QHexView::document () { return m_document; } void QHexView::setDocument (QHexDocument *document) { if (m_renderer) m_renderer->deleteLater (); if (m_document) m_document->deleteLater (); m_document = document; m_renderer = new QHexRenderer (m_document, this->fontMetrics (), this); connect (m_document, &QHexDocument::documentChanged, this, [&] () { this->adjustScrollBars (); this->viewport ()->update (); }); connect (m_document->cursor (), &QHexCursor::positionChanged, this, &QHexView::moveToSelection); connect (m_document->cursor (), &QHexCursor::insertionModeChanged, this, &QHexView::renderCurrentLine); this->adjustScrollBars (); this->viewport ()->update (); } void QHexView::setReadOnly (bool b) { m_readonly = b; if (m_document) m_document->cursor ()->setInsertionMode (QHexCursor::OverwriteMode); } bool QHexView::event (QEvent *e) { if (m_document && m_renderer && (e->type () == QEvent::ToolTip)) { QHelpEvent *helpevent = static_cast<QHelpEvent *> (e); QHexPosition position; QPoint abspos = absolutePosition (helpevent->pos ()); if (m_renderer->hitTest (abspos, &position, this->firstVisibleLine ())) { QString comments = m_document->metadata ()->comments ( position.line, position.column); if (!comments.isEmpty ()) QToolTip::showText (helpevent->globalPos (), comments, this); } return true; } return QAbstractScrollArea::event (e); } void QHexView::keyPressEvent (QKeyEvent *e) { if (!m_renderer || !m_document) { QAbstractScrollArea::keyPressEvent (e); return; } QHexCursor *cur = m_document->cursor (); m_blinktimer->stop (); m_renderer->enableCursor (); bool handled = this->processMove (cur, e); if (!handled) handled = this->processAction (cur, e); if (!handled) handled = this->processTextInput (cur, e); if (!handled) QAbstractScrollArea::keyPressEvent (e); m_blinktimer->start (); } QPoint QHexView::absolutePosition (const QPoint &pos) const { QPoint shift (horizontalScrollBar ()->value (), 0); QPoint abs = pos + shift; return abs; } void QHexView::mousePressEvent (QMouseEvent *e) { QAbstractScrollArea::mousePressEvent (e); if (!m_renderer || (e->buttons () != Qt::LeftButton)) return; QHexPosition position; QPoint abspos = absolutePosition (e->pos ()); if (!m_renderer->hitTest (abspos, &position, this->firstVisibleLine ())) return; m_renderer->selectArea (abspos); if (m_renderer->editableArea (m_renderer->selectedArea ())) { m_document->cursor ()->moveTo (position); } e->accept (); } void QHexView::mouseMoveEvent (QMouseEvent *e) { QAbstractScrollArea::mouseMoveEvent (e); if (!m_renderer || !m_document) return; QPoint abspos = absolutePosition (e->pos ()); if (e->buttons () == Qt::LeftButton) { if (m_blinktimer->isActive ()) { m_blinktimer->stop (); m_renderer->enableCursor (false); } QHexCursor *cursor = m_document->cursor (); QHexPosition position; if (!m_renderer->hitTest (abspos, &position, this->firstVisibleLine ())) return; cursor->select (position.line, position.column, 0); e->accept (); } if (e->buttons () != Qt::NoButton) return; int hittest = m_renderer->hitTestArea (abspos); if (m_renderer->editableArea (hittest)) this->setCursor (Qt::IBeamCursor); else this->setCursor (Qt::ArrowCursor); } void QHexView::mouseReleaseEvent (QMouseEvent *e) { QAbstractScrollArea::mouseReleaseEvent (e); if (e->button () != Qt::LeftButton) return; if (!m_blinktimer->isActive ()) m_blinktimer->start (); e->accept (); } void QHexView::focusInEvent (QFocusEvent *e) { QAbstractScrollArea::focusInEvent (e); if (!m_renderer) return; m_renderer->enableCursor (); m_blinktimer->start (); } void QHexView::focusOutEvent (QFocusEvent *e) { QAbstractScrollArea::focusOutEvent (e); if (!m_renderer) return; m_blinktimer->stop (); m_renderer->enableCursor (false); } void QHexView::wheelEvent (QWheelEvent *e) { if (e->angleDelta ().y () == 0) { int value = this->verticalScrollBar ()->value (); qDebug () << "Current value: " << value; if (e->angleDelta ().x () < 0) // Scroll Down this->verticalScrollBar ()->setValue (value + DOCUMENT_WHEEL_LINES); else if (e->angleDelta ().x () > 0) // Scroll Up this->verticalScrollBar ()->setValue (value - DOCUMENT_WHEEL_LINES); return; } QAbstractScrollArea::wheelEvent (e); } void QHexView::resizeEvent (QResizeEvent *e) { QAbstractScrollArea::resizeEvent (e); this->adjustScrollBars (); } void QHexView::paintEvent (QPaintEvent *e) { if (!m_document) return; QPainter painter (this->viewport ()); painter.setFont (this->font ()); const QRect &r = e->rect (); const quint64 firstVisible = this->firstVisibleLine (); const int lineHeight = m_renderer->lineHeight (); const int headerCount = m_renderer->headerLineCount (); // these are lines from the point of view of the visible rect // where the first "headerCount" are taken by the header const int first = (r.top () / lineHeight); // included const int lastPlusOne = (r.bottom () / lineHeight) + 1; // excluded // compute document lines, adding firstVisible and removing the header // the max is necessary if the rect covers the header const quint64 begin = firstVisible + std::max (first - headerCount, 0); const quint64 end = firstVisible + std::max (lastPlusOne - headerCount, 0); painter.save (); painter.translate (-this->horizontalScrollBar ()->value (), 0); m_renderer->render (&painter, begin, end, firstVisible); m_renderer->renderFrame (&painter); painter.restore (); } void QHexView::moveToSelection () { QHexCursor *cur = m_document->cursor (); if (!this->isLineVisible (cur->currentLine ())) { QScrollBar *vscrollbar = this->verticalScrollBar (); int scrollPos = static_cast<int> ( std::max (quint64 (0), (cur->currentLine () - this->visibleLines () / 2)) / documentSizeFactor ()); vscrollbar->setValue (scrollPos); } else this->viewport ()->update (); } void QHexView::blinkCursor () { if (!m_renderer) return; m_renderer->blinkCursor (); this->renderCurrentLine (); } void QHexView::moveNext (bool select) { QHexCursor *cur = m_document->cursor (); quint64 line = cur->currentLine (); int column = cur->currentColumn (); bool lastcell = (line >= m_renderer->documentLastLine ()) && (column >= m_renderer->documentLastColumn ()); if ((m_renderer->selectedArea () == QHexRenderer::AsciiArea) && lastcell) return; int nibbleindex = cur->currentNibble (); if (m_renderer->selectedArea () == QHexRenderer::HexArea) { if (lastcell && !nibbleindex) return; if (cur->position ().offset () >= m_document->length () && nibbleindex) return; } if ((m_renderer->selectedArea () == QHexRenderer::HexArea)) { nibbleindex++; nibbleindex %= 2; if (nibbleindex) column++; } else { nibbleindex = 1; column++; } if (column > m_renderer->hexLineWidth () - 1) { line = std::min (m_renderer->documentLastLine (), line + 1); column = 0; nibbleindex = 1; } if (select) cur->select (line, std::min (m_renderer->hexLineWidth () - 1, column), nibbleindex); else cur->moveTo (line, std::min (m_renderer->hexLineWidth () - 1, column), nibbleindex); } void QHexView::movePrevious (bool select) { QHexCursor *cur = m_document->cursor (); quint64 line = cur->currentLine (); int column = cur->currentColumn (); bool firstcell = !line && !column; if ((m_renderer->selectedArea () == QHexRenderer::AsciiArea) && firstcell) return; int nibbleindex = cur->currentNibble (); if ((m_renderer->selectedArea () == QHexRenderer::HexArea) && firstcell && nibbleindex) return; if ((m_renderer->selectedArea () == QHexRenderer::HexArea)) { nibbleindex--; nibbleindex %= 2; if (!nibbleindex) column--; } else { nibbleindex = 1; column--; } if (column < 0) { line = std::max (quint64 (0), line - 1); column = m_renderer->hexLineWidth () - 1; nibbleindex = 0; } if (select) cur->select (line, std::max (0, column), nibbleindex); else cur->moveTo (line, std::max (0, column), nibbleindex); } void QHexView::renderCurrentLine () { if (!m_document) return; this->renderLine (m_document->cursor ()->currentLine ()); } bool QHexView::processAction (QHexCursor *cur, QKeyEvent *e) { if (m_readonly) return false; if (e->modifiers () != Qt::NoModifier) { if (e->matches (QKeySequence::SelectAll)) { m_document->cursor ()->moveTo (0, 0); m_document->cursor ()->select (m_renderer->documentLastLine (), m_renderer->documentLastColumn () - 1); } else if (e->matches (QKeySequence::Undo)) m_document->undo (); else if (e->matches (QKeySequence::Redo)) m_document->redo (); else if (e->matches (QKeySequence::Cut)) m_document->cut ( (m_renderer->selectedArea () == QHexRenderer::HexArea)); else if (e->matches (QKeySequence::Copy)) m_document->copy ( (m_renderer->selectedArea () == QHexRenderer::HexArea)); else if (e->matches (QKeySequence::Paste)) m_document->paste ( (m_renderer->selectedArea () == QHexRenderer::HexArea)); else return false; return true; } if ((e->key () == Qt::Key_Backspace) || (e->key () == Qt::Key_Delete)) { if (!cur->hasSelection ()) { const QHexPosition &pos = cur->position (); if (pos.offset () <= 0) return true; if (e->key () == Qt::Key_Backspace) m_document->remove (cur->position ().offset () - 1, 1); else m_document->remove (cur->position ().offset (), 1); } else { QHexPosition oldpos = cur->selectionStart (); m_document->removeSelection (); cur->moveTo (oldpos.line, oldpos.column + 1); } if (e->key () == Qt::Key_Backspace) { if (m_renderer->selectedArea () == QHexRenderer::HexArea) this->movePrevious (); this->movePrevious (); } } else if (e->key () == Qt::Key_Insert) cur->switchInsertionMode (); else return false; return true; } bool QHexView::processMove (QHexCursor *cur, QKeyEvent *e) { if (e->matches (QKeySequence::MoveToNextChar) || e->matches (QKeySequence::SelectNextChar)) this->moveNext (e->matches (QKeySequence::SelectNextChar)); else if (e->matches (QKeySequence::MoveToPreviousChar) || e->matches (QKeySequence::SelectPreviousChar)) this->movePrevious (e->matches (QKeySequence::SelectPreviousChar)); else if (e->matches (QKeySequence::MoveToNextLine) || e->matches (QKeySequence::SelectNextLine)) { if (m_renderer->documentLastLine () == cur->currentLine ()) return true; int nextline = cur->currentLine () + 1; if (e->matches (QKeySequence::MoveToNextLine)) cur->moveTo (nextline, cur->currentColumn ()); else cur->select (nextline, cur->currentColumn ()); } else if (e->matches (QKeySequence::MoveToPreviousLine) || e->matches (QKeySequence::SelectPreviousLine)) { if (!cur->currentLine ()) return true; quint64 prevline = cur->currentLine () - 1; if (e->matches (QKeySequence::MoveToPreviousLine)) cur->moveTo (prevline, cur->currentColumn ()); else cur->select (prevline, cur->currentColumn ()); } else if (e->matches (QKeySequence::MoveToNextPage) || e->matches (QKeySequence::SelectNextPage)) { if (m_renderer->documentLastLine () == cur->currentLine ()) return true; int pageline = std::min (m_renderer->documentLastLine (), cur->currentLine () + this->visibleLines ()); if (e->matches (QKeySequence::MoveToNextPage)) cur->moveTo (pageline, cur->currentColumn ()); else cur->select (pageline, cur->currentColumn ()); } else if (e->matches (QKeySequence::MoveToPreviousPage) || e->matches (QKeySequence::SelectPreviousPage)) { if (!cur->currentLine ()) return true; quint64 pageline = std::max (quint64 (0), cur->currentLine () - this->visibleLines ()); if (e->matches (QKeySequence::MoveToPreviousPage)) cur->moveTo (pageline, cur->currentColumn ()); else cur->select (pageline, cur->currentColumn ()); } else if (e->matches (QKeySequence::MoveToStartOfDocument) || e->matches (QKeySequence::SelectStartOfDocument)) { if (!cur->currentLine ()) return true; if (e->matches (QKeySequence::MoveToStartOfDocument)) cur->moveTo (0, 0); else cur->select (0, 0); } else if (e->matches (QKeySequence::MoveToEndOfDocument) || e->matches (QKeySequence::SelectEndOfDocument)) { if (m_renderer->documentLastLine () == cur->currentLine ()) return true; if (e->matches (QKeySequence::MoveToEndOfDocument)) cur->moveTo (m_renderer->documentLastLine (), m_renderer->documentLastColumn ()); else cur->select (m_renderer->documentLastLine (), m_renderer->documentLastColumn ()); } else if (e->matches (QKeySequence::MoveToStartOfLine) || e->matches (QKeySequence::SelectStartOfLine)) { if (e->matches (QKeySequence::MoveToStartOfLine)) cur->moveTo (cur->currentLine (), 0); else cur->select (cur->currentLine (), 0); } else if (e->matches (QKeySequence::MoveToEndOfLine) || e->matches (QKeySequence::SelectEndOfLine)) { if (e->matches (QKeySequence::MoveToEndOfLine)) { if (cur->currentLine () == m_renderer->documentLastLine ()) cur->moveTo (cur->currentLine (), m_renderer->documentLastColumn ()); else cur->moveTo (cur->currentLine (), m_renderer->hexLineWidth () - 1, 0); } else { if (cur->currentLine () == m_renderer->documentLastLine ()) cur->select (cur->currentLine (), m_renderer->documentLastColumn ()); else cur->select (cur->currentLine (), m_renderer->hexLineWidth () - 1, 0); } } else return false; return true; } bool QHexView::processTextInput (QHexCursor *cur, QKeyEvent *e) { if (m_readonly || (e->modifiers () & Qt::ControlModifier)) return false; uchar key = static_cast<uchar> (e->text ()[0].toLatin1 ()); if ((m_renderer->selectedArea () == QHexRenderer::HexArea)) { if (!((key >= '0' && key <= '9') || (key >= 'a' && key <= 'f'))) // Check if is a Hex Char return false; uchar val = static_cast<uchar> ( QString (static_cast<char> (key)).toUInt (nullptr, 16)); m_document->removeSelection (); if (m_document->atEnd () || (cur->currentNibble () && (cur->insertionMode () == QHexCursor::InsertMode))) { m_document->insert (cur->position ().offset (), val << 4); // X0 byte this->moveNext (); return true; } uchar ch = static_cast<uchar> (m_document->at (cur->position ().offset ())); if (cur->currentNibble ()) // X0 val = (ch & 0x0F) | (val << 4); else // 0X val = (ch & 0xF0) | val; m_document->replace (cur->position ().offset (), val); this->moveNext (); return true; } if ((m_renderer->selectedArea () == QHexRenderer::AsciiArea)) { if (!(key >= 0x20 && key <= 0x7E)) // Check if is a Printable Char return false; m_document->removeSelection (); if (!m_document->atEnd () && (cur->insertionMode () == QHexCursor::OverwriteMode)) m_document->replace (cur->position ().offset (), key); else m_document->insert (cur->position ().offset (), key); QKeyEvent keyevent (QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier); qApp->sendEvent (this, &keyevent); return true; } return false; } void QHexView::adjustScrollBars () { QScrollBar *vscrollbar = this->verticalScrollBar (); int sizeFactor = this->documentSizeFactor (); vscrollbar->setSingleStep (sizeFactor); quint64 docLines = m_renderer->documentLines (); quint64 visLines = this->visibleLines (); if (docLines > visLines) { this->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn); vscrollbar->setMaximum ( static_cast<int> ((docLines - visLines) / sizeFactor + 1)); } else { this->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff); vscrollbar->setValue (0); vscrollbar->setMaximum (static_cast<int> (docLines)); } QScrollBar *hscrollbar = this->horizontalScrollBar (); int documentWidth = m_renderer->documentWidth (); int viewportWidth = viewport ()->width (); if (documentWidth > viewportWidth) { this->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn); // +1 to see the rightmost vertical line, +2 seems more pleasant to the // eyes hscrollbar->setMaximum (documentWidth - viewportWidth + 2); } else { this->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); hscrollbar->setValue (0); hscrollbar->setMaximum (documentWidth); } } void QHexView::renderLine (quint64 line) { if (!this->isLineVisible (line)) return; this->viewport ()->update ( /*m_renderer->getLineRect(line, this->firstVisibleLine())*/); } quint64 QHexView::firstVisibleLine () const { quint64 value = quint64 (this->verticalScrollBar ()->value ()) * documentSizeFactor (); return value; } quint64 QHexView::lastVisibleLine () const { return this->firstVisibleLine () + this->visibleLines () - 1; } quint64 QHexView::visibleLines () const { int visLines = std::ceil (this->height () / m_renderer->lineHeight ()) - m_renderer->headerLineCount (); return std::min (quint64 (visLines), m_renderer->documentLines ()); } bool QHexView::isLineVisible (quint64 line) const { if (!m_document) return false; if (line < this->firstVisibleLine ()) return false; if (line > this->lastVisibleLine ()) return false; return true; } int QHexView::documentSizeFactor () const { int factor = 1; if (m_document) { quint64 docLines = m_renderer->documentLines (); if (docLines >= INT_MAX) { factor = static_cast<int> (docLines / INT_MAX) + 1; } } return factor; } void QHexView::offset_jump (quint64 value) { this->verticalScrollBar ()->setValue ( static_cast<int> (value / 16 / documentSizeFactor ())); }
26.022556
79
0.608446
xmikula
ab52169cfe7b90242ba9110652f1da45dfb2c856
9,397
cpp
C++
core/lib/soci_sqlite3/session.cpp
RomanWlm/lib-ledger-core
8c068fccb074c516096abb818a4e20786e02318b
[ "MIT" ]
92
2016-11-13T01:28:34.000Z
2022-03-25T01:11:37.000Z
core/lib/soci_sqlite3/session.cpp
RomanWlm/lib-ledger-core
8c068fccb074c516096abb818a4e20786e02318b
[ "MIT" ]
242
2016-11-28T11:13:09.000Z
2022-03-04T13:02:53.000Z
core/lib/soci_sqlite3/session.cpp
RomanWlm/lib-ledger-core
8c068fccb074c516096abb818a4e20786e02318b
[ "MIT" ]
91
2017-06-20T10:35:28.000Z
2022-03-09T14:15:40.000Z
// // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, David Courtney // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "soci-sqlite3.h" #include <connection-parameters.h> #include <sstream> #include <string> #include <cstdio> #include <cstring> #ifdef _MSC_VER #pragma warning(disable:4355) #endif using namespace soci; using namespace soci::details; using namespace sqlite_api; namespace // anonymous { // helper function for hardcoded queries void execute_hardcoded(sqlite_api::sqlite3* conn, char const* const query, char const* const errMsg) { char *zErrMsg = 0; int const res = sqlite3_exec(conn, query, 0, 0, &zErrMsg); if (res != SQLITE_OK) { std::ostringstream ss; ss << errMsg << " " << zErrMsg; sqlite3_free(zErrMsg); throw sqlite3_soci_error(ss.str(), res); } } void check_sqlite_err(sqlite_api::sqlite3* conn, int res, char const* const errMsg) { if (SQLITE_OK != res) { const char *zErrMsg = sqlite3_errmsg(conn); std::ostringstream ss; ss << errMsg << zErrMsg; throw sqlite3_soci_error(ss.str(), res); } } void post_connection_helper(sqlite_api::sqlite3* conn, const std::string &dbname, int connection_flags, int timeout, const std::string &synchronous) { int res = sqlite3_open_v2(dbname.c_str(), &conn, connection_flags, NULL); check_sqlite_err(conn, res, "Cannot establish connection to the database. "); if (!synchronous.empty()) { std::string const query("pragma synchronous=" + synchronous); std::string const errMsg("Query failed: " + query); execute_hardcoded(conn, query.c_str(), errMsg.c_str()); } res = sqlite3_busy_timeout(conn, timeout * 1000); check_sqlite_err(conn, res, "Failed to set busy timeout for connection. "); } void sqlcipher_export(sqlite_api::sqlite3* conn, int flags, int timeout, const std::string &synchronous, const std::string &exportQuery, const std::string &dbName, const std::string &newDbName, const std::string &msgError, const std::string &newPassKey) { execute_hardcoded(conn, exportQuery.c_str(), msgError.c_str()); auto r = sqlite3_close_v2(conn); if (r == SQLITE_OK) { // correctly closed, rename the file if (std::remove(dbName.c_str()) == 0) { if (std::rename(newDbName.c_str(), dbName.c_str()) == 0) { r = sqlite3_open_v2(dbName.c_str(), &conn, flags, NULL); check_sqlite_err(conn, r, "Cannot establish connection to the database. "); post_connection_helper(conn, dbName, flags, timeout, synchronous); if (!newPassKey.empty()) { r = sqlite3_key_v2(conn, dbName.c_str(), newPassKey.c_str(), strlen(newPassKey.c_str())); check_sqlite_err(conn, r, "Cannot establish connection to the database with newly set password. "); } } else { // old DB removed but cannot rename the new one: bad throw sqlite3_soci_error("Cannot rename new SQLCipher database", r); } } else { // cannot remove the old database throw sqlite3_soci_error("Cannot remove old SQLCipher database", r); } } else { // likely a still busy database throw sqlite3_soci_error("Cannot close SQLCipher database", r); } } } // namespace anonymous sqlite3_session_backend::sqlite3_session_backend( connection_parameters const & parameters) { int timeout = 0; int connection_flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; std::string synchronous, passKey, newPassKey; bool disableEncryption = false; std::string const & connectString = parameters.get_connect_string(); std::string dbname(connectString); std::stringstream ssconn(connectString); while (!ssconn.eof() && ssconn.str().find('=') != std::string::npos) { std::string key, val; std::getline(ssconn, key, '='); std::getline(ssconn, val, ' '); if (val.size()>0 && val[0]=='\"') { std::string quotedVal = val.erase(0, 1); if (quotedVal[quotedVal.size()-1] == '\"') { quotedVal.erase(val.size()-1); } else // space inside value string { std::getline(ssconn, val, '\"'); quotedVal = quotedVal + " " + val; std::string keepspace; std::getline(ssconn, keepspace, ' '); } val = quotedVal; } if ("dbname" == key || "db" == key) { dbname = val; } else if ("timeout" == key) { std::istringstream converter(val); converter >> timeout; } else if ("synchronous" == key) { synchronous = val; } else if ("shared_cache" == key && "true" == val) { connection_flags |= SQLITE_OPEN_SHAREDCACHE; } else if ("key" == key) { passKey = val; } else if ("new_key" == key) { newPassKey = val; } else if ("disable_encryption" == key && val == "true") { disableEncryption = true; } } int res = sqlite3_open_v2(dbname.c_str(), &conn_, connection_flags, NULL); check_sqlite_err(conn_, res, "Cannot establish connection to the database. "); post_connection(dbname, connection_flags, timeout, synchronous); //Set password if (!passKey.empty() || !newPassKey.empty()) { if (!passKey.empty()){ res = sqlite3_key_v2(conn_, dbname.c_str(), passKey.c_str(), strlen(passKey.c_str())); check_sqlite_err(conn_, res, "Failed to encrypt database. "); } if (!passKey.empty() && !newPassKey.empty()) { //Set new password res = sqlite3_rekey_v2(conn_, dbname.c_str(), newPassKey.c_str(), strlen(newPassKey.c_str())); check_sqlite_err(conn_, res, "Failed to change database's password. "); } else if (!newPassKey.empty()) { std::string const dbNameEncrypted = dbname + ".encrypt"; std::string const query( "ATTACH DATABASE '" + dbNameEncrypted + "' AS encrypted KEY '" + newPassKey +"';" "SELECT sqlcipher_export('encrypted');" "DETACH DATABASE encrypted;" ); std::string const errMsg("Unable to enable encryption"); sqlcipher_export(conn_, connection_flags, timeout, synchronous, query, dbname, dbNameEncrypted, errMsg, newPassKey); } else if (disableEncryption) { // FIXME: security concerns: maybe we want to sanitize? :D // convert back to plain text; this method copies the current database in plaintext // mode; once it’s done, we must close the connection, rename the database and re-open // connection std::string const dbnamePlain = dbname + ".plain"; std::string const query( "PRAGMA key = '" + passKey + "';" "ATTACH DATABASE '" + dbnamePlain + "' AS plaintext KEY '';" // empty key = plaintext "SELECT sqlcipher_export('plaintext');" "DETACH DATABASE plaintext;" ); std::string const errMsg("Unable to disabling encryption"); sqlcipher_export(conn_, connection_flags, timeout, synchronous, query, dbname, dbnamePlain, errMsg, newPassKey); } } } sqlite3_session_backend::~sqlite3_session_backend() { clean_up(); } void sqlite3_session_backend::begin() { execute_hardcoded(conn_, "BEGIN", "Cannot begin transaction."); } void sqlite3_session_backend::commit() { execute_hardcoded(conn_, "COMMIT", "Cannot commit transaction."); } void sqlite3_session_backend::rollback() { execute_hardcoded(conn_, "ROLLBACK", "Cannot rollback transaction."); } void sqlite3_session_backend::post_connection(std::string const& dbname, int connection_flags, int timeout, std::string const& synchronous) { post_connection_helper(conn_, dbname, connection_flags, timeout, synchronous); } void sqlite3_session_backend::clean_up() { sqlite3_close(conn_); } sqlite3_statement_backend * sqlite3_session_backend::make_statement_backend() { return new sqlite3_statement_backend(*this); } sqlite3_rowid_backend * sqlite3_session_backend::make_rowid_backend() { return new sqlite3_rowid_backend(*this); } sqlite3_blob_backend * sqlite3_session_backend::make_blob_backend() { return new sqlite3_blob_backend(*this); } bool sqlite3_session_backend::isAlive() const { return true; }
34.547794
152
0.582952
RomanWlm
ab527f317a4f0cec4b2216c71f11abf45382019f
1,626
cxx
C++
phys-services/private/pybindings/I3CutValues.cxx
hschwane/offline_production
e14a6493782f613b8bbe64217559765d5213dc1e
[ "MIT" ]
1
2020-12-24T22:00:01.000Z
2020-12-24T22:00:01.000Z
phys-services/private/pybindings/I3CutValues.cxx
hschwane/offline_production
e14a6493782f613b8bbe64217559765d5213dc1e
[ "MIT" ]
null
null
null
phys-services/private/pybindings/I3CutValues.cxx
hschwane/offline_production
e14a6493782f613b8bbe64217559765d5213dc1e
[ "MIT" ]
3
2020-07-17T09:20:29.000Z
2021-03-30T16:44:18.000Z
// // Copyright (c) 2008 Troy D. Straszheim and the IceCube Collaboration // // This file is part of IceTray. // // IceTray is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 3 of the License, or // (at your option) any later version. // // IceTray is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // using namespace boost::python; namespace bp = boost::python; #include <phys-services/I3CutValues.h> #include <dataclasses/physics/I3Particle.h> #include <dataclasses/geometry/I3Geometry.h> #include <dataclasses/physics/I3RecoPulse.h> void register_I3CutValues() { class_<I3CutValues, bases<I3FrameObject>, boost::shared_ptr<I3CutValues> >("I3CutValues") .def("calculate", &I3CutValues::Calculate) .def_readwrite("nchan", &I3CutValues::Nchan) .def_readwrite("nhit", &I3CutValues::Nhit) .def_readwrite("nString", &I3CutValues::Nstring) .def_readwrite("ndir", &I3CutValues::Ndir) .def_readwrite("ldir", &I3CutValues::Ldir) .def_readwrite("sdir", &I3CutValues::Sdir) .def_readwrite("sall", &I3CutValues::Sall) .def_readwrite("cog", &I3CutValues::cog) ; register_pointer_conversions<I3CutValues>(); }
36.954545
91
0.721402
hschwane
ab54b3159c75f1982fdd28d57e93714fd501d2d0
62,789
cpp
C++
orca/gporca/libnaucrates/src/statistics/CStatisticsUtils.cpp
vitessedata/gpdb.4.3.99.x
9462aad5df1bf120a2a87456b1f9574712227da4
[ "PostgreSQL", "Apache-2.0" ]
3
2017-12-10T16:41:21.000Z
2020-07-08T12:59:12.000Z
orca/gporca/libnaucrates/src/statistics/CStatisticsUtils.cpp
vitessedata/gpdb.4.3.99.x
9462aad5df1bf120a2a87456b1f9574712227da4
[ "PostgreSQL", "Apache-2.0" ]
null
null
null
orca/gporca/libnaucrates/src/statistics/CStatisticsUtils.cpp
vitessedata/gpdb.4.3.99.x
9462aad5df1bf120a2a87456b1f9574712227da4
[ "PostgreSQL", "Apache-2.0" ]
4
2017-12-10T16:41:35.000Z
2020-11-28T12:20:30.000Z
//--------------------------------------------------------------------------- // Greenplum Database // Copyright 2013 EMC Corp. // // @filename: // CStatisticsUtils.cpp // // @doc: // Statistics helper routines // // @owner: // // // @test: // // //--------------------------------------------------------------------------- #include "gpos/base.h" #include "gpopt/base/CUtils.h" #include "gpopt/base/CColRefTable.h" #include "gpopt/base/CColRefSetIter.h" #include "gpopt/exception.h" #include "gpopt/operators/ops.h" #include "gpopt/operators/CExpressionUtils.h" #include "gpopt/operators/CPredicateUtils.h" #include "gpopt/mdcache/CMDAccessor.h" #include "gpopt/engine/CStatisticsConfig.h" #include "gpopt/optimizer/COptimizerConfig.h" #include "naucrates/statistics/CStatisticsUtils.h" #include "naucrates/statistics/CStatistics.h" #include "naucrates/statistics/CStatsPredUtils.h" #include "naucrates/statistics/CStatsPredDisj.h" #include "naucrates/statistics/CStatsPredConj.h" #include "naucrates/statistics/CStatsPredLike.h" #include "naucrates/statistics/CScaleFactorUtils.h" #include "naucrates/statistics/CHistogram.h" #include "naucrates/md/IMDScalarOp.h" #include "naucrates/md/IMDType.h" #include "naucrates/md/IMDTypeInt2.h" #include "naucrates/md/IMDTypeInt8.h" #include "naucrates/md/IMDTypeOid.h" #include "naucrates/md/CMDIdColStats.h" #include "naucrates/base/IDatumInt2.h" #include "naucrates/base/IDatumInt4.h" #include "naucrates/base/IDatumInt8.h" #include "naucrates/base/IDatumOid.h" using namespace gpopt; using namespace gpmd; //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PpointNext // // @doc: // Get the next data point for new bucket boundary // //--------------------------------------------------------------------------- CPoint * CStatisticsUtils::PpointNext ( IMemoryPool *pmp, CMDAccessor *pmda, CPoint *ppoint ) { IMDId *pmdid = ppoint->Pdatum()->Pmdid(); const IMDType *pmdtype = pmda->Pmdtype(pmdid); // type has integer mapping if (pmdtype->Eti() == IMDType::EtiInt2 || pmdtype->Eti() == IMDType::EtiInt4 || pmdtype->Eti() == IMDType::EtiInt8 || pmdtype->Eti() == IMDType::EtiOid) { IDatum *pdatumNew = NULL; IDatum *pdatumOld = ppoint->Pdatum(); if (pmdtype->Eti() == IMDType::EtiInt2) { SINT sValue = (SINT) (dynamic_cast<IDatumInt2 *>(pdatumOld)->SValue() + 1); pdatumNew = dynamic_cast<const IMDTypeInt2 *>(pmdtype)->PdatumInt2(pmp, sValue, false); } else if (pmdtype->Eti() == IMDType::EtiInt4) { INT iValue = dynamic_cast<IDatumInt4 *>(pdatumOld)->IValue() + 1; pdatumNew = dynamic_cast<const IMDTypeInt4 *>(pmdtype)->PdatumInt4(pmp, iValue, false); } else if (pmdtype->Eti() == IMDType::EtiInt8) { LINT lValue = dynamic_cast<IDatumInt8 *>(pdatumOld)->LValue() + 1; pdatumNew = dynamic_cast<const IMDTypeInt8 *>(pmdtype)->PdatumInt8(pmp, lValue, false); } else { OID oidValue = dynamic_cast<IDatumOid *>(pdatumOld)->OidValue() + 1; pdatumNew = dynamic_cast<const IMDTypeOid *>(pmdtype)->PdatumOid(pmp, oidValue, false); } return GPOS_NEW(pmp) CPoint(pdatumNew); } return NULL; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PhistTransformMCV // // @doc: // Given MCVs and their frequencies, construct a CHistogram // containing MCV singleton buckets //--------------------------------------------------------------------------- CHistogram * CStatisticsUtils::PhistTransformMCV ( IMemoryPool *pmp, const IMDType *, // pmdtype, DrgPdatum *pdrgpdatumMCV, DrgPdouble *pdrgpdFreq, ULONG ulNumMCVValues ) { GPOS_ASSERT(pdrgpdatumMCV->UlLength() == ulNumMCVValues); // put MCV values and their corresponding frequencies // into a structure in order to sort DrgPsmcvpair *pdrgpsmcvpair = GPOS_NEW(pmp) DrgPsmcvpair(pmp); for (ULONG ul = 0; ul < ulNumMCVValues; ul++) { IDatum *pdatum = (*pdrgpdatumMCV)[ul]; CDouble dMcvFreq = *((*pdrgpdFreq)[ul]); pdatum->AddRef(); SMcvPair *psmcvpair = GPOS_NEW(pmp) SMcvPair(pdatum, dMcvFreq); pdrgpsmcvpair->Append(psmcvpair); } // sort the MCV value-frequency pairs according to value if (1 < ulNumMCVValues) { pdrgpsmcvpair->Sort(CStatisticsUtils::IMcvPairCmp); } // now put MCVs and their frequencies in buckets DrgPbucket *pdrgpbucketMCV = GPOS_NEW(pmp) DrgPbucket(pmp); for (ULONG ul = 0; ul < ulNumMCVValues; ul++) { IDatum *pdatum = (*pdrgpsmcvpair)[ul]->m_pdatumMCV; pdatum->AddRef(); pdatum->AddRef(); CDouble dBucketFreq = (*pdrgpsmcvpair)[ul]->m_dMcvFreq; CBucket *pbucket = GPOS_NEW(pmp) CBucket ( GPOS_NEW(pmp) CPoint(pdatum), GPOS_NEW(pmp) CPoint(pdatum), true /* fLowerClosed */, true /* fUpperClosed */, dBucketFreq, CDouble(1.0) ); pdrgpbucketMCV->Append(pbucket); } CHistogram *phist = GPOS_NEW(pmp) CHistogram(pdrgpbucketMCV); GPOS_ASSERT(phist->FValid()); pdrgpsmcvpair->Release(); return phist; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PhistMergeMcvHist // // @doc: // Given MCVs and histogram in CHistogram, merge them into a single // CHistogram // //--------------------------------------------------------------------------- CHistogram * CStatisticsUtils::PhistMergeMcvHist ( IMemoryPool *pmp, const CHistogram *phistGPDBMcv, const CHistogram *phistGPDBHist ) { GPOS_ASSERT(NULL != phistGPDBMcv); GPOS_ASSERT(NULL != phistGPDBHist); GPOS_ASSERT(phistGPDBMcv->FWellDefined()); GPOS_ASSERT(phistGPDBHist->FWellDefined()); GPOS_ASSERT(0 < phistGPDBMcv->UlBuckets()); GPOS_ASSERT(0 < phistGPDBHist->UlBuckets()); const DrgPbucket *pdrgpbucketMCV = phistGPDBMcv->Pdrgpbucket(); const DrgPbucket *pdrgpbucketHist = phistGPDBHist->Pdrgpbucket(); IDatum *pdatum = (*pdrgpbucketMCV)[0]->PpLower()->Pdatum(); // data types that are not supported in the new optimizer yet if (!pdatum->FStatsComparable(pdatum)) { // fall back to the approach that chooses the one having more information if (0.5 < phistGPDBMcv->DFrequency()) { // have to do deep copy, otherwise phistGPDBMcv and phistMerge // will point to the same object return phistGPDBMcv->PhistCopy(pmp); } return phistGPDBHist->PhistCopy(pmp); } // both MCV and histogram buckets must be sorted GPOS_ASSERT(phistGPDBMcv->FValid()); GPOS_ASSERT(phistGPDBHist->FValid()); DrgPbucket *pdrgpbucketMerged = PdrgpbucketMergeBuckets(pmp, pdrgpbucketMCV, pdrgpbucketHist); CHistogram *phistMerged = GPOS_NEW(pmp) CHistogram(pdrgpbucketMerged); GPOS_ASSERT(phistMerged->FValid()); return phistMerged; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PdrgpbucketCreateMergedBuckets // // @doc: // Given histogram buckets and MCV buckets, merge them into // an array of buckets. // //--------------------------------------------------------------------------- DrgPbucket * CStatisticsUtils::PdrgpbucketMergeBuckets ( IMemoryPool *pmp, const DrgPbucket *pdrgpbucketMCV, const DrgPbucket *pdrgpbucketHist ) { DrgPbucket *pdrgpbucketMerged = GPOS_NEW(pmp) DrgPbucket(pmp); const ULONG ulMCV = pdrgpbucketMCV->UlLength(); const ULONG ulHist = pdrgpbucketHist->UlLength(); ULONG ulMCVIdx = 0; ULONG ulHistIdx = 0; while (ulMCVIdx < ulMCV && ulHistIdx < ulHist) { CBucket *pbucketMCV = (*pdrgpbucketMCV)[ulMCVIdx]; CBucket *pbucketHist = (*pdrgpbucketHist)[ulHistIdx]; if (pbucketMCV->FBefore(pbucketHist)) { pdrgpbucketMerged->Append(pbucketMCV->PbucketCopy(pmp)); ulMCVIdx++; } else if (pbucketMCV->FAfter(pbucketHist)) { pdrgpbucketMerged->Append(pbucketHist->PbucketCopy(pmp)); ulHistIdx++; } else // pbucketMCV is contained in pbucketHist { GPOS_ASSERT(pbucketHist->FSubsumes(pbucketMCV)); SplitHistDriver(pmp, pbucketHist, pdrgpbucketMCV, pdrgpbucketMerged, &ulMCVIdx, ulMCV); ulHistIdx++; } } // append leftover buckets from either MCV or histogram AddRemainingBuckets(pmp, pdrgpbucketMCV, pdrgpbucketMerged, &ulMCVIdx); AddRemainingBuckets(pmp, pdrgpbucketHist, pdrgpbucketMerged, &ulHistIdx); return pdrgpbucketMerged; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::AddRemainingBuckets // // @doc: // Add remaining buckets from one array of buckets to the other // //--------------------------------------------------------------------------- void CStatisticsUtils::AddRemainingBuckets ( IMemoryPool *pmp, const DrgPbucket *pdrgpbucketSrc, DrgPbucket *pdrgpbucketDest, ULONG *pulStart ) { const ULONG ulTotal = pdrgpbucketSrc->UlLength(); while (*pulStart < ulTotal) { pdrgpbucketDest->Append((*pdrgpbucketSrc)[*pulStart]->PbucketCopy(pmp)); (*pulStart)++; } } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::SplitHistDriver // // @doc: // Given an MCV that are contained in a histogram bucket, // find the batch of MCVs that fall in the same histogram bucket. // Then perform the split for this batch of MCVs. // //--------------------------------------------------------------------------- void CStatisticsUtils::SplitHistDriver ( IMemoryPool *pmp, const CBucket *pbucketHist, const DrgPbucket *pdrgpbucketMCV, DrgPbucket *pdrgpbucketMerged, ULONG *pulMCVIdx, ULONG ulMCV ) { GPOS_ASSERT(NULL != pbucketHist); GPOS_ASSERT(NULL != pdrgpbucketMCV); DrgPbucket *pdrgpbucketTmpMcv = GPOS_NEW(pmp) DrgPbucket(pmp); // find the MCVs that fall into the same histogram bucket and put them in a temp array // E.g. MCV = ..., 6, 8, 12, ... and the current histogram bucket is [5,10) // then 6 and 8 will be handled together, i.e. split [5,10) into [5,6) [6,6] (6,8) [8,8] (8,10) while ((*pulMCVIdx) < ulMCV && pbucketHist->FSubsumes((*pdrgpbucketMCV)[*pulMCVIdx])) { CBucket *pbucket = (*pdrgpbucketMCV)[*pulMCVIdx]; pdrgpbucketTmpMcv->Append(pbucket->PbucketCopy(pmp)); (*pulMCVIdx)++; } // split pbucketHist given one or more MCVs it contains DrgPbucket *pdrgpbucketSplitted = PdrgpbucketSplitHistBucket(pmp, pbucketHist, pdrgpbucketTmpMcv); const ULONG ulSplitted = pdrgpbucketSplitted->UlLength(); // copy buckets from pdrgpbucketSplitted to pdrgbucketMerged for (ULONG ul = 0; ul < ulSplitted; ul++) { CBucket *pbucket = (*pdrgpbucketSplitted)[ul]; pdrgpbucketMerged->Append(pbucket->PbucketCopy(pmp)); } pdrgpbucketTmpMcv->Release(); pdrgpbucketSplitted->Release(); } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PdrgpbucketSplitHistBucket // // @doc: // Given an array of MCVs that are contained in a histogram bucket, // split the histogram bucket into smaller buckets with the MCVs being // the splitting points. The MCVs are returned too, among the smaller // buckets. // //--------------------------------------------------------------------------- DrgPbucket * CStatisticsUtils::PdrgpbucketSplitHistBucket ( IMemoryPool *pmp, const CBucket *pbucketHist, const DrgPbucket *pdrgpbucketMCV ) { GPOS_ASSERT(NULL != pbucketHist); GPOS_ASSERT(NULL != pdrgpbucketMCV); DrgPbucket *pdrgpbucketNew = GPOS_NEW(pmp) DrgPbucket(pmp); const ULONG ulMCV = pdrgpbucketMCV->UlLength(); GPOS_ASSERT(0 < ulMCV); // construct first bucket, if any CPoint *ppointMCV = (*pdrgpbucketMCV)[0]->PpLower(); CBucket *pbucketFirst = PbucketCreateValidBucket ( pmp, pbucketHist->PpLower(), ppointMCV, pbucketHist->FLowerClosed(), false // fUpperClosed ); if (NULL != pbucketFirst) { pdrgpbucketNew->Append(pbucketFirst); } // construct middle buckets, if any for (ULONG ulIdx = 0; ulIdx < ulMCV - 1; ulIdx++) { // first append the MCV itself CBucket *pbucketMCV = (*pdrgpbucketMCV)[ulIdx]; pdrgpbucketNew->Append(pbucketMCV->PbucketCopy(pmp)); // construct new buckets CPoint *ppointLeft = pbucketMCV->PpLower(); // this MCV CPoint *ppointRight = (*pdrgpbucketMCV)[ulIdx+1]->PpLower(); // next MCV CBucket *pbucketNew = PbucketCreateValidBucket(pmp, ppointLeft, ppointRight, false, false); if (NULL != pbucketNew) { pdrgpbucketNew->Append(pbucketNew); } } // append last MCV CBucket *pbucketMCV = (*pdrgpbucketMCV)[ulMCV-1]; pdrgpbucketNew->Append(pbucketMCV->PbucketCopy(pmp)); ppointMCV = pbucketMCV->PpLower(); // construct last bucket, if any CBucket *pbucketLast = PbucketCreateValidBucket(pmp, ppointMCV, pbucketHist->PpUpper(), false, pbucketHist->FUpperClosed()); if (NULL != pbucketLast) { pdrgpbucketNew->Append(pbucketLast); } // re-balance dDistinct and dFrequency in pdrgpbucketNew CDouble dDistinctTotal = std::max(CDouble(1.0), pbucketHist->DDistinct() - ulMCV); DistributeBucketProperties(pbucketHist->DFrequency(), dDistinctTotal, pdrgpbucketNew); return pdrgpbucketNew; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PbucketCreateValidBucket // // @doc: // Given lower and upper and their closedness, create a bucket if they // can form a valid bucket // //--------------------------------------------------------------------------- CBucket * CStatisticsUtils::PbucketCreateValidBucket ( IMemoryPool *pmp, CPoint *ppointLower, CPoint *ppointUpper, BOOL fLowerClosed, BOOL fUpperClosed ) { if (!FValidBucket(ppointLower, ppointUpper, fLowerClosed, fUpperClosed)) { return NULL; } ppointLower->AddRef(); ppointUpper->AddRef(); return GPOS_NEW(pmp) CBucket ( ppointLower, ppointUpper, fLowerClosed, fUpperClosed, GPOPT_BUCKET_DEFAULT_FREQ, // dFrequency will be assigned later GPOPT_BUCKET_DEFAULT_DISTINCT // dDistinct will be assigned later ); } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::FValidBucket // // @doc: // Given lower and upper and their closedness, test if they // can form a valid bucket. // E.g. [1,1) (2,3) are not valid integer buckets, (2.0, 3.0) is a // valid numeric bucket. // //--------------------------------------------------------------------------- BOOL CStatisticsUtils::FValidBucket ( CPoint *ppointLower, CPoint *ppointUpper, BOOL fLowerClosed, BOOL fUpperClosed ) { if (ppointLower->FGreaterThan(ppointUpper)) { return false; } // e.g. [1.0, 1.0) is not valid if (ppointLower->FEqual(ppointUpper) && (!fLowerClosed || !fUpperClosed)) { return false; } // datum has statsDistance, so must be statsMappable const IDatum *pdatum = ppointLower->Pdatum(); const IDatumStatisticsMappable *pdatumsm = dynamic_cast<const IDatumStatisticsMappable*>(pdatum); // for types which have integer mapping for stats purposes, e.g. int2,int4, etc. if (pdatumsm->FHasStatsLINTMapping()) { // test if this integer bucket is well-defined CDouble dVal = ppointUpper->DDistance(ppointLower); if (!fLowerClosed) { dVal = dVal + CDouble(-1.0); } if (!fUpperClosed) { dVal = dVal + CDouble(-1.0); } if (CDouble(0) > dVal) { return false; } } return true; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::DistributeBucketProperties // // @doc: // Set dDistinct and dFrequency of the new buckets according to // their ranges, based on the assumption that values are uniformly // distributed within a bucket. // //--------------------------------------------------------------------------- void CStatisticsUtils::DistributeBucketProperties ( CDouble dFrequencyTotal, CDouble dDistinctTotal, DrgPbucket *pdrgpbucket ) { GPOS_ASSERT(NULL != pdrgpbucket); CDouble dSumWidth = 0.0; const ULONG ulNew = pdrgpbucket->UlLength(); for (ULONG ul = 0; ul < ulNew; ul++) { CBucket *pbucket = (*pdrgpbucket)[ul]; if (!pbucket->FSingleton()) // the re-balance should exclude MCVs (singleton bucket) { dSumWidth = dSumWidth + pbucket->DWidth(); } } for (ULONG ul = 0; ul < ulNew; ul++) { CBucket *pbucket = (*pdrgpbucket)[ul]; if (!pbucket->FSingleton()) { CDouble dFactor = pbucket->DWidth() / dSumWidth; pbucket->SetFrequency(dFrequencyTotal * dFactor); // TODO: , Aug 1 2013 - another heuristic may be max(1, dDisinct * dFactor) pbucket->SetDistinct(dDistinctTotal * dFactor); } } } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PrintColStats // // @doc: // Utility function to print column stats before/after applying filter // //--------------------------------------------------------------------------- void CStatisticsUtils::PrintColStats ( IMemoryPool *pmp, CStatsPred *pstatspred, ULONG ulColIdCond, CHistogram *phist, CDouble dScaleFactorLast, BOOL fBefore ) { GPOS_ASSERT(NULL != pstatspred); ULONG ulColId = pstatspred->UlColId(); if (ulColId == ulColIdCond && NULL != phist) { { CAutoTrace at(pmp); if (fBefore) { at.Os() << "BEFORE" << std::endl; } else { at.Os() << "AFTER" << std::endl; } phist->OsPrint(at.Os()); at.Os() << "Scale Factor: " << dScaleFactorLast<< std::endl; } } } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::ExtractUsedColIds // // @doc: // Extract all the column identifiers used in the statistics filter // //--------------------------------------------------------------------------- void CStatisticsUtils::ExtractUsedColIds ( IMemoryPool *pmp, CBitSet *pbsColIds, CStatsPred *pstatspred, DrgPul *pdrgpulColIds ) { GPOS_ASSERT(NULL != pbsColIds); GPOS_ASSERT(NULL != pstatspred); GPOS_ASSERT(NULL != pdrgpulColIds); if (ULONG_MAX != pstatspred->UlColId()) { // the predicate is on a single column (void) pbsColIds->FExchangeSet(pstatspred->UlColId()); pdrgpulColIds->Append(GPOS_NEW(pmp) ULONG(pstatspred->UlColId())); return; } if (CStatsPred::EsptUnsupported == pstatspred->Espt()) { return; } GPOS_ASSERT(CStatsPred::EsptConj == pstatspred->Espt() || CStatsPred::EsptDisj == pstatspred->Espt()); DrgPstatspred *pdrgpstatspred = NULL; if (CStatsPred::EsptConj == pstatspred->Espt()) { pdrgpstatspred = CStatsPredConj::PstatspredConvert(pstatspred)->Pdrgpstatspred(); } else { pdrgpstatspred = CStatsPredDisj::PstatspredConvert(pstatspred)->Pdrgpstatspred(); } GPOS_ASSERT(NULL != pdrgpstatspred); const ULONG ulArity = pdrgpstatspred->UlLength(); for (ULONG ul = 0; ul < ulArity; ul++) { CStatsPred *pstatspredCurr = (*pdrgpstatspred)[ul]; ULONG ulColId = pstatspredCurr->UlColId(); if (ULONG_MAX != ulColId) { if (!pbsColIds->FBit(ulColId)) { (void) pbsColIds->FExchangeSet(ulColId); pdrgpulColIds->Append(GPOS_NEW(pmp) ULONG(ulColId)); } } else if (CStatsPred::EsptUnsupported != pstatspredCurr->Espt()) { GPOS_ASSERT(CStatsPred::EsptConj == pstatspredCurr->Espt() || CStatsPred::EsptDisj == pstatspredCurr->Espt()); ExtractUsedColIds(pmp, pbsColIds, pstatspredCurr, pdrgpulColIds); } } } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::UpdateDisjStatistics // // @doc: // Given the previously generated histogram, update the intermediate // result of the disjunction // //--------------------------------------------------------------------------- void CStatisticsUtils::UpdateDisjStatistics ( IMemoryPool *pmp, CBitSet *pbsDontUpdateStats, CDouble dRowsInputDisj, CDouble dRowsLocal, CHistogram *phistPrev, HMUlHist *phmulhistResultDisj, ULONG ulColId ) { GPOS_ASSERT(NULL != pbsDontUpdateStats); GPOS_ASSERT(NULL != phmulhistResultDisj); if (NULL != phistPrev && ULONG_MAX != ulColId && !pbsDontUpdateStats->FBit(ulColId)) { // 1. the filter is on the same column because ULONG_MAX != ulColId // 2. the histogram of the column can be updated CHistogram *phistResult = phmulhistResultDisj->PtLookup(&ulColId); if (NULL != phistResult) { // since there is already a histogram for this column, // union the previously generated histogram with the newly generated // histogram for this column CDouble dRowOutput(0.0); CHistogram *phistNew = phistPrev->PhistUnionNormalized ( pmp, dRowsInputDisj, phistResult, dRowsLocal, &dRowOutput ); GPOS_DELETE(phistPrev); phistPrev = phistNew; } AddHistogram ( pmp, ulColId, phistPrev, phmulhistResultDisj, true /*fReplaceOldEntries*/ ); } GPOS_DELETE(phistPrev); } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PbsNonUpdatableHistForDisj // // @doc: // Given a disjunction filter, generate a bit set of columns whose // histogram buckets cannot be changed by applying the predicates in the // disjunction //--------------------------------------------------------------------------- CBitSet * CStatisticsUtils::PbsNonUpdatableHistForDisj ( IMemoryPool *pmp, CStatsPredDisj *pstatspred ) { GPOS_ASSERT(NULL != pstatspred); // Consider the following disjunctive predicates: // Case 1: ((x == 1) OR (x == 2 AND y == 2)) // In such scenarios, predicate y is only operated on by the second child. // Therefore the output of the disjunction should not see the effects on // y's histogram due to the second child. In other words, DO NOT // update histogram buckets for y. // Case 2: ((x == 1 AND y== 1) OR (x == 2 AND y == 2)) // In such scenarios both child predicate operate on both x and y // therefore the output of the disjunction for each column should be // the union of stats of each predicate being applied separately. // In other words, DO update histogram buckets for both x and y. CBitSet *pbsNonUpdateable = GPOS_NEW(pmp) CBitSet(pmp); const ULONG ulDisjColId = pstatspred->UlColId(); if (ULONG_MAX != ulDisjColId) { // disjunction predicate on a single column so all are updatable return pbsNonUpdateable; } CBitSet *pbsDisj = GPOS_NEW(pmp) CBitSet(pmp); DrgPul *pdrgpulDisj = GPOS_NEW(pmp) DrgPul(pmp); ExtractUsedColIds(pmp, pbsDisj, pstatspred, pdrgpulDisj); const ULONG ulDisjUsedCol = pdrgpulDisj->UlLength(); const ULONG ulArity = pstatspred->UlFilters(); for (ULONG ulChildIdx = 0; ulChildIdx < ulArity; ulChildIdx++) { CStatsPred *pstatspredChild = pstatspred->Pstatspred(ulChildIdx); CBitSet *pbsChild = GPOS_NEW(pmp) CBitSet(pmp); DrgPul *pdrgpulChild = GPOS_NEW(pmp) DrgPul(pmp); ExtractUsedColIds(pmp, pbsChild, pstatspredChild, pdrgpulChild); const ULONG ulLen = pdrgpulChild->UlLength(); GPOS_ASSERT(ulLen <= ulDisjUsedCol); if (ulLen < ulDisjUsedCol) { // the child predicate only operates on a subset of all the columns // used in the disjunction for (ULONG ulUsedColIdx = 0; ulUsedColIdx < ulDisjUsedCol; ulUsedColIdx++) { ULONG ulColId = *(*pdrgpulDisj)[ulUsedColIdx]; if (!pbsChild->FBit(ulColId)) { (void) pbsNonUpdateable->FExchangeSet(ulColId); } } } // clean up pdrgpulChild->Release(); pbsChild->Release(); } // clean up pdrgpulDisj->Release(); pbsDisj->Release(); return pbsNonUpdateable; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::AddHistogram // // @doc: // Add histogram to histogram map if not already present. // //--------------------------------------------------------------------------- void CStatisticsUtils::AddHistogram ( IMemoryPool *pmp, ULONG ulColId, const CHistogram *phist, HMUlHist *phmulhist, BOOL fReplaceOld ) { GPOS_ASSERT(NULL != phist); if (NULL == phmulhist->PtLookup(&ulColId)) { #ifdef GPOS_DEBUG BOOL fRes = #endif phmulhist->FInsert(GPOS_NEW(pmp) ULONG(ulColId), phist->PhistCopy(pmp)); GPOS_ASSERT(fRes); } else if (fReplaceOld) { #ifdef GPOS_DEBUG BOOL fRes = #endif phmulhist->FReplace(&ulColId, phist->PhistCopy(pmp)); GPOS_ASSERT(fRes); } } #ifdef GPOS_DEBUG //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PrintHistogramMap // // @doc: // Helper method to print the hash map of histograms // //--------------------------------------------------------------------------- void CStatisticsUtils::PrintHistogramMap ( IOstream &os, HMUlHist *phmulhist ) { GPOS_ASSERT(NULL != phmulhist); HMIterUlHist hmiterulhist(phmulhist); while (hmiterulhist.FAdvance()) { ULONG ulCol = *(hmiterulhist.Pk()); os << "Column Id: " << ulCol << std::endl; const CHistogram *phist = hmiterulhist.Pt(); phist->OsPrint(os); } } #endif // GPOS_DEBUG //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PhmulhistMergeAfterDisjChild // // @doc: // Create a new hash map of histograms after merging // the histograms generated by the child of disjunction // //--------------------------------------------------------------------------- HMUlHist * CStatisticsUtils::PhmulhistMergeAfterDisjChild ( IMemoryPool *pmp, CBitSet *pbsStatsNonUpdateableCols, HMUlHist *phmulhist, HMUlHist *phmulhistDisjChild, CDouble dRowsCumulative, CDouble dRowsDisjChild ) { GPOS_ASSERT(NULL != pbsStatsNonUpdateableCols); GPOS_ASSERT(NULL != phmulhist); GPOS_ASSERT(NULL != phmulhistDisjChild); BOOL fEmpty = (CStatistics::DEpsilon >= dRowsDisjChild); CDouble dRowOutput(CStatistics::DMinRows.DVal()); HMUlHist *phmulhistMergeResult = GPOS_NEW(pmp) HMUlHist(pmp); // iterate over the new hash map of histograms and only add // histograms of columns whose output statistics can be updated HMIterUlHist hmiterulhistDisjChild(phmulhistDisjChild); while (hmiterulhistDisjChild.FAdvance()) { ULONG ulColIdDisjChild = *(hmiterulhistDisjChild.Pk()); const CHistogram *phistDisjChild = hmiterulhistDisjChild.Pt(); if (!pbsStatsNonUpdateableCols->FBit(ulColIdDisjChild)) { if (!fEmpty) { AddHistogram(pmp, ulColIdDisjChild, phistDisjChild, phmulhistMergeResult); } else { // add a dummy statistics object since the estimated number of rows for // disjunction child is "0" phmulhistMergeResult->FInsert ( GPOS_NEW(pmp) ULONG(ulColIdDisjChild), GPOS_NEW(pmp) CHistogram(GPOS_NEW(pmp) DrgPbucket(pmp), false /* fWellDefined */) ); } } GPOS_CHECK_ABORT; } // iterate over the previously generated histograms and // union them with newly created hash map of histograms (if these columns are updatable) HMIterUlHist hmiterulhist(phmulhist); while (hmiterulhist.FAdvance()) { ULONG ulColId = *(hmiterulhist.Pk()); const CHistogram *phist = hmiterulhist.Pt(); if (NULL != phist && !pbsStatsNonUpdateableCols->FBit(ulColId)) { if (fEmpty) { // since the estimated output of the disjunction child is "0" tuples // no point merging histograms. AddHistogram ( pmp, ulColId, phist, phmulhistMergeResult, true /* fReplaceOld */ ); } else { const CHistogram *phistDisjChild = phmulhistDisjChild->PtLookup(&ulColId); CHistogram *phistMergeResult = phist->PhistUnionNormalized ( pmp, dRowsCumulative, phistDisjChild, dRowsDisjChild, &dRowOutput ); AddHistogram ( pmp, ulColId, phistMergeResult, phmulhistMergeResult, true /* fReplaceOld */ ); GPOS_DELETE(phistMergeResult); } GPOS_CHECK_ABORT; } } return phmulhistMergeResult; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PhmulhistCopy // // @doc: // Helper method to copy the hash map of histograms // //--------------------------------------------------------------------------- HMUlHist * CStatisticsUtils::PhmulhistCopy ( IMemoryPool *pmp, HMUlHist *phmulhist ) { GPOS_ASSERT(NULL != phmulhist); HMUlHist *phmulhistCopy = GPOS_NEW(pmp) HMUlHist(pmp); HMIterUlHist hmiterulhist(phmulhist); while (hmiterulhist.FAdvance()) { ULONG ulColId = *(hmiterulhist.Pk()); const CHistogram *phist = hmiterulhist.Pt(); AddHistogram(pmp, ulColId, phist, phmulhistCopy); GPOS_CHECK_ABORT; } return phmulhistCopy; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::UlColId // // @doc: // Return the column identifier of the filter if the predicate is // on a single column else return ULONG_MAX // //--------------------------------------------------------------------------- ULONG CStatisticsUtils::UlColId ( const DrgPstatspred *pdrgpstatspred ) { GPOS_ASSERT(NULL != pdrgpstatspred); ULONG ulColIdResult = ULONG_MAX; BOOL fSameCol = true; const ULONG ulLen = pdrgpstatspred->UlLength(); for (ULONG ul = 0; ul < ulLen && fSameCol; ul++) { CStatsPred *pstatspred = (*pdrgpstatspred)[ul]; ULONG ulColId = pstatspred->UlColId(); if (ULONG_MAX == ulColIdResult) { ulColIdResult = ulColId; } fSameCol = (ulColIdResult == ulColId); } if (fSameCol) { return ulColIdResult; } return ULONG_MAX; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PdatumNull // // @doc: // Generate a null datum given a column reference // //--------------------------------------------------------------------------- IDatum * CStatisticsUtils::PdatumNull ( const CColRef *pcr ) { const IMDType *pmdtype = pcr->Pmdtype(); IDatum *pdatum = pmdtype->PdatumNull(); pdatum->AddRef(); return pdatum; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PstatsDeriveWithOuterRefs // // @doc: // Derive statistics when scalar expression uses outer references, // we pull statistics for outer references from the passed statistics // context, and use Join statistics derivation in this case // // For example: // // Join // |--Get(R) // +--Join // |--Get(S) // +--Select(T.t=R.r) // +--Get(T) // // when deriving statistics on 'Select(T.t=R.r)', we join T with the // cross product (R x S) based on the condition (T.t=R.r) // //--------------------------------------------------------------------------- IStatistics * CStatisticsUtils::PstatsDeriveWithOuterRefs ( IMemoryPool *pmp, BOOL fOuterJoin, CExpressionHandle & #ifdef GPOS_DEBUG exprhdl // handle attached to the logical expression we want to derive stats for #endif // GPOS_DEBUG , CExpression *pexprScalar, // scalar condition to be used for stats derivation IStatistics *pstats, // statistics object of the attached expression DrgPstat *pdrgpstatOuter // array of stats objects where outer references are defined ) { GPOS_ASSERT(exprhdl.FHasOuterRefs() && "attached expression does not have outer references"); GPOS_ASSERT(NULL != pexprScalar); GPOS_ASSERT(NULL != pstats); GPOS_ASSERT(NULL != pdrgpstatOuter); GPOS_ASSERT(0 < pdrgpstatOuter->UlLength()); // join outer stats object based on given scalar expression, // we use inner join semantics here to consider all relevant combinations of outer tuples IStatistics *pstatsOuter = PstatsJoinArray(pmp, false /*fOuterJoin*/, pdrgpstatOuter, pexprScalar); CDouble dRowsOuter = pstatsOuter->DRows(); // join passed stats object and outer stats based on the passed join type DrgPstat *pdrgpstat = GPOS_NEW(pmp) DrgPstat(pmp); pdrgpstat->Append(pstatsOuter); pstats->AddRef(); pdrgpstat->Append(pstats); IStatistics *pstatsJoined = PstatsJoinArray(pmp, fOuterJoin, pdrgpstat, pexprScalar); pdrgpstat->Release(); // scale result using cardinality of outer stats and set number of rebinds of returned stats IStatistics *pstatsResult = pstatsJoined->PstatsScale(pmp, CDouble(1.0/dRowsOuter)); pstatsResult->SetRebinds(dRowsOuter); pstatsJoined->Release(); return pstatsResult; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PstatsFilter // // @doc: // Derive statistics for filter operation based on given scalar expression // //--------------------------------------------------------------------------- IStatistics * CStatisticsUtils::PstatsFilter ( IMemoryPool *pmp, CExpressionHandle &exprhdl, IStatistics *pstatsChild, CExpression *pexprScalarLocal, // filter expression on local columns only CExpression *pexprScalarOuterRefs, // filter expression involving outer references DrgPstat *pdrgpstatOuter ) { GPOS_ASSERT(NULL != pstatsChild); GPOS_ASSERT(NULL != pexprScalarLocal); GPOS_ASSERT(NULL != pexprScalarOuterRefs); GPOS_ASSERT(NULL != pdrgpstatOuter); CColRefSet *pcrsOuterRefs = exprhdl.Pdprel()->PcrsOuter(); // TODO June 13 2014, we currently only cap ndvs when we have a filter // immediately on top of tables BOOL fCapNdvs = (1 == exprhdl.Pdprel()->UlJoinDepth()); // extract local filter CStatsPred *pstatspred = CStatsPredUtils::PstatspredExtract(pmp, pexprScalarLocal, pcrsOuterRefs); // derive stats based on local filter IStatistics *pstatsResult = pstatsChild->PstatsFilter(pmp, pstatspred, fCapNdvs); pstatspred->Release(); if (exprhdl.FHasOuterRefs() && 0 < pdrgpstatOuter->UlLength()) { // derive stats based on outer references IStatistics *pstats = PstatsDeriveWithOuterRefs(pmp, false /*fOuterJoin*/, exprhdl, pexprScalarOuterRefs, pstatsResult, pdrgpstatOuter); pstatsResult->Release(); pstatsResult = pstats; } return pstatsResult; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PstatsJoinArray // // @doc: // Derive statistics for the given join predicate // //--------------------------------------------------------------------------- IStatistics * CStatisticsUtils::PstatsJoinArray ( IMemoryPool *pmp, BOOL fOuterJoin, DrgPstat *pdrgpstat, CExpression *pexprScalar ) { GPOS_ASSERT(NULL != pexprScalar); GPOS_ASSERT(NULL != pdrgpstat); GPOS_ASSERT(0 < pdrgpstat->UlLength()); GPOS_ASSERT_IMP(fOuterJoin, 2 == pdrgpstat->UlLength()); // create an empty set of outer references for statistics derivation CColRefSet *pcrsOuterRefs = GPOS_NEW(pmp) CColRefSet(pmp); // join statistics objects one by one using relevant predicates in given scalar expression const ULONG ulStats = pdrgpstat->UlLength(); IStatistics *pstats = (*pdrgpstat)[0]->PstatsCopy(pmp); for (ULONG ul = 1; ul < ulStats; ul++) { IStatistics *pstatsCurrent = (*pdrgpstat)[ul]; DrgPcrs *pdrgpcrsOutput= GPOS_NEW(pmp) DrgPcrs(pmp); pdrgpcrsOutput->Append(pstats->Pcrs(pmp)); pdrgpcrsOutput->Append(pstatsCurrent->Pcrs(pmp)); CStatsPred *pstatspredUnsupported = NULL; DrgPstatsjoin *pdrgpstatsjoin = CStatsPredUtils::PdrgpstatsjoinExtract ( pmp, pexprScalar, pdrgpcrsOutput, pcrsOuterRefs, &pstatspredUnsupported ); IStatistics *pstatsNew = NULL; if (fOuterJoin) { pstatsNew = pstats->PstatsLOJ(pmp, pstatsCurrent, pdrgpstatsjoin); } else { pstatsNew = pstats->PstatsInnerJoin(pmp, pstatsCurrent, pdrgpstatsjoin); } pstats->Release(); pstats = pstatsNew; if (NULL != pstatspredUnsupported) { // apply the unsupported join filters as a filter on top of the join results. // TODO, June 13 2014 we currently only cap NDVs for filters // immediately on top of tables. IStatistics *pstatsAfterJoinFilter = pstats->PstatsFilter ( pmp, pstatspredUnsupported, false /* fCapNdvs */ ); pstats->Release(); pstats = pstatsAfterJoinFilter; pstatspredUnsupported->Release(); } pdrgpstatsjoin->Release(); pdrgpcrsOutput->Release(); } // clean up pcrsOuterRefs->Release(); return pstats; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PstatsJoinWithOuterRefs // // @doc: // Helper for deriving statistics for join operation based on given scalar expression // //--------------------------------------------------------------------------- IStatistics * CStatisticsUtils::PstatsJoinWithOuterRefs ( IMemoryPool *pmp, CExpressionHandle &exprhdl, DrgPstat *pdrgpstatChildren, CExpression *pexprScalarLocal, // filter expression on local columns only CExpression *pexprScalarOuterRefs, // filter expression involving outer references DrgPstat *pdrgpstatOuter ) { GPOS_ASSERT(NULL != pdrgpstatChildren); GPOS_ASSERT(NULL != pexprScalarLocal); GPOS_ASSERT(NULL != pexprScalarOuterRefs); GPOS_ASSERT(NULL != pdrgpstatOuter); COperator::EOperatorId eopid = exprhdl.Pop()->Eopid(); GPOS_ASSERT(COperator::EopLogicalLeftOuterJoin == eopid || COperator::EopLogicalInnerJoin == eopid || COperator::EopLogicalNAryJoin == eopid); BOOL fOuterJoin = (COperator::EopLogicalLeftOuterJoin == eopid); // derive stats based on local join condition IStatistics *pstatsResult = PstatsJoinArray(pmp, fOuterJoin, pdrgpstatChildren, pexprScalarLocal); if (exprhdl.FHasOuterRefs() && 0 < pdrgpstatOuter->UlLength()) { // derive stats based on outer references IStatistics *pstats = PstatsDeriveWithOuterRefs(pmp, fOuterJoin, exprhdl, pexprScalarOuterRefs, pstatsResult, pdrgpstatOuter); pstatsResult->Release(); pstatsResult = pstats; } return pstatsResult; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PstatsJoin // // @doc: // Derive statistics for join operation given array of statistics object // //--------------------------------------------------------------------------- IStatistics * CStatisticsUtils::PstatsJoin ( IMemoryPool *pmp, CExpressionHandle &exprhdl, DrgPstat *pdrgpstatCtxt ) { GPOS_ASSERT(CLogical::EspNone < CLogical::PopConvert(exprhdl.Pop())->Esp(exprhdl)); DrgPstat *pdrgpstat = GPOS_NEW(pmp) DrgPstat(pmp); const ULONG ulArity = exprhdl.UlArity(); for (ULONG ul = 0; ul < ulArity - 1; ul++) { IStatistics *pstatsChild = exprhdl.Pstats(ul); pstatsChild->AddRef(); pdrgpstat->Append(pstatsChild); } CExpression *pexprJoinPred = NULL; if (exprhdl.Pdpscalar(ulArity - 1)->FHasSubquery()) { // in case of subquery in join predicate, assume join condition is True pexprJoinPred = CUtils::PexprScalarConstBool(pmp, true /*fVal*/); } else { // remove implied predicates from join condition to avoid cardinality under-estimation pexprJoinPred = CPredicateUtils::PexprRemoveImpliedConjuncts(pmp, exprhdl.PexprScalarChild(ulArity - 1), exprhdl); } // split join predicate into local predicate and predicate involving outer references CExpression *pexprLocal = NULL; CExpression *pexprOuterRefs = NULL; // get outer references from expression handle CColRefSet *pcrsOuter = exprhdl.Pdprel()->PcrsOuter(); CPredicateUtils::SeparateOuterRefs(pmp, pexprJoinPred, pcrsOuter, &pexprLocal, &pexprOuterRefs); pexprJoinPred->Release(); IStatistics *pstatsJoin = PstatsJoinWithOuterRefs(pmp, exprhdl, pdrgpstat, pexprLocal, pexprOuterRefs, pdrgpstatCtxt); pexprLocal->Release(); pexprOuterRefs->Release(); pdrgpstat->Release(); return pstatsJoin; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PstatsDynamicScan // // @doc: // Derive statistics of dynamic scan based on the stats of corresponding // part-selector in the given map, // // for a given part table (R) with part selection predicate (R.pk=T.x), // the function assumes a LeftSemiJoin(R,T)_(R.pk=T.x) expression to // compute the stats of R after partitions are eliminated based on the // condition (R.pk=T.x) // //--------------------------------------------------------------------------- IStatistics * CStatisticsUtils::PstatsDynamicScan ( IMemoryPool *pmp, CExpressionHandle &exprhdl, ULONG ulPartIndexId, CPartFilterMap *ppfm ) { // extract part table base stats from passed handle IStatistics *pstatsBase = exprhdl.Pstats(); GPOS_ASSERT(NULL != pstatsBase); if (!GPOS_FTRACE(EopttraceDeriveStatsForDPE)) { // if stats derivation with dynamic partition elimitaion is disabled, we return base stats pstatsBase->AddRef(); return pstatsBase; } if(!ppfm->FContainsScanId(ulPartIndexId) || NULL == ppfm->Pstats(ulPartIndexId)) { // no corresponding entry is found in map, return base stats pstatsBase->AddRef(); return pstatsBase; } IStatistics *pstatsPartSelector = ppfm->Pstats(ulPartIndexId); CExpression *pexprScalar = ppfm->Pexpr(ulPartIndexId); DrgPcrs *pdrgpcrsOutput = GPOS_NEW(pmp) DrgPcrs(pmp); pdrgpcrsOutput->Append(pstatsBase->Pcrs(pmp)); pdrgpcrsOutput->Append(pstatsPartSelector->Pcrs(pmp)); CColRefSet *pcrsOuterRefs = GPOS_NEW(pmp) CColRefSet(pmp); // extract all the conjuncts CStatsPred *pstatspredUnsupported = NULL; DrgPstatsjoin *pdrgpstatsjoin = CStatsPredUtils::PdrgpstatsjoinExtract ( pmp, pexprScalar, pdrgpcrsOutput, pcrsOuterRefs, &pstatspredUnsupported ); IStatistics *pstatLSJoin = pstatsBase->PstatsLSJoin(pmp, pstatsPartSelector, pdrgpstatsjoin); // TODO: May 15 2014, handle unsupported predicates for LS joins // cleanup CRefCount::SafeRelease(pstatspredUnsupported); pdrgpcrsOutput->Release(); pcrsOuterRefs->Release(); pdrgpstatsjoin->Release(); return pstatLSJoin; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PstatsIndexGet // // @doc: // Derive statistics of (dynamic) index get // //--------------------------------------------------------------------------- IStatistics * CStatisticsUtils::PstatsIndexGet ( IMemoryPool *pmp, CExpressionHandle &exprhdl, DrgPstat *pdrgpstatCtxt ) { COperator::EOperatorId eopid = exprhdl.Pop()->Eopid() ; GPOS_ASSERT(CLogical::EopLogicalIndexGet == eopid || CLogical::EopLogicalDynamicIndexGet == eopid); // collect columns used by index conditions and distribution of the table // for statistics CColRefSet *pcrsUsed = GPOS_NEW(pmp) CColRefSet(pmp); CTableDescriptor *ptabdesc = NULL; if (CLogical::EopLogicalIndexGet == eopid) { CLogicalIndexGet *popIndexGet = CLogicalIndexGet::PopConvert(exprhdl.Pop()); ptabdesc = popIndexGet->Ptabdesc(); if (NULL != popIndexGet->PcrsDist()) { pcrsUsed->Include(popIndexGet->PcrsDist()); } } else { CLogicalDynamicIndexGet *popDynamicIndexGet = CLogicalDynamicIndexGet::PopConvert(exprhdl.Pop()); ptabdesc = popDynamicIndexGet->Ptabdesc(); if (NULL != popDynamicIndexGet->PcrsDist()) { pcrsUsed->Include(popDynamicIndexGet->PcrsDist()); } } CExpression *pexprScalar = exprhdl.PexprScalarChild(0 /*ulChidIndex*/); CExpression *pexprLocal = NULL; CExpression *pexprOuterRefs = NULL; // get outer references from expression handle CColRefSet *pcrsOuter = exprhdl.Pdprel()->PcrsOuter(); CPredicateUtils::SeparateOuterRefs(pmp, pexprScalar, pcrsOuter, &pexprLocal, &pexprOuterRefs); pcrsUsed->Union(exprhdl.Pdpscalar(0 /*ulChildIndex*/)->PcrsUsed()); // filter out outer references in used columns pcrsUsed->Difference(pcrsOuter); IStatistics *pstatsBaseTable = CLogical::PstatsBaseTable(pmp, exprhdl, ptabdesc, pcrsUsed); pcrsUsed->Release(); IStatistics *pstats = PstatsFilter(pmp, exprhdl, pstatsBaseTable, pexprLocal, pexprOuterRefs, pdrgpstatCtxt); pstatsBaseTable->Release(); pexprLocal->Release(); pexprOuterRefs->Release(); return pstats; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PstatsBitmapGet // // @doc: // Derive statistics of bitmap table get // //--------------------------------------------------------------------------- IStatistics * CStatisticsUtils::PstatsBitmapTableGet ( IMemoryPool *pmp, CExpressionHandle &exprhdl, DrgPstat *pdrgpstatCtxt ) { GPOS_ASSERT(CLogical::EopLogicalBitmapTableGet == exprhdl.Pop()->Eopid() || CLogical::EopLogicalDynamicBitmapTableGet == exprhdl.Pop()->Eopid()); CTableDescriptor *ptabdesc = CLogical::PtabdescFromTableGet(exprhdl.Pop()); // the index of the condition ULONG ulChildConditionIndex = 0; // get outer references from expression handle CColRefSet *pcrsOuter = exprhdl.Pdprel()->PcrsOuter(); CExpression *pexprLocal = NULL; CExpression *pexprOuterRefs = NULL; CExpression *pexprScalar = exprhdl.PexprScalarChild(ulChildConditionIndex); CPredicateUtils::SeparateOuterRefs(pmp, pexprScalar, pcrsOuter, &pexprLocal, &pexprOuterRefs); // collect columns used by the index CColRefSet *pcrsUsed = GPOS_NEW(pmp) CColRefSet(pmp); pcrsUsed->Union(exprhdl.Pdpscalar(ulChildConditionIndex)->PcrsUsed()); pcrsUsed->Difference(pcrsOuter); IStatistics *pstatsBaseTable = CLogical::PstatsBaseTable(pmp, exprhdl, ptabdesc, pcrsUsed); pcrsUsed->Release(); IStatistics *pstats = PstatsFilter ( pmp, exprhdl, pstatsBaseTable, pexprLocal, pexprOuterRefs, pdrgpstatCtxt ); pstatsBaseTable->Release(); pexprLocal->Release(); pexprOuterRefs->Release(); return pstats; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PhmpuldrgpulTblOpIdToGrpColsMap // // @doc: // Return the mapping between the table column used for grouping to the // logical operator id where it was defined. If the grouping column is // not a table column then the logical op id is initialized to ULONG_MAX //--------------------------------------------------------------------------- HMUlPdrgpul * CStatisticsUtils::PhmpuldrgpulTblOpIdToGrpColsMap ( IMemoryPool *pmp, CStatistics *pstats, const CColRefSet *pcrsGrpCols, CBitSet *pbsKeys // keys derived during optimization ) { GPOS_ASSERT(NULL != pcrsGrpCols); GPOS_ASSERT(NULL != pstats); HMUlPdrgpul *phmulpdrgpul = GPOS_NEW(pmp) HMUlPdrgpul(pmp); CColumnFactory *pcf = COptCtxt::PoctxtFromTLS()->Pcf(); // iterate over grouping columns CColRefSetIter crsi(*pcrsGrpCols); while (crsi.FAdvance()) { CColRef *pcr = crsi.Pcr(); ULONG ulColId = pcr->UlId(); if (NULL == pbsKeys || pbsKeys->FBit(ulColId)) { // if keys are available then only consider grouping columns defined as // key columns else consider all grouping columns const CColRef *pcr = pcf->PcrLookup(ulColId); const ULONG ulIdxUpperBoundNDVs = pstats->UlIndexUpperBoundNDVs(pcr); const DrgPul *pdrgpul = phmulpdrgpul->PtLookup(&ulIdxUpperBoundNDVs); if (NULL == pdrgpul) { DrgPul *pdrgpulNew = GPOS_NEW(pmp) DrgPul(pmp); pdrgpulNew->Append(GPOS_NEW(pmp) ULONG(ulColId)); #ifdef GPOS_DEBUG BOOL fres = #endif // GPOS_DEBUG phmulpdrgpul->FInsert(GPOS_NEW(pmp) ULONG(ulIdxUpperBoundNDVs), pdrgpulNew); GPOS_ASSERT(fres); } else { (const_cast<DrgPul *>(pdrgpul))->Append(GPOS_NEW(pmp) ULONG(ulColId)); } } } return phmulpdrgpul; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::AddNdvForAllGrpCols // // @doc: // Add the NDV for all of the grouping columns //--------------------------------------------------------------------------- void CStatisticsUtils::AddNdvForAllGrpCols ( IMemoryPool *pmp, const CStatistics *pstatsInput, const DrgPul *pdrgpulGrpCol, // array of grouping column ids from a source DrgPdouble *pdrgpdNDV // output array of ndvs ) { GPOS_ASSERT(NULL != pdrgpulGrpCol); GPOS_ASSERT(NULL != pstatsInput); GPOS_ASSERT(NULL != pdrgpdNDV); const ULONG ulCols = pdrgpulGrpCol->UlLength(); // iterate over grouping columns for (ULONG ul = 0; ul < ulCols; ul++) { ULONG ulColId = (*(*pdrgpulGrpCol)[ul]); CDouble dDistVals = CStatisticsUtils::DDefaultDistinctVals(pstatsInput->DRows()); const CHistogram *phist = pstatsInput->Phist(ulColId); if (NULL != phist) { dDistVals = phist->DDistinct(); if (phist->FEmpty()) { dDistVals = DDefaultDistinctVals(pstatsInput->DRows()); } } pdrgpdNDV->Append(GPOS_NEW(pmp) CDouble(dDistVals)); } } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PdrgPdoubleNDV // // @doc: // Extract NDVs for the given array of grouping columns. If one or more // of the grouping columns' NDV have been capped, table has been filtered, // then we add the maximum NDV only for computing the cardinality of // the group by. The logic is that number of groups cannot be greater // than the card of filter table. Else we add the NDVs for all grouping // columns as is. //--------------------------------------------------------------------------- DrgPdouble * CStatisticsUtils::PdrgPdoubleNDV ( IMemoryPool *pmp, CStatisticsConfig *pstatsconf, const IStatistics *pstats, CColRefSet *pcrsGrpCols, CBitSet *pbsKeys // keys derived during optimization ) { GPOS_ASSERT(NULL != pstats); GPOS_ASSERT(NULL != pcrsGrpCols); CStatistics *pstatsInput = CStatistics::PstatsConvert(const_cast<IStatistics *>(pstats)); DrgPdouble *pdrgpdNDV = GPOS_NEW(pmp) DrgPdouble(pmp); HMUlPdrgpul *phmulpdrgpul = PhmpuldrgpulTblOpIdToGrpColsMap(pmp, pstatsInput, pcrsGrpCols, pbsKeys); HMIterUlPdrgpul hmiterulpdrgpul(phmulpdrgpul); while (hmiterulpdrgpul.FAdvance()) { ULONG ulSourceId = *(hmiterulpdrgpul.Pk()); const DrgPul *pdrgpulPerSrc = hmiterulpdrgpul.Pt(); if (ULONG_MAX == ulSourceId) { // this array of grouping columns represents computed columns. // Since we currently do not cap computed columns, we add all of their NDVs as is AddNdvForAllGrpCols(pmp, pstatsInput, pdrgpulPerSrc, pdrgpdNDV); } else { // compute the maximum number of groups when aggregated on columns from the given source CDouble dMaxGrpsPerSrc = DMaxGroupsFromSource(pmp, pstatsconf, pstatsInput, pdrgpulPerSrc); pdrgpdNDV->Append(GPOS_NEW(pmp) CDouble(dMaxGrpsPerSrc)); } } // clean up phmulpdrgpul->Release(); return pdrgpdNDV; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::FExistsCappedGrpCol // // @doc: // Check to see if any one of the grouping columns has been capped //--------------------------------------------------------------------------- BOOL CStatisticsUtils::FExistsCappedGrpCol ( const CStatistics *pstats, const DrgPul *pdrgpulGrpCol ) { GPOS_ASSERT(NULL != pstats); GPOS_ASSERT(NULL != pdrgpulGrpCol); const ULONG ulCols = pdrgpulGrpCol->UlLength(); for (ULONG ul = 0; ul < ulCols; ul++) { ULONG ulColId = (*(*pdrgpulGrpCol)[ul]); const CHistogram *phist = pstats->Phist(ulColId); if (NULL != phist && phist->FScaledNDV()) { return true; } } return false; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::DMaxNdv // // @doc: // Return the maximum NDV given an array of grouping columns //--------------------------------------------------------------------------- CDouble CStatisticsUtils::DMaxNdv ( const CStatistics *pstats, const DrgPul *pdrgpulGrpCol ) { GPOS_ASSERT(NULL != pstats); GPOS_ASSERT(NULL != pdrgpulGrpCol); const ULONG ulGrpCols = pdrgpulGrpCol->UlLength(); CDouble dNdvMax(1.0); for (ULONG ul = 0; ul < ulGrpCols; ul++) { CDouble dNdv = CStatisticsUtils::DDefaultDistinctVals(pstats->DRows()); ULONG ulColId = (*(*pdrgpulGrpCol)[ul]); const CHistogram *phist = pstats->Phist(ulColId); if (NULL != phist) { dNdv = phist->DDistinct(); if (phist->FEmpty()) { dNdv = CStatisticsUtils::DDefaultDistinctVals(pstats->DRows()); } } if (dNdvMax < dNdv) { dNdvMax = dNdv; } } return dNdvMax; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::DMaxGroupsFromSource // // @doc: // Compute max number of groups when grouping on columns from the given source //--------------------------------------------------------------------------- CDouble CStatisticsUtils::DMaxGroupsFromSource ( IMemoryPool *pmp, CStatisticsConfig *pstatsconf, CStatistics *pstatsInput, const DrgPul *pdrgpulPerSrc ) { GPOS_ASSERT(NULL != pstatsInput); GPOS_ASSERT(NULL != pdrgpulPerSrc); GPOS_ASSERT(0 < pdrgpulPerSrc->UlLength()); CDouble dRowsInput = pstatsInput->DRows(); CColumnFactory *pcf = COptCtxt::PoctxtFromTLS()->Pcf(); CColRef *pcrFirst = pcf->PcrLookup(*(*pdrgpulPerSrc)[0]); CDouble dUpperBoundNDVs = pstatsInput->DUpperBoundNDVs(pcrFirst); DrgPdouble *pdrgpdNDV = GPOS_NEW(pmp) DrgPdouble(pmp); AddNdvForAllGrpCols(pmp, pstatsInput, pdrgpulPerSrc, pdrgpdNDV); // take the minimum of (a) the estimated number of groups from the columns of this source, // (b) input rows, and (c) cardinality upper bound for the given source in the // input statistics object // DNumOfDistVal internally damps the number of columns with our formula. // (a) For columns from the same table, they will be damped based on the formula in DNumOfDistVal // (b) If the group by has columns from multiple tables, they will again be damped by the formula // in DNumOfDistVal when we compute the final group by cardinality CDouble dGroups = std::min ( std::max ( CStatistics::DMinRows.DVal(), DNumOfDistinctVal(pstatsconf, pdrgpdNDV).DVal() ), std::min(dRowsInput.DVal(), dUpperBoundNDVs.DVal()) ); pdrgpdNDV->Release(); return dGroups; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::DGroups // // @doc: // Compute the cumulative number of groups for the given set of grouping columns // //--------------------------------------------------------------------------- CDouble CStatisticsUtils::DGroups ( IMemoryPool *pmp, IStatistics *pstats, CStatisticsConfig *pstatsconf, DrgPul *pdrgpulGC, CBitSet *pbsKeys // keys derived during optimization ) { GPOS_ASSERT(NULL != pstats); GPOS_ASSERT(NULL != pstatsconf); GPOS_ASSERT(NULL != pdrgpulGC); CColRefSet *pcrsGrpColComputed = GPOS_NEW(pmp) CColRefSet(pmp); CColRefSet *pcrsGrpColForStats = PcrsGrpColsForStats(pmp, pdrgpulGC, pcrsGrpColComputed); DrgPdouble *pdrgpdNDV = PdrgPdoubleNDV(pmp, pstatsconf, pstats, pcrsGrpColForStats, pbsKeys); CDouble dGroups = std::min ( std::max ( CStatistics::DMinRows.DVal(), DNumOfDistinctVal(pstatsconf, pdrgpdNDV).DVal() ), pstats->DRows().DVal() ); // clean up pcrsGrpColForStats->Release(); pcrsGrpColComputed->Release(); pdrgpdNDV->Release(); return dGroups; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::DNumOfDistinctVal // // @doc: // Compute the total number of groups of the group by operator // from the array of NDVs of the individual grouping columns //--------------------------------------------------------------------------- CDouble CStatisticsUtils::DNumOfDistinctVal ( CStatisticsConfig *pstatsconf, DrgPdouble *pdrgpdNDV ) { GPOS_ASSERT(NULL != pstatsconf); GPOS_ASSERT(NULL != pdrgpdNDV); CScaleFactorUtils::SortScalingFactor(pdrgpdNDV, true /* fDescending */); const ULONG ulDistVals = pdrgpdNDV->UlLength(); if (0 == ulDistVals) { return CDouble(1.0); } CDouble dCumulativeNDV = *(*pdrgpdNDV)[0]; for (ULONG ulDV = 1; ulDV < ulDistVals; ulDV++) { CDouble dNDV = *(*pdrgpdNDV)[ulDV]; CDouble dNDVDamped = std::max ( CHistogram::DMinDistinct.DVal(), (dNDV * CScaleFactorUtils::DDampingGroupBy(pstatsconf, ulDV)).DVal() ); dCumulativeNDV = dCumulativeNDV * dNDVDamped; } return dCumulativeNDV; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::AddGrpColStats // // @doc: // Add the statistics (histogram and width) of the grouping columns //--------------------------------------------------------------------------- void CStatisticsUtils::AddGrpColStats ( IMemoryPool *pmp, const CStatistics *pstatsInput, CColRefSet *pcrsGrpCols, HMUlHist *phmulhistOutput, HMUlDouble *phmuldoubleWidthOutput ) { GPOS_ASSERT(NULL != pstatsInput); GPOS_ASSERT(NULL != pcrsGrpCols); GPOS_ASSERT(NULL != phmulhistOutput); GPOS_ASSERT(NULL != phmuldoubleWidthOutput); // iterate over grouping columns CColRefSetIter crsi(*pcrsGrpCols); while (crsi.FAdvance()) { CColRef *pcr = crsi.Pcr(); ULONG ulGrpColId = pcr->UlId(); CDouble dDistVals(CHistogram::DMinDistinct); const CHistogram *phist = pstatsInput->Phist(ulGrpColId); if (NULL != phist) { CHistogram *phistAfter = phist->PhistGroupByNormalized(pmp, pstatsInput->DRows(), &dDistVals); if (phist->FScaledNDV()) { phistAfter->SetNDVScaled(); } AddHistogram(pmp, ulGrpColId, phistAfter, phmulhistOutput); GPOS_DELETE(phistAfter); } const CDouble *pdWidth = pstatsInput->PdWidth(ulGrpColId); if (NULL != pdWidth) { phmuldoubleWidthOutput->FInsert(GPOS_NEW(pmp) ULONG(ulGrpColId), GPOS_NEW(pmp) CDouble(*pdWidth)); } } } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::PcrsGrpColsForStats // // @doc: // Return the set of grouping columns for statistics computation. // If the grouping column (c) is a computed column, for example c = f(a,b), // then we include columns a and b as the grouping column instead of c. //--------------------------------------------------------------------------- CColRefSet * CStatisticsUtils::PcrsGrpColsForStats ( IMemoryPool *pmp, const DrgPul *pdrgpulGrpCol, CColRefSet *pcrsGrpColComputed ) { GPOS_ASSERT(NULL != pdrgpulGrpCol); GPOS_ASSERT(NULL != pcrsGrpColComputed); CColumnFactory *pcf = COptCtxt::PoctxtFromTLS()->Pcf(); CColRefSet *pcrsGrpColForStats = GPOS_NEW(pmp) CColRefSet(pmp); const ULONG ulGrpCols = pdrgpulGrpCol->UlLength(); // iterate over grouping columns for (ULONG ul = 0; ul < ulGrpCols; ul++) { ULONG ulColId = *(*pdrgpulGrpCol) [ul]; CColRef *pcrGrpCol = pcf->PcrLookup(ulColId); GPOS_ASSERT(NULL != pcrGrpCol); // check to see if the grouping column is a computed attribute const CColRefSet *pcrsUsed = pcf->PcrsUsedInComputedCol(pcrGrpCol); if (NULL == pcrsUsed || 0 == pcrsUsed->CElements()) { (void) pcrsGrpColForStats->Include(pcrGrpCol); } else { (void) pcrsGrpColForStats->Union(pcrsUsed); (void) pcrsGrpColComputed->Include(pcrGrpCol); } } return pcrsGrpColForStats; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::DNullFreqLASJ // // @doc: // Compute the null frequency for LASJ // //--------------------------------------------------------------------------- CDouble CStatisticsUtils::DNullFreqLASJ ( CStatsPred::EStatsCmpType escmpt, const CHistogram *phistOuter, const CHistogram *phistInner ) { GPOS_ASSERT(NULL != phistOuter); GPOS_ASSERT(NULL != phistInner); if (CStatsPred::EstatscmptINDF != escmpt) { // for equality predicate NULLs on the outer side of the join // will not join with those in the inner side return phistOuter->DNullFreq(); } if (CStatistics::DEpsilon < phistInner->DNullFreq()) { // for INDF predicate NULLs on the outer side of the join // will join with those in the inner side if they are present return CDouble(0.0); } return phistOuter->DNullFreq(); } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::DDistinct // // @doc: // Sum of number of distinct values in the given array of buckets // //--------------------------------------------------------------------------- CDouble CStatisticsUtils::DDistinct ( const DrgPbucket *pdrgppbucket ) { GPOS_ASSERT(NULL != pdrgppbucket); CDouble dDistinct = CDouble(0.0); const ULONG ulBuckets = pdrgppbucket->UlLength(); for (ULONG ulBucketIdx = 0; ulBucketIdx < ulBuckets; ulBucketIdx++) { CBucket *pbucket = (*pdrgppbucket)[ulBucketIdx]; dDistinct = dDistinct + pbucket->DDistinct(); } return dDistinct; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::DFrequency // // @doc: // Sum of the frequencies of buckets in the given array of buckets // //--------------------------------------------------------------------------- CDouble CStatisticsUtils::DFrequency ( const DrgPbucket *pdrgppbucket ) { GPOS_ASSERT(NULL != pdrgppbucket); CDouble dFreq = CDouble(0.0); const ULONG ulBuckets = pdrgppbucket->UlLength(); for (ULONG ulBucketIdx = 0; ulBucketIdx < ulBuckets; ulBucketIdx++) { CBucket *pbucket = (*pdrgppbucket)[ulBucketIdx]; dFreq = dFreq + pbucket->DFrequency(); } return dFreq; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::FIncreasesRisk // // @doc: // Return true if the given operator increases the risk of cardinality // misestimation. // //--------------------------------------------------------------------------- BOOL CStatisticsUtils::FIncreasesRisk ( CLogical *popLogical ) { if (popLogical->FSelectionOp()) { // operators that perform filters (e.g. joins, select) increase the risk return true; } static COperator::EOperatorId rgeopidGroupingAndSemiJoinOps[] = { COperator::EopLogicalGbAgg, COperator::EopLogicalIntersect, COperator::EopLogicalIntersectAll, COperator::EopLogicalUnion, COperator::EopLogicalDifference, COperator::EopLogicalDifferenceAll }; COperator::EOperatorId eopid = popLogical->Eopid(); for (ULONG ul = 0; ul < GPOS_ARRAY_SIZE(rgeopidGroupingAndSemiJoinOps); ul++) { if (rgeopidGroupingAndSemiJoinOps[ul] == eopid) { return true; } } return false; } //--------------------------------------------------------------------------- // @function: // CStatisticsUtils::DDefaultColumnWidth // // @doc: // Return the default column width // //--------------------------------------------------------------------------- CDouble CStatisticsUtils::DDefaultColumnWidth ( const IMDType *pmdtype ) { CDouble dWidth(CStatistics::DDefaultColumnWidth); if (pmdtype->FFixedLength()) { dWidth = CDouble(pmdtype->UlLength()); } return dWidth; } // EOF
27.993313
138
0.63664
vitessedata
ab557d5a1bfad72e3369f82383143e30ebed024e
720
cpp
C++
llvm/tools/clang/test/CodeGenCXX/mangle-literal-suffix.cpp
oslab-swrc/juxta
481cd6f01e87790041a07379805968bcf57d75f4
[ "MIT" ]
58
2016-08-27T03:19:14.000Z
2022-01-05T17:33:44.000Z
llvm/tools/clang/test/CodeGenCXX/mangle-literal-suffix.cpp
oslab-swrc/juxta
481cd6f01e87790041a07379805968bcf57d75f4
[ "MIT" ]
14
2017-12-01T17:16:59.000Z
2020-12-21T12:16:35.000Z
llvm/tools/clang/test/CodeGenCXX/mangle-literal-suffix.cpp
oslab-swrc/juxta
481cd6f01e87790041a07379805968bcf57d75f4
[ "MIT" ]
22
2016-11-27T09:53:31.000Z
2021-11-22T00:22:53.000Z
// RUN: %clang_cc1 -triple mips-none-none -emit-llvm -o - %s | FileCheck %s template <class T> void g3(char (&buffer)[sizeof(T() + 5.0)]) {} template void g3<int>(char (&)[sizeof(double)]); // CHECK: _Z2g3IiEvRAszplcvT__ELd4014000000000000E_c template <class T> void g4(char (&buffer)[sizeof(T() + 5.0L)]) {} template void g4<int>(char (&)[sizeof(long double)]); // CHECK: _Z2g4IiEvRAszplcvT__ELe4014000000000000E_c template <class T> void g5(char (&buffer)[sizeof(T() + 5)]) {} template void g5<int>(char (&)[sizeof(int)]); // CHECK: _Z2g5IiEvRAszplcvT__ELi5E_c template <class T> void g6(char (&buffer)[sizeof(T() + 5L)]) {} template void g6<int>(char (&)[sizeof(long int)]); // CHECK: _Z2g6IiEvRAszplcvT__ELl5E_c
40
75
0.691667
oslab-swrc
ab58451b672784990c2d510c4cdd98b33c1fe695
6,301
cc
C++
src/database_fs_locking.cc
reactive-systems/edacc_client
d15a42f4f02bf6985423bb900d91410b1d184390
[ "MIT" ]
null
null
null
src/database_fs_locking.cc
reactive-systems/edacc_client
d15a42f4f02bf6985423bb900d91410b1d184390
[ "MIT" ]
null
null
null
src/database_fs_locking.cc
reactive-systems/edacc_client
d15a42f4f02bf6985423bb900d91410b1d184390
[ "MIT" ]
null
null
null
/* * database_fs_locking.cc * * Created on: 13.03.2012 * Author: simon */ #include <string> #include <vector> #include <mysql/mysqld_error.h> #include "database.h" #include "database_fs_locking.h" #include "log.h" // the fsid, from database.cc extern int fsid; extern MYSQL* connection; /** * Tries to update the file lock.<br/> * @param instance the instance for which the lock should be updated * @return value != 0: success */ int update_file_lock(string &filename) { char *query = new char[4096]; snprintf(query, 1024, QUERY_UPDATE_FILE_LOCK, filename.c_str(), fsid); unsigned int tries = 0; do { if (database_query_update(query) == 1) { delete[] query; return mysql_affected_rows(connection) == 1; } } while (is_recoverable_error() && ++tries < max_recover_tries); log_error(AT, "Couldn't execute QUERY_UPDATE_FILE_LOCK query"); // TODO: do something delete[] query; return 0; } /** * Locks a file.<br/> * <br/> * On success it is guaranteed that this file was locked. * @param filename the name of the file which should be locked * @return -1 when the operation should be tried again, 0 on errors, 1 on success */ int lock_file(string &filename) { mysql_autocommit(connection, 0); // this query locks the entry with (filename, fsid) if existent // this is needed to determine if the the client which locked this file is dead // => only one client should check this and update the lock char *query = new char[4096]; snprintf(query, 1024, QUERY_CHECK_FILE_LOCK, filename.c_str(), fsid); MYSQL_RES* result; if (database_query_select(query, result) == 0) { log_error(AT, "Couldn't execute QUERY_CHECK_FILE_LOCK query"); delete[] query; mysql_rollback(connection); mysql_autocommit(connection, 1); return 0; } delete[] query; MYSQL_ROW row = mysql_fetch_row(result); if (row == NULL) { // file is currently not locked by another client // try to create a lock mysql_free_result(result); query = new char[1024]; snprintf(query, 1024, QUERY_LOCK_FILE, filename.c_str(), fsid); if (database_query_update(query) == 0) { // ER_DUP_ENTRY is ok -> was locked by another client if (mysql_errno(connection) != ER_DUP_ENTRY) { log_error(AT, "Couldn't execute QUERY_LOCK_FILE query"); } mysql_rollback(connection); mysql_autocommit(connection, 1); delete[] query; return -1; } mysql_commit(connection); mysql_autocommit(connection, 1); delete[] query; // success return 1; } else if (atoi(row[0]) > DOWNLOAD_TIMEOUT) { // file was locked by another client but DOWNLOAD_TIMEOUT reached // try to update the file lock => steal lock from dead client // might fail if another client was in the same situation (before the row lock) and faster mysql_free_result(result); int res = update_file_lock(filename); mysql_commit(connection); mysql_autocommit(connection, 1); return res; } mysql_free_result(result); mysql_commit(connection); mysql_autocommit(connection, 1); return 0; } /** * Removes the file lock. * @param filename the name of the file for which the lock should be removed * @return value != 0: success */ int unlock_file(string& filename) { char *query = new char[1024]; snprintf(query, 1024, QUERY_UNLOCK_FILE, filename.c_str(), fsid); unsigned int tries = 0; do { if (database_query_update(query) == 1) { delete[] query; return 1; } } while (is_recoverable_error() && ++tries < max_recover_tries); log_error(AT, "Couldn't execute QUERY_UNLOCK_FILE query"); delete[] query; return 0; } /** * Checks if the specified file with the file system id is currently locked by any client. * @param filename the filename to be checked * @return value != 0: file is locked */ int file_locked(string& filename) { char *query = new char[1024]; snprintf(query, 1024, QUERY_CHECK_FILE_LOCK, filename.c_str(), fsid); MYSQL_RES* result; if (database_query_select(query, result) == 0) { log_error(AT, "Couldn't execute QUERY_CHECK_FILE_LOCK query"); delete[] query; return 1; } delete[] query; MYSQL_ROW row = mysql_fetch_row(result); if (mysql_num_rows(result) < 1) { mysql_free_result(result); return 0; } int timediff = atoi(row[0]); mysql_free_result(result); return timediff <= DOWNLOAD_TIMEOUT; } /** * Updates the file lock until finished is set to true in the <code>File_lock_update</code> data structure.<br/> * <br/> * Will not delete the file lock. * @param ptr pointer to <code>File_lock_update</code> data structure. */ void *update_file_lock_thread(void* ptr) { File_lock_update* ilu = (File_lock_update*) ptr; // create connection MYSQL* con = NULL; if (!get_new_connection(con)) { log_error(AT, "[update_instance_lock_thread] Database connection attempt failed: %s", mysql_error(con)); return NULL; } // prepare query char *query = new char[1024]; snprintf(query, 1024, QUERY_UPDATE_FILE_LOCK, ilu->filename.c_str(), ilu->fsid); int qtime = 0; while (!ilu->finished) { if (qtime <= 0) { // update lastReport entry for this instance if (!database_query_update(query, con)) { log_error(AT, "[update_file_lock_thread] Couldn't execute QUERY_UPDATE_FILE_LOCK query for binary %s.", ilu->filename.c_str()); // TODO: do something delete[] query; return NULL; } qtime = DOWNLOAD_REFRESH; } sleep(1); qtime--; } delete[] query; mysql_close(con); log_message(LOG_DEBUG, "[update_file_lock_thread] Closed database connection"); return NULL; }
32.647668
144
0.615934
reactive-systems
ab5923966452a465b1ca20a7f4e091080c341a99
1,508
cpp
C++
libs/runtime_configuration/src/runtime_mode.cpp
jokteur/hpx
689ce9b586322c90f966ef84aa6eba190f037dd7
[ "BSL-1.0" ]
1,822
2015-01-03T11:22:37.000Z
2022-03-31T14:49:59.000Z
libs/runtime_configuration/src/runtime_mode.cpp
jokteur/hpx
689ce9b586322c90f966ef84aa6eba190f037dd7
[ "BSL-1.0" ]
3,288
2015-01-05T17:00:23.000Z
2022-03-31T18:49:41.000Z
libs/runtime_configuration/src/runtime_mode.cpp
jokteur/hpx
689ce9b586322c90f966ef84aa6eba190f037dd7
[ "BSL-1.0" ]
431
2015-01-07T06:22:14.000Z
2022-03-31T14:50:04.000Z
//////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2012 Bryce Adelstein-Lelbach // Copyright (c) 2012-2017 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //////////////////////////////////////////////////////////////////////////////// #include <hpx/config.hpp> #include <hpx/runtime_configuration/runtime_mode.hpp> #include <cstddef> #include <string> namespace hpx { namespace strings { char const* const runtime_mode_names[] = { "invalid", // -1 "console", // 0 "worker", // 1 "connect", // 2 "local", // 3 "default", // 4 }; } char const* get_runtime_mode_name(runtime_mode state) { if (state < runtime_mode::invalid || state >= runtime_mode::last) return "invalid (value out of bounds)"; return strings::runtime_mode_names[static_cast<int>(state) + 1]; } runtime_mode get_runtime_mode_from_name(std::string const& mode) { for (std::size_t i = 0; static_cast<runtime_mode>(i) < runtime_mode::last; ++i) { if (mode == strings::runtime_mode_names[i]) return static_cast<runtime_mode>(i - 1); } return runtime_mode::invalid; } } // namespace hpx
32.782609
80
0.525199
jokteur
ab5d5c911c98f1a043baf0cd01c29bd9cd2a0db7
185
cpp
C++
Sources/functions.cpp
Gabriel-Barbosa-Pereira/vilut
626ba392297552a15ced328a1f0fd4912b374faf
[ "MIT" ]
null
null
null
Sources/functions.cpp
Gabriel-Barbosa-Pereira/vilut
626ba392297552a15ced328a1f0fd4912b374faf
[ "MIT" ]
null
null
null
Sources/functions.cpp
Gabriel-Barbosa-Pereira/vilut
626ba392297552a15ced328a1f0fd4912b374faf
[ "MIT" ]
null
null
null
#include <cstdlib> #include <cmath> void net(){ system("ping www.google.com"); } double pit(double b, double c){ double a; a = sqrt(pow(b, 2) + pow(c, 2)); return a; }
15.416667
36
0.578378
Gabriel-Barbosa-Pereira
ab5dae9226c70ba540d9ab235c33a55b1e031d63
2,830
hpp
C++
modules/scene_manager/include/lifecycle_msgs/srv/get_available_states__response__rosidl_typesupport_opensplice_cpp.hpp
Omnirobotic/godot
d50b5d047bbf6c68fc458c1ad097321ca627185d
[ "CC-BY-3.0", "Apache-2.0", "MIT" ]
null
null
null
modules/scene_manager/include/lifecycle_msgs/srv/get_available_states__response__rosidl_typesupport_opensplice_cpp.hpp
Omnirobotic/godot
d50b5d047bbf6c68fc458c1ad097321ca627185d
[ "CC-BY-3.0", "Apache-2.0", "MIT" ]
3
2019-11-14T12:20:06.000Z
2020-08-07T13:51:10.000Z
modules/scene_manager/include/lifecycle_msgs/srv/get_available_states__response__rosidl_typesupport_opensplice_cpp.hpp
Omnirobotic/godot
d50b5d047bbf6c68fc458c1ad097321ca627185d
[ "CC-BY-3.0", "Apache-2.0", "MIT" ]
null
null
null
// generated from // rosidl_typesupport_opensplice_cpp/resource/msg__rosidl_typesupport_opensplice_cpp.hpp.em // generated code does not contain a copyright notice #ifndef LIFECYCLE_MSGS__SRV__GET_AVAILABLE_STATES__RESPONSE__ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_HPP_ #define LIFECYCLE_MSGS__SRV__GET_AVAILABLE_STATES__RESPONSE__ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_HPP_ #include "lifecycle_msgs/srv/get_available_states__response__struct.hpp" #include "lifecycle_msgs/srv/dds_opensplice/ccpp_GetAvailableStates_Response_.h" #include "rosidl_generator_c/message_type_support_struct.h" #include "rosidl_typesupport_interface/macros.h" #include "lifecycle_msgs/msg/rosidl_typesupport_opensplice_cpp__visibility_control.h" namespace DDS { class DomainParticipant; class DataReader; class DataWriter; } // namespace DDS namespace lifecycle_msgs { namespace srv { namespace typesupport_opensplice_cpp { ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_lifecycle_msgs extern void register_type__GetAvailableStates_Response( DDS::DomainParticipant * participant, const char * type_name); ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_lifecycle_msgs extern void convert_ros_message_to_dds( const lifecycle_msgs::srv::GetAvailableStates_Response & ros_message, lifecycle_msgs::srv::dds_::GetAvailableStates_Response_ & dds_message); ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_lifecycle_msgs extern void publish__GetAvailableStates_Response( DDS::DataWriter * topic_writer, const void * untyped_ros_message); ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_lifecycle_msgs extern void convert_dds_message_to_ros( const lifecycle_msgs::srv::dds_::GetAvailableStates_Response_ & dds_message, lifecycle_msgs::srv::GetAvailableStates_Response & ros_message); ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_lifecycle_msgs extern bool take__GetAvailableStates_Response( DDS::DataReader * topic_reader, bool ignore_local_publications, void * untyped_ros_message, bool * taken); ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_EXPORT_lifecycle_msgs const char * serialize__GetAvailableStates_Response( const void * untyped_ros_message, void * serialized_data); ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_EXPORT_lifecycle_msgs const char * deserialize__GetAvailableStates_Response( const uint8_t * buffer, unsigned length, void * untyped_ros_message); } // namespace typesupport_opensplice_cpp } // namespace srv } // namespace lifecycle_msgs #ifdef __cplusplus extern "C" { #endif ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_lifecycle_msgs const rosidl_message_type_support_t * ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_opensplice_cpp, lifecycle_msgs, srv, GetAvailableStates_Response)(); #ifdef __cplusplus } #endif #endif // LIFECYCLE_MSGS__SRV__GET_AVAILABLE_STATES__RESPONSE__ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_HPP_
30.430108
139
0.863604
Omnirobotic
ab5f1c641901a8ba056bddb959ce47d644460973
13,525
cpp
C++
src/Plugins/MoviePlugin/Movie2Data.cpp
irov/Mengine
b76e9f8037325dd826d4f2f17893ac2b236edad8
[ "MIT" ]
39
2016-04-21T03:25:26.000Z
2022-01-19T14:16:38.000Z
src/Plugins/MoviePlugin/Movie2Data.cpp
irov/Mengine
b76e9f8037325dd826d4f2f17893ac2b236edad8
[ "MIT" ]
23
2016-06-28T13:03:17.000Z
2022-02-02T10:11:54.000Z
src/Plugins/MoviePlugin/Movie2Data.cpp
irov/Mengine
b76e9f8037325dd826d4f2f17893ac2b236edad8
[ "MIT" ]
14
2016-06-22T20:45:37.000Z
2021-07-05T12:25:19.000Z
#include "Movie2Data.h" #include "Interface/ResourceServiceInterface.h" #include "Interface/MaterialEnumInterface.h" #include "Kernel/Materialable.h" #include "Kernel/Logger.h" #include "Kernel/DocumentHelper.h" #include "Kernel/AssertionMemoryPanic.h" #include "Kernel/ConstStringHelper.h" namespace Mengine { ////////////////////////////////////////////////////////////////////////// Movie2Data::Movie2Data() : m_movieData( nullptr ) { } ////////////////////////////////////////////////////////////////////////// Movie2Data::~Movie2Data() { if( m_movieData != nullptr ) { ae_delete_movie_data( m_movieData ); m_movieData = nullptr; } } ////////////////////////////////////////////////////////////////////////// bool Movie2Data::acquire() { //Empty return true; } ////////////////////////////////////////////////////////////////////////// void Movie2Data::release() { //Empty } ////////////////////////////////////////////////////////////////////////// static ae_bool_t __ae_movie_resource_image_acquire( const aeMovieResourceImage * _resource, const Movie2Data * _data ) { MENGINE_UNUSED( _data ); ae_userdata_t resource_ud = ae_get_movie_resource_userdata( (const aeMovieResource *)_resource ); Movie2Data::ImageDesc * image_desc = reinterpret_cast<Movie2Data::ImageDesc *>(resource_ud); ResourceImage * resourceImage = image_desc->resourceImage; if( resourceImage->compile() == false ) { return AE_FALSE; } if( ++image_desc->refcount == 1 ) { image_desc->materials[EMB_NORMAL] = Helper::makeImageMaterial( ResourceImagePtr::from( resourceImage ), ConstString::none(), EMB_NORMAL, false, false, MENGINE_DOCUMENT_FORWARD_PTR( _data ) ); image_desc->materials[EMB_ADD] = Helper::makeImageMaterial( ResourceImagePtr::from( resourceImage ), ConstString::none(), EMB_ADD, false, false, MENGINE_DOCUMENT_FORWARD_PTR( _data ) ); image_desc->materials[EMB_SCREEN] = Helper::makeImageMaterial( ResourceImagePtr::from( resourceImage ), ConstString::none(), EMB_SCREEN, false, false, MENGINE_DOCUMENT_FORWARD_PTR( _data ) ); image_desc->materials[EMB_MULTIPLY] = Helper::makeImageMaterial( ResourceImagePtr::from( resourceImage ), ConstString::none(), EMB_MULTIPLY, false, false, MENGINE_DOCUMENT_FORWARD_PTR( _data ) ); } return AE_TRUE; } ////////////////////////////////////////////////////////////////////////// static ae_bool_t __ae_movie_layer_data_visitor_acquire( const aeMovieCompositionData * _compositionData, const aeMovieLayerData * _layer, ae_userdata_t _ud ) { AE_UNUSED( _compositionData ); const Movie2Data * data = reinterpret_cast<const Movie2Data *>(_ud); aeMovieResourceTypeEnum resource_type = ae_get_movie_layer_data_resource_type( _layer ); switch( resource_type ) { case AE_MOVIE_RESOURCE_SEQUENCE: { const aeMovieResource * resource = ae_get_movie_layer_data_resource( _layer ); const aeMovieResourceSequence * resource_sequence = (const aeMovieResourceSequence *)resource; for( ae_uint32_t index = 0; index != resource_sequence->image_count; ++index ) { const aeMovieResourceImage * resource_image = resource_sequence->images[index]; if( __ae_movie_resource_image_acquire( resource_image, data ) == AE_FALSE ) { return AE_FALSE; } } return AE_TRUE; }break; case AE_MOVIE_RESOURCE_IMAGE: { const aeMovieResource * resource = ae_get_movie_layer_data_resource( _layer ); const aeMovieResourceImage * resource_image = reinterpret_cast<const aeMovieResourceImage *>(resource); if( __ae_movie_resource_image_acquire( resource_image, data ) == AE_FALSE ) { return AE_FALSE; } return AE_TRUE; }break; case AE_MOVIE_RESOURCE_VIDEO: case AE_MOVIE_RESOURCE_SOUND: case AE_MOVIE_RESOURCE_PARTICLE: { ae_userdata_t resource_ud = ae_get_movie_layer_data_resource_userdata( _layer ); if( resource_ud == AE_USERDATA_NULL ) { return AE_TRUE; } Resource * resource = reinterpret_cast<Resource *>(resource_ud); if( resource->compile() == false ) { return AE_FALSE; } return AE_TRUE; }break; default: break; } return AE_TRUE; } ////////////////////////////////////////////////////////////////////////// bool Movie2Data::acquireCompositionData( const aeMovieCompositionData * _compositionData ) { if( ae_visit_composition_layer_data( _compositionData, &__ae_movie_layer_data_visitor_acquire, this ) == AE_FALSE ) { return false; } return true; } ////////////////////////////////////////////////////////////////////////// static void __ae_movie_resource_image_release( const aeMovieResourceImage * _resource ) { ae_userdata_t resource_ud = ae_get_movie_resource_userdata( (const aeMovieResource *)_resource ); Movie2Data::ImageDesc * image_desc = reinterpret_cast<Movie2Data::ImageDesc *>(resource_ud); ResourceImage * resourceImage = image_desc->resourceImage; resourceImage->release(); if( --image_desc->refcount == 0 ) { image_desc->materials[EMB_NORMAL] = nullptr; image_desc->materials[EMB_ADD] = nullptr; image_desc->materials[EMB_SCREEN] = nullptr; image_desc->materials[EMB_MULTIPLY] = nullptr; } } ////////////////////////////////////////////////////////////////////////// static ae_bool_t __ae_movie_layer_data_visitor_release( const aeMovieCompositionData * _compositionData, const aeMovieLayerData * _layer, ae_userdata_t _ud ) { AE_UNUSED( _compositionData ); AE_UNUSED( _ud ); aeMovieResourceTypeEnum resource_type = ae_get_movie_layer_data_resource_type( _layer ); switch( resource_type ) { case AE_MOVIE_RESOURCE_SEQUENCE: { const aeMovieResource * resource = ae_get_movie_layer_data_resource( _layer ); const aeMovieResourceSequence * resource_sequence = (const aeMovieResourceSequence *)resource; for( ae_uint32_t index = 0; index != resource_sequence->image_count; ++index ) { const aeMovieResourceImage * resource_image = resource_sequence->images[index]; __ae_movie_resource_image_release( resource_image ); } return AE_TRUE; }break; case AE_MOVIE_RESOURCE_IMAGE: { const aeMovieResource * resource = ae_get_movie_layer_data_resource( _layer ); const aeMovieResourceImage * resource_image = reinterpret_cast<const aeMovieResourceImage *>(resource); __ae_movie_resource_image_release( resource_image ); return AE_TRUE; }break; case AE_MOVIE_RESOURCE_VIDEO: case AE_MOVIE_RESOURCE_SOUND: case AE_MOVIE_RESOURCE_PARTICLE: { ae_userdata_t resource_ud = ae_get_movie_layer_data_resource_userdata( _layer ); if( resource_ud == AE_USERDATA_NULL ) { return AE_TRUE; } Resource * resource = reinterpret_cast<Resource *>(resource_ud); resource->release(); return AE_TRUE; }break; default: break; } return AE_TRUE; } ////////////////////////////////////////////////////////////////////////// void Movie2Data::releaseCompositionData( const aeMovieCompositionData * _compositionData ) { ae_visit_composition_layer_data( _compositionData, &__ae_movie_layer_data_visitor_release, this ); } ////////////////////////////////////////////////////////////////////////// static ae_bool_t __ae_movie_layer_data_visitor_get( const aeMovieCompositionData * _compositionData, const aeMovieLayerData * _layer, ae_userdata_t _ud ) { AE_UNUSED( _compositionData ); const Movie2DataInterface::LambdaResource * lambda = reinterpret_cast<const Movie2DataInterface::LambdaResource *>(_ud); aeMovieResourceTypeEnum resource_type = ae_get_movie_layer_data_resource_type( _layer ); switch( resource_type ) { case AE_MOVIE_RESOURCE_SEQUENCE: { const aeMovieResource * resource = ae_get_movie_layer_data_resource( _layer ); const aeMovieResourceSequence * resource_sequence = (const aeMovieResourceSequence *)resource; for( ae_uint32_t index = 0; index != resource_sequence->image_count; ++index ) { const aeMovieResourceImage * resource_image = resource_sequence->images[index]; ae_userdata_t resource_ud = ae_get_movie_resource_userdata( (const aeMovieResource *)resource_image ); Movie2Data::ImageDesc * image_desc = reinterpret_cast<Movie2Data::ImageDesc *>(resource_ud); ResourceImage * resourceImage = image_desc->resourceImage; (*lambda)(ResourcePtr::from( resourceImage )); } return AE_TRUE; }break; case AE_MOVIE_RESOURCE_IMAGE: { const aeMovieResource * resource = ae_get_movie_layer_data_resource( _layer ); const aeMovieResourceImage * resource_image = reinterpret_cast<const aeMovieResourceImage *>(resource); ae_userdata_t resource_ud = ae_get_movie_resource_userdata( (const aeMovieResource *)resource_image ); Movie2Data::ImageDesc * image_desc = reinterpret_cast<Movie2Data::ImageDesc *>(resource_ud); ResourceImage * resourceImage = image_desc->resourceImage; (*lambda)(ResourcePtr::from( resourceImage )); return AE_TRUE; }break; case AE_MOVIE_RESOURCE_VIDEO: case AE_MOVIE_RESOURCE_SOUND: case AE_MOVIE_RESOURCE_PARTICLE: { ae_userdata_t resource_ud = ae_get_movie_layer_data_resource_userdata( _layer ); if( resource_ud == AE_USERDATA_NULL ) { return AE_TRUE; } Resource * resource = reinterpret_cast<Resource *>(resource_ud); (*lambda)(ResourcePtr::from( resource )); return AE_TRUE; }break; default: break; } return AE_TRUE; } ////////////////////////////////////////////////////////////////////////// void Movie2Data::visitCompositionDataResources( const aeMovieCompositionData * _compositionData, const LambdaResource & _lambda ) { ae_visit_composition_layer_data( _compositionData, &__ae_movie_layer_data_visitor_get, const_cast<void *>(reinterpret_cast<const void *>(&_lambda)) ); } ////////////////////////////////////////////////////////////////////////// void Movie2Data::setGroupName( const ConstString & _groupName ) { m_groupName = _groupName; } ////////////////////////////////////////////////////////////////////////// const ConstString & Movie2Data::getGroupName() const { return m_groupName; } ////////////////////////////////////////////////////////////////////////// void Movie2Data::setMovieData( const aeMovieData * _movieData ) { m_movieData = _movieData; } ////////////////////////////////////////////////////////////////////////// const aeMovieData * Movie2Data::getMovieData() const { return m_movieData; } ////////////////////////////////////////////////////////////////////////// const ResourcePtr & Movie2Data::getResource( const Char * _resourceName ) { const ResourcePtr & resource = RESOURCE_SERVICE() ->getResourceReference( m_groupName, Helper::stringizeString( _resourceName ) ); MENGINE_ASSERTION_MEMORY_PANIC( resource, "not found resource '%s'" , _resourceName ); return resource; } ////////////////////////////////////////////////////////////////////////// Movie2Data::ImageDesc * Movie2Data::makeImageDesc( const ResourcePtr & _resource ) { ImageDesc * desc = m_poolImageDesc.createT(); desc->refcount = 0; desc->resourceImage = Helper::staticResourceCast<ResourceImage *>( _resource.get() ); return desc; } ////////////////////////////////////////////////////////////////////////// void Movie2Data::removeImageDesc( ImageDesc * _desc ) { m_poolImageDesc.destroyT( _desc ); } ////////////////////////////////////////////////////////////////////////// }
38.642857
207
0.553789
irov
ab5fb7104d3fc5fd3e30669b6db3c6dc3eb94ca3
4,045
cpp
C++
src/armnnTfParser/test/Gather.cpp
Project-Xtended/external_armnn
c5e1bbf9fc8ecbb8c9eb073a1550d4c8c15fce94
[ "MIT" ]
2
2021-12-09T15:14:04.000Z
2021-12-10T01:37:53.000Z
src/armnnTfParser/test/Gather.cpp
Project-Xtended/external_armnn
c5e1bbf9fc8ecbb8c9eb073a1550d4c8c15fce94
[ "MIT" ]
null
null
null
src/armnnTfParser/test/Gather.cpp
Project-Xtended/external_armnn
c5e1bbf9fc8ecbb8c9eb073a1550d4c8c15fce94
[ "MIT" ]
3
2022-01-23T11:34:40.000Z
2022-02-12T15:51:37.000Z
// // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "armnnTfParser/ITfParser.hpp" #include "ParserPrototxtFixture.hpp" #include <PrototxtConversions.hpp> #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_SUITE(TensorflowParser) namespace { // helper for setting the dimensions in prototxt void dimsHelper(const std::vector<int>& dims, std::string& text){ for(unsigned int i = 0; i < dims.size(); ++i) { text.append(R"(dim { size: )"); text.append(std::to_string(dims[i])); text.append(R"( })"); } } // helper for converting from integer to octal representation void octalHelper(const std::vector<int>& indicesContent, std::string& text){ for(unsigned int i = 0; i < indicesContent.size(); ++i) { text.append(armnnUtils::ConvertInt32ToOctalString(static_cast<int>(indicesContent[i]))); } } } // namespace struct GatherFixture : public armnnUtils::ParserPrototxtFixture<armnnTfParser::ITfParser> { GatherFixture(const armnn::TensorShape& inputShape0, const armnn::TensorShape& inputShape1, const std::vector<int>& input1Content, const std::vector<int>& input0Dims, const std::vector<int>& input1Dims, int axis = 0) { m_Prototext = R"( node { name: "input0" op: "Placeholder" attr { key: "dtype" value { type: DT_FLOAT } } attr { key: "shape" value { shape { )"; dimsHelper(input0Dims, m_Prototext); m_Prototext.append(R"( } } } } node { name: "input1" op: "Const" attr { key: "dtype" value { type: DT_INT32 } } attr { key: "value" value { tensor { dtype: DT_INT32 tensor_shape { )"); dimsHelper(input1Dims, m_Prototext); m_Prototext.append(R"( } tensor_content: ")"); octalHelper(input1Content, m_Prototext); m_Prototext.append(R"(" } } } } node { name: "output" op: "Gather" input: "input0" input: "input1" attr { key: "Tindices" value { type: DT_INT32 } } attr { key: "Tparams" value { type: DT_FLOAT } } attr { key: "axis" value { i: )"); m_Prototext += std::to_string(axis); m_Prototext.append(R"( } } } )"); Setup({ { "input0", inputShape0 }, { "input1", inputShape1 } }, { "output" }); } }; struct GatherFixture1DParams1DIndices : public GatherFixture { GatherFixture1DParams1DIndices() : GatherFixture( { 4, 1, 1, 1 }, { 4, 0, 0, 0 }, { 0, 2, 1, 3 }, { 4 }, { 4 }, 0) {} }; struct GatherFixture1DParamsMultiDimIndices : public GatherFixture { GatherFixture1DParamsMultiDimIndices() : GatherFixture( { 4, 1, 1 }, { 2, 2, 1, 1 }, { 0, 1, 1, 3 }, { 4 }, { 2, 2 }, 0) {} }; struct GatherFixtureMultiDimParamMultiDimIndices : public GatherFixture { GatherFixtureMultiDimParamMultiDimIndices() : GatherFixture( { 5, 2, 1 }, { 2, 1, 4 }, { 1, 3, 0, 2 }, { 5, 2 }, { 2, 2 }, 0) {} }; BOOST_FIXTURE_TEST_CASE(ParseGather1DParams1DIndices, GatherFixture1DParams1DIndices) { RunTest<4>({ { "input0", { 1, 2, 3, 4 } } }, { { "output", { 1, 3, 2, 4 } } }); } BOOST_FIXTURE_TEST_CASE(ParseGather1DParamsMultiDimIndices, GatherFixture1DParamsMultiDimIndices) { RunTest<4>({ { "input0", { 1, 2, 3, 4 } } }, { { "output", { 1, 2, 2, 4 } } }); } BOOST_FIXTURE_TEST_CASE(ParseGatherMultiDimParamMultiDimIndices, GatherFixtureMultiDimParamMultiDimIndices) { RunTest<4>({ { "input0", { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } } }, { { "output", { 3, 4, 7, 8, 1, 2, 5, 6} } }); } BOOST_AUTO_TEST_SUITE_END()
21.864865
107
0.549567
Project-Xtended
ab601c9dfd7974cee110faf31abd8da455ea5cf0
176
hpp
C++
hiro/cocoa/header.hpp
CasualPokePlayer/ares
58690cd5fc7bb6566c22935c5b80504a158cca29
[ "BSD-3-Clause" ]
153
2020-07-25T17:55:29.000Z
2021-10-01T23:45:01.000Z
hiro/cocoa/header.hpp
CasualPokePlayer/ares
58690cd5fc7bb6566c22935c5b80504a158cca29
[ "BSD-3-Clause" ]
245
2021-10-08T09:14:46.000Z
2022-03-31T08:53:13.000Z
hiro/cocoa/header.hpp
CasualPokePlayer/ares
58690cd5fc7bb6566c22935c5b80504a158cca29
[ "BSD-3-Clause" ]
44
2020-07-25T08:51:55.000Z
2021-09-25T16:09:01.000Z
#include <nall/macos/guard.hpp> #include <Cocoa/Cocoa.h> #include <Carbon/Carbon.h> #include <IOKit/pwr_mgt/IOPMLib.h> #include <nall/macos/guard.hpp> #include <nall/run.hpp>
22
34
0.738636
CasualPokePlayer
ab607b4662e0307b79748fff8fc9c806dfd9f8bb
43,850
cc
C++
unittest/types_t.cc
mysql/mysql-shell
7a299599a79ef2b2f578ffa41cbc901a88fc6b62
[ "Apache-2.0" ]
119
2016-04-14T14:16:22.000Z
2022-03-08T20:24:38.000Z
unittest/types_t.cc
mysql/mysql-shell
7a299599a79ef2b2f578ffa41cbc901a88fc6b62
[ "Apache-2.0" ]
9
2017-04-26T20:48:42.000Z
2021-09-07T01:52:44.000Z
unittest/types_t.cc
mysql/mysql-shell
7a299599a79ef2b2f578ffa41cbc901a88fc6b62
[ "Apache-2.0" ]
51
2016-07-20T05:06:48.000Z
2022-03-09T01:20:53.000Z
/* * Copyright (c) 2014, 2021, Oracle and/or its affiliates. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2.0, * as published by the Free Software Foundation. * * This program is also distributed with certain software (including * but not limited to OpenSSL) that is licensed under separate terms, as * designated in a particular file or component or in included license * documentation. The authors of MySQL hereby grant you an additional * permission to link the program and your derivative works with the * separately licensed software that they have included with MySQL. * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License, version 2.0, for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include <algorithm> #include <cstdio> #include <cstdlib> #include <fstream> #include <random> #include <string> #include "scripting/types.h" #include "scripting/types_cpp.h" #include "unittest/test_utils.h" using namespace ::testing; namespace shcore { namespace tests { TEST(ValueTests, SimpleInt) { shcore::Value v(20); std::string mydescr = v.descr(true); std::string myrepr = v.repr(); std::string myjson = v.json(); EXPECT_EQ(shcore::Integer, v.type); EXPECT_STREQ("20", mydescr.c_str()); EXPECT_STREQ("20", myrepr.c_str()); EXPECT_STREQ("20", myjson.c_str()); shcore::Value v2 = Value::parse(myrepr); mydescr = v2.descr(true); myrepr = v2.repr(); myjson = v2.json(); EXPECT_EQ(shcore::Integer, v2.type); EXPECT_STREQ("20", mydescr.c_str()); EXPECT_STREQ("20", myrepr.c_str()); EXPECT_STREQ("20", myjson.c_str()); } TEST(ValueTests, SimpleBool) { shcore::Value v; v = shcore::Value(true); EXPECT_EQ(shcore::Bool, v.type); EXPECT_STREQ("true", v.descr().c_str()); EXPECT_STREQ("true", v.repr().c_str()); EXPECT_STREQ("true", v.json().c_str()); v = shcore::Value(false); EXPECT_EQ(shcore::Bool, v.type); EXPECT_STREQ("false", v.descr().c_str()); EXPECT_STREQ("false", v.repr().c_str()); EXPECT_STREQ("false", v.json().c_str()); EXPECT_EQ(Value::True().as_bool(), true); EXPECT_TRUE(Value::True() == Value::True()); EXPECT_TRUE(Value::True() == Value(1)); EXPECT_FALSE(Value::True() == Value(1.1)); EXPECT_FALSE(Value::True() == Value("1")); EXPECT_FALSE(Value::True() == Value::Null()); EXPECT_TRUE(Value::False() == Value(0)); EXPECT_FALSE(Value::False() == Value(0.1)); EXPECT_FALSE(Value::False() == Value("0")); EXPECT_FALSE(Value::False() == Value::Null()); } TEST(ValueTests, SimpleDouble) { EXPECT_EQ(Value(1.1234).as_double(), 1.1234); } TEST(ValueTests, Conversion) { // OK conversions EXPECT_THROW(Value::Null().as_bool(), shcore::Exception); EXPECT_EQ(true, Value::True().as_bool()); EXPECT_FALSE(Value::False().as_bool()); EXPECT_EQ(true, Value(42).as_bool()); EXPECT_FALSE(Value(0).as_bool()); EXPECT_EQ(true, Value(42U).as_bool()); EXPECT_FALSE(Value(0U).as_bool()); EXPECT_EQ(true, Value(42.5).as_bool()); EXPECT_FALSE(Value(0.0).as_bool()); EXPECT_FALSE(Value("0").as_bool()); EXPECT_FALSE(Value("false").as_bool()); EXPECT_TRUE(Value("1").as_bool()); EXPECT_TRUE(Value("true").as_bool()); EXPECT_THROW(Value("foo").as_bool(), shcore::Exception); EXPECT_THROW(Value::new_array().as_bool(), shcore::Exception); EXPECT_THROW(Value::new_map().as_bool(), shcore::Exception); EXPECT_EQ(1, Value::True().as_int()); EXPECT_EQ(0, Value::False().as_int()); EXPECT_EQ(-42, Value(-42).as_int()); EXPECT_EQ(42, Value(42).as_int()); EXPECT_EQ(0, Value(0).as_int()); EXPECT_EQ(42, Value(42U).as_int()); EXPECT_EQ(0, Value(0U).as_int()); EXPECT_EQ(-42, Value(-42.0).as_int()); EXPECT_EQ(42, Value(42.0).as_int()); EXPECT_THROW(Value(-42.5).as_uint(), shcore::Exception); EXPECT_THROW(Value(42.5).as_uint(), shcore::Exception); EXPECT_EQ(0, Value(0.0).as_int()); EXPECT_EQ(-42, Value("-42").as_int()); EXPECT_EQ(42, Value("42").as_int()); EXPECT_THROW(Value("foo").as_int(), shcore::Exception); EXPECT_THROW(Value::new_array().as_int(), shcore::Exception); EXPECT_THROW(Value::new_map().as_int(), shcore::Exception); EXPECT_EQ(1, Value::True().as_uint()); EXPECT_EQ(0, Value::False().as_uint()); EXPECT_THROW(Value(-42).as_uint(), shcore::Exception); EXPECT_THROW(Value("-42").as_uint(), shcore::Exception); EXPECT_EQ(42, Value(42).as_uint()); EXPECT_EQ(0, Value(0).as_uint()); EXPECT_EQ(42, Value(42U).as_uint()); EXPECT_EQ(0, Value(0U).as_uint()); EXPECT_EQ(42, Value("42").as_uint()); EXPECT_EQ(42, Value(42.0).as_uint()); EXPECT_THROW(Value(-42.5).as_uint(), shcore::Exception); EXPECT_THROW(Value(42.5).as_uint(), shcore::Exception); EXPECT_THROW(Value("42.0").as_uint(), shcore::Exception); EXPECT_EQ(0, Value(0.0).as_uint()); EXPECT_THROW(Value("foo").as_uint(), shcore::Exception); EXPECT_THROW(Value::new_array().as_uint(), shcore::Exception); EXPECT_THROW(Value::new_map().as_uint(), shcore::Exception); EXPECT_EQ(1.0, Value::True().as_double()); EXPECT_EQ(0.0, Value::False().as_double()); EXPECT_EQ(-42.0, Value(-42).as_double()); EXPECT_EQ(42.0, Value(42).as_double()); EXPECT_EQ(0.0, Value(0).as_double()); EXPECT_EQ(42.0, Value(42U).as_double()); EXPECT_EQ(0.0, Value(0U).as_double()); EXPECT_EQ(-42.5, Value(-42.5).as_double()); EXPECT_EQ(42.5, Value(42.5).as_double()); EXPECT_EQ(0.0, Value(0.0).as_double()); EXPECT_EQ(-42.5, Value("-42.5").as_double()); EXPECT_EQ(42.5, Value("42.5").as_double()); EXPECT_THROW(Value("foo").as_double(), shcore::Exception); EXPECT_THROW(Value::new_array().as_double(), shcore::Exception); EXPECT_THROW(Value::new_map().as_double(), shcore::Exception); EXPECT_EQ("true", Value::True().as_string()); EXPECT_EQ("false", Value::False().as_string()); EXPECT_EQ("-42", Value(-42).as_string()); EXPECT_EQ("42", Value(static_cast<uint64_t>(42)).as_string()); EXPECT_EQ("42.5", Value(42.5).as_string()); } TEST(ValueTests, ConversionRanges) { static constexpr uint64_t kBiggestUIntThatFitsInDouble = (1ULL << DBL_MANT_DIG); static constexpr int64_t kSmallestIntThatFitsInDouble = -(1LL << DBL_MANT_DIG); static constexpr int64_t kBiggestIntThatFitsInDouble = (1LL << DBL_MANT_DIG); // int64_t -> uint64_t // min -> error // max -> OK EXPECT_THROW(Value(std::numeric_limits<int64_t>::min()).as_uint(), shcore::Exception); EXPECT_TRUE(static_cast<uint64_t>(std::numeric_limits<int64_t>::max()) == Value(std::numeric_limits<int64_t>::max()).as_uint()); // int64_t -> double // min -> error // max -> error EXPECT_THROW(Value(std::numeric_limits<int64_t>::min()).as_double(), shcore::Exception); EXPECT_THROW(Value(std::numeric_limits<int64_t>::max()).as_double(), shcore::Exception); EXPECT_TRUE(Value(kBiggestIntThatFitsInDouble).as_double() == kBiggestIntThatFitsInDouble); EXPECT_THROW(Value(kBiggestIntThatFitsInDouble + 1).as_double(), shcore::Exception); EXPECT_TRUE(Value(kSmallestIntThatFitsInDouble).as_double() == kSmallestIntThatFitsInDouble); EXPECT_THROW(Value(kSmallestIntThatFitsInDouble - 1).as_double(), shcore::Exception); // uint64_t -> int64_t // min -> OK // max -> error EXPECT_TRUE(std::numeric_limits<uint64_t>::min() == static_cast<uint64_t>( Value(std::numeric_limits<uint64_t>::min()).as_int())); EXPECT_THROW(Value(std::numeric_limits<uint64_t>::max()).as_int(), shcore::Exception); // uint64_t -> double // min -> OK // max -> error EXPECT_TRUE(std::numeric_limits<uint64_t>::min() == Value(std::numeric_limits<uint64_t>::min()).as_double()); EXPECT_THROW(Value(std::numeric_limits<uint64_t>::max()).as_double(), shcore::Exception); EXPECT_TRUE(Value(kBiggestUIntThatFitsInDouble).as_double() == kBiggestUIntThatFitsInDouble); EXPECT_THROW(Value(kBiggestUIntThatFitsInDouble + 1).as_double(), shcore::Exception); // double -> int64_t // min -> error (min for a double means the smallest number in (0.0, 1.0) // interval) max -> error EXPECT_THROW(Value(std::numeric_limits<double>::lowest()).as_int(), shcore::Exception); EXPECT_THROW(Value(std::numeric_limits<double>::max()).as_int(), shcore::Exception); EXPECT_TRUE( Value(static_cast<double>(kBiggestIntThatFitsInDouble)).as_int() == kBiggestIntThatFitsInDouble); EXPECT_THROW( Value(static_cast<double>(kBiggestIntThatFitsInDouble) + 2.0).as_int(), shcore::Exception); EXPECT_TRUE( Value(static_cast<double>(kSmallestIntThatFitsInDouble)).as_int() == kSmallestIntThatFitsInDouble); EXPECT_THROW( Value(static_cast<double>(kSmallestIntThatFitsInDouble) - 2.0).as_int(), shcore::Exception); // double -> uint64_t // min -> error // max -> error EXPECT_THROW(Value(std::numeric_limits<double>::lowest()).as_uint(), shcore::Exception); EXPECT_THROW(Value(std::numeric_limits<double>::max()).as_uint(), shcore::Exception); EXPECT_TRUE( Value(static_cast<double>(kBiggestUIntThatFitsInDouble)).as_uint() == kBiggestUIntThatFitsInDouble); EXPECT_THROW( Value(static_cast<double>(kBiggestUIntThatFitsInDouble) + 2.0).as_uint(), shcore::Exception); } TEST(ValueTests, SimpleString) { const std::string input("Hello world"); shcore::Value v(input); std::string mydescr = v.descr(true); std::string myrepr = v.repr(); std::string myjson = v.json(); EXPECT_EQ(shcore::String, v.type); EXPECT_STREQ("Hello world", mydescr.c_str()); EXPECT_STREQ("\"Hello world\"", myrepr.c_str()); EXPECT_STREQ("\"Hello world\"", myjson.c_str()); shcore::Value v2("Hello / world"); mydescr = v2.descr(true); myrepr = v2.repr(); myjson = v2.json(); EXPECT_EQ(shcore::String, v.type); EXPECT_STREQ("Hello / world", mydescr.c_str()); EXPECT_STREQ("\"Hello / world\"", myrepr.c_str()); EXPECT_STREQ("\"Hello / world\"", myjson.c_str()); // Test unicode literal EXPECT_STREQ(u8"\u0061", shcore::Value::parse("\"\\u0061\"").get_string().c_str()); EXPECT_STREQ(u8"\u0161", shcore::Value::parse("\"\\u0161\"").get_string().c_str()); EXPECT_STREQ(u8"\u0ab0", shcore::Value::parse("\"\\u0ab0\"").get_string().c_str()); EXPECT_STREQ(u8"\u100b0", shcore::Value::parse("\"\\u100b0\"").get_string().c_str()); } TEST(ValueTests, ArrayCompare) { Value arr1(Value::new_array()); Value arr2(Value::new_array()); arr1.as_array()->push_back(Value(12345)); arr2.as_array()->push_back(Value(12345)); EXPECT_TRUE(arr1 == arr2); } static Value do_test(const Argument_list &args) { args.ensure_count(1, 2, "do_test"); int code = args.int_at(0); switch (code) { case 0: // test string_at return Value(args.string_at(1)); } return Value::Null(); } TEST(ValueTests, to_string_container) { Value arr(Value::new_array()); arr.as_array()->push_back(Value("one")); arr.as_array()->push_back(Value("2")); arr.as_array()->push_back(Value("3.4")); std::vector<std::string> v = arr.to_string_container<std::vector<std::string>>(); EXPECT_EQ(3, v.size()); EXPECT_EQ("one", v[0]); EXPECT_EQ("2", v[1]); EXPECT_EQ("3.4", v[2]); std::list<std::string> l = arr.to_string_container<std::list<std::string>>(); auto li = l.begin(); EXPECT_EQ(3, l.size()); EXPECT_EQ("one", *li++); EXPECT_EQ("2", *li++); EXPECT_EQ("3.4", *li++); std::set<std::string> s = arr.to_string_container<std::set<std::string>>(); auto si = s.begin(); EXPECT_EQ(3, s.size()); EXPECT_EQ("2", *si++); EXPECT_EQ("3.4", *si++); EXPECT_EQ("one", *si++); arr.as_array()->push_back(Value(123)); EXPECT_THROW(arr.to_string_container<std::vector<std::string>>(), std::exception); } TEST(Functions, function_wrappers) { std::shared_ptr<Function_base> f(Cpp_function::create( "test", do_test, {{"test_index", Integer}, {"test_arg", String}})); { Argument_list args; args.push_back(Value(1234)); args.push_back(Value("hello")); args.push_back(Value(333)); EXPECT_THROW(f->invoke(args), Exception); } { Argument_list args; args.push_back(Value(0)); args.push_back(Value("hello")); EXPECT_EQ(f->invoke(args), Value("hello")); } } TEST(Parsing, Integer) { { const std::string data = "1984"; shcore::Value v = shcore::Value::parse(data); std::string mydescr = v.descr(true); std::string myrepr = v.repr(); EXPECT_EQ(shcore::Integer, v.type); EXPECT_STREQ("1984", mydescr.c_str()); EXPECT_STREQ("1984", myrepr.c_str()); } { const std::string data = "1984 \n"; shcore::Value v = shcore::Value::parse(data); std::string mydescr = v.descr(true); std::string myrepr = v.repr(); EXPECT_EQ(shcore::Integer, v.type); EXPECT_STREQ("1984", mydescr.c_str()); EXPECT_STREQ("1984", myrepr.c_str()); } } TEST(Parsing, Float) { const std::string data = "3.1"; shcore::Value v = shcore::Value::parse(data); std::string mydescr = v.descr(true); std::string myrepr = v.repr(); EXPECT_EQ(shcore::Float, v.type); double d = std::stod(myrepr); EXPECT_EQ(3.1, d); } TEST(Parsing, Bool) { shcore::Value v; const std::string data = "false"; const std::string data2 = "true"; v = shcore::Value::parse(data); std::string mydescr = v.descr(true); std::string myrepr = v.repr(); EXPECT_EQ(shcore::Bool, v.type); EXPECT_STREQ("false", mydescr.c_str()); EXPECT_STREQ("false", myrepr.c_str()); v = shcore::Value::parse(data2); mydescr = v.descr(true); myrepr = v.repr(); EXPECT_EQ(shcore::Bool, v.type); EXPECT_STREQ("true", mydescr.c_str()); EXPECT_STREQ("true", myrepr.c_str()); const std::string data3 = "FALSE "; const std::string data4 = "TRUE\t"; v = shcore::Value::parse(data3); mydescr = v.descr(true); myrepr = v.repr(); EXPECT_EQ(shcore::Bool, v.type); EXPECT_STREQ("false", mydescr.c_str()); EXPECT_STREQ("false", myrepr.c_str()); v = shcore::Value::parse(data4); mydescr = v.descr(true); myrepr = v.repr(); EXPECT_EQ(shcore::Bool, v.type); EXPECT_STREQ("true", mydescr.c_str()); EXPECT_STREQ("true", myrepr.c_str()); } TEST(Parsing, Null) { const std::string data = "undefined"; shcore::Value v = shcore::Value::parse(data); std::string mydescr = v.descr(true); std::string myrepr = v.repr(); EXPECT_EQ(shcore::Undefined, v.type); EXPECT_STREQ("undefined", mydescr.c_str()); EXPECT_STREQ("undefined", myrepr.c_str()); } TEST(Parsing, String) { const std::string data = "\"Hello World\""; shcore::Value v = shcore::Value::parse(data); std::string mydescr = v.descr(true); std::string myrepr = v.repr(); EXPECT_EQ(shcore::String, v.type); EXPECT_STREQ("Hello World", mydescr.c_str()); EXPECT_STREQ("\"Hello World\"", myrepr.c_str()); } TEST(Parsing, Bad) { EXPECT_THROW(shcore::Value::parse("bla"), shcore::Exception); EXPECT_THROW(shcore::Value::parse("123foo"), shcore::Exception); EXPECT_THROW(shcore::Value::parse("truefoo"), shcore::Exception); EXPECT_THROW(shcore::Value::parse("true123"), shcore::Exception); EXPECT_THROW(shcore::Value::parse("123true"), shcore::Exception); EXPECT_THROW(shcore::Value::parse("falsefoo"), shcore::Exception); EXPECT_THROW(shcore::Value::parse("blafoo"), shcore::Exception); EXPECT_THROW(shcore::Value::parse("nullfoo"), shcore::Exception); EXPECT_THROW(shcore::Value::parse("[true123]"), shcore::Exception); EXPECT_THROW(shcore::Value::parse("{'a':truefoo}"), shcore::Exception); EXPECT_THROW_LIKE(shcore::Value::parse("-"), shcore::Exception, "Error parsing number from: '-'"); EXPECT_THROW_LIKE(shcore::Value::parse("+"), shcore::Exception, "Error parsing number from: '+'"); EXPECT_THROW_LIKE(shcore::Value::parse("45."), shcore::Exception, "Error parsing number from: '45.'"); EXPECT_THROW_LIKE(shcore::Value::parse("45.3e"), shcore::Exception, "Error parsing number from: '45.3e'"); EXPECT_THROW_LIKE(shcore::Value::parse("45.3e+"), shcore::Exception, "Error parsing number from: '45.3e+'"); EXPECT_THROW_LIKE(shcore::Value::parse("45.3e-"), shcore::Exception, "Error parsing number from: '45.3e-'"); EXPECT_THROW_LIKE(shcore::Value::parse("45e"), shcore::Exception, "Error parsing number from: '45e'"); EXPECT_THROW_LIKE(shcore::Value::parse("45e-"), shcore::Exception, "Error parsing number from: '45e-'"); EXPECT_THROW_LIKE(shcore::Value::parse("45e+"), shcore::Exception, "Error parsing number from: '45e+'"); // Not bad EXPECT_NO_THROW(shcore::Value::parse("{'a':true \n}")); EXPECT_NO_THROW(shcore::Value::parse("{'a' : 1 } \t\n")); } TEST(Parsing, StringSingleQuoted) { const std::string data = "\'Hello World\'"; shcore::Value v = shcore::Value::parse(data); std::string mydescr = v.descr(true); std::string myrepr = v.repr(); EXPECT_EQ(shcore::String, v.type); EXPECT_STREQ("Hello World", mydescr.c_str()); EXPECT_STREQ("\"Hello World\"", myrepr.c_str()); } TEST(Parsing, Map) { const std::string data = "{\"null\" : null, \"false\" : false, \"true\" : true, \"string\" : " "\"string value\", \"integer\":560, \"nested\": {\"inner\": \"value\"}}"; shcore::Value v = shcore::Value::parse(data); EXPECT_EQ(shcore::Map, v.type); Value::Map_type_ref map = v.as_map(); EXPECT_TRUE(map->has_key("null")); EXPECT_EQ(shcore::Null, (*map)["null"].type); EXPECT_FALSE((*map)["null"]); EXPECT_TRUE(map->has_key("false")); EXPECT_EQ(shcore::Bool, (*map)["false"].type); EXPECT_FALSE((*map)["false"].as_bool()); EXPECT_TRUE(map->has_key("true")); EXPECT_EQ(shcore::Bool, (*map)["true"].type); EXPECT_TRUE((*map)["true"].as_bool()); EXPECT_TRUE(map->has_key("string")); EXPECT_EQ(shcore::String, (*map)["string"].type); EXPECT_EQ("string value", (*map)["string"].get_string()); EXPECT_TRUE(map->has_key("integer")); EXPECT_EQ(shcore::Integer, (*map)["integer"].type); EXPECT_EQ(560, (*map)["integer"].as_int()); EXPECT_TRUE(map->has_key("nested")); EXPECT_EQ(shcore::Map, (*map)["nested"].type); Value::Map_type_ref nested = (*map)["nested"].as_map(); EXPECT_TRUE(nested->has_key("inner")); EXPECT_EQ(shcore::String, (*nested)["inner"].type); EXPECT_EQ("value", (*nested)["inner"].get_string()); shcore::Value v2 = shcore::Value::parse("{}"); EXPECT_EQ(shcore::Map, v2.type); Value::Map_type_ref map2 = v2.as_map(); EXPECT_EQ(map2->size(), 0); // regression test shcore::Value v3 = shcore::Value::parse( "{'hello': {'item':1}, 'world': {}, 'foo': 'bar', 'bar':32}"); EXPECT_EQ(shcore::Map, v3.type); EXPECT_EQ(4, v3.as_map()->size()); v3 = shcore::Value::parse( "{'hello': {'item':1}, 'world': [], 'foo': 'bar', 'bar':32}"); EXPECT_EQ(shcore::Map, v3.type); EXPECT_EQ(4, v3.as_map()->size()); } TEST(Parsing, Array) { const std::string data = "[450, 450.3, +3.5e-10, \"a string\", [1,2,3], " "{\"nested\":\"document\"}, true, false, null, undefined]"; shcore::Value v = shcore::Value::parse(data); EXPECT_EQ(shcore::Array, v.type); Value::Array_type_ref array = v.as_array(); EXPECT_EQ(shcore::Integer, (*array)[0].type); EXPECT_EQ(450, (*array)[0].as_int()); EXPECT_EQ(shcore::Float, (*array)[1].type); EXPECT_EQ(450.3, (*array)[1].as_double()); EXPECT_EQ(shcore::Float, (*array)[2].type); EXPECT_EQ(3.5e-10, (*array)[2].as_double()); EXPECT_EQ(shcore::String, (*array)[3].type); EXPECT_EQ("a string", (*array)[3].get_string()); EXPECT_EQ(shcore::Array, (*array)[4].type); Value::Array_type_ref inner = (*array)[4].as_array(); EXPECT_EQ(shcore::Integer, (*inner)[0].type); EXPECT_EQ(1, (*inner)[0].as_int()); EXPECT_EQ(shcore::Integer, (*inner)[1].type); EXPECT_EQ(2, (*inner)[1].as_int()); EXPECT_EQ(shcore::Integer, (*inner)[2].type); EXPECT_EQ(3, (*inner)[2].as_int()); EXPECT_EQ(shcore::Map, (*array)[5].type); Value::Map_type_ref nested = (*array)[5].as_map(); EXPECT_TRUE(nested->has_key("nested")); EXPECT_EQ(shcore::String, (*nested)["nested"].type); EXPECT_EQ("document", (*nested)["nested"].get_string()); EXPECT_EQ(shcore::Bool, (*array)[6].type); EXPECT_TRUE((*array)[6].as_bool()); EXPECT_EQ(shcore::Bool, (*array)[7].type); EXPECT_FALSE((*array)[7].as_bool()); EXPECT_EQ(shcore::Null, (*array)[8].type); EXPECT_FALSE((*array)[8]); EXPECT_EQ(shcore::Undefined, (*array)[9].type); EXPECT_FALSE((*array)[9]); shcore::Value v2 = shcore::Value::parse("[]"); EXPECT_EQ(shcore::Array, v2.type); Value::Array_type_ref array2 = v2.as_array(); EXPECT_EQ(array2->size(), 0); } TEST(Parsing, newline_characters) { for (const auto file : {"{\r\n \"k\": [\r\n 1\r\n ]\r\n}", "{\n \"k\": [\n 1\n ]\n}", "{\r \"k\": [\r 1\r ]\r}"}) { SCOPED_TRACE("TESTING: " + std::string(file)); const auto v = shcore::Value::parse(file); EXPECT_EQ(shcore::Value_type::Map, v.type); const auto m = v.as_map(); EXPECT_EQ(1, m->size()); const auto k = m->find("k"); ASSERT_NE(m->end(), k); EXPECT_EQ(shcore::Value_type::Array, k->second.type); const auto a = k->second.as_array(); ASSERT_EQ(1, a->size()); EXPECT_EQ(shcore::Value_type::Integer, (*a)[0].type); EXPECT_EQ(1, (*a)[0].as_int()); } } TEST(Parsing, whitespace_characters) { std::string json = " { \"k\": [ 7 ] } "; for (const auto whitespace : {' ', '\t', '\r', '\n', '\v', '\f'}) { SCOPED_TRACE("TESTING: " + std::to_string(static_cast<int>(whitespace))); json[0] = json[2] = json[7] = json[9] = json[11] = json[13] = json[15] = whitespace; const auto v = shcore::Value::parse(json); EXPECT_EQ(shcore::Value_type::Map, v.type); const auto m = v.as_map(); EXPECT_EQ(1, m->size()); const auto k = m->find("k"); ASSERT_NE(m->end(), k); EXPECT_EQ(shcore::Value_type::Array, k->second.type); const auto a = k->second.as_array(); ASSERT_EQ(1, a->size()); EXPECT_EQ(shcore::Value_type::Integer, (*a)[0].type); EXPECT_EQ(7, (*a)[0].as_int()); } } TEST(Argument_map, all) { { Argument_map args; args["int"] = Value(-1234); args["bool"] = Value(true); args["uint"] = Value(4321); args["str"] = Value("string"); args["flt"] = Value(1.234); args["vec"] = Value::new_array(); args["map"] = Value::new_map(); ASSERT_NO_THROW(args.ensure_keys( {"int", "bool", "uint", "str", "flt", "vec"}, {"map"}, "test1")); ASSERT_THROW(args.ensure_keys({"int", "bool", "uint", "str", "flt"}, {"map"}, "test2"), Exception); ASSERT_THROW(args.ensure_keys({"int", "bool", "uint", "str", "flt", "bla"}, {"map"}, "test3"), Exception); ASSERT_NO_THROW(args.ensure_keys( {"int", "bool", "uint", "str", "flt", "vec"}, {"map", "bla"}, "test2")); EXPECT_EQ(args.bool_at("bool"), true); EXPECT_EQ(args.bool_at("int"), true); EXPECT_EQ(args.bool_at("uint"), true); EXPECT_THROW(args.bool_at("str"), Exception); EXPECT_EQ(args.bool_at("flt"), true); EXPECT_THROW(args.bool_at("vec"), Exception); EXPECT_THROW(args.bool_at("map"), Exception); EXPECT_EQ(args.int_at("bool"), 1); EXPECT_EQ(args.int_at("int"), -1234); EXPECT_EQ(args.int_at("uint"), 4321); EXPECT_THROW(args.int_at("str"), Exception); EXPECT_THROW(args.int_at("flt"), Exception); EXPECT_THROW(args.int_at("vec"), Exception); EXPECT_THROW(args.int_at("map"), Exception); EXPECT_EQ(args.uint_at("bool"), 1); EXPECT_THROW(args.uint_at("int"), Exception); EXPECT_EQ(args.uint_at("uint"), 4321); EXPECT_THROW(args.uint_at("str"), Exception); EXPECT_THROW(args.uint_at("flt"), Exception); EXPECT_THROW(args.uint_at("vec"), Exception); EXPECT_THROW(args.uint_at("map"), Exception); EXPECT_EQ(args.double_at("bool"), 1.0); EXPECT_EQ(args.double_at("int"), -1234.0); EXPECT_EQ(args.double_at("uint"), 4321.0); EXPECT_THROW(args.double_at("str"), Exception); EXPECT_EQ(args.double_at("flt"), 1.234); EXPECT_THROW(args.double_at("vec"), Exception); EXPECT_THROW(args.double_at("map"), Exception); EXPECT_THROW(args.string_at("bool"), Exception); EXPECT_THROW(args.string_at("int"), Exception); EXPECT_THROW(args.string_at("uint"), Exception); EXPECT_EQ(args.string_at("str"), "string"); EXPECT_THROW(args.string_at("flt"), Exception); EXPECT_THROW(args.uint_at("vec"), Exception); EXPECT_THROW(args.uint_at("map"), Exception); } // option alias, success alias 1 { shcore::Value::Map_type_ref options(new shcore::Value::Map_type()); (*options)["user"] = shcore::Value("sample"); (*options)["password"] = shcore::Value("sample"); Argument_map args(*options); ASSERT_NO_THROW( args.ensure_keys({"password|dbPassword"}, {"user"}, "test1")); } // option alias, success alias 2 { shcore::Value::Map_type_ref options(new shcore::Value::Map_type()); (*options)["user"] = shcore::Value("sample"); (*options)["dbPassword"] = shcore::Value("sample"); Argument_map args(*options); ASSERT_NO_THROW( args.ensure_keys({"password|dbPassword"}, {"user"}, "test1")); } // option alias, failure two aliases { shcore::Value::Map_type_ref options(new shcore::Value::Map_type()); (*options)["user"] = shcore::Value("sample"); (*options)["password"] = shcore::Value("sample"); (*options)["dbPassword"] = shcore::Value("sample"); Argument_map args(*options); ASSERT_THROW( args.ensure_keys({"password|dbPassword"}, {"user"}, "multiple aliases"), Exception); } // option alias, failure no aliases { shcore::Value::Map_type_ref options(new shcore::Value::Map_type()); (*options)["user"] = shcore::Value("sample"); Argument_map args(*options); ASSERT_THROW( args.ensure_keys({"password|dbPassword"}, {"user"}, "no aliases"), Exception); } } TEST(Types_descr, double_single_quote) { const char text[] = "There are two common quote characters: \" and ' and we \xe2\x9d\xa4" " Unicode. Backslash \\! \xc3\x98\x00 \x00 \x00." "\x00" "Text after null char with \" and '."; const Value s(text, sizeof(text) - 1); { std::string stdout_string; s.append_descr(stdout_string, -1, '\''); const char expect_text[] = "'There are two common quote characters: \" and \\' and we \xe2\x9d\xa4" " Unicode. Backslash \\\\! \xc3\x98\x00 \x00 \x00." "\x00" "Text after null char with \" and \\'.'"; EXPECT_EQ(stdout_string, std::string(expect_text, sizeof(expect_text) - 1)); } { std::string stdout_string; s.append_descr(stdout_string, -1, '"'); const char expect_text[] = "\"There are two common quote characters: \\\" and ' and we " "\xe2\x9d\xa4" " Unicode. Backslash \\\\! \xc3\x98\x00 \x00 \x00." "\x00" "Text after null char with \\\" and '.\""; EXPECT_EQ(stdout_string, std::string(expect_text, sizeof(expect_text) - 1)); } } TEST(Types_repr, encode_decode_simple) { const char text[] = "There are two common quote characters: \" and ' and we \xe2\x9d\xa4 " "Unicode. Backslash \\! \xc3\x98\x00 \x00 \x00." "\x00" "Text after null char with \" and '."; const Value s(text, sizeof(text) - 1); { const std::string serialized = s.repr(); const char expect_serialized[] = "\"There are two common quote characters: \\\" and \\' and we " "\\xe2\\x9d\\xa4 Unicode. Backslash \\\\! \\xc3\\x98\\x00 \\x00 \\x00." "\\x00" "Text after null char with \\\" and \\'.\""; EXPECT_EQ(serialized, expect_serialized); Value to_original = Value::parse(serialized); EXPECT_EQ(s, to_original); EXPECT_STREQ(text, to_original.get_string().c_str()); EXPECT_EQ(std::string(text, sizeof(text) - 1), to_original.get_string()); } } TEST(Types_repr, encode_decode_nontrivial) { { const char text[] = ""; const Value s(text, sizeof(text) - 1); const std::string serialized = s.repr(); const char expect_serialized[] = "\"\""; EXPECT_EQ(serialized, expect_serialized); Value to_original = Value::parse(serialized); EXPECT_EQ(s, to_original); EXPECT_STREQ(text, to_original.get_string().c_str()); EXPECT_EQ(std::string(text, sizeof(text) - 1), to_original.get_string()); } { const char text[] = "\""; const Value s(text, sizeof(text) - 1); const std::string serialized = s.repr(); const char expect_serialized[] = R"_("\"")_"; EXPECT_EQ(serialized, expect_serialized); Value to_original = Value::parse(serialized); EXPECT_EQ(s, to_original); EXPECT_STREQ(text, to_original.get_string().c_str()); EXPECT_EQ(std::string(text, sizeof(text) - 1), to_original.get_string()); } { const char text[] = "\\"; const Value s(text, sizeof(text) - 1); const std::string serialized = s.repr(); const char expect_serialized[] = R"_("\\")_"; EXPECT_EQ(serialized, expect_serialized); Value to_original = Value::parse(serialized); EXPECT_EQ(s, to_original); EXPECT_STREQ(text, to_original.get_string().c_str()); EXPECT_EQ(std::string(text, sizeof(text) - 1), to_original.get_string()); } } TEST(Types_repr, encode_decode_one_char) { for (int tc = 0; tc <= 0xff; tc++) { const char text[1] = {static_cast<char>(tc)}; const Value s(text, sizeof(text)); { const std::string serialized = s.repr(); Value to_original = Value::parse(serialized); EXPECT_EQ(s, to_original); EXPECT_EQ(std::string(text, sizeof(text)), to_original.get_string()); } } } TEST(Types_repr, encode_decode_random) { std::mt19937 gen(2017); std::uniform_int_distribution<> dist(0, 0xff); for (int tc = 0; tc < 1000; tc++) { char text[1 << 6]; std::generate_n(text, sizeof(text), [&dist, &gen]() { return dist(gen); }); const Value s(text, sizeof(text)); { const std::string serialized = s.repr(); Value to_original = Value::parse(serialized); EXPECT_EQ(s, to_original); EXPECT_EQ(std::string(text, sizeof(text)), to_original.get_string()); } } } /** * Check for proper backtracking for backslashes when compute length in parse * function. * * `text` const char array must be a string returned by `repr()` function. */ TEST(Types_repr, backslash_backtracking) { { const char text[] = {'"', 'p', 's', '\\', '"', 'W', '}', 'q', 't', '"', 0}; EXPECT_THROW_NOTHING(Value::parse(Value(text).get_string()).repr()); EXPECT_THROW_NOTHING(Value::parse(Value(text).repr())); } { const char text[] = {'"', 'p', 's', '\\', '\\', '\\', '"', 'W', '}', 'q', 't', '"', 0}; EXPECT_THROW_NOTHING(Value::parse(Value(text).get_string()).repr()); EXPECT_THROW_NOTHING(Value::parse(Value(text).repr())); } { const char text[] = {'"', 'p', 's', '\\', '\\', '\\', '\\', '\\', '"', 'W', '}', 'q', 't', '"', 0}; EXPECT_THROW_NOTHING(Value::parse(Value(text).get_string()).repr()); EXPECT_THROW_NOTHING(Value::parse(Value(text).repr())); } } TEST(Types_repr, wrong_repr) { { // good. char text[] = {'"', 'p', 's', '\\', '\\', '\\', '\\', '\\', '"', 'W', '}', 'q', 't', '\\', '"', '\\', '"', '\\', '"', '"', 0}; EXPECT_THROW_NOTHING(Value::parse(Value(text).get_string()).repr()); } { // non-escaped `"`. char text[] = {'"', 'p', 's', '\\', '\\', '\\', '\\', '\\', '"', 'W', '}', 'q', 't', '\\', '"', '\\', '"', '"', '"', 0}; EXPECT_THROW(Value::parse(Value(text).get_string()).repr(), shcore::Exception); } { // non-escaped `""`. char text[] = {'"', 'p', 's', '\\', '\\', '\\', '\\', '\\', '"', 'W', '}', 'q', 't', '\\', '"', '"', '"', '"', 0}; EXPECT_THROW(Value::parse(Value(text).get_string()).repr(), shcore::Exception); } { // non-escaped `"""`. char text[] = {'"', 'p', 's', '\\', '\\', '\\', '\\', '\\', '"', 'W', '}', 'q', 't', '"', '"', '"', '"', 0}; EXPECT_THROW(Value::parse(Value(text).get_string()).repr(), shcore::Exception); } } TEST(Types_yaml, array) { const auto array = make_array(); array->emplace_back(Value()); array->emplace_back(Value::Null()); array->emplace_back(Value::False()); array->emplace_back(Value::True()); array->emplace_back("simple string"); array->emplace_back(INT64_C(-1234)); array->emplace_back(UINT64_C(5678)); array->emplace_back(9.01112); const auto sub_array = make_array(); sub_array->emplace_back(1); sub_array->emplace_back(2); sub_array->emplace_back(3); array->emplace_back(std::move(sub_array)); const auto sub_map = make_dict(); sub_map->emplace("4", 7); sub_map->emplace("5", 8); sub_map->emplace("6", 9); array->emplace_back(std::move(sub_map)); static constexpr auto expected = R"(--- - - - false - true - simple string - -1234 - 5678 - 9.01112 - - 1 - 2 - 3 - 4: 7 5: 8 6: 9 )"; EXPECT_EQ(expected, Value{array}.yaml()); } TEST(Types_yaml, map) { const auto map = make_dict(); map->emplace("a", Value()); map->emplace("b", Value::Null()); map->emplace("c", Value::False()); map->emplace("d", Value::True()); map->emplace("e", "simple string"); map->emplace("f", INT64_C(-1234)); map->emplace("g", UINT64_C(5678)); map->emplace("h", 9.01112); const auto sub_array = make_array(); sub_array->emplace_back(1); sub_array->emplace_back(2); sub_array->emplace_back(3); map->emplace("i", std::move(sub_array)); const auto sub_map = make_dict(); sub_map->emplace("4", 7); sub_map->emplace("5", 8); sub_map->emplace("6", 9); map->emplace("j", std::move(sub_map)); static constexpr auto expected = R"(--- a: b: c: false d: true e: simple string f: -1234 g: 5678 h: 9.01112 i: - 1 - 2 - 3 j: 4: 7 5: 8 6: 9 )"; EXPECT_EQ(expected, Value{map}.yaml()); } TEST(Types_yaml, string) { const auto array = make_array(); array->emplace_back(""); array->emplace_back("simple string"); array->emplace_back(" leading space"); array->emplace_back("\tleading tab"); array->emplace_back("trailing space "); array->emplace_back("trailing tab\t"); array->emplace_back("- leading indicator"); array->emplace_back("? leading indicator"); array->emplace_back(": leading indicator"); array->emplace_back(", leading indicator"); array->emplace_back("[ leading indicator"); array->emplace_back("] leading indicator"); array->emplace_back("{ leading indicator"); array->emplace_back("} leading indicator"); array->emplace_back("# leading indicator"); array->emplace_back("& leading indicator"); array->emplace_back("* leading indicator"); array->emplace_back("! leading indicator"); array->emplace_back("| leading indicator"); array->emplace_back("> leading indicator"); array->emplace_back("' leading indicator"); array->emplace_back("\" leading indicator"); array->emplace_back("% leading indicator"); array->emplace_back("@ leading indicator"); array->emplace_back("` leading indicator"); array->emplace_back("the - indicator"); array->emplace_back("the ? indicator"); array->emplace_back("the : indicator"); array->emplace_back("the , indicator"); array->emplace_back("the [ indicator"); array->emplace_back("the ] indicator"); array->emplace_back("the { indicator"); array->emplace_back("the } indicator"); array->emplace_back("the # indicator"); array->emplace_back("the & indicator"); array->emplace_back("the * indicator"); array->emplace_back("the ! indicator"); array->emplace_back("the | indicator"); array->emplace_back("the > indicator"); array->emplace_back("the ' indicator"); array->emplace_back("the \" indicator"); array->emplace_back("the % indicator"); array->emplace_back("the @ indicator"); array->emplace_back("the ` indicator"); array->emplace_back("-_leading indicator without space"); array->emplace_back("?_leading indicator without space"); array->emplace_back(":_leading indicator without space"); array->emplace_back("the \": \" sequence must be quoted"); array->emplace_back("the \" #\" sequence must be quoted"); array->emplace_back("the ': ' -> single quotes must be escaped if quoted"); static constexpr auto expected = R"(--- - '' - simple string - ' leading space' - ' leading tab' - 'trailing space ' - 'trailing tab ' - '- leading indicator' - '? leading indicator' - ': leading indicator' - ', leading indicator' - '[ leading indicator' - '] leading indicator' - '{ leading indicator' - '} leading indicator' - '# leading indicator' - '& leading indicator' - '* leading indicator' - '! leading indicator' - '| leading indicator' - '> leading indicator' - ''' leading indicator' - '" leading indicator' - '% leading indicator' - '@ leading indicator' - '` leading indicator' - the - indicator - the ? indicator - 'the : indicator' - the , indicator - the [ indicator - the ] indicator - the { indicator - the } indicator - 'the # indicator' - the & indicator - the * indicator - the ! indicator - the | indicator - the > indicator - the ' indicator - the " indicator - the % indicator - the @ indicator - the ` indicator - -_leading indicator without space - ?_leading indicator without space - :_leading indicator without space - 'the ": " sequence must be quoted' - 'the " #" sequence must be quoted' - 'the '': '' -> single quotes must be escaped if quoted' )"; EXPECT_EQ(expected, Value{array}.yaml()); } TEST(Types_yaml, multiline_string) { const auto array = make_array(); array->emplace_back("\n"); array->emplace_back("\n\n\n"); array->emplace_back("simple string\nsecond line"); array->emplace_back("second line\nends with a newline\n"); array->emplace_back(" leading space\nsecond line"); array->emplace_back("\tleading tab\nsecond line"); array->emplace_back("trailing space \nsecond line"); array->emplace_back("trailing tab\t\nsecond line"); array->emplace_back("- leading indicator\nsecond line"); array->emplace_back("? leading indicator\nsecond line"); array->emplace_back(": leading indicator\nsecond line"); array->emplace_back(", leading indicator\nsecond line"); array->emplace_back("[ leading indicator\nsecond line"); array->emplace_back("] leading indicator\nsecond line"); array->emplace_back("{ leading indicator\nsecond line"); array->emplace_back("} leading indicator\nsecond line"); array->emplace_back("# leading indicator\nsecond line"); array->emplace_back("& leading indicator\nsecond line"); array->emplace_back("* leading indicator\nsecond line"); array->emplace_back("! leading indicator\nsecond line"); array->emplace_back("| leading indicator\nsecond line"); array->emplace_back("> leading indicator\nsecond line"); array->emplace_back("' leading indicator\nsecond line"); array->emplace_back("\" leading indicator\nsecond line"); array->emplace_back("% leading indicator\nsecond line"); array->emplace_back("@ leading indicator\nsecond line"); array->emplace_back("` leading indicator\nsecond line"); array->emplace_back("the - indicator\nsecond line"); array->emplace_back("the ? indicator\nsecond line"); array->emplace_back("the : indicator\nsecond line"); array->emplace_back("the , indicator\nsecond line"); array->emplace_back("the [ indicator\nsecond line"); array->emplace_back("the ] indicator\nsecond line"); array->emplace_back("the { indicator\nsecond line"); array->emplace_back("the } indicator\nsecond line"); array->emplace_back("the # indicator\nsecond line"); array->emplace_back("the & indicator\nsecond line"); array->emplace_back("the * indicator\nsecond line"); array->emplace_back("the ! indicator\nsecond line"); array->emplace_back("the | indicator\nsecond line"); array->emplace_back("the > indicator\nsecond line"); array->emplace_back("the ' indicator\nsecond line"); array->emplace_back("the \" indicator\nsecond line"); array->emplace_back("the % indicator\nsecond line"); array->emplace_back("the @ indicator\nsecond line"); array->emplace_back("the ` indicator\nsecond line"); array->emplace_back("-_leading indicator without space\nsecond line"); array->emplace_back("?_leading indicator without space\nsecond line"); array->emplace_back(":_leading indicator without space\nsecond line"); array->emplace_back("the \": \" sequence\nsecond line"); array->emplace_back("the \" #\" sequence\nsecond line"); static constexpr auto expected = R"(--- - |+ - |+ - |- simple string second line - | second line ends with a newline - |4- leading space second line - |4- leading tab second line - |- trailing space second line - |- trailing tab second line - |- - leading indicator second line - |- ? leading indicator second line - |- : leading indicator second line - |- , leading indicator second line - |- [ leading indicator second line - |- ] leading indicator second line - |- { leading indicator second line - |- } leading indicator second line - |- # leading indicator second line - |- & leading indicator second line - |- * leading indicator second line - |- ! leading indicator second line - |- | leading indicator second line - |- > leading indicator second line - |- ' leading indicator second line - |- " leading indicator second line - |- % leading indicator second line - |- @ leading indicator second line - |- ` leading indicator second line - |- the - indicator second line - |- the ? indicator second line - |- the : indicator second line - |- the , indicator second line - |- the [ indicator second line - |- the ] indicator second line - |- the { indicator second line - |- the } indicator second line - |- the # indicator second line - |- the & indicator second line - |- the * indicator second line - |- the ! indicator second line - |- the | indicator second line - |- the > indicator second line - |- the ' indicator second line - |- the " indicator second line - |- the % indicator second line - |- the @ indicator second line - |- the ` indicator second line - |- -_leading indicator without space second line - |- ?_leading indicator without space second line - |- :_leading indicator without space second line - |- the ": " sequence second line - |- the " #" sequence second line )"; EXPECT_EQ(expected, Value{array}.yaml()); } } // namespace tests } // namespace shcore
31.729378
80
0.632908
mysql
ab615e780f7777cf5c6c44d984acc61e5a9e108c
977
cxx
C++
1.4 Sortland/main.cxx
SemenMartynov/openedu-itmo-algorithms
93697a1ac4de2300a9140d8752de7851743c0426
[ "MIT" ]
null
null
null
1.4 Sortland/main.cxx
SemenMartynov/openedu-itmo-algorithms
93697a1ac4de2300a9140d8752de7851743c0426
[ "MIT" ]
null
null
null
1.4 Sortland/main.cxx
SemenMartynov/openedu-itmo-algorithms
93697a1ac4de2300a9140d8752de7851743c0426
[ "MIT" ]
null
null
null
#include <fstream> #include <iostream> #include <algorithm> #include <vector> struct citizen_t { long id; double account; }; int main(int argc, char **argv) { std::ifstream fin("input.txt"); std::ofstream fout("output.txt"); size_t citezens_c; fin >> citezens_c; std::vector<citizen_t> citezens(citezens_c); // read data for (size_t i = 0; i != citezens_c; ++i) { fin >> citezens[i].account; citezens[i].id = static_cast<long>(i) + 1; } // sort for (size_t i = 1; i < citezens_c; ++i) { for (size_t j = i; j > 0; --j) { if (citezens[j].account < citezens[j - 1].account) { std::swap(citezens[j], citezens[j - 1]); continue; } break; } } // show results fout << citezens[0].id << " " << citezens[citezens_c / 2].id << " " << citezens[citezens_c - 1].id << std::endl; return 0; }
20.787234
116
0.511771
SemenMartynov
ab6283662cdfbfa4d3e34bd586015f639bdc1b2c
17,722
cpp
C++
src/cmfd_solver.cpp
HunterBelanger/openmc
7f7977091df7552449cff6c3b96a1166e4b43e45
[ "MIT" ]
1
2020-12-18T16:09:59.000Z
2020-12-18T16:09:59.000Z
src/cmfd_solver.cpp
HunterBelanger/openmc
7f7977091df7552449cff6c3b96a1166e4b43e45
[ "MIT" ]
null
null
null
src/cmfd_solver.cpp
HunterBelanger/openmc
7f7977091df7552449cff6c3b96a1166e4b43e45
[ "MIT" ]
null
null
null
#include "openmc/cmfd_solver.h" #include <vector> #include <cmath> #ifdef _OPENMP #include <omp.h> #endif #include "xtensor/xtensor.hpp" #include "openmc/bank.h" #include "openmc/error.h" #include "openmc/constants.h" #include "openmc/capi.h" #include "openmc/mesh.h" #include "openmc/message_passing.h" #include "openmc/tallies/filter_energy.h" #include "openmc/tallies/filter_mesh.h" #include "openmc/tallies/tally.h" namespace openmc { namespace cmfd { //============================================================================== // Global variables //============================================================================== std::vector<int> indptr; std::vector<int> indices; int dim; double spectral; int nx, ny, nz, ng; xt::xtensor<int, 2> indexmap; int use_all_threads; StructuredMesh* mesh; std::vector<double> egrid; double norm; } // namespace cmfd //============================================================================== // GET_CMFD_ENERGY_BIN returns the energy bin for a source site energy //============================================================================== int get_cmfd_energy_bin(const double E) { // Check if energy is out of grid bounds if (E < cmfd::egrid[0]) { // throw warning message warning("Detected source point below energy grid"); return 0; } else if (E >= cmfd::egrid[cmfd::ng]) { // throw warning message warning("Detected source point above energy grid"); return cmfd::ng - 1; } else { // Iterate through energy grid to find matching bin for (int g = 0; g < cmfd::ng; g++) { if (E >= cmfd::egrid[g] && E < cmfd::egrid[g+1]) { return g; } } } // Return -1 by default return -1; } //============================================================================== // COUNT_BANK_SITES bins fission sites according to CMFD mesh and energy //============================================================================== xt::xtensor<double, 1> count_bank_sites(xt::xtensor<int, 1>& bins, bool* outside) { // Determine shape of array for counts std::size_t cnt_size = cmfd::nx * cmfd::ny * cmfd::nz * cmfd::ng; std::vector<std::size_t> cnt_shape = {cnt_size}; // Create array of zeros xt::xarray<double> cnt {cnt_shape, 0.0}; bool outside_ = false; auto bank_size = simulation::source_bank.size(); for (int i = 0; i < bank_size; i++) { const auto& site = simulation::source_bank[i]; // determine scoring bin for CMFD mesh int mesh_bin = cmfd::mesh->get_bin(site.r); // if outside mesh, skip particle if (mesh_bin < 0) { outside_ = true; continue; } // determine scoring bin for CMFD energy int energy_bin = get_cmfd_energy_bin(site.E); // add to appropriate bin cnt(mesh_bin*cmfd::ng+energy_bin) += site.wgt; // store bin index which is used again when updating weights bins[i] = mesh_bin*cmfd::ng+energy_bin; } // Create copy of count data. Since ownership will be acquired by xtensor, // std::allocator must be used to avoid Valgrind mismatched free() / delete // warnings. int total = cnt.size(); double* cnt_reduced = std::allocator<double>{}.allocate(total); #ifdef OPENMC_MPI // collect values from all processors MPI_Reduce(cnt.data(), cnt_reduced, total, MPI_DOUBLE, MPI_SUM, 0, mpi::intracomm); // Check if there were sites outside the mesh for any processor MPI_Reduce(&outside_, outside, 1, MPI_C_BOOL, MPI_LOR, 0, mpi::intracomm); #else std::copy(cnt.data(), cnt.data() + total, cnt_reduced); *outside = outside_; #endif // Adapt reduced values in array back into an xarray auto arr = xt::adapt(cnt_reduced, total, xt::acquire_ownership(), cnt_shape); xt::xarray<double> counts = arr; return counts; } //============================================================================== // OPENMC_CMFD_REWEIGHT performs reweighting of particles in source bank //============================================================================== extern "C" void openmc_cmfd_reweight(const bool feedback, const double* cmfd_src) { // Get size of source bank and cmfd_src auto bank_size = simulation::source_bank.size(); std::size_t src_size = cmfd::nx * cmfd::ny * cmfd::nz * cmfd::ng; // count bank sites for CMFD mesh, store bins in bank_bins for reweighting xt::xtensor<int, 1> bank_bins({bank_size}, 0); bool sites_outside; xt::xtensor<double, 1> sourcecounts = count_bank_sites(bank_bins, &sites_outside); // Compute CMFD weightfactors xt::xtensor<double, 1> weightfactors = xt::xtensor<double, 1>({src_size}, 1.); if (mpi::master) { if (sites_outside) { fatal_error("Source sites outside of the CMFD mesh"); } double norm = xt::sum(sourcecounts)()/cmfd::norm; for (int i = 0; i < src_size; i++) { if (sourcecounts[i] > 0 && cmfd_src[i] > 0) { weightfactors[i] = cmfd_src[i] * norm / sourcecounts[i]; } } } if (!feedback) return; #ifdef OPENMC_MPI // Send weightfactors to all processors MPI_Bcast(weightfactors.data(), src_size, MPI_DOUBLE, 0, mpi::intracomm); #endif // Iterate through fission bank and update particle weights for (int64_t i = 0; i < bank_size; i++) { auto& site = simulation::source_bank[i]; site.wgt *= weightfactors(bank_bins(i)); } } //============================================================================== // OPENMC_INITIALIZE_MESH_EGRID sets the mesh and energy grid for CMFD reweight //============================================================================== extern "C" void openmc_initialize_mesh_egrid(const int meshtally_id, const int* cmfd_indices, const double norm) { // Make sure all CMFD memory is freed free_memory_cmfd(); // Set CMFD indices cmfd::nx = cmfd_indices[0]; cmfd::ny = cmfd_indices[1]; cmfd::nz = cmfd_indices[2]; cmfd::ng = cmfd_indices[3]; // Set CMFD reweight properties cmfd::norm = norm; // Find index corresponding to tally id int32_t tally_index; openmc_get_tally_index(meshtally_id, &tally_index); // Get filters assocaited with tally const auto& tally_filters = model::tallies[tally_index]->filters(); // Get mesh filter index auto meshfilter_index = tally_filters[0]; // Store energy filter index if defined, otherwise set to -1 auto energy_index = (tally_filters.size() == 2) ? tally_filters[1] : -1; // Get mesh index from mesh filter index int32_t mesh_index; openmc_mesh_filter_get_mesh(meshfilter_index, &mesh_index); // Get mesh from mesh index cmfd::mesh = dynamic_cast<StructuredMesh*>(model::meshes[mesh_index].get()); // Get energy bins from energy index, otherwise use default if (energy_index != -1) { auto efilt_base = model::tally_filters[energy_index].get(); auto* efilt = dynamic_cast<EnergyFilter*>(efilt_base); cmfd::egrid = efilt->bins(); } else { cmfd::egrid = {0.0, INFTY}; } } //============================================================================== // MATRIX_TO_INDICES converts a matrix index to spatial and group // indices //============================================================================== void matrix_to_indices(int irow, int& g, int& i, int& j, int& k) { g = irow % cmfd::ng; i = cmfd::indexmap(irow/cmfd::ng, 0); j = cmfd::indexmap(irow/cmfd::ng, 1); k = cmfd::indexmap(irow/cmfd::ng, 2); } //============================================================================== // GET_DIAGONAL_INDEX returns the index in CSR index array corresponding to // the diagonal element of a specified row //============================================================================== int get_diagonal_index(int row) { for (int j = cmfd::indptr[row]; j < cmfd::indptr[row+1]; j++) { if (cmfd::indices[j] == row) return j; } // Return -1 if not found return -1; } //============================================================================== // SET_INDEXMAP sets the elements of indexmap based on input coremap //============================================================================== void set_indexmap(const int* coremap) { for (int z = 0; z < cmfd::nz; z++) { for (int y = 0; y < cmfd::ny; y++) { for (int x = 0; x < cmfd::nx; x++) { int idx = (z*cmfd::ny*cmfd::nx) + (y*cmfd::nx) + x; if (coremap[idx] != CMFD_NOACCEL) { int counter = coremap[idx]; cmfd::indexmap(counter, 0) = x; cmfd::indexmap(counter, 1) = y; cmfd::indexmap(counter, 2) = z; } } } } } //============================================================================== // CMFD_LINSOLVER_1G solves a one group CMFD linear system //============================================================================== int cmfd_linsolver_1g(const double* A_data, const double* b, double* x, double tol) { // Set overrelaxation parameter double w = 1.0; // Perform Gauss-Seidel iterations for (int igs = 1; igs <= 10000; igs++) { double err = 0.0; // Copy over x vector std::vector<double> tmpx {x, x+cmfd::dim}; // Perform red/black Gauss-Seidel iterations for (int irb = 0; irb < 2; irb++) { // Loop around matrix rows #pragma omp parallel for reduction (+:err) if(cmfd::use_all_threads) for (int irow = 0; irow < cmfd::dim; irow++) { int g, i, j, k; matrix_to_indices(irow, g, i, j, k); // Filter out black cells if ((i+j+k) % 2 != irb) continue; // Get index of diagonal for current row int didx = get_diagonal_index(irow); // Perform temporary sums, first do left of diag, then right of diag double tmp1 = 0.0; for (int icol = cmfd::indptr[irow]; icol < didx; icol++) tmp1 += A_data[icol] * x[cmfd::indices[icol]]; for (int icol = didx + 1; icol < cmfd::indptr[irow + 1]; icol++) tmp1 += A_data[icol] * x[cmfd::indices[icol]]; // Solve for new x double x1 = (b[irow] - tmp1) / A_data[didx]; // Perform overrelaxation x[irow] = (1.0 - w) * x[irow] + w * x1; // Compute residual and update error double res = (tmpx[irow] - x[irow]) / tmpx[irow]; err += res * res; } } // Check convergence err = std::sqrt(err / cmfd::dim); if (err < tol) return igs; // Calculate new overrelaxation parameter w = 1.0/(1.0 - 0.25 * cmfd::spectral * w); } // Throw error, as max iterations met fatal_error("Maximum Gauss-Seidel iterations encountered."); // Return -1 by default, although error thrown before reaching this point return -1; } //============================================================================== // CMFD_LINSOLVER_2G solves a two group CMFD linear system //============================================================================== int cmfd_linsolver_2g(const double* A_data, const double* b, double* x, double tol) { // Set overrelaxation parameter double w = 1.0; // Perform Gauss-Seidel iterations for (int igs = 1; igs <= 10000; igs++) { double err = 0.0; // Copy over x vector std::vector<double> tmpx {x, x+cmfd::dim}; // Perform red/black Gauss-Seidel iterations for (int irb = 0; irb < 2; irb++) { // Loop around matrix rows #pragma omp parallel for reduction (+:err) if(cmfd::use_all_threads) for (int irow = 0; irow < cmfd::dim; irow+=2) { int g, i, j, k; matrix_to_indices(irow, g, i, j, k); // Filter out black cells if ((i+j+k) % 2 != irb) continue; // Get index of diagonals for current row and next row int d1idx = get_diagonal_index(irow); int d2idx = get_diagonal_index(irow+1); // Get block diagonal double m11 = A_data[d1idx]; // group 1 diagonal double m12 = A_data[d1idx + 1]; // group 1 right of diagonal (sorted by col) double m21 = A_data[d2idx - 1]; // group 2 left of diagonal (sorted by col) double m22 = A_data[d2idx]; // group 2 diagonal // Analytically invert the diagonal double dm = m11*m22 - m12*m21; double d11 = m22/dm; double d12 = -m12/dm; double d21 = -m21/dm; double d22 = m11/dm; // Perform temporary sums, first do left of diag, then right of diag double tmp1 = 0.0; double tmp2 = 0.0; for (int icol = cmfd::indptr[irow]; icol < d1idx; icol++) tmp1 += A_data[icol] * x[cmfd::indices[icol]]; for (int icol = cmfd::indptr[irow+1]; icol < d2idx-1; icol++) tmp2 += A_data[icol] * x[cmfd::indices[icol]]; for (int icol = d1idx + 2; icol < cmfd::indptr[irow + 1]; icol++) tmp1 += A_data[icol] * x[cmfd::indices[icol]]; for (int icol = d2idx + 1; icol < cmfd::indptr[irow + 2]; icol++) tmp2 += A_data[icol] * x[cmfd::indices[icol]]; // Adjust with RHS vector tmp1 = b[irow] - tmp1; tmp2 = b[irow + 1] - tmp2; // Solve for new x double x1 = d11*tmp1 + d12*tmp2; double x2 = d21*tmp1 + d22*tmp2; // Perform overrelaxation x[irow] = (1.0 - w) * x[irow] + w * x1; x[irow + 1] = (1.0 - w) * x[irow + 1] + w * x2; // Compute residual and update error double res = (tmpx[irow] - x[irow]) / tmpx[irow]; err += res * res; } } // Check convergence err = std::sqrt(err / cmfd::dim); if (err < tol) return igs; // Calculate new overrelaxation parameter w = 1.0/(1.0 - 0.25 * cmfd::spectral * w); } // Throw error, as max iterations met fatal_error("Maximum Gauss-Seidel iterations encountered."); // Return -1 by default, although error thrown before reaching this point return -1; } //============================================================================== // CMFD_LINSOLVER_NG solves a general CMFD linear system //============================================================================== int cmfd_linsolver_ng(const double* A_data, const double* b, double* x, double tol) { // Set overrelaxation parameter double w = 1.0; // Perform Gauss-Seidel iterations for (int igs = 1; igs <= 10000; igs++) { double err = 0.0; // Copy over x vector std::vector<double> tmpx {x, x+cmfd::dim}; // Loop around matrix rows for (int irow = 0; irow < cmfd::dim; irow++) { // Get index of diagonal for current row int didx = get_diagonal_index(irow); // Perform temporary sums, first do left of diag, then right of diag double tmp1 = 0.0; for (int icol = cmfd::indptr[irow]; icol < didx; icol++) tmp1 += A_data[icol] * x[cmfd::indices[icol]]; for (int icol = didx + 1; icol < cmfd::indptr[irow + 1]; icol++) tmp1 += A_data[icol] * x[cmfd::indices[icol]]; // Solve for new x double x1 = (b[irow] - tmp1) / A_data[didx]; // Perform overrelaxation x[irow] = (1.0 - w) * x[irow] + w * x1; // Compute residual and update error double res = (tmpx[irow] - x[irow]) / tmpx[irow]; err += res * res; } // Check convergence err = std::sqrt(err / cmfd::dim); if (err < tol) return igs; // Calculate new overrelaxation parameter w = 1.0/(1.0 - 0.25 * cmfd::spectral * w); } // Throw error, as max iterations met fatal_error("Maximum Gauss-Seidel iterations encountered."); // Return -1 by default, although error thrown before reaching this point return -1; } //============================================================================== // OPENMC_INITIALIZE_LINSOLVER sets the fixed variables that are used for the // linear solver //============================================================================== extern "C" void openmc_initialize_linsolver(const int* indptr, int len_indptr, const int* indices, int n_elements, int dim, double spectral, const int* map, bool use_all_threads) { // Store elements of indptr for (int i = 0; i < len_indptr; i++) cmfd::indptr.push_back(indptr[i]); // Store elements of indices for (int i = 0; i < n_elements; i++) cmfd::indices.push_back(indices[i]); // Set dimenion of CMFD problem and specral radius cmfd::dim = dim; cmfd::spectral = spectral; // Set indexmap if 1 or 2 group problem if (cmfd::ng == 1 || cmfd::ng == 2) { // Resize indexmap and set its elements cmfd::indexmap.resize({static_cast<size_t>(dim), 3}); set_indexmap(map); } // Use all threads allocated to OpenMC simulation to run CMFD solver cmfd::use_all_threads = use_all_threads; } //============================================================================== // OPENMC_RUN_LINSOLVER runs a Gauss Seidel linear solver to solve CMFD matrix // equations //============================================================================== extern "C" int openmc_run_linsolver(const double* A_data, const double* b, double* x, double tol) { switch (cmfd::ng) { case 1: return cmfd_linsolver_1g(A_data, b, x, tol); case 2: return cmfd_linsolver_2g(A_data, b, x, tol); default: return cmfd_linsolver_ng(A_data, b, x, tol); } } void free_memory_cmfd() { // Clear std::vectors cmfd::indptr.clear(); cmfd::indices.clear(); cmfd::egrid.clear(); // Resize xtensors to be empty cmfd::indexmap.resize({0}); // Set pointers to null cmfd::mesh = nullptr; } } // namespace openmc
31.091228
84
0.548584
HunterBelanger
ab65b3ca0855c8ca49a902ffc13aa16d498fabbc
252,842
cc
C++
plugins/community/repos/Southpole-parasites/parasites/warps/resources.cc
guillaume-plantevin/VeeSeeVSTRack
76fafc8e721613669d6f5ae82a0f58ce923a91e1
[ "Zlib", "BSD-3-Clause" ]
233
2018-07-02T16:49:36.000Z
2022-02-27T21:45:39.000Z
plugins/community/repos/Southpole-parasites/parasites/warps/resources.cc
guillaume-plantevin/VeeSeeVSTRack
76fafc8e721613669d6f5ae82a0f58ce923a91e1
[ "Zlib", "BSD-3-Clause" ]
24
2018-07-09T11:32:15.000Z
2022-01-07T01:45:43.000Z
plugins/community/repos/Southpole-parasites/parasites/warps/resources.cc
guillaume-plantevin/VeeSeeVSTRack
76fafc8e721613669d6f5ae82a0f58ce923a91e1
[ "Zlib", "BSD-3-Clause" ]
24
2018-07-14T21:55:30.000Z
2021-05-04T04:20:34.000Z
// Copyright 2014 Olivier Gillet. // // Author: Olivier Gillet (ol.gillet@gmail.com) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // // See http://creativecommons.org/licenses/MIT/ for more information. // // ----------------------------------------------------------------------------- // // Resources definitions. // // Automatically generated with: // make -f warps/makefile resources #include "warps/resources.h" namespace warps { const float fb__87_8000[] = { 1.200000000e+01, 2.630000000e+02, 1.000000000e+00, -2.572000482e-02, 4.487788340e-02, -2.572000482e-02, 4.487788340e-02, }; const float fb_110_8000[] = { 1.200000000e+01, 3.060000000e+02, 2.500000000e-01, -7.931045024e-02, 1.290681251e-02, -9.339148150e-02, 1.518494012e-02, }; const float fb_139_8000[] = { 1.200000000e+01, 2.430000000e+02, 2.500000000e-01, -9.982608285e-02, 1.623625964e-02, -1.175253889e-01, 1.909187455e-02, }; const float fb_175_8000[] = { 1.200000000e+01, 1.920000000e+02, 2.500000000e-01, -1.256102632e-01, 2.041717073e-02, -1.478403116e-01, 2.399019825e-02, }; const float fb_220_8000[] = { 1.200000000e+01, 1.530000000e+02, 2.500000000e-01, -1.579890264e-01, 2.566359509e-02, -1.858796047e-01, 3.012281471e-02, }; const float fb_277_8000[] = { 1.200000000e+01, 1.210000000e+02, 2.500000000e-01, -1.986017761e-01, 3.224184764e-02, -2.335415850e-01, 3.778648442e-02, }; const float fb_349_8000[] = { 1.200000000e+01, 9.600000000e+01, 2.500000000e-01, -2.494585699e-01, 4.048298668e-02, -2.931359041e-01, 4.733980069e-02, }; const float fb_440_8000[] = { 1.200000000e+01, 7.600000000e+01, 2.500000000e-01, -3.129923847e-01, 5.079873862e-02, -3.674252077e-01, 5.920914546e-02, }; const float fb_554_8000[] = { 1.200000000e+01, 6.000000000e+01, 2.500000000e-01, -3.920877866e-01, 6.370275117e-02, -4.596234805e-01, 7.388912125e-02, }; const float fb_698_8000[] = { 1.200000000e+01, 4.800000000e+01, 2.500000000e-01, -4.900471292e-01, 7.984109811e-02, -5.732942351e-01, 9.193058505e-02, }; const float fb_880_8000[] = { 1.200000000e+01, 3.800000000e+01, 2.500000000e-01, -6.104158833e-01, 1.000408086e-01, -7.120398134e-01, 1.139025399e-01, }; const float fb_1109_8000[] = { 1.200000000e+01, 3.000000000e+01, 2.500000000e-01, -7.565125704e-01, 1.253975556e-01, -8.787817044e-01, 1.402986139e-01, }; const float fb_1397_8000[] = { 1.200000000e+01, 2.400000000e+01, 2.500000000e-01, -9.303628940e-01, 1.574589048e-01, -1.074283292e+00, 1.713175349e-01, }; const float fb_1760_32000[] = { 3.000000000e+00, 7.600000000e+01, 2.500000000e-01, -3.129923847e-01, 5.079873862e-02, -3.674252077e-01, 5.920914546e-02, }; const float fb_2217_32000[] = { 3.000000000e+00, 6.000000000e+01, 2.500000000e-01, -3.920877866e-01, 6.370275117e-02, -4.596234805e-01, 7.388912125e-02, }; const float fb_2794_32000[] = { 3.000000000e+00, 4.800000000e+01, 2.500000000e-01, -4.900471292e-01, 7.984109811e-02, -5.732942351e-01, 9.193058505e-02, }; const float fb_3520_32000[] = { 3.000000000e+00, 3.800000000e+01, 2.500000000e-01, -6.104158833e-01, 1.000408086e-01, -7.120398134e-01, 1.139025399e-01, }; const float fb_4435_32000[] = { 3.000000000e+00, 3.000000000e+01, 2.500000000e-01, -7.565125704e-01, 1.253975556e-01, -8.787817044e-01, 1.402986139e-01, }; const float fb_5588_32000[] = { 3.000000000e+00, 2.400000000e+01, 2.500000000e-01, -9.303628940e-01, 1.574589048e-01, -1.074283292e+00, 1.713175349e-01, }; const float fb_7040_96000[] = { 1.000000000e+00, 5.000000000e+00, 3.080000000e+00, -3.104663984e-01, 6.551315014e-01, -3.104663984e-01, 6.551315014e-01, }; const float* filter_bank_table[] = { fb__87_8000, fb_110_8000, fb_139_8000, fb_175_8000, fb_220_8000, fb_277_8000, fb_349_8000, fb_440_8000, fb_554_8000, fb_698_8000, fb_880_8000, fb_1109_8000, fb_1397_8000, fb_1760_32000, fb_2217_32000, fb_2794_32000, fb_3520_32000, fb_4435_32000, fb_5588_32000, fb_7040_96000, }; const float lut_sin[] = { 0.000000000e+00, 6.135884649e-03, 1.227153829e-02, 1.840672991e-02, 2.454122852e-02, 3.067480318e-02, 3.680722294e-02, 4.293825693e-02, 4.906767433e-02, 5.519524435e-02, 6.132073630e-02, 6.744391956e-02, 7.356456360e-02, 7.968243797e-02, 8.579731234e-02, 9.190895650e-02, 9.801714033e-02, 1.041216339e-01, 1.102222073e-01, 1.163186309e-01, 1.224106752e-01, 1.284981108e-01, 1.345807085e-01, 1.406582393e-01, 1.467304745e-01, 1.527971853e-01, 1.588581433e-01, 1.649131205e-01, 1.709618888e-01, 1.770042204e-01, 1.830398880e-01, 1.890686641e-01, 1.950903220e-01, 2.011046348e-01, 2.071113762e-01, 2.131103199e-01, 2.191012402e-01, 2.250839114e-01, 2.310581083e-01, 2.370236060e-01, 2.429801799e-01, 2.489276057e-01, 2.548656596e-01, 2.607941179e-01, 2.667127575e-01, 2.726213554e-01, 2.785196894e-01, 2.844075372e-01, 2.902846773e-01, 2.961508882e-01, 3.020059493e-01, 3.078496400e-01, 3.136817404e-01, 3.195020308e-01, 3.253102922e-01, 3.311063058e-01, 3.368898534e-01, 3.426607173e-01, 3.484186802e-01, 3.541635254e-01, 3.598950365e-01, 3.656129978e-01, 3.713171940e-01, 3.770074102e-01, 3.826834324e-01, 3.883450467e-01, 3.939920401e-01, 3.996241998e-01, 4.052413140e-01, 4.108431711e-01, 4.164295601e-01, 4.220002708e-01, 4.275550934e-01, 4.330938189e-01, 4.386162385e-01, 4.441221446e-01, 4.496113297e-01, 4.550835871e-01, 4.605387110e-01, 4.659764958e-01, 4.713967368e-01, 4.767992301e-01, 4.821837721e-01, 4.875501601e-01, 4.928981922e-01, 4.982276670e-01, 5.035383837e-01, 5.088301425e-01, 5.141027442e-01, 5.193559902e-01, 5.245896827e-01, 5.298036247e-01, 5.349976199e-01, 5.401714727e-01, 5.453249884e-01, 5.504579729e-01, 5.555702330e-01, 5.606615762e-01, 5.657318108e-01, 5.707807459e-01, 5.758081914e-01, 5.808139581e-01, 5.857978575e-01, 5.907597019e-01, 5.956993045e-01, 6.006164794e-01, 6.055110414e-01, 6.103828063e-01, 6.152315906e-01, 6.200572118e-01, 6.248594881e-01, 6.296382389e-01, 6.343932842e-01, 6.391244449e-01, 6.438315429e-01, 6.485144010e-01, 6.531728430e-01, 6.578066933e-01, 6.624157776e-01, 6.669999223e-01, 6.715589548e-01, 6.760927036e-01, 6.806009978e-01, 6.850836678e-01, 6.895405447e-01, 6.939714609e-01, 6.983762494e-01, 7.027547445e-01, 7.071067812e-01, 7.114321957e-01, 7.157308253e-01, 7.200025080e-01, 7.242470830e-01, 7.284643904e-01, 7.326542717e-01, 7.368165689e-01, 7.409511254e-01, 7.450577854e-01, 7.491363945e-01, 7.531867990e-01, 7.572088465e-01, 7.612023855e-01, 7.651672656e-01, 7.691033376e-01, 7.730104534e-01, 7.768884657e-01, 7.807372286e-01, 7.845565972e-01, 7.883464276e-01, 7.921065773e-01, 7.958369046e-01, 7.995372691e-01, 8.032075315e-01, 8.068475535e-01, 8.104571983e-01, 8.140363297e-01, 8.175848132e-01, 8.211025150e-01, 8.245893028e-01, 8.280450453e-01, 8.314696123e-01, 8.348628750e-01, 8.382247056e-01, 8.415549774e-01, 8.448535652e-01, 8.481203448e-01, 8.513551931e-01, 8.545579884e-01, 8.577286100e-01, 8.608669386e-01, 8.639728561e-01, 8.670462455e-01, 8.700869911e-01, 8.730949784e-01, 8.760700942e-01, 8.790122264e-01, 8.819212643e-01, 8.847970984e-01, 8.876396204e-01, 8.904487232e-01, 8.932243012e-01, 8.959662498e-01, 8.986744657e-01, 9.013488470e-01, 9.039892931e-01, 9.065957045e-01, 9.091679831e-01, 9.117060320e-01, 9.142097557e-01, 9.166790599e-01, 9.191138517e-01, 9.215140393e-01, 9.238795325e-01, 9.262102421e-01, 9.285060805e-01, 9.307669611e-01, 9.329927988e-01, 9.351835099e-01, 9.373390119e-01, 9.394592236e-01, 9.415440652e-01, 9.435934582e-01, 9.456073254e-01, 9.475855910e-01, 9.495281806e-01, 9.514350210e-01, 9.533060404e-01, 9.551411683e-01, 9.569403357e-01, 9.587034749e-01, 9.604305194e-01, 9.621214043e-01, 9.637760658e-01, 9.653944417e-01, 9.669764710e-01, 9.685220943e-01, 9.700312532e-01, 9.715038910e-01, 9.729399522e-01, 9.743393828e-01, 9.757021300e-01, 9.770281427e-01, 9.783173707e-01, 9.795697657e-01, 9.807852804e-01, 9.819638691e-01, 9.831054874e-01, 9.842100924e-01, 9.852776424e-01, 9.863080972e-01, 9.873014182e-01, 9.882575677e-01, 9.891765100e-01, 9.900582103e-01, 9.909026354e-01, 9.917097537e-01, 9.924795346e-01, 9.932119492e-01, 9.939069700e-01, 9.945645707e-01, 9.951847267e-01, 9.957674145e-01, 9.963126122e-01, 9.968202993e-01, 9.972904567e-01, 9.977230666e-01, 9.981181129e-01, 9.984755806e-01, 9.987954562e-01, 9.990777278e-01, 9.993223846e-01, 9.995294175e-01, 9.996988187e-01, 9.998305818e-01, 9.999247018e-01, 9.999811753e-01, 1.000000000e+00, 9.999811753e-01, 9.999247018e-01, 9.998305818e-01, 9.996988187e-01, 9.995294175e-01, 9.993223846e-01, 9.990777278e-01, 9.987954562e-01, 9.984755806e-01, 9.981181129e-01, 9.977230666e-01, 9.972904567e-01, 9.968202993e-01, 9.963126122e-01, 9.957674145e-01, 9.951847267e-01, 9.945645707e-01, 9.939069700e-01, 9.932119492e-01, 9.924795346e-01, 9.917097537e-01, 9.909026354e-01, 9.900582103e-01, 9.891765100e-01, 9.882575677e-01, 9.873014182e-01, 9.863080972e-01, 9.852776424e-01, 9.842100924e-01, 9.831054874e-01, 9.819638691e-01, 9.807852804e-01, 9.795697657e-01, 9.783173707e-01, 9.770281427e-01, 9.757021300e-01, 9.743393828e-01, 9.729399522e-01, 9.715038910e-01, 9.700312532e-01, 9.685220943e-01, 9.669764710e-01, 9.653944417e-01, 9.637760658e-01, 9.621214043e-01, 9.604305194e-01, 9.587034749e-01, 9.569403357e-01, 9.551411683e-01, 9.533060404e-01, 9.514350210e-01, 9.495281806e-01, 9.475855910e-01, 9.456073254e-01, 9.435934582e-01, 9.415440652e-01, 9.394592236e-01, 9.373390119e-01, 9.351835099e-01, 9.329927988e-01, 9.307669611e-01, 9.285060805e-01, 9.262102421e-01, 9.238795325e-01, 9.215140393e-01, 9.191138517e-01, 9.166790599e-01, 9.142097557e-01, 9.117060320e-01, 9.091679831e-01, 9.065957045e-01, 9.039892931e-01, 9.013488470e-01, 8.986744657e-01, 8.959662498e-01, 8.932243012e-01, 8.904487232e-01, 8.876396204e-01, 8.847970984e-01, 8.819212643e-01, 8.790122264e-01, 8.760700942e-01, 8.730949784e-01, 8.700869911e-01, 8.670462455e-01, 8.639728561e-01, 8.608669386e-01, 8.577286100e-01, 8.545579884e-01, 8.513551931e-01, 8.481203448e-01, 8.448535652e-01, 8.415549774e-01, 8.382247056e-01, 8.348628750e-01, 8.314696123e-01, 8.280450453e-01, 8.245893028e-01, 8.211025150e-01, 8.175848132e-01, 8.140363297e-01, 8.104571983e-01, 8.068475535e-01, 8.032075315e-01, 7.995372691e-01, 7.958369046e-01, 7.921065773e-01, 7.883464276e-01, 7.845565972e-01, 7.807372286e-01, 7.768884657e-01, 7.730104534e-01, 7.691033376e-01, 7.651672656e-01, 7.612023855e-01, 7.572088465e-01, 7.531867990e-01, 7.491363945e-01, 7.450577854e-01, 7.409511254e-01, 7.368165689e-01, 7.326542717e-01, 7.284643904e-01, 7.242470830e-01, 7.200025080e-01, 7.157308253e-01, 7.114321957e-01, 7.071067812e-01, 7.027547445e-01, 6.983762494e-01, 6.939714609e-01, 6.895405447e-01, 6.850836678e-01, 6.806009978e-01, 6.760927036e-01, 6.715589548e-01, 6.669999223e-01, 6.624157776e-01, 6.578066933e-01, 6.531728430e-01, 6.485144010e-01, 6.438315429e-01, 6.391244449e-01, 6.343932842e-01, 6.296382389e-01, 6.248594881e-01, 6.200572118e-01, 6.152315906e-01, 6.103828063e-01, 6.055110414e-01, 6.006164794e-01, 5.956993045e-01, 5.907597019e-01, 5.857978575e-01, 5.808139581e-01, 5.758081914e-01, 5.707807459e-01, 5.657318108e-01, 5.606615762e-01, 5.555702330e-01, 5.504579729e-01, 5.453249884e-01, 5.401714727e-01, 5.349976199e-01, 5.298036247e-01, 5.245896827e-01, 5.193559902e-01, 5.141027442e-01, 5.088301425e-01, 5.035383837e-01, 4.982276670e-01, 4.928981922e-01, 4.875501601e-01, 4.821837721e-01, 4.767992301e-01, 4.713967368e-01, 4.659764958e-01, 4.605387110e-01, 4.550835871e-01, 4.496113297e-01, 4.441221446e-01, 4.386162385e-01, 4.330938189e-01, 4.275550934e-01, 4.220002708e-01, 4.164295601e-01, 4.108431711e-01, 4.052413140e-01, 3.996241998e-01, 3.939920401e-01, 3.883450467e-01, 3.826834324e-01, 3.770074102e-01, 3.713171940e-01, 3.656129978e-01, 3.598950365e-01, 3.541635254e-01, 3.484186802e-01, 3.426607173e-01, 3.368898534e-01, 3.311063058e-01, 3.253102922e-01, 3.195020308e-01, 3.136817404e-01, 3.078496400e-01, 3.020059493e-01, 2.961508882e-01, 2.902846773e-01, 2.844075372e-01, 2.785196894e-01, 2.726213554e-01, 2.667127575e-01, 2.607941179e-01, 2.548656596e-01, 2.489276057e-01, 2.429801799e-01, 2.370236060e-01, 2.310581083e-01, 2.250839114e-01, 2.191012402e-01, 2.131103199e-01, 2.071113762e-01, 2.011046348e-01, 1.950903220e-01, 1.890686641e-01, 1.830398880e-01, 1.770042204e-01, 1.709618888e-01, 1.649131205e-01, 1.588581433e-01, 1.527971853e-01, 1.467304745e-01, 1.406582393e-01, 1.345807085e-01, 1.284981108e-01, 1.224106752e-01, 1.163186309e-01, 1.102222073e-01, 1.041216339e-01, 9.801714033e-02, 9.190895650e-02, 8.579731234e-02, 7.968243797e-02, 7.356456360e-02, 6.744391956e-02, 6.132073630e-02, 5.519524435e-02, 4.906767433e-02, 4.293825693e-02, 3.680722294e-02, 3.067480318e-02, 2.454122852e-02, 1.840672991e-02, 1.227153829e-02, 6.135884649e-03, 1.224646799e-16, -6.135884649e-03, -1.227153829e-02, -1.840672991e-02, -2.454122852e-02, -3.067480318e-02, -3.680722294e-02, -4.293825693e-02, -4.906767433e-02, -5.519524435e-02, -6.132073630e-02, -6.744391956e-02, -7.356456360e-02, -7.968243797e-02, -8.579731234e-02, -9.190895650e-02, -9.801714033e-02, -1.041216339e-01, -1.102222073e-01, -1.163186309e-01, -1.224106752e-01, -1.284981108e-01, -1.345807085e-01, -1.406582393e-01, -1.467304745e-01, -1.527971853e-01, -1.588581433e-01, -1.649131205e-01, -1.709618888e-01, -1.770042204e-01, -1.830398880e-01, -1.890686641e-01, -1.950903220e-01, -2.011046348e-01, -2.071113762e-01, -2.131103199e-01, -2.191012402e-01, -2.250839114e-01, -2.310581083e-01, -2.370236060e-01, -2.429801799e-01, -2.489276057e-01, -2.548656596e-01, -2.607941179e-01, -2.667127575e-01, -2.726213554e-01, -2.785196894e-01, -2.844075372e-01, -2.902846773e-01, -2.961508882e-01, -3.020059493e-01, -3.078496400e-01, -3.136817404e-01, -3.195020308e-01, -3.253102922e-01, -3.311063058e-01, -3.368898534e-01, -3.426607173e-01, -3.484186802e-01, -3.541635254e-01, -3.598950365e-01, -3.656129978e-01, -3.713171940e-01, -3.770074102e-01, -3.826834324e-01, -3.883450467e-01, -3.939920401e-01, -3.996241998e-01, -4.052413140e-01, -4.108431711e-01, -4.164295601e-01, -4.220002708e-01, -4.275550934e-01, -4.330938189e-01, -4.386162385e-01, -4.441221446e-01, -4.496113297e-01, -4.550835871e-01, -4.605387110e-01, -4.659764958e-01, -4.713967368e-01, -4.767992301e-01, -4.821837721e-01, -4.875501601e-01, -4.928981922e-01, -4.982276670e-01, -5.035383837e-01, -5.088301425e-01, -5.141027442e-01, -5.193559902e-01, -5.245896827e-01, -5.298036247e-01, -5.349976199e-01, -5.401714727e-01, -5.453249884e-01, -5.504579729e-01, -5.555702330e-01, -5.606615762e-01, -5.657318108e-01, -5.707807459e-01, -5.758081914e-01, -5.808139581e-01, -5.857978575e-01, -5.907597019e-01, -5.956993045e-01, -6.006164794e-01, -6.055110414e-01, -6.103828063e-01, -6.152315906e-01, -6.200572118e-01, -6.248594881e-01, -6.296382389e-01, -6.343932842e-01, -6.391244449e-01, -6.438315429e-01, -6.485144010e-01, -6.531728430e-01, -6.578066933e-01, -6.624157776e-01, -6.669999223e-01, -6.715589548e-01, -6.760927036e-01, -6.806009978e-01, -6.850836678e-01, -6.895405447e-01, -6.939714609e-01, -6.983762494e-01, -7.027547445e-01, -7.071067812e-01, -7.114321957e-01, -7.157308253e-01, -7.200025080e-01, -7.242470830e-01, -7.284643904e-01, -7.326542717e-01, -7.368165689e-01, -7.409511254e-01, -7.450577854e-01, -7.491363945e-01, -7.531867990e-01, -7.572088465e-01, -7.612023855e-01, -7.651672656e-01, -7.691033376e-01, -7.730104534e-01, -7.768884657e-01, -7.807372286e-01, -7.845565972e-01, -7.883464276e-01, -7.921065773e-01, -7.958369046e-01, -7.995372691e-01, -8.032075315e-01, -8.068475535e-01, -8.104571983e-01, -8.140363297e-01, -8.175848132e-01, -8.211025150e-01, -8.245893028e-01, -8.280450453e-01, -8.314696123e-01, -8.348628750e-01, -8.382247056e-01, -8.415549774e-01, -8.448535652e-01, -8.481203448e-01, -8.513551931e-01, -8.545579884e-01, -8.577286100e-01, -8.608669386e-01, -8.639728561e-01, -8.670462455e-01, -8.700869911e-01, -8.730949784e-01, -8.760700942e-01, -8.790122264e-01, -8.819212643e-01, -8.847970984e-01, -8.876396204e-01, -8.904487232e-01, -8.932243012e-01, -8.959662498e-01, -8.986744657e-01, -9.013488470e-01, -9.039892931e-01, -9.065957045e-01, -9.091679831e-01, -9.117060320e-01, -9.142097557e-01, -9.166790599e-01, -9.191138517e-01, -9.215140393e-01, -9.238795325e-01, -9.262102421e-01, -9.285060805e-01, -9.307669611e-01, -9.329927988e-01, -9.351835099e-01, -9.373390119e-01, -9.394592236e-01, -9.415440652e-01, -9.435934582e-01, -9.456073254e-01, -9.475855910e-01, -9.495281806e-01, -9.514350210e-01, -9.533060404e-01, -9.551411683e-01, -9.569403357e-01, -9.587034749e-01, -9.604305194e-01, -9.621214043e-01, -9.637760658e-01, -9.653944417e-01, -9.669764710e-01, -9.685220943e-01, -9.700312532e-01, -9.715038910e-01, -9.729399522e-01, -9.743393828e-01, -9.757021300e-01, -9.770281427e-01, -9.783173707e-01, -9.795697657e-01, -9.807852804e-01, -9.819638691e-01, -9.831054874e-01, -9.842100924e-01, -9.852776424e-01, -9.863080972e-01, -9.873014182e-01, -9.882575677e-01, -9.891765100e-01, -9.900582103e-01, -9.909026354e-01, -9.917097537e-01, -9.924795346e-01, -9.932119492e-01, -9.939069700e-01, -9.945645707e-01, -9.951847267e-01, -9.957674145e-01, -9.963126122e-01, -9.968202993e-01, -9.972904567e-01, -9.977230666e-01, -9.981181129e-01, -9.984755806e-01, -9.987954562e-01, -9.990777278e-01, -9.993223846e-01, -9.995294175e-01, -9.996988187e-01, -9.998305818e-01, -9.999247018e-01, -9.999811753e-01, -1.000000000e+00, -9.999811753e-01, -9.999247018e-01, -9.998305818e-01, -9.996988187e-01, -9.995294175e-01, -9.993223846e-01, -9.990777278e-01, -9.987954562e-01, -9.984755806e-01, -9.981181129e-01, -9.977230666e-01, -9.972904567e-01, -9.968202993e-01, -9.963126122e-01, -9.957674145e-01, -9.951847267e-01, -9.945645707e-01, -9.939069700e-01, -9.932119492e-01, -9.924795346e-01, -9.917097537e-01, -9.909026354e-01, -9.900582103e-01, -9.891765100e-01, -9.882575677e-01, -9.873014182e-01, -9.863080972e-01, -9.852776424e-01, -9.842100924e-01, -9.831054874e-01, -9.819638691e-01, -9.807852804e-01, -9.795697657e-01, -9.783173707e-01, -9.770281427e-01, -9.757021300e-01, -9.743393828e-01, -9.729399522e-01, -9.715038910e-01, -9.700312532e-01, -9.685220943e-01, -9.669764710e-01, -9.653944417e-01, -9.637760658e-01, -9.621214043e-01, -9.604305194e-01, -9.587034749e-01, -9.569403357e-01, -9.551411683e-01, -9.533060404e-01, -9.514350210e-01, -9.495281806e-01, -9.475855910e-01, -9.456073254e-01, -9.435934582e-01, -9.415440652e-01, -9.394592236e-01, -9.373390119e-01, -9.351835099e-01, -9.329927988e-01, -9.307669611e-01, -9.285060805e-01, -9.262102421e-01, -9.238795325e-01, -9.215140393e-01, -9.191138517e-01, -9.166790599e-01, -9.142097557e-01, -9.117060320e-01, -9.091679831e-01, -9.065957045e-01, -9.039892931e-01, -9.013488470e-01, -8.986744657e-01, -8.959662498e-01, -8.932243012e-01, -8.904487232e-01, -8.876396204e-01, -8.847970984e-01, -8.819212643e-01, -8.790122264e-01, -8.760700942e-01, -8.730949784e-01, -8.700869911e-01, -8.670462455e-01, -8.639728561e-01, -8.608669386e-01, -8.577286100e-01, -8.545579884e-01, -8.513551931e-01, -8.481203448e-01, -8.448535652e-01, -8.415549774e-01, -8.382247056e-01, -8.348628750e-01, -8.314696123e-01, -8.280450453e-01, -8.245893028e-01, -8.211025150e-01, -8.175848132e-01, -8.140363297e-01, -8.104571983e-01, -8.068475535e-01, -8.032075315e-01, -7.995372691e-01, -7.958369046e-01, -7.921065773e-01, -7.883464276e-01, -7.845565972e-01, -7.807372286e-01, -7.768884657e-01, -7.730104534e-01, -7.691033376e-01, -7.651672656e-01, -7.612023855e-01, -7.572088465e-01, -7.531867990e-01, -7.491363945e-01, -7.450577854e-01, -7.409511254e-01, -7.368165689e-01, -7.326542717e-01, -7.284643904e-01, -7.242470830e-01, -7.200025080e-01, -7.157308253e-01, -7.114321957e-01, -7.071067812e-01, -7.027547445e-01, -6.983762494e-01, -6.939714609e-01, -6.895405447e-01, -6.850836678e-01, -6.806009978e-01, -6.760927036e-01, -6.715589548e-01, -6.669999223e-01, -6.624157776e-01, -6.578066933e-01, -6.531728430e-01, -6.485144010e-01, -6.438315429e-01, -6.391244449e-01, -6.343932842e-01, -6.296382389e-01, -6.248594881e-01, -6.200572118e-01, -6.152315906e-01, -6.103828063e-01, -6.055110414e-01, -6.006164794e-01, -5.956993045e-01, -5.907597019e-01, -5.857978575e-01, -5.808139581e-01, -5.758081914e-01, -5.707807459e-01, -5.657318108e-01, -5.606615762e-01, -5.555702330e-01, -5.504579729e-01, -5.453249884e-01, -5.401714727e-01, -5.349976199e-01, -5.298036247e-01, -5.245896827e-01, -5.193559902e-01, -5.141027442e-01, -5.088301425e-01, -5.035383837e-01, -4.982276670e-01, -4.928981922e-01, -4.875501601e-01, -4.821837721e-01, -4.767992301e-01, -4.713967368e-01, -4.659764958e-01, -4.605387110e-01, -4.550835871e-01, -4.496113297e-01, -4.441221446e-01, -4.386162385e-01, -4.330938189e-01, -4.275550934e-01, -4.220002708e-01, -4.164295601e-01, -4.108431711e-01, -4.052413140e-01, -3.996241998e-01, -3.939920401e-01, -3.883450467e-01, -3.826834324e-01, -3.770074102e-01, -3.713171940e-01, -3.656129978e-01, -3.598950365e-01, -3.541635254e-01, -3.484186802e-01, -3.426607173e-01, -3.368898534e-01, -3.311063058e-01, -3.253102922e-01, -3.195020308e-01, -3.136817404e-01, -3.078496400e-01, -3.020059493e-01, -2.961508882e-01, -2.902846773e-01, -2.844075372e-01, -2.785196894e-01, -2.726213554e-01, -2.667127575e-01, -2.607941179e-01, -2.548656596e-01, -2.489276057e-01, -2.429801799e-01, -2.370236060e-01, -2.310581083e-01, -2.250839114e-01, -2.191012402e-01, -2.131103199e-01, -2.071113762e-01, -2.011046348e-01, -1.950903220e-01, -1.890686641e-01, -1.830398880e-01, -1.770042204e-01, -1.709618888e-01, -1.649131205e-01, -1.588581433e-01, -1.527971853e-01, -1.467304745e-01, -1.406582393e-01, -1.345807085e-01, -1.284981108e-01, -1.224106752e-01, -1.163186309e-01, -1.102222073e-01, -1.041216339e-01, -9.801714033e-02, -9.190895650e-02, -8.579731234e-02, -7.968243797e-02, -7.356456360e-02, -6.744391956e-02, -6.132073630e-02, -5.519524435e-02, -4.906767433e-02, -4.293825693e-02, -3.680722294e-02, -3.067480318e-02, -2.454122852e-02, -1.840672991e-02, -1.227153829e-02, -6.135884649e-03, -2.449293598e-16, 6.135884649e-03, 1.227153829e-02, 1.840672991e-02, 2.454122852e-02, 3.067480318e-02, 3.680722294e-02, 4.293825693e-02, 4.906767433e-02, 5.519524435e-02, 6.132073630e-02, 6.744391956e-02, 7.356456360e-02, 7.968243797e-02, 8.579731234e-02, 9.190895650e-02, 9.801714033e-02, 1.041216339e-01, 1.102222073e-01, 1.163186309e-01, 1.224106752e-01, 1.284981108e-01, 1.345807085e-01, 1.406582393e-01, 1.467304745e-01, 1.527971853e-01, 1.588581433e-01, 1.649131205e-01, 1.709618888e-01, 1.770042204e-01, 1.830398880e-01, 1.890686641e-01, 1.950903220e-01, 2.011046348e-01, 2.071113762e-01, 2.131103199e-01, 2.191012402e-01, 2.250839114e-01, 2.310581083e-01, 2.370236060e-01, 2.429801799e-01, 2.489276057e-01, 2.548656596e-01, 2.607941179e-01, 2.667127575e-01, 2.726213554e-01, 2.785196894e-01, 2.844075372e-01, 2.902846773e-01, 2.961508882e-01, 3.020059493e-01, 3.078496400e-01, 3.136817404e-01, 3.195020308e-01, 3.253102922e-01, 3.311063058e-01, 3.368898534e-01, 3.426607173e-01, 3.484186802e-01, 3.541635254e-01, 3.598950365e-01, 3.656129978e-01, 3.713171940e-01, 3.770074102e-01, 3.826834324e-01, 3.883450467e-01, 3.939920401e-01, 3.996241998e-01, 4.052413140e-01, 4.108431711e-01, 4.164295601e-01, 4.220002708e-01, 4.275550934e-01, 4.330938189e-01, 4.386162385e-01, 4.441221446e-01, 4.496113297e-01, 4.550835871e-01, 4.605387110e-01, 4.659764958e-01, 4.713967368e-01, 4.767992301e-01, 4.821837721e-01, 4.875501601e-01, 4.928981922e-01, 4.982276670e-01, 5.035383837e-01, 5.088301425e-01, 5.141027442e-01, 5.193559902e-01, 5.245896827e-01, 5.298036247e-01, 5.349976199e-01, 5.401714727e-01, 5.453249884e-01, 5.504579729e-01, 5.555702330e-01, 5.606615762e-01, 5.657318108e-01, 5.707807459e-01, 5.758081914e-01, 5.808139581e-01, 5.857978575e-01, 5.907597019e-01, 5.956993045e-01, 6.006164794e-01, 6.055110414e-01, 6.103828063e-01, 6.152315906e-01, 6.200572118e-01, 6.248594881e-01, 6.296382389e-01, 6.343932842e-01, 6.391244449e-01, 6.438315429e-01, 6.485144010e-01, 6.531728430e-01, 6.578066933e-01, 6.624157776e-01, 6.669999223e-01, 6.715589548e-01, 6.760927036e-01, 6.806009978e-01, 6.850836678e-01, 6.895405447e-01, 6.939714609e-01, 6.983762494e-01, 7.027547445e-01, 7.071067812e-01, 7.114321957e-01, 7.157308253e-01, 7.200025080e-01, 7.242470830e-01, 7.284643904e-01, 7.326542717e-01, 7.368165689e-01, 7.409511254e-01, 7.450577854e-01, 7.491363945e-01, 7.531867990e-01, 7.572088465e-01, 7.612023855e-01, 7.651672656e-01, 7.691033376e-01, 7.730104534e-01, 7.768884657e-01, 7.807372286e-01, 7.845565972e-01, 7.883464276e-01, 7.921065773e-01, 7.958369046e-01, 7.995372691e-01, 8.032075315e-01, 8.068475535e-01, 8.104571983e-01, 8.140363297e-01, 8.175848132e-01, 8.211025150e-01, 8.245893028e-01, 8.280450453e-01, 8.314696123e-01, 8.348628750e-01, 8.382247056e-01, 8.415549774e-01, 8.448535652e-01, 8.481203448e-01, 8.513551931e-01, 8.545579884e-01, 8.577286100e-01, 8.608669386e-01, 8.639728561e-01, 8.670462455e-01, 8.700869911e-01, 8.730949784e-01, 8.760700942e-01, 8.790122264e-01, 8.819212643e-01, 8.847970984e-01, 8.876396204e-01, 8.904487232e-01, 8.932243012e-01, 8.959662498e-01, 8.986744657e-01, 9.013488470e-01, 9.039892931e-01, 9.065957045e-01, 9.091679831e-01, 9.117060320e-01, 9.142097557e-01, 9.166790599e-01, 9.191138517e-01, 9.215140393e-01, 9.238795325e-01, 9.262102421e-01, 9.285060805e-01, 9.307669611e-01, 9.329927988e-01, 9.351835099e-01, 9.373390119e-01, 9.394592236e-01, 9.415440652e-01, 9.435934582e-01, 9.456073254e-01, 9.475855910e-01, 9.495281806e-01, 9.514350210e-01, 9.533060404e-01, 9.551411683e-01, 9.569403357e-01, 9.587034749e-01, 9.604305194e-01, 9.621214043e-01, 9.637760658e-01, 9.653944417e-01, 9.669764710e-01, 9.685220943e-01, 9.700312532e-01, 9.715038910e-01, 9.729399522e-01, 9.743393828e-01, 9.757021300e-01, 9.770281427e-01, 9.783173707e-01, 9.795697657e-01, 9.807852804e-01, 9.819638691e-01, 9.831054874e-01, 9.842100924e-01, 9.852776424e-01, 9.863080972e-01, 9.873014182e-01, 9.882575677e-01, 9.891765100e-01, 9.900582103e-01, 9.909026354e-01, 9.917097537e-01, 9.924795346e-01, 9.932119492e-01, 9.939069700e-01, 9.945645707e-01, 9.951847267e-01, 9.957674145e-01, 9.963126122e-01, 9.968202993e-01, 9.972904567e-01, 9.977230666e-01, 9.981181129e-01, 9.984755806e-01, 9.987954562e-01, 9.990777278e-01, 9.993223846e-01, 9.995294175e-01, 9.996988187e-01, 9.998305818e-01, 9.999247018e-01, 9.999811753e-01, 1.000000000e+00, }; const float lut_arcsin[] = { -1.000000000e+00, -9.203706289e-01, -8.873134070e-01, -8.618971430e-01, -8.404276493e-01, -8.214749794e-01, -8.043062326e-01, -7.884862959e-01, -7.737318355e-01, -7.598461583e-01, -7.466861322e-01, -7.341437612e-01, -7.221351863e-01, -7.105937516e-01, -6.994654384e-01, -6.887057478e-01, -6.782775070e-01, -6.681492851e-01, -6.582942244e-01, -6.486891596e-01, -6.393139448e-01, -6.301509296e-01, -6.211845465e-01, -6.124009827e-01, -6.037879145e-01, -5.953342919e-01, -5.870301615e-01, -5.788665198e-01, -5.708351903e-01, -5.629287213e-01, -5.551402986e-01, -5.474636710e-01, -5.398930877e-01, -5.324232433e-01, -5.250492308e-01, -5.177665009e-01, -5.105708258e-01, -5.034582687e-01, -4.964251556e-01, -4.894680517e-01, -4.825837395e-01, -4.757692002e-01, -4.690215962e-01, -4.623382565e-01, -4.557166630e-01, -4.491544378e-01, -4.426493331e-01, -4.361992206e-01, -4.298020828e-01, -4.234560051e-01, -4.171591678e-01, -4.109098402e-01, -4.047063738e-01, -3.985471970e-01, -3.924308100e-01, -3.863557800e-01, -3.803207370e-01, -3.743243695e-01, -3.683654214e-01, -3.624426882e-01, -3.565550140e-01, -3.507012885e-01, -3.448804446e-01, -3.390914556e-01, -3.333333333e-01, -3.276051254e-01, -3.219059136e-01, -3.162348121e-01, -3.105909654e-01, -3.049735469e-01, -2.993817576e-01, -2.938148240e-01, -2.882719975e-01, -2.827525527e-01, -2.772557865e-01, -2.717810168e-01, -2.663275813e-01, -2.608948371e-01, -2.554821590e-01, -2.500889395e-01, -2.447145871e-01, -2.393585260e-01, -2.340201956e-01, -2.286990490e-01, -2.233945532e-01, -2.181061879e-01, -2.128334453e-01, -2.075758290e-01, -2.023328540e-01, -1.971040461e-01, -1.918889411e-01, -1.866870844e-01, -1.814980309e-01, -1.763213443e-01, -1.711565967e-01, -1.660033681e-01, -1.608612465e-01, -1.557298269e-01, -1.506087115e-01, -1.454975090e-01, -1.403958344e-01, -1.353033088e-01, -1.302195590e-01, -1.251442172e-01, -1.200769208e-01, -1.150173122e-01, -1.099650383e-01, -1.049197503e-01, -9.988110384e-02, -9.484875828e-02, -8.982237675e-02, -8.480162582e-02, -7.978617535e-02, -7.477569824e-02, -6.976987025e-02, -6.476836978e-02, -5.977087768e-02, -5.477707708e-02, -4.978665318e-02, -4.479929306e-02, -3.981468554e-02, -3.483252094e-02, -2.985249095e-02, -2.487428845e-02, -1.989760733e-02, -1.492214229e-02, -9.947588740e-03, -4.973642567e-03, 0.000000000e+00, 4.973642567e-03, 9.947588740e-03, 1.492214229e-02, 1.989760733e-02, 2.487428845e-02, 2.985249095e-02, 3.483252094e-02, 3.981468554e-02, 4.479929306e-02, 4.978665318e-02, 5.477707708e-02, 5.977087768e-02, 6.476836978e-02, 6.976987025e-02, 7.477569824e-02, 7.978617535e-02, 8.480162582e-02, 8.982237675e-02, 9.484875828e-02, 9.988110384e-02, 1.049197503e-01, 1.099650383e-01, 1.150173122e-01, 1.200769208e-01, 1.251442172e-01, 1.302195590e-01, 1.353033088e-01, 1.403958344e-01, 1.454975090e-01, 1.506087115e-01, 1.557298269e-01, 1.608612465e-01, 1.660033681e-01, 1.711565967e-01, 1.763213443e-01, 1.814980309e-01, 1.866870844e-01, 1.918889411e-01, 1.971040461e-01, 2.023328540e-01, 2.075758290e-01, 2.128334453e-01, 2.181061879e-01, 2.233945532e-01, 2.286990490e-01, 2.340201956e-01, 2.393585260e-01, 2.447145871e-01, 2.500889395e-01, 2.554821590e-01, 2.608948371e-01, 2.663275813e-01, 2.717810168e-01, 2.772557865e-01, 2.827525527e-01, 2.882719975e-01, 2.938148240e-01, 2.993817576e-01, 3.049735469e-01, 3.105909654e-01, 3.162348121e-01, 3.219059136e-01, 3.276051254e-01, 3.333333333e-01, 3.390914556e-01, 3.448804446e-01, 3.507012885e-01, 3.565550140e-01, 3.624426882e-01, 3.683654214e-01, 3.743243695e-01, 3.803207370e-01, 3.863557800e-01, 3.924308100e-01, 3.985471970e-01, 4.047063738e-01, 4.109098402e-01, 4.171591678e-01, 4.234560051e-01, 4.298020828e-01, 4.361992206e-01, 4.426493331e-01, 4.491544378e-01, 4.557166630e-01, 4.623382565e-01, 4.690215962e-01, 4.757692002e-01, 4.825837395e-01, 4.894680517e-01, 4.964251556e-01, 5.034582687e-01, 5.105708258e-01, 5.177665009e-01, 5.250492308e-01, 5.324232433e-01, 5.398930877e-01, 5.474636710e-01, 5.551402986e-01, 5.629287213e-01, 5.708351903e-01, 5.788665198e-01, 5.870301615e-01, 5.953342919e-01, 6.037879145e-01, 6.124009827e-01, 6.211845465e-01, 6.301509296e-01, 6.393139448e-01, 6.486891596e-01, 6.582942244e-01, 6.681492851e-01, 6.782775070e-01, 6.887057478e-01, 6.994654384e-01, 7.105937516e-01, 7.221351863e-01, 7.341437612e-01, 7.466861322e-01, 7.598461583e-01, 7.737318355e-01, 7.884862959e-01, 8.043062326e-01, 8.214749794e-01, 8.404276493e-01, 8.618971430e-01, 8.873134070e-01, 9.203706289e-01, 1.000000000e+00, }; const float lut_xfade_in[] = { 0.000000000e+00, 0.000000000e+00, 0.000000000e+00, 0.000000000e+00, 0.000000000e+00, 2.593122279e-04, 4.754021803e-03, 9.248539291e-03, 1.374268309e-02, 1.823627161e-02, 2.272912328e-02, 2.722105658e-02, 3.171189001e-02, 3.620144210e-02, 4.068953146e-02, 4.517597675e-02, 4.966059668e-02, 5.414321007e-02, 5.862363578e-02, 6.310169278e-02, 6.757720014e-02, 7.204997701e-02, 7.651984269e-02, 8.098661655e-02, 8.545011812e-02, 8.991016705e-02, 9.436658313e-02, 9.881918630e-02, 1.032677966e-01, 1.077122344e-01, 1.121523200e-01, 1.165878741e-01, 1.210187174e-01, 1.254446709e-01, 1.298655558e-01, 1.342811934e-01, 1.386914053e-01, 1.430960134e-01, 1.474948396e-01, 1.518877062e-01, 1.562744358e-01, 1.606548510e-01, 1.650287749e-01, 1.693960308e-01, 1.737564422e-01, 1.781098329e-01, 1.824560270e-01, 1.867948489e-01, 1.911261233e-01, 1.954496752e-01, 1.997653299e-01, 2.040729129e-01, 2.083722504e-01, 2.126631685e-01, 2.169454939e-01, 2.212190535e-01, 2.254836747e-01, 2.297391851e-01, 2.339854129e-01, 2.382221864e-01, 2.424493344e-01, 2.466666862e-01, 2.508740714e-01, 2.550713199e-01, 2.592582621e-01, 2.634347290e-01, 2.676005517e-01, 2.717555618e-01, 2.758995917e-01, 2.800324736e-01, 2.841540408e-01, 2.882641267e-01, 2.923625651e-01, 2.964491905e-01, 3.005238378e-01, 3.045863424e-01, 3.086365400e-01, 3.126742671e-01, 3.166993604e-01, 3.207116574e-01, 3.247109959e-01, 3.286972144e-01, 3.326701518e-01, 3.366296475e-01, 3.405755416e-01, 3.445076746e-01, 3.484258877e-01, 3.523300225e-01, 3.562199212e-01, 3.600954268e-01, 3.639563827e-01, 3.678026327e-01, 3.716340216e-01, 3.754503944e-01, 3.792515971e-01, 3.830374759e-01, 3.868078781e-01, 3.905626511e-01, 3.943016433e-01, 3.980247036e-01, 4.017316815e-01, 4.054224274e-01, 4.090967921e-01, 4.127546270e-01, 4.163957845e-01, 4.200201173e-01, 4.236274791e-01, 4.272177241e-01, 4.307907072e-01, 4.343462841e-01, 4.378843111e-01, 4.414046452e-01, 4.449071442e-01, 4.483916665e-01, 4.518580715e-01, 4.553062190e-01, 4.587359696e-01, 4.621471849e-01, 4.655397270e-01, 4.689134588e-01, 4.722682440e-01, 4.756039471e-01, 4.789204331e-01, 4.822175683e-01, 4.854952193e-01, 4.887532537e-01, 4.919915398e-01, 4.952099469e-01, 4.984083449e-01, 5.015866045e-01, 5.047445973e-01, 5.078821957e-01, 5.109992730e-01, 5.140957032e-01, 5.171713612e-01, 5.202261227e-01, 5.232598643e-01, 5.262724634e-01, 5.292637982e-01, 5.322337480e-01, 5.351821928e-01, 5.381090133e-01, 5.410140913e-01, 5.438973095e-01, 5.467585513e-01, 5.495977011e-01, 5.524146443e-01, 5.552092670e-01, 5.579814562e-01, 5.607311000e-01, 5.634580873e-01, 5.661623079e-01, 5.688436525e-01, 5.715020128e-01, 5.741372814e-01, 5.767493517e-01, 5.793381183e-01, 5.819034766e-01, 5.844453228e-01, 5.869635543e-01, 5.894580694e-01, 5.919287672e-01, 5.943755480e-01, 5.967983128e-01, 5.991969637e-01, 6.015714039e-01, 6.039215374e-01, 6.062472693e-01, 6.085485055e-01, 6.108251531e-01, 6.130771202e-01, 6.153043156e-01, 6.175066495e-01, 6.196840328e-01, 6.218363775e-01, 6.239635968e-01, 6.260656046e-01, 6.281423160e-01, 6.301936471e-01, 6.322195150e-01, 6.342198378e-01, 6.361945349e-01, 6.381435262e-01, 6.400667332e-01, 6.419640780e-01, 6.438354840e-01, 6.456808757e-01, 6.475001784e-01, 6.492933187e-01, 6.510602240e-01, 6.528008231e-01, 6.545150455e-01, 6.562028220e-01, 6.578640844e-01, 6.594987656e-01, 6.611067995e-01, 6.626881211e-01, 6.642426667e-01, 6.657703733e-01, 6.672711792e-01, 6.687450238e-01, 6.701918475e-01, 6.716115919e-01, 6.730041996e-01, 6.743696144e-01, 6.757077810e-01, 6.770186454e-01, 6.783021546e-01, 6.795582569e-01, 6.807869013e-01, 6.819880383e-01, 6.831616194e-01, 6.843075971e-01, 6.854259251e-01, 6.865165582e-01, 6.875794525e-01, 6.886145648e-01, 6.896218534e-01, 6.906012777e-01, 6.915527979e-01, 6.924763757e-01, 6.933719738e-01, 6.942395560e-01, 6.950790872e-01, 6.958905334e-01, 6.966738620e-01, 6.974290413e-01, 6.981560407e-01, 6.988548308e-01, 6.995253835e-01, 7.001676716e-01, 7.007816693e-01, 7.013673516e-01, 7.019246949e-01, 7.024536767e-01, 7.029542757e-01, 7.034264715e-01, 7.038702452e-01, 7.042855787e-01, 7.046724553e-01, 7.050308595e-01, 7.053607766e-01, 7.056621934e-01, 7.059350976e-01, 7.061794783e-01, 7.063953256e-01, 7.065826308e-01, 7.067413862e-01, 7.068715855e-01, 7.069732234e-01, 7.070462959e-01, 7.070907999e-01, 7.071067336e-01, 7.071067812e-01, 7.071067812e-01, 7.071067812e-01, 7.071067812e-01, }; const float lut_xfade_out[] = { 7.071067812e-01, 7.071067812e-01, 7.071067812e-01, 7.071067812e-01, 7.071067812e-01, 7.071067336e-01, 7.070907999e-01, 7.070462959e-01, 7.069732234e-01, 7.068715855e-01, 7.067413862e-01, 7.065826308e-01, 7.063953256e-01, 7.061794783e-01, 7.059350976e-01, 7.056621934e-01, 7.053607766e-01, 7.050308595e-01, 7.046724553e-01, 7.042855787e-01, 7.038702452e-01, 7.034264715e-01, 7.029542757e-01, 7.024536767e-01, 7.019246949e-01, 7.013673516e-01, 7.007816693e-01, 7.001676716e-01, 6.995253835e-01, 6.988548308e-01, 6.981560407e-01, 6.974290413e-01, 6.966738620e-01, 6.958905334e-01, 6.950790872e-01, 6.942395560e-01, 6.933719738e-01, 6.924763757e-01, 6.915527979e-01, 6.906012777e-01, 6.896218534e-01, 6.886145648e-01, 6.875794525e-01, 6.865165582e-01, 6.854259251e-01, 6.843075971e-01, 6.831616194e-01, 6.819880383e-01, 6.807869013e-01, 6.795582569e-01, 6.783021546e-01, 6.770186454e-01, 6.757077810e-01, 6.743696144e-01, 6.730041996e-01, 6.716115919e-01, 6.701918475e-01, 6.687450238e-01, 6.672711792e-01, 6.657703733e-01, 6.642426667e-01, 6.626881211e-01, 6.611067995e-01, 6.594987656e-01, 6.578640844e-01, 6.562028220e-01, 6.545150455e-01, 6.528008231e-01, 6.510602240e-01, 6.492933187e-01, 6.475001784e-01, 6.456808757e-01, 6.438354840e-01, 6.419640780e-01, 6.400667332e-01, 6.381435262e-01, 6.361945349e-01, 6.342198378e-01, 6.322195150e-01, 6.301936471e-01, 6.281423160e-01, 6.260656046e-01, 6.239635968e-01, 6.218363775e-01, 6.196840328e-01, 6.175066495e-01, 6.153043156e-01, 6.130771202e-01, 6.108251531e-01, 6.085485055e-01, 6.062472693e-01, 6.039215374e-01, 6.015714039e-01, 5.991969637e-01, 5.967983128e-01, 5.943755480e-01, 5.919287672e-01, 5.894580694e-01, 5.869635543e-01, 5.844453228e-01, 5.819034766e-01, 5.793381183e-01, 5.767493517e-01, 5.741372814e-01, 5.715020128e-01, 5.688436525e-01, 5.661623079e-01, 5.634580873e-01, 5.607311000e-01, 5.579814562e-01, 5.552092670e-01, 5.524146443e-01, 5.495977011e-01, 5.467585513e-01, 5.438973095e-01, 5.410140913e-01, 5.381090133e-01, 5.351821928e-01, 5.322337480e-01, 5.292637982e-01, 5.262724634e-01, 5.232598643e-01, 5.202261227e-01, 5.171713612e-01, 5.140957032e-01, 5.109992730e-01, 5.078821957e-01, 5.047445973e-01, 5.015866045e-01, 4.984083449e-01, 4.952099469e-01, 4.919915398e-01, 4.887532537e-01, 4.854952193e-01, 4.822175683e-01, 4.789204331e-01, 4.756039471e-01, 4.722682440e-01, 4.689134588e-01, 4.655397270e-01, 4.621471849e-01, 4.587359696e-01, 4.553062190e-01, 4.518580715e-01, 4.483916665e-01, 4.449071442e-01, 4.414046452e-01, 4.378843111e-01, 4.343462841e-01, 4.307907072e-01, 4.272177241e-01, 4.236274791e-01, 4.200201173e-01, 4.163957845e-01, 4.127546270e-01, 4.090967921e-01, 4.054224274e-01, 4.017316815e-01, 3.980247036e-01, 3.943016433e-01, 3.905626511e-01, 3.868078781e-01, 3.830374759e-01, 3.792515971e-01, 3.754503944e-01, 3.716340216e-01, 3.678026327e-01, 3.639563827e-01, 3.600954268e-01, 3.562199212e-01, 3.523300225e-01, 3.484258877e-01, 3.445076746e-01, 3.405755416e-01, 3.366296475e-01, 3.326701518e-01, 3.286972144e-01, 3.247109959e-01, 3.207116574e-01, 3.166993604e-01, 3.126742671e-01, 3.086365400e-01, 3.045863424e-01, 3.005238378e-01, 2.964491905e-01, 2.923625651e-01, 2.882641267e-01, 2.841540408e-01, 2.800324736e-01, 2.758995917e-01, 2.717555618e-01, 2.676005517e-01, 2.634347290e-01, 2.592582621e-01, 2.550713199e-01, 2.508740714e-01, 2.466666862e-01, 2.424493344e-01, 2.382221864e-01, 2.339854129e-01, 2.297391851e-01, 2.254836747e-01, 2.212190535e-01, 2.169454939e-01, 2.126631685e-01, 2.083722504e-01, 2.040729129e-01, 1.997653299e-01, 1.954496752e-01, 1.911261233e-01, 1.867948489e-01, 1.824560270e-01, 1.781098329e-01, 1.737564422e-01, 1.693960308e-01, 1.650287749e-01, 1.606548510e-01, 1.562744358e-01, 1.518877062e-01, 1.474948396e-01, 1.430960134e-01, 1.386914053e-01, 1.342811934e-01, 1.298655558e-01, 1.254446709e-01, 1.210187174e-01, 1.165878741e-01, 1.121523200e-01, 1.077122344e-01, 1.032677966e-01, 9.881918630e-02, 9.436658313e-02, 8.991016705e-02, 8.545011812e-02, 8.098661655e-02, 7.651984269e-02, 7.204997701e-02, 6.757720014e-02, 6.310169278e-02, 5.862363578e-02, 5.414321007e-02, 4.966059668e-02, 4.517597675e-02, 4.068953146e-02, 3.620144210e-02, 3.171189001e-02, 2.722105658e-02, 2.272912328e-02, 1.823627161e-02, 1.374268309e-02, 9.248539291e-03, 4.754021803e-03, 2.593122279e-04, 4.329780281e-17, 4.329780281e-17, 4.329780281e-17, 4.329780281e-17, }; const float lut_bipolar_fold[] = { -8.678009033e-01, -8.677901336e-01, -8.677789794e-01, -8.677676173e-01, -8.677560993e-01, -8.677444533e-01, -8.677326970e-01, -8.677208428e-01, -8.677089000e-01, -8.676968760e-01, -8.676847765e-01, -8.676726064e-01, -8.676603697e-01, -8.676480698e-01, -8.676357099e-01, -8.676232924e-01, -8.676108197e-01, -8.675982939e-01, -8.675857167e-01, -8.675730900e-01, -8.675604151e-01, -8.675476935e-01, -8.675349264e-01, -8.675221149e-01, -8.675092603e-01, -8.674971687e-01, -8.674885432e-01, -8.674798907e-01, -8.674712118e-01, -8.674625070e-01, -8.674537767e-01, -8.674450213e-01, -8.674362413e-01, -8.674274372e-01, -8.674186091e-01, -8.674097576e-01, -8.674008829e-01, -8.673919854e-01, -8.673830653e-01, -8.673741230e-01, -8.673651587e-01, -8.673520079e-01, -8.673384967e-01, -8.673249535e-01, -8.673113789e-01, -8.672977731e-01, -8.672841364e-01, -8.672704691e-01, -8.672567715e-01, -8.672430440e-01, -8.672292867e-01, -8.672154999e-01, -8.672016839e-01, -8.671878389e-01, -8.671739651e-01, -8.671600628e-01, -8.671461321e-01, -8.671321734e-01, -8.671181867e-01, -8.671041723e-01, -8.670901303e-01, -8.670760610e-01, -8.670619645e-01, -8.670478409e-01, -8.670336905e-01, -8.670195134e-01, -8.670053098e-01, -8.669910797e-01, -8.669768235e-01, -8.669625411e-01, -8.669527118e-01, -8.669431556e-01, -8.669335823e-01, -8.669239920e-01, -8.669143846e-01, -8.669047604e-01, -8.668951193e-01, -8.668854615e-01, -8.668757870e-01, -8.668660960e-01, -8.668563883e-01, -8.668466642e-01, -8.668369237e-01, -8.668270539e-01, -8.668123942e-01, -8.667977101e-01, -8.667830018e-01, -8.667682693e-01, -8.667535127e-01, -8.667387321e-01, -8.667239276e-01, -8.667090992e-01, -8.666942471e-01, -8.666793712e-01, -8.666644717e-01, -8.666495487e-01, -8.666346021e-01, -8.666217470e-01, -8.666117514e-01, -8.666017403e-01, -8.665917137e-01, -8.665816717e-01, -8.665716142e-01, -8.665615414e-01, -8.665514532e-01, -8.665413497e-01, -8.665312309e-01, -8.665210969e-01, -8.665109477e-01, -8.665007833e-01, -8.664900561e-01, -8.664747641e-01, -8.664594496e-01, -8.664441124e-01, -8.664287528e-01, -8.664133706e-01, -8.663979660e-01, -8.663825389e-01, -8.663670896e-01, -8.663516178e-01, -8.663361238e-01, -8.663206075e-01, -8.663050690e-01, -8.662895083e-01, -8.662739255e-01, -8.662583205e-01, -8.662426934e-01, -8.662270443e-01, -8.662113732e-01, -8.661956800e-01, -8.661799649e-01, -8.661642278e-01, -8.661484688e-01, -8.661326879e-01, -8.661168852e-01, -8.661010606e-01, -8.660864319e-01, -8.660758531e-01, -8.660652598e-01, -8.660546520e-01, -8.660440297e-01, -8.660333930e-01, -8.660227418e-01, -8.660120761e-01, -8.660013961e-01, -8.659907016e-01, -8.659799927e-01, -8.659692695e-01, -8.659585318e-01, -8.659443748e-01, -8.659282252e-01, -8.659120541e-01, -8.658958615e-01, -8.658796475e-01, -8.658634119e-01, -8.658471549e-01, -8.658308765e-01, -8.658145766e-01, -8.657982553e-01, -8.657819126e-01, -8.657655484e-01, -8.657491629e-01, -8.657327560e-01, -8.657163278e-01, -8.656998782e-01, -8.656834072e-01, -8.656669150e-01, -8.656504013e-01, -8.656338664e-01, -8.656173101e-01, -8.656007326e-01, -8.655841337e-01, -8.655675136e-01, -8.655511674e-01, -8.655400589e-01, -8.655289362e-01, -8.655177994e-01, -8.655066483e-01, -8.654954832e-01, -8.654843038e-01, -8.654731103e-01, -8.654619026e-01, -8.654506807e-01, -8.654394447e-01, -8.654281945e-01, -8.654166550e-01, -8.653997373e-01, -8.653827983e-01, -8.653658381e-01, -8.653488567e-01, -8.653318540e-01, -8.653148301e-01, -8.652977850e-01, -8.652807186e-01, -8.652636310e-01, -8.652465222e-01, -8.652293922e-01, -8.652122409e-01, -8.651950683e-01, -8.651778746e-01, -8.651606596e-01, -8.651434234e-01, -8.651261659e-01, -8.651088872e-01, -8.650915872e-01, -8.650742660e-01, -8.650569235e-01, -8.650395598e-01, -8.650221748e-01, -8.650080618e-01, -8.649964435e-01, -8.649848109e-01, -8.649731642e-01, -8.649615033e-01, -8.649498281e-01, -8.649381388e-01, -8.649264353e-01, -8.649147176e-01, -8.649029856e-01, -8.648912395e-01, -8.648790331e-01, -8.648613712e-01, -8.648436880e-01, -8.648259834e-01, -8.648082575e-01, -8.647905101e-01, -8.647727415e-01, -8.647549514e-01, -8.647371399e-01, -8.647193071e-01, -8.647014528e-01, -8.646835771e-01, -8.646656800e-01, -8.646477614e-01, -8.646298214e-01, -8.646118600e-01, -8.645938771e-01, -8.645758727e-01, -8.645578468e-01, -8.645397994e-01, -8.645217305e-01, -8.645036401e-01, -8.644855282e-01, -8.644673947e-01, -8.644492397e-01, -8.644310631e-01, -8.644128649e-01, -8.643946451e-01, -8.643764038e-01, -8.643581408e-01, -8.643398562e-01, -8.643215500e-01, -8.643032221e-01, -8.642848725e-01, -8.642697086e-01, -8.642574466e-01, -8.642451702e-01, -8.642328793e-01, -8.642205739e-01, -8.642082540e-01, -8.641959197e-01, -8.641835708e-01, -8.641712073e-01, -8.641588294e-01, -8.641464369e-01, -8.641301219e-01, -8.641114894e-01, -8.640928351e-01, -8.640741589e-01, -8.640554608e-01, -8.640367408e-01, -8.640179989e-01, -8.639992351e-01, -8.639804492e-01, -8.639616414e-01, -8.639428117e-01, -8.639239599e-01, -8.639050860e-01, -8.638861902e-01, -8.638672722e-01, -8.638483322e-01, -8.638293701e-01, -8.638103859e-01, -8.637913796e-01, -8.637723511e-01, -8.637533004e-01, -8.637358229e-01, -8.637230929e-01, -8.637103480e-01, -8.636975884e-01, -8.636848138e-01, -8.636720245e-01, -8.636592202e-01, -8.636464011e-01, -8.636335671e-01, -8.636207182e-01, -8.636078544e-01, -8.635900953e-01, -8.635707548e-01, -8.635513918e-01, -8.635320064e-01, -8.635125985e-01, -8.634931680e-01, -8.634737151e-01, -8.634542397e-01, -8.634347416e-01, -8.634152210e-01, -8.633956778e-01, -8.633761120e-01, -8.633565236e-01, -8.633369124e-01, -8.633172786e-01, -8.632976221e-01, -8.632779428e-01, -8.632582408e-01, -8.632385160e-01, -8.632187684e-01, -8.631989980e-01, -8.631792047e-01, -8.631593886e-01, -8.631395496e-01, -8.631196877e-01, -8.630998028e-01, -8.630798950e-01, -8.630599642e-01, -8.630400104e-01, -8.630200336e-01, -8.630001852e-01, -8.629868366e-01, -8.629734725e-01, -8.629600931e-01, -8.629466982e-01, -8.629332878e-01, -8.629198620e-01, -8.629064207e-01, -8.628929639e-01, -8.628794916e-01, -8.628659001e-01, -8.628456450e-01, -8.628253666e-01, -8.628050648e-01, -8.627847395e-01, -8.627643909e-01, -8.627440187e-01, -8.627236231e-01, -8.627032040e-01, -8.626827614e-01, -8.626622952e-01, -8.626418054e-01, -8.626212920e-01, -8.626007550e-01, -8.625801943e-01, -8.625596098e-01, -8.625390017e-01, -8.625183698e-01, -8.624977142e-01, -8.624770347e-01, -8.624586806e-01, -8.624448625e-01, -8.624310285e-01, -8.624171785e-01, -8.624033125e-01, -8.623894306e-01, -8.623755327e-01, -8.623616187e-01, -8.623476888e-01, -8.623337427e-01, -8.623151201e-01, -8.622941528e-01, -8.622731612e-01, -8.622521455e-01, -8.622311056e-01, -8.622100413e-01, -8.621889528e-01, -8.621678399e-01, -8.621467027e-01, -8.621255411e-01, -8.621043551e-01, -8.620831446e-01, -8.620619097e-01, -8.620406502e-01, -8.620193662e-01, -8.619980577e-01, -8.619767245e-01, -8.619553667e-01, -8.619339842e-01, -8.619125770e-01, -8.618911451e-01, -8.618696884e-01, -8.618482069e-01, -8.618267006e-01, -8.618051695e-01, -8.617836134e-01, -8.617620324e-01, -8.617404265e-01, -8.617187956e-01, -8.616971396e-01, -8.616754586e-01, -8.616537525e-01, -8.616320213e-01, -8.616102649e-01, -8.615884834e-01, -8.615666766e-01, -8.615448445e-01, -8.615231373e-01, -8.615085488e-01, -8.614939435e-01, -8.614793212e-01, -8.614646820e-01, -8.614500257e-01, -8.614353525e-01, -8.614206623e-01, -8.614059550e-01, -8.613912306e-01, -8.613701537e-01, -8.613480158e-01, -8.613258523e-01, -8.613036629e-01, -8.612814478e-01, -8.612592069e-01, -8.612369401e-01, -8.612146474e-01, -8.611923288e-01, -8.611699842e-01, -8.611476136e-01, -8.611252170e-01, -8.611027943e-01, -8.610803455e-01, -8.610578705e-01, -8.610353693e-01, -8.610128419e-01, -8.609902883e-01, -8.609677083e-01, -8.609451020e-01, -8.609224693e-01, -8.608998102e-01, -8.608771246e-01, -8.608544125e-01, -8.608316739e-01, -8.608089087e-01, -8.607861169e-01, -8.607705030e-01, -8.607552729e-01, -8.607400250e-01, -8.607247592e-01, -8.607094756e-01, -8.606941741e-01, -8.606788546e-01, -8.606635171e-01, -8.606469252e-01, -8.606238651e-01, -8.606007779e-01, -8.605776636e-01, -8.605545222e-01, -8.605313536e-01, -8.605081577e-01, -8.604849347e-01, -8.604616843e-01, -8.604384065e-01, -8.604151014e-01, -8.603917689e-01, -8.603684088e-01, -8.603450213e-01, -8.603216062e-01, -8.602981635e-01, -8.602746931e-01, -8.602511951e-01, -8.602276694e-01, -8.602041158e-01, -8.601805345e-01, -8.601569253e-01, -8.601332882e-01, -8.601096231e-01, -8.600859300e-01, -8.600622089e-01, -8.600384598e-01, -8.600146825e-01, -8.599908770e-01, -8.599670433e-01, -8.599431814e-01, -8.599192911e-01, -8.598953725e-01, -8.598714255e-01, -8.598474501e-01, -8.598234461e-01, -8.597994137e-01, -8.597753526e-01, -8.597512630e-01, -8.597271446e-01, -8.597029975e-01, -8.596788217e-01, -8.596546170e-01, -8.596347739e-01, -8.596185989e-01, -8.596024047e-01, -8.595861911e-01, -8.595699581e-01, -8.595537058e-01, -8.595374340e-01, -8.595211427e-01, -8.595026092e-01, -8.594781138e-01, -8.594535890e-01, -8.594290348e-01, -8.594044512e-01, -8.593798381e-01, -8.593551954e-01, -8.593305232e-01, -8.593058213e-01, -8.592810897e-01, -8.592563284e-01, -8.592315373e-01, -8.592067163e-01, -8.591818654e-01, -8.591569846e-01, -8.591320738e-01, -8.591071330e-01, -8.590821621e-01, -8.590571610e-01, -8.590321297e-01, -8.590070681e-01, -8.589819762e-01, -8.589568540e-01, -8.589317014e-01, -8.589065183e-01, -8.588813046e-01, -8.588560604e-01, -8.588307856e-01, -8.588054801e-01, -8.587801439e-01, -8.587547769e-01, -8.587293790e-01, -8.587039502e-01, -8.586784905e-01, -8.586529998e-01, -8.586274781e-01, -8.586019252e-01, -8.585763411e-01, -8.585507258e-01, -8.585250793e-01, -8.585003334e-01, -8.584831938e-01, -8.584660333e-01, -8.584488518e-01, -8.584316493e-01, -8.584144257e-01, -8.583971810e-01, -8.583799151e-01, -8.583599820e-01, -8.583340196e-01, -8.583080252e-01, -8.582819989e-01, -8.582559405e-01, -8.582298501e-01, -8.582037275e-01, -8.581775727e-01, -8.581513857e-01, -8.581251664e-01, -8.580989147e-01, -8.580726305e-01, -8.580463139e-01, -8.580199647e-01, -8.579935829e-01, -8.579671684e-01, -8.579407212e-01, -8.579142411e-01, -8.578877283e-01, -8.578611825e-01, -8.578346037e-01, -8.578079919e-01, -8.577813470e-01, -8.577546689e-01, -8.577279576e-01, -8.577012130e-01, -8.576744351e-01, -8.576476237e-01, -8.576207789e-01, -8.575939005e-01, -8.575669885e-01, -8.575400429e-01, -8.575130635e-01, -8.574860503e-01, -8.574590032e-01, -8.574319223e-01, -8.574048073e-01, -8.573776583e-01, -8.573504752e-01, -8.573232578e-01, -8.572960063e-01, -8.572687204e-01, -8.572414001e-01, -8.572140454e-01, -8.571866561e-01, -8.571592323e-01, -8.571317738e-01, -8.571042806e-01, -8.570767526e-01, -8.570491898e-01, -8.570215920e-01, -8.569939593e-01, -8.569662914e-01, -8.569450616e-01, -8.569265695e-01, -8.569080539e-01, -8.568895148e-01, -8.568709520e-01, -8.568523656e-01, -8.568337555e-01, -8.568108172e-01, -8.567828308e-01, -8.567548086e-01, -8.567267505e-01, -8.566986566e-01, -8.566705267e-01, -8.566423607e-01, -8.566141587e-01, -8.565859204e-01, -8.565576459e-01, -8.565293351e-01, -8.565009878e-01, -8.564726041e-01, -8.564441838e-01, -8.564157269e-01, -8.563872334e-01, -8.563587030e-01, -8.563301358e-01, -8.563015316e-01, -8.562728905e-01, -8.562442123e-01, -8.562154969e-01, -8.561867444e-01, -8.561579545e-01, -8.561291272e-01, -8.561002625e-01, -8.560713603e-01, -8.560424205e-01, -8.560134430e-01, -8.559844277e-01, -8.559553746e-01, -8.559262835e-01, -8.558971545e-01, -8.558679874e-01, -8.558387821e-01, -8.558095386e-01, -8.557802568e-01, -8.557509366e-01, -8.557215780e-01, -8.556921808e-01, -8.556627449e-01, -8.556332703e-01, -8.556037570e-01, -8.555742048e-01, -8.555446136e-01, -8.555149834e-01, -8.554853140e-01, -8.554556055e-01, -8.554258576e-01, -8.553960704e-01, -8.553662438e-01, -8.553363776e-01, -8.553064718e-01, -8.552765263e-01, -8.552465410e-01, -8.552165158e-01, -8.551864507e-01, -8.551563455e-01, -8.551262002e-01, -8.550960147e-01, -8.550657889e-01, -8.550355227e-01, -8.550052160e-01, -8.549748688e-01, -8.549444809e-01, -8.549140523e-01, -8.548835829e-01, -8.548530725e-01, -8.548225212e-01, -8.547919287e-01, -8.547612951e-01, -8.547306202e-01, -8.546999040e-01, -8.546691463e-01, -8.546383471e-01, -8.546075062e-01, -8.545766237e-01, -8.545456993e-01, -8.545147330e-01, -8.544837247e-01, -8.544526744e-01, -8.544215818e-01, -8.543904470e-01, -8.543592699e-01, -8.543280502e-01, -8.542967881e-01, -8.542654833e-01, -8.542341357e-01, -8.542027453e-01, -8.541713120e-01, -8.541398356e-01, -8.541083162e-01, -8.540767535e-01, -8.540451475e-01, -8.540134981e-01, -8.539818052e-01, -8.539500687e-01, -8.539182885e-01, -8.538864645e-01, -8.538545966e-01, -8.538226847e-01, -8.537907287e-01, -8.537587286e-01, -8.537266841e-01, -8.536945952e-01, -8.536624619e-01, -8.536302839e-01, -8.535980613e-01, -8.535657938e-01, -8.535334815e-01, -8.535011242e-01, -8.534687218e-01, -8.534362741e-01, -8.534037812e-01, -8.533712428e-01, -8.533386590e-01, -8.533060295e-01, -8.532733543e-01, -8.532406332e-01, -8.532078663e-01, -8.531750533e-01, -8.531421941e-01, -8.531092887e-01, -8.530763370e-01, -8.530433388e-01, -8.530102940e-01, -8.529772025e-01, -8.529440643e-01, -8.529108791e-01, -8.528776470e-01, -8.528443677e-01, -8.528110413e-01, -8.527776675e-01, -8.527442462e-01, -8.527107774e-01, -8.526772609e-01, -8.526436967e-01, -8.526100846e-01, -8.525764245e-01, -8.525427163e-01, -8.525089598e-01, -8.524751550e-01, -8.524413018e-01, -8.524074000e-01, -8.523734495e-01, -8.523394502e-01, -8.523054021e-01, -8.522713049e-01, -8.522371585e-01, -8.522029629e-01, -8.521687180e-01, -8.521344235e-01, -8.521000794e-01, -8.520656857e-01, -8.520312420e-01, -8.519967484e-01, -8.519622048e-01, -8.519276109e-01, -8.518929667e-01, -8.518582721e-01, -8.518235269e-01, -8.517887310e-01, -8.517538844e-01, -8.517189868e-01, -8.516840381e-01, -8.516490383e-01, -8.516139872e-01, -8.515788847e-01, -8.515437306e-01, -8.515085249e-01, -8.514732673e-01, -8.514379579e-01, -8.514025964e-01, -8.513671828e-01, -8.513317168e-01, -8.512961985e-01, -8.512606276e-01, -8.512250040e-01, -8.511893276e-01, -8.511535983e-01, -8.511178159e-01, -8.510819803e-01, -8.510460914e-01, -8.510101491e-01, -8.509741531e-01, -8.509381035e-01, -8.509020000e-01, -8.508658426e-01, -8.508296310e-01, -8.507933652e-01, -8.507570450e-01, -8.507206703e-01, -8.506842409e-01, -8.506477568e-01, -8.506112177e-01, -8.505746236e-01, -8.505379743e-01, -8.505012697e-01, -8.504645097e-01, -8.504276940e-01, -8.503908226e-01, -8.503538953e-01, -8.503169120e-01, -8.502798725e-01, -8.502427768e-01, -8.502056246e-01, -8.501684158e-01, -8.501311504e-01, -8.500938280e-01, -8.500564487e-01, -8.500190122e-01, -8.499815184e-01, -8.499334277e-01, -8.498832826e-01, -8.498330606e-01, -8.497827615e-01, -8.497323850e-01, -8.496882060e-01, -8.496503072e-01, -8.496123499e-01, -8.495743340e-01, -8.495362594e-01, -8.494981258e-01, -8.494599333e-01, -8.494216815e-01, -8.493833704e-01, -8.493449998e-01, -8.493065695e-01, -8.492680794e-01, -8.492295294e-01, -8.491909193e-01, -8.491522489e-01, -8.491135181e-01, -8.490747268e-01, -8.490358747e-01, -8.489969618e-01, -8.489579878e-01, -8.489189526e-01, -8.488798561e-01, -8.488406981e-01, -8.488014784e-01, -8.487621969e-01, -8.487228534e-01, -8.486834478e-01, -8.486439798e-01, -8.486044495e-01, -8.485648565e-01, -8.485252007e-01, -8.484854819e-01, -8.484457001e-01, -8.484058550e-01, -8.483659465e-01, -8.483259743e-01, -8.482822115e-01, -8.482287450e-01, -8.481751931e-01, -8.481215555e-01, -8.480678320e-01, -8.480176579e-01, -8.479772359e-01, -8.479367489e-01, -8.478961969e-01, -8.478555796e-01, -8.478148968e-01, -8.477741484e-01, -8.477333343e-01, -8.476924541e-01, -8.476515078e-01, -8.476104953e-01, -8.475694162e-01, -8.475282705e-01, -8.474870579e-01, -8.474457783e-01, -8.474044315e-01, -8.473630174e-01, -8.473215358e-01, -8.472799864e-01, -8.472383691e-01, -8.471879448e-01, -8.471322733e-01, -8.470765105e-01, -8.470206563e-01, -8.469647103e-01, -8.469200907e-01, -8.468779930e-01, -8.468358260e-01, -8.467935895e-01, -8.467512832e-01, -8.467089070e-01, -8.466664607e-01, -8.466239442e-01, -8.465813572e-01, -8.465386995e-01, -8.464959709e-01, -8.464531714e-01, -8.464103006e-01, -8.463673584e-01, -8.463243445e-01, -8.462812589e-01, -8.462381013e-01, -8.461948715e-01, -8.461515693e-01, -8.460946988e-01, -8.460367687e-01, -8.459787414e-01, -8.459206165e-01, -8.458668270e-01, -8.458230864e-01, -8.457792721e-01, -8.457353837e-01, -8.456914213e-01, -8.456473844e-01, -8.456032730e-01, -8.455590868e-01, -8.455148257e-01, -8.454704894e-01, -8.454260777e-01, -8.453815905e-01, -8.453370274e-01, -8.452923884e-01, -8.452382712e-01, -8.451785490e-01, -8.451187247e-01, -8.450587979e-01, -8.450009074e-01, -8.449558080e-01, -8.449106312e-01, -8.448653768e-01, -8.448200444e-01, -8.447746340e-01, -8.447291452e-01, -8.446835780e-01, -8.446379320e-01, -8.445922070e-01, -8.445464029e-01, -8.445005194e-01, -8.444545562e-01, -8.444085133e-01, -8.443488283e-01, -8.442872240e-01, -8.442255123e-01, -8.441636931e-01, -8.441099548e-01, -8.440634282e-01, -8.440168203e-01, -8.439701308e-01, -8.439233594e-01, -8.438765060e-01, -8.438295703e-01, -8.437825521e-01, -8.437354512e-01, -8.436882672e-01, -8.436410001e-01, -8.435936496e-01, -8.435462153e-01, -8.434881718e-01, -8.434247021e-01, -8.433611199e-01, -8.432974250e-01, -8.432406423e-01, -8.431927012e-01, -8.431446747e-01, -8.430965627e-01, -8.430483649e-01, -8.430000811e-01, -8.429517110e-01, -8.429032544e-01, -8.428533191e-01, -8.427884787e-01, -8.427235218e-01, -8.426584484e-01, -8.425932579e-01, -8.425435456e-01, -8.424944766e-01, -8.424453191e-01, -8.423960728e-01, -8.423467376e-01, -8.422973132e-01, -8.422477993e-01, -8.421981956e-01, -8.421355026e-01, -8.420691241e-01, -8.420026250e-01, -8.419360048e-01, -8.418816838e-01, -8.418315364e-01, -8.417812975e-01, -8.417309668e-01, -8.416682157e-01, -8.416008623e-01, -8.415333855e-01, -8.414657849e-01, -8.414107888e-01, -8.413599019e-01, -8.413089214e-01, -8.412578470e-01, -8.412066784e-01, -8.411554155e-01, -8.411040578e-01, -8.410526051e-01, -8.409860288e-01, -8.409171710e-01, -8.408481854e-01, -8.407790718e-01, -8.407267693e-01, -8.406747411e-01, -8.406226161e-01, -8.405703939e-01, -8.405180742e-01, -8.404656569e-01, -8.404131415e-01, -8.403557852e-01, -8.402855023e-01, -8.402150875e-01, -8.401445406e-01, -8.400819462e-01, -8.400288369e-01, -8.399756276e-01, -8.399223180e-01, -8.398569488e-01, -8.397856008e-01, -8.397141179e-01, -8.396424998e-01, -8.395871172e-01, -8.395331999e-01, -8.394791802e-01, -8.394218057e-01, -8.393495055e-01, -8.392770676e-01, -8.392044917e-01, -8.391403980e-01, -8.390857581e-01, -8.390310138e-01, -8.389761649e-01, -8.389212108e-01, -8.388661515e-01, -8.388109865e-01, -8.387531449e-01, -8.386793086e-01, -8.386053303e-01, -8.385312095e-01, -8.384664276e-01, -8.384106223e-01, -8.383547092e-01, -8.382986880e-01, -8.382255920e-01, -8.381506075e-01, -8.380754775e-01, -8.380063768e-01, -8.379498102e-01, -8.378931335e-01, -8.378363465e-01, -8.377647696e-01, -8.376887580e-01, -8.376125979e-01, -8.375409497e-01, -8.374836060e-01, -8.374261500e-01, -8.373685813e-01, -8.372966944e-01, -8.372196344e-01, -8.371424230e-01, -8.370700349e-01, -8.370118980e-01, -8.369536464e-01, -8.368952799e-01, -8.368212157e-01, -8.367430857e-01, -8.366648009e-01, -8.365935183e-01, -8.365345717e-01, -8.364755081e-01, -8.364163270e-01, -8.363381796e-01, -8.362589570e-01, -8.361795766e-01, -8.361000378e-01, -8.360203401e-01, -8.359404831e-01, -8.358644660e-01, -8.358043331e-01, -8.357440798e-01, -8.356837055e-01, -8.356059302e-01, -8.355251073e-01, -8.354441216e-01, -8.353738531e-01, -8.353128688e-01, -8.352517614e-01, -8.351856812e-01, -8.351038749e-01, -8.350219030e-01, -8.349397649e-01, -8.348772261e-01, -8.348153723e-01, -8.347533928e-01, -8.346766805e-01, -8.345937044e-01, -8.345105593e-01, -8.344272445e-01, -8.343437596e-01, -8.342601041e-01, -8.341817076e-01, -8.341187088e-01, -8.340555810e-01, -8.339909041e-01, -8.339063877e-01, -8.338216975e-01, -8.337368331e-01, -8.336517939e-01, -8.335665794e-01, -8.334811891e-01, -8.334115850e-01, -8.333472773e-01, -8.332828365e-01, -8.332049975e-01, -8.331187200e-01, -8.330322634e-01, -8.329565959e-01, -8.328914837e-01, -8.328262360e-01, -8.327517746e-01, -8.326644146e-01, -8.325768724e-01, -8.324891473e-01, -8.324012387e-01, -8.323131461e-01, -8.322248691e-01, -8.321364069e-01, -8.320477590e-01, -8.319647991e-01, -8.318980335e-01, -8.318311273e-01, -8.317584382e-01, -8.316688535e-01, -8.315790798e-01, -8.314891163e-01, -8.313989626e-01, -8.313086181e-01, -8.312245358e-01, -8.311564899e-01, -8.310882995e-01, -8.310124589e-01, -8.309211516e-01, -8.308296499e-01, -8.307379532e-01, -8.306460610e-01, -8.305539727e-01, -8.304616877e-01, -8.303692053e-01, -8.302765250e-01, -8.301969387e-01, -8.301271301e-01, -8.300571718e-01, -8.299709507e-01, -8.298772715e-01, -8.297833907e-01, -8.296893077e-01, -8.295950218e-01, -8.295005324e-01, -8.294058389e-01, -8.293109406e-01, -8.292193118e-01, -8.291478296e-01, -8.290761924e-01, -8.289964262e-01, -8.289004947e-01, -8.288043547e-01, -8.287080054e-01, -8.286114463e-01, -8.285146767e-01, -8.284176959e-01, -8.283205034e-01, -8.282230983e-01, -8.281254802e-01, -8.280276482e-01, -8.279296018e-01, -8.278313403e-01, -8.277328630e-01, -8.276470136e-01, -8.275728305e-01, -8.274984840e-01, -8.274039212e-01, -8.273043549e-01, -8.272045687e-01, -8.271045620e-01, -8.270043341e-01, -8.269038843e-01, -8.268032119e-01, -8.267023162e-01, -8.266011966e-01, -8.264998522e-01, -8.263982824e-01, -8.262964866e-01, -8.261944640e-01, -8.260922138e-01, -8.259897354e-01, -8.258870281e-01, -8.257840911e-01, -8.256809238e-01, -8.255775253e-01, -8.254738951e-01, -8.253700323e-01, -8.252659362e-01, -8.251616061e-01, -8.250570412e-01, -8.249522409e-01, -8.248472043e-01, -8.247560941e-01, -8.246769606e-01, -8.245976483e-01, -8.244918195e-01, -8.243855906e-01, -8.242791209e-01, -8.241724098e-01, -8.240654564e-01, -8.239582600e-01, -8.238508198e-01, -8.237431350e-01, -8.236352050e-01, -8.235270288e-01, -8.234186057e-01, -8.233099350e-01, -8.232010158e-01, -8.230918473e-01, -8.229815761e-01, -8.228444895e-01, -8.227070884e-01, -8.225855267e-01, -8.224751001e-01, -8.223644195e-01, -8.222534841e-01, -8.221422930e-01, -8.220308455e-01, -8.219191407e-01, -8.218071778e-01, -8.216949560e-01, -8.215824744e-01, -8.214697323e-01, -8.213567287e-01, -8.212434629e-01, -8.211299340e-01, -8.210161412e-01, -8.209020837e-01, -8.207877605e-01, -8.206731708e-01, -8.205583139e-01, -8.204431887e-01, -8.203277946e-01, -8.202121305e-01, -8.200961956e-01, -8.199799892e-01, -8.198382378e-01, -8.196922974e-01, -8.195625925e-01, -8.194452908e-01, -8.193277130e-01, -8.192098582e-01, -8.190917257e-01, -8.189733145e-01, -8.188546236e-01, -8.187356523e-01, -8.186163995e-01, -8.184824087e-01, -8.183326357e-01, -8.181898049e-01, -8.180694174e-01, -8.179487439e-01, -8.178277834e-01, -8.177065351e-01, -8.175849980e-01, -8.174631712e-01, -8.173410538e-01, -8.172186447e-01, -8.170837350e-01, -8.169299911e-01, -8.167825197e-01, -8.166589348e-01, -8.165350534e-01, -8.164108748e-01, -8.162863978e-01, -8.161340337e-01, -8.159776881e-01, -8.158440286e-01, -8.157183486e-01, -8.155923655e-01, -8.154660781e-01, -8.153245645e-01, -8.151659411e-01, -8.150182423e-01, -8.148907281e-01, -8.147629048e-01, -8.146347713e-01, -8.145013164e-01, -8.143403701e-01, -8.141813606e-01, -8.140519760e-01, -8.139222760e-01, -8.137597949e-01, -8.135968777e-01, -8.134641351e-01, -8.133331634e-01, -8.132018711e-01, -8.130702572e-01, -8.129105717e-01, -8.127452463e-01, -8.126063365e-01, -8.124734255e-01, -8.123139673e-01, -8.121470098e-01, -8.120055877e-01, -8.118713623e-01, -8.117108020e-01, -8.115421906e-01, -8.113995552e-01, -8.112639980e-01, -8.111009883e-01, -8.109307010e-01, -8.107881688e-01, -8.106512620e-01, -8.104844376e-01, -8.103124520e-01, -8.101713569e-01, -8.100330824e-01, -8.098610598e-01, -8.096873533e-01, -8.095132129e-01, -8.093422477e-01, -8.092022378e-01, -8.090553129e-01, -8.088794227e-01, -8.087129613e-01, -8.085715421e-01, -8.084162378e-01, -8.082385740e-01, -8.080604632e-01, -8.078819038e-01, -8.077248155e-01, -8.075812466e-01, -8.074106577e-01, -8.072302889e-01, -8.070494638e-01, -8.068690566e-01, -8.067236630e-01, -8.065713750e-01, -8.063887098e-01, -8.062055807e-01, -8.060219862e-01, -8.058379246e-01, -8.056533943e-01, -8.054940999e-01, -8.053457221e-01, -8.051641146e-01, -8.049776939e-01, -8.047907966e-01, -8.046034211e-01, -8.044155656e-01, -8.042272287e-01, -8.040384087e-01, -8.038764022e-01, -8.037245692e-01, -8.035361720e-01, -8.033454029e-01, -8.031541425e-01, -8.029623889e-01, -8.027701406e-01, -8.025773958e-01, -8.023841529e-01, -8.021904101e-01, -8.019961657e-01, -8.018014180e-01, -8.016061654e-01, -8.014104060e-01, -8.012141381e-01, -8.010173600e-01, -8.008200699e-01, -8.006222661e-01, -8.004239468e-01, -8.002251102e-01, -8.000257545e-01, -7.998258781e-01, -7.996254789e-01, -7.994245554e-01, -7.992231055e-01, -7.990211277e-01, -7.988186199e-01, -7.986155804e-01, -7.984120073e-01, -7.982078988e-01, -7.980032531e-01, -7.977980682e-01, -7.975923423e-01, -7.973860736e-01, -7.971792601e-01, -7.969656451e-01, -7.967161547e-01, -7.964883933e-01, -7.962793818e-01, -7.960698159e-01, -7.958596938e-01, -7.956490135e-01, -7.954066753e-01, -7.951588319e-01, -7.949464653e-01, -7.947335327e-01, -7.945200321e-01, -7.943059616e-01, -7.940729128e-01, -7.938146530e-01, -7.935931711e-01, -7.933631958e-01, -7.931028549e-01, -7.928751783e-01, -7.926570614e-01, -7.924383582e-01, -7.921887590e-01, -7.919320462e-01, -7.917115720e-01, -7.914621878e-01, -7.912016991e-01, -7.909794349e-01, -7.907291729e-01, -7.904659632e-01, -7.902418900e-01, -7.899896456e-01, -7.897247810e-01, -7.894988796e-01, -7.892435365e-01, -7.889780945e-01, -7.887503452e-01, -7.884907750e-01, -7.882258447e-01, -7.879962277e-01, -7.877312899e-01, -7.874542420e-01, -7.871764363e-01, -7.868978702e-01, -7.866372768e-01, -7.864038640e-01, -7.861247200e-01, -7.858430845e-01, -7.855654956e-01, -7.853295066e-01, -7.850606601e-01, -7.847759109e-01, -7.844903763e-01, -7.842040534e-01, -7.839169394e-01, -7.836290314e-01, -7.833403267e-01, -7.830508222e-01, -7.827605151e-01, -7.824694025e-01, -7.822202483e-01, -7.819518879e-01, -7.816583412e-01, -7.813639773e-01, -7.810314713e-01, -7.807056472e-01, -7.804088137e-01, -7.801111510e-01, -7.798126560e-01, -7.795133258e-01, -7.792131573e-01, -7.789121473e-01, -7.786102930e-01, -7.783075911e-01, -7.780040385e-01, -7.776490826e-01, -7.773272303e-01, -7.770211070e-01, -7.767141206e-01, -7.764062678e-01, -7.760597258e-01, -7.757208116e-01, -7.754103404e-01, -7.750989901e-01, -7.747430788e-01, -7.744065001e-01, -7.740785705e-01, -7.737111875e-01, -7.733946589e-01, -7.730404216e-01, -7.726932294e-01, -7.723654453e-01, -7.719927991e-01, -7.716678543e-01, -7.713114483e-01, -7.709573184e-01, -7.706258081e-01, -7.702478002e-01, -7.698687080e-01, -7.695251481e-01, -7.691743927e-01, -7.687920230e-01, -7.684085525e-01, -7.680239772e-01, -7.676802695e-01, -7.673186342e-01, -7.669307195e-01, -7.665416833e-01, -7.661515213e-01, -7.657602294e-01, -7.653678032e-01, -7.649742384e-01, -7.645795309e-01, -7.641836761e-01, -7.637866699e-01, -7.633885078e-01, -7.629448462e-01, -7.625215598e-01, -7.621199038e-01, -7.617170742e-01, -7.613130666e-01, -7.609078765e-01, -7.604470611e-01, -7.600267923e-01, -7.596180277e-01, -7.591798546e-01, -7.587297533e-01, -7.583057924e-01, -7.578366395e-01, -7.574218256e-01, -7.569507065e-01, -7.565213829e-01, -7.560626842e-01, -7.556160071e-01, -7.551690024e-01, -7.546864562e-01, -7.542024788e-01, -7.537170644e-01, -7.532302077e-01, -7.528027601e-01, -7.523192834e-01, -7.518280659e-01, -7.513353835e-01, -7.508412305e-01, -7.503456012e-01, -7.498484898e-01, -7.493266103e-01, -7.487826590e-01, -7.482810667e-01, -7.477779689e-01, -7.472733600e-01, -7.467652072e-01, -7.461941019e-01, -7.456832677e-01, -7.451138624e-01, -7.445931611e-01, -7.440266878e-01, -7.434968657e-01, -7.429325234e-01, -7.423943327e-01, -7.418313138e-01, -7.412444804e-01, -7.406558646e-01, -7.401032167e-01, -7.395403968e-01, -7.389463918e-01, -7.383505760e-01, -7.377529424e-01, -7.371534835e-01, -7.365521922e-01, -7.359164372e-01, -7.352769442e-01, -7.346701115e-01, -7.340279306e-01, -7.333837140e-01, -7.327712731e-01, -7.321207296e-01, -7.314735915e-01, -7.308163854e-01, -7.301274694e-01, -7.294364257e-01, -7.287882326e-01, -7.281150592e-01, -7.274175804e-01, -7.267179392e-01, -7.260161269e-01, -7.253121346e-01, -7.245433554e-01, -7.238304359e-01, -7.231198503e-01, -7.223998291e-01, -7.216248844e-01, -7.208914534e-01, -7.201000003e-01, -7.193320895e-01, -7.185767906e-01, -7.177778750e-01, -7.169764513e-01, -7.161725094e-01, -7.153660388e-01, -7.145570291e-01, -7.137449470e-01, -7.128642118e-01, -7.120330208e-01, -7.111611116e-01, -7.103098306e-01, -7.094476434e-01, -7.085752828e-01, -7.076701508e-01, -7.067621439e-01, -7.058512500e-01, -7.049247176e-01, -7.039536145e-01, -7.030339872e-01, -7.021114243e-01, -7.011346950e-01, -7.001288515e-01, -6.991197876e-01, -6.981074898e-01, -6.970919444e-01, -6.960731378e-01, -6.950510562e-01, -6.939647296e-01, -6.929240663e-01, -6.918126924e-01, -6.906977314e-01, -6.896224810e-01, -6.885241260e-01, -6.873958444e-01, -6.861857061e-01, -6.850014461e-01, -6.838207742e-01, -6.825988082e-01, -6.813728658e-01, -6.801634307e-01, -6.789404973e-01, -6.776199915e-01, -6.762951709e-01, -6.749660168e-01, -6.736325107e-01, -6.722946336e-01, -6.710172793e-01, -6.695760863e-01, -6.680882024e-01, -6.666479296e-01, -6.652029113e-01, -6.637345691e-01, -6.622314162e-01, -6.607163474e-01, -6.590913286e-01, -6.574762575e-01, -6.558692444e-01, -6.542164425e-01, -6.526252869e-01, -6.509218125e-01, -6.491646005e-01, -6.473343917e-01, -6.455298669e-01, -6.437234352e-01, -6.418635584e-01, -6.399874579e-01, -6.380484328e-01, -6.359903535e-01, -6.339502225e-01, -6.318994524e-01, -6.298253080e-01, -6.277805089e-01, -6.255494421e-01, -6.231880202e-01, -6.208859795e-01, -6.185718779e-01, -6.161913475e-01, -6.138658244e-01, -6.112866531e-01, -6.086230422e-01, -6.059649646e-01, -6.032586056e-01, -6.006093891e-01, -5.978351442e-01, -5.948375985e-01, -5.917787601e-01, -5.886749459e-01, -5.855624502e-01, -5.824720214e-01, -5.792039620e-01, -5.756289648e-01, -5.720186264e-01, -5.683958312e-01, -5.647605217e-01, -5.610963737e-01, -5.570782874e-01, -5.528045083e-01, -5.484586279e-01, -5.441600777e-01, -5.398465758e-01, -5.354296542e-01, -5.302779255e-01, -5.251118372e-01, -5.199875762e-01, -5.147816485e-01, -5.095574851e-01, -5.036797201e-01, -4.973872812e-01, -4.911398612e-01, -4.848548947e-01, -4.785328922e-01, -4.717225911e-01, -4.641573244e-01, -4.565345045e-01, -4.489219944e-01, -4.412153602e-01, -4.331930849e-01, -4.241409016e-01, -4.149620747e-01, -4.057737873e-01, -3.965524909e-01, -3.870236272e-01, -3.764596299e-01, -3.656520357e-01, -3.548057075e-01, -3.439397597e-01, -3.329382194e-01, -3.207980391e-01, -3.085723229e-01, -2.963025178e-01, -2.839884095e-01, -2.715018631e-01, -2.581964373e-01, -2.448427879e-01, -2.314406791e-01, -2.179898734e-01, -2.043030259e-01, -1.902675027e-01, -1.760929666e-01, -1.619234702e-01, -1.476554798e-01, -1.332160513e-01, -1.185990395e-01, -1.039283711e-01, -8.920377957e-02, -7.442499652e-02, -5.951902303e-02, -4.456949653e-02, -2.955937273e-02, -1.446543567e-02, 6.269998803e-04, 1.573666648e-02, 3.090245313e-02, 4.612464271e-02, 6.140352002e-02, 7.656642461e-02, 9.172145201e-02, 1.069838459e-01, 1.222442242e-01, 1.374276654e-01, 1.524277539e-01, 1.674575962e-01, 1.825302395e-01, 1.976019004e-01, 2.122380051e-01, 2.267586833e-01, 2.413343176e-01, 2.559651915e-01, 2.700191566e-01, 2.836596887e-01, 2.973523860e-01, 3.110654348e-01, 3.243506365e-01, 3.366929830e-01, 3.490825607e-01, 3.615196165e-01, 3.737281613e-01, 3.844614791e-01, 3.952358436e-01, 4.060514710e-01, 4.166803367e-01, 4.257798396e-01, 4.347723328e-01, 4.438231703e-01, 4.526908965e-01, 4.600437932e-01, 4.672220769e-01, 4.744283423e-01, 4.813203572e-01, 4.864949058e-01, 4.914695247e-01, 4.964633851e-01, 5.010599883e-01, 5.022030681e-01, 5.034015471e-01, 5.046126245e-01, 5.042566986e-01, 4.996887986e-01, 4.950815660e-01, 4.904329245e-01, 4.844355398e-01, 4.769005912e-01, 4.693358805e-01, 4.616930963e-01, 4.530931011e-01, 4.440845815e-01, 4.350396722e-01, 4.257972733e-01, 4.154583206e-01, 4.050094772e-01, 3.944746196e-01, 3.833792894e-01, 3.715038495e-01, 3.595257648e-01, 3.475268050e-01, 3.345121314e-01, 3.212037430e-01, 3.078408032e-01, 2.941626331e-01, 2.797600674e-01, 2.652830811e-01, 2.507464008e-01, 2.356223330e-01, 2.202579180e-01, 2.048301396e-01, 1.891513632e-01, 1.731502936e-01, 1.571092435e-01, 1.409566756e-01, 1.245430102e-01, 1.079707205e-01, 9.139616494e-02, 7.461752374e-02, 5.776866721e-02, 4.081689878e-02, 2.379152544e-02, 6.662410103e-03, -1.053858087e-02, -2.774473210e-02, -4.502360894e-02, -6.237564145e-02, -7.973412446e-02, -9.704415348e-02, -1.144442667e-01, -1.319172955e-01, -1.491810971e-01, -1.665197096e-01, -1.838651823e-01, -2.009746507e-01, -2.180010427e-01, -2.350917902e-01, -2.517892845e-01, -2.682456251e-01, -2.847732085e-01, -3.007676039e-01, -3.163397663e-01, -3.319889307e-01, -3.470009795e-01, -3.613673581e-01, -3.758178355e-01, -3.894313827e-01, -4.024598764e-01, -4.155491115e-01, -4.275805003e-01, -4.391481964e-01, -4.507664584e-01, -4.611942342e-01, -4.714226209e-01, -4.816413244e-01, -4.906136111e-01, -4.995483706e-01, -5.083294115e-01, -5.161975268e-01, -5.240637961e-01, -5.315959253e-01, -5.385344345e-01, -5.454740899e-01, -5.519485586e-01, -5.581012417e-01, -5.642815458e-01, -5.698841656e-01, -5.753690758e-01, -5.807157085e-01, -5.856354255e-01, -5.905649652e-01, -5.952297484e-01, -5.995807193e-01, -6.039642575e-01, -6.078930409e-01, -6.117829790e-01, -6.154006503e-01, -6.186400422e-01, -6.219169818e-01, -6.243672715e-01, -6.266345668e-01, -6.279983539e-01, -6.274904632e-01, -6.270002921e-01, -6.226824919e-01, -6.174747455e-01, -6.117159004e-01, -6.048799875e-01, -5.979831000e-01, -5.901641657e-01, -5.822211418e-01, -5.735496776e-01, -5.641731566e-01, -5.545211163e-01, -5.433928009e-01, -5.322065124e-01, -5.192044499e-01, -5.057139554e-01, -4.908042754e-01, -4.743147968e-01, -4.571229541e-01, -4.370268507e-01, -4.167148453e-01, -3.931093165e-01, -3.688664938e-01, -3.421732156e-01, -3.141158323e-01, -2.847489177e-01, -2.536973370e-01, -2.220665016e-01, -1.889564547e-01, -1.555800210e-01, -1.213242465e-01, -8.685672603e-02, -5.183668501e-02, -1.666517200e-02, 1.868361461e-02, 5.414382810e-02, 8.953397305e-02, 1.249570820e-01, 1.599964307e-01, 1.947840481e-01, 2.288802660e-01, 2.623422482e-01, 2.946273114e-01, 3.255781921e-01, 3.549916337e-01, 3.824820416e-01, 4.082234716e-01, 4.316935233e-01, 4.533095582e-01, 4.728606755e-01, 4.906425220e-01, 5.067158849e-01, 5.210111073e-01, 5.339753204e-01, 5.448022418e-01, 5.544274597e-01, 5.584685118e-01, 5.605622137e-01, 5.519649684e-01, 5.413629500e-01, 5.280651968e-01, 5.141502331e-01, 4.982160409e-01, 4.811974220e-01, 4.621541072e-01, 4.412120897e-01, 4.185457115e-01, 3.931167232e-01, 3.664233780e-01, 3.364691757e-01, 3.055601231e-01, 2.721616612e-01, 2.377229337e-01, 2.019713012e-01, 1.651505594e-01, 1.276895855e-01, 8.950506743e-02, 5.099269105e-02, 1.206254184e-02, -2.707145084e-02, -6.631734634e-02, -1.055215370e-01, -1.446993334e-01, -1.835209249e-01, -2.216101440e-01, -2.592719612e-01, -2.952091706e-01, -3.297066193e-01, -3.628324654e-01, -3.926787832e-01, -4.208475556e-01, -4.465628739e-01, -4.692594308e-01, -4.904610799e-01, -5.092288937e-01, -5.260465774e-01, -5.417076653e-01, -5.556160008e-01, -5.682175792e-01, -5.799512322e-01, -5.904499713e-01, -5.998332491e-01, -6.082771835e-01, -6.149934423e-01, -6.128644005e-01, -6.062344895e-01, -5.954213994e-01, -5.831088277e-01, -5.696842977e-01, -5.550153416e-01, -5.382626423e-01, -5.192101223e-01, -4.978716957e-01, -4.740481479e-01, -4.455945979e-01, -4.135863407e-01, -3.779761969e-01, -3.383286738e-01, -2.942395483e-01, -2.473309563e-01, -1.982670242e-01, -1.473699292e-01, -9.503612609e-02, -4.191635426e-02, 1.169040579e-02, 6.556624748e-02, 1.194911610e-01, 1.728675945e-01, 2.252565586e-01, 2.759562532e-01, 3.242534737e-01, 3.692692796e-01, 4.093092911e-01, 4.447306036e-01, 4.759107828e-01, 5.031961145e-01, 5.269959597e-01, 5.478147411e-01, 5.658544582e-01, 5.816465879e-01, 5.947954816e-01, 5.940417154e-01, 5.809315402e-01, 5.647958462e-01, 5.461374917e-01, 5.248193699e-01, 5.000336674e-01, 4.711684823e-01, 4.374751373e-01, 3.983334630e-01, 3.534903566e-01, 3.032419651e-01, 2.485508826e-01, 1.902596944e-01, 1.298385802e-01, 6.763823143e-02, 4.766845703e-03, -5.843010954e-02, -1.203677791e-01, -1.811078897e-01, -2.393462251e-01, -2.944894778e-01, -3.451117489e-01, -3.905345840e-01, -4.302707288e-01, -4.645489024e-01, -4.940017162e-01, -5.192033359e-01, -5.409884063e-01, -5.598734888e-01, -5.764982109e-01, -5.909733692e-01, -5.948560496e-01, -5.865611621e-01, -5.718793082e-01, -5.552405607e-01, -5.364485932e-01, -5.149980409e-01, -4.901381290e-01, -4.618992472e-01, -4.299953818e-01, -3.941424865e-01, -3.540433456e-01, -3.094774792e-01, -2.625054822e-01, -2.135437573e-01, -1.631899831e-01, -1.119898251e-01, -6.055278277e-02, -9.225035736e-03, 4.178118740e-02, 9.235149431e-02, 1.418668884e-01, 1.904108536e-01, 2.377385028e-01, 2.822324748e-01, 3.242810100e-01, 3.637179501e-01, 3.990482164e-01, 4.303219376e-01, 4.587339504e-01, 4.837248784e-01, 5.051305646e-01, 5.244711334e-01, 5.418954264e-01, 5.568256822e-01, 5.705964720e-01, 5.831873391e-01, 5.942663514e-01, 6.045855627e-01, 6.138985578e-01, 6.141910357e-01, 6.112865888e-01, 6.040521284e-01, 5.957247300e-01, 5.868289882e-01, 5.766599936e-01, 5.657696636e-01, 5.542582241e-01, 5.410362405e-01, 5.271954158e-01, 5.118204624e-01, 4.949505701e-01, 4.769183160e-01, 4.562966690e-01, 4.347816898e-01, 4.102802256e-01, 3.843900239e-01, 3.566782702e-01, 3.267343219e-01, 2.959366865e-01, 2.632140585e-01, 2.302177991e-01, 1.957706689e-01, 1.613027485e-01, 1.265065333e-01, 9.151827902e-02, 5.641184893e-02, 2.154507742e-02, -1.313832659e-02, -4.774229658e-02, -8.219189298e-02, -1.158772683e-01, -1.493528314e-01, -1.821006001e-01, -2.145700329e-01, -2.454620264e-01, -2.759943386e-01, -3.047094546e-01, -3.328940700e-01, -3.584468087e-01, -3.835084498e-01, -4.057325148e-01, -4.275604213e-01, -4.463697439e-01, -4.648074574e-01, -4.806656995e-01, -4.962736860e-01, -5.096459000e-01, -5.226920231e-01, -5.341958836e-01, -5.451747614e-01, -5.530448163e-01, -5.591295028e-01, -5.600327757e-01, -5.550211130e-01, -5.488445415e-01, -5.394323437e-01, -5.299425822e-01, -5.180005294e-01, -5.060835331e-01, -4.919617783e-01, -4.772806742e-01, -4.610796806e-01, -4.434178938e-01, -4.251444511e-01, -4.039695084e-01, -3.828604018e-01, -3.591421124e-01, -3.349474445e-01, -3.094490699e-01, -2.824521875e-01, -2.554445310e-01, -2.269486061e-01, -1.985284892e-01, -1.694469411e-01, -1.399641858e-01, -1.105981990e-01, -8.096796820e-02, -5.151979237e-02, -2.193903502e-02, 7.596210986e-03, 3.696304515e-02, 6.600677284e-02, 9.489151706e-02, 1.234815687e-01, 1.517394568e-01, 1.799002016e-01, 2.069534065e-01, 2.337832792e-01, 2.600296173e-01, 2.850156596e-01, 3.098350150e-01, 3.330419594e-01, 3.550461706e-01, 3.768392133e-01, 3.960994977e-01, 4.148130904e-01, 4.330731301e-01, 4.485258600e-01, 4.638169360e-01, 4.783035534e-01, 4.909148607e-01, 5.033992846e-01, 5.148643757e-01, 5.251025306e-01, 5.352745120e-01, 5.444893236e-01, 5.529662118e-01, 5.614587793e-01, 5.690110722e-01, 5.761265291e-01, 5.832071876e-01, 5.896133427e-01, 5.956521380e-01, 6.016746176e-01, 6.071525488e-01, 6.123086901e-01, 6.174145988e-01, 6.212540922e-01, 6.242713771e-01, 6.272741271e-01, 6.284420955e-01, 6.278094678e-01, 6.271130450e-01, 6.259359137e-01, 6.237785265e-01, 6.216641886e-01, 6.194812618e-01, 6.167179480e-01, 6.139433003e-01, 6.111813477e-01, 6.080512873e-01, 6.048419148e-01, 6.016863881e-01, 5.982985926e-01, 5.946894237e-01, 5.910861340e-01, 5.874111504e-01, 5.834106226e-01, 5.794392343e-01, 5.754862830e-01, 5.710789993e-01, 5.666012343e-01, 5.621597948e-01, 5.575676475e-01, 5.525603276e-01, 5.476071290e-01, 5.426890743e-01, 5.371486597e-01, 5.315600537e-01, 5.259894644e-01, 5.202041457e-01, 5.138723909e-01, 5.076056181e-01, 5.013468581e-01, 4.944268812e-01, 4.872415499e-01, 4.800875853e-01, 4.728713209e-01, 4.648472764e-01, 4.567504693e-01, 4.486332484e-01, 4.403451927e-01, 4.310920615e-01, 4.219156392e-01, 4.127175703e-01, 4.031194333e-01, 3.928414377e-01, 3.826741822e-01, 3.724830923e-01, 3.616697075e-01, 3.504026428e-01, 3.391933498e-01, 3.280098649e-01, 3.163277496e-01, 3.043201031e-01, 2.923623544e-01, 2.804541684e-01, 2.680701589e-01, 2.555127568e-01, 2.429405140e-01, 2.304862419e-01, 2.178134120e-01, 2.049269600e-01, 1.921594285e-01, 1.794439439e-01, 1.665898904e-01, 1.535885908e-01, 1.406340314e-01, 1.277315409e-01, 1.148340501e-01, 1.019053895e-01, 8.902829794e-02, 7.620243906e-02, 6.340379520e-02, 5.053550932e-02, 3.768412916e-02, 2.493257130e-02, 1.216612313e-02, -4.845009750e-04, -1.308568026e-02, -2.570487127e-02, -3.820811196e-02, -5.066285370e-02, -6.306940665e-02, -7.549521713e-02, -8.780631293e-02, -1.000701354e-01, -1.122049137e-01, -1.242534391e-01, -1.361912088e-01, -1.481493348e-01, -1.600137077e-01, -1.716440791e-01, -1.832305718e-01, -1.948405999e-01, -2.063401592e-01, -2.176356999e-01, -2.286417885e-01, -2.396159830e-01, -2.505709440e-01, -2.614408244e-01, -2.719628702e-01, -2.822519966e-01, -2.925032664e-01, -3.026610904e-01, -3.127914148e-01, -3.223370553e-01, -3.316534920e-01, -3.409360766e-01, -3.501850161e-01, -3.594005162e-01, -3.678483127e-01, -3.761156901e-01, -3.843533995e-01, -3.925885005e-01, -4.007960910e-01, -4.080988658e-01, -4.152623702e-01, -4.224333258e-01, -4.295603169e-01, -4.366469524e-01, -4.430281618e-01, -4.491983047e-01, -4.552922304e-01, -4.614067857e-01, -4.675125191e-01, -4.728791881e-01, -4.778597960e-01, -4.827562775e-01, -4.876358719e-01, -4.924986788e-01, -4.964730069e-01, -4.984253696e-01, -5.003039264e-01, -5.022429938e-01, -5.041526291e-01, -5.059771922e-01, -5.043394045e-01, -5.023257822e-01, -5.003189353e-01, -4.983188244e-01, -4.963254104e-01, -4.933688094e-01, -4.892635562e-01, -4.851692389e-01, -4.810555034e-01, -4.769384397e-01, -4.728167645e-01, -4.675591104e-01, -4.620266529e-01, -4.565123144e-01, -4.510159914e-01, -4.455375811e-01, -4.397712998e-01, -4.331210932e-01, -4.263632865e-01, -4.196272891e-01, -4.129129778e-01, -4.062202298e-01, -3.990698697e-01, -3.911086197e-01, -3.831721066e-01, -3.751949830e-01, -3.673094508e-01, -3.594384712e-01, -3.510851143e-01, -3.420793998e-01, -3.331019802e-01, -3.241526980e-01, -3.152313969e-01, -3.063379218e-01, -2.970179870e-01, -2.872765146e-01, -2.775007078e-01, -2.677741287e-01, -2.580362646e-01, -2.483921622e-01, -2.384860291e-01, -2.282598429e-01, -2.180212506e-01, -2.078138285e-01, -1.976374067e-01, -1.874246779e-01, -1.772390804e-01, -1.668153873e-01, -1.563203976e-01, -1.458047934e-01, -1.353800993e-01, -1.249865354e-01, -1.146079937e-01, -1.041224247e-01, -9.361803352e-02, -8.310763615e-02, -7.261333915e-02, -6.214993171e-02, -5.171724915e-02, -4.131099675e-02, -3.085563149e-02, -2.039385187e-02, -9.969045156e-03, 3.969106622e-04, 1.079690176e-02, 2.113384955e-02, 3.144347914e-02, 4.175109739e-02, 5.198166036e-02, 6.222583193e-02, 7.242171741e-02, 8.257942810e-02, 9.274518634e-02, 1.028059189e-01, 1.127937512e-01, 1.227701295e-01, 1.327276545e-01, 1.426225537e-01, 1.525407760e-01, 1.623435837e-01, 1.720281529e-01, 1.815952834e-01, 1.911571522e-01, 2.006484742e-01, 2.101693198e-01, 2.196185196e-01, 2.290338128e-01, 2.381201357e-01, 2.470594192e-01, 2.559989486e-01, 2.649141474e-01, 2.738051386e-01, 2.826720445e-01, 2.914490247e-01, 2.998229878e-01, 3.078854107e-01, 3.159600267e-01, 3.240293935e-01, 3.320104087e-01, 3.400369431e-01, 3.480183370e-01, 3.556149076e-01, 3.626820130e-01, 3.697045661e-01, 3.766845967e-01, 3.836840650e-01, 3.906140278e-01, 3.975851057e-01, 4.043719545e-01, 4.105146388e-01, 4.164174251e-01, 4.223049116e-01, 4.281436002e-01, 4.339671453e-01, 4.398091792e-01, 4.456362093e-01, 4.510762929e-01, 4.560270737e-01, 4.608814797e-01, 4.657235322e-01, 4.705559341e-01, 4.754379530e-01, 4.802433007e-01, 4.849836151e-01, 4.893687291e-01, 4.933664145e-01, 4.973540874e-01, 5.013317956e-01, 5.052995865e-01, 5.092575071e-01, 5.131738438e-01, 5.170430705e-01, 5.206187454e-01, 5.239188753e-01, 5.272108878e-01, 5.304948210e-01, 5.337707129e-01, 5.370386012e-01, 5.402985231e-01, 5.435505159e-01, 5.464885748e-01, 5.492528675e-01, 5.520104814e-01, 5.547173659e-01, 5.574386579e-01, 5.601764204e-01, 5.629076267e-01, 5.656323070e-01, 5.681431619e-01, 5.704837159e-01, 5.728324128e-01, 5.751641578e-01, 5.774626299e-01, 5.797905891e-01, 5.821104776e-01, 5.843927636e-01, 5.866114706e-01, 5.886726382e-01, 5.906396913e-01, 5.926423304e-01, 5.946403188e-01, 5.966336773e-01, 5.986089795e-01, 6.005394487e-01, 6.025049759e-01, 6.043489933e-01, 6.061287838e-01, 6.078411150e-01, 6.095495377e-01, 6.112540692e-01, 6.130061549e-01, 6.147186657e-01, 6.164116261e-01, 6.180626436e-01, 6.196521540e-01, 6.211805951e-01, 6.226719440e-01, 6.241783572e-01, 6.257117765e-01, 6.271931504e-01, 6.286712281e-01, 6.301460238e-01, 6.316753367e-01, 6.330493157e-01, 6.343465350e-01, 6.356651161e-01, 6.370021627e-01, 6.383362773e-01, 6.396674726e-01, 6.409957609e-01, 6.423211545e-01, 6.436436658e-01, 6.448446832e-01, 6.460417587e-01, 6.472362468e-01, 6.484281584e-01, 6.495881062e-01, 6.507371568e-01, 6.519214036e-01, 6.531031168e-01, 6.542823069e-01, 6.554027100e-01, 6.564703319e-01, 6.575248470e-01, 6.585771286e-01, 6.596271860e-01, 6.606879123e-01, 6.617878032e-01, 6.628312424e-01, 6.638724937e-01, 6.649115659e-01, 6.658813312e-01, 6.668250158e-01, 6.678002376e-01, 6.687691839e-01, 6.696832359e-01, 6.706466479e-01, 6.716138191e-01, 6.725789978e-01, 6.735220315e-01, 6.744171428e-01, 6.752635388e-01, 6.761633674e-01, 6.770182857e-01, 6.778926750e-01, 6.787661665e-01, 6.796146876e-01, 6.805065455e-01, 6.813416622e-01, 6.822177228e-01, 6.830410301e-01, 6.838151346e-01, 6.845954669e-01, 6.854215441e-01, 6.861952952e-01, 6.870016143e-01, 6.877967656e-01, 6.885616443e-01, 6.893258819e-01, 6.901421504e-01, 6.908718751e-01, 6.916060475e-01, 6.923469112e-01, 6.930521238e-01, 6.938065045e-01, 6.945155443e-01, 6.952437018e-01, 6.959768388e-01, 6.966750354e-01, 6.974220863e-01, 6.980824182e-01, 6.987489175e-01, 6.994385847e-01, 7.001265478e-01, 7.007607109e-01, 7.014324812e-01, 7.020925217e-01, 7.027327761e-01, 7.034145305e-01, 7.040949830e-01, 7.047416512e-01, 7.053673708e-01, 7.059919017e-01, 7.066152482e-01, 7.072374146e-01, 7.078347434e-01, 7.084110856e-01, 7.090297372e-01, 7.096472256e-01, 7.102635549e-01, 7.108787293e-01, 7.114927530e-01, 7.120581311e-01, 7.126188874e-01, 7.131786000e-01, 7.137372726e-01, 7.142949087e-01, 7.148843998e-01, 7.154742248e-01, 7.160287734e-01, 7.165823000e-01, 7.171348081e-01, 7.176863012e-01, 7.182367829e-01, 7.187374617e-01, 7.192675873e-01, 7.198150556e-01, 7.203615263e-01, 7.208607251e-01, 7.213843496e-01, 7.219169399e-01, 7.224101345e-01, 7.229447564e-01, 7.234609905e-01, 7.239515192e-01, 7.244411653e-01, 7.249299316e-01, 7.254178212e-01, 7.259048369e-01, 7.263909816e-01, 7.269064135e-01, 7.274278085e-01, 7.279113576e-01, 7.283940472e-01, 7.288538927e-01, 7.292897205e-01, 7.297698484e-01, 7.302491280e-01, 7.307151085e-01, 7.311449405e-01, 7.316147654e-01, 7.320694773e-01, 7.324986192e-01, 7.329728659e-01, 7.334170847e-01, 7.338517352e-01, 7.343235017e-01, 7.347579952e-01, 7.351811086e-01, 7.356034874e-01, 7.360251337e-01, 7.364460500e-01, 7.368683845e-01, 7.373344544e-01, 7.377715797e-01, 7.381895983e-01, 7.386068981e-01, 7.390234813e-01, 7.394393502e-01, 7.398545069e-01, 7.402318813e-01, 7.406155539e-01, 7.410285871e-01, 7.414409168e-01, 7.418334744e-01, 7.421987447e-01, 7.426065675e-01, 7.430161044e-01, 7.434249483e-01, 7.438331013e-01, 7.442172539e-01, 7.445788339e-01, 7.449398051e-01, 7.453245681e-01, 7.457270675e-01, 7.460862236e-01, 7.464447781e-01, 7.468051436e-01, 7.472071700e-01, 7.475839889e-01, 7.479401549e-01, 7.482957282e-01, 7.486507103e-01, 7.490051031e-01, 7.493589081e-01, 7.497121272e-01, 7.500647620e-01, 7.504168141e-01, 7.507682852e-01, 7.511191769e-01, 7.515097447e-01, 7.518863675e-01, 7.522355310e-01, 7.525841216e-01, 7.529188643e-01, 7.532228828e-01, 7.535593337e-01, 7.539056489e-01, 7.542513991e-01, 7.545682774e-01, 7.548740723e-01, 7.552181371e-01, 7.555616432e-01, 7.559045920e-01, 7.562054003e-01, 7.565216854e-01, 7.568629717e-01, 7.572037068e-01, 7.575332177e-01, 7.578304002e-01, 7.581554810e-01, 7.584904699e-01, 7.587862210e-01, 7.590814975e-01, 7.593763006e-01, 7.597085051e-01, 7.600316306e-01, 7.603250212e-01, 7.606472785e-01, 7.609775371e-01, 7.612695262e-01, 7.615610506e-01, 7.618521115e-01, 7.621427101e-01, 7.624328475e-01, 7.627225250e-01, 7.630117438e-01, 7.633005049e-01, 7.635888096e-01, 7.638919631e-01, 7.642204149e-01, 7.645181355e-01, 7.648046261e-01, 7.650906660e-01, 7.653762564e-01, 7.656613984e-01, 7.659460930e-01, 7.662240818e-01, 7.664673418e-01, 7.667303656e-01, 7.670132822e-01, 7.672957569e-01, 7.675777910e-01, 7.678593854e-01, 7.681405413e-01, 7.684212597e-01, 7.687015417e-01, 7.689753627e-01, 7.692148589e-01, 7.694726410e-01, 7.697511878e-01, 7.700293035e-01, 7.703034166e-01, 7.705410649e-01, 7.707939349e-01, 7.710703361e-01, 7.713463112e-01, 7.716218613e-01, 7.718580970e-01, 7.721045514e-01, 7.723788322e-01, 7.726305300e-01, 7.728649068e-01, 7.731320133e-01, 7.733997221e-01, 7.736330235e-01, 7.738814307e-01, 7.741527842e-01, 7.743979292e-01, 7.746298085e-01, 7.748613342e-01, 7.750997870e-01, 7.753690783e-01, 7.756209369e-01, 7.758510565e-01, 7.761073592e-01, 7.763750174e-01, 7.766064599e-01, 7.768351860e-01, 7.770635658e-01, 7.772915998e-01, 7.775192890e-01, 7.777466340e-01, 7.779736356e-01, 7.782331889e-01, 7.784937505e-01, 7.787197266e-01, 7.789453623e-01, 7.791706584e-01, 7.793956155e-01, 7.796202345e-01, 7.798445161e-01, 7.800684610e-01, 7.802920699e-01, 7.805153436e-01, 7.807382827e-01, 7.809608880e-01, 7.811831602e-01, 7.814051000e-01, 7.816267080e-01, 7.818479851e-01, 7.820689319e-01, 7.822895491e-01, 7.825098373e-01, 7.827297973e-01, 7.829494298e-01, 7.831687354e-01, 7.833877149e-01, 7.836063688e-01, 7.838246979e-01, 7.840427028e-01, 7.842603843e-01, 7.844777429e-01, 7.846648796e-01, 7.848454753e-01, 7.850607496e-01, 7.852768235e-01, 7.854925778e-01, 7.857080132e-01, 7.859231304e-01, 7.861379299e-01, 7.863524124e-01, 7.865492159e-01, 7.867274246e-01, 7.869268258e-01, 7.871400468e-01, 7.873529539e-01, 7.875655478e-01, 7.877488175e-01, 7.879254586e-01, 7.881343177e-01, 7.883451016e-01, 7.885209659e-01, 7.887002909e-01, 7.889107096e-01, 7.891208199e-01, 7.893306225e-01, 7.895307054e-01, 7.897050295e-01, 7.898910511e-01, 7.900996288e-01, 7.902936127e-01, 7.904669199e-01, 7.906563967e-01, 7.908637588e-01, 7.910524642e-01, 7.912247624e-01, 7.914168939e-01, 7.916230497e-01, 7.918072908e-01, 7.919785875e-01, 7.921725796e-01, 7.923775381e-01, 7.925581229e-01, 7.927284257e-01, 7.928984811e-01, 7.930682896e-01, 7.932635959e-01, 7.934667753e-01, 7.936433773e-01, 7.938122029e-01, 7.939807840e-01, 7.941491209e-01, 7.943439871e-01, 7.945454071e-01, 7.947198100e-01, 7.948871749e-01, 7.950542979e-01, 7.952211793e-01, 7.953878198e-01, 7.955542197e-01, 7.957458029e-01, 7.959449069e-01, 7.961191187e-01, 7.962845605e-01, 7.964497639e-01, 7.966147293e-01, 7.967794572e-01, 7.969439478e-01, 7.971082018e-01, 7.972722194e-01, 7.974554279e-01, 7.976516835e-01, 7.978299973e-01, 7.979930739e-01, 7.981559162e-01, 7.983185248e-01, 7.984809000e-01, 7.986430421e-01, 7.988049517e-01, 7.989666291e-01, 7.991280748e-01, 7.992892890e-01, 7.994502724e-01, 7.996110251e-01, 7.997715477e-01, 7.999318406e-01, 8.000919041e-01, 8.002517386e-01, 8.004113445e-01, 8.005707223e-01, 8.007298723e-01, 8.008887949e-01, 8.010474904e-01, 8.012059594e-01, 8.013642022e-01, 8.015222191e-01, 8.016800105e-01, 8.018375769e-01, 8.019949185e-01, 8.021520359e-01, 8.023089293e-01, 8.024655992e-01, 8.026220459e-01, 8.027782698e-01, 8.029342713e-01, 8.030900507e-01, 8.032456085e-01, 8.034009449e-01, 8.035345456e-01, 8.036584616e-01, 8.037984915e-01, 8.039529464e-01, 8.041071819e-01, 8.042611983e-01, 8.044149959e-01, 8.045685752e-01, 8.047219364e-01, 8.048750800e-01, 8.050280063e-01, 8.051565355e-01, 8.052785297e-01, 8.054183464e-01, 8.055704072e-01, 8.057222524e-01, 8.058738825e-01, 8.060252978e-01, 8.061764986e-01, 8.063274853e-01, 8.064496965e-01, 8.065701441e-01, 8.067120257e-01, 8.068621596e-01, 8.070120810e-01, 8.071617905e-01, 8.073041087e-01, 8.074235379e-01, 8.075427982e-01, 8.076913763e-01, 8.078400308e-01, 8.079884753e-01, 8.081367103e-01, 8.082708551e-01, 8.083891085e-01, 8.085130219e-01, 8.086604217e-01, 8.088076135e-01, 8.089545977e-01, 8.091013746e-01, 8.092294104e-01, 8.093465010e-01, 8.094733263e-01, 8.096192774e-01, 8.097639226e-01, 8.098803547e-01, 8.099966228e-01, 8.101338900e-01, 8.102788161e-01, 8.104235383e-01, 8.105680567e-01, 8.107097901e-01, 8.108250797e-01, 8.109402072e-01, 8.110769615e-01, 8.112204664e-01, 8.113517578e-01, 8.114662391e-01, 8.115826330e-01, 8.117253327e-01, 8.118678319e-01, 8.119896965e-01, 8.121033759e-01, 8.122168955e-01, 8.123302558e-01, 8.124434570e-01, 8.125843570e-01, 8.127254615e-01, 8.128492467e-01, 8.129618138e-01, 8.130804495e-01, 8.132207639e-01, 8.133608815e-01, 8.134776441e-01, 8.135894240e-01, 8.137129181e-01, 8.138522516e-01, 8.139909635e-01, 8.141021183e-01, 8.142131173e-01, 8.143239608e-01, 8.144346491e-01, 8.145498863e-01, 8.146878595e-01, 8.148256396e-01, 8.149429936e-01, 8.150529093e-01, 8.151626713e-01, 8.152722797e-01, 8.153817348e-01, 8.155140036e-01, 8.156504400e-01, 8.157763212e-01, 8.158851654e-01, 8.159938575e-01, 8.161023976e-01, 8.162107861e-01, 8.163307857e-01, 8.164658929e-01, 8.166008115e-01, 8.167099665e-01, 8.168176000e-01, 8.169250833e-01, 8.170324166e-01, 8.171396000e-01, 8.172720984e-01, 8.174057039e-01, 8.175273922e-01, 8.176339786e-01, 8.177404163e-01, 8.178467056e-01, 8.179528467e-01, 8.180588397e-01, 8.181646850e-01, 8.182703827e-01, 8.183759331e-01, 8.184813364e-01, 8.185945692e-01, 8.187259564e-01, 8.188571606e-01, 8.189686218e-01, 8.190732930e-01, 8.191778184e-01, 8.192821982e-01, 8.193864328e-01, 8.194905223e-01, 8.195944668e-01, 8.196982668e-01, 8.198019223e-01, 8.199054336e-01, 8.200088009e-01, 8.201120244e-01, 8.202151043e-01, 8.203392626e-01, 8.204677545e-01, 8.205906237e-01, 8.206931316e-01, 8.207954971e-01, 8.208977203e-01, 8.209998014e-01, 8.211017407e-01, 8.212035384e-01, 8.213051948e-01, 8.214067099e-01, 8.215080841e-01, 8.216093175e-01, 8.217104104e-01, 8.218113630e-01, 8.219121754e-01, 8.220128480e-01, 8.221133809e-01, 8.222137743e-01, 8.223140284e-01, 8.224141435e-01, 8.225141197e-01, 8.226139573e-01, 8.227136565e-01, 8.228132175e-01, 8.229126404e-01, 8.230119256e-01, 8.231110732e-01, 8.232100834e-01, 8.233089564e-01, 8.234076925e-01, 8.235062918e-01, 8.236047546e-01, 8.237030810e-01, 8.238012713e-01, 8.238993257e-01, 8.239972444e-01, 8.240950275e-01, 8.241926753e-01, 8.242901881e-01, 8.243875659e-01, 8.244848090e-01, 8.245819176e-01, 8.246788920e-01, 8.247757322e-01, 8.248724386e-01, 8.249690113e-01, 8.250654505e-01, 8.251617564e-01, 8.252579293e-01, 8.253539692e-01, 8.254498766e-01, 8.255456514e-01, 8.256412940e-01, 8.257368045e-01, 8.258321831e-01, 8.259274301e-01, 8.260225456e-01, 8.261175298e-01, 8.262123830e-01, 8.263071053e-01, 8.264016969e-01, 8.264961580e-01, 8.265904889e-01, 8.266846897e-01, 8.267787606e-01, 8.268727018e-01, 8.269665135e-01, 8.270601959e-01, 8.271537493e-01, 8.272471737e-01, 8.273260308e-01, 8.273959062e-01, 8.274656854e-01, 8.275524477e-01, 8.276452305e-01, 8.277378857e-01, 8.278304133e-01, 8.279228135e-01, 8.280150866e-01, 8.281072328e-01, 8.281992522e-01, 8.282911450e-01, 8.283829114e-01, 8.284745517e-01, 8.285641369e-01, 8.286326782e-01, 8.287011253e-01, 8.287727160e-01, 8.288637282e-01, 8.289546154e-01, 8.290453777e-01, 8.291360154e-01, 8.292265286e-01, 8.293169176e-01, 8.294071824e-01, 8.294973233e-01, 8.295873406e-01, 8.296772343e-01, 8.297670047e-01, 8.298509851e-01, 8.299181283e-01, 8.299851794e-01, 8.300577180e-01, 8.301468746e-01, 8.302359089e-01, 8.303248213e-01, 8.304136118e-01, 8.305022806e-01, 8.305908280e-01, 8.306792542e-01, 8.307675592e-01, 8.308520736e-01, 8.309181212e-01, 8.309840783e-01, 8.310524335e-01, 8.311401358e-01, 8.312277182e-01, 8.313151808e-01, 8.314025238e-01, 8.314897474e-01, 8.315768517e-01, 8.316638369e-01, 8.317507033e-01, 8.318374510e-01, 8.319050962e-01, 8.319699793e-01, 8.320347738e-01, 8.321161196e-01, 8.322022766e-01, 8.322883159e-01, 8.323742377e-01, 8.324600424e-01, 8.325457300e-01, 8.326201430e-01, 8.326842334e-01, 8.327482365e-01, 8.328201745e-01, 8.329052795e-01, 8.329902684e-01, 8.330751416e-01, 8.331598991e-01, 8.332445412e-01, 8.333280998e-01, 8.333914086e-01, 8.334546312e-01, 8.335177677e-01, 8.335988873e-01, 8.336828405e-01, 8.337666793e-01, 8.338504042e-01, 8.339340152e-01, 8.340175125e-01, 8.340916025e-01, 8.341540553e-01, 8.342164233e-01, 8.342832299e-01, 8.343661615e-01, 8.344489804e-01, 8.345316869e-01, 8.345941337e-01, 8.346559953e-01, 8.347177729e-01, 8.347942532e-01, 8.348764000e-01, 8.349584354e-01, 8.350403596e-01, 8.351221728e-01, 8.352038750e-01, 8.352821541e-01, 8.353432649e-01, 8.354042928e-01, 8.354652381e-01, 8.355435903e-01, 8.356246308e-01, 8.357055616e-01, 8.357753341e-01, 8.358358681e-01, 8.358963202e-01, 8.359610528e-01, 8.360414378e-01, 8.361217141e-01, 8.362018819e-01, 8.362644956e-01, 8.363244591e-01, 8.363843416e-01, 8.364543329e-01, 8.365339608e-01, 8.366134811e-01, 8.366902029e-01, 8.367496823e-01, 8.368090815e-01, 8.368684007e-01, 8.369423381e-01, 8.370212171e-01, 8.370999898e-01, 8.371720172e-01, 8.372309376e-01, 8.372897787e-01, 8.373485406e-01, 8.374251259e-01, 8.375032643e-01, 8.375812975e-01, 8.376499369e-01, 8.377083045e-01, 8.377665936e-01, 8.378252436e-01, 8.379027536e-01, 8.379801594e-01, 8.380574612e-01, 8.381240046e-01, 8.381818254e-01, 8.382395685e-01, 8.382984931e-01, 8.383752774e-01, 8.384519587e-01, 8.385285372e-01, 8.385942626e-01, 8.386515426e-01, 8.387087457e-01, 8.387666870e-01, 8.388427537e-01, 8.389187184e-01, 8.389945814e-01, 8.390607528e-01, 8.391174978e-01, 8.391741670e-01, 8.392307603e-01, 8.393052378e-01, 8.393804938e-01, 8.394556493e-01, 8.395235166e-01, 8.395797327e-01, 8.396358737e-01, 8.396919397e-01, 8.397479309e-01, 8.398038473e-01, 8.398596891e-01, 8.399190136e-01, 8.399932709e-01, 8.400674291e-01, 8.401414885e-01, 8.402049219e-01, 8.402603185e-01, 8.403156414e-01, 8.403708906e-01, 8.404431696e-01, 8.405166392e-01, 8.405900111e-01, 8.406582916e-01, 8.407131742e-01, 8.407679838e-01, 8.408227206e-01, 8.408882706e-01, 8.409610592e-01, 8.410337511e-01, 8.411063464e-01, 8.411624544e-01, 8.412167565e-01, 8.412709865e-01, 8.413251447e-01, 8.413792310e-01, 8.414332456e-01, 8.414871886e-01, 8.415493758e-01, 8.416211095e-01, 8.416927481e-01, 8.417642919e-01, 8.418229728e-01, 8.418764887e-01, 8.419299339e-01, 8.419833084e-01, 8.420366123e-01, 8.420898458e-01, 8.421430090e-01, 8.421989693e-01, 8.422696664e-01, 8.423402702e-01, 8.424107808e-01, 8.424749125e-01, 8.425276561e-01, 8.425803301e-01, 8.426329347e-01, 8.426854699e-01, 8.427379360e-01, 8.427903329e-01, 8.428426609e-01, 8.429069311e-01, 8.429765182e-01, 8.430460138e-01, 8.431154179e-01, 8.431704085e-01, 8.432223249e-01, 8.432741731e-01, 8.433259531e-01, 8.433776652e-01, 8.434293094e-01, 8.434808858e-01, 8.435331017e-01, 8.436016899e-01, 8.436701883e-01, 8.437385969e-01, 8.438048939e-01, 8.438560660e-01, 8.439071710e-01, 8.439582092e-01, 8.440091806e-01, 8.440600853e-01, 8.441109234e-01, 8.441616950e-01, 8.442124003e-01, 8.442630393e-01, 8.443136122e-01, 8.443641191e-01, 8.444183879e-01, 8.444855547e-01, 8.445526338e-01, 8.446196255e-01, 8.446828051e-01, 8.447329179e-01, 8.447829655e-01, 8.448329478e-01, 8.448828651e-01, 8.449327174e-01, 8.449825048e-01, 8.450322275e-01, 8.450818855e-01, 8.451314789e-01, 8.451810079e-01, 8.452304725e-01, 8.452812043e-01, 8.453469860e-01, 8.454126823e-01, 8.454782934e-01, 8.455438193e-01, 8.455930536e-01, 8.456420708e-01, 8.456910244e-01, 8.457399146e-01, 8.457887415e-01, 8.458375052e-01, 8.458862058e-01, 8.459348434e-01, 8.459834181e-01, 8.460319300e-01, 8.460803792e-01, 8.461287659e-01, 8.461865595e-01, 8.462509085e-01, 8.463151744e-01, 8.463793575e-01, 8.464369024e-01, 8.464849156e-01, 8.465328670e-01, 8.465807565e-01, 8.466285844e-01, 8.466763508e-01, 8.467240556e-01, 8.467716991e-01, 8.468192813e-01, 8.468668023e-01, 8.469142622e-01, 8.469616612e-01, 8.470089993e-01, 8.470562766e-01, 8.471034933e-01, 8.471506494e-01, 8.471977450e-01, 8.472520734e-01, 8.473147067e-01, 8.473772597e-01, 8.474397326e-01, 8.474994579e-01, 8.475461927e-01, 8.475928677e-01, 8.476394830e-01, 8.476860387e-01, 8.477325350e-01, 8.477789718e-01, 8.478253493e-01, 8.478716677e-01, 8.479179269e-01, 8.479641271e-01, 8.480102684e-01, 8.480563509e-01, 8.481023747e-01, 8.481483398e-01, 8.481942464e-01, 8.482400946e-01, 8.482858844e-01, 8.483316160e-01, 8.483772895e-01, 8.484229049e-01, 8.484684624e-01, 8.485191043e-01, 8.485796934e-01, 8.486402056e-01, 8.487006411e-01, 8.487609999e-01, 8.488077341e-01, 8.488528885e-01, 8.488979858e-01, 8.489430259e-01, 8.489880090e-01, 8.490329353e-01, 8.490778047e-01, 8.491226173e-01, 8.491673733e-01, 8.492120728e-01, 8.492567159e-01, 8.493013025e-01, 8.493458329e-01, 8.493903072e-01, 8.494347253e-01, 8.494790875e-01, 8.495233938e-01, 8.495676443e-01, 8.496118390e-01, 8.496559782e-01, 8.497000618e-01, 8.497440900e-01, 8.497880628e-01, 8.498319804e-01, 8.498758428e-01, 8.499196501e-01, 8.499634025e-01, 8.500070999e-01, 8.500507426e-01, 8.500943306e-01, 8.501378639e-01, 8.501813427e-01, 8.502247670e-01, 8.502681370e-01, 8.503114528e-01, 8.503547143e-01, 8.504044231e-01, 8.504619611e-01, 8.505194272e-01, 8.505768215e-01, 8.506341442e-01, 8.506802897e-01, 8.507231745e-01, 8.507660059e-01, 8.508087839e-01, 8.508515086e-01, 8.508941801e-01, 8.509367985e-01, 8.509793639e-01, 8.510218763e-01, 8.510643359e-01, 8.511067427e-01, 8.511490968e-01, 8.511913984e-01, 8.512336474e-01, 8.512758440e-01, 8.513179883e-01, 8.513600803e-01, 8.514021202e-01, 8.514441080e-01, 8.514860439e-01, 8.515279278e-01, 8.515697599e-01, 8.516115403e-01, 8.516532690e-01, 8.516949462e-01, 8.517365719e-01, 8.517781462e-01, 8.518196692e-01, 8.518611409e-01, 8.519025616e-01, 8.519439312e-01, 8.519852498e-01, 8.520265175e-01, 8.520677344e-01, 8.521089006e-01, 8.521500162e-01, 8.521910812e-01, 8.522320958e-01, 8.522730600e-01, 8.523139738e-01, 8.523548375e-01, 8.523956510e-01, 8.524364145e-01, 8.524771280e-01, 8.525177916e-01, 8.525584054e-01, 8.525989694e-01, 8.526394839e-01, 8.526799487e-01, 8.527203641e-01, 8.527607301e-01, 8.528010468e-01, 8.528413142e-01, 8.528815325e-01, 8.529217017e-01, 8.529618220e-01, 8.530018933e-01, 8.530419158e-01, 8.530818895e-01, 8.531218145e-01, 8.531616910e-01, 8.532015190e-01, 8.532412985e-01, 8.532810297e-01, 8.533207126e-01, 8.533603473e-01, 8.533999339e-01, 8.534394724e-01, 8.534789630e-01, 8.535184058e-01, 8.535578007e-01, 8.535971479e-01, 8.536364475e-01, 8.536756995e-01, 8.537149040e-01, 8.537540611e-01, 8.537931709e-01, 8.538322335e-01, 8.538712489e-01, 8.539102171e-01, 8.539491384e-01, 8.539880127e-01, 8.540268402e-01, 8.540656209e-01, 8.541043548e-01, 8.541430422e-01, 8.541816829e-01, 8.542202772e-01, 8.542588251e-01, 8.542973267e-01, 8.543357820e-01, 8.543741912e-01, 8.544125542e-01, 8.544508713e-01, 8.544891423e-01, 8.545273675e-01, 8.545655469e-01, 8.546036806e-01, 8.546417687e-01, 8.546798111e-01, 8.547178081e-01, 8.547557597e-01, 8.547936659e-01, 8.548315268e-01, 8.548693425e-01, 8.549071131e-01, 8.549448387e-01, 8.549825193e-01, 8.550201550e-01, 8.550577458e-01, 8.550952919e-01, 8.551327933e-01, 8.551702501e-01, 8.552076623e-01, 8.552450301e-01, 8.552823536e-01, 8.553196326e-01, 8.553568675e-01, 8.553940582e-01, 8.554312047e-01, 8.554683073e-01, 8.555053658e-01, 8.555423805e-01, 8.555793514e-01, 8.556162786e-01, 8.556531621e-01, 8.556900019e-01, 8.557267983e-01, 8.557635512e-01, 8.558002607e-01, 8.558369269e-01, 8.558735498e-01, 8.559101296e-01, 8.559466663e-01, 8.559831600e-01, 8.560196107e-01, 8.560560184e-01, 8.560923834e-01, 8.561287057e-01, 8.561649852e-01, 8.562012221e-01, 8.562374165e-01, 8.562735685e-01, 8.563096780e-01, 8.563457452e-01, 8.563817701e-01, 8.564177528e-01, 8.564536934e-01, 8.564890737e-01, 8.565129780e-01, 8.565368544e-01, 8.565607030e-01, 8.565845236e-01, 8.566083165e-01, 8.566369651e-01, 8.566725711e-01, 8.567081357e-01, 8.567436588e-01, 8.567791405e-01, 8.568145809e-01, 8.568499800e-01, 8.568853380e-01, 8.569206548e-01, 8.569559307e-01, 8.569911655e-01, 8.570263595e-01, 8.570615125e-01, 8.570966249e-01, 8.571316965e-01, 8.571667274e-01, 8.572017178e-01, 8.572366677e-01, 8.572715771e-01, 8.573064462e-01, 8.573412749e-01, 8.573760634e-01, 8.574108117e-01, 8.574455198e-01, 8.574801879e-01, 8.575148161e-01, 8.575494043e-01, 8.575839526e-01, 8.576184612e-01, 8.576529300e-01, 8.576873592e-01, 8.577217487e-01, 8.577560987e-01, 8.577904092e-01, 8.578246804e-01, 8.578589122e-01, 8.578931047e-01, 8.579272579e-01, 8.579613721e-01, 8.579954471e-01, 8.580294831e-01, 8.580634801e-01, 8.580974382e-01, 8.581313575e-01, 8.581652380e-01, 8.581990798e-01, 8.582328830e-01, 8.582556459e-01, 8.582781299e-01, 8.583005883e-01, 8.583230210e-01, 8.583454282e-01, 8.583678099e-01, 8.584012892e-01, 8.584347854e-01, 8.584682435e-01, 8.585016635e-01, 8.585350455e-01, 8.585683897e-01, 8.586016960e-01, 8.586349645e-01, 8.586681952e-01, 8.587013883e-01, 8.587345438e-01, 8.587676618e-01, 8.588007422e-01, 8.588337853e-01, 8.588667909e-01, 8.588997593e-01, 8.589326904e-01, 8.589655843e-01, 8.589984411e-01, 8.590312609e-01, 8.590640436e-01, 8.590967894e-01, 8.591294982e-01, 8.591621703e-01, 8.591948056e-01, 8.592274041e-01, 8.592599660e-01, 8.592924914e-01, 8.593249801e-01, 8.593574324e-01, 8.593848989e-01, 8.594064852e-01, 8.594280474e-01, 8.594495854e-01, 8.594710992e-01, 8.594925890e-01, 8.595164434e-01, 8.595486059e-01, 8.595807326e-01, 8.596128233e-01, 8.596448781e-01, 8.596768972e-01, 8.597088806e-01, 8.597408283e-01, 8.597727403e-01, 8.598046168e-01, 8.598364579e-01, 8.598682634e-01, 8.599000336e-01, 8.599317685e-01, 8.599634680e-01, 8.599951324e-01, 8.600267616e-01, 8.600583557e-01, 8.600899147e-01, 8.601214387e-01, 8.601529278e-01, 8.601843820e-01, 8.602158014e-01, 8.602471860e-01, 8.602785359e-01, 8.603098512e-01, 8.603324016e-01, 8.603532324e-01, 8.603740401e-01, 8.603948248e-01, 8.604155866e-01, 8.604363256e-01, 8.604609531e-01, 8.604919930e-01, 8.605229987e-01, 8.605539703e-01, 8.605849078e-01, 8.606158113e-01, 8.606466809e-01, 8.606775166e-01, 8.607083184e-01, 8.607390864e-01, 8.607698207e-01, 8.608005213e-01, 8.608311882e-01, 8.608618216e-01, 8.608924214e-01, 8.609229878e-01, 8.609535207e-01, 8.609840203e-01, 8.610144865e-01, 8.610449195e-01, 8.610753192e-01, 8.611056858e-01, 8.611360193e-01, 8.611663197e-01, 8.611965871e-01, 8.612268216e-01, 8.612563097e-01, 8.612764222e-01, 8.612965128e-01, 8.613165816e-01, 8.613366285e-01, 8.613566538e-01, 8.613766572e-01, 8.614003785e-01, 8.614303187e-01, 8.614602264e-01, 8.614901018e-01, 8.615199448e-01, 8.615497555e-01, 8.615795340e-01, 8.616092803e-01, 8.616389945e-01, 8.616686766e-01, 8.616983266e-01, 8.617279447e-01, 8.617575308e-01, 8.617870850e-01, 8.618166074e-01, 8.618460980e-01, 8.618755569e-01, 8.619049840e-01, 8.619343796e-01, 8.619637435e-01, 8.619930759e-01, 8.620127206e-01, 8.620322336e-01, 8.620517256e-01, 8.620711968e-01, 8.620906471e-01, 8.621100765e-01, 8.621303850e-01, 8.621594669e-01, 8.621885176e-01, 8.622175373e-01, 8.622465259e-01, 8.622754836e-01, 8.623044104e-01, 8.623333064e-01, 8.623621715e-01, 8.623910059e-01, 8.624198095e-01, 8.624485825e-01, 8.624773248e-01, 8.625060366e-01, 8.625347178e-01, 8.625633686e-01, 8.625919889e-01, 8.626205788e-01, 8.626491384e-01, 8.626776677e-01, 8.627061668e-01, 8.627346356e-01, 8.627630743e-01, 8.627914829e-01, 8.628198614e-01, 8.628482099e-01, 8.628765285e-01, 8.629048171e-01, 8.629330758e-01, 8.629519864e-01, 8.629707858e-01, 8.629895654e-01, 8.630083252e-01, 8.630270652e-01, 8.630457855e-01, 8.630644861e-01, 8.630909370e-01, 8.631189290e-01, 8.631468914e-01, 8.631748246e-01, 8.632027283e-01, 8.632306028e-01, 8.632584481e-01, 8.632862641e-01, 8.633140511e-01, 8.633418089e-01, 8.633695376e-01, 8.633972373e-01, 8.634249081e-01, 8.634525499e-01, 8.634769282e-01, 8.634953176e-01, 8.635136878e-01, 8.635320388e-01, 8.635503707e-01, 8.635686835e-01, 8.635869772e-01, 8.636055095e-01, 8.636328930e-01, 8.636602479e-01, 8.636875744e-01, 8.637148725e-01, 8.637421422e-01, 8.637693836e-01, 8.637965967e-01, 8.638237816e-01, 8.638509383e-01, 8.638780669e-01, 8.639051673e-01, 8.639322397e-01, 8.639592841e-01, 8.639863005e-01, 8.640132889e-01, 8.640402495e-01, 8.640671822e-01, 8.640940871e-01, 8.641209643e-01, 8.641478137e-01, 8.641746354e-01, 8.642014295e-01, 8.642217921e-01, 8.642396181e-01, 8.642574257e-01, 8.642752150e-01, 8.642929860e-01, 8.643107388e-01, 8.643284733e-01, 8.643476536e-01, 8.643742008e-01, 8.644007208e-01, 8.644272135e-01, 8.644536792e-01, 8.644801177e-01, 8.645065292e-01, 8.645329137e-01, 8.645592711e-01, 8.645856017e-01, 8.646119053e-01, 8.646381821e-01, 8.646644320e-01, 8.646906552e-01, 8.647168516e-01, 8.647430214e-01, 8.647614742e-01, 8.647788852e-01, 8.647962784e-01, 8.648136540e-01, 8.648310119e-01, 8.648483521e-01, 8.648656747e-01, 8.648842841e-01, 8.649102154e-01, 8.649361203e-01, 8.649619989e-01, 8.649878514e-01, 8.650136776e-01, 8.650394777e-01, 8.650652517e-01, 8.650909996e-01, 8.651167215e-01, 8.651424174e-01, 8.651680873e-01, 8.651937313e-01, 8.652193495e-01, 8.652449418e-01, 8.652705083e-01, 8.652917671e-01, 8.653087771e-01, 8.653257700e-01, 8.653427458e-01, 8.653597045e-01, 8.653766462e-01, 8.653935708e-01, 8.654104785e-01, 8.654323135e-01, 8.654576241e-01, 8.654829093e-01, 8.655081692e-01, 8.655334038e-01, 8.655586131e-01, 8.655837971e-01, 8.656089560e-01, 8.656340897e-01, 8.656591983e-01, 8.656842818e-01, 8.657093402e-01, 8.657343737e-01, 8.657593821e-01, 8.657843657e-01, 8.658093243e-01, 8.658296095e-01, 8.658462155e-01, 8.658628049e-01, 8.658793779e-01, 8.658959343e-01, 8.659124743e-01, 8.659289979e-01, 8.659455050e-01, 8.659656988e-01, 8.659904104e-01, 8.660150975e-01, 8.660397602e-01, 8.660643984e-01, 8.660890122e-01, 8.661136017e-01, 8.661381668e-01, 8.661627077e-01, 8.661872243e-01, 8.662117166e-01, 8.662361848e-01, 8.662606289e-01, 8.662850488e-01, 8.663094447e-01, 8.663338165e-01, 8.663579168e-01, 8.663741327e-01, 8.663903327e-01, 8.664065167e-01, 8.664226848e-01, 8.664388370e-01, 8.664549733e-01, 8.664710938e-01, 8.664871985e-01, 8.665090814e-01, 8.665331911e-01, 8.665572771e-01, 8.665813396e-01, 8.666053784e-01, 8.666293938e-01, 8.666533857e-01, 8.666773541e-01, 8.667012991e-01, 8.667252207e-01, 8.667491189e-01, 8.667729938e-01, 8.667968455e-01, 8.668206738e-01, 8.668444790e-01, 8.668682610e-01, 8.668920198e-01, 8.669086808e-01, 8.669244892e-01, 8.669402822e-01, 8.669560599e-01, 8.669718223e-01, 8.669875693e-01, 8.670033011e-01, 8.670190176e-01, 8.670376741e-01, 8.670612032e-01, 8.670847095e-01, 8.671081931e-01, 8.671316539e-01, 8.671550921e-01, 8.671785076e-01, 8.672019004e-01, 8.672252707e-01, 8.672424871e-01, 8.672580373e-01, 8.672735724e-01, 8.672890925e-01, 8.673045977e-01, 8.673200879e-01, 8.673355633e-01, 8.673510237e-01, 8.673674529e-01, 8.673905990e-01, 8.674137228e-01, 8.674368245e-01, 8.674599039e-01, 8.674829612e-01, 8.675059964e-01, 8.675290095e-01, 8.675520005e-01, 8.675749695e-01, 8.675979165e-01, 8.676208416e-01, 8.676437447e-01, 8.676666260e-01, }; const float lut_midi_to_f_high[] = { 5.322785752e-06, 5.639295064e-06, 5.974624998e-06, 6.329894688e-06, 6.706289813e-06, 7.105066557e-06, 7.527555801e-06, 7.975167561e-06, 8.449395703e-06, 8.951822917e-06, 9.484126007e-06, 1.004808149e-05, 1.064557150e-05, 1.127859013e-05, 1.194925000e-05, 1.265978938e-05, 1.341257963e-05, 1.421013311e-05, 1.505511160e-05, 1.595033512e-05, 1.689879141e-05, 1.790364583e-05, 1.896825201e-05, 2.009616297e-05, 2.129114301e-05, 2.255718026e-05, 2.389849999e-05, 2.531957875e-05, 2.682515925e-05, 2.842026623e-05, 3.011022320e-05, 3.190067025e-05, 3.379758281e-05, 3.580729167e-05, 3.793650403e-05, 4.019232595e-05, 4.258228602e-05, 4.511436051e-05, 4.779699999e-05, 5.063915751e-05, 5.365031851e-05, 5.684053246e-05, 6.022044640e-05, 6.380134049e-05, 6.759516562e-05, 7.161458333e-05, 7.587300806e-05, 8.038465190e-05, 8.516457204e-05, 9.022872102e-05, 9.559399997e-05, 1.012783150e-04, 1.073006370e-04, 1.136810649e-04, 1.204408928e-04, 1.276026810e-04, 1.351903312e-04, 1.432291667e-04, 1.517460161e-04, 1.607693038e-04, 1.703291441e-04, 1.804574420e-04, 1.911879999e-04, 2.025566300e-04, 2.146012740e-04, 2.273621298e-04, 2.408817856e-04, 2.552053620e-04, 2.703806625e-04, 2.864583333e-04, 3.034920322e-04, 3.215386076e-04, 3.406582882e-04, 3.609148841e-04, 3.823759999e-04, 4.051132601e-04, 4.292025481e-04, 4.547242597e-04, 4.817635712e-04, 5.104107239e-04, 5.407613250e-04, 5.729166667e-04, 6.069840645e-04, 6.430772152e-04, 6.813165763e-04, 7.218297682e-04, 7.647519998e-04, 8.102265201e-04, 8.584050961e-04, 9.094485194e-04, 9.635271425e-04, 1.020821448e-03, 1.081522650e-03, 1.145833333e-03, 1.213968129e-03, 1.286154430e-03, 1.362633153e-03, 1.443659536e-03, 1.529504000e-03, 1.620453040e-03, 1.716810192e-03, 1.818897039e-03, 1.927054285e-03, 2.041642896e-03, 2.163045300e-03, 2.291666667e-03, 2.427936258e-03, 2.572308861e-03, 2.725266305e-03, 2.887319073e-03, 3.059007999e-03, 3.240906080e-03, 3.433620385e-03, 3.637794077e-03, 3.854108570e-03, 4.083285791e-03, 4.326090600e-03, 4.583333333e-03, 4.855872516e-03, 5.144617721e-03, 5.450532610e-03, 5.774638145e-03, 6.118015998e-03, 6.481812161e-03, 6.867240769e-03, 7.275588155e-03, 7.708217140e-03, 8.166571583e-03, 8.652181200e-03, 9.166666667e-03, 9.711745032e-03, 1.028923544e-02, 1.090106522e-02, 1.154927629e-02, 1.223603200e-02, 1.296362432e-02, 1.373448154e-02, 1.455117631e-02, 1.541643428e-02, 1.633314317e-02, 1.730436240e-02, 1.833333333e-02, 1.942349006e-02, 2.057847089e-02, 2.180213044e-02, 2.309855258e-02, 2.447206399e-02, 2.592724864e-02, 2.746896308e-02, 2.910235262e-02, 3.083286856e-02, 3.266628633e-02, 3.460872480e-02, 3.666666667e-02, 3.884698013e-02, 4.115694177e-02, 4.360426088e-02, 4.619710516e-02, 4.894412799e-02, 5.185449729e-02, 5.493792615e-02, 5.820470524e-02, 6.166573712e-02, 6.533257266e-02, 6.921744960e-02, 7.333333333e-02, 7.769396025e-02, 8.231388354e-02, 8.720852177e-02, 9.239421033e-02, 9.788825597e-02, 1.037089946e-01, 1.098758523e-01, 1.164094105e-01, 1.233314742e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, 1.250000000e-01, }; const float lut_midi_to_f_low[] = { 1.000000000e+00, 1.000225659e+00, 1.000451370e+00, 1.000677131e+00, 1.000902943e+00, 1.001128806e+00, 1.001354720e+00, 1.001580685e+00, 1.001806701e+00, 1.002032768e+00, 1.002258886e+00, 1.002485055e+00, 1.002711275e+00, 1.002937546e+00, 1.003163868e+00, 1.003390242e+00, 1.003616666e+00, 1.003843141e+00, 1.004069668e+00, 1.004296246e+00, 1.004522874e+00, 1.004749554e+00, 1.004976285e+00, 1.005203068e+00, 1.005429901e+00, 1.005656786e+00, 1.005883722e+00, 1.006110709e+00, 1.006337747e+00, 1.006564836e+00, 1.006791977e+00, 1.007019169e+00, 1.007246412e+00, 1.007473707e+00, 1.007701053e+00, 1.007928450e+00, 1.008155898e+00, 1.008383398e+00, 1.008610949e+00, 1.008838551e+00, 1.009066205e+00, 1.009293910e+00, 1.009521667e+00, 1.009749475e+00, 1.009977334e+00, 1.010205245e+00, 1.010433207e+00, 1.010661221e+00, 1.010889286e+00, 1.011117403e+00, 1.011345571e+00, 1.011573790e+00, 1.011802061e+00, 1.012030384e+00, 1.012258758e+00, 1.012487183e+00, 1.012715661e+00, 1.012944189e+00, 1.013172770e+00, 1.013401401e+00, 1.013630085e+00, 1.013858820e+00, 1.014087607e+00, 1.014316445e+00, 1.014545335e+00, 1.014774277e+00, 1.015003270e+00, 1.015232315e+00, 1.015461411e+00, 1.015690560e+00, 1.015919760e+00, 1.016149011e+00, 1.016378315e+00, 1.016607670e+00, 1.016837077e+00, 1.017066536e+00, 1.017296046e+00, 1.017525609e+00, 1.017755223e+00, 1.017984889e+00, 1.018214607e+00, 1.018444376e+00, 1.018674198e+00, 1.018904071e+00, 1.019133996e+00, 1.019363973e+00, 1.019594002e+00, 1.019824083e+00, 1.020054216e+00, 1.020284401e+00, 1.020514637e+00, 1.020744926e+00, 1.020975266e+00, 1.021205659e+00, 1.021436104e+00, 1.021666600e+00, 1.021897149e+00, 1.022127749e+00, 1.022358402e+00, 1.022589107e+00, 1.022819863e+00, 1.023050672e+00, 1.023281533e+00, 1.023512446e+00, 1.023743411e+00, 1.023974428e+00, 1.024205498e+00, 1.024436619e+00, 1.024667793e+00, 1.024899019e+00, 1.025130297e+00, 1.025361627e+00, 1.025593009e+00, 1.025824444e+00, 1.026055931e+00, 1.026287470e+00, 1.026519061e+00, 1.026750705e+00, 1.026982401e+00, 1.027214149e+00, 1.027445949e+00, 1.027677802e+00, 1.027909707e+00, 1.028141664e+00, 1.028373674e+00, 1.028605736e+00, 1.028837851e+00, 1.029070017e+00, 1.029302237e+00, 1.029534508e+00, 1.029766832e+00, 1.029999209e+00, 1.030231638e+00, 1.030464119e+00, 1.030696653e+00, 1.030929239e+00, 1.031161878e+00, 1.031394569e+00, 1.031627313e+00, 1.031860109e+00, 1.032092958e+00, 1.032325859e+00, 1.032558813e+00, 1.032791820e+00, 1.033024879e+00, 1.033257991e+00, 1.033491155e+00, 1.033724372e+00, 1.033957641e+00, 1.034190964e+00, 1.034424338e+00, 1.034657766e+00, 1.034891246e+00, 1.035124779e+00, 1.035358364e+00, 1.035592003e+00, 1.035825694e+00, 1.036059437e+00, 1.036293234e+00, 1.036527083e+00, 1.036760985e+00, 1.036994940e+00, 1.037228947e+00, 1.037463008e+00, 1.037697121e+00, 1.037931287e+00, 1.038165506e+00, 1.038399777e+00, 1.038634102e+00, 1.038868479e+00, 1.039102910e+00, 1.039337393e+00, 1.039571929e+00, 1.039806518e+00, 1.040041160e+00, 1.040275855e+00, 1.040510603e+00, 1.040745404e+00, 1.040980258e+00, 1.041215165e+00, 1.041450125e+00, 1.041685138e+00, 1.041920204e+00, 1.042155323e+00, 1.042390495e+00, 1.042625720e+00, 1.042860998e+00, 1.043096329e+00, 1.043331714e+00, 1.043567151e+00, 1.043802642e+00, 1.044038185e+00, 1.044273782e+00, 1.044509433e+00, 1.044745136e+00, 1.044980892e+00, 1.045216702e+00, 1.045452565e+00, 1.045688481e+00, 1.045924450e+00, 1.046160473e+00, 1.046396549e+00, 1.046632678e+00, 1.046868860e+00, 1.047105096e+00, 1.047341385e+00, 1.047577727e+00, 1.047814123e+00, 1.048050572e+00, 1.048287074e+00, 1.048523630e+00, 1.048760239e+00, 1.048996902e+00, 1.049233618e+00, 1.049470387e+00, 1.049707210e+00, 1.049944086e+00, 1.050181015e+00, 1.050417999e+00, 1.050655035e+00, 1.050892125e+00, 1.051129269e+00, 1.051366466e+00, 1.051603717e+00, 1.051841021e+00, 1.052078378e+00, 1.052315790e+00, 1.052553255e+00, 1.052790773e+00, 1.053028345e+00, 1.053265971e+00, 1.053503650e+00, 1.053741383e+00, 1.053979169e+00, 1.054217010e+00, 1.054454903e+00, 1.054692851e+00, 1.054930852e+00, 1.055168907e+00, 1.055407016e+00, 1.055645178e+00, 1.055883395e+00, 1.056121664e+00, 1.056359988e+00, 1.056598366e+00, 1.056836797e+00, 1.057075282e+00, 1.057313821e+00, 1.057552413e+00, 1.057791060e+00, 1.058029760e+00, 1.058268515e+00, 1.058507323e+00, 1.058746185e+00, 1.058985101e+00, 1.059224071e+00, }; const float lut_pot_curve[] = { 0.000000000e+00, 3.255208333e-02, 6.510416667e-02, 9.765625000e-02, 1.056640625e-01, 1.117675781e-01, 1.178710938e-01, 1.239746094e-01, 1.263912671e-01, 1.280634632e-01, 1.297356592e-01, 1.314078553e-01, 1.330800514e-01, 1.347522474e-01, 1.364244435e-01, 1.380966396e-01, 1.397688356e-01, 1.414410317e-01, 1.431132277e-01, 1.447854238e-01, 1.464576199e-01, 1.481298159e-01, 1.498020120e-01, 1.514742080e-01, 1.531464041e-01, 1.548186002e-01, 1.564907962e-01, 1.581629923e-01, 1.598351884e-01, 1.615073844e-01, 1.631795805e-01, 1.648517765e-01, 1.665239726e-01, 1.681961687e-01, 1.698683647e-01, 1.715405608e-01, 1.732127568e-01, 1.748849529e-01, 1.765571490e-01, 1.782293450e-01, 1.799015411e-01, 1.815737372e-01, 1.832459332e-01, 1.849181293e-01, 1.865903253e-01, 1.882625214e-01, 1.899347175e-01, 1.916069135e-01, 1.932791096e-01, 1.949513057e-01, 1.966235017e-01, 1.982956978e-01, 1.999678938e-01, 2.016400899e-01, 2.033122860e-01, 2.049844820e-01, 2.066566781e-01, 2.083288741e-01, 2.100010702e-01, 2.116732663e-01, 2.133454623e-01, 2.150176584e-01, 2.166898545e-01, 2.183620505e-01, 2.200342466e-01, 2.217064426e-01, 2.233786387e-01, 2.250508348e-01, 2.267230308e-01, 2.283952269e-01, 2.300674229e-01, 2.317396190e-01, 2.334118151e-01, 2.350840111e-01, 2.367562072e-01, 2.384284033e-01, 2.401005993e-01, 2.417727954e-01, 2.434449914e-01, 2.451171875e-01, 2.467893836e-01, 2.484615796e-01, 2.501148897e-01, 2.515510110e-01, 2.529871324e-01, 2.544232537e-01, 2.558593750e-01, 2.572954963e-01, 2.587316176e-01, 2.601677390e-01, 2.616038603e-01, 2.630399816e-01, 2.644761029e-01, 2.659122243e-01, 2.673483456e-01, 2.687844669e-01, 2.702205882e-01, 2.716567096e-01, 2.730928309e-01, 2.745289522e-01, 2.759650735e-01, 2.774011949e-01, 2.788373162e-01, 2.802734375e-01, 2.817095588e-01, 2.831456801e-01, 2.845818015e-01, 2.860179228e-01, 2.874540441e-01, 2.888901654e-01, 2.903262868e-01, 2.917624081e-01, 2.931985294e-01, 2.946346507e-01, 2.960707721e-01, 2.975068934e-01, 2.989430147e-01, 3.003791360e-01, 3.018152574e-01, 3.032513787e-01, 3.046875000e-01, 3.061236213e-01, 3.075597426e-01, 3.089958640e-01, 3.104319853e-01, 3.118681066e-01, 3.133042279e-01, 3.147403493e-01, 3.161764706e-01, 3.176125919e-01, 3.190487132e-01, 3.204848346e-01, 3.219209559e-01, 3.233570772e-01, 3.247931985e-01, 3.262293199e-01, 3.276654412e-01, 3.291015625e-01, 3.305376838e-01, 3.319738051e-01, 3.334099265e-01, 3.348460478e-01, 3.362821691e-01, 3.377182904e-01, 3.391544118e-01, 3.405905331e-01, 3.420266544e-01, 3.434627757e-01, 3.448988971e-01, 3.463350184e-01, 3.477711397e-01, 3.492072610e-01, 3.506433824e-01, 3.520795037e-01, 3.535156250e-01, 3.549517463e-01, 3.563878676e-01, 3.578239890e-01, 3.592601103e-01, 3.606962316e-01, 3.621323529e-01, 3.635684743e-01, 3.650045956e-01, 3.664407169e-01, 3.678768382e-01, 3.693129596e-01, 3.707490809e-01, 3.721852022e-01, 3.736213235e-01, 3.750574449e-01, 3.764935662e-01, 3.779296875e-01, 3.793658088e-01, 3.808019301e-01, 3.822380515e-01, 3.836741728e-01, 3.851102941e-01, 3.865464154e-01, 3.879825368e-01, 3.894186581e-01, 3.908547794e-01, 3.922909007e-01, 3.937270221e-01, 3.951631434e-01, 3.965992647e-01, 3.980353860e-01, 3.994715074e-01, 4.009076287e-01, 4.023437500e-01, 4.037798713e-01, 4.052159926e-01, 4.066521140e-01, 4.080882353e-01, 4.095243566e-01, 4.109604779e-01, 4.123965993e-01, 4.138327206e-01, 4.152688419e-01, 4.167049632e-01, 4.181410846e-01, 4.195772059e-01, 4.210133272e-01, 4.224494485e-01, 4.238855699e-01, 4.253216912e-01, 4.267578125e-01, 4.281939338e-01, 4.296300551e-01, 4.310661765e-01, 4.325022978e-01, 4.339384191e-01, 4.353745404e-01, 4.368106618e-01, 4.382467831e-01, 4.396829044e-01, 4.411190257e-01, 4.425551471e-01, 4.439912684e-01, 4.454273897e-01, 4.468635110e-01, 4.482996324e-01, 4.497357537e-01, 4.511718750e-01, 4.526079963e-01, 4.540441176e-01, 4.554802390e-01, 4.569163603e-01, 4.583524816e-01, 4.597886029e-01, 4.612247243e-01, 4.626608456e-01, 4.640969669e-01, 4.655330882e-01, 4.669692096e-01, 4.684053309e-01, 4.698414522e-01, 4.712775735e-01, 4.727136949e-01, 4.741498162e-01, 4.755859375e-01, 4.770220588e-01, 4.784581801e-01, 4.798943015e-01, 4.813304228e-01, 4.827665441e-01, 4.842026654e-01, 4.856387868e-01, 4.870749081e-01, 4.885110294e-01, 4.899471507e-01, 4.913832721e-01, 4.928193934e-01, 4.942555147e-01, 4.956916360e-01, 4.971277574e-01, 4.985638787e-01, 5.000000000e-01, 5.014361213e-01, 5.028722426e-01, 5.043083640e-01, 5.057444853e-01, 5.071806066e-01, 5.086167279e-01, 5.100528493e-01, 5.114889706e-01, 5.129250919e-01, 5.143612132e-01, 5.157973346e-01, 5.172334559e-01, 5.186695772e-01, 5.201056985e-01, 5.215418199e-01, 5.229779412e-01, 5.244140625e-01, 5.258501838e-01, 5.272863051e-01, 5.287224265e-01, 5.301585478e-01, 5.315946691e-01, 5.330307904e-01, 5.344669118e-01, 5.359030331e-01, 5.373391544e-01, 5.387752757e-01, 5.402113971e-01, 5.416475184e-01, 5.430836397e-01, 5.445197610e-01, 5.459558824e-01, 5.473920037e-01, 5.488281250e-01, 5.502642463e-01, 5.517003676e-01, 5.531364890e-01, 5.545726103e-01, 5.560087316e-01, 5.574448529e-01, 5.588809743e-01, 5.603170956e-01, 5.617532169e-01, 5.631893382e-01, 5.646254596e-01, 5.660615809e-01, 5.674977022e-01, 5.689338235e-01, 5.703699449e-01, 5.718060662e-01, 5.732421875e-01, 5.746783088e-01, 5.761144301e-01, 5.775505515e-01, 5.789866728e-01, 5.804227941e-01, 5.818589154e-01, 5.832950368e-01, 5.847311581e-01, 5.861672794e-01, 5.876034007e-01, 5.890395221e-01, 5.904756434e-01, 5.919117647e-01, 5.933478860e-01, 5.947840074e-01, 5.962201287e-01, 5.976562500e-01, 5.990923713e-01, 6.005284926e-01, 6.019646140e-01, 6.034007353e-01, 6.048368566e-01, 6.062729779e-01, 6.077090993e-01, 6.091452206e-01, 6.105813419e-01, 6.120174632e-01, 6.134535846e-01, 6.148897059e-01, 6.163258272e-01, 6.177619485e-01, 6.191980699e-01, 6.206341912e-01, 6.220703125e-01, 6.235064338e-01, 6.249425551e-01, 6.263786765e-01, 6.278147978e-01, 6.292509191e-01, 6.306870404e-01, 6.321231618e-01, 6.335592831e-01, 6.349954044e-01, 6.364315257e-01, 6.378676471e-01, 6.393037684e-01, 6.407398897e-01, 6.421760110e-01, 6.436121324e-01, 6.450482537e-01, 6.464843750e-01, 6.479204963e-01, 6.493566176e-01, 6.507927390e-01, 6.522288603e-01, 6.536649816e-01, 6.551011029e-01, 6.565372243e-01, 6.579733456e-01, 6.594094669e-01, 6.608455882e-01, 6.622817096e-01, 6.637178309e-01, 6.651539522e-01, 6.665900735e-01, 6.680261949e-01, 6.694623162e-01, 6.708984375e-01, 6.723345588e-01, 6.737706801e-01, 6.752068015e-01, 6.766429228e-01, 6.780790441e-01, 6.795151654e-01, 6.809512868e-01, 6.823874081e-01, 6.838235294e-01, 6.852596507e-01, 6.866957721e-01, 6.881318934e-01, 6.895680147e-01, 6.910041360e-01, 6.924402574e-01, 6.938763787e-01, 6.953125000e-01, 6.967486213e-01, 6.981847426e-01, 6.996208640e-01, 7.010569853e-01, 7.024931066e-01, 7.039292279e-01, 7.053653493e-01, 7.068014706e-01, 7.082375919e-01, 7.096737132e-01, 7.111098346e-01, 7.125459559e-01, 7.139820772e-01, 7.154181985e-01, 7.168543199e-01, 7.182904412e-01, 7.197265625e-01, 7.211626838e-01, 7.225988051e-01, 7.240349265e-01, 7.254710478e-01, 7.269071691e-01, 7.283432904e-01, 7.297794118e-01, 7.312155331e-01, 7.326516544e-01, 7.340877757e-01, 7.355238971e-01, 7.369600184e-01, 7.383961397e-01, 7.398322610e-01, 7.412683824e-01, 7.427045037e-01, 7.441406250e-01, 7.455767463e-01, 7.470128676e-01, 7.484489890e-01, 7.498851103e-01, 7.518717448e-01, 7.539062500e-01, 7.559407552e-01, 7.579752604e-01, 7.600097656e-01, 7.620442708e-01, 7.640787760e-01, 7.661132812e-01, 7.681477865e-01, 7.701822917e-01, 7.722167969e-01, 7.742513021e-01, 7.762858073e-01, 7.783203125e-01, 7.803548177e-01, 7.823893229e-01, 7.844238281e-01, 7.864583333e-01, 7.884928385e-01, 7.905273438e-01, 7.925618490e-01, 7.945963542e-01, 7.966308594e-01, 7.986653646e-01, 8.006998698e-01, 8.027343750e-01, 8.047688802e-01, 8.068033854e-01, 8.088378906e-01, 8.108723958e-01, 8.129069010e-01, 8.149414062e-01, 8.169759115e-01, 8.190104167e-01, 8.210449219e-01, 8.230794271e-01, 8.251139323e-01, 8.271484375e-01, 8.291829427e-01, 8.312174479e-01, 8.332519531e-01, 8.352864583e-01, 8.373209635e-01, 8.393554688e-01, 8.413899740e-01, 8.434244792e-01, 8.454589844e-01, 8.474934896e-01, 8.495279948e-01, 8.515625000e-01, 8.535970052e-01, 8.556315104e-01, 8.576660156e-01, 8.597005208e-01, 8.617350260e-01, 8.637695312e-01, 8.658040365e-01, 8.678385417e-01, 8.698730469e-01, 8.719075521e-01, 8.739420573e-01, 8.756893382e-01, 8.771254596e-01, 8.785615809e-01, 8.799977022e-01, 8.814338235e-01, 8.828699449e-01, 8.843060662e-01, 8.857421875e-01, 8.871783088e-01, 8.886144301e-01, 8.900505515e-01, 8.914866728e-01, 8.929227941e-01, 8.943589154e-01, 8.957950368e-01, 8.972311581e-01, 8.986672794e-01, 9.023437500e-01, 9.348958333e-01, 9.674479167e-01, 1.000000000e+00, }; const float lut_ap_poles[] = { 9.999174437e-01, 9.997160329e-01, 9.993897602e-01, 9.987952776e-01, 9.976718129e-01, 9.955280098e-01, 9.914315323e-01, 9.836199785e-01, 9.688016569e-01, 9.409767040e-01, 8.897147107e-01, 7.984785110e-01, 6.454684139e-01, 4.118108699e-01, 9.725667152e-02, -2.775386379e-01, -7.176356738e-01, }; const float* lookup_table_table[] = { lut_sin, lut_arcsin, lut_xfade_in, lut_xfade_out, lut_bipolar_fold, lut_midi_to_f_high, lut_midi_to_f_low, lut_pot_curve, lut_ap_poles, }; const float wav_sine_i[] = { -8.704110566e-18, -6.135884649e-03, -1.227153829e-02, -1.840672991e-02, -2.454122852e-02, -3.067480318e-02, -3.680722294e-02, -4.293825693e-02, -4.906767433e-02, -5.519524435e-02, -6.132073630e-02, -6.744391956e-02, -7.356456360e-02, -7.968243797e-02, -8.579731234e-02, -9.190895650e-02, -9.801714033e-02, -1.041216339e-01, -1.102222073e-01, -1.163186309e-01, -1.224106752e-01, -1.284981108e-01, -1.345807085e-01, -1.406582393e-01, -1.467304745e-01, -1.527971853e-01, -1.588581433e-01, -1.649131205e-01, -1.709618888e-01, -1.770042204e-01, -1.830398880e-01, -1.890686641e-01, -1.950903220e-01, -2.011046348e-01, -2.071113762e-01, -2.131103199e-01, -2.191012402e-01, -2.250839114e-01, -2.310581083e-01, -2.370236060e-01, -2.429801799e-01, -2.489276057e-01, -2.548656596e-01, -2.607941179e-01, -2.667127575e-01, -2.726213554e-01, -2.785196894e-01, -2.844075372e-01, -2.902846773e-01, -2.961508882e-01, -3.020059493e-01, -3.078496400e-01, -3.136817404e-01, -3.195020308e-01, -3.253102922e-01, -3.311063058e-01, -3.368898534e-01, -3.426607173e-01, -3.484186802e-01, -3.541635254e-01, -3.598950365e-01, -3.656129978e-01, -3.713171940e-01, -3.770074102e-01, -3.826834324e-01, -3.883450467e-01, -3.939920401e-01, -3.996241998e-01, -4.052413140e-01, -4.108431711e-01, -4.164295601e-01, -4.220002708e-01, -4.275550934e-01, -4.330938189e-01, -4.386162385e-01, -4.441221446e-01, -4.496113297e-01, -4.550835871e-01, -4.605387110e-01, -4.659764958e-01, -4.713967368e-01, -4.767992301e-01, -4.821837721e-01, -4.875501601e-01, -4.928981922e-01, -4.982276670e-01, -5.035383837e-01, -5.088301425e-01, -5.141027442e-01, -5.193559902e-01, -5.245896827e-01, -5.298036247e-01, -5.349976199e-01, -5.401714727e-01, -5.453249884e-01, -5.504579729e-01, -5.555702330e-01, -5.606615762e-01, -5.657318108e-01, -5.707807459e-01, -5.758081914e-01, -5.808139581e-01, -5.857978575e-01, -5.907597019e-01, -5.956993045e-01, -6.006164794e-01, -6.055110414e-01, -6.103828063e-01, -6.152315906e-01, -6.200572118e-01, -6.248594881e-01, -6.296382389e-01, -6.343932842e-01, -6.391244449e-01, -6.438315429e-01, -6.485144010e-01, -6.531728430e-01, -6.578066933e-01, -6.624157776e-01, -6.669999223e-01, -6.715589548e-01, -6.760927036e-01, -6.806009978e-01, -6.850836678e-01, -6.895405447e-01, -6.939714609e-01, -6.983762494e-01, -7.027547445e-01, -7.071067812e-01, -7.114321957e-01, -7.157308253e-01, -7.200025080e-01, -7.242470830e-01, -7.284643904e-01, -7.326542717e-01, -7.368165689e-01, -7.409511254e-01, -7.450577854e-01, -7.491363945e-01, -7.531867990e-01, -7.572088465e-01, -7.612023855e-01, -7.651672656e-01, -7.691033376e-01, -7.730104534e-01, -7.768884657e-01, -7.807372286e-01, -7.845565972e-01, -7.883464276e-01, -7.921065773e-01, -7.958369046e-01, -7.995372691e-01, -8.032075315e-01, -8.068475535e-01, -8.104571983e-01, -8.140363297e-01, -8.175848132e-01, -8.211025150e-01, -8.245893028e-01, -8.280450453e-01, -8.314696123e-01, -8.348628750e-01, -8.382247056e-01, -8.415549774e-01, -8.448535652e-01, -8.481203448e-01, -8.513551931e-01, -8.545579884e-01, -8.577286100e-01, -8.608669386e-01, -8.639728561e-01, -8.670462455e-01, -8.700869911e-01, -8.730949784e-01, -8.760700942e-01, -8.790122264e-01, -8.819212643e-01, -8.847970984e-01, -8.876396204e-01, -8.904487232e-01, -8.932243012e-01, -8.959662498e-01, -8.986744657e-01, -9.013488470e-01, -9.039892931e-01, -9.065957045e-01, -9.091679831e-01, -9.117060320e-01, -9.142097557e-01, -9.166790599e-01, -9.191138517e-01, -9.215140393e-01, -9.238795325e-01, -9.262102421e-01, -9.285060805e-01, -9.307669611e-01, -9.329927988e-01, -9.351835099e-01, -9.373390119e-01, -9.394592236e-01, -9.415440652e-01, -9.435934582e-01, -9.456073254e-01, -9.475855910e-01, -9.495281806e-01, -9.514350210e-01, -9.533060404e-01, -9.551411683e-01, -9.569403357e-01, -9.587034749e-01, -9.604305194e-01, -9.621214043e-01, -9.637760658e-01, -9.653944417e-01, -9.669764710e-01, -9.685220943e-01, -9.700312532e-01, -9.715038910e-01, -9.729399522e-01, -9.743393828e-01, -9.757021300e-01, -9.770281427e-01, -9.783173707e-01, -9.795697657e-01, -9.807852804e-01, -9.819638691e-01, -9.831054874e-01, -9.842100924e-01, -9.852776424e-01, -9.863080972e-01, -9.873014182e-01, -9.882575677e-01, -9.891765100e-01, -9.900582103e-01, -9.909026354e-01, -9.917097537e-01, -9.924795346e-01, -9.932119492e-01, -9.939069700e-01, -9.945645707e-01, -9.951847267e-01, -9.957674145e-01, -9.963126122e-01, -9.968202993e-01, -9.972904567e-01, -9.977230666e-01, -9.981181129e-01, -9.984755806e-01, -9.987954562e-01, -9.990777278e-01, -9.993223846e-01, -9.995294175e-01, -9.996988187e-01, -9.998305818e-01, -9.999247018e-01, -9.999811753e-01, -1.000000000e+00, -9.999811753e-01, -9.999247018e-01, -9.998305818e-01, -9.996988187e-01, -9.995294175e-01, -9.993223846e-01, -9.990777278e-01, -9.987954562e-01, -9.984755806e-01, -9.981181129e-01, -9.977230666e-01, -9.972904567e-01, -9.968202993e-01, -9.963126122e-01, -9.957674145e-01, -9.951847267e-01, -9.945645707e-01, -9.939069700e-01, -9.932119492e-01, -9.924795346e-01, -9.917097537e-01, -9.909026354e-01, -9.900582103e-01, -9.891765100e-01, -9.882575677e-01, -9.873014182e-01, -9.863080972e-01, -9.852776424e-01, -9.842100924e-01, -9.831054874e-01, -9.819638691e-01, -9.807852804e-01, -9.795697657e-01, -9.783173707e-01, -9.770281427e-01, -9.757021300e-01, -9.743393828e-01, -9.729399522e-01, -9.715038910e-01, -9.700312532e-01, -9.685220943e-01, -9.669764710e-01, -9.653944417e-01, -9.637760658e-01, -9.621214043e-01, -9.604305194e-01, -9.587034749e-01, -9.569403357e-01, -9.551411683e-01, -9.533060404e-01, -9.514350210e-01, -9.495281806e-01, -9.475855910e-01, -9.456073254e-01, -9.435934582e-01, -9.415440652e-01, -9.394592236e-01, -9.373390119e-01, -9.351835099e-01, -9.329927988e-01, -9.307669611e-01, -9.285060805e-01, -9.262102421e-01, -9.238795325e-01, -9.215140393e-01, -9.191138517e-01, -9.166790599e-01, -9.142097557e-01, -9.117060320e-01, -9.091679831e-01, -9.065957045e-01, -9.039892931e-01, -9.013488470e-01, -8.986744657e-01, -8.959662498e-01, -8.932243012e-01, -8.904487232e-01, -8.876396204e-01, -8.847970984e-01, -8.819212643e-01, -8.790122264e-01, -8.760700942e-01, -8.730949784e-01, -8.700869911e-01, -8.670462455e-01, -8.639728561e-01, -8.608669386e-01, -8.577286100e-01, -8.545579884e-01, -8.513551931e-01, -8.481203448e-01, -8.448535652e-01, -8.415549774e-01, -8.382247056e-01, -8.348628750e-01, -8.314696123e-01, -8.280450453e-01, -8.245893028e-01, -8.211025150e-01, -8.175848132e-01, -8.140363297e-01, -8.104571983e-01, -8.068475535e-01, -8.032075315e-01, -7.995372691e-01, -7.958369046e-01, -7.921065773e-01, -7.883464276e-01, -7.845565972e-01, -7.807372286e-01, -7.768884657e-01, -7.730104534e-01, -7.691033376e-01, -7.651672656e-01, -7.612023855e-01, -7.572088465e-01, -7.531867990e-01, -7.491363945e-01, -7.450577854e-01, -7.409511254e-01, -7.368165689e-01, -7.326542717e-01, -7.284643904e-01, -7.242470830e-01, -7.200025080e-01, -7.157308253e-01, -7.114321957e-01, -7.071067812e-01, -7.027547445e-01, -6.983762494e-01, -6.939714609e-01, -6.895405447e-01, -6.850836678e-01, -6.806009978e-01, -6.760927036e-01, -6.715589548e-01, -6.669999223e-01, -6.624157776e-01, -6.578066933e-01, -6.531728430e-01, -6.485144010e-01, -6.438315429e-01, -6.391244449e-01, -6.343932842e-01, -6.296382389e-01, -6.248594881e-01, -6.200572118e-01, -6.152315906e-01, -6.103828063e-01, -6.055110414e-01, -6.006164794e-01, -5.956993045e-01, -5.907597019e-01, -5.857978575e-01, -5.808139581e-01, -5.758081914e-01, -5.707807459e-01, -5.657318108e-01, -5.606615762e-01, -5.555702330e-01, -5.504579729e-01, -5.453249884e-01, -5.401714727e-01, -5.349976199e-01, -5.298036247e-01, -5.245896827e-01, -5.193559902e-01, -5.141027442e-01, -5.088301425e-01, -5.035383837e-01, -4.982276670e-01, -4.928981922e-01, -4.875501601e-01, -4.821837721e-01, -4.767992301e-01, -4.713967368e-01, -4.659764958e-01, -4.605387110e-01, -4.550835871e-01, -4.496113297e-01, -4.441221446e-01, -4.386162385e-01, -4.330938189e-01, -4.275550934e-01, -4.220002708e-01, -4.164295601e-01, -4.108431711e-01, -4.052413140e-01, -3.996241998e-01, -3.939920401e-01, -3.883450467e-01, -3.826834324e-01, -3.770074102e-01, -3.713171940e-01, -3.656129978e-01, -3.598950365e-01, -3.541635254e-01, -3.484186802e-01, -3.426607173e-01, -3.368898534e-01, -3.311063058e-01, -3.253102922e-01, -3.195020308e-01, -3.136817404e-01, -3.078496400e-01, -3.020059493e-01, -2.961508882e-01, -2.902846773e-01, -2.844075372e-01, -2.785196894e-01, -2.726213554e-01, -2.667127575e-01, -2.607941179e-01, -2.548656596e-01, -2.489276057e-01, -2.429801799e-01, -2.370236060e-01, -2.310581083e-01, -2.250839114e-01, -2.191012402e-01, -2.131103199e-01, -2.071113762e-01, -2.011046348e-01, -1.950903220e-01, -1.890686641e-01, -1.830398880e-01, -1.770042204e-01, -1.709618888e-01, -1.649131205e-01, -1.588581433e-01, -1.527971853e-01, -1.467304745e-01, -1.406582393e-01, -1.345807085e-01, -1.284981108e-01, -1.224106752e-01, -1.163186309e-01, -1.102222073e-01, -1.041216339e-01, -9.801714033e-02, -9.190895650e-02, -8.579731234e-02, -7.968243797e-02, -7.356456360e-02, -6.744391956e-02, -6.132073630e-02, -5.519524435e-02, -4.906767433e-02, -4.293825693e-02, -3.680722294e-02, -3.067480318e-02, -2.454122852e-02, -1.840672991e-02, -1.227153829e-02, -6.135884649e-03, -1.311687905e-16, 6.135884649e-03, 1.227153829e-02, 1.840672991e-02, 2.454122852e-02, 3.067480318e-02, 3.680722294e-02, 4.293825693e-02, 4.906767433e-02, 5.519524435e-02, 6.132073630e-02, 6.744391956e-02, 7.356456360e-02, 7.968243797e-02, 8.579731234e-02, 9.190895650e-02, 9.801714033e-02, 1.041216339e-01, 1.102222073e-01, 1.163186309e-01, 1.224106752e-01, 1.284981108e-01, 1.345807085e-01, 1.406582393e-01, 1.467304745e-01, 1.527971853e-01, 1.588581433e-01, 1.649131205e-01, 1.709618888e-01, 1.770042204e-01, 1.830398880e-01, 1.890686641e-01, 1.950903220e-01, 2.011046348e-01, 2.071113762e-01, 2.131103199e-01, 2.191012402e-01, 2.250839114e-01, 2.310581083e-01, 2.370236060e-01, 2.429801799e-01, 2.489276057e-01, 2.548656596e-01, 2.607941179e-01, 2.667127575e-01, 2.726213554e-01, 2.785196894e-01, 2.844075372e-01, 2.902846773e-01, 2.961508882e-01, 3.020059493e-01, 3.078496400e-01, 3.136817404e-01, 3.195020308e-01, 3.253102922e-01, 3.311063058e-01, 3.368898534e-01, 3.426607173e-01, 3.484186802e-01, 3.541635254e-01, 3.598950365e-01, 3.656129978e-01, 3.713171940e-01, 3.770074102e-01, 3.826834324e-01, 3.883450467e-01, 3.939920401e-01, 3.996241998e-01, 4.052413140e-01, 4.108431711e-01, 4.164295601e-01, 4.220002708e-01, 4.275550934e-01, 4.330938189e-01, 4.386162385e-01, 4.441221446e-01, 4.496113297e-01, 4.550835871e-01, 4.605387110e-01, 4.659764958e-01, 4.713967368e-01, 4.767992301e-01, 4.821837721e-01, 4.875501601e-01, 4.928981922e-01, 4.982276670e-01, 5.035383837e-01, 5.088301425e-01, 5.141027442e-01, 5.193559902e-01, 5.245896827e-01, 5.298036247e-01, 5.349976199e-01, 5.401714727e-01, 5.453249884e-01, 5.504579729e-01, 5.555702330e-01, 5.606615762e-01, 5.657318108e-01, 5.707807459e-01, 5.758081914e-01, 5.808139581e-01, 5.857978575e-01, 5.907597019e-01, 5.956993045e-01, 6.006164794e-01, 6.055110414e-01, 6.103828063e-01, 6.152315906e-01, 6.200572118e-01, 6.248594881e-01, 6.296382389e-01, 6.343932842e-01, 6.391244449e-01, 6.438315429e-01, 6.485144010e-01, 6.531728430e-01, 6.578066933e-01, 6.624157776e-01, 6.669999223e-01, 6.715589548e-01, 6.760927036e-01, 6.806009978e-01, 6.850836678e-01, 6.895405447e-01, 6.939714609e-01, 6.983762494e-01, 7.027547445e-01, 7.071067812e-01, 7.114321957e-01, 7.157308253e-01, 7.200025080e-01, 7.242470830e-01, 7.284643904e-01, 7.326542717e-01, 7.368165689e-01, 7.409511254e-01, 7.450577854e-01, 7.491363945e-01, 7.531867990e-01, 7.572088465e-01, 7.612023855e-01, 7.651672656e-01, 7.691033376e-01, 7.730104534e-01, 7.768884657e-01, 7.807372286e-01, 7.845565972e-01, 7.883464276e-01, 7.921065773e-01, 7.958369046e-01, 7.995372691e-01, 8.032075315e-01, 8.068475535e-01, 8.104571983e-01, 8.140363297e-01, 8.175848132e-01, 8.211025150e-01, 8.245893028e-01, 8.280450453e-01, 8.314696123e-01, 8.348628750e-01, 8.382247056e-01, 8.415549774e-01, 8.448535652e-01, 8.481203448e-01, 8.513551931e-01, 8.545579884e-01, 8.577286100e-01, 8.608669386e-01, 8.639728561e-01, 8.670462455e-01, 8.700869911e-01, 8.730949784e-01, 8.760700942e-01, 8.790122264e-01, 8.819212643e-01, 8.847970984e-01, 8.876396204e-01, 8.904487232e-01, 8.932243012e-01, 8.959662498e-01, 8.986744657e-01, 9.013488470e-01, 9.039892931e-01, 9.065957045e-01, 9.091679831e-01, 9.117060320e-01, 9.142097557e-01, 9.166790599e-01, 9.191138517e-01, 9.215140393e-01, 9.238795325e-01, 9.262102421e-01, 9.285060805e-01, 9.307669611e-01, 9.329927988e-01, 9.351835099e-01, 9.373390119e-01, 9.394592236e-01, 9.415440652e-01, 9.435934582e-01, 9.456073254e-01, 9.475855910e-01, 9.495281806e-01, 9.514350210e-01, 9.533060404e-01, 9.551411683e-01, 9.569403357e-01, 9.587034749e-01, 9.604305194e-01, 9.621214043e-01, 9.637760658e-01, 9.653944417e-01, 9.669764710e-01, 9.685220943e-01, 9.700312532e-01, 9.715038910e-01, 9.729399522e-01, 9.743393828e-01, 9.757021300e-01, 9.770281427e-01, 9.783173707e-01, 9.795697657e-01, 9.807852804e-01, 9.819638691e-01, 9.831054874e-01, 9.842100924e-01, 9.852776424e-01, 9.863080972e-01, 9.873014182e-01, 9.882575677e-01, 9.891765100e-01, 9.900582103e-01, 9.909026354e-01, 9.917097537e-01, 9.924795346e-01, 9.932119492e-01, 9.939069700e-01, 9.945645707e-01, 9.951847267e-01, 9.957674145e-01, 9.963126122e-01, 9.968202993e-01, 9.972904567e-01, 9.977230666e-01, 9.981181129e-01, 9.984755806e-01, 9.987954562e-01, 9.990777278e-01, 9.993223846e-01, 9.995294175e-01, 9.996988187e-01, 9.998305818e-01, 9.999247018e-01, 9.999811753e-01, 1.000000000e+00, 9.999811753e-01, 9.999247018e-01, 9.998305818e-01, 9.996988187e-01, 9.995294175e-01, 9.993223846e-01, 9.990777278e-01, 9.987954562e-01, 9.984755806e-01, 9.981181129e-01, 9.977230666e-01, 9.972904567e-01, 9.968202993e-01, 9.963126122e-01, 9.957674145e-01, 9.951847267e-01, 9.945645707e-01, 9.939069700e-01, 9.932119492e-01, 9.924795346e-01, 9.917097537e-01, 9.909026354e-01, 9.900582103e-01, 9.891765100e-01, 9.882575677e-01, 9.873014182e-01, 9.863080972e-01, 9.852776424e-01, 9.842100924e-01, 9.831054874e-01, 9.819638691e-01, 9.807852804e-01, 9.795697657e-01, 9.783173707e-01, 9.770281427e-01, 9.757021300e-01, 9.743393828e-01, 9.729399522e-01, 9.715038910e-01, 9.700312532e-01, 9.685220943e-01, 9.669764710e-01, 9.653944417e-01, 9.637760658e-01, 9.621214043e-01, 9.604305194e-01, 9.587034749e-01, 9.569403357e-01, 9.551411683e-01, 9.533060404e-01, 9.514350210e-01, 9.495281806e-01, 9.475855910e-01, 9.456073254e-01, 9.435934582e-01, 9.415440652e-01, 9.394592236e-01, 9.373390119e-01, 9.351835099e-01, 9.329927988e-01, 9.307669611e-01, 9.285060805e-01, 9.262102421e-01, 9.238795325e-01, 9.215140393e-01, 9.191138517e-01, 9.166790599e-01, 9.142097557e-01, 9.117060320e-01, 9.091679831e-01, 9.065957045e-01, 9.039892931e-01, 9.013488470e-01, 8.986744657e-01, 8.959662498e-01, 8.932243012e-01, 8.904487232e-01, 8.876396204e-01, 8.847970984e-01, 8.819212643e-01, 8.790122264e-01, 8.760700942e-01, 8.730949784e-01, 8.700869911e-01, 8.670462455e-01, 8.639728561e-01, 8.608669386e-01, 8.577286100e-01, 8.545579884e-01, 8.513551931e-01, 8.481203448e-01, 8.448535652e-01, 8.415549774e-01, 8.382247056e-01, 8.348628750e-01, 8.314696123e-01, 8.280450453e-01, 8.245893028e-01, 8.211025150e-01, 8.175848132e-01, 8.140363297e-01, 8.104571983e-01, 8.068475535e-01, 8.032075315e-01, 7.995372691e-01, 7.958369046e-01, 7.921065773e-01, 7.883464276e-01, 7.845565972e-01, 7.807372286e-01, 7.768884657e-01, 7.730104534e-01, 7.691033376e-01, 7.651672656e-01, 7.612023855e-01, 7.572088465e-01, 7.531867990e-01, 7.491363945e-01, 7.450577854e-01, 7.409511254e-01, 7.368165689e-01, 7.326542717e-01, 7.284643904e-01, 7.242470830e-01, 7.200025080e-01, 7.157308253e-01, 7.114321957e-01, 7.071067812e-01, 7.027547445e-01, 6.983762494e-01, 6.939714609e-01, 6.895405447e-01, 6.850836678e-01, 6.806009978e-01, 6.760927036e-01, 6.715589548e-01, 6.669999223e-01, 6.624157776e-01, 6.578066933e-01, 6.531728430e-01, 6.485144010e-01, 6.438315429e-01, 6.391244449e-01, 6.343932842e-01, 6.296382389e-01, 6.248594881e-01, 6.200572118e-01, 6.152315906e-01, 6.103828063e-01, 6.055110414e-01, 6.006164794e-01, 5.956993045e-01, 5.907597019e-01, 5.857978575e-01, 5.808139581e-01, 5.758081914e-01, 5.707807459e-01, 5.657318108e-01, 5.606615762e-01, 5.555702330e-01, 5.504579729e-01, 5.453249884e-01, 5.401714727e-01, 5.349976199e-01, 5.298036247e-01, 5.245896827e-01, 5.193559902e-01, 5.141027442e-01, 5.088301425e-01, 5.035383837e-01, 4.982276670e-01, 4.928981922e-01, 4.875501601e-01, 4.821837721e-01, 4.767992301e-01, 4.713967368e-01, 4.659764958e-01, 4.605387110e-01, 4.550835871e-01, 4.496113297e-01, 4.441221446e-01, 4.386162385e-01, 4.330938189e-01, 4.275550934e-01, 4.220002708e-01, 4.164295601e-01, 4.108431711e-01, 4.052413140e-01, 3.996241998e-01, 3.939920401e-01, 3.883450467e-01, 3.826834324e-01, 3.770074102e-01, 3.713171940e-01, 3.656129978e-01, 3.598950365e-01, 3.541635254e-01, 3.484186802e-01, 3.426607173e-01, 3.368898534e-01, 3.311063058e-01, 3.253102922e-01, 3.195020308e-01, 3.136817404e-01, 3.078496400e-01, 3.020059493e-01, 2.961508882e-01, 2.902846773e-01, 2.844075372e-01, 2.785196894e-01, 2.726213554e-01, 2.667127575e-01, 2.607941179e-01, 2.548656596e-01, 2.489276057e-01, 2.429801799e-01, 2.370236060e-01, 2.310581083e-01, 2.250839114e-01, 2.191012402e-01, 2.131103199e-01, 2.071113762e-01, 2.011046348e-01, 1.950903220e-01, 1.890686641e-01, 1.830398880e-01, 1.770042204e-01, 1.709618888e-01, 1.649131205e-01, 1.588581433e-01, 1.527971853e-01, 1.467304745e-01, 1.406582393e-01, 1.345807085e-01, 1.284981108e-01, 1.224106752e-01, 1.163186309e-01, 1.102222073e-01, 1.041216339e-01, 9.801714033e-02, 9.190895650e-02, 8.579731234e-02, 7.968243797e-02, 7.356456360e-02, 6.744391956e-02, 6.132073630e-02, 5.519524435e-02, 4.906767433e-02, 4.293825693e-02, 3.680722294e-02, 3.067480318e-02, 2.454122852e-02, 1.840672991e-02, 1.227153829e-02, 6.135884649e-03, -8.704110566e-18, }; const float wav_sine_q[] = { -1.000000000e+00, -9.999811753e-01, -9.999247018e-01, -9.998305818e-01, -9.996988187e-01, -9.995294175e-01, -9.993223846e-01, -9.990777278e-01, -9.987954562e-01, -9.984755806e-01, -9.981181129e-01, -9.977230666e-01, -9.972904567e-01, -9.968202993e-01, -9.963126122e-01, -9.957674145e-01, -9.951847267e-01, -9.945645707e-01, -9.939069700e-01, -9.932119492e-01, -9.924795346e-01, -9.917097537e-01, -9.909026354e-01, -9.900582103e-01, -9.891765100e-01, -9.882575677e-01, -9.873014182e-01, -9.863080972e-01, -9.852776424e-01, -9.842100924e-01, -9.831054874e-01, -9.819638691e-01, -9.807852804e-01, -9.795697657e-01, -9.783173707e-01, -9.770281427e-01, -9.757021300e-01, -9.743393828e-01, -9.729399522e-01, -9.715038910e-01, -9.700312532e-01, -9.685220943e-01, -9.669764710e-01, -9.653944417e-01, -9.637760658e-01, -9.621214043e-01, -9.604305194e-01, -9.587034749e-01, -9.569403357e-01, -9.551411683e-01, -9.533060404e-01, -9.514350210e-01, -9.495281806e-01, -9.475855910e-01, -9.456073254e-01, -9.435934582e-01, -9.415440652e-01, -9.394592236e-01, -9.373390119e-01, -9.351835099e-01, -9.329927988e-01, -9.307669611e-01, -9.285060805e-01, -9.262102421e-01, -9.238795325e-01, -9.215140393e-01, -9.191138517e-01, -9.166790599e-01, -9.142097557e-01, -9.117060320e-01, -9.091679831e-01, -9.065957045e-01, -9.039892931e-01, -9.013488470e-01, -8.986744657e-01, -8.959662498e-01, -8.932243012e-01, -8.904487232e-01, -8.876396204e-01, -8.847970984e-01, -8.819212643e-01, -8.790122264e-01, -8.760700942e-01, -8.730949784e-01, -8.700869911e-01, -8.670462455e-01, -8.639728561e-01, -8.608669386e-01, -8.577286100e-01, -8.545579884e-01, -8.513551931e-01, -8.481203448e-01, -8.448535652e-01, -8.415549774e-01, -8.382247056e-01, -8.348628750e-01, -8.314696123e-01, -8.280450453e-01, -8.245893028e-01, -8.211025150e-01, -8.175848132e-01, -8.140363297e-01, -8.104571983e-01, -8.068475535e-01, -8.032075315e-01, -7.995372691e-01, -7.958369046e-01, -7.921065773e-01, -7.883464276e-01, -7.845565972e-01, -7.807372286e-01, -7.768884657e-01, -7.730104534e-01, -7.691033376e-01, -7.651672656e-01, -7.612023855e-01, -7.572088465e-01, -7.531867990e-01, -7.491363945e-01, -7.450577854e-01, -7.409511254e-01, -7.368165689e-01, -7.326542717e-01, -7.284643904e-01, -7.242470830e-01, -7.200025080e-01, -7.157308253e-01, -7.114321957e-01, -7.071067812e-01, -7.027547445e-01, -6.983762494e-01, -6.939714609e-01, -6.895405447e-01, -6.850836678e-01, -6.806009978e-01, -6.760927036e-01, -6.715589548e-01, -6.669999223e-01, -6.624157776e-01, -6.578066933e-01, -6.531728430e-01, -6.485144010e-01, -6.438315429e-01, -6.391244449e-01, -6.343932842e-01, -6.296382389e-01, -6.248594881e-01, -6.200572118e-01, -6.152315906e-01, -6.103828063e-01, -6.055110414e-01, -6.006164794e-01, -5.956993045e-01, -5.907597019e-01, -5.857978575e-01, -5.808139581e-01, -5.758081914e-01, -5.707807459e-01, -5.657318108e-01, -5.606615762e-01, -5.555702330e-01, -5.504579729e-01, -5.453249884e-01, -5.401714727e-01, -5.349976199e-01, -5.298036247e-01, -5.245896827e-01, -5.193559902e-01, -5.141027442e-01, -5.088301425e-01, -5.035383837e-01, -4.982276670e-01, -4.928981922e-01, -4.875501601e-01, -4.821837721e-01, -4.767992301e-01, -4.713967368e-01, -4.659764958e-01, -4.605387110e-01, -4.550835871e-01, -4.496113297e-01, -4.441221446e-01, -4.386162385e-01, -4.330938189e-01, -4.275550934e-01, -4.220002708e-01, -4.164295601e-01, -4.108431711e-01, -4.052413140e-01, -3.996241998e-01, -3.939920401e-01, -3.883450467e-01, -3.826834324e-01, -3.770074102e-01, -3.713171940e-01, -3.656129978e-01, -3.598950365e-01, -3.541635254e-01, -3.484186802e-01, -3.426607173e-01, -3.368898534e-01, -3.311063058e-01, -3.253102922e-01, -3.195020308e-01, -3.136817404e-01, -3.078496400e-01, -3.020059493e-01, -2.961508882e-01, -2.902846773e-01, -2.844075372e-01, -2.785196894e-01, -2.726213554e-01, -2.667127575e-01, -2.607941179e-01, -2.548656596e-01, -2.489276057e-01, -2.429801799e-01, -2.370236060e-01, -2.310581083e-01, -2.250839114e-01, -2.191012402e-01, -2.131103199e-01, -2.071113762e-01, -2.011046348e-01, -1.950903220e-01, -1.890686641e-01, -1.830398880e-01, -1.770042204e-01, -1.709618888e-01, -1.649131205e-01, -1.588581433e-01, -1.527971853e-01, -1.467304745e-01, -1.406582393e-01, -1.345807085e-01, -1.284981108e-01, -1.224106752e-01, -1.163186309e-01, -1.102222073e-01, -1.041216339e-01, -9.801714033e-02, -9.190895650e-02, -8.579731234e-02, -7.968243797e-02, -7.356456360e-02, -6.744391956e-02, -6.132073630e-02, -5.519524435e-02, -4.906767433e-02, -4.293825693e-02, -3.680722294e-02, -3.067480318e-02, -2.454122852e-02, -1.840672991e-02, -1.227153829e-02, -6.135884649e-03, -3.627591754e-16, 6.135884649e-03, 1.227153829e-02, 1.840672991e-02, 2.454122852e-02, 3.067480318e-02, 3.680722294e-02, 4.293825693e-02, 4.906767433e-02, 5.519524435e-02, 6.132073630e-02, 6.744391956e-02, 7.356456360e-02, 7.968243797e-02, 8.579731234e-02, 9.190895650e-02, 9.801714033e-02, 1.041216339e-01, 1.102222073e-01, 1.163186309e-01, 1.224106752e-01, 1.284981108e-01, 1.345807085e-01, 1.406582393e-01, 1.467304745e-01, 1.527971853e-01, 1.588581433e-01, 1.649131205e-01, 1.709618888e-01, 1.770042204e-01, 1.830398880e-01, 1.890686641e-01, 1.950903220e-01, 2.011046348e-01, 2.071113762e-01, 2.131103199e-01, 2.191012402e-01, 2.250839114e-01, 2.310581083e-01, 2.370236060e-01, 2.429801799e-01, 2.489276057e-01, 2.548656596e-01, 2.607941179e-01, 2.667127575e-01, 2.726213554e-01, 2.785196894e-01, 2.844075372e-01, 2.902846773e-01, 2.961508882e-01, 3.020059493e-01, 3.078496400e-01, 3.136817404e-01, 3.195020308e-01, 3.253102922e-01, 3.311063058e-01, 3.368898534e-01, 3.426607173e-01, 3.484186802e-01, 3.541635254e-01, 3.598950365e-01, 3.656129978e-01, 3.713171940e-01, 3.770074102e-01, 3.826834324e-01, 3.883450467e-01, 3.939920401e-01, 3.996241998e-01, 4.052413140e-01, 4.108431711e-01, 4.164295601e-01, 4.220002708e-01, 4.275550934e-01, 4.330938189e-01, 4.386162385e-01, 4.441221446e-01, 4.496113297e-01, 4.550835871e-01, 4.605387110e-01, 4.659764958e-01, 4.713967368e-01, 4.767992301e-01, 4.821837721e-01, 4.875501601e-01, 4.928981922e-01, 4.982276670e-01, 5.035383837e-01, 5.088301425e-01, 5.141027442e-01, 5.193559902e-01, 5.245896827e-01, 5.298036247e-01, 5.349976199e-01, 5.401714727e-01, 5.453249884e-01, 5.504579729e-01, 5.555702330e-01, 5.606615762e-01, 5.657318108e-01, 5.707807459e-01, 5.758081914e-01, 5.808139581e-01, 5.857978575e-01, 5.907597019e-01, 5.956993045e-01, 6.006164794e-01, 6.055110414e-01, 6.103828063e-01, 6.152315906e-01, 6.200572118e-01, 6.248594881e-01, 6.296382389e-01, 6.343932842e-01, 6.391244449e-01, 6.438315429e-01, 6.485144010e-01, 6.531728430e-01, 6.578066933e-01, 6.624157776e-01, 6.669999223e-01, 6.715589548e-01, 6.760927036e-01, 6.806009978e-01, 6.850836678e-01, 6.895405447e-01, 6.939714609e-01, 6.983762494e-01, 7.027547445e-01, 7.071067812e-01, 7.114321957e-01, 7.157308253e-01, 7.200025080e-01, 7.242470830e-01, 7.284643904e-01, 7.326542717e-01, 7.368165689e-01, 7.409511254e-01, 7.450577854e-01, 7.491363945e-01, 7.531867990e-01, 7.572088465e-01, 7.612023855e-01, 7.651672656e-01, 7.691033376e-01, 7.730104534e-01, 7.768884657e-01, 7.807372286e-01, 7.845565972e-01, 7.883464276e-01, 7.921065773e-01, 7.958369046e-01, 7.995372691e-01, 8.032075315e-01, 8.068475535e-01, 8.104571983e-01, 8.140363297e-01, 8.175848132e-01, 8.211025150e-01, 8.245893028e-01, 8.280450453e-01, 8.314696123e-01, 8.348628750e-01, 8.382247056e-01, 8.415549774e-01, 8.448535652e-01, 8.481203448e-01, 8.513551931e-01, 8.545579884e-01, 8.577286100e-01, 8.608669386e-01, 8.639728561e-01, 8.670462455e-01, 8.700869911e-01, 8.730949784e-01, 8.760700942e-01, 8.790122264e-01, 8.819212643e-01, 8.847970984e-01, 8.876396204e-01, 8.904487232e-01, 8.932243012e-01, 8.959662498e-01, 8.986744657e-01, 9.013488470e-01, 9.039892931e-01, 9.065957045e-01, 9.091679831e-01, 9.117060320e-01, 9.142097557e-01, 9.166790599e-01, 9.191138517e-01, 9.215140393e-01, 9.238795325e-01, 9.262102421e-01, 9.285060805e-01, 9.307669611e-01, 9.329927988e-01, 9.351835099e-01, 9.373390119e-01, 9.394592236e-01, 9.415440652e-01, 9.435934582e-01, 9.456073254e-01, 9.475855910e-01, 9.495281806e-01, 9.514350210e-01, 9.533060404e-01, 9.551411683e-01, 9.569403357e-01, 9.587034749e-01, 9.604305194e-01, 9.621214043e-01, 9.637760658e-01, 9.653944417e-01, 9.669764710e-01, 9.685220943e-01, 9.700312532e-01, 9.715038910e-01, 9.729399522e-01, 9.743393828e-01, 9.757021300e-01, 9.770281427e-01, 9.783173707e-01, 9.795697657e-01, 9.807852804e-01, 9.819638691e-01, 9.831054874e-01, 9.842100924e-01, 9.852776424e-01, 9.863080972e-01, 9.873014182e-01, 9.882575677e-01, 9.891765100e-01, 9.900582103e-01, 9.909026354e-01, 9.917097537e-01, 9.924795346e-01, 9.932119492e-01, 9.939069700e-01, 9.945645707e-01, 9.951847267e-01, 9.957674145e-01, 9.963126122e-01, 9.968202993e-01, 9.972904567e-01, 9.977230666e-01, 9.981181129e-01, 9.984755806e-01, 9.987954562e-01, 9.990777278e-01, 9.993223846e-01, 9.995294175e-01, 9.996988187e-01, 9.998305818e-01, 9.999247018e-01, 9.999811753e-01, 1.000000000e+00, 9.999811753e-01, 9.999247018e-01, 9.998305818e-01, 9.996988187e-01, 9.995294175e-01, 9.993223846e-01, 9.990777278e-01, 9.987954562e-01, 9.984755806e-01, 9.981181129e-01, 9.977230666e-01, 9.972904567e-01, 9.968202993e-01, 9.963126122e-01, 9.957674145e-01, 9.951847267e-01, 9.945645707e-01, 9.939069700e-01, 9.932119492e-01, 9.924795346e-01, 9.917097537e-01, 9.909026354e-01, 9.900582103e-01, 9.891765100e-01, 9.882575677e-01, 9.873014182e-01, 9.863080972e-01, 9.852776424e-01, 9.842100924e-01, 9.831054874e-01, 9.819638691e-01, 9.807852804e-01, 9.795697657e-01, 9.783173707e-01, 9.770281427e-01, 9.757021300e-01, 9.743393828e-01, 9.729399522e-01, 9.715038910e-01, 9.700312532e-01, 9.685220943e-01, 9.669764710e-01, 9.653944417e-01, 9.637760658e-01, 9.621214043e-01, 9.604305194e-01, 9.587034749e-01, 9.569403357e-01, 9.551411683e-01, 9.533060404e-01, 9.514350210e-01, 9.495281806e-01, 9.475855910e-01, 9.456073254e-01, 9.435934582e-01, 9.415440652e-01, 9.394592236e-01, 9.373390119e-01, 9.351835099e-01, 9.329927988e-01, 9.307669611e-01, 9.285060805e-01, 9.262102421e-01, 9.238795325e-01, 9.215140393e-01, 9.191138517e-01, 9.166790599e-01, 9.142097557e-01, 9.117060320e-01, 9.091679831e-01, 9.065957045e-01, 9.039892931e-01, 9.013488470e-01, 8.986744657e-01, 8.959662498e-01, 8.932243012e-01, 8.904487232e-01, 8.876396204e-01, 8.847970984e-01, 8.819212643e-01, 8.790122264e-01, 8.760700942e-01, 8.730949784e-01, 8.700869911e-01, 8.670462455e-01, 8.639728561e-01, 8.608669386e-01, 8.577286100e-01, 8.545579884e-01, 8.513551931e-01, 8.481203448e-01, 8.448535652e-01, 8.415549774e-01, 8.382247056e-01, 8.348628750e-01, 8.314696123e-01, 8.280450453e-01, 8.245893028e-01, 8.211025150e-01, 8.175848132e-01, 8.140363297e-01, 8.104571983e-01, 8.068475535e-01, 8.032075315e-01, 7.995372691e-01, 7.958369046e-01, 7.921065773e-01, 7.883464276e-01, 7.845565972e-01, 7.807372286e-01, 7.768884657e-01, 7.730104534e-01, 7.691033376e-01, 7.651672656e-01, 7.612023855e-01, 7.572088465e-01, 7.531867990e-01, 7.491363945e-01, 7.450577854e-01, 7.409511254e-01, 7.368165689e-01, 7.326542717e-01, 7.284643904e-01, 7.242470830e-01, 7.200025080e-01, 7.157308253e-01, 7.114321957e-01, 7.071067812e-01, 7.027547445e-01, 6.983762494e-01, 6.939714609e-01, 6.895405447e-01, 6.850836678e-01, 6.806009978e-01, 6.760927036e-01, 6.715589548e-01, 6.669999223e-01, 6.624157776e-01, 6.578066933e-01, 6.531728430e-01, 6.485144010e-01, 6.438315429e-01, 6.391244449e-01, 6.343932842e-01, 6.296382389e-01, 6.248594881e-01, 6.200572118e-01, 6.152315906e-01, 6.103828063e-01, 6.055110414e-01, 6.006164794e-01, 5.956993045e-01, 5.907597019e-01, 5.857978575e-01, 5.808139581e-01, 5.758081914e-01, 5.707807459e-01, 5.657318108e-01, 5.606615762e-01, 5.555702330e-01, 5.504579729e-01, 5.453249884e-01, 5.401714727e-01, 5.349976199e-01, 5.298036247e-01, 5.245896827e-01, 5.193559902e-01, 5.141027442e-01, 5.088301425e-01, 5.035383837e-01, 4.982276670e-01, 4.928981922e-01, 4.875501601e-01, 4.821837721e-01, 4.767992301e-01, 4.713967368e-01, 4.659764958e-01, 4.605387110e-01, 4.550835871e-01, 4.496113297e-01, 4.441221446e-01, 4.386162385e-01, 4.330938189e-01, 4.275550934e-01, 4.220002708e-01, 4.164295601e-01, 4.108431711e-01, 4.052413140e-01, 3.996241998e-01, 3.939920401e-01, 3.883450467e-01, 3.826834324e-01, 3.770074102e-01, 3.713171940e-01, 3.656129978e-01, 3.598950365e-01, 3.541635254e-01, 3.484186802e-01, 3.426607173e-01, 3.368898534e-01, 3.311063058e-01, 3.253102922e-01, 3.195020308e-01, 3.136817404e-01, 3.078496400e-01, 3.020059493e-01, 2.961508882e-01, 2.902846773e-01, 2.844075372e-01, 2.785196894e-01, 2.726213554e-01, 2.667127575e-01, 2.607941179e-01, 2.548656596e-01, 2.489276057e-01, 2.429801799e-01, 2.370236060e-01, 2.310581083e-01, 2.250839114e-01, 2.191012402e-01, 2.131103199e-01, 2.071113762e-01, 2.011046348e-01, 1.950903220e-01, 1.890686641e-01, 1.830398880e-01, 1.770042204e-01, 1.709618888e-01, 1.649131205e-01, 1.588581433e-01, 1.527971853e-01, 1.467304745e-01, 1.406582393e-01, 1.345807085e-01, 1.284981108e-01, 1.224106752e-01, 1.163186309e-01, 1.102222073e-01, 1.041216339e-01, 9.801714033e-02, 9.190895650e-02, 8.579731234e-02, 7.968243797e-02, 7.356456360e-02, 6.744391956e-02, 6.132073630e-02, 5.519524435e-02, 4.906767433e-02, 4.293825693e-02, 3.680722294e-02, 3.067480318e-02, 2.454122852e-02, 1.840672991e-02, 1.227153829e-02, 6.135884649e-03, 4.261138617e-16, -6.135884649e-03, -1.227153829e-02, -1.840672991e-02, -2.454122852e-02, -3.067480318e-02, -3.680722294e-02, -4.293825693e-02, -4.906767433e-02, -5.519524435e-02, -6.132073630e-02, -6.744391956e-02, -7.356456360e-02, -7.968243797e-02, -8.579731234e-02, -9.190895650e-02, -9.801714033e-02, -1.041216339e-01, -1.102222073e-01, -1.163186309e-01, -1.224106752e-01, -1.284981108e-01, -1.345807085e-01, -1.406582393e-01, -1.467304745e-01, -1.527971853e-01, -1.588581433e-01, -1.649131205e-01, -1.709618888e-01, -1.770042204e-01, -1.830398880e-01, -1.890686641e-01, -1.950903220e-01, -2.011046348e-01, -2.071113762e-01, -2.131103199e-01, -2.191012402e-01, -2.250839114e-01, -2.310581083e-01, -2.370236060e-01, -2.429801799e-01, -2.489276057e-01, -2.548656596e-01, -2.607941179e-01, -2.667127575e-01, -2.726213554e-01, -2.785196894e-01, -2.844075372e-01, -2.902846773e-01, -2.961508882e-01, -3.020059493e-01, -3.078496400e-01, -3.136817404e-01, -3.195020308e-01, -3.253102922e-01, -3.311063058e-01, -3.368898534e-01, -3.426607173e-01, -3.484186802e-01, -3.541635254e-01, -3.598950365e-01, -3.656129978e-01, -3.713171940e-01, -3.770074102e-01, -3.826834324e-01, -3.883450467e-01, -3.939920401e-01, -3.996241998e-01, -4.052413140e-01, -4.108431711e-01, -4.164295601e-01, -4.220002708e-01, -4.275550934e-01, -4.330938189e-01, -4.386162385e-01, -4.441221446e-01, -4.496113297e-01, -4.550835871e-01, -4.605387110e-01, -4.659764958e-01, -4.713967368e-01, -4.767992301e-01, -4.821837721e-01, -4.875501601e-01, -4.928981922e-01, -4.982276670e-01, -5.035383837e-01, -5.088301425e-01, -5.141027442e-01, -5.193559902e-01, -5.245896827e-01, -5.298036247e-01, -5.349976199e-01, -5.401714727e-01, -5.453249884e-01, -5.504579729e-01, -5.555702330e-01, -5.606615762e-01, -5.657318108e-01, -5.707807459e-01, -5.758081914e-01, -5.808139581e-01, -5.857978575e-01, -5.907597019e-01, -5.956993045e-01, -6.006164794e-01, -6.055110414e-01, -6.103828063e-01, -6.152315906e-01, -6.200572118e-01, -6.248594881e-01, -6.296382389e-01, -6.343932842e-01, -6.391244449e-01, -6.438315429e-01, -6.485144010e-01, -6.531728430e-01, -6.578066933e-01, -6.624157776e-01, -6.669999223e-01, -6.715589548e-01, -6.760927036e-01, -6.806009978e-01, -6.850836678e-01, -6.895405447e-01, -6.939714609e-01, -6.983762494e-01, -7.027547445e-01, -7.071067812e-01, -7.114321957e-01, -7.157308253e-01, -7.200025080e-01, -7.242470830e-01, -7.284643904e-01, -7.326542717e-01, -7.368165689e-01, -7.409511254e-01, -7.450577854e-01, -7.491363945e-01, -7.531867990e-01, -7.572088465e-01, -7.612023855e-01, -7.651672656e-01, -7.691033376e-01, -7.730104534e-01, -7.768884657e-01, -7.807372286e-01, -7.845565972e-01, -7.883464276e-01, -7.921065773e-01, -7.958369046e-01, -7.995372691e-01, -8.032075315e-01, -8.068475535e-01, -8.104571983e-01, -8.140363297e-01, -8.175848132e-01, -8.211025150e-01, -8.245893028e-01, -8.280450453e-01, -8.314696123e-01, -8.348628750e-01, -8.382247056e-01, -8.415549774e-01, -8.448535652e-01, -8.481203448e-01, -8.513551931e-01, -8.545579884e-01, -8.577286100e-01, -8.608669386e-01, -8.639728561e-01, -8.670462455e-01, -8.700869911e-01, -8.730949784e-01, -8.760700942e-01, -8.790122264e-01, -8.819212643e-01, -8.847970984e-01, -8.876396204e-01, -8.904487232e-01, -8.932243012e-01, -8.959662498e-01, -8.986744657e-01, -9.013488470e-01, -9.039892931e-01, -9.065957045e-01, -9.091679831e-01, -9.117060320e-01, -9.142097557e-01, -9.166790599e-01, -9.191138517e-01, -9.215140393e-01, -9.238795325e-01, -9.262102421e-01, -9.285060805e-01, -9.307669611e-01, -9.329927988e-01, -9.351835099e-01, -9.373390119e-01, -9.394592236e-01, -9.415440652e-01, -9.435934582e-01, -9.456073254e-01, -9.475855910e-01, -9.495281806e-01, -9.514350210e-01, -9.533060404e-01, -9.551411683e-01, -9.569403357e-01, -9.587034749e-01, -9.604305194e-01, -9.621214043e-01, -9.637760658e-01, -9.653944417e-01, -9.669764710e-01, -9.685220943e-01, -9.700312532e-01, -9.715038910e-01, -9.729399522e-01, -9.743393828e-01, -9.757021300e-01, -9.770281427e-01, -9.783173707e-01, -9.795697657e-01, -9.807852804e-01, -9.819638691e-01, -9.831054874e-01, -9.842100924e-01, -9.852776424e-01, -9.863080972e-01, -9.873014182e-01, -9.882575677e-01, -9.891765100e-01, -9.900582103e-01, -9.909026354e-01, -9.917097537e-01, -9.924795346e-01, -9.932119492e-01, -9.939069700e-01, -9.945645707e-01, -9.951847267e-01, -9.957674145e-01, -9.963126122e-01, -9.968202993e-01, -9.972904567e-01, -9.977230666e-01, -9.981181129e-01, -9.984755806e-01, -9.987954562e-01, -9.990777278e-01, -9.993223846e-01, -9.995294175e-01, -9.996988187e-01, -9.998305818e-01, -9.999247018e-01, -9.999811753e-01, -1.000000000e+00, }; const float wav_harmonics_i[] = { -2.478929878e-19, 1.715531411e-03, 3.423631606e-03, 5.116876885e-03, 6.787858584e-03, 8.429190567e-03, 1.003351671e-02, 1.159351833e-02, 1.310192162e-02, 1.455150503e-02, 1.593510654e-02, 1.724563095e-02, 1.847605712e-02, 1.961944502e-02, 2.066894285e-02, 2.161779397e-02, 2.245934381e-02, 2.318704662e-02, 2.379447218e-02, 2.427531232e-02, 2.462338744e-02, 2.483265278e-02, 2.489720467e-02, 2.481128656e-02, 2.456929495e-02, 2.416578521e-02, 2.359547718e-02, 2.285326066e-02, 2.193420069e-02, 2.083354276e-02, 1.954671772e-02, 1.806934664e-02, 1.639724537e-02, 1.452642902e-02, 1.245311616e-02, 1.017373293e-02, 7.684916836e-03, 4.983520421e-03, 2.066614721e-03, -1.068507503e-03, -4.424328739e-03, -8.003103907e-03, -1.180685776e-02, -1.583738252e-02, -2.009623570e-02, -2.458473818e-02, -2.930397250e-02, -3.425478139e-02, -3.943776648e-02, -4.485328735e-02, -5.050146065e-02, -5.638215961e-02, -6.249501367e-02, -6.883940840e-02, -7.541448566e-02, -8.221914393e-02, -8.925203892e-02, -9.651158443e-02, -1.039959534e-01, -1.117030792e-01, -1.196306572e-01, -1.277761463e-01, -1.361367714e-01, -1.447095251e-01, -1.534911702e-01, -1.624782427e-01, -1.716670543e-01, -1.810536956e-01, -1.906340394e-01, -2.004037442e-01, -2.103582579e-01, -2.204928215e-01, -2.308024736e-01, -2.412820545e-01, -2.519262106e-01, -2.627293992e-01, -2.736858931e-01, -2.847897863e-01, -2.960349984e-01, -3.074152803e-01, -3.189242201e-01, -3.305552482e-01, -3.423016434e-01, -3.541565393e-01, -3.661129295e-01, -3.781636749e-01, -3.903015095e-01, -4.025190469e-01, -4.148087873e-01, -4.271631241e-01, -4.395743507e-01, -4.520346673e-01, -4.645361886e-01, -4.770709500e-01, -4.896309157e-01, -5.022079855e-01, -5.147940021e-01, -5.273807589e-01, -5.399600071e-01, -5.525234636e-01, -5.650628180e-01, -5.775697407e-01, -5.900358903e-01, -6.024529211e-01, -6.148124909e-01, -6.271062687e-01, -6.393259421e-01, -6.514632249e-01, -6.635098650e-01, -6.754576517e-01, -6.872984234e-01, -6.990240749e-01, -7.106265649e-01, -7.220979236e-01, -7.334302598e-01, -7.446157683e-01, -7.556467367e-01, -7.665155533e-01, -7.772147133e-01, -7.877368261e-01, -7.980746222e-01, -8.082209594e-01, -8.181688303e-01, -8.279113678e-01, -8.374418521e-01, -8.467537166e-01, -8.558405540e-01, -8.646961224e-01, -8.733143510e-01, -8.816893456e-01, -8.898153941e-01, -8.976869720e-01, -9.052987473e-01, -9.126455855e-01, -9.197225544e-01, -9.265249287e-01, -9.330481943e-01, -9.392880528e-01, -9.452404250e-01, -9.509014551e-01, -9.562675143e-01, -9.613352037e-01, -9.661013583e-01, -9.705630493e-01, -9.747175871e-01, -9.785625236e-01, -9.820956551e-01, -9.853150237e-01, -9.882189194e-01, -9.908058819e-01, -9.930747019e-01, -9.950244221e-01, -9.966543385e-01, -9.979640005e-01, -9.989532121e-01, -9.996220316e-01, -9.999707719e-01, -1.000000000e+00, -9.997105368e-01, -9.991034563e-01, -9.981800847e-01, -9.969419989e-01, -9.953910257e-01, -9.935292398e-01, -9.913589620e-01, -9.888827571e-01, -9.861034316e-01, -9.830240314e-01, -9.796478387e-01, -9.759783691e-01, -9.720193688e-01, -9.677748106e-01, -9.632488910e-01, -9.584460257e-01, -9.533708460e-01, -9.480281947e-01, -9.424231212e-01, -9.365608775e-01, -9.304469131e-01, -9.240868699e-01, -9.174865775e-01, -9.106520476e-01, -9.035894686e-01, -8.963051999e-01, -8.888057662e-01, -8.810978518e-01, -8.731882937e-01, -8.650840766e-01, -8.567923253e-01, -8.483202991e-01, -8.396753849e-01, -8.308650903e-01, -8.218970370e-01, -8.127789538e-01, -8.035186697e-01, -7.941241064e-01, -7.846032715e-01, -7.749642509e-01, -7.652152017e-01, -7.553643448e-01, -7.454199572e-01, -7.353903645e-01, -7.252839336e-01, -7.151090649e-01, -7.048741847e-01, -6.945877375e-01, -6.842581785e-01, -6.738939660e-01, -6.635035532e-01, -6.530953814e-01, -6.426778714e-01, -6.322594168e-01, -6.218483758e-01, -6.114530638e-01, -6.010817459e-01, -5.907426297e-01, -5.804438574e-01, -5.701934989e-01, -5.599995442e-01, -5.498698966e-01, -5.398123653e-01, -5.298346583e-01, -5.199443758e-01, -5.101490034e-01, -5.004559050e-01, -4.908723165e-01, -4.814053395e-01, -4.720619346e-01, -4.628489155e-01, -4.537729428e-01, -4.448405182e-01, -4.360579786e-01, -4.274314906e-01, -4.189670451e-01, -4.106704521e-01, -4.025473352e-01, -3.946031273e-01, -3.868430654e-01, -3.792721862e-01, -3.718953217e-01, -3.647170952e-01, -3.577419171e-01, -3.509739815e-01, -3.444172620e-01, -3.380755092e-01, -3.319522466e-01, -3.260507687e-01, -3.203741375e-01, -3.149251804e-01, -3.097064877e-01, -3.047204110e-01, -2.999690608e-01, -2.954543053e-01, -2.911777690e-01, -2.871408316e-01, -2.833446269e-01, -2.797900423e-01, -2.764777185e-01, -2.734080489e-01, -2.705811801e-01, -2.679970119e-01, -2.656551979e-01, -2.635551463e-01, -2.616960204e-01, -2.600767407e-01, -2.586959854e-01, -2.575521927e-01, -2.566435624e-01, -2.559680578e-01, -2.555234087e-01, -2.553071133e-01, -2.553164411e-01, -2.555484363e-01, -2.559999202e-01, -2.566674956e-01, -2.575475496e-01, -2.586362577e-01, -2.599295879e-01, -2.614233047e-01, -2.631129738e-01, -2.649939663e-01, -2.670614639e-01, -2.693104633e-01, -2.717357820e-01, -2.743320628e-01, -2.770937800e-01, -2.800152445e-01, -2.830906097e-01, -2.863138775e-01, -2.896789043e-01, -2.931794070e-01, -2.968089698e-01, -3.005610499e-01, -3.044289847e-01, -3.084059983e-01, -3.124852080e-01, -3.166596315e-01, -3.209221937e-01, -3.252657338e-01, -3.296830124e-01, -3.341667187e-01, -3.387094778e-01, -3.433038580e-01, -3.479423782e-01, -3.526175152e-01, -3.573217114e-01, -3.620473820e-01, -3.667869228e-01, -3.715327174e-01, -3.762771451e-01, -3.810125881e-01, -3.857314392e-01, -3.904261095e-01, -3.950890356e-01, -3.997126870e-01, -4.042895740e-01, -4.088122547e-01, -4.132733424e-01, -4.176655133e-01, -4.219815131e-01, -4.262141645e-01, -4.303563745e-01, -4.344011409e-01, -4.383415597e-01, -4.421708318e-01, -4.458822695e-01, -4.494693033e-01, -4.529254885e-01, -4.562445113e-01, -4.594201954e-01, -4.624465079e-01, -4.653175651e-01, -4.680276390e-01, -4.705711623e-01, -4.729427341e-01, -4.751371257e-01, -4.771492852e-01, -4.789743430e-01, -4.806076165e-01, -4.820446147e-01, -4.832810428e-01, -4.843128067e-01, -4.851360166e-01, -4.857469916e-01, -4.861422629e-01, -4.863185775e-01, -4.862729015e-01, -4.860024235e-01, -4.855045568e-01, -4.847769429e-01, -4.838174532e-01, -4.826241919e-01, -4.811954976e-01, -4.795299452e-01, -4.776263475e-01, -4.754837564e-01, -4.731014642e-01, -4.704790044e-01, -4.676161524e-01, -4.645129257e-01, -4.611695844e-01, -4.575866308e-01, -4.537648094e-01, -4.497051064e-01, -4.454087486e-01, -4.408772028e-01, -4.361121746e-01, -4.311156065e-01, -4.258896768e-01, -4.204367975e-01, -4.147596118e-01, -4.088609926e-01, -4.027440391e-01, -3.964120745e-01, -3.898686430e-01, -3.831175064e-01, -3.761626407e-01, -3.690082328e-01, -3.616586762e-01, -3.541185674e-01, -3.463927014e-01, -3.384860675e-01, -3.304038445e-01, -3.221513963e-01, -3.137342664e-01, -3.051581731e-01, -2.964290044e-01, -2.875528120e-01, -2.785358062e-01, -2.693843497e-01, -2.601049522e-01, -2.507042636e-01, -2.411890686e-01, -2.315662797e-01, -2.218429313e-01, -2.120261727e-01, -2.021232616e-01, -1.921415571e-01, -1.820885133e-01, -1.719716717e-01, -1.617986547e-01, -1.515771578e-01, -1.413149429e-01, -1.310198309e-01, -1.206996942e-01, -1.103624494e-01, -1.000160496e-01, -8.966847739e-02, -7.932773687e-02, -6.900184633e-02, -5.869883061e-02, -4.842671352e-02, -3.819351028e-02, -2.800721994e-02, -1.787581776e-02, -7.807247752e-03, 2.190584936e-03, 1.210982146e-02, 2.194265675e-02, 3.168134691e-02, 4.131821658e-02, 5.084566624e-02, 6.025617941e-02, 6.954232981e-02, 7.869678845e-02, 8.771233060e-02, 9.658184268e-02, 1.052983290e-01, 1.138549187e-01, 1.222448718e-01, 1.304615861e-01, 1.384986035e-01, 1.463496159e-01, 1.540084715e-01, 1.614691806e-01, 1.687259213e-01, 1.757730453e-01, 1.826050833e-01, 1.892167501e-01, 1.956029499e-01, 2.017587813e-01, 2.076795418e-01, 2.133607326e-01, 2.187980628e-01, 2.239874540e-01, 2.289250437e-01, 2.336071897e-01, 2.380304731e-01, 2.421917023e-01, 2.460879157e-01, 2.497163850e-01, 2.530746176e-01, 2.561603596e-01, 2.589715977e-01, 2.615065613e-01, 2.637637248e-01, 2.657418087e-01, 2.674397813e-01, 2.688568599e-01, 2.699925114e-01, 2.708464536e-01, 2.714186551e-01, 2.717093358e-01, 2.717189672e-01, 2.714482715e-01, 2.708982218e-01, 2.700700409e-01, 2.689652009e-01, 2.675854214e-01, 2.659326689e-01, 2.640091544e-01, 2.618173321e-01, 2.593598972e-01, 2.566397834e-01, 2.536601606e-01, 2.504244323e-01, 2.469362322e-01, 2.431994214e-01, 2.392180850e-01, 2.349965281e-01, 2.305392728e-01, 2.258510535e-01, 2.209368127e-01, 2.158016973e-01, 2.104510534e-01, 2.048904215e-01, 1.991255320e-01, 1.931622999e-01, 1.870068192e-01, 1.806653579e-01, 1.741443521e-01, 1.674504002e-01, 1.605902571e-01, 1.535708281e-01, 1.463991627e-01, 1.390824480e-01, 1.316280027e-01, 1.240432700e-01, 1.163358110e-01, 1.085132983e-01, 1.005835084e-01, 9.255431521e-02, 8.443368253e-02, 7.622965712e-02, 6.795036131e-02, 5.960398563e-02, 5.119878143e-02, 4.274305338e-02, 3.424515194e-02, 2.571346581e-02, 1.715641434e-02, 8.582439844e-03, 1.710740969e-16, -8.582439844e-03, -1.715641434e-02, -2.571346581e-02, -3.424515194e-02, -4.274305338e-02, -5.119878143e-02, -5.960398563e-02, -6.795036131e-02, -7.622965712e-02, -8.443368253e-02, -9.255431521e-02, -1.005835084e-01, -1.085132983e-01, -1.163358110e-01, -1.240432700e-01, -1.316280027e-01, -1.390824480e-01, -1.463991627e-01, -1.535708281e-01, -1.605902571e-01, -1.674504002e-01, -1.741443521e-01, -1.806653579e-01, -1.870068192e-01, -1.931622999e-01, -1.991255320e-01, -2.048904215e-01, -2.104510534e-01, -2.158016973e-01, -2.209368127e-01, -2.258510535e-01, -2.305392728e-01, -2.349965281e-01, -2.392180850e-01, -2.431994214e-01, -2.469362322e-01, -2.504244323e-01, -2.536601606e-01, -2.566397834e-01, -2.593598972e-01, -2.618173321e-01, -2.640091544e-01, -2.659326689e-01, -2.675854214e-01, -2.689652009e-01, -2.700700409e-01, -2.708982218e-01, -2.714482715e-01, -2.717189672e-01, -2.717093358e-01, -2.714186551e-01, -2.708464536e-01, -2.699925114e-01, -2.688568599e-01, -2.674397813e-01, -2.657418087e-01, -2.637637248e-01, -2.615065613e-01, -2.589715977e-01, -2.561603596e-01, -2.530746176e-01, -2.497163850e-01, -2.460879157e-01, -2.421917023e-01, -2.380304731e-01, -2.336071897e-01, -2.289250437e-01, -2.239874540e-01, -2.187980628e-01, -2.133607326e-01, -2.076795418e-01, -2.017587813e-01, -1.956029499e-01, -1.892167501e-01, -1.826050833e-01, -1.757730453e-01, -1.687259213e-01, -1.614691806e-01, -1.540084715e-01, -1.463496159e-01, -1.384986035e-01, -1.304615861e-01, -1.222448718e-01, -1.138549187e-01, -1.052983290e-01, -9.658184268e-02, -8.771233060e-02, -7.869678845e-02, -6.954232981e-02, -6.025617941e-02, -5.084566624e-02, -4.131821658e-02, -3.168134691e-02, -2.194265675e-02, -1.210982146e-02, -2.190584936e-03, 7.807247752e-03, 1.787581776e-02, 2.800721994e-02, 3.819351028e-02, 4.842671352e-02, 5.869883061e-02, 6.900184633e-02, 7.932773687e-02, 8.966847739e-02, 1.000160496e-01, 1.103624494e-01, 1.206996942e-01, 1.310198309e-01, 1.413149429e-01, 1.515771578e-01, 1.617986547e-01, 1.719716717e-01, 1.820885133e-01, 1.921415571e-01, 2.021232616e-01, 2.120261727e-01, 2.218429313e-01, 2.315662797e-01, 2.411890686e-01, 2.507042636e-01, 2.601049522e-01, 2.693843497e-01, 2.785358062e-01, 2.875528120e-01, 2.964290044e-01, 3.051581731e-01, 3.137342664e-01, 3.221513963e-01, 3.304038445e-01, 3.384860675e-01, 3.463927014e-01, 3.541185674e-01, 3.616586762e-01, 3.690082328e-01, 3.761626407e-01, 3.831175064e-01, 3.898686430e-01, 3.964120745e-01, 4.027440391e-01, 4.088609926e-01, 4.147596118e-01, 4.204367975e-01, 4.258896768e-01, 4.311156065e-01, 4.361121746e-01, 4.408772028e-01, 4.454087486e-01, 4.497051064e-01, 4.537648094e-01, 4.575866308e-01, 4.611695844e-01, 4.645129257e-01, 4.676161524e-01, 4.704790044e-01, 4.731014642e-01, 4.754837564e-01, 4.776263475e-01, 4.795299452e-01, 4.811954976e-01, 4.826241919e-01, 4.838174532e-01, 4.847769429e-01, 4.855045568e-01, 4.860024235e-01, 4.862729015e-01, 4.863185775e-01, 4.861422629e-01, 4.857469916e-01, 4.851360166e-01, 4.843128067e-01, 4.832810428e-01, 4.820446147e-01, 4.806076165e-01, 4.789743430e-01, 4.771492852e-01, 4.751371257e-01, 4.729427341e-01, 4.705711623e-01, 4.680276390e-01, 4.653175651e-01, 4.624465079e-01, 4.594201954e-01, 4.562445113e-01, 4.529254885e-01, 4.494693033e-01, 4.458822695e-01, 4.421708318e-01, 4.383415597e-01, 4.344011409e-01, 4.303563745e-01, 4.262141645e-01, 4.219815131e-01, 4.176655133e-01, 4.132733424e-01, 4.088122547e-01, 4.042895740e-01, 3.997126870e-01, 3.950890356e-01, 3.904261095e-01, 3.857314392e-01, 3.810125881e-01, 3.762771451e-01, 3.715327174e-01, 3.667869228e-01, 3.620473820e-01, 3.573217114e-01, 3.526175152e-01, 3.479423782e-01, 3.433038580e-01, 3.387094778e-01, 3.341667187e-01, 3.296830124e-01, 3.252657338e-01, 3.209221937e-01, 3.166596315e-01, 3.124852080e-01, 3.084059983e-01, 3.044289847e-01, 3.005610499e-01, 2.968089698e-01, 2.931794070e-01, 2.896789043e-01, 2.863138775e-01, 2.830906097e-01, 2.800152445e-01, 2.770937800e-01, 2.743320628e-01, 2.717357820e-01, 2.693104633e-01, 2.670614639e-01, 2.649939663e-01, 2.631129738e-01, 2.614233047e-01, 2.599295879e-01, 2.586362577e-01, 2.575475496e-01, 2.566674956e-01, 2.559999202e-01, 2.555484363e-01, 2.553164411e-01, 2.553071133e-01, 2.555234087e-01, 2.559680578e-01, 2.566435624e-01, 2.575521927e-01, 2.586959854e-01, 2.600767407e-01, 2.616960204e-01, 2.635551463e-01, 2.656551979e-01, 2.679970119e-01, 2.705811801e-01, 2.734080489e-01, 2.764777185e-01, 2.797900423e-01, 2.833446269e-01, 2.871408316e-01, 2.911777690e-01, 2.954543053e-01, 2.999690608e-01, 3.047204110e-01, 3.097064877e-01, 3.149251804e-01, 3.203741375e-01, 3.260507687e-01, 3.319522466e-01, 3.380755092e-01, 3.444172620e-01, 3.509739815e-01, 3.577419171e-01, 3.647170952e-01, 3.718953217e-01, 3.792721862e-01, 3.868430654e-01, 3.946031273e-01, 4.025473352e-01, 4.106704521e-01, 4.189670451e-01, 4.274314906e-01, 4.360579786e-01, 4.448405182e-01, 4.537729428e-01, 4.628489155e-01, 4.720619346e-01, 4.814053395e-01, 4.908723165e-01, 5.004559050e-01, 5.101490034e-01, 5.199443758e-01, 5.298346583e-01, 5.398123653e-01, 5.498698966e-01, 5.599995442e-01, 5.701934989e-01, 5.804438574e-01, 5.907426297e-01, 6.010817459e-01, 6.114530638e-01, 6.218483758e-01, 6.322594168e-01, 6.426778714e-01, 6.530953814e-01, 6.635035532e-01, 6.738939660e-01, 6.842581785e-01, 6.945877375e-01, 7.048741847e-01, 7.151090649e-01, 7.252839336e-01, 7.353903645e-01, 7.454199572e-01, 7.553643448e-01, 7.652152017e-01, 7.749642509e-01, 7.846032715e-01, 7.941241064e-01, 8.035186697e-01, 8.127789538e-01, 8.218970370e-01, 8.308650903e-01, 8.396753849e-01, 8.483202991e-01, 8.567923253e-01, 8.650840766e-01, 8.731882937e-01, 8.810978518e-01, 8.888057662e-01, 8.963051999e-01, 9.035894686e-01, 9.106520476e-01, 9.174865775e-01, 9.240868699e-01, 9.304469131e-01, 9.365608775e-01, 9.424231212e-01, 9.480281947e-01, 9.533708460e-01, 9.584460257e-01, 9.632488910e-01, 9.677748106e-01, 9.720193688e-01, 9.759783691e-01, 9.796478387e-01, 9.830240314e-01, 9.861034316e-01, 9.888827571e-01, 9.913589620e-01, 9.935292398e-01, 9.953910257e-01, 9.969419989e-01, 9.981800847e-01, 9.991034563e-01, 9.997105368e-01, 1.000000000e+00, 9.999707719e-01, 9.996220316e-01, 9.989532121e-01, 9.979640005e-01, 9.966543385e-01, 9.950244221e-01, 9.930747019e-01, 9.908058819e-01, 9.882189194e-01, 9.853150237e-01, 9.820956551e-01, 9.785625236e-01, 9.747175871e-01, 9.705630493e-01, 9.661013583e-01, 9.613352037e-01, 9.562675143e-01, 9.509014551e-01, 9.452404250e-01, 9.392880528e-01, 9.330481943e-01, 9.265249287e-01, 9.197225544e-01, 9.126455855e-01, 9.052987473e-01, 8.976869720e-01, 8.898153941e-01, 8.816893456e-01, 8.733143510e-01, 8.646961224e-01, 8.558405540e-01, 8.467537166e-01, 8.374418521e-01, 8.279113678e-01, 8.181688303e-01, 8.082209594e-01, 7.980746222e-01, 7.877368261e-01, 7.772147133e-01, 7.665155533e-01, 7.556467367e-01, 7.446157683e-01, 7.334302598e-01, 7.220979236e-01, 7.106265649e-01, 6.990240749e-01, 6.872984234e-01, 6.754576517e-01, 6.635098650e-01, 6.514632249e-01, 6.393259421e-01, 6.271062687e-01, 6.148124909e-01, 6.024529211e-01, 5.900358903e-01, 5.775697407e-01, 5.650628180e-01, 5.525234636e-01, 5.399600071e-01, 5.273807589e-01, 5.147940021e-01, 5.022079855e-01, 4.896309157e-01, 4.770709500e-01, 4.645361886e-01, 4.520346673e-01, 4.395743507e-01, 4.271631241e-01, 4.148087873e-01, 4.025190469e-01, 3.903015095e-01, 3.781636749e-01, 3.661129295e-01, 3.541565393e-01, 3.423016434e-01, 3.305552482e-01, 3.189242201e-01, 3.074152803e-01, 2.960349984e-01, 2.847897863e-01, 2.736858931e-01, 2.627293992e-01, 2.519262106e-01, 2.412820545e-01, 2.308024736e-01, 2.204928215e-01, 2.103582579e-01, 2.004037442e-01, 1.906340394e-01, 1.810536956e-01, 1.716670543e-01, 1.624782427e-01, 1.534911702e-01, 1.447095251e-01, 1.361367714e-01, 1.277761463e-01, 1.196306572e-01, 1.117030792e-01, 1.039959534e-01, 9.651158443e-02, 8.925203892e-02, 8.221914393e-02, 7.541448566e-02, 6.883940840e-02, 6.249501367e-02, 5.638215961e-02, 5.050146065e-02, 4.485328735e-02, 3.943776648e-02, 3.425478139e-02, 2.930397250e-02, 2.458473818e-02, 2.009623570e-02, 1.583738252e-02, 1.180685776e-02, 8.003103907e-03, 4.424328739e-03, 1.068507503e-03, -2.066614721e-03, -4.983520421e-03, -7.684916836e-03, -1.017373293e-02, -1.245311616e-02, -1.452642902e-02, -1.639724537e-02, -1.806934664e-02, -1.954671772e-02, -2.083354276e-02, -2.193420069e-02, -2.285326066e-02, -2.359547718e-02, -2.416578521e-02, -2.456929495e-02, -2.481128656e-02, -2.489720467e-02, -2.483265278e-02, -2.462338744e-02, -2.427531232e-02, -2.379447218e-02, -2.318704662e-02, -2.245934381e-02, -2.161779397e-02, -2.066894285e-02, -1.961944502e-02, -1.847605712e-02, -1.724563095e-02, -1.593510654e-02, -1.455150503e-02, -1.310192162e-02, -1.159351833e-02, -1.003351671e-02, -8.429190567e-03, -6.787858584e-03, -5.116876885e-03, -3.423631606e-03, -1.715531411e-03, -2.478929878e-19, }; const float wav_harmonics_q[] = { -5.595800846e-01, -5.596801473e-01, -5.599802150e-01, -5.604799268e-01, -5.611786816e-01, -5.620756384e-01, -5.631697177e-01, -5.644596020e-01, -5.659437373e-01, -5.676203347e-01, -5.694873717e-01, -5.715425948e-01, -5.737835211e-01, -5.762074410e-01, -5.788114207e-01, -5.815923051e-01, -5.845467208e-01, -5.876710795e-01, -5.909615812e-01, -5.944142179e-01, -5.980247779e-01, -6.017888493e-01, -6.057018246e-01, -6.097589051e-01, -6.139551055e-01, -6.182852586e-01, -6.227440206e-01, -6.273258760e-01, -6.320251430e-01, -6.368359791e-01, -6.417523866e-01, -6.467682186e-01, -6.518771847e-01, -6.570728573e-01, -6.623486777e-01, -6.676979625e-01, -6.731139101e-01, -6.785896075e-01, -6.841180363e-01, -6.896920804e-01, -6.953045323e-01, -7.009481004e-01, -7.066154159e-01, -7.122990400e-01, -7.179914713e-01, -7.236851528e-01, -7.293724795e-01, -7.350458056e-01, -7.406974522e-01, -7.463197146e-01, -7.519048698e-01, -7.574451839e-01, -7.629329203e-01, -7.683603462e-01, -7.737197412e-01, -7.790034041e-01, -7.842036608e-01, -7.893128718e-01, -7.943234396e-01, -7.992278159e-01, -8.040185098e-01, -8.086880941e-01, -8.132292135e-01, -8.176345914e-01, -8.218970370e-01, -8.260094527e-01, -8.299648411e-01, -8.337563114e-01, -8.373770869e-01, -8.408205115e-01, -8.440800559e-01, -8.471493248e-01, -8.500220626e-01, -8.526921603e-01, -8.551536610e-01, -8.574007663e-01, -8.594278419e-01, -8.612294234e-01, -8.628002219e-01, -8.641351289e-01, -8.652292222e-01, -8.660777705e-01, -8.666762380e-01, -8.670202897e-01, -8.671057955e-01, -8.669288344e-01, -8.664856988e-01, -8.657728984e-01, -8.647871637e-01, -8.635254499e-01, -8.619849395e-01, -8.601630462e-01, -8.580574171e-01, -8.556659356e-01, -8.529867238e-01, -8.500181450e-01, -8.467588049e-01, -8.432075542e-01, -8.393634897e-01, -8.352259555e-01, -8.307945444e-01, -8.260690984e-01, -8.210497097e-01, -8.157367205e-01, -8.101307236e-01, -8.042325621e-01, -7.980433294e-01, -7.915643678e-01, -7.847972688e-01, -7.777438711e-01, -7.704062601e-01, -7.627867658e-01, -7.548879614e-01, -7.467126614e-01, -7.382639192e-01, -7.295450248e-01, -7.205595023e-01, -7.113111070e-01, -7.018038220e-01, -6.920418557e-01, -6.820296374e-01, -6.717718144e-01, -6.612732477e-01, -6.505390078e-01, -6.395743710e-01, -6.283848142e-01, -6.169760107e-01, -6.053538252e-01, -5.935243087e-01, -5.814936936e-01, -5.692683878e-01, -5.568549698e-01, -5.442601825e-01, -5.314909274e-01, -5.185542589e-01, -5.054573779e-01, -4.922076255e-01, -4.788124769e-01, -4.652795343e-01, -4.516165209e-01, -4.378312735e-01, -4.239317360e-01, -4.099259525e-01, -3.958220597e-01, -3.816282803e-01, -3.673529156e-01, -3.530043379e-01, -3.385909834e-01, -3.241213448e-01, -3.096039635e-01, -2.950474221e-01, -2.804603374e-01, -2.658513518e-01, -2.512291264e-01, -2.366023330e-01, -2.219796467e-01, -2.073697378e-01, -1.927812645e-01, -1.782228649e-01, -1.637031499e-01, -1.492306948e-01, -1.348140324e-01, -1.204616451e-01, -1.061819573e-01, -9.198332831e-02, -7.787404460e-02, -6.386231267e-02, -4.995625172e-02, -3.616388648e-02, -2.249314013e-02, -8.951827325e-03, 4.452352754e-03, 1.771182314e-02, 3.081913577e-02, 4.376697805e-02, 5.654817927e-02, 6.915571694e-02, 8.158272290e-02, 9.382248936e-02, 1.058684748e-01, 1.177143097e-01, 1.293538020e-01, 1.407809425e-01, 1.519899103e-01, 1.629750777e-01, 1.737310148e-01, 1.842524947e-01, 1.945344977e-01, 2.045722157e-01, 2.143610560e-01, 2.238966459e-01, 2.331748356e-01, 2.421917023e-01, 2.509435532e-01, 2.594269288e-01, 2.676386053e-01, 2.755755980e-01, 2.832351628e-01, 2.906147992e-01, 2.977122518e-01, 3.045255124e-01, 3.110528209e-01, 3.172926675e-01, 3.232437927e-01, 3.289051892e-01, 3.342761015e-01, 3.393560271e-01, 3.441447159e-01, 3.486421705e-01, 3.528486460e-01, 3.567646490e-01, 3.603909369e-01, 3.637285169e-01, 3.667786452e-01, 3.695428244e-01, 3.720228028e-01, 3.742205721e-01, 3.761383649e-01, 3.777786527e-01, 3.791441432e-01, 3.802377771e-01, 3.810627256e-01, 3.816223868e-01, 3.819203820e-01, 3.819605526e-01, 3.817469556e-01, 3.812838599e-01, 3.805757419e-01, 3.796272809e-01, 3.784433547e-01, 3.770290344e-01, 3.753895799e-01, 3.735304341e-01, 3.714572179e-01, 3.691757246e-01, 3.666919142e-01, 3.640119076e-01, 3.611419806e-01, 3.580885577e-01, 3.548582059e-01, 3.514576284e-01, 3.478936579e-01, 3.441732502e-01, 3.403034772e-01, 3.362915204e-01, 3.321446634e-01, 3.278702855e-01, 3.234758543e-01, 3.189689183e-01, 3.143570999e-01, 3.096480882e-01, 3.048496310e-01, 2.999695282e-01, 2.950156236e-01, 2.899957978e-01, 2.849179603e-01, 2.797900423e-01, 2.746199890e-01, 2.694157518e-01, 2.641852809e-01, 2.589365177e-01, 2.536773871e-01, 2.484157900e-01, 2.431595960e-01, 2.379166353e-01, 2.326946921e-01, 2.275014965e-01, 2.223447172e-01, 2.172319548e-01, 2.121707339e-01, 2.071684963e-01, 2.022325940e-01, 1.973702818e-01, 1.925887112e-01, 1.878949228e-01, 1.832958402e-01, 1.787982631e-01, 1.744088613e-01, 1.701341679e-01, 1.659805734e-01, 1.619543200e-01, 1.580614948e-01, 1.543080252e-01, 1.506996725e-01, 1.472420268e-01, 1.439405018e-01, 1.408003294e-01, 1.378265555e-01, 1.350240344e-01, 1.323974249e-01, 1.299511857e-01, 1.276895713e-01, 1.256166281e-01, 1.237361904e-01, 1.220518774e-01, 1.205670890e-01, 1.192850037e-01, 1.182085746e-01, 1.173405278e-01, 1.166833588e-01, 1.162393312e-01, 1.160104742e-01, 1.159985806e-01, 1.162052056e-01, 1.166316655e-01, 1.172790360e-01, 1.181481519e-01, 1.192396061e-01, 1.205537493e-01, 1.220906897e-01, 1.238502932e-01, 1.258321835e-01, 1.280357426e-01, 1.304601114e-01, 1.331041912e-01, 1.359666443e-01, 1.390458955e-01, 1.423401340e-01, 1.458473152e-01, 1.495651626e-01, 1.534911702e-01, 1.576226052e-01, 1.619565105e-01, 1.664897079e-01, 1.712188011e-01, 1.761401792e-01, 1.812500200e-01, 1.865442945e-01, 1.920187700e-01, 1.976690149e-01, 2.034904030e-01, 2.094781178e-01, 2.156271575e-01, 2.219323398e-01, 2.283883071e-01, 2.349895317e-01, 2.417303211e-01, 2.486048239e-01, 2.556070354e-01, 2.627308033e-01, 2.699698340e-01, 2.773176986e-01, 2.847678395e-01, 2.923135761e-01, 2.999481124e-01, 3.076645426e-01, 3.154558586e-01, 3.233149565e-01, 3.312346437e-01, 3.392076458e-01, 3.472266139e-01, 3.552841316e-01, 3.633727223e-01, 3.714848567e-01, 3.796129599e-01, 3.877494190e-01, 3.958865905e-01, 4.040168075e-01, 4.121323879e-01, 4.202256411e-01, 4.282888760e-01, 4.363144087e-01, 4.442945696e-01, 4.522217108e-01, 4.600882144e-01, 4.678864992e-01, 4.756090284e-01, 4.832483170e-01, 4.907969392e-01, 4.982475357e-01, 5.055928207e-01, 5.128255893e-01, 5.199387248e-01, 5.269252052e-01, 5.337781103e-01, 5.404906290e-01, 5.470560652e-01, 5.534678452e-01, 5.597195236e-01, 5.658047902e-01, 5.717174758e-01, 5.774515588e-01, 5.830011706e-01, 5.883606020e-01, 5.935243087e-01, 5.984869167e-01, 6.032432280e-01, 6.077882253e-01, 6.121170777e-01, 6.162251450e-01, 6.201079829e-01, 6.237613471e-01, 6.271811977e-01, 6.303637036e-01, 6.333052460e-01, 6.360024227e-01, 6.384520510e-01, 6.406511715e-01, 6.425970510e-01, 6.442871854e-01, 6.457193025e-01, 6.468913644e-01, 6.478015696e-01, 6.484483554e-01, 6.488303992e-01, 6.489466204e-01, 6.487961819e-01, 6.483784908e-01, 6.476931993e-01, 6.467402058e-01, 6.455196548e-01, 6.440319376e-01, 6.422776917e-01, 6.402578009e-01, 6.379733947e-01, 6.354258474e-01, 6.326167774e-01, 6.295480458e-01, 6.262217551e-01, 6.226402471e-01, 6.188061017e-01, 6.147221343e-01, 6.103913936e-01, 6.058171590e-01, 6.010029378e-01, 5.959524624e-01, 5.906696866e-01, 5.851587830e-01, 5.794241384e-01, 5.734703507e-01, 5.673022246e-01, 5.609247673e-01, 5.543431842e-01, 5.475628743e-01, 5.405894254e-01, 5.334286088e-01, 5.260863747e-01, 5.185688465e-01, 5.108823155e-01, 5.030332350e-01, 4.950282150e-01, 4.868740155e-01, 4.785775412e-01, 4.701458346e-01, 4.615860701e-01, 4.529055474e-01, 4.441116847e-01, 4.352120120e-01, 4.262141645e-01, 4.171258756e-01, 4.079549695e-01, 3.987093547e-01, 3.893970163e-01, 3.800260089e-01, 3.706044491e-01, 3.611405086e-01, 3.516424059e-01, 3.421183996e-01, 3.325767805e-01, 3.230258638e-01, 3.134739818e-01, 3.039294763e-01, 2.944006908e-01, 2.848959628e-01, 2.754236162e-01, 2.659919539e-01, 2.566092499e-01, 2.472837418e-01, 2.380236231e-01, 2.288370361e-01, 2.197320638e-01, 2.107167229e-01, 2.017989566e-01, 1.929866265e-01, 1.842875062e-01, 1.757092739e-01, 1.672595050e-01, 1.589456655e-01, 1.507751052e-01, 1.427550504e-01, 1.348925977e-01, 1.271947075e-01, 1.196681973e-01, 1.123197355e-01, 1.051558353e-01, 9.818284881e-02, 9.140696093e-02, 8.483418385e-02, 7.847035142e-02, 7.232111378e-02, 6.639193214e-02, 6.068807378e-02, 5.521460712e-02, 4.997639709e-02, 4.497810064e-02, 4.022416239e-02, 3.571881060e-02, 3.146605320e-02, 2.746967413e-02, 2.373322981e-02, 2.026004590e-02, 1.705321419e-02, 1.411558974e-02, 1.144978827e-02, 9.058183747e-03, 6.942906149e-03, 5.105839538e-03, 3.548620298e-03, 2.272635633e-03, 1.279022277e-03, 5.686654498e-04, 1.421980359e-04, -8.377285203e-16, 1.421980359e-04, 5.686654498e-04, 1.279022277e-03, 2.272635633e-03, 3.548620298e-03, 5.105839538e-03, 6.942906149e-03, 9.058183747e-03, 1.144978827e-02, 1.411558974e-02, 1.705321419e-02, 2.026004590e-02, 2.373322981e-02, 2.746967413e-02, 3.146605320e-02, 3.571881060e-02, 4.022416239e-02, 4.497810064e-02, 4.997639709e-02, 5.521460712e-02, 6.068807378e-02, 6.639193214e-02, 7.232111378e-02, 7.847035142e-02, 8.483418385e-02, 9.140696093e-02, 9.818284881e-02, 1.051558353e-01, 1.123197355e-01, 1.196681973e-01, 1.271947075e-01, 1.348925977e-01, 1.427550504e-01, 1.507751052e-01, 1.589456655e-01, 1.672595050e-01, 1.757092739e-01, 1.842875062e-01, 1.929866265e-01, 2.017989566e-01, 2.107167229e-01, 2.197320638e-01, 2.288370361e-01, 2.380236231e-01, 2.472837418e-01, 2.566092499e-01, 2.659919539e-01, 2.754236162e-01, 2.848959628e-01, 2.944006908e-01, 3.039294763e-01, 3.134739818e-01, 3.230258638e-01, 3.325767805e-01, 3.421183996e-01, 3.516424059e-01, 3.611405086e-01, 3.706044491e-01, 3.800260089e-01, 3.893970163e-01, 3.987093547e-01, 4.079549695e-01, 4.171258756e-01, 4.262141645e-01, 4.352120120e-01, 4.441116847e-01, 4.529055474e-01, 4.615860701e-01, 4.701458346e-01, 4.785775412e-01, 4.868740155e-01, 4.950282150e-01, 5.030332350e-01, 5.108823155e-01, 5.185688465e-01, 5.260863747e-01, 5.334286088e-01, 5.405894254e-01, 5.475628743e-01, 5.543431842e-01, 5.609247673e-01, 5.673022246e-01, 5.734703507e-01, 5.794241384e-01, 5.851587830e-01, 5.906696866e-01, 5.959524624e-01, 6.010029378e-01, 6.058171590e-01, 6.103913936e-01, 6.147221343e-01, 6.188061017e-01, 6.226402471e-01, 6.262217551e-01, 6.295480458e-01, 6.326167774e-01, 6.354258474e-01, 6.379733947e-01, 6.402578009e-01, 6.422776917e-01, 6.440319376e-01, 6.455196548e-01, 6.467402058e-01, 6.476931993e-01, 6.483784908e-01, 6.487961819e-01, 6.489466204e-01, 6.488303992e-01, 6.484483554e-01, 6.478015696e-01, 6.468913644e-01, 6.457193025e-01, 6.442871854e-01, 6.425970510e-01, 6.406511715e-01, 6.384520510e-01, 6.360024227e-01, 6.333052460e-01, 6.303637036e-01, 6.271811977e-01, 6.237613471e-01, 6.201079829e-01, 6.162251450e-01, 6.121170777e-01, 6.077882253e-01, 6.032432280e-01, 5.984869167e-01, 5.935243087e-01, 5.883606020e-01, 5.830011706e-01, 5.774515588e-01, 5.717174758e-01, 5.658047902e-01, 5.597195236e-01, 5.534678452e-01, 5.470560652e-01, 5.404906290e-01, 5.337781103e-01, 5.269252052e-01, 5.199387248e-01, 5.128255893e-01, 5.055928207e-01, 4.982475357e-01, 4.907969392e-01, 4.832483170e-01, 4.756090284e-01, 4.678864992e-01, 4.600882144e-01, 4.522217108e-01, 4.442945696e-01, 4.363144087e-01, 4.282888760e-01, 4.202256411e-01, 4.121323879e-01, 4.040168075e-01, 3.958865905e-01, 3.877494190e-01, 3.796129599e-01, 3.714848567e-01, 3.633727223e-01, 3.552841316e-01, 3.472266139e-01, 3.392076458e-01, 3.312346437e-01, 3.233149565e-01, 3.154558586e-01, 3.076645426e-01, 2.999481124e-01, 2.923135761e-01, 2.847678395e-01, 2.773176986e-01, 2.699698340e-01, 2.627308033e-01, 2.556070354e-01, 2.486048239e-01, 2.417303211e-01, 2.349895317e-01, 2.283883071e-01, 2.219323398e-01, 2.156271575e-01, 2.094781178e-01, 2.034904030e-01, 1.976690149e-01, 1.920187700e-01, 1.865442945e-01, 1.812500200e-01, 1.761401792e-01, 1.712188011e-01, 1.664897079e-01, 1.619565105e-01, 1.576226052e-01, 1.534911702e-01, 1.495651626e-01, 1.458473152e-01, 1.423401340e-01, 1.390458955e-01, 1.359666443e-01, 1.331041912e-01, 1.304601114e-01, 1.280357426e-01, 1.258321835e-01, 1.238502932e-01, 1.220906897e-01, 1.205537493e-01, 1.192396061e-01, 1.181481519e-01, 1.172790360e-01, 1.166316655e-01, 1.162052056e-01, 1.159985806e-01, 1.160104742e-01, 1.162393312e-01, 1.166833588e-01, 1.173405278e-01, 1.182085746e-01, 1.192850037e-01, 1.205670890e-01, 1.220518774e-01, 1.237361904e-01, 1.256166281e-01, 1.276895713e-01, 1.299511857e-01, 1.323974249e-01, 1.350240344e-01, 1.378265555e-01, 1.408003294e-01, 1.439405018e-01, 1.472420268e-01, 1.506996725e-01, 1.543080252e-01, 1.580614948e-01, 1.619543200e-01, 1.659805734e-01, 1.701341679e-01, 1.744088613e-01, 1.787982631e-01, 1.832958402e-01, 1.878949228e-01, 1.925887112e-01, 1.973702818e-01, 2.022325940e-01, 2.071684963e-01, 2.121707339e-01, 2.172319548e-01, 2.223447172e-01, 2.275014965e-01, 2.326946921e-01, 2.379166353e-01, 2.431595960e-01, 2.484157900e-01, 2.536773871e-01, 2.589365177e-01, 2.641852809e-01, 2.694157518e-01, 2.746199890e-01, 2.797900423e-01, 2.849179603e-01, 2.899957978e-01, 2.950156236e-01, 2.999695282e-01, 3.048496310e-01, 3.096480882e-01, 3.143570999e-01, 3.189689183e-01, 3.234758543e-01, 3.278702855e-01, 3.321446634e-01, 3.362915204e-01, 3.403034772e-01, 3.441732502e-01, 3.478936579e-01, 3.514576284e-01, 3.548582059e-01, 3.580885577e-01, 3.611419806e-01, 3.640119076e-01, 3.666919142e-01, 3.691757246e-01, 3.714572179e-01, 3.735304341e-01, 3.753895799e-01, 3.770290344e-01, 3.784433547e-01, 3.796272809e-01, 3.805757419e-01, 3.812838599e-01, 3.817469556e-01, 3.819605526e-01, 3.819203820e-01, 3.816223868e-01, 3.810627256e-01, 3.802377771e-01, 3.791441432e-01, 3.777786527e-01, 3.761383649e-01, 3.742205721e-01, 3.720228028e-01, 3.695428244e-01, 3.667786452e-01, 3.637285169e-01, 3.603909369e-01, 3.567646490e-01, 3.528486460e-01, 3.486421705e-01, 3.441447159e-01, 3.393560271e-01, 3.342761015e-01, 3.289051892e-01, 3.232437927e-01, 3.172926675e-01, 3.110528209e-01, 3.045255124e-01, 2.977122518e-01, 2.906147992e-01, 2.832351628e-01, 2.755755980e-01, 2.676386053e-01, 2.594269288e-01, 2.509435532e-01, 2.421917023e-01, 2.331748356e-01, 2.238966459e-01, 2.143610560e-01, 2.045722157e-01, 1.945344977e-01, 1.842524947e-01, 1.737310148e-01, 1.629750777e-01, 1.519899103e-01, 1.407809425e-01, 1.293538020e-01, 1.177143097e-01, 1.058684748e-01, 9.382248936e-02, 8.158272290e-02, 6.915571694e-02, 5.654817927e-02, 4.376697805e-02, 3.081913577e-02, 1.771182314e-02, 4.452352754e-03, -8.951827325e-03, -2.249314013e-02, -3.616388648e-02, -4.995625172e-02, -6.386231267e-02, -7.787404460e-02, -9.198332831e-02, -1.061819573e-01, -1.204616451e-01, -1.348140324e-01, -1.492306948e-01, -1.637031499e-01, -1.782228649e-01, -1.927812645e-01, -2.073697378e-01, -2.219796467e-01, -2.366023330e-01, -2.512291264e-01, -2.658513518e-01, -2.804603374e-01, -2.950474221e-01, -3.096039635e-01, -3.241213448e-01, -3.385909834e-01, -3.530043379e-01, -3.673529156e-01, -3.816282803e-01, -3.958220597e-01, -4.099259525e-01, -4.239317360e-01, -4.378312735e-01, -4.516165209e-01, -4.652795343e-01, -4.788124769e-01, -4.922076255e-01, -5.054573779e-01, -5.185542589e-01, -5.314909274e-01, -5.442601825e-01, -5.568549698e-01, -5.692683878e-01, -5.814936936e-01, -5.935243087e-01, -6.053538252e-01, -6.169760107e-01, -6.283848142e-01, -6.395743710e-01, -6.505390078e-01, -6.612732477e-01, -6.717718144e-01, -6.820296374e-01, -6.920418557e-01, -7.018038220e-01, -7.113111070e-01, -7.205595023e-01, -7.295450248e-01, -7.382639192e-01, -7.467126614e-01, -7.548879614e-01, -7.627867658e-01, -7.704062601e-01, -7.777438711e-01, -7.847972688e-01, -7.915643678e-01, -7.980433294e-01, -8.042325621e-01, -8.101307236e-01, -8.157367205e-01, -8.210497097e-01, -8.260690984e-01, -8.307945444e-01, -8.352259555e-01, -8.393634897e-01, -8.432075542e-01, -8.467588049e-01, -8.500181450e-01, -8.529867238e-01, -8.556659356e-01, -8.580574171e-01, -8.601630462e-01, -8.619849395e-01, -8.635254499e-01, -8.647871637e-01, -8.657728984e-01, -8.664856988e-01, -8.669288344e-01, -8.671057955e-01, -8.670202897e-01, -8.666762380e-01, -8.660777705e-01, -8.652292222e-01, -8.641351289e-01, -8.628002219e-01, -8.612294234e-01, -8.594278419e-01, -8.574007663e-01, -8.551536610e-01, -8.526921603e-01, -8.500220626e-01, -8.471493248e-01, -8.440800559e-01, -8.408205115e-01, -8.373770869e-01, -8.337563114e-01, -8.299648411e-01, -8.260094527e-01, -8.218970370e-01, -8.176345914e-01, -8.132292135e-01, -8.086880941e-01, -8.040185098e-01, -7.992278159e-01, -7.943234396e-01, -7.893128718e-01, -7.842036608e-01, -7.790034041e-01, -7.737197412e-01, -7.683603462e-01, -7.629329203e-01, -7.574451839e-01, -7.519048698e-01, -7.463197146e-01, -7.406974522e-01, -7.350458056e-01, -7.293724795e-01, -7.236851528e-01, -7.179914713e-01, -7.122990400e-01, -7.066154159e-01, -7.009481004e-01, -6.953045323e-01, -6.896920804e-01, -6.841180363e-01, -6.785896075e-01, -6.731139101e-01, -6.676979625e-01, -6.623486777e-01, -6.570728573e-01, -6.518771847e-01, -6.467682186e-01, -6.417523866e-01, -6.368359791e-01, -6.320251430e-01, -6.273258760e-01, -6.227440206e-01, -6.182852586e-01, -6.139551055e-01, -6.097589051e-01, -6.057018246e-01, -6.017888493e-01, -5.980247779e-01, -5.944142179e-01, -5.909615812e-01, -5.876710795e-01, -5.845467208e-01, -5.815923051e-01, -5.788114207e-01, -5.762074410e-01, -5.737835211e-01, -5.715425948e-01, -5.694873717e-01, -5.676203347e-01, -5.659437373e-01, -5.644596020e-01, -5.631697177e-01, -5.620756384e-01, -5.611786816e-01, -5.604799268e-01, -5.599802150e-01, -5.596801473e-01, -5.595800846e-01, }; const float wav_buzzy_i[] = { 8.971760921e-01, 9.082591841e-01, 9.187698318e-01, 9.286945583e-01, 9.380204364e-01, 9.467351098e-01, 9.548268127e-01, 9.622843889e-01, 9.690973112e-01, 9.752556985e-01, 9.807503335e-01, 9.855726789e-01, 9.897148929e-01, 9.931698441e-01, 9.959311250e-01, 9.979930655e-01, 9.993507443e-01, 1.000000000e+00, 9.999374417e-01, 9.991604575e-01, 9.976672227e-01, 9.954567068e-01, 9.925286795e-01, 9.888837156e-01, 9.845231984e-01, 9.794493228e-01, 9.736650966e-01, 9.671743410e-01, 9.599816899e-01, 9.520925880e-01, 9.435132877e-01, 9.342508454e-01, 9.243131155e-01, 9.137087448e-01, 9.024471641e-01, 8.905385803e-01, 8.779939659e-01, 8.648250483e-01, 8.510442980e-01, 8.366649148e-01, 8.217008142e-01, 8.061666117e-01, 7.900776064e-01, 7.734497638e-01, 7.562996973e-01, 7.386446487e-01, 7.205024678e-01, 7.018915914e-01, 6.828310205e-01, 6.633402978e-01, 6.434394832e-01, 6.231491296e-01, 6.024902566e-01, 5.814843249e-01, 5.601532087e-01, 5.385191685e-01, 5.166048223e-01, 4.944331168e-01, 4.720272980e-01, 4.494108812e-01, 4.266076203e-01, 4.036414771e-01, 3.805365898e-01, 3.573172418e-01, 3.340078292e-01, 3.106328290e-01, 2.872167666e-01, 2.637841836e-01, 2.403596047e-01, 2.169675056e-01, 1.936322799e-01, 1.703782068e-01, 1.472294186e-01, 1.242098680e-01, 1.013432966e-01, 7.865320248e-02, 5.616280879e-02, 3.389503254e-02, 1.187245372e-02, -9.882715135e-03, -3.134865880e-02, -5.250398879e-02, -7.332777212e-02, -9.379955950e-02, -1.138994128e-01, -1.336079319e-01, -1.529062805e-01, -1.717762116e-01, -1.902000919e-01, -2.081609249e-01, -2.256423739e-01, -2.426287835e-01, -2.591052003e-01, -2.750573924e-01, -2.904718680e-01, -3.053358930e-01, -3.196375073e-01, -3.333655402e-01, -3.465096241e-01, -3.590602080e-01, -3.710085686e-01, -3.823468210e-01, -3.930679283e-01, -4.031657089e-01, -4.126348435e-01, -4.214708808e-01, -4.296702412e-01, -4.372302197e-01, -4.441489878e-01, -4.504255930e-01, -4.560599584e-01, -4.610528799e-01, -4.654060225e-01, -4.691219156e-01, -4.722039460e-01, -4.746563512e-01, -4.764842099e-01, -4.776934319e-01, -4.782907472e-01, -4.782836928e-01, -4.776805993e-01, -4.764905759e-01, -4.747234939e-01, -4.723899699e-01, -4.695013471e-01, -4.660696758e-01, -4.621076931e-01, -4.576288011e-01, -4.526470447e-01, -4.471770878e-01, -4.412341892e-01, -4.348341770e-01, -4.279934231e-01, -4.207288156e-01, -4.130577320e-01, -4.049980102e-01, -3.965679198e-01, -3.877861327e-01, -3.786716928e-01, -3.692439852e-01, -3.595227055e-01, -3.495278277e-01, -3.392795730e-01, -3.287983770e-01, -3.181048577e-01, -3.072197824e-01, -2.961640352e-01, -2.849585842e-01, -2.736244480e-01, -2.621826632e-01, -2.506542514e-01, -2.390601863e-01, -2.274213611e-01, -2.157585562e-01, -2.040924068e-01, -1.924433715e-01, -1.808317003e-01, -1.692774040e-01, -1.578002235e-01, -1.464195995e-01, -1.351546437e-01, -1.240241090e-01, -1.130463623e-01, -1.022393562e-01, -9.162060267e-02, -8.120714720e-02, -7.101554337e-02, -6.106182886e-02, -5.136150203e-02, -4.192949963e-02, -3.278017537e-02, -2.392727958e-02, -1.538393990e-02, -7.162643068e-03, 7.247821940e-04, 8.267181171e-03, 1.545408796e-02, 2.227573910e-02, 2.872308602e-02, 3.478780620e-02, 4.046231319e-02, 4.573976529e-02, 5.061407300e-02, 5.507990521e-02, 5.913269407e-02, 6.276863859e-02, 6.598470695e-02, 6.877863751e-02, 7.114893854e-02, 7.309488661e-02, 7.461652378e-02, 7.571465344e-02, 7.639083489e-02, 7.664737669e-02, 7.648732877e-02, 7.591447328e-02, 7.493331424e-02, 7.354906604e-02, 7.176764070e-02, 6.959563404e-02, 6.704031073e-02, 6.410958825e-02, 6.081201973e-02, 5.715677584e-02, 5.315362566e-02, 4.881291657e-02, 4.414555320e-02, 3.916297557e-02, 3.387713628e-02, 2.830047695e-02, 2.244590394e-02, 1.632676320e-02, 9.956814633e-03, 3.350205664e-03, -3.478555680e-03, -1.051462826e-02, -1.774286581e-02, -2.514784534e-02, -3.271389595e-02, -4.042512798e-02, -4.826546241e-02, -5.621866057e-02, -6.426835397e-02, -7.239807429e-02, -8.059128345e-02, -8.883140368e-02, -9.710184761e-02, -1.053860483e-01, -1.136674889e-01, -1.219297327e-01, -1.301564522e-01, -1.383314586e-01, -1.464387302e-01, -1.544624414e-01, -1.623869903e-01, -1.701970263e-01, -1.778774772e-01, -1.854135758e-01, -1.927908851e-01, -1.999953243e-01, -2.070131925e-01, -2.138311928e-01, -2.204364550e-01, -2.268165578e-01, -2.329595502e-01, -2.388539712e-01, -2.444888698e-01, -2.498538231e-01, -2.549389539e-01, -2.597349468e-01, -2.642330638e-01, -2.684251583e-01, -2.723036886e-01, -2.758617295e-01, -2.790929837e-01, -2.819917908e-01, -2.845531365e-01, -2.867726598e-01, -2.886466588e-01, -2.901720963e-01, -2.913466026e-01, -2.921684791e-01, -2.926366988e-01, -2.927509066e-01, -2.925114182e-01, -2.919192177e-01, -2.909759541e-01, -2.896839362e-01, -2.880461271e-01, -2.860661368e-01, -2.837482137e-01, -2.810972354e-01, -2.781186982e-01, -2.748187051e-01, -2.712039532e-01, -2.672817198e-01, -2.630598475e-01, -2.585467284e-01, -2.537512872e-01, -2.486829634e-01, -2.433516926e-01, -2.377678869e-01, -2.319424144e-01, -2.258865780e-01, -2.196120937e-01, -2.131310673e-01, -2.064559718e-01, -1.995996226e-01, -1.925751533e-01, -1.853959905e-01, -1.780758282e-01, -1.706286014e-01, -1.630684601e-01, -1.554097419e-01, -1.476669449e-01, -1.398547008e-01, -1.319877466e-01, -1.240808971e-01, -1.161490171e-01, -1.082069931e-01, -1.002697057e-01, -9.235200147e-02, -8.446866516e-02, -7.663439211e-02, -6.886376066e-02, -6.117120500e-02, -5.357098824e-02, -4.607717575e-02, -3.870360907e-02, -3.146388008e-02, -2.437130577e-02, -1.743890353e-02, -1.067936696e-02, -4.105042359e-03, 2.272094136e-03, 8.440458717e-03, 1.438888132e-02, 2.010662625e-02, 2.558341200e-02, 3.080943021e-02, 3.577536370e-02, 4.047240364e-02, 4.489226575e-02, 4.902720546e-02, 5.287003213e-02, 5.641412221e-02, 5.965343133e-02, 6.258250532e-02, 6.519649016e-02, 6.749114071e-02, 6.946282847e-02, 7.110854800e-02, 7.242592238e-02, 7.341320734e-02, 7.406929429e-02, 7.439371218e-02, 7.438662813e-02, 7.404884694e-02, 7.338180932e-02, 7.238758906e-02, 7.106888891e-02, 6.942903540e-02, 6.747197242e-02, 6.520225370e-02, 6.262503414e-02, 5.974606004e-02, 5.657165823e-02, 5.310872411e-02, 4.936470864e-02, 4.534760432e-02, 4.106593016e-02, 3.652871561e-02, 3.174548365e-02, 2.672623288e-02, 2.148141875e-02, 1.602193395e-02, 1.035908798e-02, 4.504585901e-03, -1.529493542e-03, -7.730720628e-03, -1.408633794e-02, -2.058328429e-02, -2.720821920e-02, -3.394754791e-02, -4.078744693e-02, -4.771388987e-02, -5.471267385e-02, -6.176944612e-02, -6.886973097e-02, -7.599895699e-02, -8.314248438e-02, -9.028563250e-02, -9.741370749e-02, -1.045120299e-01, -1.115659622e-01, -1.185609368e-01, -1.254824830e-01, -1.323162543e-01, -1.390480562e-01, -1.456638721e-01, -1.521498904e-01, -1.584925306e-01, -1.646784688e-01, -1.706946634e-01, -1.765283795e-01, -1.821672133e-01, -1.875991160e-01, -1.928124164e-01, -1.977958438e-01, -2.025385488e-01, -2.070301253e-01, -2.112606294e-01, -2.152205995e-01, -2.189010745e-01, -2.222936108e-01, -2.253902994e-01, -2.281837812e-01, -2.306672615e-01, -2.328345239e-01, -2.346799422e-01, -2.361984923e-01, -2.373857623e-01, -2.382379619e-01, -2.387519301e-01, -2.389251425e-01, -2.387557169e-01, -2.382424176e-01, -2.373846593e-01, -2.361825091e-01, -2.346366872e-01, -2.327485672e-01, -2.305201742e-01, -2.279541826e-01, -2.250539120e-01, -2.218233225e-01, -2.182670081e-01, -2.143901898e-01, -2.101987067e-01, -2.056990065e-01, -2.008981347e-01, -1.958037225e-01, -1.904239742e-01, -1.847676524e-01, -1.788440636e-01, -1.726630414e-01, -1.662349299e-01, -1.595705649e-01, -1.526812556e-01, -1.455787637e-01, -1.382752835e-01, -1.307834195e-01, -1.231161643e-01, -1.152868750e-01, -1.073092497e-01, -9.919730260e-02, -9.096533878e-02, -8.262792831e-02, -7.419987994e-02, -6.569621416e-02, -5.713213590e-02, -4.852300677e-02, -3.988431697e-02, -3.123165692e-02, -2.258068864e-02, -1.394711683e-02, -5.346659989e-03, 3.204978775e-03, 1.169214082e-02, 2.009924112e-02, 2.841079735e-02, 3.661145884e-02, 4.468603537e-02, 5.261952581e-02, 6.039714641e-02, 6.800435883e-02, 7.542689783e-02, 8.265079845e-02, 8.966242287e-02, 9.644848660e-02, 1.029960843e-01, 1.092927147e-01, 1.153263053e-01, 1.210852361e-01, 1.265583623e-01, 1.317350371e-01, 1.366051326e-01, 1.411590607e-01, 1.453877927e-01, 1.492828780e-01, 1.528364619e-01, 1.560413025e-01, 1.588907861e-01, 1.613789421e-01, 1.635004568e-01, 1.652506856e-01, 1.666256641e-01, 1.676221189e-01, 1.682374760e-01, 1.684698691e-01, 1.683181456e-01, 1.677818725e-01, 1.668613401e-01, 1.655575650e-01, 1.638722917e-01, 1.618079929e-01, 1.593678687e-01, 1.565558440e-01, 1.533765655e-01, 1.498353964e-01, 1.459384112e-01, 1.416923874e-01, 1.371047980e-01, 1.321838011e-01, 1.269382294e-01, 1.213775774e-01, 1.155119891e-01, 1.093522426e-01, 1.029097348e-01, 9.619646482e-02, 8.922501600e-02, 8.200853705e-02, 7.456072211e-02, 6.689578992e-02, 5.902846189e-02, 5.097393927e-02, 4.274787955e-02, 3.436637178e-02, 2.584591133e-02, 1.720337365e-02, 8.455987483e-03, -3.786927566e-04, -9.282815139e-03, -1.823825903e-02, -2.722666441e-02, -3.622946176e-02, -4.522790230e-02, -5.420308871e-02, -6.313600617e-02, -7.200755371e-02, -8.079857577e-02, -8.948989403e-02, -9.806233930e-02, -1.064967835e-01, -1.147741720e-01, -1.228755549e-01, -1.307821202e-01, -1.384752243e-01, -1.459364249e-01, -1.531475114e-01, -1.600905369e-01, -1.667478483e-01, -1.731021173e-01, -1.791363704e-01, -1.848340177e-01, -1.901788829e-01, -1.951552309e-01, -1.997477960e-01, -2.039418091e-01, -2.077230234e-01, -2.110777409e-01, -2.139928366e-01, -2.164557826e-01, -2.184546712e-01, -2.199782371e-01, -2.210158786e-01, -2.215576772e-01, -2.215944178e-01, -2.211176056e-01, -2.201194838e-01, -2.185930494e-01, -2.165320675e-01, -2.139310851e-01, -2.107854432e-01, -2.070912881e-01, -2.028455811e-01, -1.980461071e-01, -1.926914819e-01, -1.867811581e-01, -1.803154301e-01, -1.732954371e-01, -1.657231656e-01, -1.576014500e-01, -1.489339720e-01, -1.397252588e-01, -1.299806801e-01, -1.197064432e-01, -1.089095877e-01, -9.759797797e-02, -8.578029515e-02, -7.346602720e-02, -6.066545816e-02, -4.738965594e-02, -3.365045896e-02, -1.946046156e-02, -4.832998268e-03, 1.021787315e-02, 2.567738971e-02, 4.153010233e-02, 5.775989612e-02, 7.435001152e-02, 9.128306666e-02, 1.085410805e-01, 1.261054971e-01, 1.439572106e-01, 1.620765911e-01, 1.804435113e-01, 1.990373745e-01, 2.178371421e-01, 2.368213630e-01, 2.559682031e-01, 2.752554754e-01, 2.946606705e-01, 3.141609882e-01, 3.337333689e-01, 3.533545256e-01, 3.730009765e-01, 3.926490775e-01, 4.122750553e-01, 4.318550406e-01, 4.513651012e-01, 4.707812754e-01, 4.900796058e-01, 5.092361722e-01, 5.282271255e-01, 5.470287206e-01, 5.656173495e-01, 5.839695746e-01, 6.020621608e-01, 6.198721081e-01, 6.373766838e-01, 6.545534535e-01, 6.713803126e-01, 6.878355167e-01, 7.038977119e-01, 7.195459640e-01, 7.347597874e-01, 7.495191732e-01, 7.638046169e-01, 7.775971446e-01, 7.908783392e-01, 8.036303653e-01, 8.158359935e-01, 8.274786231e-01, 8.385423054e-01, 8.490117640e-01, 8.588724158e-01, 8.681103900e-01, 8.767125463e-01, 8.846664925e-01, 8.919605999e-01, 8.985840188e-01, 9.045266920e-01, 9.097793674e-01, 9.143336098e-01, 9.181818106e-01, 9.213171973e-01, 9.237338414e-01, 9.254266647e-01, 9.263914448e-01, 9.266248196e-01, 9.261242898e-01, 9.248882208e-01, 9.229158433e-01, 9.202072527e-01, 9.167634065e-01, 9.125861220e-01, 9.076780714e-01, 9.020427762e-01, 8.956846010e-01, 8.886087450e-01, 8.808212335e-01, 8.723289075e-01, 8.631394121e-01, 8.532611852e-01, 8.427034428e-01, 8.314761657e-01, 8.195900832e-01, 8.070566575e-01, 7.938880657e-01, 7.800971816e-01, 7.656975570e-01, 7.507034011e-01, 7.351295601e-01, 7.189914954e-01, 7.023052610e-01, 6.850874811e-01, 6.673553256e-01, 6.491264862e-01, 6.304191511e-01, 6.112519799e-01, 5.916440772e-01, 5.716149663e-01, 5.511845623e-01, 5.303731445e-01, 5.092013293e-01, 4.876900416e-01, 4.658604873e-01, 4.437341244e-01, 4.213326346e-01, 3.986778948e-01, 3.757919480e-01, 3.526969748e-01, 3.294152644e-01, 3.059691862e-01, 2.823811607e-01, 2.586736313e-01, 2.348690360e-01, 2.109897792e-01, 1.870582039e-01, 1.630965640e-01, 1.391269974e-01, 1.151714989e-01, 9.125189397e-02, 6.738981246e-02, 4.360666353e-02, 1.992361040e-02, -3.638454014e-03, -2.705893091e-02, -5.031753886e-02, -7.339433640e-02, -9.626974396e-02, -1.189245651e-01, -1.413400068e-01, -1.634976998e-01, -1.853797169e-01, -2.069685914e-01, -2.282473350e-01, -2.491994536e-01, -2.698089633e-01, -2.900604056e-01, -3.099388610e-01, -3.294299623e-01, -3.485199068e-01, -3.671954675e-01, -3.854440037e-01, -4.032534703e-01, -4.206124265e-01, -4.375100435e-01, -4.539361110e-01, -4.698810432e-01, -4.853358836e-01, -5.002923089e-01, -5.147426323e-01, -5.286798053e-01, -5.420974189e-01, -5.549897044e-01, -5.673515325e-01, -5.791784117e-01, -5.904664867e-01, -6.012125345e-01, -6.114139611e-01, -6.210687963e-01, -6.301756885e-01, -6.387338980e-01, -6.467432905e-01, -6.542043286e-01, -6.611180638e-01, -6.674861271e-01, -6.733107193e-01, -6.785946000e-01, -6.833410772e-01, -6.875539950e-01, -6.912377216e-01, -6.943971364e-01, -6.970376166e-01, -6.991650237e-01, -7.007856890e-01, -7.019063987e-01, -7.025343795e-01, -7.026772825e-01, -7.023431678e-01, -7.015404882e-01, -7.002780733e-01, -6.985651123e-01, -6.964111376e-01, -6.938260078e-01, -6.908198904e-01, -6.874032445e-01, -6.835868039e-01, -6.793815589e-01, -6.747987395e-01, -6.698497976e-01, -6.645463897e-01, -6.589003592e-01, -6.529237195e-01, -6.466286363e-01, -6.400274109e-01, -6.331324628e-01, -6.259563132e-01, -6.185115684e-01, -6.108109033e-01, -6.028670450e-01, -5.946927574e-01, -5.863008256e-01, -5.777040398e-01, -5.689151815e-01, -5.599470078e-01, -5.508122378e-01, -5.415235382e-01, -5.320935102e-01, -5.225346758e-01, -5.128594657e-01, -5.030802064e-01, -4.932091088e-01, -4.832582562e-01, -4.732395938e-01, -4.631649179e-01, -4.530458658e-01, -4.428939064e-01, -4.327203306e-01, -4.225362430e-01, -4.123525537e-01, -4.021799703e-01, -3.920289908e-01, -3.819098968e-01, -3.718327473e-01, -3.618073726e-01, -3.518433692e-01, -3.419500946e-01, -3.321366633e-01, -3.224119421e-01, -3.127845472e-01, -3.032628407e-01, -2.938549279e-01, -2.845686554e-01, -2.754116085e-01, -2.663911102e-01, -2.575142202e-01, -2.487877338e-01, -2.402181815e-01, -2.318118293e-01, -2.235746788e-01, -2.155124678e-01, -2.076306713e-01, -1.999345024e-01, -1.924289143e-01, -1.851186015e-01, -1.780080021e-01, -1.711013000e-01, -1.644024271e-01, -1.579150661e-01, -1.516426532e-01, -1.455883809e-01, -1.397552017e-01, -1.341458304e-01, -1.287627484e-01, -1.236082063e-01, -1.186842281e-01, -1.139926144e-01, -1.095349463e-01, -1.053125889e-01, -1.013266952e-01, -9.757820970e-02, -9.406787238e-02, -9.079622213e-02, -8.776360065e-02, -8.497015608e-02, -8.241584661e-02, -8.010044409e-02, -7.802353748e-02, -7.618453631e-02, -7.458267397e-02, -7.321701101e-02, -7.208643822e-02, -7.118967971e-02, -7.052529579e-02, -7.009168577e-02, -6.988709061e-02, -6.990959552e-02, -7.015713229e-02, -7.062748159e-02, -7.131827513e-02, -7.222699760e-02, -7.335098856e-02, -7.468744416e-02, -7.623341872e-02, -7.798582615e-02, -7.994144128e-02, -8.209690107e-02, -8.444870562e-02, -8.699321916e-02, -8.972667083e-02, -9.264515543e-02, -9.574463400e-02, -9.902093438e-02, -1.024697516e-01, -1.060866482e-01, -1.098670547e-01, -1.138062696e-01, -1.178994595e-01, -1.221416595e-01, -1.265277732e-01, -1.310525726e-01, -1.357106984e-01, -1.404966600e-01, -1.454048355e-01, -1.504294720e-01, -1.555646856e-01, -1.608044617e-01, -1.661426552e-01, -1.715729912e-01, -1.770890648e-01, -1.826843423e-01, -1.883521617e-01, -1.940857332e-01, -1.998781406e-01, -2.057223420e-01, -2.116111714e-01, -2.175373402e-01, -2.234934384e-01, -2.294719369e-01, -2.354651895e-01, -2.414654349e-01, -2.474647995e-01, -2.534553004e-01, -2.594288478e-01, -2.653772489e-01, -2.712922111e-01, -2.771653461e-01, -2.829881739e-01, -2.887521273e-01, -2.944485565e-01, -3.000687344e-01, -3.056038617e-01, -3.110450728e-01, -3.163834415e-01, -3.216099876e-01, -3.267156834e-01, -3.316914605e-01, -3.365282173e-01, -3.412168265e-01, -3.457481429e-01, -3.501130117e-01, -3.543022771e-01, -3.583067908e-01, -3.621174218e-01, -3.657250649e-01, -3.691206512e-01, -3.722951576e-01, -3.752396174e-01, -3.779451303e-01, -3.804028738e-01, -3.826041137e-01, -3.845402153e-01, -3.862026553e-01, -3.875830328e-01, -3.886730813e-01, -3.894646811e-01, -3.899498704e-01, -3.901208587e-01, -3.899700380e-01, -3.894899961e-01, -3.886735286e-01, -3.875136516e-01, -3.860036141e-01, -3.841369111e-01, -3.819072952e-01, -3.793087903e-01, -3.763357030e-01, -3.729826358e-01, -3.692444989e-01, -3.651165225e-01, -3.605942688e-01, -3.556736440e-01, -3.503509096e-01, -3.446226941e-01, -3.384860038e-01, -3.319382343e-01, -3.249771802e-01, -3.176010463e-01, -3.098084567e-01, -3.015984651e-01, -2.929705630e-01, -2.839246896e-01, -2.744612389e-01, -2.645810684e-01, -2.542855060e-01, -2.435763571e-01, -2.324559105e-01, -2.209269445e-01, -2.089927320e-01, -1.966570451e-01, -1.839241589e-01, -1.707988550e-01, -1.572864242e-01, -1.433926686e-01, -1.291239028e-01, -1.144869548e-01, -9.948916584e-02, -8.413838969e-02, -6.844299122e-02, -5.241184420e-02, -3.605432835e-02, -1.938032568e-02, -2.400215989e-03, 1.487512830e-02, 3.243434814e-02, 5.026560463e-02, 6.835658650e-02, 8.669451848e-02, 1.052661703e-01, 1.240578665e-01, 1.430554972e-01, 1.622445294e-01, 1.816100188e-01, 2.011366233e-01, 2.208086160e-01, 2.406098997e-01, 2.605240223e-01, 2.805341920e-01, 3.006232941e-01, 3.207739079e-01, 3.409683246e-01, 3.611885658e-01, 3.814164020e-01, 4.016333728e-01, 4.218208066e-01, 4.419598417e-01, 4.620314471e-01, 4.820164447e-01, 5.018955312e-01, 5.216493005e-01, 5.412582676e-01, 5.607028909e-01, 5.799635969e-01, 5.990208039e-01, 6.178549462e-01, 6.364464992e-01, 6.547760038e-01, 6.728240918e-01, 6.905715105e-01, 7.079991487e-01, 7.250880615e-01, 7.418194960e-01, 7.581749163e-01, 7.741360291e-01, 7.896848091e-01, 8.048035237e-01, 8.194747581e-01, 8.336814403e-01, 8.474068653e-01, 8.606347196e-01, 8.733491047e-01, 8.855345614e-01, 8.971760921e-01, }; const float wav_buzzy_q[] = { 3.921090973e-01, 3.710671298e-01, 3.496552835e-01, 3.278907715e-01, 3.057913244e-01, 2.833751720e-01, 2.606610243e-01, 2.376680512e-01, 2.144158626e-01, 1.909244859e-01, 1.672143448e-01, 1.433062356e-01, 1.192213037e-01, 9.498101970e-02, 7.060715393e-02, 4.612175125e-02, 2.154710486e-02, -3.094270391e-03, -2.777966504e-02, -5.248620266e-02, -7.719086784e-02, -1.018705345e-01, -1.265019949e-01, -1.510619881e-01, -1.755272299e-01, -1.998744418e-01, -2.240803811e-01, -2.481218702e-01, -2.719758271e-01, -2.956192947e-01, -3.190294711e-01, -3.421837396e-01, -3.650596979e-01, -3.876351885e-01, -4.098883274e-01, -4.317975340e-01, -4.533415596e-01, -4.744995162e-01, -4.952509048e-01, -5.155756431e-01, -5.354540932e-01, -5.548670884e-01, -5.737959594e-01, -5.922225601e-01, -6.101292932e-01, -6.274991343e-01, -6.443156558e-01, -6.605630499e-01, -6.762261512e-01, -6.912904577e-01, -7.057421519e-01, -7.195681200e-01, -7.327559713e-01, -7.452940554e-01, -7.571714796e-01, -7.683781246e-01, -7.789046590e-01, -7.887425535e-01, -7.978840933e-01, -8.063223895e-01, -8.140513898e-01, -8.210658875e-01, -8.273615297e-01, -8.329348239e-01, -8.377831441e-01, -8.419047346e-01, -8.452987138e-01, -8.479650760e-01, -8.499046918e-01, -8.511193078e-01, -8.516115450e-01, -8.513848955e-01, -8.504437180e-01, -8.487932327e-01, -8.464395143e-01, -8.433894838e-01, -8.396508996e-01, -8.352323464e-01, -8.301432243e-01, -8.243937353e-01, -8.179948692e-01, -8.109583889e-01, -8.032968136e-01, -7.950234015e-01, -7.861521310e-01, -7.766976816e-01, -7.666754126e-01, -7.561013418e-01, -7.449921229e-01, -7.333650217e-01, -7.212378917e-01, -7.086291489e-01, -6.955577451e-01, -6.820431417e-01, -6.681052811e-01, -6.537645590e-01, -6.390417947e-01, -6.239582017e-01, -6.085353570e-01, -5.927951707e-01, -5.767598544e-01, -5.604518891e-01, -5.438939936e-01, -5.271090915e-01, -5.101202786e-01, -4.929507898e-01, -4.756239655e-01, -4.581632190e-01, -4.405920020e-01, -4.229337719e-01, -4.052119579e-01, -3.874499276e-01, -3.696709537e-01, -3.518981807e-01, -3.341545925e-01, -3.164629791e-01, -2.988459046e-01, -2.813256753e-01, -2.639243080e-01, -2.466634991e-01, -2.295645940e-01, -2.126485573e-01, -1.959359431e-01, -1.794468669e-01, -1.632009772e-01, -1.472174285e-01, -1.315148550e-01, -1.161113446e-01, -1.010244149e-01, -8.627098888e-02, -7.186737238e-02, -5.782923220e-02, -4.417157535e-02, -3.090872928e-02, -1.805432328e-02, -5.621270972e-03, 6.378246124e-03, 1.793279374e-02, 2.903169890e-02, 3.966506271e-02, 4.982377189e-02, 5.949950915e-02, 6.868476216e-02, 7.737283135e-02, 8.555783637e-02, 9.323472123e-02, 1.003992582e-01, 1.070480503e-01, 1.131785326e-01, 1.187889720e-01, 1.238784660e-01, 1.284469398e-01, 1.324951424e-01, 1.360246412e-01, 1.390378154e-01, 1.415378483e-01, 1.435287176e-01, 1.450151858e-01, 1.460027880e-01, 1.464978190e-01, 1.465073200e-01, 1.460390624e-01, 1.451015326e-01, 1.437039137e-01, 1.418560673e-01, 1.395685144e-01, 1.368524141e-01, 1.337195428e-01, 1.301822713e-01, 1.262535417e-01, 1.219468432e-01, 1.172761868e-01, 1.122560798e-01, 1.069014993e-01, 1.012278647e-01, 9.525101032e-02, 8.898715643e-02, 8.245288062e-02, 7.566508824e-02, 6.864098245e-02, 6.139803392e-02, 5.395395016e-02, 4.632664460e-02, 3.853420535e-02, 3.059486387e-02, 2.252696341e-02, 1.434892747e-02, 6.079228126e-03, -2.263645514e-03, -1.066121888e-02, -1.909506328e-02, -2.754682714e-02, -3.599826696e-02, -4.443127800e-02, -5.282792458e-02, -6.117047012e-02, -6.944140656e-02, -7.762348346e-02, -8.569973644e-02, -9.365351513e-02, -1.014685104e-01, -1.091287810e-01, -1.166187795e-01, -1.239233771e-01, -1.310278885e-01, -1.379180950e-01, -1.445802670e-01, -1.510011860e-01, -1.571681652e-01, -1.630690691e-01, -1.686923325e-01, -1.740269779e-01, -1.790626322e-01, -1.837895424e-01, -1.881985896e-01, -1.922813026e-01, -1.960298696e-01, -1.994371494e-01, -2.024966807e-01, -2.052026910e-01, -2.075501033e-01, -2.095345425e-01, -2.111523399e-01, -2.124005367e-01, -2.132768864e-01, -2.137798553e-01, -2.139086229e-01, -2.136630795e-01, -2.130438243e-01, -2.120521606e-01, -2.106900908e-01, -2.089603102e-01, -2.068661988e-01, -2.044118128e-01, -2.016018741e-01, -1.984417597e-01, -1.949374888e-01, -1.910957095e-01, -1.869236846e-01, -1.824292755e-01, -1.776209260e-01, -1.725076443e-01, -1.670989849e-01, -1.614050288e-01, -1.554363632e-01, -1.492040603e-01, -1.427196553e-01, -1.359951235e-01, -1.290428569e-01, -1.218756398e-01, -1.145066241e-01, -1.069493038e-01, -9.921748903e-02, -9.132527928e-02, -8.328703680e-02, -7.511735904e-02, -6.683105094e-02, -5.844309687e-02, -4.996863242e-02, -4.142291581e-02, -3.282129930e-02, -2.417920039e-02, -1.551207308e-02, -6.835378984e-03, 1.835441365e-03, 1.048499719e-02, 1.909797596e-02, 2.765917170e-02, 3.615351297e-02, 4.456609068e-02, 5.288218539e-02, 6.108729434e-02, 6.916715794e-02, 7.710778579e-02, 8.489548218e-02, 9.251687098e-02, 9.995891989e-02, 1.072089640e-01, 1.142547288e-01, 1.210843520e-01, 1.276864051e-01, 1.340499138e-01, 1.401643775e-01, 1.460197883e-01, 1.516066485e-01, 1.569159872e-01, 1.619393769e-01, 1.666689473e-01, 1.710973997e-01, 1.752180196e-01, 1.790246880e-01, 1.825118921e-01, 1.856747343e-01, 1.885089408e-01, 1.910108685e-01, 1.931775107e-01, 1.950065017e-01, 1.964961207e-01, 1.976452936e-01, 1.984535943e-01, 1.989212448e-01, 1.990491136e-01, 1.988387131e-01, 1.982921965e-01, 1.974123522e-01, 1.962025984e-01, 1.946669755e-01, 1.928101382e-01, 1.906373454e-01, 1.881544503e-01, 1.853678884e-01, 1.822846649e-01, 1.789123411e-01, 1.752590191e-01, 1.713333267e-01, 1.671444003e-01, 1.627018672e-01, 1.580158276e-01, 1.530968346e-01, 1.479558740e-01, 1.426043439e-01, 1.370540323e-01, 1.313170951e-01, 1.254060324e-01, 1.193336656e-01, 1.131131122e-01, 1.067577616e-01, 1.002812492e-01, 9.369743126e-02, 8.702035797e-02, 8.026424745e-02, 7.344345872e-02, 6.657246463e-02, 5.966582457e-02, 5.273815706e-02, 4.580411219e-02, 3.887834406e-02, 3.197548317e-02, 2.511010894e-02, 1.829672222e-02, 1.154971806e-02, 4.883358653e-03, -1.688253549e-03, -8.151202293e-03, -1.449178372e-02, -2.069653214e-02, -2.675224534e-02, -3.264600944e-02, -3.836522318e-02, -4.389762164e-02, -4.923129934e-02, -5.435473268e-02, -5.925680161e-02, -6.392681067e-02, -6.835450913e-02, -7.253011037e-02, -7.644431039e-02, -8.008830539e-02, -8.345380850e-02, -8.653306551e-02, -8.931886957e-02, -9.180457497e-02, -9.398410983e-02, -9.585198772e-02, -9.740331824e-02, -9.863381642e-02, -9.953981114e-02, -1.001182523e-01, -1.003667167e-01, -1.002834132e-01, -9.986718637e-02, -9.911751884e-02, -9.803453286e-02, -9.661899038e-02, -9.487229209e-02, -9.279647519e-02, -9.039420998e-02, -8.766879540e-02, -8.462415320e-02, -8.126482111e-02, -7.759594483e-02, -7.362326881e-02, -6.935312601e-02, -6.479242654e-02, -5.994864513e-02, -5.482980771e-02, -4.944447678e-02, -4.380173591e-02, -3.791117318e-02, -3.178286371e-02, -2.542735126e-02, -1.885562891e-02, -1.207911897e-02, -5.109651958e-03, 2.040555067e-03, 9.358921028e-03, 1.683252399e-02, 2.444812498e-02, 3.219219246e-02, 4.005092732e-02, 4.801028846e-02, 5.605601875e-02, 6.417367156e-02, 7.234863756e-02, 8.056617193e-02, 8.881142179e-02, 9.706945398e-02, 1.053252829e-01, 1.135638985e-01, 1.217702946e-01, 1.299294967e-01, 1.380265907e-01, 1.460467504e-01, 1.539752655e-01, 1.617975701e-01, 1.694992694e-01, 1.770661675e-01, 1.844842944e-01, 1.917399323e-01, 1.988196423e-01, 2.057102897e-01, 2.123990697e-01, 2.188735314e-01, 2.251216028e-01, 2.311316134e-01, 2.368923174e-01, 2.423929157e-01, 2.476230770e-01, 2.525729583e-01, 2.572332244e-01, 2.615950668e-01, 2.656502213e-01, 2.693909850e-01, 2.728102317e-01, 2.759014272e-01, 2.786586432e-01, 2.810765691e-01, 2.831505248e-01, 2.848764702e-01, 2.862510152e-01, 2.872714274e-01, 2.879356396e-01, 2.882422553e-01, 2.881905535e-01, 2.877804918e-01, 2.870127091e-01, 2.858885261e-01, 2.844099454e-01, 2.825796498e-01, 2.804009995e-01, 2.778780285e-01, 2.750154389e-01, 2.718185951e-01, 2.682935157e-01, 2.644468648e-01, 2.602859424e-01, 2.558186727e-01, 2.510535922e-01, 2.459998359e-01, 2.406671232e-01, 2.350657418e-01, 2.292065313e-01, 2.231008656e-01, 2.167606336e-01, 2.101982201e-01, 2.034264848e-01, 1.964587409e-01, 1.893087324e-01, 1.819906115e-01, 1.745189136e-01, 1.669085332e-01, 1.591746981e-01, 1.513329435e-01, 1.433990845e-01, 1.353891896e-01, 1.273195519e-01, 1.192066615e-01, 1.110671760e-01, 1.029178915e-01, 9.477571312e-02, 8.665762515e-02, 7.858066069e-02, 7.056187160e-02, 6.261829802e-02, 5.476693786e-02, 4.702471630e-02, 3.940845528e-02, 3.193484307e-02, 2.462040402e-02, 1.748146843e-02, 1.053414267e-02, 3.794279613e-03, -2.722550611e-03, -9.001089472e-03, -1.502641846e-02, -2.078398700e-02, -2.625963986e-02, -3.143964394e-02, -3.631071444e-02, -4.086004039e-02, -4.507530934e-02, -4.894473147e-02, -5.245706268e-02, -5.560162699e-02, -5.836833801e-02, -6.074771939e-02, -6.273092447e-02, -6.430975478e-02, -6.547667757e-02, -6.622484234e-02, -6.654809610e-02, -6.644099772e-02, -6.589883096e-02, -6.491761644e-02, -6.349412233e-02, -6.162587390e-02, -5.931116177e-02, -5.654904898e-02, -5.333937673e-02, -4.968276886e-02, -4.558063510e-02, -4.103517295e-02, -3.604936831e-02, -3.062699478e-02, -2.477261169e-02, -1.849156077e-02, -1.178996162e-02, -4.674705766e-03, 2.846550483e-03, 1.076539448e-02, 1.907266696e-02, 2.775847299e-02, 3.681219417e-02, 4.622250207e-02, 5.597737279e-02, 6.606410277e-02, 7.646932571e-02, 8.717903065e-02, 9.817858109e-02, 1.094527352e-01, 1.209856671e-01, 1.327609892e-01, 1.447617751e-01, 1.569705841e-01, 1.693694861e-01, 1.819400874e-01, 1.946635577e-01, 2.075206571e-01, 2.204917646e-01, 2.335569072e-01, 2.466957887e-01, 2.598878206e-01, 2.731121523e-01, 2.863477022e-01, 2.995731894e-01, 3.127671659e-01, 3.259080482e-01, 3.389741507e-01, 3.519437180e-01, 3.647949581e-01, 3.775060754e-01, 3.900553043e-01, 4.024209418e-01, 4.145813813e-01, 4.265151456e-01, 4.382009196e-01, 4.496175836e-01, 4.607442453e-01, 4.715602729e-01, 4.820453260e-01, 4.921793882e-01, 5.019427974e-01, 5.113162770e-01, 5.202809655e-01, 5.288184466e-01, 5.369107773e-01, 5.445405169e-01, 5.516907537e-01, 5.583451323e-01, 5.644878792e-01, 5.701038278e-01, 5.751784427e-01, 5.796978427e-01, 5.836488235e-01, 5.870188785e-01, 5.897962193e-01, 5.919697945e-01, 5.935293086e-01, 5.944652380e-01, 5.947688475e-01, 5.944322047e-01, 5.934481934e-01, 5.918105261e-01, 5.895137548e-01, 5.865532809e-01, 5.829253636e-01, 5.786271275e-01, 5.736565681e-01, 5.680125568e-01, 5.616948444e-01, 5.547040628e-01, 5.470417261e-01, 5.387102302e-01, 5.297128505e-01, 5.200537394e-01, 5.097379216e-01, 4.987712886e-01, 4.871605915e-01, 4.749134332e-01, 4.620382588e-01, 4.485443450e-01, 4.344417882e-01, 4.197414914e-01, 4.044551504e-01, 3.885952381e-01, 3.721749881e-01, 3.552083774e-01, 3.377101075e-01, 3.196955851e-01, 3.011809013e-01, 2.821828102e-01, 2.627187062e-01, 2.428066009e-01, 2.224650986e-01, 2.017133715e-01, 1.805711337e-01, 1.590586147e-01, 1.371965322e-01, 1.150060645e-01, 9.250882135e-02, 6.972681558e-02, 4.668243319e-02, 2.339840346e-02, -1.022315231e-04, -2.379614765e-02, -4.765976992e-02, -7.166930386e-02, -9.580076712e-02, -1.200300213e-01, -1.443328040e-01, -1.686847606e-01, -1.930614765e-01, -2.174385092e-01, -2.417914201e-01, -2.660958066e-01, -2.903273336e-01, -3.144617652e-01, -3.384749958e-01, -3.623430810e-01, -3.860422686e-01, -4.095490284e-01, -4.328400823e-01, -4.558924334e-01, -4.786833952e-01, -5.011906193e-01, -5.233921235e-01, -5.452663189e-01, -5.667920359e-01, -5.879485500e-01, -6.087156070e-01, -6.290734469e-01, -6.490028272e-01, -6.684850454e-01, -6.875019610e-01, -7.060360159e-01, -7.240702541e-01, -7.415883411e-01, -7.585745815e-01, -7.750139358e-01, -7.908920368e-01, -8.061952039e-01, -8.209104575e-01, -8.350255315e-01, -8.485288854e-01, -8.614097144e-01, -8.736579596e-01, -8.852643159e-01, -8.962202402e-01, -9.065179567e-01, -9.161504629e-01, -9.251115334e-01, -9.333957227e-01, -9.409983675e-01, -9.479155870e-01, -9.541442833e-01, -9.596821391e-01, -9.645276162e-01, -9.686799513e-01, -9.721391520e-01, -9.749059907e-01, -9.769819987e-01, -9.783694579e-01, -9.790713928e-01, -9.790915609e-01, -9.784344421e-01, -9.771052275e-01, -9.751098071e-01, -9.724547570e-01, -9.691473251e-01, -9.651954167e-01, -9.606075790e-01, -9.553929848e-01, -9.495614154e-01, -9.431232433e-01, -9.360894141e-01, -9.284714269e-01, -9.202813158e-01, -9.115316291e-01, -9.022354092e-01, -8.924061718e-01, -8.820578841e-01, -8.712049430e-01, -8.598621534e-01, -8.480447052e-01, -8.357681508e-01, -8.230483819e-01, -8.099016064e-01, -7.963443248e-01, -7.823933068e-01, -7.680655674e-01, -7.533783434e-01, -7.383490696e-01, -7.229953550e-01, -7.073349587e-01, -6.913857671e-01, -6.751657695e-01, -6.586930354e-01, -6.419856907e-01, -6.250618953e-01, -6.079398198e-01, -5.906376235e-01, -5.731734320e-01, -5.555653152e-01, -5.378312664e-01, -5.199891805e-01, -5.020568342e-01, -4.840518649e-01, -4.659917517e-01, -4.478937959e-01, -4.297751020e-01, -4.116525601e-01, -3.935428277e-01, -3.754623132e-01, -3.574271590e-01, -3.394532258e-01, -3.215560775e-01, -3.037509667e-01, -2.860528202e-01, -2.684762267e-01, -2.510354233e-01, -2.337442842e-01, -2.166163092e-01, -1.996646133e-01, -1.829019167e-01, -1.663405362e-01, -1.499923761e-01, -1.338689210e-01, -1.179812286e-01, -1.023399237e-01, -8.695519218e-02, -7.183677638e-02, -5.699397096e-02, -4.243561932e-02, -2.817011077e-02, -1.420537846e-02, -5.488978346e-04, 1.279231417e-02, 2.581169929e-02, 3.850315752e-02, 5.086104604e-02, 6.288017757e-02, 7.455581809e-02, 8.588368407e-02, 9.685993907e-02, 1.074811898e-01, 1.177444819e-01, 1.276472947e-01, 1.371875359e-01, 1.463635361e-01, 1.551740419e-01, 1.636182095e-01, 1.716955976e-01, 1.794061599e-01, 1.867502371e-01, 1.937285488e-01, 2.003421849e-01, 2.065925971e-01, 2.124815896e-01, 2.180113098e-01, 2.231842388e-01, 2.280031817e-01, 2.324712579e-01, 2.365918907e-01, 2.403687971e-01, 2.438059780e-01, 2.469077072e-01, 2.496785212e-01, 2.521232089e-01, 2.542468005e-01, 2.560545576e-01, 2.575519622e-01, 2.587447064e-01, 2.596386816e-01, 2.602399687e-01, 2.605548273e-01, 2.605896855e-01, 2.603511302e-01, 2.598458965e-01, 2.590808585e-01, 2.580630190e-01, 2.567995006e-01, 2.552975360e-01, 2.535644588e-01, 2.516076950e-01, 2.494347538e-01, 2.470532195e-01, 2.444707429e-01, 2.416950336e-01, 2.387338518e-01, 2.355950015e-01, 2.322863223e-01, 2.288156832e-01, 2.251909752e-01, 2.214201053e-01, 2.175109900e-01, 2.134715496e-01, 2.093097019e-01, 2.050333577e-01, 2.006504147e-01, 1.961687532e-01, 1.915962311e-01, 1.869406799e-01, 1.822099000e-01, 1.774116571e-01, 1.725536785e-01, 1.676436496e-01, 1.626892108e-01, 1.576979540e-01, 1.526774204e-01, 1.476350976e-01, 1.425784170e-01, 1.375147518e-01, 1.324514146e-01, 1.273956559e-01, 1.223546619e-01, 1.173355529e-01, 1.123453819e-01, 1.073911332e-01, 1.024797206e-01, 9.761798668e-02, 9.281270148e-02, 8.807056114e-02, 8.339818706e-02, 7.880212475e-02, 7.428884286e-02, 6.986473212e-02, 6.553610440e-02, 6.130919165e-02, 5.719014485e-02, 5.318503296e-02, 4.929984178e-02, 4.554047276e-02, 4.191274179e-02, 3.842237782e-02, 3.507502150e-02, 3.187622364e-02, 2.883144361e-02, 2.594604761e-02, 2.322530683e-02, 2.067439549e-02, 1.829838869e-02, 1.610226022e-02, 1.409088015e-02, 1.226901228e-02, 1.064131144e-02, 9.212320681e-03, 7.986468233e-03, 6.968064353e-03, 6.161297994e-03, 5.570233314e-03, 5.198806025e-03, 5.050819585e-03, 5.129941223e-03, 5.439697824e-03, 5.983471644e-03, 6.764495895e-03, 7.785850175e-03, 9.050455769e-03, 1.056107081e-02, 1.232028535e-02, 1.433051625e-02, 1.659400204e-02, 1.911279764e-02, 2.188876897e-02, 2.492358759e-02, 2.821872511e-02, 3.177544770e-02, 3.559481051e-02, 3.967765199e-02, 4.402458830e-02, 4.863600771e-02, 5.351206490e-02, 5.865267547e-02, 6.405751035e-02, 6.972599033e-02, 7.565728068e-02, 8.185028583e-02, 8.830364418e-02, 9.501572307e-02, 1.019846138e-01, 1.092081270e-01, 1.166837879e-01, 1.244088320e-01, 1.323802011e-01, 1.405945390e-01, 1.490481883e-01, 1.577371864e-01, 1.666572631e-01, 1.758038370e-01, 1.851720138e-01, 1.947565835e-01, 2.045520187e-01, 2.145524735e-01, 2.247517821e-01, 2.351434582e-01, 2.457206948e-01, 2.564763645e-01, 2.674030196e-01, 2.784928939e-01, 2.897379036e-01, 3.011296496e-01, 3.126594198e-01, 3.243181923e-01, 3.360966388e-01, 3.479851285e-01, 3.599737326e-01, 3.720522295e-01, 3.842101101e-01, 3.964365843e-01, 4.087205872e-01, 4.210507866e-01, 4.334155905e-01, 4.458031554e-01, 4.582013955e-01, 4.705979912e-01, 4.829804000e-01, 4.953358659e-01, 5.076514314e-01, 5.199139478e-01, 5.321100884e-01, 5.442263599e-01, 5.562491160e-01, 5.681645709e-01, 5.799588128e-01, 5.916178188e-01, 6.031274693e-01, 6.144735637e-01, 6.256418358e-01, 6.366179700e-01, 6.473876178e-01, 6.579364146e-01, 6.682499969e-01, 6.783140199e-01, 6.881141750e-01, 6.976362083e-01, 7.068659386e-01, 7.157892760e-01, 7.243922407e-01, 7.326609822e-01, 7.405817977e-01, 7.481411520e-01, 7.553256964e-01, 7.621222882e-01, 7.685180099e-01, 7.745001888e-01, 7.800564163e-01, 7.851745670e-01, 7.898428182e-01, 7.940496689e-01, 7.977839586e-01, 8.010348862e-01, 8.037920285e-01, 8.060453583e-01, 8.077852628e-01, 8.090025609e-01, 8.096885208e-01, 8.098348767e-01, 8.094338459e-01, 8.084781441e-01, 8.069610018e-01, 8.048761791e-01, 8.022179802e-01, 7.989812677e-01, 7.951614762e-01, 7.907546246e-01, 7.857573288e-01, 7.801668130e-01, 7.739809205e-01, 7.671981240e-01, 7.598175348e-01, 7.518389113e-01, 7.432626669e-01, 7.340898770e-01, 7.243222851e-01, 7.139623079e-01, 7.030130401e-01, 6.914782575e-01, 6.793624197e-01, 6.666706719e-01, 6.534088456e-01, 6.395834585e-01, 6.252017131e-01, 6.102714948e-01, 5.948013688e-01, 5.788005760e-01, 5.622790280e-01, 5.452473010e-01, 5.277166290e-01, 5.096988956e-01, 4.912066253e-01, 4.722529733e-01, 4.528517149e-01, 4.330172335e-01, 4.127645075e-01, 3.921090973e-01, }; const float* wav_table[] = { wav_sine_i, wav_sine_q, wav_harmonics_i, wav_harmonics_q, wav_buzzy_i, wav_buzzy_q, }; } // namespace warps
70.645991
80
0.702387
guillaume-plantevin
ab6743463b56c9f3efd40d32725b056dce2b39d2
11,140
cpp
C++
src/analysis/processing/qgsalgorithmrastersurfacevolume.cpp
dyna-mis/Hilabeling
cb7d5d4be29624a20c8a367162dbc6fd779b2b52
[ "MIT" ]
null
null
null
src/analysis/processing/qgsalgorithmrastersurfacevolume.cpp
dyna-mis/Hilabeling
cb7d5d4be29624a20c8a367162dbc6fd779b2b52
[ "MIT" ]
null
null
null
src/analysis/processing/qgsalgorithmrastersurfacevolume.cpp
dyna-mis/Hilabeling
cb7d5d4be29624a20c8a367162dbc6fd779b2b52
[ "MIT" ]
1
2021-12-25T08:40:30.000Z
2021-12-25T08:40:30.000Z
/*************************************************************************** qgsalgorithmrasterlayeruniquevalues.cpp --------------------- begin : January 2019 copyright : (C) 2019 by Nyall Dawson email : nyall dot dawson at gmail dot com ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "qgsalgorithmrastersurfacevolume.h" #include "qgsstringutils.h" ///@cond PRIVATE QString QgsRasterSurfaceVolumeAlgorithm::name() const { return QStringLiteral( "rastersurfacevolume" ); } QString QgsRasterSurfaceVolumeAlgorithm::displayName() const { return QObject::tr( "Raster surface volume" ); } QStringList QgsRasterSurfaceVolumeAlgorithm::tags() const { return QObject::tr( "sum,volume,area,height,terrain,dem,elevation" ).split( ',' ); } QString QgsRasterSurfaceVolumeAlgorithm::group() const { return QObject::tr( "Raster analysis" ); } QString QgsRasterSurfaceVolumeAlgorithm::groupId() const { return QStringLiteral( "rasteranalysis" ); } void QgsRasterSurfaceVolumeAlgorithm::initAlgorithm( const QVariantMap & ) { addParameter( new QgsProcessingParameterRasterLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) ); addParameter( new QgsProcessingParameterBand( QStringLiteral( "BAND" ), QObject::tr( "Band number" ), 1, QStringLiteral( "INPUT" ) ) ); addParameter( new QgsProcessingParameterNumber( QStringLiteral( "LEVEL" ), QObject::tr( "Base level" ), QgsProcessingParameterNumber::Double, 0 ) ); addParameter( new QgsProcessingParameterEnum( QStringLiteral( "METHOD" ), QObject::tr( "Method" ), QStringList() << QObject::tr( "Count Only Above Base Level" ) << QObject::tr( "Count Only Below Base Level" ) << QObject::tr( "Subtract Volumes Below Base Level" ) << QObject::tr( "Add Volumes Below Base Level" ) ) ); addParameter( new QgsProcessingParameterFileDestination( QStringLiteral( "OUTPUT_HTML_FILE" ), QObject::tr( "Surface volume report" ), QObject::tr( "HTML files (*.html)" ), QVariant(), true ) ); addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT_TABLE" ), QObject::tr( "Surface volume table" ), QgsProcessing::TypeVector, QVariant(), true, false ) ); addOutput( new QgsProcessingOutputNumber( QStringLiteral( "VOLUME" ), QObject::tr( "Volume" ) ) ); addOutput( new QgsProcessingOutputNumber( QStringLiteral( "PIXEL_COUNT" ), QObject::tr( "Pixel count" ) ) ); addOutput( new QgsProcessingOutputNumber( QStringLiteral( "AREA" ), QObject::tr( "Area" ) ) ); } QString QgsRasterSurfaceVolumeAlgorithm::shortHelpString() const { return QObject::tr( "This algorithm calculates the volume under a raster grid's surface.\n\n" "Several methods of volume calculation are available, which control whether " "only values above or below the specified base level are considered, or " "whether volumes below the base level should be added or subtracted from the total volume.\n\n" "The algorithm outputs the calculated volume, the total area, and the total number of pixels analysed. " "If the 'Count Only Above Base Level' or 'Count Only Below Base Level' methods are used, " "then the calculated area and pixel count only includes pixels which are above or below the " "specified base level respectively.\n\n" "Units of the calculated volume are dependent on the coordinate reference system of " "the input raster file. For a CRS in meters, with a DEM height in meters, the calculated " "value will be in meters³. If instead the input raster is in a geographic coordinate system " "(e.g. latitude/longitude values), then the result will be in degrees² × meters, and an " "appropriate scaling factor will need to be applied in order to convert to meters³." ); } QString QgsRasterSurfaceVolumeAlgorithm::shortDescription() const { return QObject::tr( "Calculates the volume under a raster grid's surface." ); } QgsRasterSurfaceVolumeAlgorithm *QgsRasterSurfaceVolumeAlgorithm::createInstance() const { return new QgsRasterSurfaceVolumeAlgorithm(); } bool QgsRasterSurfaceVolumeAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * ) { QgsRasterLayer *layer = parameterAsRasterLayer( parameters, QStringLiteral( "INPUT" ), context ); int band = parameterAsInt( parameters, QStringLiteral( "BAND" ), context ); if ( !layer ) throw QgsProcessingException( invalidRasterError( parameters, QStringLiteral( "INPUT" ) ) ); mBand = parameterAsInt( parameters, QStringLiteral( "BAND" ), context ); if ( mBand < 1 || mBand > layer->bandCount() ) throw QgsProcessingException( QObject::tr( "Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand ) .arg( layer->bandCount() ) ); mInterface.reset( layer->dataProvider()->clone() ); mHasNoDataValue = layer->dataProvider()->sourceHasNoDataValue( band ); mLayerWidth = layer->width(); mLayerHeight = layer->height(); mExtent = layer->extent(); mCrs = layer->crs(); mRasterUnitsPerPixelX = layer->rasterUnitsPerPixelX(); mRasterUnitsPerPixelY = layer->rasterUnitsPerPixelY(); mSource = layer->source(); mLevel = parameterAsDouble( parameters, QStringLiteral( "LEVEL" ), context ); mMethod = static_cast< Method >( parameterAsEnum( parameters, QStringLiteral( "METHOD" ), context ) ); return true; } QVariantMap QgsRasterSurfaceVolumeAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) { QString outputFile = parameterAsFileOutput( parameters, QStringLiteral( "OUTPUT_HTML_FILE" ), context ); QString areaUnit = QgsUnitTypes::toAbbreviatedString( QgsUnitTypes::distanceToAreaUnit( mCrs.mapUnits() ) ); QString tableDest; std::unique_ptr< QgsFeatureSink > sink; if ( parameters.contains( QStringLiteral( "OUTPUT_TABLE" ) ) && parameters.value( QStringLiteral( "OUTPUT_TABLE" ) ).isValid() ) { QgsFields outFields; outFields.append( QgsField( QStringLiteral( "volume" ), QVariant::Double, QString(), 20, 8 ) ); outFields.append( QgsField( areaUnit.replace( QStringLiteral( "²" ), QStringLiteral( "2" ) ), QVariant::Double, QString(), 20, 8 ) ); outFields.append( QgsField( QStringLiteral( "pixel_count" ), QVariant::LongLong ) ); sink.reset( parameterAsSink( parameters, QStringLiteral( "OUTPUT_TABLE" ), context, tableDest, outFields, QgsWkbTypes::NoGeometry, QgsCoordinateReferenceSystem() ) ); if ( !sink ) throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT_TABLE" ) ) ); } double volume = 0; long long count = 0; int maxWidth = QgsRasterIterator::DEFAULT_MAXIMUM_TILE_WIDTH; int maxHeight = QgsRasterIterator::DEFAULT_MAXIMUM_TILE_HEIGHT; int nbBlocksWidth = static_cast< int >( std::ceil( 1.0 * mLayerWidth / maxWidth ) ); int nbBlocksHeight = static_cast< int >( std::ceil( 1.0 * mLayerHeight / maxHeight ) ); int nbBlocks = nbBlocksWidth * nbBlocksHeight; QgsRasterIterator iter( mInterface.get() ); iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent ); int iterLeft = 0; int iterTop = 0; int iterCols = 0; int iterRows = 0; std::unique_ptr< QgsRasterBlock > rasterBlock; while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) ) { feedback->setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks ); for ( int row = 0; row < iterRows; row++ ) { if ( feedback->isCanceled() ) break; for ( int column = 0; column < iterCols; column++ ) { if ( mHasNoDataValue && rasterBlock->isNoData( row, column ) ) { continue; } const double z = rasterBlock->value( row, column ) - mLevel; switch ( mMethod ) { case CountOnlyAboveBaseLevel: if ( z > 0.0 ) { volume += z; count++; } continue; case CountOnlyBelowBaseLevel: if ( z < 0.0 ) { volume += z; count++; } continue; case SubtractVolumesBelowBaseLevel: volume += z; count++; continue; case AddVolumesBelowBaseLevel: volume += std::fabs( z ); count++; continue; } } } } QVariantMap outputs; double pixelArea = mRasterUnitsPerPixelX * mRasterUnitsPerPixelY; double area = count * pixelArea; volume *= pixelArea; if ( !outputFile.isEmpty() ) { QFile file( outputFile ); if ( file.open( QIODevice::WriteOnly | QIODevice::Text ) ) { const QString encodedAreaUnit = QgsStringUtils::ampersandEncode( areaUnit ); QTextStream out( &file ); out << QStringLiteral( "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/></head><body>\n" ); out << QStringLiteral( "<p>%1: %2 (%3 %4)</p>\n" ).arg( QObject::tr( "Analyzed file" ), mSource, QObject::tr( "band" ) ).arg( mBand ); out << QObject::tr( "<p>%1: %2</p>\n" ).arg( QObject::tr( "Volume" ), QString::number( volume, 'g', 16 ) ); out << QObject::tr( "<p>%1: %2</p>\n" ).arg( QObject::tr( "Pixel count" ) ).arg( count ); out << QObject::tr( "<p>%1: %2 %3</p>\n" ).arg( QObject::tr( "Area" ), QString::number( area, 'g', 16 ), encodedAreaUnit ); out << QStringLiteral( "</body></html>" ); outputs.insert( QStringLiteral( "OUTPUT_HTML_FILE" ), outputFile ); } } if ( sink ) { QgsFeature f; f.setAttributes( QgsAttributes() << volume << area << count ); sink->addFeature( f, QgsFeatureSink::FastInsert ); outputs.insert( QStringLiteral( "OUTPUT_TABLE" ), tableDest ); } outputs.insert( QStringLiteral( "VOLUME" ), volume ); outputs.insert( QStringLiteral( "AREA" ), area ); outputs.insert( QStringLiteral( "PIXEL_COUNT" ), count ); return outputs; } ///@endcond
44.38247
170
0.62325
dyna-mis
0369f1cd6f22e3f59ae90e28252641a56965a5c4
544
cc
C++
pcraster/pcraster-4.2.0/pcraster-4.2.0/source/pcrcom/com_singlevaluedrastertest.cc
quanpands/wflow
b454a55e4a63556eaac3fbabd97f8a0b80901e5a
[ "MIT" ]
null
null
null
pcraster/pcraster-4.2.0/pcraster-4.2.0/source/pcrcom/com_singlevaluedrastertest.cc
quanpands/wflow
b454a55e4a63556eaac3fbabd97f8a0b80901e5a
[ "MIT" ]
null
null
null
pcraster/pcraster-4.2.0/pcraster-4.2.0/source/pcrcom/com_singlevaluedrastertest.cc
quanpands/wflow
b454a55e4a63556eaac3fbabd97f8a0b80901e5a
[ "MIT" ]
null
null
null
#define BOOST_TEST_MODULE pcraster com single_valued_raster #include <boost/test/unit_test.hpp> #include "csftypes.h" #include "com_singlevaluedraster.h" BOOST_AUTO_TEST_CASE(this_) { using namespace com; SingleValuedRaster<UINT1> v(4,5,8); BOOST_CHECK(v.nrRows()==4); BOOST_CHECK(v.nrCols()==5); BOOST_CHECK(v.cell(0,0)==8); BOOST_CHECK(v.cell(3,4)==8); v.setMV(0,2); BOOST_CHECK(v.cell(0,0)==MV_UINT1); BOOST_CHECK(v.isMV(0,0)); BOOST_CHECK(v.isMV(2,0)); } BOOST_AUTO_TEST_CASE(i_raster) { using namespace com; }
18.758621
59
0.713235
quanpands
036cbd9d2e99f378768e00e52d456c3fef8c1f6c
4,073
hpp
C++
Libraries/Support/FileSupport.hpp
jodavis42/WelderEngineRevamp
1b8776c53857e66b2c933321e965bbe12f0df61e
[ "MIT" ]
3
2022-02-11T10:34:33.000Z
2022-02-24T17:44:17.000Z
Code/Foundation/Support/FileSupport.hpp
WelderUpdates/WelderEngineRevamp
1c665239566e9c7156926852f7952948d9286d7d
[ "MIT" ]
null
null
null
Code/Foundation/Support/FileSupport.hpp
WelderUpdates/WelderEngineRevamp
1c665239566e9c7156926852f7952948d9286d7d
[ "MIT" ]
null
null
null
// MIT Licensed (see LICENSE.md). #pragma once namespace Zero { inline u32 EndianSwap(u32 x) { return (x >> 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x << 24); } inline u64 EndianSwap(u64 x) { return (x >> 56) | ((x << 40) & 0x00FF000000000000ULL) | ((x << 24) & 0x0000FF0000000000ULL) | ((x << 8) & 0x000000FF00000000ULL) | ((x >> 8) & 0x00000000FF000000ULL) | ((x >> 24) & 0x0000000000FF0000ULL) | ((x >> 40) & 0x000000000000FF00ULL) | (x << 56); } template <typename bufferType, typename type> void Read(bufferType& buffer, type& data) { Status status; buffer.Read(status, (byte*)&data, sizeof(type)); } template <typename bufferType, typename type> void Write(bufferType& buffer, type& data) { buffer.Write((byte*)&data, sizeof(type)); } template <typename bufferType, typename stringType> void ReadString(bufferType& buffer, uint size, stringType& str) { Status status; byte* data = (byte*)alloca(size + 1); buffer.Read(status, data, size); data[size] = '\0'; str = (char*)data; } template <typename bufferType, typename type> void PeekType(bufferType& buffer, type& data) { Read(buffer, data); int offset = (int)sizeof(data); buffer.Seek(-offset, SeekOrigin::Current); } void WriteStringRangeToFile(StringParam path, StringRange range); DeclareEnum2(FilterResult, Ignore, Include); class FileFilter { public: virtual FilterResult::Enum Filter(StringParam filename) = 0; }; class FilterFileRegex : public FileFilter { public: String mAccept; String mIgnore; FilterFileRegex(StringParam accept, StringParam ignore) : mAccept(accept), mIgnore(ignore) { } FilterResult::Enum Filter(StringParam filename) override; }; class ExtensionFilterFile : public FileFilter { public: String mExtension; bool mCaseSensative; ExtensionFilterFile(StringParam extension, bool caseSensative = false) : mExtension(extension), mCaseSensative(caseSensative) { } FilterResult::Enum Filter(StringParam filename) override; }; // Move the contents of a folder. bool MoveFolderContents(StringParam dest, StringParam source, FileFilter* filter = 0); // Copy the contents of a folder. void CopyFolderContents(StringParam dest, StringParam source, FileFilter* filter = 0); // Finds all files in the given path void FindFilesRecursively(StringParam path, Array<String>& foundFiles); // Finds files matching a filter in the given path void FindFilesRecursively(StringParam path, Array<String>& foundFiles, FileFilter* filter); // Get a time stamp. String GetTimeAndDateStamp(); // Get the date String GetDate(); // Make a time stamped backup of a file. void BackUpFile(StringParam backupPath, StringParam fileName); // Data Block // Allocate a Data Block DataBlock AllocateBlock(size_t size); // Free memory in data block void FreeBlock(DataBlock& block); // Clone (not just copy) new memory will be allocated void CloneBlock(DataBlock& destBlock, const DataBlock& source); u64 ComputeFolderSizeRecursive(StringParam folder); String HumanReadableFileSize(u64 bytes); // A callback that we use with the Platform FileSystemInitializer for // platforms that don't have an actual file system, so we use memory instead. void PopulateVirtualFileSystemWithZip(void* userData); // Download a single file. void Download(StringParam fileName, const Array<byte>& binaryData); // Download a single file. void Download(StringParam fileName, const DataBlock& binaryData); // Download a single file. void Download(StringParam fileName, StringParam binaryData); // Download a single file. void Download(StringParam fileName, const ByteBufferBlock& binaryData); // Download a single file or if it is a directory download a zip of the directory. void Download(StringParam filePath); // If we're passed a single file, download the file individually. // If we're passed a directory or a set of files or directories, then zip them and download as one. void Download(StringParam suggestedNameWithoutExtension, StringParam workingDirectory, const Array<String>& filePaths); } // namespace Zero
28.886525
120
0.741959
jodavis42
036df1406e680bd1a2a6472454450f5855a8223e
596
cpp
C++
LinkedList/linkedlist.cpp
Farhan-Khalifa-Ibrahim/Data-Structure
a2864d70a38cdcb5dbbfb9ef9dc09f49fd2412af
[ "MIT" ]
null
null
null
LinkedList/linkedlist.cpp
Farhan-Khalifa-Ibrahim/Data-Structure
a2864d70a38cdcb5dbbfb9ef9dc09f49fd2412af
[ "MIT" ]
null
null
null
LinkedList/linkedlist.cpp
Farhan-Khalifa-Ibrahim/Data-Structure
a2864d70a38cdcb5dbbfb9ef9dc09f49fd2412af
[ "MIT" ]
null
null
null
#include <bits/stdc++.h> using namespace std; class Node { public: Node(int number); int getdata(); Node *next; private: int data; }; Node::Node(int number) { data = number; next = NULL; } int Node::getdata() { return data; } void printList(Node *n) { while (n != NULL) { cout << n->getdata() << " "; n = n->next; } } int main() { Node *first; Node *second; Node *third; first = new Node(1); second = new Node(2); third = new Node(3); first->next = second; second->next = third; printList(first); }
12.956522
36
0.531879
Farhan-Khalifa-Ibrahim
0370c4933d3ba9c646169dda13548168167fe6ee
5,104
cpp
C++
private/tst/avb_streamhandler/src/IasTestAvbRxStreamClockDomain.cpp
tnishiok/AVBStreamHandler
7621daf8c9238361e030fe35188b921ee8ea2466
[ "BSL-1.0", "BSD-3-Clause" ]
13
2018-09-26T13:32:35.000Z
2021-05-20T10:01:12.000Z
private/tst/avb_streamhandler/src/IasTestAvbRxStreamClockDomain.cpp
keerockl/AVBStreamHandler
c0c9aa92656ae0acd0f57492d4f325eee2f7d13b
[ "BSD-3-Clause" ]
23
2018-10-03T22:45:21.000Z
2020-03-05T23:40:12.000Z
private/tst/avb_streamhandler/src/IasTestAvbRxStreamClockDomain.cpp
keerockl/AVBStreamHandler
c0c9aa92656ae0acd0f57492d4f325eee2f7d13b
[ "BSD-3-Clause" ]
22
2018-09-14T03:55:34.000Z
2021-12-07T01:13:27.000Z
/* * Copyright (C) 2018 Intel Corporation. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ /** * @file IasTestAvbRxStreamClockDomain.cpp * @date 2018 * @brief This file contains the unit tests of the IasAvbRxStreamClockDomain class. */ #include "gtest/gtest.h" #define private public #define protected public #include "avb_streamhandler/IasAvbRxStreamClockDomain.hpp" #include "avb_streamhandler/IasAvbStreamHandlerEnvironment.hpp" #undef protected #undef private #include "test_common/IasSpringVilleInfo.hpp" extern size_t heapSpaceLeft; extern size_t heapSpaceInitSize; namespace IasMediaTransportAvb { class IasTestAvbRxStreamClockDomain : public ::testing::Test { protected: IasTestAvbRxStreamClockDomain(): mRxClockDomain(NULL), mEnvironment(NULL) { } virtual ~IasTestAvbRxStreamClockDomain() {} // Sets up the test fixture. virtual void SetUp() { // needed only for :Update" test // but // needs to be set up here due to ClockDomain gets Ptp on its CTor ASSERT_TRUE(LocalSetup()); heapSpaceLeft = heapSpaceInitSize; mRxClockDomain = new IasAvbRxStreamClockDomain; } virtual void TearDown() { delete mEnvironment; mEnvironment = NULL; delete mRxClockDomain; mRxClockDomain = NULL; heapSpaceLeft = heapSpaceInitSize; } bool LocalSetup() { mEnvironment = new IasAvbStreamHandlerEnvironment(DLT_LOG_INFO); if (mEnvironment) { mEnvironment->setDefaultConfigValues(); if (IasSpringVilleInfo::fetchData()) { IasSpringVilleInfo::printDebugInfo(); mEnvironment->setConfigValue(IasRegKeys::cNwIfName, IasSpringVilleInfo::getInterfaceName()); if (eIasAvbProcOK == mEnvironment->createIgbDevice()) { if (eIasAvbProcOK == mEnvironment->createPtpProxy()) { if (IasAvbStreamHandlerEnvironment::getIgbDevice()) { if (IasAvbStreamHandlerEnvironment::getPtpProxy()) { return true; } } } } } } return false; } IasAvbRxStreamClockDomain* mRxClockDomain; IasAvbStreamHandlerEnvironment* mEnvironment; }; TEST_F(IasTestAvbRxStreamClockDomain, Reset) { ASSERT_TRUE(NULL != mRxClockDomain); IasAvbSrClass cl = IasAvbSrClass::eIasAvbSrClassHigh; uint32_t callsPerSecond = IasAvbTSpec::getPacketsPerSecondByClass(cl); uint64_t skipTime = 0u; uint32_t timestamp = 1u; uint32_t eventRate = 48000u; mEnvironment->setConfigValue(IasRegKeys::cRxClkUpdateInterval, skipTime); // IasAvbStreamHandlerEnvironment::getConfigValue(IasRegKeys::cRxClkUpdateInterval, skipTime) (T) // && (0u != skipTime) (F) mRxClockDomain->reset(cl, timestamp, eventRate); ASSERT_EQ(callsPerSecond, mRxClockDomain->mAvgCallsPerSec); mEnvironment->setConfigValue(IasRegKeys::cRxClkUpdateInterval, "skipTime"); // IasAvbStreamHandlerEnvironment::getConfigValue(IasRegKeys::cRxClkUpdateInterval, skipTime) (F) // && (0u != skipTime) (F) mRxClockDomain->reset(cl, timestamp, eventRate); ASSERT_EQ(callsPerSecond, mRxClockDomain->mAvgCallsPerSec); callsPerSecond = 1E6; skipTime = 1u; mEnvironment->setConfigValue(IasRegKeys::cRxClkUpdateInterval, skipTime); // IasAvbStreamHandlerEnvironment::getConfigValue(IasRegKeys::cRxClkUpdateInterval, skipTime) (T) // && (0u != skipTime) (T) mRxClockDomain->reset(cl, timestamp, eventRate); ASSERT_EQ(callsPerSecond, mRxClockDomain->mAvgCallsPerSec); } TEST_F(IasTestAvbRxStreamClockDomain, Update) { ASSERT_TRUE(NULL != mRxClockDomain); uint32_t deltaMediaClock = 0; uint32_t deltaWallClock = 0; uint32_t events = 6u; uint32_t timestamp = 0u; mRxClockDomain->update(events, timestamp, deltaMediaClock, deltaWallClock); deltaMediaClock = 1; timestamp = 125000; mRxClockDomain->update(events, timestamp, deltaMediaClock, deltaWallClock); } TEST_F(IasTestAvbRxStreamClockDomain, CTor_setSwDeviation) { ASSERT_TRUE(NULL != mRxClockDomain); mEnvironment->setConfigValue(IasRegKeys::cClkRxDeviationLongterm, 1000u); mEnvironment->setConfigValue(IasRegKeys::cClkRxDeviationUnlock, 1000u); delete mRxClockDomain; mRxClockDomain = new IasAvbRxStreamClockDomain(); ASSERT_EQ(1.0f, mRxClockDomain->mFactorLong); ASSERT_EQ(1.0f, mRxClockDomain->mFactorUnlock); } TEST_F(IasTestAvbRxStreamClockDomain, invalidate) { ASSERT_TRUE(NULL != mRxClockDomain); mRxClockDomain->mTimeConstant = 1.0f; mRxClockDomain->mAvgCallsPerSec = 0; mRxClockDomain->mLockState = IasAvbClockDomain::IasAvbLockState::eIasAvbLockStateInit; mRxClockDomain->invalidate(); ASSERT_EQ(1, mRxClockDomain->mAvgCallsPerSec); ASSERT_EQ(1.0f, mRxClockDomain->mTimeConstant); ASSERT_EQ(IasAvbClockDomain::IasAvbLockState::eIasAvbLockStateInit, mRxClockDomain->mLockState); } } // IasMediaTransportAvb
29.674419
100
0.706505
tnishiok
03730e9cc9e6dbb959be34cb8bb22cee50224346
253
cpp
C++
src/cbag/layout/via_wrapper.cpp
ayan-biswas/cbag
0d08394cf39e90bc3acb4a94fd7b5a6560cf103c
[ "BSD-3-Clause" ]
1
2020-01-07T04:44:17.000Z
2020-01-07T04:44:17.000Z
src/cbag/layout/via_wrapper.cpp
skyworksinc/cbag
0d08394cf39e90bc3acb4a94fd7b5a6560cf103c
[ "BSD-3-Clause" ]
null
null
null
src/cbag/layout/via_wrapper.cpp
skyworksinc/cbag
0d08394cf39e90bc3acb4a94fd7b5a6560cf103c
[ "BSD-3-Clause" ]
1
2020-01-07T04:45:13.000Z
2020-01-07T04:45:13.000Z
#include <cbag/layout/via_wrapper.h> namespace cbag { namespace layout { via_wrapper::via_wrapper() = default; via_wrapper::via_wrapper(via &&v, bool add_layers) : v(std::move(v)), add_layers(add_layers) {} } // namespace layout } // namespace cbag
21.083333
95
0.72332
ayan-biswas
0378476e6f80c8f11254a3fe6ec963be47c226ea
719
hpp
C++
src/scene/BVH.hpp
huang-jl/Graphics-Renderer
947c145330aeec9fe127c168e9629aeab84e416e
[ "MIT" ]
null
null
null
src/scene/BVH.hpp
huang-jl/Graphics-Renderer
947c145330aeec9fe127c168e9629aeab84e416e
[ "MIT" ]
null
null
null
src/scene/BVH.hpp
huang-jl/Graphics-Renderer
947c145330aeec9fe127c168e9629aeab84e416e
[ "MIT" ]
null
null
null
#ifndef BVH_HPP #define BVH_HPP #include "AABB.hpp" #include "Hitable.hpp" #include "Ray.hpp" #include <vector> /* * 层次包围体BHV:用AABB实现 * 这里认为层次包围盒也是一个Hitable * 其作用是一个容器,能够高效处理光线和物体是否相交 */ class BVHNode : public Hitable { public: BVHNode() {} // BVHNode(Hitable **l, int n, float time0, float time1); BVHNode(std::vector<shared_ptr<Hitable>> &l,size_t start, size_t end, float time0, float time1); virtual bool bounding_box(float t0, float t1, AABB &output_box) const override; virtual bool hit(const Ray &r, float t_min, float t_max, Hit &rec) const override; /*data*/ shared_ptr<Hitable> left_c; //左孩子,为了通用性,指针为Hitbale shared_ptr<Hitable> right_c; //右孩子 AABB box; }; #endif
25.678571
100
0.698192
huang-jl
0378b92d9bbc2a0decd7fa86b24800700a175488
3,500
hpp
C++
sdl/Util/LogInfo.hpp
sdl-research/hyp
d39f388f9cd283bcfa2f035f399b466407c30173
[ "Apache-2.0" ]
29
2015-01-26T21:49:51.000Z
2021-06-18T18:09:42.000Z
sdl/Util/LogInfo.hpp
hypergraphs/hyp
d39f388f9cd283bcfa2f035f399b466407c30173
[ "Apache-2.0" ]
1
2015-12-08T15:03:15.000Z
2016-01-26T14:31:06.000Z
sdl/Util/LogInfo.hpp
hypergraphs/hyp
d39f388f9cd283bcfa2f035f399b466407c30173
[ "Apache-2.0" ]
4
2015-11-21T14:25:38.000Z
2017-10-30T22:22:00.000Z
// Copyright 2014-2015 SDL plc // 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. /** \file StringConsumer (fn accepting string) for log4cxx LOG_INFO. */ #ifndef LOGINFO_JG2012813_HPP #define LOGINFO_JG2012813_HPP #pragma once #include <sdl/Util/LogLevel.hpp> #include <sdl/Log.hpp> #include <sdl/StringConsumer.hpp> #ifndef NLOG #include <log4cxx/logger.h> #endif namespace sdl { namespace Util { struct LogInfo { explicit LogInfo(std::string const& logname) : logname(logname) {} std::string logname; // TODO: save log4cxx object? for now, let logging cfg change and we reflect that // always. this is used for infos only so perf. shouldn't matter. would use: // LoggerPtr plog; void operator()(std::string const& msg) const { #ifdef NLOG std::cerr << logname << ": " << msg << '\n'; #else LOG4CXX_INFO(log4cxx::Logger::getLogger(logname), msg); #endif } }; inline StringConsumer logInfo(std::string const& module, std::string const& prefix = "sdl.") { return LogInfo(prefix + module); } struct LogAtLevel { explicit LogAtLevel(std::string const& logname_, LogLevel level = kLogInfo) { set(logname_, level); } LogAtLevel(std::string const& logname_, LogLevelPtr levelptr) { set(logname_, levelptr); } LogAtLevel(std::string const& logname_, std::string const& levelName, LogLevel fallbacklevel = kLogInfo) { set(logname_, levelName, fallbacklevel); } void setLevel(std::string const& name, LogLevel fallbacklevel = kLogInfo) { plevel = logLevel(name, fallbacklevel); } void setLevel(LogLevel level = kLogInfo) { plevel = logLevel(level); } void set(std::string logname_) { logname = logname_; #ifndef NLOG plog = log4cxx::Logger::getLogger(logname); #endif } void set(std::string const& logname_, std::string const& logLevelName, LogLevel fallbacklevel = kLogInfo) { set(logname_); setLevel(logLevelName, fallbacklevel); } void set(std::string const& logname_, LogLevel level) { set(logname_); setLevel(level); } void set(std::string const& logname_, LogLevelPtr levelptr) { set(logname_); plevel = levelptr; } std::string logname; // TODO: save log4cxx object? for now, let logging cfg change and we reflect that // always. this is used for warnings only so perf. shouldn't matter. would use: LoggerPtr plog; LogLevelPtr plevel; void operator()(std::string const& msg) const { #ifdef NLOG std::cerr << logname << ": " << msg << '\n'; #else LOG4CXX_LOG(plog, plevel, msg); #endif } }; inline StringConsumer logAtLevel(std::string const& module, std::string const& level, std::string const& prefix = SDL_LOG_PREFIX_STR, LogLevel fallback = kLogInfo) { return LogAtLevel(prefix + module, level, fallback); } inline StringConsumer logAtLevel(std::string const& module, LogLevel level = kLogInfo, std::string const& prefix = SDL_LOG_PREFIX_STR) { return LogAtLevel(prefix + module, level); } }} #endif
33.653846
112
0.702857
sdl-research
037c16bca08a729b681c298b16c40690dd8a7511
6,023
hh
C++
L1Trigger/TrackFindingTracklet/interface/FPGATrackDer.hh
thesps/cmssw
ad5315934948ce96699b29cc1d5b03a59f99634f
[ "Apache-2.0" ]
null
null
null
L1Trigger/TrackFindingTracklet/interface/FPGATrackDer.hh
thesps/cmssw
ad5315934948ce96699b29cc1d5b03a59f99634f
[ "Apache-2.0" ]
null
null
null
L1Trigger/TrackFindingTracklet/interface/FPGATrackDer.hh
thesps/cmssw
ad5315934948ce96699b29cc1d5b03a59f99634f
[ "Apache-2.0" ]
null
null
null
#ifndef FPGATRACKDER_H #define FPGATRACKDER_H #include <iostream> #include <fstream> #include <assert.h> #include <math.h> #include <vector> using namespace std; class FPGATrackDer{ public: FPGATrackDer() { for (unsigned int i=0;i<6;i++){ irinvdphi_[i]=9999999; irinvdzordr_[i]=9999999; iphi0dphi_[i]=9999999; iphi0dzordr_[i]=9999999; itdphi_[i]=9999999; itdzordr_[i]=9999999; iz0dphi_[i]=9999999; iz0dzordr_[i]=9999999; rinvdphi_[i]=0.0; rinvdzordr_[i]=0.0; phi0dphi_[i]=0.0; phi0dzordr_[i]=0.0; tdphi_[i]=0.0; tdzordr_[i]=0.0; z0dphi_[i]=0.0; z0dzordr_[i]=0.0; } for (unsigned int i=0;i<3;i++){ for (unsigned int j=0;j<3;j++){ tdzcorr_[i][j]=0.0; z0dzcorr_[i][j]=0.0; } } } ~FPGATrackDer() { } void setIndex(int layermask,int diskmask,int alphamask, int irinv){ layermask_=layermask; diskmask_=diskmask; alphamask_=alphamask; irinv_=irinv; } int getLayerMask() const {return layermask_;} int getDiskMask() const {return diskmask_;} int getAlphaMask() const {return alphamask_;} int getirinv() const {return irinv_;} void setirinvdphi(int i, int irinvdphi) { irinvdphi_[i]=irinvdphi;} void setirinvdzordr(int i, int irinvdzordr) { irinvdzordr_[i]=irinvdzordr;} void setiphi0dphi(int i, int iphi0dphi) { iphi0dphi_[i]=iphi0dphi;} void setiphi0dzordr(int i, int iphi0dzordr) { iphi0dzordr_[i]=iphi0dzordr;} void setitdphi(int i, int itdphi) { itdphi_[i]=itdphi;} void setitdzordr(int i, int itdzordr) { itdzordr_[i]=itdzordr;} void setiz0dphi(int i, int iz0dphi) { iz0dphi_[i]=iz0dphi;} void setiz0dzordr(int i, int iz0dzordr) { iz0dzordr_[i]=iz0dzordr;} void setitdzcorr(int i,int j, int itdzcorr) {itdzcorr_[i][j]=itdzcorr;} void setiz0dzcorr(int i,int j, int iz0dzcorr) {iz0dzcorr_[i][j]=iz0dzcorr;} void setrinvdphi(int i, double rinvdphi) { rinvdphi_[i]=rinvdphi;} void setrinvdzordr(int i, double rinvdzordr) { rinvdzordr_[i]=rinvdzordr;} void setphi0dphi(int i, double phi0dphi) { phi0dphi_[i]=phi0dphi;} void setphi0dzordr(int i, double phi0dzordr) { phi0dzordr_[i]=phi0dzordr;} void settdphi(int i, double tdphi) { tdphi_[i]=tdphi;} void settdzordr(int i, double tdzordr) { tdzordr_[i]=tdzordr;} void setz0dphi(int i, double z0dphi) { z0dphi_[i]=z0dphi;} void setz0dzordr(int i, double z0dzordr) { z0dzordr_[i]=z0dzordr;} void settdzcorr(int i,int j, double tdzcorr) {tdzcorr_[i][j]=tdzcorr;} void setz0dzcorr(int i,int j, double z0dzcorr) {z0dzcorr_[i][j]=z0dzcorr;} double getrinvdphi(int i) const { return rinvdphi_[i];} double getrinvdzordr(int i) const { return rinvdzordr_[i];} double getphi0dphi(int i) const { return phi0dphi_[i];} double getphi0dzordr(int i) const { return phi0dzordr_[i];} double gettdphi(int i) const { return tdphi_[i];} double gettdzordr(int i) const { return tdzordr_[i];} double getz0dphi(int i) const { return z0dphi_[i];} double getz0dzordr(int i) const { return z0dzordr_[i];} double gettdzcorr(int i,int j) const {return tdzcorr_[i][j];} double getz0dzcorr(int i,int j) const {return z0dzcorr_[i][j];} double getirinvdphi(int i) const { return irinvdphi_[i];} double getirinvdzordr(int i) const { return irinvdzordr_[i];} double getiphi0dphi(int i) const { return iphi0dphi_[i];} double getiphi0dzordr(int i) const { return iphi0dzordr_[i];} double getitdphi(int i) const { return itdphi_[i];} double getitdzordr(int i) const { return itdzordr_[i];} double getiz0dphi(int i) const { return iz0dphi_[i];} double getiz0dzordr(int i) const { return iz0dzordr_[i];} int getitdzcorr(int i,int j) const {return itdzcorr_[i][j];} int getiz0dzcorr(int i,int j) const {return iz0dzcorr_[i][j];} void sett(double t) { t_=t; } double gett() const { return t_; } void fill(int t, double MinvDt[4][12], int iMinvDt[4][12]){ unsigned int nlayer=0; if (layermask_&1) nlayer++; if (layermask_&2) nlayer++; if (layermask_&4) nlayer++; if (layermask_&8) nlayer++; if (layermask_&16) nlayer++; if (layermask_&32) nlayer++; int sign=1; if (t<0) sign=-1; for (unsigned int i=0;i<6;i++){ if (i<nlayer) { MinvDt[0][2*i]=rinvdphi_[i]; MinvDt[1][2*i]=phi0dphi_[i]; MinvDt[2][2*i]=sign*tdphi_[i]; MinvDt[3][2*i]=sign*z0dphi_[i]; MinvDt[0][2*i+1]=sign*rinvdzordr_[i]; MinvDt[1][2*i+1]=sign*phi0dzordr_[i]; MinvDt[2][2*i+1]=tdzordr_[i]; MinvDt[3][2*i+1]=z0dzordr_[i]; iMinvDt[0][2*i]=irinvdphi_[i]; iMinvDt[1][2*i]=iphi0dphi_[i]; iMinvDt[2][2*i]=sign*itdphi_[i]; iMinvDt[3][2*i]=sign*iz0dphi_[i]; iMinvDt[0][2*i+1]=sign*irinvdzordr_[i]; iMinvDt[1][2*i+1]=sign*iphi0dzordr_[i]; iMinvDt[2][2*i+1]=itdzordr_[i]; iMinvDt[3][2*i+1]=iz0dzordr_[i]; } else { MinvDt[0][2*i]=rinvdphi_[i]; MinvDt[1][2*i]=phi0dphi_[i]; MinvDt[2][2*i]=sign*tdphi_[i]; MinvDt[3][2*i]=sign*z0dphi_[i]; MinvDt[0][2*i+1]=rinvdzordr_[i]; MinvDt[1][2*i+1]=phi0dzordr_[i]; MinvDt[2][2*i+1]=sign*tdzordr_[i]; MinvDt[3][2*i+1]=sign*z0dzordr_[i]; iMinvDt[0][2*i]=irinvdphi_[i]; iMinvDt[1][2*i]=iphi0dphi_[i]; iMinvDt[2][2*i]=sign*itdphi_[i]; iMinvDt[3][2*i]=sign*iz0dphi_[i]; iMinvDt[0][2*i+1]=irinvdzordr_[i]; iMinvDt[1][2*i+1]=iphi0dzordr_[i]; iMinvDt[2][2*i+1]=sign*itdzordr_[i]; iMinvDt[3][2*i+1]=sign*iz0dzordr_[i]; } } } private: int irinvdphi_[6]; int irinvdzordr_[6]; int iphi0dphi_[6]; int iphi0dzordr_[6]; int itdphi_[6]; int itdzordr_[6]; int iz0dphi_[6]; int iz0dzordr_[6]; int itdzcorr_[3][3]; int iz0dzcorr_[3][3]; double rinvdphi_[6]; double rinvdzordr_[6]; double phi0dphi_[6]; double phi0dzordr_[6]; double tdphi_[6]; double tdzordr_[6]; double z0dphi_[6]; double z0dzordr_[6]; double tdzcorr_[3][3]; double z0dzcorr_[3][3]; double t_; int layermask_; int diskmask_; int alphamask_; int irinv_; }; #endif
28.956731
78
0.659804
thesps
0380bf57dd0284f716d35ededc515eeab745d947
1,487
cpp
C++
Lezioni/04/11_3.cpp
FoxySeta/unibo-00819-programmazione
e8b54bf38c9f7885b05eabff9bced7c212aeb97e
[ "MIT" ]
3
2021-11-02T16:06:46.000Z
2022-02-15T11:24:15.000Z
Lezioni/04/11_3.cpp
FoxySeta/unibo-00819-programmazione
e8b54bf38c9f7885b05eabff9bced7c212aeb97e
[ "MIT" ]
1
2020-09-25T17:54:52.000Z
2020-09-25T22:15:42.000Z
Lezioni/04/11_3.cpp
FoxySeta/unibo-00819-programmazione
e8b54bf38c9f7885b05eabff9bced7c212aeb97e
[ "MIT" ]
null
null
null
/* Università di Bologna Corso di laurea in Informatica 00819 - Programmazione Stefano Volpe #969766 01/10/2020 11_3.cpp "Comandi condizionali e iterativi", d. 11, es. 3 */ #include <iostream> using namespace std; int main() { cout << "Inserisci interi x, y, z: "; // diverrà più agevole con i vettori int x, y, z; // poco leggibile con input più lunghi di \t cin >> x >> y >> z; cout << "Inserisci oparatore ('-' o '/'): "; char operatore; cin >> operatore; while (operatore != '-' && operatore != '/') // meglio costanti manifeste? { cout << "Errore. Ritenta: "; cin >> operatore; } // diverrà più agevole con lambda e loro alternative if (operatore == '-') // non sostituisco differenze nulle con lo 0 per chiarezza cout << '\t' << x << '\t' << y << '\t' << z << '\n' << x << '\t' << x - x << '\t' << x - y << '\t' << x - z << '\n' << y << '\t' << y - x << '\t' << y - y << '\t' << y - z << '\n' << z << '\t' << z - x << '\t' << z - y << '\t' << z - z << '\n'; else if (!(x && y && z)) cout << "Divisioni per zero non ammesse.\n"; else cout << '\t' << x << '\t' << y << '\t' << z << '\n' << x << '\t' << x / x << '\t' << x / y << '\t' << x / z << '\n' << y << '\t' << y / x << '\t' << y / y << '\t' << y / z << '\n' << z << '\t' << z / x << '\t' << z / y << '\t' << z / z << '\n'; }
31.638298
78
0.417619
FoxySeta
0387f3344dc39e9b5d3d54312b7cacccdef236d1
2,970
cpp
C++
src/Dengo/Init_MemAllocate_Dengo.cpp
hisunnytang/gamer-fork
8ca0cd1dd3ffd5bbd04049a4af5bdf63103b0df9
[ "BSD-3-Clause" ]
null
null
null
src/Dengo/Init_MemAllocate_Dengo.cpp
hisunnytang/gamer-fork
8ca0cd1dd3ffd5bbd04049a4af5bdf63103b0df9
[ "BSD-3-Clause" ]
null
null
null
src/Dengo/Init_MemAllocate_Dengo.cpp
hisunnytang/gamer-fork
8ca0cd1dd3ffd5bbd04049a4af5bdf63103b0df9
[ "BSD-3-Clause" ]
null
null
null
#include "GAMER.h" #ifdef SUPPORT_DENGO // global variables for accessing h_Che_Array[] // --> also used by Dengo_Prepare.cpp and Dengo_Close.cpp // --> they are not declared in "Global.h" simply because they are only used by a few Dengo routines int Che_NField = NULL_INT; int CheIdx_Dens = Idx_Undefined; int CheIdx_sEint = Idx_Undefined; int CheIdx_Ek = Idx_Undefined; int CheIdx_e = Idx_Undefined; int CheIdx_HI = Idx_Undefined; int CheIdx_HII = Idx_Undefined; int CheIdx_HeI = Idx_Undefined; int CheIdx_HeII = Idx_Undefined; int CheIdx_HeIII = Idx_Undefined; int CheIdx_HM = Idx_Undefined; int CheIdx_H2I = Idx_Undefined; int CheIdx_H2II = Idx_Undefined; int CheIdx_CoolingTime = Idx_Undefined; int CheIdx_Gamma = Idx_Undefined; int CheIdx_MolecularWeight = Idx_Undefined; int CheIdx_Temperature = Idx_Undefined; //------------------------------------------------------------------------------------------------------- // Function : Init_MemAllocate_Dengo // Description : Allocate the CPU memory for the Dengo solver // // Note : 1. Work even when GPU is enabled // 2. Invoked by Init_MemAllocate() // 3. Also set global variables for accessing h_Che_Array[] // --> Declared on the top of this file // // Parameter : Che_NPG : Number of patch groups to be evaluated at a time //------------------------------------------------------------------------------------------------------- void Init_MemAllocate_Dengo( const int Che_NPG ) { // nothing to do if Dengo is disabled if ( !DENGO_ACTIVATE ) return; // set global variables related to h_Che_Array[] Che_NField = 0; CheIdx_Dens = Che_NField ++; CheIdx_sEint = Che_NField ++; CheIdx_Ek = Che_NField ++; //if ( DENGO_PRIMORDIAL >= DENGO_PRI_CHE_NSPE6 ) { CheIdx_e = Che_NField ++; CheIdx_HI = Che_NField ++; CheIdx_HII = Che_NField ++; CheIdx_HeI = Che_NField ++; CheIdx_HeII = Che_NField ++; CheIdx_HeIII = Che_NField ++; //} //if ( DENGO_PRIMORDIAL >= DENGO_PRI_CHE_NSPE9 ) { CheIdx_HM = Che_NField ++; CheIdx_H2I = Che_NField ++; CheIdx_H2II = Che_NField ++; //} /* if ( DENGO_PRIMORDIAL >= DENGO_PRI_CHE_NSPE12 ) { CheIdx_DI = Che_NField ++; CheIdx_DII = Che_NField ++; CheIdx_HDI = Che_NField ++; } if ( DENGO_METAL ) CheIdx_Metal = Che_NField ++; */ CheIdx_CoolingTime = Che_NField++; CheIdx_Gamma = Che_NField++; CheIdx_MolecularWeight = Che_NField++; CheIdx_Temperature = Che_NField++; fprintf(stderr, "done creating array in MemAllocate_Denngo %d, %d, %d \n", Che_NField, Che_NPG, PS2); // allocate the input/output array for the Dengo solver for (int t=0; t<2; t++) h_Che_Array[t] = new real [ (long)Che_NField*(long)Che_NPG*(long)CUBE(PS2) ]; } // FUNCTION : Init_MemAllocate_Dengo #endif // #ifdef SUPPORT_DENGO
30.618557
105
0.622896
hisunnytang
038b11d5956e807a02dc734015bd8dda3048d7b6
3,780
cpp
C++
source/styles/conditional_format.cpp
wuganhao/xlnt
4acfa185c0891e64b044ddac16046baee011bdf5
[ "Unlicense" ]
null
null
null
source/styles/conditional_format.cpp
wuganhao/xlnt
4acfa185c0891e64b044ddac16046baee011bdf5
[ "Unlicense" ]
null
null
null
source/styles/conditional_format.cpp
wuganhao/xlnt
4acfa185c0891e64b044ddac16046baee011bdf5
[ "Unlicense" ]
1
2021-11-22T10:07:34.000Z
2021-11-22T10:07:34.000Z
// Copyright (c) 2014-2021 Thomas Fussell // Copyright (c) 2010-2015 openpyxl // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE // // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file #include <xlnt/styles/border.hpp> #include <xlnt/styles/conditional_format.hpp> #include <xlnt/styles/fill.hpp> #include <xlnt/styles/font.hpp> #include <detail/implementations/conditional_format_impl.hpp> #include <detail/implementations/stylesheet.hpp> namespace xlnt { condition condition::text_starts_with(const std::string &text) { condition c; c.type_ = type::contains_text; c.operator_ = condition_operator::starts_with; c.text_comparand_ = text; return c; } condition condition::text_ends_with(const std::string &text) { condition c; c.type_ = type::contains_text; c.operator_ = condition_operator::ends_with; c.text_comparand_ = text; return c; } condition condition::text_contains(const std::string &text) { condition c; c.type_ = type::contains_text; c.operator_ = condition_operator::contains; c.text_comparand_ = text; return c; } condition condition::text_does_not_contain(const std::string &text) { condition c; c.type_ = type::contains_text; c.operator_ = condition_operator::does_not_contain; c.text_comparand_ = text; return c; } conditional_format::conditional_format(detail::conditional_format_impl *d) : d_(d) { } bool conditional_format::operator==(const conditional_format &other) const { return d_ == other.d_; } bool conditional_format::operator!=(const conditional_format &other) const { return !(*this == other); } bool conditional_format::has_border() const { return d_->border_id.is_set(); } xlnt::border conditional_format::border() const { return d_->parent->borders.at(d_->border_id.get()); } conditional_format conditional_format::border(const xlnt::border &new_border) { d_->border_id = d_->parent->find_or_add(d_->parent->borders, new_border); return *this; } bool conditional_format::has_fill() const { return d_->fill_id.is_set(); } xlnt::fill conditional_format::fill() const { return d_->parent->fills.at(d_->fill_id.get()); } conditional_format conditional_format::fill(const xlnt::fill &new_fill) { d_->fill_id = d_->parent->find_or_add(d_->parent->fills, new_fill); return *this; } bool conditional_format::has_font() const { return d_->font_id.is_set(); } xlnt::font conditional_format::font() const { return d_->parent->fonts.at(d_->font_id.get()); } conditional_format conditional_format::font(const xlnt::font &new_font) { d_->font_id = d_->parent->find_or_add(d_->parent->fonts, new_font); return *this; } } // namespace xlnt
28.208955
80
0.73254
wuganhao
038c602020ed7fb1b51e746ffbc7d102648ad832
1,810
cc
C++
cc/layer_quad.cc
GnorTech/chromium
e1c7731d5bd099ca5544fcf8eda3867d4ce5bab5
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
1
2018-03-10T13:08:49.000Z
2018-03-10T13:08:49.000Z
cc/layer_quad.cc
GnorTech/chromium
e1c7731d5bd099ca5544fcf8eda3867d4ce5bab5
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
null
null
null
cc/layer_quad.cc
GnorTech/chromium
e1c7731d5bd099ca5544fcf8eda3867d4ce5bab5
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
1
2020-11-04T07:19:31.000Z
2020-11-04T07:19:31.000Z
// Copyright 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "cc/layer_quad.h" #include "base/logging.h" #include "ui/gfx/quad_f.h" namespace cc { LayerQuad::Edge::Edge(const gfx::PointF& p, const gfx::PointF& q) { DCHECK(p != q); gfx::Vector2dF tangent(p.y() - q.y(), q.x() - p.x()); float cross2 = p.x() * q.y() - q.x() * p.y(); set(tangent.x(), tangent.y(), cross2); scale(1.0f / tangent.Length()); } LayerQuad::LayerQuad(const gfx::QuadF& quad) { // Create edges. m_left = Edge(quad.p4(), quad.p1()); m_right = Edge(quad.p2(), quad.p3()); m_top = Edge(quad.p1(), quad.p2()); m_bottom = Edge(quad.p3(), quad.p4()); float sign = quad.IsCounterClockwise() ? -1 : 1; m_left.scale(sign); m_right.scale(sign); m_top.scale(sign); m_bottom.scale(sign); } LayerQuad::LayerQuad(const Edge& left, const Edge& top, const Edge& right, const Edge& bottom) : m_left(left) , m_top(top) , m_right(right) , m_bottom(bottom) { } gfx::QuadF LayerQuad::ToQuadF() const { return gfx::QuadF(m_left.intersect(m_top), m_top.intersect(m_right), m_right.intersect(m_bottom), m_bottom.intersect(m_left)); } void LayerQuad::toFloatArray(float flattened[12]) const { flattened[0] = m_left.x(); flattened[1] = m_left.y(); flattened[2] = m_left.z(); flattened[3] = m_top.x(); flattened[4] = m_top.y(); flattened[5] = m_top.z(); flattened[6] = m_right.x(); flattened[7] = m_right.y(); flattened[8] = m_right.z(); flattened[9] = m_bottom.x(); flattened[10] = m_bottom.y(); flattened[11] = m_bottom.z(); } } // namespace cc
25.492958
94
0.601105
GnorTech
039044f2605a851c5273020b1f45d670c8279b18
3,166
cpp
C++
cpp02/ex03/Fixed.cpp
ostef/42-cpp
59853e5252793e8aef9a7dfe31d2888304146e90
[ "Unlicense" ]
1
2022-02-16T18:07:02.000Z
2022-02-16T18:07:02.000Z
cpp02/ex03/Fixed.cpp
ostef/42-cpp
59853e5252793e8aef9a7dfe31d2888304146e90
[ "Unlicense" ]
null
null
null
cpp02/ex03/Fixed.cpp
ostef/42-cpp
59853e5252793e8aef9a7dfe31d2888304146e90
[ "Unlicense" ]
null
null
null
#include "Fixed.hpp" #include <iostream> #include <cmath> // | integral | fractional | // 32 ... 8 ... 0 const int Fixed::FRACT_BITS = 8; Fixed::Fixed () : m_raw (0) { std::cout << "Default constructor called... Yay..." << std::endl; } Fixed::Fixed (const int i) : m_raw (0) { std::cout << "Constructor (const int i) called... Yay..." << std::endl; m_raw = i << FRACT_BITS; } Fixed::Fixed (const float f) : m_raw (0) { std::cout << "Constructor (const float f) called... Yay..." << std::endl; m_raw = roundf (f * (1 << FRACT_BITS)); } Fixed::Fixed (const Fixed &other) : m_raw (other.m_raw) { std::cout << "Copy constructor called... Yay..." << std::endl; } Fixed::~Fixed () { std::cout << "Destructor called... Yay..." << std::endl; } Fixed &Fixed::operator = (const Fixed &other) { std::cout << "Assignment operator called... Yay..." << std::endl; m_raw = other.m_raw; return *this; } Fixed &Fixed::min (Fixed &a, Fixed &b) { if (a < b) return a; return b; } const Fixed &Fixed::min (const Fixed &a, const Fixed &b) { if (a < b) return a; return b; } Fixed &Fixed::max (Fixed &a, Fixed &b) { if (a > b) return a; return b; } const Fixed &Fixed::max (const Fixed &a, const Fixed &b) { if (a > b) return a; return b; } int Fixed::getRawBits () const { std::cout << "getRawBits member function called... Yay..." << std::endl; return m_raw; } void Fixed::setRawBits (const int raw) { std::cout << "setRawBits member function called... Yay..." << std::endl; m_raw = raw; } float Fixed::toFloat () const { return (float)m_raw / (float)(1 << FRACT_BITS); } int Fixed::toInt () const { return m_raw >> FRACT_BITS; } Fixed Fixed::operator + (const Fixed &other) const { Fixed result; result.m_raw = m_raw + other.m_raw; return result; } Fixed Fixed::operator - (const Fixed &other) const { Fixed result; result.m_raw = m_raw - other.m_raw; return result; } Fixed Fixed::operator * (const Fixed &other) const { Fixed result; result.m_raw = (m_raw * other.m_raw) / (1 << FRACT_BITS); return result; } Fixed Fixed::operator / (const Fixed &other) const { Fixed result; result.m_raw = (m_raw * (1 << FRACT_BITS)) / other.m_raw; return result; } Fixed &Fixed::operator ++ () { m_raw += 1; return *this; } Fixed Fixed::operator ++ (int) { Fixed temp = *this; m_raw += 1; return temp; } Fixed &Fixed::operator -- () { m_raw -= 1; return *this; } Fixed Fixed::operator -- (int) { Fixed temp = *this; m_raw -= 1; return temp; } bool Fixed::operator < (const Fixed &other) const { return m_raw < other.m_raw; } bool Fixed::operator <= (const Fixed &other) const { return m_raw <= other.m_raw; } bool Fixed::operator > (const Fixed &other) const { return m_raw > other.m_raw; } bool Fixed::operator >= (const Fixed &other) const { return m_raw >= other.m_raw; } bool Fixed::operator == (const Fixed &other) const { return m_raw == other.m_raw; } bool Fixed::operator != (const Fixed &other) const { return m_raw != other.m_raw; } std::ostream &operator << (std::ostream &out, const Fixed &fixed) { return out << fixed.toFloat (); }
16.575916
74
0.618446
ostef
03907e4ac617f43d27f9482051a79d447119109f
7,346
cpp
C++
src/NVProperty.cpp
RadioShuttle/NVProperty
5028d28c2addcd2a4091e37989fd0817e7d7fbe9
[ "Apache-2.0" ]
null
null
null
src/NVProperty.cpp
RadioShuttle/NVProperty
5028d28c2addcd2a4091e37989fd0817e7d7fbe9
[ "Apache-2.0" ]
null
null
null
src/NVProperty.cpp
RadioShuttle/NVProperty
5028d28c2addcd2a4091e37989fd0817e7d7fbe9
[ "Apache-2.0" ]
null
null
null
/* * Copyright (c) 2019 Helmut Tschemernjak * 30826 Garbsen (Hannover) Germany * Licensed under the Apache License, Version 2.0); */ #ifdef ARDUINO #include <Arduino.h> #elif __MBED__ #include <mbed.h> #else #error "Unkown operating system" #endif #include <NVPropertyProviderInterface.h> #include <NVProperty_SRAM.h> #ifdef ARDUINO_ARCH_ESP32 #include <NVProperty_ESP32NVS.h> #include <NVProperty_ESP32efuse.h> #elif defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_ARCH_SAMD) #include <NVProperty_D21Flash.h> #elif __MBED__ #include <mbed.h> #include <NVProperty_MBEDFlash.h> #ifdef TARGET_STM32L4 #include <NVProperty_L4OTP.h> #endif #else #error "Unkown implementation" #endif #include <NVProperty.h> NVProperty::NVProperty(int propSizekB, bool erase) { _flash = NULL; _otp = NULL; _ram = new NVProperty_SRAM(); #ifdef ARDUINO_ARCH_ESP32 _flash = new NVProperty_ESP32NVS(); #elif defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_ARCH_SAMD) _flash = new NVProperty_D21Flash(propSizekB, erase); #elif __MBED__ _flash = new NVProperty_MBEDFlash(propSizekB, erase); #else #error "unkown platform" #endif #ifdef ARDUINO_ARCH_ESP32 _otp = new NVProperty_ESP32efuse(); #elif TARGET_STM32L4 _otp = new NVProperty_L4OTP(); #endif _allowWrite = false; _didOpen = false; } NVProperty::~NVProperty() { if (_ram) { delete _ram; } if (_flash) delete _flash; if (_otp) delete _otp; } int NVProperty::GetProperty(int key, int defaultValue) { int res; if (!_didOpen) OpenPropertyStore(); if (_ram) { res = _ram->GetProperty(key); if (res != NVP_ENOENT) return res; } if (_flash) { res = _flash->GetProperty(key); if (res != NVP_ENOENT) return res; } if (_otp) { res = _otp->GetProperty(key); if (res != NVP_ENOENT) return res; } return defaultValue; } int64_t NVProperty::GetProperty64(int key, int64_t defaultValue) { int64_t res; if (!_didOpen) OpenPropertyStore(); if (_ram) { res = _ram->GetProperty64(key); if (res != NVP_ENOENT) return res; } if (_flash) { res = _flash->GetProperty64(key); if (res != NVP_ENOENT) return res; } if (_otp) { res = _otp->GetProperty64(key); if (res != NVP_ENOENT) return res; } return defaultValue; } const char * NVProperty::GetProperty(int key, const char *defaultValue) { const char *res; if (!_didOpen) OpenPropertyStore(); if (_ram) { res = _ram->GetPropertyStr(key); if (res != NULL) return res; } if (_flash) { res = _flash->GetPropertyStr(key); if (res != NULL) return res; } if (_otp) { res = _otp->GetPropertyStr(key); if (res != NULL) return res; } if (res != NULL) return res; return defaultValue; } int NVProperty::GetProperty(int key, void *buffer, int *size) { int res; int maxsize = *size; if (!_didOpen) OpenPropertyStore(); if (_ram) { res = _ram->GetPropertyBlob(key, buffer, &maxsize); if (res == NVP_OK) return res; } if (_flash) { res = _flash->GetPropertyBlob(key, buffer, &maxsize); if (res == NVP_OK) return res; } if (_otp) { res = _otp->GetPropertyBlob(key, buffer, &maxsize); if (res == NVP_OK) return res; } return NVP_ENOENT; } int NVProperty::SetProperty(int key, NVPType ptype, int64_t value, NVPStore store) { int res = NVP_OK; if (!_didOpen) OpenPropertyStore(); if (!_allowWrite) return NVP_NO_PERM; if (store == S_RAM && _ram) { res = _ram->SetProperty(key, value, ptype); } else if (store == S_FLASH && _flash) { res = _flash->SetProperty(key, value, ptype); } else if (store == S_OTP && _otp) { res = _otp->SetProperty(key, value, ptype); } else { return NVP_NO_STORE; } return res; } int NVProperty::SetProperty(int key, NVPType ptype, const char *value, NVPStore store) { int res = NVP_OK; if (!_didOpen) OpenPropertyStore(); if (!_allowWrite) return NVP_NO_PERM; if (store == S_RAM && _ram) { res = _ram->SetPropertyStr(key, value, ptype); } else if (store == S_FLASH && _flash) { res = _flash->SetPropertyStr(key, value, ptype); } else if (store == S_OTP && _otp) { res = _otp->SetPropertyStr(key, value, ptype); } else { return NVP_NO_STORE; } return res; } // NVProperty_SRAM::SetPropertyBlob(int key, const void *blob, int size, int type) int NVProperty::SetProperty(int key, NVPType ptype, const void *blob, int length, NVPStore store) { int res = NVP_OK; if (!_didOpen) OpenPropertyStore(); if (!_allowWrite) { return NVP_NO_PERM; } if (store == S_RAM && _ram) { res = _ram->SetPropertyBlob(key, blob, length, ptype); } else if (store == S_FLASH && _flash) { res = _flash->SetPropertyBlob(key, blob, length, ptype); } else if (store == S_OTP && _otp) { res = _otp->SetPropertyBlob(key, blob, length, ptype); } else { return NVP_NO_STORE; } return res; } int NVProperty::EraseProperty(int key, NVPStore store) { if (!_didOpen) OpenPropertyStore(); int res = NVP_OK; if (!_allowWrite) return NVP_NO_PERM; if (store == S_RAM && _ram) { res = _ram->EraseProperty(key); } else if (store == S_FLASH && _flash) { res = _flash->EraseProperty(key); } else if (store == S_OTP && _otp) { res = _otp->EraseProperty(key); } else { return NVP_NO_STORE; } return res; } int NVProperty::ReorgProperties(NVPStore store) { int res = NVP_OK; if (!_didOpen) OpenPropertyStore(); if (!_allowWrite) return NVP_NO_PERM; if (store == S_RAM && _ram) { res = _ram->ReorgProperties(); } else if (store == S_FLASH && _flash) { res = _flash->ReorgProperties(); } else if (store == S_OTP && _otp) { res = _otp->ReorgProperties(); } else { return NVP_NO_STORE; } return res; } int NVProperty::OpenPropertyStore(bool forWrite) { int res = NVP_OK; if (_didOpen) { if (_ram) _ram->ClosePropertyStore(); if (_flash) _flash->ClosePropertyStore(); if (_otp) _otp->ClosePropertyStore(); } if (_ram) _ram->OpenPropertyStore(forWrite); if (_flash) res = _flash->OpenPropertyStore(forWrite); if (_otp) _otp->OpenPropertyStore(forWrite); _didOpen = true; if(forWrite) _allowWrite = true; return res; } int NVProperty::ClosePropertyStore(bool flush) { int res = NVP_OK; if (_didOpen) return NVP_NO_PERM; if (_ram) _ram->ClosePropertyStore(flush); if (_flash) res = _flash->ClosePropertyStore(flush); if (_otp) _otp->ClosePropertyStore(flush); return res; }
20.751412
94
0.585216
RadioShuttle
0392611ba04118daee7bc62ab7989233c6d5535c
706
cpp
C++
Competitve Programming & Online Problems/Coding-Interview/Chapter 3 - Stacks and Queues/3.5 sort_stack.cpp
srini1392/Programming-in-Cpp
099f44d65cbe976b27625e5806b32ab88414b019
[ "MIT" ]
1
2019-01-02T21:52:49.000Z
2019-01-02T21:52:49.000Z
Competitve Programming & Online Problems/Coding-Interview/Chapter 3 - Stacks and Queues/3.5 sort_stack.cpp
srini1392/Programming-in-Cpp
099f44d65cbe976b27625e5806b32ab88414b019
[ "MIT" ]
1
2019-04-05T00:00:13.000Z
2019-04-05T00:00:13.000Z
Competitve Programming & Online Problems/Coding-Interview/Chapter 3 - Stacks and Queues/3.5 sort_stack.cpp
srini1392/Programming-in-Cpp
099f44d65cbe976b27625e5806b32ab88414b019
[ "MIT" ]
5
2019-02-18T08:42:32.000Z
2021-04-27T12:11:43.000Z
#include <bits/stdc++.h> using namespace std; template <class T> void sort_stack(vector<T> *s) { vector<T> r; while ((*s).size()) { T temp = (*s).back(); (*s).pop_back(); while (r.size() && r.back() > temp) { (*s).push_back(r.back()); r.pop_back(); } r.push_back(temp); } while (r.size()) { (*s).push_back(r.back()); r.pop_back(); } } int main() { vector<int> v; v.push_back(5); v.push_back(3); v.push_back(1); v.push_back(4); v.push_back(2); sort_stack(&v); while (v.size()) { cout << v.back() << " "; v.pop_back(); } return 0; }
18.102564
43
0.446176
srini1392
0394b50e8ed2c4dd1acc34bea63e9c815266adc5
4,997
cpp
C++
OpenSees/SRC/element/updatedLagrangianBeamColumn/Elastic2DGNL.cpp
kuanshi/ductile-fracture
ccb350564df54f5c5ec3a079100effe261b46650
[ "MIT" ]
8
2019-03-05T16:25:10.000Z
2020-04-17T14:12:03.000Z
SRC/element/updatedLagrangianBeamColumn/Elastic2DGNL.cpp
steva44/OpenSees
417c3be117992a108c6bbbcf5c9b63806b9362ab
[ "TCL" ]
null
null
null
SRC/element/updatedLagrangianBeamColumn/Elastic2DGNL.cpp
steva44/OpenSees
417c3be117992a108c6bbbcf5c9b63806b9362ab
[ "TCL" ]
3
2019-09-21T03:11:11.000Z
2020-01-19T07:29:37.000Z
/* ****************************************************************** ** ** OpenSees - Open System for Earthquake Engineering Simulation ** ** Pacific Earthquake Engineering Research Center ** ** ** ** ** ** (C) Copyright 1999, The Regents of the University of California ** ** All Rights Reserved. ** ** ** ** See file 'COPYRIGHT' in main directory for information on usage ** ** and redistribution of OpenSees, and for a DISCLAIMER OF ALL ** ** WARRANTIES. ** ** ** ** Element2dGNL.cpp: implementation of the Element2dGNL class ** ** Developed by: ** ** Rohit Kaul (rkaul@stanford.edu) ** ** Greg Deierlein (ggd@stanford.edu) ** ** ** ** John A. Blume Earthquake Engineering Center ** ** Stanford University ** ** ****************************************************************** **/ #include <Domain.h> #include <Channel.h> #include <FEM_ObjectBroker.h> #include <Renderer.h> #include <math.h> #include <stdlib.h> #include <elementAPI.h> #include "Elastic2DGNL.h" #define Ele_TAG_Elastic2dGNL -1 ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// void* OPS_Elastic2DGNL() { if (OPS_GetNumRemainingInputArgs() < 6) { opserr << "WARNING insufficient arguments\n"; opserr << "element element2dGNL int tag, int Nd1, int Nd2, double A, double E, double Iz, <int linear>\n"; return 0; } int idata[3]; int numdata = 3; if (OPS_GetIntInput(&numdata, idata) < 0) { opserr << "WARNING invalid Elastic2dGNL int inputs" << endln; return 0; } int tag = idata[0]; int ndI = idata[1]; int ndJ = idata[2]; double data[3]; numdata = 3; if (OPS_GetDoubleInput(&numdata, data) < 0) { opserr << "WARNING invalid Elastic2dGNL double inputs" << endln; return 0; } double A = data[0]; double E = data[1]; double I = data[2]; bool linear = false; if (OPS_GetNumRemainingInputArgs() > 0) { numdata = 1; if (OPS_GetIntInput(&numdata, idata) < 0) { opserr << "WARNING invalid Elastic2dGNL int inputs" << endln; return 0; } if (idata[0] == 1) linear = true; } return new Elastic2dGNL(tag, A, E, I, ndI, ndJ, linear);//, false, massDens); } // Constructor Elastic2dGNL::Elastic2dGNL(int tag, double a, double e, double i, int Nd1, int Nd2, bool islinear, double rho) :UpdatedLagrangianBeam2D(tag, Ele_TAG_Elastic2dGNL, Nd1, Nd2, islinear), A(a), E(e), Iz(i) { massDof = A*L*rho; massDof = massDof/2; } Elastic2dGNL::~Elastic2dGNL() { } void Elastic2dGNL::getLocalMass(Matrix &M) { if(massDof < 0) { opserr << "Elastic2dGNL::getMass - Distributed mass not implemented\n"; M.Zero(); } else if(massDof == 0)//this cond. is taken care of already { M.Zero(); } else { M.Zero(); M(0,0) = M(1,1) = M(2,2) = M(3,3) = M(4,4) = M(5,5) = massDof; } } void Elastic2dGNL::getLocalStiff(Matrix &K) { double EIbyL = E*Iz/L_hist; double l = L_hist; K(0, 1) = K(0, 2) = K(0, 4) = K(0, 5)=0; K(1, 0) = K(1, 3) =0; K(2, 0) = K(2, 3) =0; K(3, 1) = K(3, 2) = K(3, 4) = K(3, 5)=0; K(4, 0) = K(4, 3) =0; K(5, 0) = K(5, 3) =0; K(0,0) = K(3,3) = (A/Iz)*(EIbyL); K(0,3) = K(3,0) = (-A/Iz)*(EIbyL); K(1,1) = K(4,4) = (12/(l*l))*(EIbyL); K(1,4) = K(4,1) = (-12/(l*l))*(EIbyL); K(1,2) = K(2,1) = K(1,5) = K(5,1) = (6/l)*(EIbyL); K(2,4) = K(4,2) = K(4,5) = K(5,4) = (-6/l)*(EIbyL); K(2,2) = K(5,5) = 4*(EIbyL); K(2,5) = K(5,2) = 2*(EIbyL); }//getLocalStiff void Elastic2dGNL::Print(OPS_Stream &s, int flag) { s << "\nElement No: " << this->getTag(); s << " type: Elastic2dGNL iNode: " << connectedExternalNodes(0); s << " jNode: " << connectedExternalNodes(1); if(isLinear) s << "(1st-Order):\n"; else s << "(2nd-Order):\n"; } int Elastic2dGNL::sendSelf(int commitTag, Channel &theChannel) { opserr << "WARNING (W_C_10) - Elastic2dGNL::sendSelf(..) [" << getTag() <<"]\n"; opserr << "method not implemented\n"; return -1; } int Elastic2dGNL::recvSelf(int commitTag, Channel &theChannel, FEM_ObjectBroker &theBroker) { opserr << "WARNING (W_C_20) - Elastic2dGNL::recvSelf(..) [" << getTag() <<"]\n"; opserr << "method not implemented\n"; return -1; }
29.744048
107
0.479288
kuanshi
039522f4f213257af29a27c6a775fba3c27e0242
29,098
cpp
C++
sample/caged.cpp
jb55/libcage
7d39947a5c73bfba2e0b68513ded7a9de0d8dac6
[ "BSD-3-Clause" ]
1
2015-03-29T11:00:09.000Z
2015-03-29T11:00:09.000Z
sample/caged.cpp
jb55/libcage
7d39947a5c73bfba2e0b68513ded7a9de0d8dac6
[ "BSD-3-Clause" ]
null
null
null
sample/caged.cpp
jb55/libcage
7d39947a5c73bfba2e0b68513ded7a9de0d8dac6
[ "BSD-3-Clause" ]
null
null
null
#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/stat.h> #include <event.h> #include <libcage/cage.hpp> #include <iostream> #include <string> #include <boost/lexical_cast.hpp> #include <boost/tokenizer.hpp> #include <boost/shared_ptr.hpp> #include <boost/unordered_map.hpp> // #define DEBUG #ifdef DEBUG #define D(X) X #else #define D(X) #endif extern char *optarg; extern int optind, opterr, optopt; typedef boost::char_separator<char> char_separator; typedef boost::tokenizer<char_separator> tokenizer; typedef boost::escaped_list_separator<char> esc_separator; typedef boost::tokenizer<esc_separator> esc_tokenizer; typedef boost::unordered_map<std::string, boost::shared_ptr<libcage::cage> > name2node_type; typedef boost::unordered_map<int, boost::shared_ptr<event> > sock2ev_type; sock2ev_type sock2ev; name2node_type name2node; void usage(char *cmd); bool start_listen(int port); void callback_accept(int fd, short ev, void *arg); void callback_read(int fd, short ev, void *arg); void replace(std::string &str, std::string from, std::string to); void do_command(int sockfd, std::string command); void process_set_id(int sockfd, esc_tokenizer::iterator &it, const esc_tokenizer::iterator &end); void process_new(int sockfd, esc_tokenizer::iterator &it, const esc_tokenizer::iterator &end); void process_delete(int sockfd, esc_tokenizer::iterator &it, const esc_tokenizer::iterator &end); void process_join(int sockfd, esc_tokenizer::iterator &it, const esc_tokenizer::iterator &end); void process_put(int sockfd, esc_tokenizer::iterator &it, const esc_tokenizer::iterator &end); void process_get(int sockfd, esc_tokenizer::iterator &it, const esc_tokenizer::iterator &end); static const char * const SUCCEEDED_NEW = "200"; static const char * const SUCCEEDED_DELETE = "201"; static const char * const SUCCEEDED_JOIN = "202"; static const char * const SUCCEEDED_PUT = "203"; static const char * const SUCCEEDED_GET = "204"; static const char * const SUCCEEDED_SET_ID = "205"; static const char * const ERR_UNKNOWN_COMMAND = "400"; static const char * const ERR_INVALID_STATEMENT = "401"; static const char * const ERR_CANNOT_OPEN_PORT = "402"; static const char * const ERR_ALREADY_EXIST = "403"; static const char * const ERR_DEL_NO_SUCH_NODE = "404"; static const char * const ERR_JOIN_NO_SUCH_NODE = "405"; static const char * const ERR_JOIN_FAILED = "406"; static const char * const ERR_PUT_NO_SUCH_NODE = "407"; static const char * const ERR_GET_NO_SUCH_NODE = "408"; static const char * const ERR_GET = "409"; /* escape character: \ reserved words: words in small letters, and numbers variables: words in capital letters new,NODE_NAME,PORT_NUMBER | new,NODE_NAME,PORT_NUMBER,global -> 200,new,NODE_NAME,PORT_NUMBER | 400 | 401,COMMENT | 402 | 403,new,NODE_NAME,PORT_NUMBER,COMMENT delete,NODE_NAME -> 201,delete,NODE_NAME | 404,delete,NODE_NAME,COMMENT set_id,NODE_NAME,IDNETIFIER -> 205,set_id,NODE_NAME,IDENTIFIER | 400 | 401,COMMENT join,NODE_NAME,HOST,PORT -> 202,join,NODE_NAME,HOST,PORT 400 | 401,COMMENT 405 | 406,join,NODE_NAME,HOST,PORT,COMMENT put,NODE_NAME,KEY,VALUE,TTL | put,NODE_NAME,KEY,VALUE,TTL,unique -> 203,put,NODE_NAME,KEY,VALUE,TTL | 400 | 401,COMMENT | 407,put,NODE_NAME,KEY,VALUE,TTL,COMMENT get,NODE_NAME,key -> 204,get,NODE_NAME,KEY,VALUE1,VALUE2,VALUE3,... | 400 | 401,COMMENT | 408,get,KEY,COMMENT | 409,get,KEY */ int main(int argc, char *argv[]) { int opt; int port = 12080; bool is_daemon = false; pid_t pid; while ((opt = getopt(argc, argv, "dhp:")) != -1) { switch (opt) { case 'h': usage(argv[0]); return 0; case 'd': is_daemon = true; break; case 'p': port = atoi(optarg); break; } } if (is_daemon) { if ((pid = fork()) < 0) { return -1; } else { exit(0); } setsid(); chdir("/"); umask(0); } event_init(); if (start_listen(port) == false) { std::cerr << "can't listen port: " << port << std::endl; return -1; } event_dispatch(); return 0; } void usage(char *cmd) { printf("%s [-d] [-p port]\n", cmd); printf(" -d: run as daemon\n"); printf(" -h: show this help\n"); printf(" -p: the port number to listen, default value is 12080\n"); } bool start_listen(int port) { sockaddr_in saddr_in; event *ev = new event; int sockfd; int on = 1; if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { perror("sockfd"); return false; } if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { perror("setsockopt"); } memset(&saddr_in, 0, sizeof(saddr_in)); saddr_in.sin_port = htons(port); saddr_in.sin_family = PF_INET; saddr_in.sin_addr.s_addr = htonl(0x7f000001); if (bind(sockfd, (sockaddr*)&saddr_in, sizeof(saddr_in)) < 0) { close(sockfd); perror("bind"); return false; } if (listen(sockfd, 10) < 0) { close(sockfd); perror("listen"); return false; } event_set(ev, sockfd, EV_READ | EV_PERSIST, &callback_accept, NULL); event_add(ev, NULL); return true; } void callback_accept(int sockfd, short ev, void *arg) { if (ev == EV_READ) { sockaddr_in saddr_in; socklen_t len = sizeof(saddr_in); int fd = accept(sockfd, (sockaddr*)&saddr_in, &len); boost::shared_ptr<event> readev(new event); sock2ev[fd] = readev; event_set(readev.get(), fd, EV_READ | EV_PERSIST, &callback_read, NULL); event_add(readev.get(), NULL); } } void callback_read(int sockfd, short ev, void *arg) { ssize_t size; char buf[1024 * 4]; if (ev == EV_READ) { retry: size = recv(sockfd, buf, sizeof(buf) - 1, 0); if (size <= 0) { if (size == -1) { if (errno == EINTR) goto retry; perror("recv"); } event_del(sock2ev[sockfd].get()); sock2ev.erase(sockfd); shutdown(sockfd, SHUT_RDWR); return; } buf[size - 1] = '\0'; std::string str(buf); replace(str, "\r\n", "\n"); replace(str, "\r", "\n"); char_separator sep("\n", "", boost::drop_empty_tokens); tokenizer tokens(str, sep); for (tokenizer::iterator it = tokens.begin(); it != tokens.end(); ++it) { do_command(sockfd, *it); } } } void replace(std::string &str, std::string from, std::string to) { for (std::string::size_type pos = str.find(from); pos != std::string::npos; pos = str.find(from, from.length() + pos)) { str.replace(pos, from.length(), to); } } void do_command(int sockfd, std::string command) { esc_separator sep("\\", ",", "\""); esc_tokenizer tokens(command, sep); esc_tokenizer::iterator it = tokens.begin(); if (it == tokens.end()) return; if (*it == "new") { D(std::cout << "process new" << std::endl); process_new(sockfd, ++it, tokens.end()); } else if (*it == "delete") { D(std::cout << "process delete" << std::endl); process_delete(sockfd, ++it, tokens.end()); } else if (*it == "set_id") { D(std::cout << "process set_id" << std::endl;); process_set_id(sockfd, ++it, tokens.end()); } else if (*it == "join") { D(std::cout << "process join" << std::endl;); process_join(sockfd, ++it, tokens.end()); } else if (*it == "put") { D(std::cout << "process put" << std::endl); process_put(sockfd, ++it, tokens.end()); } else if (*it == "get") { D(std::cout << "process get" << std::endl); process_get(sockfd, ++it, tokens.end()); } else { D(std::cout << "unknown command: " << *it << std::endl); char result[1024]; // format: 400,COMMENT snprintf(result, sizeof(result), "400,unknown command. cannot recognize '%s'\n", it->c_str()); send(sockfd, result, strlen(result), 0); } } void process_set_id(int sockfd, esc_tokenizer::iterator &it, const esc_tokenizer::iterator &end) { name2node_type::iterator it_n2n; std::string node_name; std::string esc_node_name; char result[1024 * 4]; // read node_name if (it == end || it->length() == 0) { // there is no port number // format: 401,COMMENT snprintf(result, sizeof(result), "401,node name is required\n"); send(sockfd, result, strlen(result), 0); return; } node_name = *it; esc_node_name = *it; replace(esc_node_name, ",", "\\,"); it_n2n = name2node.find(node_name); if (it_n2n == name2node.end()) { // invalid node name // format: 404,delete,NODE_NAME,COMMENT snprintf(result, sizeof(result), "%s,delete,%s,no such node named '%s'\n", ERR_DEL_NO_SUCH_NODE, esc_node_name.c_str(), esc_node_name.c_str()); send(sockfd, result, strlen(result), 0); return; } ++it; // read port number if (it == end) { // there is no identifier // format: 401,COMMENT snprintf(result, sizeof(result), "401,identifier is required\n"); send(sockfd, result, strlen(result), 0); return; } it_n2n->second->set_id(it->c_str(), it->size()); // format: 205,set_id,NODE_NAME,IDENTIFIER snprintf(result, sizeof(result), "205,set_id,%s,%s\n", esc_node_name.c_str(), it->c_str()); send(sockfd, result, strlen(result), 0); } void process_new(int sockfd, esc_tokenizer::iterator &it, const esc_tokenizer::iterator &end) { std::string node_name; std::string esc_node_name; int port; char result[1024 * 4]; bool is_global = false; // read node_name if (it == end || it->length() == 0) { // there is no port number // format: 401,COMMENT snprintf(result, sizeof(result), "401,node name is required\n"); send(sockfd, result, strlen(result), 0); return; } node_name = *it; esc_node_name = *it; replace(esc_node_name, ",", "\\,"); ++it; // read port number if (it == end) { // there is no port number // format: 401,COMMENT snprintf(result, sizeof(result), "401,port number is required\n"); send(sockfd, result, strlen(result), 0); return; } try { port = boost::lexical_cast<int>(*it); } catch (boost::bad_lexical_cast) { // no integer // format: 401,COMMENT std::string esc_port = *it; replace(esc_port, ",", "\\,"); snprintf(result, sizeof(result), "401,'%s' is not a valid number\n", esc_port.c_str()); send(sockfd, result, strlen(result), 0); return; } ++it; // read option if (it != end) { if (*it == "global") is_global = true; } D(std::cout << " node_name: " << node_name << "\n port: " << port << "\n is_global: " << is_global << std::endl); // check whether the node_name has been used already or not if (name2node.find(node_name) != name2node.end()) { // the node name has been already used // format: 403,new,NODE_NAME,PORT_NUMBER,COMMENT snprintf(result, sizeof(result), "%s,new,%s,%d,the node name '%s' exists already\n", ERR_ALREADY_EXIST, esc_node_name.c_str(), port, esc_node_name.c_str()); send(sockfd, result, strlen(result), 0); return; } boost::shared_ptr<libcage::cage> c(new libcage::cage); // open port if (c->open(PF_INET, port) == false) { // cannot open port // format: 402,new,NODE_NAME,PORT_NUMBER,COMMENT snprintf(result, sizeof(result), "%s,new,%s,%d,cannot open port(%d)\n", ERR_CANNOT_OPEN_PORT, esc_node_name.c_str(), port, port); send(sockfd, result, strlen(result), 0); return; } // set as global if (is_global) { c->set_global(); } name2node[node_name] = c; // send result // format: 200,new,NODE_NAME,PORT_NUMBER snprintf(result, sizeof(result), "%s,new,%s,%d\n", SUCCEEDED_NEW, esc_node_name.c_str(), port); send(sockfd, result, strlen(result), 0); return; } void process_delete(int sockfd, esc_tokenizer::iterator &it, const esc_tokenizer::iterator &end) { name2node_type::iterator it_n2n; std::string node_name; std::string esc_node_name; char result[1024 * 4]; if (it == end) { // there is no node_name // format: 401,COMMENT snprintf(result, sizeof(result), "401,node name is required\n"); send(sockfd, result, strlen(result), 0); return; } node_name = *it; esc_node_name = *it; replace(esc_node_name, ",", "\\,"); it_n2n = name2node.find(node_name); if (it_n2n == name2node.end()) { // invalid node name // format: 404,delete,NODE_NAME,COMMENT snprintf(result, sizeof(result), "%s,delete,%s,no such node named '%s'\n", ERR_DEL_NO_SUCH_NODE, esc_node_name.c_str(), esc_node_name.c_str()); send(sockfd, result, strlen(result), 0); return; } D(std::cout << " node_name: " << node_name); name2node.erase(it_n2n); // send result // format: 201,delete,NODE_NAME snprintf(result, sizeof(result), "%s,delete,%s\n", SUCCEEDED_DELETE, esc_node_name.c_str()); send(sockfd, result, strlen(result), 0); } class func_join { public: std::string esc_node_name; std::string esc_host; int port; int sockfd; void operator() (bool is_join) { sock2ev_type::iterator it; char result[1024 * 4]; it = sock2ev.find(sockfd); if (it == sock2ev.end()) { return; } if (is_join) { // send result of the success // format: 202,join,NODE_NAME,HOST,PORT snprintf(result, sizeof(result), "%s,join,%s,%s,%d\n", SUCCEEDED_JOIN, esc_node_name.c_str(), esc_host.c_str(), port); send(sockfd, result, strlen(result), 0); } else { // send result of the fail // format: 406,join,NODE_NAME,HOST,PORT,COMMENT snprintf(result, sizeof(result), "%s,join,%s,%s,%d,failed in connecting to '%s:%d'\n", ERR_JOIN_FAILED, esc_node_name.c_str(), esc_host.c_str(), port, esc_host.c_str(), port); send(sockfd, result, strlen(result), 0); } } }; void process_join(int sockfd, esc_tokenizer::iterator &it, const esc_tokenizer::iterator &end) { std::string node_name; std::string esc_node_name; std::string host; std::string esc_host; int port; func_join func; char result[1024 * 4]; name2node_type::iterator it_n2n; if (it == end) { // there is no node_name // format: 401,COMMENT snprintf(result, sizeof(result), "401,node name is required\n"); send(sockfd, result, strlen(result), 0); return; } node_name = *it; esc_node_name = node_name; replace(esc_node_name, ",", "\\,"); ++it; if (it == end) { // there is no host // format: 401,COMMENT snprintf(result, sizeof(result), "401,host is required\n"); send(sockfd, result, strlen(result), 0); return; } host = *it; esc_host = host; replace(esc_host, ",", "\\,"); ++it; if (it == end) { // there is no port number // format: 401,COMMENT snprintf(result, sizeof(result), "401,port number is required\n"); send(sockfd, result, strlen(result), 0); return; } try { port = boost::lexical_cast<int>(*it); } catch (boost::bad_lexical_cast) { // no integer // format: 401,COMMENT std::string esc_port = *it; replace(esc_port, ",", "\\,"); snprintf(result, sizeof(result), "401,'%s' is not a valid number\n", esc_port.c_str()); send(sockfd, result, strlen(result), 0); return; } it_n2n = name2node.find(node_name); if (it_n2n == name2node.end()) { // invalid node name // format: 405,join,NODE_NAME,HOST,PORT,COMMENT snprintf(result, sizeof(result), "%s,join,%s,%s,%d,no such node named '%s'\n", ERR_JOIN_NO_SUCH_NODE, esc_node_name.c_str(), host.c_str(), port, esc_node_name.c_str()); send(sockfd, result, strlen(result), 0); return; } D(std::cout << " node_name: " << node_name << "\n host: " << host << "\n port: " << port << std::endl;) func.esc_node_name = esc_node_name; func.esc_host = esc_host; func.port = port; func.sockfd = sockfd; // join to the host:port it_n2n->second->join(host, port, func); } void process_put(int sockfd, esc_tokenizer::iterator &it, const esc_tokenizer::iterator &end) { std::string node_name; std::string esc_node_name; std::string key, value; std::string esc_key, esc_value; uint16_t ttl; bool is_unique = false; char result[1024 * 4]; if (it == end) { // there is no node_name // format: result,401,COMMENT snprintf(result, sizeof(result), "401,node name is required\n"); send(sockfd, result, strlen(result), 0); return; } node_name = *it; esc_node_name = node_name; replace(esc_node_name, ",", "\\,"); ++it; if (it == end) { // there is no key // format: 401,COMMENT snprintf(result, sizeof(result), "401,key is required\n"); send(sockfd, result, strlen(result), 0); return; } key = *it; esc_key = key; replace(esc_key, ",", "\\,"); ++it; if (it == end) { // there is no value // format: result,401,COMMENT snprintf(result, sizeof(result), "401,value is required\n"); send(sockfd, result, strlen(result), 0); return; } value = *it; esc_value = value; replace(esc_value, ",", "\\,"); ++it; if (it == end) { // there is no ttl // format: 401,COMMENT snprintf(result, sizeof(result), "401,ttl is required\n"); send(sockfd, result, strlen(result), 0); return; } try { ttl = boost::lexical_cast<uint16_t>(*it); } catch (boost::bad_lexical_cast) { // no integer // format: 401,COMMENT std::string esc_ttl = *it; replace(esc_ttl, ",", "\\,"); snprintf(result, sizeof(result), "401,'%s' is not a valid number\n", esc_ttl.c_str()); send(sockfd, result, strlen(result), 0); return; } ++it; if (it != end && *it == "unique") is_unique = true; name2node_type::iterator it_n2n; it_n2n = name2node.find(node_name); if (it_n2n == name2node.end()) { // invalid node name // format: 407,put,NODE_NAME,KEY,VALUE,TTL,COMMENT snprintf(result, sizeof(result), "%s,put,%s,%s,%s,%d,no such node named '%s'\n", ERR_PUT_NO_SUCH_NODE, esc_node_name.c_str(), esc_key.c_str(), esc_value.c_str(), ttl, esc_node_name.c_str()); send(sockfd, result, strlen(result), 0); return; } it_n2n->second->put(key.c_str(), key.length(), value.c_str(), value.length(), ttl, is_unique); D(std::cout << " node_name: " << node_name << "\n key: " << key << "\n value: " << value << "\n TTL: " << ttl << std::endl); // send result of the success if (is_unique) { // format: 203,put,NODE_NAME,KEY,VALUE,TTL,unique snprintf(result, sizeof(result), "%s,put,%s,%s,%s,%d,unique\n", SUCCEEDED_PUT, esc_node_name.c_str(), esc_key.c_str(), esc_value.c_str(), ttl); } else { // format: 203,put,NODE_NAME,KEY,VALUE,TTL snprintf(result, sizeof(result), "%s,put,%s,%s,%s,%d\n", SUCCEEDED_PUT, esc_node_name.c_str(), esc_key.c_str(), esc_value.c_str(), ttl); } send(sockfd, result, strlen(result), 0); } class func_get { public: std::string esc_node_name; std::string esc_key; int sockfd; void operator() (bool is_get, libcage::dht::value_set_ptr vset) { sock2ev_type::iterator it; char result[1024 * 1024]; it = sock2ev.find(sockfd); if (it == sock2ev.end()) { return; } if (is_get) { std::string values; libcage::dht::value_set::iterator it; for (it = vset->begin(); it != vset->end(); ++it) { boost::shared_array<char> tmp(new char[it->len + 1]); std::string value; memcpy(tmp.get(), it->value.get(), it->len); tmp[it->len] = '\0'; value = tmp.get(); replace(value, ",", "\\,"); values += ","; values += value; } // send value // format: 204,get,NODE_NAME,KEY,VALUE snprintf(result, sizeof(result), "%s,get,%s,%s%s\n", SUCCEEDED_GET, esc_node_name.c_str(), esc_key.c_str(), values.c_str()); send(sockfd, result, strlen(result), 0); return; } else { // send result of fail // format: 409,get,NODE_NAME,KEY snprintf(result, sizeof(result), "%s,get,%s,%s\n", ERR_GET, esc_node_name.c_str(), esc_key.c_str()); send(sockfd, result, strlen(result), 0); } } }; void process_get(int sockfd, esc_tokenizer::iterator &it, const esc_tokenizer::iterator &end) { std::string node_name; std::string esc_node_name; std::string key; std::string esc_key; char result[1024 * 4]; func_get func; if (it == end) { // there is no node_name // format: 401,COMMENT snprintf(result, sizeof(result), "401,node name is required\n"); send(sockfd, result, strlen(result), 0); return; } node_name = *it; esc_node_name = node_name; replace(esc_node_name, ",", "\\,"); ++it; if (it == end) { // there is no key // format: 401,COMMENT snprintf(result, sizeof(result), "401,key is required\n"); send(sockfd, result, strlen(result), 0); return; } key = *it; esc_key = key; replace(esc_key, ",", "\\,"); name2node_type::iterator it_n2n; it_n2n = name2node.find(node_name); if (it_n2n == name2node.end()) { // invalid node name // format: 408,NODE_NAME,get,KEY,COMMENT snprintf(result, sizeof(result), "%s,get,%s,%s,no such node named '%s'\n", ERR_GET_NO_SUCH_NODE, esc_node_name.c_str(), esc_key.c_str(), esc_node_name.c_str()); send(sockfd, result, strlen(result), 0); return; } D(std::cout << " node_name: " << node_name << "\n key: " << key << std::endl); func.esc_node_name = esc_node_name; func.esc_key = esc_key; func.sockfd = sockfd; it_n2n->second->get(key.c_str(), key.length(), func); }
31.697168
92
0.468177
jb55
0396df5b6a69bf857f9697957de56037943d4780
3,068
cpp
C++
LeetCode/941.cpp
jnvshubham7/CPP_Programming
a17c4a42209556495302ca305b7c3026df064041
[ "Apache-2.0" ]
1
2021-12-22T12:37:36.000Z
2021-12-22T12:37:36.000Z
LeetCode/941.cpp
jnvshubham7/CPP_Programming
a17c4a42209556495302ca305b7c3026df064041
[ "Apache-2.0" ]
null
null
null
LeetCode/941.cpp
jnvshubham7/CPP_Programming
a17c4a42209556495302ca305b7c3026df064041
[ "Apache-2.0" ]
null
null
null
class Solution { public: bool validMountainArray(vector<int>& arr) { int n=arr.size(); int count1=0; int count2=0; if(arr.size() < 3) return false; //check any any element is same in array return false for(int i = 0; i < arr.size() - 1; i++) { if(arr[i] == arr[i+1]) return false; } //find max element in array and its index int max_index = 0; int max_element = arr[0]; for(int i = 0; i < arr.size(); i++) { if(arr[i] > max_element) { max_element = arr[i]; max_index = i; } } //check before max index is increasing or not for(int i = 0; i < max_index; i++) { if(arr[i] > arr[i+1]) return false; count1++; } //check after max index is decreasing or not for(int i = max_index; i < arr.size() - 1; i++) { if(arr[i] < arr[i+1]) return false; count2++; } if(count1<1 || count2<1) return false; return true; // for(int i=0;i<max_index;i++) // { // if(arr[i]>arr[i+1]) // { // return false; // } // } // for(int i=max_index+1;i<n;i++) // { // if(arr[i]<arr[i-1]) // { // return false; // } // } //create two loop one for left to right and one for right to left // for(int i=0;i<n;i++){ // while(arr[i+1] > arr[i]){ // continue; // i++; // } // break; // int j=i; // //check arr[i] to arr[n-1] is decreasing // while(arr[j] < arr[j+1]){ // continue; // j++; // } // if(j==n-1) return true; // else return false; // } // for(int j=n-1;j>i;j--){ // } // } // check this condition arr[0] < arr[1] < ... < arr[i - 1] < arr[i] // and also this condition arr[i] > arr[i + 1] > ... > arr[arr.length - 1] // int i = 0; // while(i < arr.size() - 1 && arr[i] < arr[i+1]) // { // i++; // } // if(i == 0 || i == arr.size() - 1) return false; //check if any element is grater than both side return true // for(int i = 0; i < arr.size() - 1; i++) // { // if(arr[i] > arr[i+1]) return true; // } // for(int i = 0; i < arr.size() - 1; i++) // { // if((arr[i] > arr[i-1]) && (arr[i+1]> arr[i]) ) return true; // } //check arr[0] to arr[i] is increasing // for(int i = 0; i < arr.size() - 1; i++) // { // if(arr[i] > arr[i+1]) return false; // } //check arr[i] to arr[n-1] is decreasing // for(int i = 0; i < arr.size() - 1; i++) // { // if(arr[i] < arr[i+1]) return false; // } // return true; } };
22.558824
75
0.390156
jnvshubham7
0397526a8bc73b4e3f64ed5cd6ea08b8aef7d6eb
1,254
hpp
C++
Animator/src/Debug.hpp
Trequend/Animator
583d1d76d4e25a2840d1e122654c80f794f91d51
[ "MIT" ]
null
null
null
Animator/src/Debug.hpp
Trequend/Animator
583d1d76d4e25a2840d1e122654c80f794f91d51
[ "MIT" ]
null
null
null
Animator/src/Debug.hpp
Trequend/Animator
583d1d76d4e25a2840d1e122654c80f794f91d51
[ "MIT" ]
null
null
null
#pragma once #include <ctime> #include <cstdio> #include <vector> #include <imgui/imgui.h> #include "window/DebugWindow.hpp" #ifndef MESSAGE_BUFFER_SIZE #define MESSAGE_BUFFER_SIZE 2000 #endif // !MESSAGE_BUFFER_SIZE class Debug { friend class DebugWindow; public: enum class MessageType { Info, Warning, Error }; struct Message { char* Content; size_t ContentLength; MessageType Type; char Time[11]; Message() = default; Message(char* content, size_t size, MessageType type) : Content(content), ContentLength(size), Type(type) { std::time_t t = std::time(nullptr); std::tm tm; localtime_s(&tm, &t); std::strftime(Time, 11, "[%H:%M:%S]", &tm); } }; private: static std::vector<Message> messages; static size_t GetMessagesCount() { return messages.size(); } static const Message& GetMessage(int index) { return messages[index]; } static void Clear(); public: static void Log(const char* message, Debug::MessageType type = Debug::MessageType::Info); static void LogWarning(const char* message); static void LogError(const char* message); static void LogFormat(MessageType type, const char* fmt, ...); static void LogFormat(MessageType type, size_t bufferSize, const char* fmt, ...); };
19.292308
90
0.703349
Trequend
039b753bf1d4f56f250fb5527fd17d860af561fc
11,782
cpp
C++
src/all/frm/core/TextureAtlas.cpp
CPau/GfxSampleFramework
aa32d505d7ad6b53691daa2805a1b6c408e6c34a
[ "MIT" ]
null
null
null
src/all/frm/core/TextureAtlas.cpp
CPau/GfxSampleFramework
aa32d505d7ad6b53691daa2805a1b6c408e6c34a
[ "MIT" ]
null
null
null
src/all/frm/core/TextureAtlas.cpp
CPau/GfxSampleFramework
aa32d505d7ad6b53691daa2805a1b6c408e6c34a
[ "MIT" ]
null
null
null
#include "TextureAtlas.h" #include <frm/core/Texture.h> #include <apt/Image.h> #ifdef frm_TextureAtlas_DEBUG #include <imgui/imgui.h> static eastl::vector<frm::TextureAtlas::Region*> s_dbgRegionList; #endif using namespace frm; using namespace apt; /******************************************************************************* TextureAtlas *******************************************************************************/ struct TextureAtlas::Node { Node* m_parent; Node* m_children[4]; bool m_isEmpty; uint16 m_sizeX, m_sizeY; uint16 m_startX, m_startY; Node(Node* _parent) : m_parent(_parent) , m_isEmpty(true) { m_children[0] = 0; m_children[1] = 0; m_children[2] = 0; m_children[3] = 0; } bool isLeaf() const { return m_children[0] == 0; } bool isEmpty() const { return m_isEmpty; } }; // PUBLIC TextureAtlas* TextureAtlas::Create(GLsizei _width, GLsizei _height, GLenum _format, GLsizei _mipCount) { uint64 id = GetUniqueId(); APT_ASSERT(!Find(id)); // id collision TextureAtlas* ret = new TextureAtlas(id, "", _format, _width, _height, _mipCount); ret->setNamef("%llu", id); Use((Texture*&)ret); return ret; } void TextureAtlas::Destroy(TextureAtlas*& _inst_) { APT_ASSERT(_inst_); TextureAtlas* inst = _inst_; // make a copy because Unuse will nullify _inst_ Release((Texture*&)_inst_); if (inst->getRefCount() == 0) { APT_ASSERT(false); // \todo this is a double delete - Release() is also deleting the object delete inst; } } TextureAtlas::Region* TextureAtlas::alloc(GLsizei _width, GLsizei _height) { Node* node = insert(m_root, _width, _height); if (node) { Region* ret = m_regionPool.alloc(); ret->m_uvScale = vec2(_width, _height) * m_rsize; // note it's the requested size, not the node size ret->m_uvBias = vec2(node->m_startX, node->m_startY) * m_rsize; if (isCompressed()) { // compressed atlas, the smallest usable region is 4x4, hence the max lod is log2(w/4) ret->m_lodMax = APT_MIN((int)log2((double)(_width / 4)), (int)log2((double)(_height / 4))); } else { // uncompressed, the smallest usable region is log2(w) ret->m_lodMax = APT_MIN((int)log2((double)(_width)), (int)log2((double)(_height))); } #ifdef frm_TextureAtlas_DEBUG s_dbgRegionList.push_back(ret); #endif return ret; } return 0; } TextureAtlas::Region* TextureAtlas::alloc(const apt::Image& _img, RegionId _id) { APT_ASSERT(_img.getType() == Image::Type_2d); Region* ret = alloc((GLsizei)_img.getWidth(), (GLsizei)_img.getHeight()); GLenum srcFormat; switch (_img.getLayout()) { case Image::Layout_R: srcFormat = GL_RED; break; case Image::Layout_RG: srcFormat = GL_RG; break; case Image::Layout_RGB: srcFormat = GL_RGB; break; case Image::Layout_RGBA: srcFormat = GL_RGBA; break; default: APT_ASSERT(false); return false; }; GLenum srcType = _img.isCompressed() ? GL_UNSIGNED_BYTE : internal::DataTypeToGLenum(_img.getImageDataType()); int mipMax = APT_MIN(APT_MIN((int)getMipCount(), (int)_img.getMipmapCount()), ret->m_lodMax + 1); for (int mip = 0; mip < mipMax; ++mip) { if (_img.isCompressed()) { // \hack, see Texture.h srcType = (GLenum)_img.getRawImageSize(mip); } upload(*ret, _img.getRawImage(0, mip), srcFormat, srcType, mip); } if (_id != 0) { m_regionMap.push_back(RegionRef()); m_regionMap.back().m_id = _id; m_regionMap.back().m_region = ret; m_regionMap.back().m_refCount = 1; } return ret; } void TextureAtlas::free(Region*& _region_) { APT_ASSERT(_region_); #ifdef APT_DEBUG for (auto it = m_regionMap.begin(); it != m_regionMap.end(); ++it) { if (it->m_region == _region_) { APT_ASSERT(false); // named regions must be freed via unuseFree() } } #endif Node* node = find(*_region_); APT_ASSERT(node); remove(node); m_regionPool.free(_region_); _region_ = 0; } TextureAtlas::Region* TextureAtlas::findUse(RegionId _id) { for (auto it = m_regionMap.begin(); it != m_regionMap.end(); ++it) { if (it->m_id == _id) { ++it->m_refCount; return it->m_region; } } return 0; // not found } void TextureAtlas::unuseFree(Region*& _region_) { for (auto it = m_regionMap.begin(); it != m_regionMap.end(); ++it) { if (it->m_region == _region_) { if (--it->m_refCount == 0) { m_regionMap.erase(it); free(_region_); } _region_ = 0; // always null the ptr return; } } APT_ASSERT(false); // region not found, didn't set the region name via alloc()? } void TextureAtlas::upload(const Region& _region, const void* _data, GLenum _dataFormat, GLenum _dataType, GLint _mip) { APT_ASSERT(_mip < getMipCount()); GLsizei x = (GLsizei)(_region.m_uvBias.x * (float)getWidth()); GLsizei y = (GLsizei)(_region.m_uvBias.y * (float)getHeight()); GLsizei w = (GLsizei)(_region.m_uvScale.x * (float)getWidth()); GLsizei h = (GLsizei)(_region.m_uvScale.y * (float)getHeight()); GLsizei div = (GLsizei)pow(2.0, (double)_mip); w = w / div; h = h / div; x = x / div; y = y / div; setSubData(x, y, 0, w, h, 0, _data, _dataFormat, _dataType, _mip); } // PROTECTED TextureAtlas::TextureAtlas( uint64 _id, const char* _name, GLenum _format, GLsizei _width, GLsizei _height, GLsizei _mipCount ) : Texture(_id, _name, GL_TEXTURE_2D, _width, _height, 0, 0, _mipCount, _format) , m_regionPool(256) { m_rsize = 1.0f / vec2(getWidth(), getHeight()); // init allocator m_nodePool = new Pool<Node>(128); m_root = m_nodePool->alloc(Node(0)); m_root->m_startX = m_root->m_startY = 0; m_root->m_sizeX = getWidth(); m_root->m_sizeY = getHeight(); } TextureAtlas::~TextureAtlas() { // destroy allocator m_nodePool->free(m_root); delete m_nodePool; } // PRIVATE TextureAtlas::Node* TextureAtlas::insert(Node* _root, uint16 _sizeX, uint16 _sizeY) { if (!_root->isEmpty()) { return 0; } if (_root->isLeaf()) { // node is too small if (_root->m_sizeX < _sizeX || _root->m_sizeY < _sizeY) { return 0; } // node is best fit uint16 nextSizeX = _root->m_sizeX / 2; uint16 nextSizeY = _root->m_sizeY / 2; if (nextSizeX < _sizeX || nextSizeY < _sizeY) { _root->m_isEmpty = false; return _root; } // subdivide the node // +---+---+ // | 0 | 1 | // +---+---+ // | 3 | 2 | // +---+---+ for (int i = 0; i < 4; ++i) { _root->m_children[i] = m_nodePool->alloc(Node(_root)); _root->m_children[i]->m_sizeX = nextSizeX; _root->m_children[i]->m_sizeY = nextSizeY; } _root->m_children[0]->m_startX = _root->m_startX; _root->m_children[0]->m_startY = _root->m_startY; _root->m_children[1]->m_startX = _root->m_startX + nextSizeX; _root->m_children[1]->m_startY = _root->m_startY; _root->m_children[2]->m_startX = _root->m_startX + nextSizeX; _root->m_children[2]->m_startY = _root->m_startY + nextSizeY; _root->m_children[3]->m_startX = _root->m_startX; _root->m_children[3]->m_startY = _root->m_startY + nextSizeY; return insert(_root->m_children[0], _sizeX, _sizeY); } else { Node* ret = 0; for (int i = 0; i < 4; ++i) { ret = insert(_root->m_children[i], _sizeX, _sizeY); if (ret != 0) { break; } } return ret; } } void TextureAtlas::remove(Node*& _node_) { APT_ASSERT(_node_->isLeaf()); _node_->m_isEmpty = true; Node* parent = _node_->m_parent; // remove parent if all children are empty leaves for (int i = 0; i < 4; ++i) { bool canRemove = parent->m_children[i]->isEmpty() && parent->m_children[i]->isLeaf(); if (!canRemove) { return; } } for (int i = 0; i < 4; ++i) { m_nodePool->free(parent->m_children[i]); parent->m_children[i] = 0; } if (parent != m_root) { remove(parent); } } // \todo improve find(), search for the node corner rather than the node center TextureAtlas::Node* TextureAtlas::find(const Region& _region) { // convert region -> node center uint16 startX = (uint16)(_region.m_uvBias.x * (float)getWidth()); uint16 startY = (uint16)(_region.m_uvBias.y * (float)getHeight()); uint16 sizeX = (uint16)(_region.m_uvScale.x * (float)getWidth()); uint16 sizeY = (uint16)(_region.m_uvScale.y * (float)getHeight()); uint16 originX = startX + sizeX / 2; uint16 originY = startY + sizeY / 2; return find(m_root, originX, originY); } TextureAtlas::Node* TextureAtlas::find(Node* _root, uint16 _originX, uint16 _originY) { uint16 x0 = _root->m_startX; uint16 y0 = _root->m_startY; uint16 x1 = x0 + _root->m_sizeX; uint16 y1 = y0 + _root->m_sizeY; if (_originX >= x0 && _originX <= x1 && _originY >= y0 && _originY <= y1) { if (_root->isLeaf()) { return _root; } for (int i = 0; i < 4; ++i) { Node* ret = find(_root->m_children[i], _originX, _originY); if (ret) { return ret; } } } return 0; } #ifdef frm_TextureAtlas_DEBUG static const ImU32 kDbgColorBackground = ImColor(0.1f, 0.1f, 0.1f, 1.0f); static const ImU32 kDbgColorLines = ImColor(1.0f, 1.0f, 1.0f, 1.0f); static const float kDbgLineThickness = 1.0f; void TextureAtlas::debug() { ImDrawList* drawList = ImGui::GetWindowDrawList(); const vec2 drawSize = ImGui::GetContentRegionAvail(); const vec2 drawStart = vec2(ImGui::GetWindowPos()) + vec2(ImGui::GetCursorPos()); const vec2 drawEnd = drawStart + drawSize; drawList->AddRectFilled(drawStart, drawStart + drawSize, kDbgColorBackground); const vec2 txSize = vec2(getWidth(), getHeight()); const vec2 buttonStart = ImGui::GetCursorPos(); for (int i = 0; i < s_dbgRegionList.size(); ++i) { ImGui::PushID(i); vec2 start = s_dbgRegionList[i]->m_uvBias * drawSize; vec2 size = s_dbgRegionList[i]->m_uvScale * drawSize; ImGui::SetCursorPos(buttonStart + start); if (ImGui::Button("", size)) { free(s_dbgRegionList[i]); s_dbgRegionList.erase(s_dbgRegionList.begin() + i); } else { if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); ImGui::Text("Uv Bias: %1.2f, %1.2f", s_dbgRegionList[i]->m_uvBias.x, s_dbgRegionList[i]->m_uvBias.y); ImGui::Text("Uv Scale: %1.2f, %1.2f", s_dbgRegionList[i]->m_uvScale.x, s_dbgRegionList[i]->m_uvScale.y); ImGui::Text("Max Lod: %d", s_dbgRegionList[i]->m_lodMax); ImGui::EndTooltip(); } } ImGui::PopID(); } drawList->AddLine(vec2(drawStart.x, drawStart.y), vec2(drawEnd.x, drawStart.y), kDbgColorLines, kDbgLineThickness); drawList->AddLine(vec2(drawEnd.x, drawStart.y), vec2(drawEnd.x, drawEnd.y), kDbgColorLines, kDbgLineThickness); drawList->AddLine(vec2(drawEnd.x, drawEnd.y), vec2(drawStart.x, drawEnd.y), kDbgColorLines, kDbgLineThickness); drawList->AddLine(vec2(drawStart.x, drawEnd.y), vec2(drawStart.x, drawStart.y), kDbgColorLines, kDbgLineThickness); debugDrawNode(m_root, drawStart, drawSize); } void TextureAtlas::debugDrawNode(const Node* _node, const vec2& _drawStart, const vec2& _drawSize) { if (!_node->isLeaf()) { ImDrawList* drawList = ImGui::GetWindowDrawList(); vec2 a, b; a = vec2((float)(_node->m_startX + _node->m_sizeX / 2), (float)(_node->m_startY )) * m_rsize; b = vec2((float)(_node->m_startX + _node->m_sizeX / 2), (float)(_node->m_startY + _node->m_sizeY)) * m_rsize; drawList->AddLine(_drawStart + a * _drawSize, _drawStart + b * _drawSize, kDbgColorLines, kDbgLineThickness); a = vec2((float)(_node->m_startX ), (float)(_node->m_startY + _node->m_sizeY / 2)) * m_rsize; b = vec2((float)(_node->m_startX + _node->m_sizeX), (float)(_node->m_startY + _node->m_sizeY / 2)) * m_rsize; drawList->AddLine(_drawStart + a * _drawSize, _drawStart + b * _drawSize, kDbgColorLines, kDbgLineThickness); for (int i = 0; i < 4; ++i) { debugDrawNode(_node->m_children[i], _drawStart, _drawSize); } } } #endif // frm_TextureAtlas_DEBUG
29.827848
119
0.652775
CPau
039ddd9c06d91ad456c52f2731f6fe4ddb61526c
765
cpp
C++
tests/lexy/input/base.cpp
netcan/lexy
775e3d6bf1169ce13b08598d774e707c253f0792
[ "BSL-1.0" ]
null
null
null
tests/lexy/input/base.cpp
netcan/lexy
775e3d6bf1169ce13b08598d774e707c253f0792
[ "BSL-1.0" ]
null
null
null
tests/lexy/input/base.cpp
netcan/lexy
775e3d6bf1169ce13b08598d774e707c253f0792
[ "BSL-1.0" ]
null
null
null
// Copyright (C) 2020 Jonathan Müller <jonathanmueller.dev@gmail.com> // This file is subject to the license terms in the LICENSE file // found in the top-level directory of this distribution. #include <lexy/input/base.hpp> #include <doctest/doctest.h> #include <lexy/input/string_input.hpp> TEST_CASE("partial_reader()") { auto input = lexy::zstring_input("abc"); auto end = input.end() - 1; auto partial = lexy::partial_reader(input.reader(), end); CHECK(partial.cur() == input.begin()); CHECK(partial.peek() == 'a'); CHECK(!partial.eof()); partial.bump(); CHECK(partial.peek() == 'b'); CHECK(!partial.eof()); partial.bump(); CHECK(partial.peek() == lexy::default_encoding::eof()); CHECK(partial.eof()); }
26.37931
69
0.654902
netcan
03a26d793d446d7efba14b9a7df18e1e3221ec17
1,060
cpp
C++
example-8/src/ClientWin.cpp
GGolbik/basics-cpp
37466e7fa03b428093055a269e2ee96b8e685b82
[ "MIT" ]
null
null
null
example-8/src/ClientWin.cpp
GGolbik/basics-cpp
37466e7fa03b428093055a269e2ee96b8e685b82
[ "MIT" ]
null
null
null
example-8/src/ClientWin.cpp
GGolbik/basics-cpp
37466e7fa03b428093055a269e2ee96b8e685b82
[ "MIT" ]
null
null
null
#ifdef _WIN32 // _WIN32 marco is defined for both 32-bit and 64-bit environments // windows code goes here #include <iostream> #include "Client.h" namespace ggolbik { namespace cpp { namespace tls { Client::Client(std::string serverAddress, unsigned short port) : serverAddress{serverAddress}, port{port} {} Client::~Client() { this->close(); } bool Client::open() { std::cerr << "NOT IMPLEMENTED" << std::endl; return false; } void Client::close() {} bool Client::closeSocket() { return false; } /** * ssize_t write(int fd, const void *buf, size_t count); */ bool Client::write(const byte data[], size_t length) { return false; } bool Client::readString(std::string &message) { return false; } int Client::tryReadString(std::string &message) { return -1; } int Client::tryReadStringTls(std::string &message) { return -1; } bool Client::readStringTls(std::string &message) { return false; } bool Client::writeTls(const byte data[], size_t length) { return false; } } // namespace tls } // namespace cpp } // namespace ggolbik #endif
23.555556
73
0.695283
GGolbik
03a354546d987610a72062ef6ae9f7cfb7c5a721
5,742
cpp
C++
applications/DEMApplication/custom_constitutive/DEM_continuum_constitutive_law.cpp
clazaro/Kratos
b947b82c90dfcbf13d60511427f85990d36b90be
[ "BSD-4-Clause" ]
2
2020-12-22T11:50:11.000Z
2021-09-15T11:36:30.000Z
applications/DEMApplication/custom_constitutive/DEM_continuum_constitutive_law.cpp
clazaro/Kratos
b947b82c90dfcbf13d60511427f85990d36b90be
[ "BSD-4-Clause" ]
3
2021-08-18T16:12:20.000Z
2021-09-02T07:36:15.000Z
applications/DEMApplication/custom_constitutive/DEM_continuum_constitutive_law.cpp
clazaro/Kratos
b947b82c90dfcbf13d60511427f85990d36b90be
[ "BSD-4-Clause" ]
1
2020-12-28T15:39:39.000Z
2020-12-28T15:39:39.000Z
#include "DEM_continuum_constitutive_law.h" #include "custom_elements/spheric_continuum_particle.h" namespace Kratos { DEMContinuumConstitutiveLaw::DEMContinuumConstitutiveLaw() {} DEMContinuumConstitutiveLaw::DEMContinuumConstitutiveLaw(const DEMContinuumConstitutiveLaw &rReferenceContinuumConstitutiveLaw) {} DEMContinuumConstitutiveLaw::~DEMContinuumConstitutiveLaw() {} std::string DEMContinuumConstitutiveLaw::GetTypeOfLaw() { KRATOS_ERROR << "This function (DEMContinuumConstitutiveLaw::GetTypeOfLaw) shouldn't be accessed, use derived class instead"<<std::endl; std::string type_of_law = ""; return type_of_law; } void DEMContinuumConstitutiveLaw::Initialize(SphericContinuumParticle* element1, SphericContinuumParticle* element2, Properties::Pointer pProps) { mpProperties = pProps; } void DEMContinuumConstitutiveLaw::SetConstitutiveLawInProperties(Properties::Pointer pProp, bool verbose) { if (verbose) KRATOS_INFO("DEM") << "Assigning " << pProp->GetValue(DEM_CONTINUUM_CONSTITUTIVE_LAW_NAME) << " to Properties " << pProp->Id() << std::endl; pProp->SetValue(DEM_CONTINUUM_CONSTITUTIVE_LAW_POINTER, this->Clone()); this->Check(pProp); } void DEMContinuumConstitutiveLaw::SetConstitutiveLawInPropertiesWithParameters(Properties::Pointer pProp, const Parameters& parameters, bool verbose) { if(verbose) KRATOS_INFO("DEM") << "Assigning " << pProp->GetValue(DEM_CONTINUUM_CONSTITUTIVE_LAW_NAME) << " to Properties " << pProp->Id() << std::endl; pProp->SetValue(DEM_CONTINUUM_CONSTITUTIVE_LAW_POINTER, this->Clone()); TransferParametersToProperties(parameters, pProp); this->Check(pProp); } void DEMContinuumConstitutiveLaw::TransferParametersToProperties(const Parameters& parameters, Properties::Pointer pProp) { } void DEMContinuumConstitutiveLaw::Check(Properties::Pointer pProp) const { KRATOS_ERROR << "This function (DEMContinuumConstitutiveLaw::Check) shouldn't be accessed, use derived class instead"<<std::endl; } DEMContinuumConstitutiveLaw::Pointer DEMContinuumConstitutiveLaw::Clone() const { DEMContinuumConstitutiveLaw::Pointer p_clone(new DEMContinuumConstitutiveLaw(*this)); return p_clone; } void DEMContinuumConstitutiveLaw::CalculateViscoDamping(double LocalRelVel[3], double ViscoDampingLocalContactForce[3], double indentation, double equiv_visco_damp_coeff_normal, double equiv_visco_damp_coeff_tangential, bool& sliding, int failure_id) { KRATOS_ERROR << "This function (DEMContinuumConstitutiveLaw::CalculateViscoDamping) shouldn't be accessed, use derived class instead"<<std::endl; } void DEMContinuumConstitutiveLaw::ComputeParticleRotationalMoments(SphericContinuumParticle* element, SphericContinuumParticle* neighbor, double equiv_young, double distance, double calculation_area, double LocalCoordSystem[3][3], double ElasticLocalRotationalMoment[3], double ViscoLocalRotationalMoment[3], double equiv_poisson, double indentation) { KRATOS_ERROR << "This function (DEMContinuumConstitutiveLaw::ComputeParticleRotationalMoments) shouldn't be accessed, use derived class instead"<<std::endl; } void DEMContinuumConstitutiveLaw::AddPoissonContribution(const double equiv_poisson, double LocalCoordSystem[3][3], double& normal_force, double calculation_area, BoundedMatrix<double, 3, 3>* mSymmStressTensor, SphericContinuumParticle* element1, SphericContinuumParticle* element2, const ProcessInfo& r_process_info, const int i_neighbor_count, const double indentation) { } double DEMContinuumConstitutiveLaw::LocalMaxSearchDistance(const int i, SphericContinuumParticle* element1, SphericContinuumParticle* element2) { KRATOS_ERROR << "This function (DEMContinuumConstitutiveLaw::LocalMaxSearchDistance) shouldn't be accessed, use derived class instead"<<std::endl; } bool DEMContinuumConstitutiveLaw::CheckRequirementsOfStressTensor() { return false; } } //kratos
59.8125
164
0.550157
clazaro
03a42e9142ad8381137aab0a63659e963d46d1b6
6,323
cpp
C++
groups/bbl/bblscm/bblscm_versiontag.t.cpp
Nexuscompute/bde
d717c1cb780a46afe9373f522ba0e6ef9bab6220
[ "Apache-2.0" ]
null
null
null
groups/bbl/bblscm/bblscm_versiontag.t.cpp
Nexuscompute/bde
d717c1cb780a46afe9373f522ba0e6ef9bab6220
[ "Apache-2.0" ]
null
null
null
groups/bbl/bblscm/bblscm_versiontag.t.cpp
Nexuscompute/bde
d717c1cb780a46afe9373f522ba0e6ef9bab6220
[ "Apache-2.0" ]
null
null
null
// bblscm_versiontag.t.cpp -*-C++-*- #include <bblscm_versiontag.h> #include <bsls_bsltestutil.h> #include <bsl_cstdlib.h> // atoi() #include <bsl_cstring.h> #include <bsl_cstdio.h> using namespace BloombergLP; static bool verbose = false; static bool veryVerbose = false; // ============================================================================ // STANDARD BSL ASSERT TEST FUNCTION // ---------------------------------------------------------------------------- namespace { int testStatus = 0; void aSsErT(bool condition, const char *message, int line) { if (condition) { printf("Error " __FILE__ "(%d): %s (failed)\n", line, message); if (0 <= testStatus && testStatus <= 100) { ++testStatus; } } } } // close unnamed namespace // ============================================================================ // STANDARD BSL TEST DRIVER MACRO ABBREVIATIONS // ---------------------------------------------------------------------------- #define ASSERT BSLS_BSLTESTUTIL_ASSERT #define ASSERTV BSLS_BSLTESTUTIL_ASSERTV #define LOOP_ASSERT BSLS_BSLTESTUTIL_LOOP_ASSERT #define LOOP0_ASSERT BSLS_BSLTESTUTIL_LOOP0_ASSERT #define LOOP1_ASSERT BSLS_BSLTESTUTIL_LOOP1_ASSERT #define LOOP2_ASSERT BSLS_BSLTESTUTIL_LOOP2_ASSERT #define LOOP3_ASSERT BSLS_BSLTESTUTIL_LOOP3_ASSERT #define LOOP4_ASSERT BSLS_BSLTESTUTIL_LOOP4_ASSERT #define LOOP5_ASSERT BSLS_BSLTESTUTIL_LOOP5_ASSERT #define LOOP6_ASSERT BSLS_BSLTESTUTIL_LOOP6_ASSERT #define Q BSLS_BSLTESTUTIL_Q // Quote identifier literally. #define P BSLS_BSLTESTUTIL_P // Print identifier and value. #define P_ BSLS_BSLTESTUTIL_P_ // P(X) without '\n'. #define T_ BSLS_BSLTESTUTIL_T_ // Print a tab (w/o newline). #define L_ BSLS_BSLTESTUTIL_L_ // current Line number //============================================================================= // USAGE EXAMPLE HELPER FUNCTIONS //----------------------------------------------------------------------------- int newFunction() // Return 1 { return 1; } // int OldFunction() // Not defined and never called due to conditional compilation //============================================================================= // MAIN PROGRAM //----------------------------------------------------------------------------- int main(int argc, char *argv[]) { int test = argc > 1 ? bsl::atoi(argv[1]) : 0; verbose = (argc > 2); veryVerbose = (argc > 3); bsl::printf("TEST %s CASE %d\n", __FILE__, test); switch (test) { case 0: case 2: { //-------------------------------------------------------------------- // TEST USAGE EXAMPLE // // Concern: // That the usage example in the user documentation compiles and // runs as expected. // // Plan: // Use the exact text of the usage example from the user // documentation, but change uses of 'assert' to 'ASSERT'. // // Testing: // USAGE EXAMPLE //-------------------------------------------------------------------- if (verbose) bsl::printf("\nTEST USAGE EXAMPLE" "\n==================\n"); // At compile time, the version of BBL can be used to select an older or newer // way to accomplish a task, to enable new functionality, or to accommodate an // interface change. For example, if a function changed names (a rare // occurrence, but disruptive when it does happen), disruption can be minimized // by conditionally calling the old or new function name using conditional // compilation. The '#if' directive compares 'BBL_VERSION' to a specified // major, minor, and patch version 4 composed using 'BSL_MAKE_VERSION': //.. #if BBL_VERSION > BSL_MAKE_VERSION(1, 2) // Call 'newFunction' for BBL version 1.2 and later: int result = newFunction(); #else // Call 'oldFunction' for BBL older than version 1.2: int result = oldFunction(); #endif ASSERT(result); //.. } break; case 1: { //-------------------------------------------------------------------- // TEST VERSION CONSISTENCY // // Concerns: // That BBL_VERSION corresponds to the two components // BBL_VERSION_MAJOR and BBL_VERSION_MINOR // // Plan: // Decompose BBL_VERSION into its three components and verify // that they correspond to the defined macros. // // Testing: // BBL_VERSION // BBL_VERSION_MAJOR // BBL_VERSION_MINOR //-------------------------------------------------------------------- if (verbose) bsl::printf("\nTEST VERSION CONSISTENCY" "\n========================\n"); int major = BSL_GET_VERSION_MAJOR(BBL_VERSION); int minor = BSL_GET_VERSION_MINOR(BBL_VERSION); ASSERTV(BBL_VERSION_MAJOR, major, BBL_VERSION_MAJOR == major); ASSERTV(BBL_VERSION_MINOR, minor, BBL_VERSION_MINOR == minor); } break; default: { bsl::fprintf(stderr, "WARNING: CASE `%d' NOT FOUND.\n", test); testStatus = -1; } } if (testStatus > 0) { bsl::fprintf(stderr, "Error, non-zero test status = %d.\n", testStatus); } return testStatus; } // ---------------------------------------------------------------------------- // Copyright 2015 Bloomberg Finance L.P. // // 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. // ----------------------------- END-OF-FILE ----------------------------------
34.933702
79
0.517792
Nexuscompute
03a61165250c861cd34edb1cd981042de23e67c8
4,579
cpp
C++
Source/UnrealEnginePython/Private/Slate/UEPySGraphPanel.cpp
recogni/UnrealEnginePython
57310d0881a408d9392188aa8f6aeb4443e17c96
[ "MIT" ]
null
null
null
Source/UnrealEnginePython/Private/Slate/UEPySGraphPanel.cpp
recogni/UnrealEnginePython
57310d0881a408d9392188aa8f6aeb4443e17c96
[ "MIT" ]
null
null
null
Source/UnrealEnginePython/Private/Slate/UEPySGraphPanel.cpp
recogni/UnrealEnginePython
57310d0881a408d9392188aa8f6aeb4443e17c96
[ "MIT" ]
null
null
null
#include "UnrealEnginePythonPrivatePCH.h" #if WITH_EDITOR #if ENGINE_MINOR_VERSION > 15 #include "UEPySGraphPanel.h" #define sw_graph_panel StaticCastSharedRef<SGraphPanel>(self->s_nodePanel.s_panel.s_widget) /* static PyObject *py_ue_sgraph_panel_add_slot(ue_PySGraphPanel* self, PyObject *args, PyObject *kwargs) { PyObject *py_content; int z_order = -1; int h_align = 0; PyObject *padding = nullptr; int v_align = 0; char *kwlist[] = { (char *)"widget", (char *)"z_order", (char *)"h_align", (char *)"padding", (char *)"v_align", nullptr }; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iiOi:add_slot", kwlist, &py_content, &z_order, &h_align, &padding, &v_align)) { return nullptr; } ue_PySWidget *py_swidget = py_ue_is_swidget(py_content); if (!py_swidget) { return PyErr_Format(PyExc_Exception, "argument is not a SWidget"); } Py_INCREF(py_swidget); self->s_nodePanel.s_panel.s_widget.py_swidget_slots.Add(py_swidget); sw_graph_panel; SOverlay::FOverlaySlot &fslot = sw_graph_panel->//sw_overlay->AddSlot(z_order); fslot.AttachWidget(py_swidget->s_widget->AsShared()); fslot.HAlign((EHorizontalAlignment)h_align); if (padding) { if (PyTuple_Check(padding)) { FMargin margin; if (!PyArg_ParseTuple(padding, "f|fff", &margin.Left, &margin.Top, &margin.Right, &margin.Bottom)) { return PyErr_Format(PyExc_Exception, "invalid padding value"); } fslot.Padding(margin); } else if (PyNumber_Check(padding)) { PyObject *py_float = PyNumber_Float(padding); fslot.Padding(PyFloat_AsDouble(py_float)); Py_DECREF(py_float); } else { return PyErr_Format(PyExc_Exception, "invalid padding value"); } } fslot.VAlign((EVerticalAlignment)v_align); Py_INCREF(self); return (PyObject *)self; } */ static PyMethodDef ue_PySGraphPanel_methods[] = { //{"add_slot", (PyCFunction)py_ue_sgraph_panel_add_slot, METH_VARARGS | METH_KEYWORDS, "" }, { NULL } /* Sentinel */ }; PyTypeObject ue_PySGraphPanelType = { PyVarObject_HEAD_INIT(NULL, 0) "unreal_engine.SGraphPanel", /* tp_name */ sizeof(ue_PySGraphPanel), /* tp_basicsize */ 0, /* tp_itemsize */ 0, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ "Unreal Engine SGraphPanel", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ ue_PySGraphPanel_methods, /* tp_methods */ }; //why do you need to return an integer? static int ue_py_sgraph_panel_init(ue_PySGraphPanel *self, PyObject *args, PyObject *kwargs) { //so for right now, let's just have this commented out to see if we get any errors //if says we don't have s_nodePanel ue_py_snew_simple(SGraphPanel, s_nodePanel.s_panel.s_widget);//s_nodePanel.s_panel); //ue_py_snew(SGraphPanel, s_nodePanel.s_panel.s_widget); return 0; } void ue_python_init_sgraph_panel(PyObject *ue_module) { //ue_PySGraphPanelType.tp_init = (initproc)ue_py_sgraph_panel_init; //ue_PySGraphPanelType.tp_call = (ternaryfunc)py_ue_sgraph_panel_add_slot; ue_PySGraphPanelType.tp_base = &ue_PySNodePanelType; if (PyType_Ready(&ue_PySGraphPanelType) < 0) return; Py_INCREF(&ue_PySGraphPanelType); PyModule_AddObject(ue_module, "SGraphPanel", (PyObject *)&ue_PySGraphPanelType); } #endif #endif
32.942446
110
0.56366
recogni
03a64b7c25c08d22ff6ef2a03d9014ce1515f1fe
700
hpp
C++
link.hpp
helm100/2d-cdt
e79044451f0f84c1b0ff5c3290a61b5f24df45c0
[ "MIT" ]
3
2021-01-11T14:28:27.000Z
2022-02-08T14:19:30.000Z
link.hpp
helm100/2d-cdt
e79044451f0f84c1b0ff5c3290a61b5f24df45c0
[ "MIT" ]
1
2021-02-26T12:40:53.000Z
2021-02-26T12:40:53.000Z
link.hpp
helm100/2d-cdt
e79044451f0f84c1b0ff5c3290a61b5f24df45c0
[ "MIT" ]
1
2021-03-02T16:03:14.000Z
2021-03-02T16:03:14.000Z
// Copyright 2020 Joren Brunekreef and Andrzej Görlich #ifndef LINK_HPP_ #define LINK_HPP_ #include "pool.hpp" class Vertex; class Triangle; class Link : public Pool<Link> { public: static const unsigned pool_size = 10000000; Pool<Vertex>::Label getVertexFinal(); Pool<Vertex>::Label getVertexInitial(); Pool<Triangle>::Label getTrianglePlus(); Pool<Triangle>::Label getTriangleMinus(); void setVertices(Pool<Vertex>::Label vi, Pool<Vertex>::Label vf); void setTriangles(Pool<Triangle>::Label tp, Pool<Triangle>::Label tm); bool isTimelike(); bool isSpacelike(); private: Pool<Vertex>::Label vi, vf; // vertices Pool<Triangle>::Label tp, tm; // triangles }; #endif // LINK_HPP_
22.580645
71
0.732857
helm100
03a7a16d727583b5c47cc642f4e617a104217942
1,141
cpp
C++
examples/Primitives/src/main.cpp
jamjarlabs/JamJarNative
ed8aea9cbd3f1eed3eb49c7da0df50eea87e880e
[ "MIT" ]
1
2022-03-28T02:26:23.000Z
2022-03-28T02:26:23.000Z
examples/Primitives/src/main.cpp
jamjarlabs/JamJarNative
ed8aea9cbd3f1eed3eb49c7da0df50eea87e880e
[ "MIT" ]
103
2020-02-24T23:52:58.000Z
2021-04-18T21:00:50.000Z
examples/Primitives/src/main.cpp
jamjarlabs/JamJarNative
ed8aea9cbd3f1eed3eb49c7da0df50eea87e880e
[ "MIT" ]
1
2021-05-20T22:29:44.000Z
2021-05-20T22:29:44.000Z
#include "emscripten/html5.h" #include "entity/entity_manager.hpp" #include "game.hpp" #include "message/message_bus.hpp" #include "message/message_payload.hpp" #include "primitives.hpp" #include "standard/2d/interpolation/interpolation_system.hpp" #include "standard/2d/primitive/primitive_system.hpp" #include "standard/2d/webgl2/webgl2_system.hpp" #include "standard/file_texture/file_texture_system.hpp" #include "standard/sdl2_input/sdl2_input_system.hpp" #include "window.hpp" #include <SDL2/SDL.h> #include <iostream> #include <memory> #include <stdlib.h> #include <string> int main(int argc, char *argv[]) { auto window = JamJar::GetWindow("Primitives"); auto context = JamJar::GetCanvasContext(); auto messageBus = new JamJar::MessageBus(); new JamJar::EntityManager(messageBus); auto game = new Primitives(messageBus); new JamJar::Standard::_2D::WebGL2System(messageBus, window, context); new JamJar::Standard::_2D::InterpolationSystem(messageBus); new JamJar::Standard::_2D::PrimitiveSystem(messageBus); new JamJar::Standard::SDL2InputSystem(messageBus); game->Start(); return 0; }
32.6
73
0.751096
jamjarlabs
03a8672bbce093bf438e43aaf4102e41ec18d631
16,114
cc
C++
lib/seldon/test/unit/eigenvalue_feast.cc
HongyuHe/lsolver
c791bf192308ba6b564cb60cb3991d2e72093cd7
[ "Apache-2.0" ]
7
2021-01-31T23:20:07.000Z
2021-09-09T20:54:15.000Z
lib/seldon/test/unit/eigenvalue_feast.cc
HongyuHe/lsolver
c791bf192308ba6b564cb60cb3991d2e72093cd7
[ "Apache-2.0" ]
1
2021-06-07T07:52:38.000Z
2021-08-13T20:40:55.000Z
lib/seldon/test/unit/eigenvalue_feast.cc
HongyuHe/lsolver
c791bf192308ba6b564cb60cb3991d2e72093cd7
[ "Apache-2.0" ]
null
null
null
#include "SeldonLib.hxx" using namespace Seldon; double threshold = 1e-10; /************************ * Checking eigenvalues * ************************/ // checking symmetric standard eigenproblems template<class MatrixS, class Vector1, class Matrix1> void CheckEigenvalues(const MatrixS& mat_stiff, const Vector1& lambda, const Matrix1& eigen_vec) { int N = mat_stiff.GetM(); typedef typename Matrix1::entry_type T1; Vector<T1> X(N), Y(N); X.Fill(0); Y.Fill(0); for (int i = 0; i < lambda.GetM(); i++) { for (int j = 0; j < N; j++) X(j) = eigen_vec(j, i); Mlt(mat_stiff, X, Y); double err = 0; double normeX = sqrt(abs(DotProdConj(X, X))); for (int j = 0; j < N; j++) err += pow(abs(Y(j) - lambda(i)*X(j)), 2.0); err = sqrt(err); if (err > threshold*normeX) { cout << "Error on eigenvalue " << lambda(i) << endl; cout << "Error = " << err/normeX << endl; abort(); } } } // checking unsymmetric standard eigenproblems template<class Prop, class Storage, class Matrix1> void CheckEigenvalues(const Matrix<double, Prop, Storage>& mat_stiff, const Vector<double>& lambda, const Vector<double>& lambda_imag, const Matrix1& eigen_vec) { int N = mat_stiff.GetM(); Vector<double> X(N), Xi(N), Y(N), Yi(N); X.Fill(0); Xi.Fill(0); Y.Fill(0); Yi.Fill(0); int i = 0; while (i < lambda.GetM()) { bool eigen_pair = false; if (i < lambda.GetM()-1) { if ( (lambda(i) == lambda(i+1)) && (lambda_imag(i) == -lambda_imag(i+1))) eigen_pair = true; } if ((lambda_imag(i) != 0) && (!eigen_pair)) { DISP(i); DISP(lambda.GetM()); cout << "Eigenpair at the end of the list" << endl; break; } double err = 0, normeX(1); if (eigen_pair) { for (int j = 0; j < N; j++) { X(j) = eigen_vec(j, i); Xi(j) = eigen_vec(j, i+1); } Mlt(mat_stiff, X, Y); Mlt(mat_stiff, Xi, Yi); normeX = sqrt(DotProd(Xi, Xi) + DotProd(X, X)); for (int j = 0; j < N; j++) err += pow(abs(complex<double>(Y(j), Yi(j)) - complex<double>(lambda(i), lambda_imag(i)) *complex<double>(X(j), Xi(j)) ), 2.0); err = sqrt(err); } else { for (int j = 0; j < N; j++) X(j) = eigen_vec(j, i); Mlt(mat_stiff, X, Y); normeX = sqrt(DotProd(X, X)); for (int j = 0; j < N; j++) err += pow(Y(j) - lambda(i)*X(j), 2.0); err = sqrt(err); } if (err > threshold*normeX) { cout << "Error on eigenvalue " << lambda(i) << endl; cout << "Error = " << err/normeX << endl; abort(); } if (eigen_pair) i += 2; else i++; } } template<class MatrixS, class Matrix1> void CheckEigenvalues(const MatrixS& mat_stiff, const Vector<complex<double> >& lambda, const Vector<complex<double> >& lambda_imag, const Matrix1& eigen_vec) { CheckEigenvalues(mat_stiff, lambda, eigen_vec); } // checking unsymmetric generalized eigenproblems template<class Prop0, class Storage0, class Prop1, class Storage1, class Matrix1> void CheckEigenvalues(const Matrix<double, Prop0, Storage0>& mat_stiff, const Matrix<double, Prop1, Storage1>& mat_mass, const Vector<double>& lambda, const Vector<double>& lambda_imag, const Matrix1& eigen_vec) { int N = mat_stiff.GetM(); Vector<double> X(N), Xi(N), Y(N), Yi(N), Mx(N), Mxi(N); X.Fill(0); Xi.Fill(0); Mx.Fill(0); Mxi.Fill(0); Y.Fill(0); Yi.Fill(0); int i = 0; while (i < lambda.GetM()) { bool eigen_pair = false; if (i < lambda.GetM()-1) { if ( (lambda(i) == lambda(i+1)) && (lambda_imag(i) == -lambda_imag(i+1))) eigen_pair = true; } if ((lambda_imag(i) != 0) && (!eigen_pair)) { DISP(i); DISP(lambda.GetM()); cout << "Eigenpair at the end of the list" << endl; break; } double err = 0, normeX(1); if (eigen_pair) { for (int j = 0; j < N; j++) { X(j) = eigen_vec(j, i); Xi(j) = eigen_vec(j, i+1); } Mlt(mat_stiff, X, Y); Mlt(mat_stiff, Xi, Yi); Mlt(mat_mass, X, Mx); Mlt(mat_mass, Xi, Mxi); normeX = sqrt(DotProd(Xi, Xi) + DotProd(X, X)); for (int j = 0; j < N; j++) err += pow(abs(complex<double>(Y(j), Yi(j)) - complex<double>(lambda(i), lambda_imag(i)) *complex<double>(Mx(j), Mxi(j)) ), 2.0); err = sqrt(err); } else { for (int j = 0; j < N; j++) X(j) = eigen_vec(j, i); Mlt(mat_stiff, X, Y); Mlt(mat_mass, X, Mx); normeX = sqrt(DotProd(X, X)); for (int j = 0; j < N; j++) err += pow(Y(j) - lambda(i)*Mx(j), 2.0); err = sqrt(err); } if (err > threshold*normeX) { cout << "Error on eigenvalue " << lambda(i) << endl; cout << "Error = " << err/normeX << endl; abort(); } if (eigen_pair) i += 2; else i++; } } // checking complex generalized eigenproblems template<class MatrixS, class MatrixM, class Vector1, class Matrix1> void CheckEigenvalues(const MatrixS& mat_stiff, const MatrixM& mat_mass, const Vector1& lambda, const Matrix1& eigen_vec) { int N = mat_stiff.GetM(); typedef typename Matrix1::entry_type T1; Vector<T1> X(N), Y(N), Mx(N); X.Fill(0); Y.Fill(0); Mx.Fill(0); for (int i = 0; i < lambda.GetM(); i++) { for (int j = 0; j < N; j++) X(j) = eigen_vec(j, i); Mlt(mat_stiff, X, Y); Mlt(mat_mass, X, Mx); double normeX = sqrt(abs(DotProdConj(X, X))); double err = 0; for (int j = 0; j < N; j++) err += pow(abs(Y(j) - lambda(i)*Mx(j)), 2.0); err = sqrt(err); if (err > threshold*normeX) { cout << "Error on eigenvalue " << lambda(i) << endl; cout << "Error = " << err/normeX << endl; abort(); } } } template<class MatrixS, class MatrixM, class Matrix1> void CheckEigenvalues(const MatrixS& mat_stiff, const MatrixM& mat_mass, const Vector<complex<double> >& lambda, const Vector<complex<double> >& lambda_imag, const Matrix1& eigen_vec) { CheckEigenvalues(mat_stiff, mat_mass, lambda, eigen_vec); } template<class T> void GetRandNumber(T& x) { x = T(rand())/RAND_MAX; } template<class T> void GetRandNumber(complex<T>& x) { int type = rand()%3; if (type == 0) x = complex<T>(0, rand())/Real_wp(RAND_MAX); else if (type == 1) x = complex<T>(rand(), 0)/Real_wp(RAND_MAX); else x = complex<T>(rand(), rand())/Real_wp(RAND_MAX); } template<class T> void GenerateRandomVector(Vector<T>& x, int n) { x.Reallocate(n); for (int i = 0; i < n; i++) GetRandNumber(x(i)); } template<class T, class Prop, class Storage, class Allocator> void GenerateRandomMatrix(Matrix<T, Prop, Storage, Allocator>& A, int m, int n, int nnz) { typename Matrix<T, Prop, Storage, Allocator>::entry_type x; A.Clear(); A.Reallocate(m, n); for (int k = 0; k < nnz; k++) { int i = rand()%m; int j = rand()%n; GetRandNumber(x); A.Set(i, j, x); } } // copy from a sparse matrix to a complexe dense matrix template<class T0, class T1> void Copy(const Matrix<T0, Symmetric, ArrayRowSymSparse>& Asp, Matrix<T1>& A) { int N = Asp.GetM(); A.Reallocate(N, N); A.Fill(0); for (int i = 0; i < N; i++) for (int j = 0; j < Asp.GetRowSize(i); j++) { A(i, Asp.Index(i, j)) = Asp.Value(i, j); A(Asp.Index(i, j), i) = Asp.Value(i, j); } } // copy from a sparse matrix to a complexe dense matrix template<class T0, class T1> void Copy(const Matrix<T0, General, ArrayRowSparse>& Asp, Matrix<T1>& A) { int N = Asp.GetM(); A.Reallocate(N, N); A.Fill(0); for (int i = 0; i < N; i++) for (int j = 0; j < Asp.GetRowSize(i); j++) A(i, Asp.Index(i, j)) = Asp.Value(i, j); } template<class MatrixK, class MatrixM> void FindReferenceEigenvalues(MatrixK& K, MatrixM& M, Vector<complex<double> >& L) { Matrix<complex<double> > invM, Kd, A; Copy(M, invM); GetInverse(invM); Copy(K, Kd); A.Reallocate(K.GetM(), K.GetM()); Mlt(invM, Kd, A); Kd.Clear(); invM.Clear(); GetEigenvalues(A, L); } template<class MatrixK, class MatrixM, class T> void TestSymmetricProblem(MatrixK& K, MatrixM& M, T&, bool add_pos_diag, int nb_eigenval, bool test_chol) { int type_solver = TypeEigenvalueSolver::FEAST; Vector<T> lambda, lambda_imag; Matrix<T, General, ColMajor> eigen_vec; int m = 40, n = m, nnz = 4*m; GenerateRandomMatrix(K, m, n, nnz); GenerateRandomMatrix(M, m, n, nnz); // on rajoute des coefs sur la diagonale de M // pour avoir une matrice definie positive typename MatrixM::entry_type coef_diag; for (int i = 0; i < M.GetM(); i++) { GetRandNumber(coef_diag); if (add_pos_diag) coef_diag += 5.0; M.AddInteraction(i, i, coef_diag); } K.WriteText("K.dat"); M.WriteText("M.dat"); SparseEigenProblem<T, MatrixK, MatrixM> var_eig; // first, we test the case without the mass matrix M var_eig.SetStoppingCriterion(1e-12); var_eig.SetNbAskedEigenvalues(nb_eigenval); var_eig.InitMatrix(K); // eigenvalues in a given interval var_eig.SetIntervalSpectrum(-1.7, -1.0); GetEigenvaluesEigenvectors(var_eig, lambda, lambda_imag, eigen_vec, type_solver); DISP(lambda); DISP(lambda_imag); CheckEigenvalues(K, lambda, eigen_vec); // case with a diagonal matrix M MatrixM Mdiag(n, n); Vector<typename MatrixM::entry_type> D; GenerateRandomVector(D, n); D.Write("D.dat"); for (int i = 0; i < n; i++) Mdiag.AddInteraction(i, i, D(i)); var_eig.InitMatrix(K, Mdiag); var_eig.SetDiagonalMass(); // eigenvalues in a given interval var_eig.SetIntervalSpectrum(0.1, 1.4); GetEigenvaluesEigenvectors(var_eig, lambda, lambda_imag, eigen_vec, type_solver); DISP(lambda); DISP(lambda_imag); CheckEigenvalues(K, Mdiag, lambda, eigen_vec); // case with a symmetric positive definite mass matrix if (test_chol) { var_eig.InitMatrix(K, M); var_eig.SetCholeskyFactoForMass(); var_eig.SetIntervalSpectrum(-0.2, -0.04); GetEigenvaluesEigenvectors(var_eig, lambda, lambda_imag, eigen_vec, type_solver); DISP(lambda); DISP(lambda_imag); CheckEigenvalues(K, M, lambda, eigen_vec); } } template<class MatrixK, class MatrixM, class T> void TestGeneralProblem(MatrixK& K, MatrixM& M, T&, bool add_pos_diag, int nb_eigenval, bool test_chol) { int type_solver = TypeEigenvalueSolver::FEAST; Vector<T> lambda, lambda_imag; Matrix<T, General, ColMajor> eigen_vec; int m = 40, n = m, nnz = 4*m; GenerateRandomMatrix(K, m, n, nnz); GenerateRandomMatrix(M, m, n, nnz); typename MatrixM::entry_type coef_diag; for (int i = 0; i < M.GetM(); i++) { GetRandNumber(coef_diag); if (add_pos_diag) coef_diag += 5.0; M.AddInteraction(i, i, coef_diag); } K.WriteText("K.dat"); M.WriteText("M.dat"); SparseEigenProblem<T, MatrixK, MatrixM> var_eig; // first, we test the case without the mass matrix M var_eig.SetPrintLevel(1); var_eig.SetStoppingCriterion(1e-12); var_eig.SetNbAskedEigenvalues(nb_eigenval); var_eig.InitMatrix(K); var_eig.SetCircleSpectrum(complex<double>(1.2, 0.4), 1.0); GetEigenvaluesEigenvectors(var_eig, lambda, lambda_imag, eigen_vec, type_solver); DISP(lambda); DISP(lambda_imag); CheckEigenvalues(K, lambda, lambda_imag, eigen_vec); // then we test with the mass matrix var_eig.InitMatrix(K, M); GetEigenvaluesEigenvectors(var_eig, lambda, lambda_imag, eigen_vec, type_solver); DISP(lambda); DISP(lambda_imag); CheckEigenvalues(K, M, lambda, lambda_imag, eigen_vec); return; } class HermitianEigenProblem : public SparseEigenProblem<complex<double>, Matrix<complex<double>, General, ArrayRowSparse>, Matrix<complex<double>, General, ArrayRowSparse> > { public: bool IsHermitianProblem() const { return true; } }; template<class MatrixK, class MatrixM> void TestHermitianProblem(MatrixK& K, MatrixM& M, int nb_eigenval) { int type_solver = TypeEigenvalueSolver::FEAST; Vector<complex<double> > lambda, lambda_imag; Matrix<complex<double>, General, ColMajor> eigen_vec; int m = 40, n = m, nnz = 4*m; GenerateRandomMatrix(K, m, n, nnz); GenerateRandomMatrix(M, m, n, nnz); MatrixK K2 = K; MatrixM M2 = M; // on rend les matrices hermitiennes for (int i = 0; i < M2.GetM(); i++) for (int j = 0; j < M2.GetRowSize(i); j++) M.AddInteraction(M2.Index(i, j), i, conjugate(M2.Value(i, j))); for (int i = 0; i < K2.GetM(); i++) for (int j = 0; j < K2.GetRowSize(i); j++) K.AddInteraction(K2.Index(i, j), i, conjugate(K2.Value(i, j))); // on rajoute des coefs sur la diagonale de M // pour avoir une matrice definie positive double coef_diag; for (int i = 0; i < M.GetM(); i++) { GetRandNumber(coef_diag); coef_diag += 3.0; M.AddInteraction(i, i, coef_diag); } K.WriteText("K.dat"); M.WriteText("M.dat"); HermitianEigenProblem var_eig; // first, we test the case without the mass matrix M var_eig.SetStoppingCriterion(1e-12); var_eig.SetNbAskedEigenvalues(nb_eigenval); var_eig.InitMatrix(K); var_eig.SetPrintLevel(1); // eigenvalues in a given interval var_eig.SetIntervalSpectrum(-2.5, -1.0); GetEigenvaluesEigenvectors(var_eig, lambda, lambda_imag, eigen_vec, type_solver); DISP(lambda); DISP(lambda_imag); CheckEigenvalues(K, lambda, eigen_vec); // generalized problem var_eig.InitMatrix(K, M); var_eig.SetIntervalSpectrum(-0.8, -0.2); GetEigenvaluesEigenvectors(var_eig, lambda, lambda_imag, eigen_vec, type_solver); DISP(lambda); DISP(lambda_imag); CheckEigenvalues(K, M, lambda, eigen_vec); } int main(int argc, char** argv) { InitSeldon(argc, argv); bool all_test = true; srand(0); // testing non-symmetric solver { int nb_eigenval = 20; Matrix<double, General, ArrayRowSparse> K; Matrix<double, General, ArrayRowSparse> M; double x; TestGeneralProblem(K, M, x, false, nb_eigenval, false); } srand(0); { int nb_eigenval = 20; Matrix<complex<double>, General, ArrayRowSparse> K; Matrix<complex<double>, General, ArrayRowSparse> M; complex<double> x; TestGeneralProblem(K, M, x, false, nb_eigenval, false); } srand(0); { int nb_eigenval = 20; Matrix<complex<double>, Symmetric, ArrayRowSymSparse> K; Matrix<complex<double>, Symmetric, ArrayRowSymSparse> M; complex<double> x; TestGeneralProblem(K, M, x, false, nb_eigenval, false); } srand(0); // testing symmetric solver { int nb_eigenval = 6; Matrix<double, Symmetric, ArrayRowSymSparse> K; Matrix<double, Symmetric, ArrayRowSymSparse> M; double x; TestSymmetricProblem(K, M, x, true, nb_eigenval, true); } srand(0); { int nb_eigenval = 12; Matrix<complex<double>, General, ArrayRowSparse> K; Matrix<complex<double>, General, ArrayRowSparse> M; TestHermitianProblem(K, M, nb_eigenval); } if (all_test) cout << "All tests passed successfully" << endl; return FinalizeSeldon(); }
26.373159
173
0.583592
HongyuHe
03a91fe7f6ffd57ba51261e671bb6adbae3f5b27
73,798
cpp
C++
2006/samples/reactors/DWFMetaData/DWFAPI.cpp
kevinzhwl/ObjectARXMod
ef4c87db803a451c16213a7197470a3e9b40b1c6
[ "MIT" ]
1
2021-06-25T02:58:47.000Z
2021-06-25T02:58:47.000Z
2006/samples/reactors/DWFMetaData/DWFAPI.cpp
kevinzhwl/ObjectARXMod
ef4c87db803a451c16213a7197470a3e9b40b1c6
[ "MIT" ]
null
null
null
2006/samples/reactors/DWFMetaData/DWFAPI.cpp
kevinzhwl/ObjectARXMod
ef4c87db803a451c16213a7197470a3e9b40b1c6
[ "MIT" ]
3
2020-05-23T02:47:44.000Z
2020-10-27T01:26:53.000Z
// (C) Copyright 2004 by Autodesk, Inc. // // Permission to use, copy, modify, and distribute this software in // object code form for any purpose and without fee is hereby granted, // provided that the above copyright notice appears in all copies and // that both that copyright notice and the limited warranty and // restricted rights notice below appear in all supporting // documentation. // // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE // UNINTERRUPTED OR ERROR FREE. // // Use, duplication, or disclosure by the U.S. Government is subject to // restrictions set forth in FAR 52.227-19 (Commercial Computer // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) // (Rights in Technical Data and Computer Software), as applicable. // // DWFAPI.cpp : Defines the initialization routines for the DLL. // #include "stdafx.h" #include "DWFAPI.h" #include "U:\develop\global\src\coreapps\acmgdreverse\mgPublishUtils.h" #include "dbents.h" #include <stack> #include "AcDMMapi.h" #include "steelSect.h" // this is required for the custom entity CSteelSection #include "dynprops.h" TdDMMReactor *g_pDMMReactor = NULL; //TdPublishReactor *g_pPubReactor = NULL; //TdPublishUIReactor *g_pPubUIReactor = NULL; CCW_AcPublishMgdServices* g_pDxServices; bool g_bIncludeBlockInfo; std::stack<int>g_NodeStack; std::vector<unsigned long>g_entIdVec; int BlockNo = 0; bool invalidTest = true; #ifdef _DEBUG #define new DEBUG_NEW #endif CString OUTFILE(L"C:\\Current Project\\DWFAPI\\DWFs\\OutFile.txt"); HINSTANCE _hdllInstance = NULL; // // Note! // // If this DLL is dynamically linked against the MFC // DLLs, any functions exported from this DLL which // call into MFC must have the AFX_MANAGE_STATE macro // added at the very beginning of the function. // // For example: // // extern "C" BOOL PASCAL EXPORT ExportedFunction() // { // AFX_MANAGE_STATE(AfxGetStaticModuleState()); // // normal function body here // } // // It is very important that this macro appear in each // function, prior to any calls into MFC. This means that // it must appear as the first statement within the // function, even before any object variable declarations // as their constructors may generate calls into the MFC // DLL. // // Please see MFC Technical Notes 33 and 58 for additional // details. // // CDWFAPIApp BEGIN_MESSAGE_MAP(CDWFAPIApp, CWinApp) END_MESSAGE_MAP() // CDWFAPIApp construction CDWFAPIApp::CDWFAPIApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance } // The one and only CDWFAPIApp object CDWFAPIApp theApp; // CDWFAPIApp initialization BOOL CDWFAPIApp::InitInstance() { CWinApp::InitInstance(); return TRUE; } // This functions registers an ARX command. // It can be used to read the localized command name // from a string table stored in the resources. void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc, const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal=-1) { char cmdLocRes[65]; // If idLocal is not -1, it's treated as an ID for // a string stored in the resources. if (idLocal != -1) { // Load strings from the string table and register the command. ::LoadString(_hdllInstance, idLocal, cmdLocRes, 64); acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes, cmdFlags, cmdProc); } else // idLocal is -1, so the 'hard coded' // localized function name is used. acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLoc, cmdFlags, cmdProc); } // Init this application. Register your // commands, reactors... void InitApplication() { // NOTE: DO NOT edit the following lines. //{{AFX_ARX_INIT AddCommand("DWFAPI", "dwfapi", "DWFAPI", ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET,DWFAPI); //}}AFX_ARX_INIT // TODO: add your initialization functions acedPostCommandPrompt(); } // Unload this application. Unregister all objects // registered in InitApplication. void UnloadApplication() { // NOTE: DO NOT edit the following lines. //{{AFX_ARX_EXIT acedRegCmds->removeGroup("ASDKPROPERTY_INS"); //}}AFX_ARX_EXIT // TODO: clean up your application } //////////////////////////////////////////////////////////////////////////// // ObjectARX EntryPoint extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt) { switch (msg) { case AcRx::kInitAppMsg: // Comment out the following line if your // application should be locked into memory acrxDynamicLinker->unlockApplication(pkt); acrxDynamicLinker->registerAppMDIAware(pkt); InitApplication(); acutPrintf("\nType 'DWFAPI' to run the app."); break; case AcRx::kUnloadAppMsg: UnloadApplication(); break; } return AcRx::kRetOK; } // print functions. void myPrintf(CString text, CString filename) { if (filename != "") { FILE *stream; if((stream = fopen(filename, "a+")) == NULL) { printf("\n...Output file could not be created!"); exit(0); } // write the text. fprintf(stream, text); // close the file output if opened. if(fclose(stream)) printf("\n...Output file could not be closed!"); } else printf(text); } void myPrintf(CString text) { printf(text); } //TdDMMReactor class implementation. TdDMMReactor::TdDMMReactor() { A1=false; A2=false; A3=false; A4=false; } TdDMMReactor::~TdDMMReactor() { A1=false; A2=false; A3=false; A4=false; } //wchar_t* TdDMMReactor::D2W(double value) //{ // CString str; // str.Format("%g",value); // USES_CONVERSION; // m_wchar = A2W(str); // return m_wchar; //} void TdDMMReactor::OnBeginEntity(AcDMMEntityReactorInfo * pInfo) //#4 { if (A1 == false) { myPrintf("\nTdDMMReactor::OnBeginEntity", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nTdDMMReactor::OnBeginEntity"); A1 = true; } if (g_bIncludeBlockInfo) { AcDbEntity* pEntity = pInfo->entity(); AcDbObjectId objId = pEntity->objectId(); long oldId = objId.asOldId(); unsigned long front = 0; // this is a custom entity. // assigning a property to the custom entity. if (pEntity->isKindOf(CSteelSection::desc())) { myPrintf("\nCSteelSection FOUND, assigning metadata properties to it.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nCSteelSection FOUND, assigning metadata properties to it."); CSteelSection* pSteelEnt = (CSteelSection*)pEntity; AcDMMEPlotProperties props0; AcDMMEPlotProperty prop0; prop0.SetCategory(L"Steel Section"); USES_CONVERSION; prop0.SetName(L"Section Type"); //Adesk::Int16 SType; //(CSteelSection*)pEntity->getSectionType(SType); prop0.SetValue(L"W Section"); props0.AddProperty(&prop0); prop0.SetName(L"Section Depth"); //Adesk::Int16 SType; double depth = pSteelEnt->getDepth(); m_cstr.Format("%g",depth); m_wchar = A2W(m_cstr); prop0.SetValue(m_wchar); props0.AddProperty(&prop0); prop0.SetName(L"Section Length"); //Adesk::Int16 SType; double length = pSteelEnt->getLength(); m_cstr.Format("%g",length); m_wchar = A2W(m_cstr); prop0.SetValue(m_wchar); props0.AddProperty(&prop0); prop0.SetName(L"Section Flange Width"); //Adesk::Int16 SType; double fWidth = pSteelEnt->getFlangeWidth(); m_cstr.Format("%g",fWidth); m_wchar = A2W(m_cstr); prop0.SetValue(m_wchar); props0.AddProperty(&prop0); prop0.SetName(L"Section Flange Thickness"); //Adesk::Int16 SType; double fThick = pSteelEnt->getFlangeThickness(); m_cstr.Format("%g",fThick); m_wchar = A2W(m_cstr); prop0.SetValue(m_wchar); props0.AddProperty(&prop0); prop0.SetName(L"Section Web Thickness"); //Adesk::Int16 SType; double wThick = pSteelEnt->getWebThickness(); m_cstr.Format("%g",wThick); m_wchar = A2W(m_cstr); prop0.SetValue(m_wchar); props0.AddProperty(&prop0); const wchar_t* wsUnique0 = pInfo->UniqueEntityId(); AcDMMWideString wsPropId0; // need an unique ID for properties. wsPropId0 = L"CUSTOM_ENTITY-"; wsPropId0 += wsUnique0; delete wsUnique0; props0.SetId(PCWIDESTR(wsPropId0)); pInfo->AddProperties(&props0); // add props obj to cache // Invalid value test. if (invalidTest == true) { AcDMMEPlotProperties props100; AcDMMEPlotProperty prop100; props100.AddProperty(&prop100); props100.AddProperty(NULL); pInfo->AddProperties(&props100); //DID 607332 //pInfo->AddProperties(NULL); } // to test different AcDMMProperty methods. // SetType, SetUnit, SetName, SetValue AcDMMEPlotProperty* prop00 = new AcDMMEPlotProperty(); prop00->SetName(L"Test Name"); prop00->SetValue(L"Test Value"); prop00->SetType(L"Test Type"); prop00->SetUnits(L"Test Unit"); AcDMMEPlotProperty* prop01 = prop00; // GetType, GetUnit, GetName, GetValue if(strcmp(OLE2A(prop00->GetName()), "Test Name") == 0) myPrintf("\nPassed: AcDMMEPlotProperty::SetName(), GetName() work fine.", OUTFILE); else myPrintf("\nFailed: AcDMMEPlotProperty::SetName(), GetName() do not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMEPlotProperty::SetName(), GetName()."); if(strcmp(OLE2A(prop00->GetValue()), "Test Value") == 0) myPrintf("\nPassed: AcDMMEPlotProperty::SetValue(), GetValue() work fine.", OUTFILE); else myPrintf("\nFailed: AcDMMEPlotProperty::SetValue(), GetValue() do not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMEPlotProperty::SetValue(), GetValue()"); if(strcmp(OLE2A(prop00->GetType()), "Test Type") == 0) myPrintf("\nPassed: AcDMMEPlotProperty::SetType(), GetType() work fine.", OUTFILE); else myPrintf("\nFailed: AcDMMEPlotProperty::SetType(), GetType() do not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMEPlotProperty::SetType(), GetType()"); if(strcmp(OLE2A(prop00->GetUnits()), "Test Unit") == 0) myPrintf("\nPassed: AcDMMEPlotProperty::SetUnits(), GetUnits() work fine.", OUTFILE); else myPrintf("\nFailed: AcDMMEPlotProperty::SetUnits(), GetUnits() do not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMEPlotProperty::SetUnits(), GetUnits()"); // to test different AcDMMProperties methods for testing. AcDMMEPlotProperties props00 = props0; const AcDMMEPlotPropertyVec propVec = props00.GetProperties(); //AcDMMEPlotProperty* tempProp; int noProp = propVec.size(); for (int i=0; i<=noProp; i++) { const AcDMMEPlotProperty* tempProp = props00.GetProperty(i); } // Invalid value test. if (invalidTest == true) { const AcDMMEPlotProperty* tempProp100 = props00.GetProperty(0); const AcDMMEPlotProperty* tempProp101 = props00.GetProperty(123456); const AcDMMEPlotProperty* tempProp102 = props00.GetProperty(-34); } props00.SetId(L"Partha ID"); props00.SetNamespace(L"http:\\www.autodesk.com", L"Partha Location"); AcDMMStringVec IdVec00; IdVec00.push_back(wsPropId0); props00.SetRefs(IdVec00); // Invalid value test. if (invalidTest == true) { AcDMMStringVec vec100; props00.SetRefs(vec100); } if(strcmp(OLE2A(props00.GetId()), "Partha ID") == 0) myPrintf("\nPassed: AcDMMEPlotProperties::SetId(), GetId() work fine.", OUTFILE); else myPrintf("\nFailed: AcDMMEPlotProperties::SetId(), GetId() do not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMEPlotProperties::SetId(), GetId()"); if(strcmp(OLE2A(props00.GetNamespaceUrl()), "http:\\www.autodesk.com") == 0) myPrintf("\nPassed: AcDMMEPlotProperties::SetNameSpace(), GetNameSpaceUrl() work fine.", OUTFILE); else myPrintf("\nFailed: AcDMMEPlotProperties::SetNameSpace(), GetNameSpaceUrl() do not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMEPlotProperties::SetNameSpace(), GetNameSpaceUrl()"); if(strcmp(OLE2A(props00.GetNamespaceLocation()), "Partha Location") == 0) myPrintf("\nPassed: AcDMMEPlotProperties::SetNameSpace(), GetNameSpaceLocation() work fine.", OUTFILE); else myPrintf("\nFailed: AcDMMEPlotProperties::SetNameSpace(), GetNameSpaceLocation() do not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMEPlotProperties::SetNameSpace(), GetNameSpaceLocation()"); if(props00.GetRefs()->size() == IdVec00.size()) myPrintf("\nPassed: AcDMMEPlotProperties::SetRef(), GetRef() work fine.", OUTFILE); else myPrintf("\nFailed: AcDMMEPlotProperties::SetRef(), GetRef() do not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMEPlotProperties::SetRef(), GetRef()"); // AcDMMWideString. // for testing only will not be written AcDMMWideString wsTemp(wsPropId0); size_t len0 = wsTemp.GetLength(); if (wsTemp.GetLength() == 57) myPrintf("\nAcDMMWideString::GetLength() returns correcft length.", OUTFILE); else myPrintf("\nAcDMMWideString::GetLength() does not return correct length.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMWideString::GetLength()"); if (!wsTemp.IsEmpty()) wsTemp.Empty(); if (wsTemp.IsEmpty()) myPrintf("\nAcDMMWideString::IsEmpty(), Empty() works fine", OUTFILE); else myPrintf("\nAcDMMWideString::IsEmpty(), Empty() do not work fine", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMWideString::IsEmpty(), Empty()"); // string Vector AcDMMStringVec IdVec0; IdVec0.push_back(wsPropId0); int nodeId0 = 0; const AcDMMNode* node0; // check to see if this node already assigned if(!pInfo->GetEntityNode(objId, front, nodeId0)) { nodeId0 = pInfo->GetNextAvailableNodeId(); node0 = new AcDMMNode(nodeId0, L"CUSTOM_ENTITY"); bool bret; bret = pInfo->AddNodeToMap(objId, front, nodeId0); // Invalid value test. if (invalidTest == true) { int NodeId100; unsigned long front100 = g_entIdVec.front(); AcDbObjectId objId100 = pEntity->objectId(); pInfo->AddNodeToMap(0, front100, NodeId100); pInfo->AddNodeToMap(objId100, 0, NodeId100); pInfo->AddNodeToMap(objId100, -3, NodeId100); pInfo->AddNodeToMap(objId100, front100, 0); pInfo->AddNodeToMap(objId100, front100, 123456); pInfo->AddNodeToMap(objId100, front100, -4); } ASSERT(bret); } else { // use the existing node. node0 = pInfo->GetNode(nodeId0); // Invalid value test. if (invalidTest == true) { pInfo->GetNode(0); pInfo->GetNode(100000); pInfo->GetNode(-10); } //bool bret; //bret = pInfo->AddNodeToMap(objId, front, nodeId0); //ASSERT(bret); } // Invalid value test. if (invalidTest == true) { int iNodeId100; unsigned long front100 = g_entIdVec.front(); AcDbObjectId objId100 = pEntity->objectId(); pInfo->GetEntityNode(0, front100, iNodeId100); pInfo->GetEntityNode(objId100, 0, iNodeId100); pInfo->GetEntityNode(objId100, -3, iNodeId100); } ASSERT(0 != nodeId0); if(0 != nodeId0) { g_NodeStack.push(nodeId0); //associate the properties with the node. pInfo->AddPropertiesIds(&IdVec0, (AcDMMNode&)*node0); // Invalid value test. if (invalidTest == true) { AcDMMStringVec IdVec100; const AcDMMNode* node100; pInfo->AddPropertiesIds(&IdVec100, (AcDMMNode&)*node0); // DID 607346 //pInfo->AddPropertiesIds(NULL, (AcDMMNode&)*node0); const AcDMMNode* node101 = NULL; pInfo->AddPropertiesIds(&IdVec100, (AcDMMNode&)*node101); // DID 607346 //pInfo->AddPropertiesIds(NULL, (AcDMMNode&)*node101); } } } if (pEntity->isKindOf(AcDbBlockReference::desc()) && (g_pDxServices != NULL)) // block { myPrintf("\nBlock FOUND, assigning metadata properties to it.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nBlock FOUND, assigning metadata properties to it"); // get the block name. AcDbBlockReference* pBlkRef = 0; char* blkName = 0; if(acdbOpenObject(pBlkRef, objId, AcDb::kForRead) == Acad::eOk) { AcDbBlockTableRecord* pTblRec = 0; if(acdbOpenObject(pTblRec, pBlkRef->blockTableRecord(), AcDb::kForRead) == Acad::eOk) { pTblRec->getName(blkName); pTblRec->close(); } pBlkRef->close(); } // get blocks properties from DX api. g_entIdVec.push_back(oldId); front = g_entIdVec.front(); AcDMMEPlotPropertyVec propVec; // FIRST SET OF PROPERTIES. AcDMMEPlotProperties props; g_pDxServices->get_block_properties(objId, &propVec); //add properties to prop objects. AcDMMEPlotPropertyVec::const_iterator iter = propVec.begin(); // get all the standard meta properties and write them in the new // property collection. while (iter != propVec.end()) { AcDMMEPlotProperty prop = (*iter++); props.AddProperty(&prop); } // write a custom property. AcDMMEPlotProperty prop1(L"ParthaProperty", L"ParthaValue"); USES_CONVERSION; if (blkName != "") prop1.SetCategory(A2W(blkName)); else prop1.SetCategory(L"Custom Catagory1"); props.AddProperty(&prop1); const wchar_t* wsUnique = pInfo->UniqueEntityId(); AcDMMWideString wsPropId; // need an unique ID for properties. wsPropId = L"PARTHA-"; wsPropId += wsUnique; delete wsUnique; props.SetId(PCWIDESTR(wsPropId)); pInfo->AddProperties(&props); // add props obj to cache // Invalid value test. if (invalidTest == true) { AcDMMEPlotProperties props100; AcDMMEPlotProperty prop100; props100.AddProperty(&prop100); props100.AddProperty(NULL); pInfo->AddProperties(&props100); //DID 607332 //pInfo->AddProperties(NULL); } // string Vector AcDMMStringVec IdVec; IdVec.push_back(wsPropId); int nodeId = 0; const AcDMMNode* node; // check to see if this node already assigned if(!pInfo->GetEntityNode(objId, front, nodeId)) { // create a node for this entity. nodeId = pInfo->GetNextAvailableNodeId(); node = new AcDMMNode(nodeId, L"PARTHA"); bool bret; bret = pInfo->AddNodeToMap(objId, front, nodeId); ASSERT(bret); // Invalid value test. if (invalidTest == true) { int NodeId100; unsigned long front100 = g_entIdVec.front(); AcDbObjectId objId100 = pEntity->objectId(); pInfo->AddNodeToMap(0, front100, NodeId100); pInfo->AddNodeToMap(objId100, 0, NodeId100); pInfo->AddNodeToMap(objId100, -3, NodeId100); pInfo->AddNodeToMap(objId100, front100, 0); pInfo->AddNodeToMap(objId100, front100, 123456); pInfo->AddNodeToMap(objId100, front100, -4); } } else { // use the existing node. node = pInfo->GetNode(nodeId); // Invalid value test. if (invalidTest == true) { pInfo->GetNode(0); pInfo->GetNode(100000); pInfo->GetNode(-10); } } // Invalid value test. if (invalidTest == true) { int iNodeId100; unsigned long front100 = g_entIdVec.front(); AcDbObjectId objId100 = pEntity->objectId(); pInfo->GetEntityNode(0, front100, iNodeId100); pInfo->GetEntityNode(objId100, 0, iNodeId100); pInfo->GetEntityNode(objId100, -3, iNodeId100); } ASSERT(0 != nodeId); if (0 != nodeId) { g_NodeStack.push(nodeId); // associate the properties with the node. pInfo->AddPropertiesIds(&IdVec, (AcDMMNode &)*node); // Invalid value test. if (invalidTest == true) { AcDMMStringVec IdVec100; const AcDMMNode* node100; pInfo->AddPropertiesIds(&IdVec100, (AcDMMNode&)*node100); // DID 607346 //pInfo->AddPropertiesIds(NULL, (AcDMMNode&)*node100); const AcDMMNode* node101 = NULL; pInfo->AddPropertiesIds(&IdVec100, (AcDMMNode&)*node101); // DID 607346 //pInfo->AddPropertiesIds(NULL, (AcDMMNode&)*node101);; } } // AcDMMNode::SetNodeNumber(), nodeNumber() // this node will not be added to the map. // this is for testing purpose only. int xNodeId = nodeId+1; AcDMMNode* node1 = new AcDMMNode(nodeId, L"PARTHA01"); node1->SetNodeNumber(xNodeId); if(node1->nodeNumber() == xNodeId) myPrintf("\nPassed: AcDMMNode::SetNodeNumber(), nodeMumber() work fine.", OUTFILE); else myPrintf("\nFailed: AcDMMNode::SetNodeNumber(), nodeNumber() do not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMNode::SetNodeNumber(), nodeMumber()"); // Invalid value test. if (invalidTest == true) { AcDMMNode* node100 = new AcDMMNode(nodeId, L"!@#$%^&*"); node100->SetNodeNumber(0); node100->SetNodeNumber(12345); node100->SetNodeNumber(-34); } //AcDMMNode::SetNodeName(), NodeName() wchar_t* name = L"PARTHA02"; node1->SetNodeName(name); if(strcmp(OLE2A(node1->nodeName()), "PARTHA02") == 0) myPrintf("\nPassed: AcDMMNode::SetNodeName(), nodeName() work fine.", OUTFILE); else myPrintf("\nFailed: AcDMMNode::SetNodeName(), nodeNAme() do not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMNode::SetNodeName(), nodeName()"); // Invalid value test. if (invalidTest == true) { node1->SetNodeName(L""); } // SECOND SET OF PROPERTIES. AcDMMEPlotProperties props2; AcDMMEPlotProperty prop2(L"BappaProperty", L"BappaValue"); if (blkName != "") prop2.SetCategory(A2W(blkName)); else prop2.SetCategory(L"Custom Catagory2"); props2.AddProperty(&prop2); const wchar_t* wsUnique2 = pInfo->UniqueEntityId(); AcDMMWideString wsPropId2; // need an unique ID for properties. wsPropId2 = L"BAPPA-"; wsPropId2 += wsUnique2; delete wsUnique2; props2.SetId(PCWIDESTR(wsPropId2)); pInfo->AddProperties(&props2); // add props obj to cache // Invalid value test. if (invalidTest == true) { AcDMMEPlotProperties props100; AcDMMEPlotProperty prop100; props100.AddProperty(&prop100); props100.AddProperty(NULL); pInfo->AddProperties(&props100); //DID 607332 //pInfo->AddProperties(NULL); } // string Vector AcDMMStringVec IdVec2; IdVec2.push_back(wsPropId2); int nodeId2 = 0; const AcDMMNode* node2; AcDMMNode* node02 = NULL; bool whichOne = true; // check to see if this node already assigned if(!pInfo->GetEntityNode(objId, front, nodeId2)) { // create a node for this entity. nodeId2 = pInfo->GetNextAvailableNodeId(); // try to add the node in a different way. //node2 = new AcDMMNode(nodeId2, L"BAPPA"); //bool bret2; //bret2 = pInfo->AddNodeToMap(objId, front, nodeId2); node02->SetNodeNumber(nodeId2); // Invalid value test. if (invalidTest == true) { AcDMMNode* node100 = new AcDMMNode(nodeId, L"!@#$%^&*"); node100->SetNodeNumber(0); node100->SetNodeNumber(12345); node100->SetNodeNumber(-34); } node02->SetNodeName(L"BAPPA"); // Invalid value test. if (invalidTest == true) { node02->SetNodeName(L""); } pInfo->SetCurrentNode(nodeId2, 0); // Invalid value test. if (invalidTest == true) { pInfo->SetCurrentNode(0, 0); pInfo->SetCurrentNode(-3, 0); pInfo->SetCurrentNode(0, -5); } whichOne = true; AcDMMNode node03; pInfo->GetCurrentEntityNode(node03, 0); /*if (node03.nodeNumber != node02->nodeNumber()) myPrintf("\nFailed: AcDMMEntityReactorInfo::GetCurrentEntityNode() does not get the correct entity node.", OUTFILE);*/ //ASSERT(bret2); // Invalid value test. if (invalidTest == true) { AcDMMNode node100; pInfo->GetCurrentEntityNode(node100, 3345); pInfo->GetCurrentEntityNode(node100, -2); } } else { // use the existing node. node2 = pInfo->GetNode(nodeId2); // Invalid value test. if (invalidTest == true) { pInfo->GetNode(0); pInfo->GetNode(100000); pInfo->GetNode(-10); } pInfo->SetNodeName(nodeId2, L"BAPPA01"); // Invalid value test. if (invalidTest == true) { int node100; pInfo->SetNodeName(node100, L"xx"); node100=12; pInfo->SetNodeName(node100, L""); } pInfo->SetCurrentNode(nodeId2, 0); // Invalid value test. if (invalidTest == true) { pInfo->SetCurrentNode(0, 0); pInfo->SetCurrentNode(-3, 0); pInfo->SetCurrentNode(0, -5); } whichOne = false; AcDMMNode node03; pInfo->GetCurrentEntityNode(node03, 0); /*if (node03.nodeNumber != node2->nodeNumber()) myPrintf("\nFailed: AcDMMEntityReactorInfo::GetCurrentEntityNode() does not get the correct entity node.", OUTFILE);*/ // Invalid value test. if (invalidTest == true) { AcDMMNode node100; pInfo->GetCurrentEntityNode(node100, 3098); pInfo->GetCurrentEntityNode(node100, -2); } } // Invalid value test. if (invalidTest == true) { int iNodeId100; unsigned long front100 = g_entIdVec.front(); AcDbObjectId objId100 = pEntity->objectId(); pInfo->GetEntityNode(0, front100, iNodeId100); pInfo->GetEntityNode(objId100, 0, iNodeId100); pInfo->GetEntityNode(objId100, -3, iNodeId100); } ASSERT(0 != nodeId2); if (0 != nodeId2) { g_NodeStack.push(nodeId2); // associate the properties with the node. if (whichOne == false) pInfo->AddPropertiesIds(&IdVec2, (AcDMMNode &)*node2); else pInfo->AddPropertiesIds(&IdVec2, (AcDMMNode &)*node02); // Invalid value test. if (invalidTest == true) { AcDMMStringVec IdVec100; const AcDMMNode* node100; pInfo->AddPropertiesIds(&IdVec100, (AcDMMNode&)*node100); // DID 607346 //pInfo->AddPropertiesIds(NULL, (AcDMMNode&)*node100); const AcDMMNode* node101 = NULL; pInfo->AddPropertiesIds(&IdVec100, (AcDMMNode&)*node101); // DID 607346 //pInfo->AddPropertiesIds(NULL, (AcDMMNode&)*node101); } } } else { if (!g_NodeStack.empty()) { //ASSERT(!g_entIdVec.empty()); int iNodeId = g_NodeStack.top(); front = g_entIdVec.front(); //if no one else has assigned a Node Id for this entity if(!pInfo->GetEntityNode(objId, front, iNodeId)) { // associate this entity with the top node on the stack bool bret; bret = pInfo->AddNodeToMap(objId, front, iNodeId); ASSERT(bret); // Invalid value test. if (invalidTest == true) { int NodeId100; unsigned long front100 = g_entIdVec.front(); AcDbObjectId objId100 = pEntity->objectId(); pInfo->AddNodeToMap(0, front100, NodeId100); pInfo->AddNodeToMap(objId100, 0, NodeId100); pInfo->AddNodeToMap(objId100, -3, NodeId100); pInfo->AddNodeToMap(objId100, front100, 0); pInfo->AddNodeToMap(objId100, front100, 123456); pInfo->AddNodeToMap(objId100, front100, -4); } } // Invalid value test. if (invalidTest == true) { int iNodeId100; unsigned long front100 = g_entIdVec.front(); AcDbObjectId objId100 = pEntity->objectId(); pInfo->GetEntityNode(0, front100, iNodeId100); pInfo->GetEntityNode(objId100, 0, iNodeId100); pInfo->GetEntityNode(objId100, -3, iNodeId100); } if(pEntity->isKindOf(AcDbBlockEnd::desc())) { g_NodeStack.pop(); g_entIdVec.pop_back(); } } } pInfo->flush(); // this is a test to Job Cancled methods. Make sure when you un-comment these, // you hit the TdPublishReactor::OnCancelledOrFailedPublishing reactor. //pInfo->cancelTheJob(); //if (!pInfo->isCancelled()) // myPrintf("\nThe job is correctly cancled.", OUTFILE); } } void TdDMMReactor::OnBeginSheet(AcDMMSheetReactorInfo * pInfo) //#3 { if (A2 == false) { myPrintf("\nTdDMMReactor::OnBeginSheet", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nTdDMMReactor::OnBeginSheet"); A2 = true; } // be sure to start with empty stack while (!g_NodeStack.empty()) g_NodeStack.pop(); if (!pInfo->isModelLayout()) // Layout { // add a resource AcDMMResourceInfo res(L"ParthaSheetResource", L"text", L"C:\\Current Project\\DWFAPI\\DWFs\\Reflection Paper.doc"); AcDMMResourceVec resVec; resVec.push_back(res); pInfo->AddPageResources(resVec); // Invalid value test. if (invalidTest == true) { AcDMMResourceVec pVec100; pInfo->AddPageResources(pVec100); } // add a property AcDMMEPlotPropertyVec propVec; //AcDMMEPlotProperty prop(L"ParthaSheetProperty", L"ParthaSheetValue"); //prop.SetCategory(L"ParthaSheetProp"); //propVec.push_back(prop); // plotLayoutId() long plotLayId = pInfo->plotLayoutId().asOldId(); AcDMMEPlotProperty propLayId(L"Layout ID", (wchar_t*)plotLayId); propLayId.SetCategory(L"ParthaSheetProp"); propVec.push_back(propLayId); // plotArea() AcDMMSheetReactorInfo::PlotArea plotarea = pInfo->plotArea(); AcDMMEPlotProperty propPlotArea; propPlotArea.SetName(L"Plot Area"); switch (plotarea) { case AcDMMSheetReactorInfo::PlotArea::kDisplay: propPlotArea.SetValue(L"Plot display, the visible portion of the picture."); break; case AcDMMSheetReactorInfo::PlotArea::kExtents: propPlotArea.SetValue(L"Plot extents, i.e. all geometry."); break; case AcDMMSheetReactorInfo::PlotArea::kLimits: propPlotArea.SetValue(L"Plot the limits set by the user."); break; case AcDMMSheetReactorInfo::PlotArea::kView: propPlotArea.SetValue(L"Plot a named view."); break; case AcDMMSheetReactorInfo::PlotArea::kWindow: propPlotArea.SetValue(L"Plot a user specified window - a rectangular area."); break; case AcDMMSheetReactorInfo::PlotArea::kLayout: propPlotArea.SetValue(L"Plot the extents of the layout."); break; } propPlotArea.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotArea); //plotRotation(). AcDMMSheetReactorInfo::PlotRotation plotrotation = pInfo->plotRotation(); AcDMMEPlotProperty propPlotRotation; propPlotRotation.SetName(L"Plot Rotation"); switch (plotrotation) { case AcDMMSheetReactorInfo::PlotRotation::k0degrees: propPlotRotation.SetValue(L"0 degrees camera rotation."); break; case AcDMMSheetReactorInfo::PlotRotation::k180degrees: propPlotRotation.SetValue(L"90 degrees camera rotation."); break; case AcDMMSheetReactorInfo::PlotRotation::k270degrees: propPlotRotation.SetValue(L"180 degrees camera rotation, i.e., plot upside down."); break; case AcDMMSheetReactorInfo::PlotRotation::k90degrees: propPlotRotation.SetValue(L"270 degrees camera rotation."); break; } propPlotRotation.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotRotation); // plotMediaUnit(). AcDMMSheetReactorInfo::PlotMediaUnits plotmediaunits = pInfo->plotMediaUnits(); AcDMMEPlotProperty propPlotMediaUnits; propPlotMediaUnits.SetName(L"Plot Rotation"); switch (plotmediaunits) { case AcDMMSheetReactorInfo::PlotMediaUnits::kInches: propPlotMediaUnits.SetValue(L"Using imperial units."); break; case AcDMMSheetReactorInfo::PlotMediaUnits::kMillimeters: propPlotMediaUnits.SetValue(L"Using metric units."); break; case AcDMMSheetReactorInfo::PlotMediaUnits::kPixels: propPlotMediaUnits.SetValue(L"Using dimensionaless raster units, not expected for DWF."); break; } propPlotMediaUnits.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotMediaUnits); USES_CONVERSION; // paperScale(). double paperScale = pInfo->paperScale(); bool isScale = pInfo->isScaleSpecified(); AcDMMEPlotProperty propPaperScale; propPaperScale.SetName(L"Paper Scale"); if (isScale) { m_cstr.Format("%g",paperScale); m_wchar = A2W(m_cstr); propPaperScale.SetValue(m_wchar); } else { propPaperScale.SetValue(L"Scale to Fit."); } propPaperScale.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPaperScale); // drawingScale(). double drawingScale = pInfo->drawingScale(); AcDMMEPlotProperty propDrawingScale; propDrawingScale.SetName(L"Drawing Scale"); m_cstr.Format("%g",drawingScale); m_wchar = A2W(m_cstr); propDrawingScale.SetValue(m_wchar); propDrawingScale.SetCategory(L"ParthaSheetProp"); propVec.push_back(propDrawingScale); // originX(). double OriginX = pInfo->originX(); AcDMMEPlotProperty propOriginX; propOriginX.SetName(L"Drawing Origin X"); m_cstr.Format("%g",OriginX); m_wchar = A2W(m_cstr); propOriginX.SetValue(m_wchar); propOriginX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propOriginX); // originY(). double OriginY = pInfo->originY(); AcDMMEPlotProperty propOriginY; propOriginY.SetName(L"Drawing Origin Y"); m_cstr.Format("%g",OriginY); m_wchar = A2W(m_cstr); propOriginY.SetValue(m_wchar); propOriginY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propOriginY); // plotWindowMinX(). double PlotWinMinX = pInfo->plotWindowMinX(); AcDMMEPlotProperty propPlotWinMinX; propPlotWinMinX.SetName(L"Plot Window MinX"); m_cstr.Format("%g",PlotWinMinX); m_wchar = A2W(m_cstr); propPlotWinMinX.SetValue(m_wchar); propPlotWinMinX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotWinMinX); // plotWindowMinY(). double PlotWinMinY = pInfo->plotWindowMinY(); AcDMMEPlotProperty propPlotWinMinY; propPlotWinMinY.SetName(L"Plot Window MinY"); m_cstr.Format("%g",PlotWinMinY); m_wchar = A2W(m_cstr); propPlotWinMinY.SetValue(m_wchar); propPlotWinMinY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotWinMinY); // plotWindowMaxX(). double PlotWinMaxX = pInfo->plotWindowMaxX(); AcDMMEPlotProperty propPlotWinMaxX; propPlotWinMaxX.SetName(L"Plot Window MaxX"); m_cstr.Format("%g",PlotWinMaxX); m_wchar = A2W(m_cstr); propPlotWinMaxX.SetValue(m_wchar); propPlotWinMaxX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotWinMaxX); // plotWindowMinY(). double PlotWinMaxY = pInfo->plotWindowMaxY(); AcDMMEPlotProperty propPlotWinMaxY; propPlotWinMaxY.SetName(L"Plot Window MaxY"); m_cstr.Format("%g",PlotWinMaxY); m_wchar = A2W(m_cstr); propPlotWinMaxY.SetValue(m_wchar); propPlotWinMaxY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotWinMaxY); //viewPlotted() const TCHAR* ViewPlotted = pInfo->viewPlotted(); AcDMMEPlotProperty propViewPlotted; propViewPlotted.SetName(L"View Plotted"); if (strcmp(ViewPlotted, "") == 0) propViewPlotted.SetValue(L"View name not defined."); else { m_cstr.Format("%s",ViewPlotted); m_wchar = A2W(m_cstr); propViewPlotted.SetValue(m_wchar); } propViewPlotted.SetCategory(L"ParthaSheetProp"); propVec.push_back(propViewPlotted); // areLinesHidden(). bool areLinesHidden = pInfo->areLinesHidden(); AcDMMEPlotProperty propIsLinesHidden; propIsLinesHidden.SetName(L"Are lines hidden"); if (areLinesHidden) propIsLinesHidden.SetValue(L"Yes"); else propIsLinesHidden.SetValue(L"No"); propIsLinesHidden.SetCategory(L"ParthaSheetProp"); propVec.push_back(propIsLinesHidden); // arePlottingLineWeights(). bool arePlottingLineWeights = pInfo->arePlottingLineWeights(); AcDMMEPlotProperty propPlottingLineWeights; propPlottingLineWeights.SetName(L"Are Plotting Line Weights"); if (arePlottingLineWeights) propPlottingLineWeights.SetValue(L"Yes"); else propPlottingLineWeights.SetValue(L"No"); propPlottingLineWeights.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlottingLineWeights); // areScallingLineWeights(). bool areScallingLineWeights = pInfo->areScalingLineWeights(); AcDMMEPlotProperty propScallingLineWeights; propScallingLineWeights.SetName(L"Are Scalling Line Weights"); if (areScallingLineWeights) propScallingLineWeights.SetValue(L"Yes"); else propScallingLineWeights.SetValue(L"No"); propScallingLineWeights.SetCategory(L"ParthaSheetProp"); propVec.push_back(propScallingLineWeights); // displayMinX(). double displayMinX = pInfo->displayMinX(); AcDMMEPlotProperty propDisplayMinX; propDisplayMinX.SetName(L"Display Min X"); m_cstr.Format("%g",displayMinX); m_wchar = A2W(m_cstr); propDisplayMinX.SetValue(m_wchar); propDisplayMinX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propDisplayMinX); // displayMinY(). double displayMinY = pInfo->displayMinY(); AcDMMEPlotProperty propDisplayMinY; propDisplayMinY.SetName(L"Display Min Y"); m_cstr.Format("%g",displayMinY); m_wchar = A2W(m_cstr); propDisplayMinY.SetValue(m_wchar); propDisplayMinY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propDisplayMinY); // displayMaxX(). double displayMaxX = pInfo->displayMaxX(); AcDMMEPlotProperty propDisplayMaxX; propDisplayMaxX.SetName(L"Display Max X"); m_cstr.Format("%g",displayMaxX); m_wchar = A2W(m_cstr); propDisplayMaxX.SetValue(m_wchar); propDisplayMaxX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propDisplayMaxX); // displayMaxY(). double displayMaxY = pInfo->displayMaxY(); AcDMMEPlotProperty propDisplayMaxY; propDisplayMaxY.SetName(L"Display Max Y"); m_cstr.Format("%g",displayMaxY); m_wchar = A2W(m_cstr); propDisplayMaxY.SetValue(m_wchar); propDisplayMaxY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propDisplayMaxY); // layoutMarginMinX(). double layoutMarginMinX = pInfo->layoutMarginMinX(); AcDMMEPlotProperty propLayoutMarginMinX; propLayoutMarginMinX.SetName(L"Layout Margin Min X"); m_cstr.Format("%g",layoutMarginMinX); m_wchar = A2W(m_cstr); propLayoutMarginMinX.SetValue(m_wchar); propLayoutMarginMinX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propLayoutMarginMinX); // layoutMarginMinY(). double layoutMarginMinY = pInfo->layoutMarginMinY(); AcDMMEPlotProperty propLayoutMarginMinY; propLayoutMarginMinY.SetName(L"Layout Margin Min Y"); m_cstr.Format("%g",layoutMarginMinY); m_wchar = A2W(m_cstr); propLayoutMarginMinY.SetValue(m_wchar); propLayoutMarginMinY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propLayoutMarginMinY); // layoutMarginMaxX(). double layoutMarginMaxX = pInfo->layoutMarginMaxX(); AcDMMEPlotProperty propLayoutMarginMaxX; propLayoutMarginMaxX.SetName(L"Layout Margin Max X"); m_cstr.Format("%g",layoutMarginMaxX); m_wchar = A2W(m_cstr); propLayoutMarginMaxX.SetValue(m_wchar); propLayoutMarginMaxX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propLayoutMarginMaxX); // layoutMarginMaxY(). double layoutMarginMaxY = pInfo->layoutMarginMaxY(); AcDMMEPlotProperty propLayoutMarginMaxY; propLayoutMarginMaxY.SetName(L"Layout Margin Max Y"); m_cstr.Format("%g",layoutMarginMaxY); m_wchar = A2W(m_cstr); propLayoutMarginMaxY.SetValue(m_wchar); propLayoutMarginMaxY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propLayoutMarginMaxY); // printableBoundsX(). double printableBoundsX = pInfo->printableBoundsX(); AcDMMEPlotProperty propPrintableBoundsX; propPrintableBoundsX.SetName(L"Printable Bounds X"); m_cstr.Format("%g",printableBoundsX); m_wchar = A2W(m_cstr); propPrintableBoundsX.SetValue(m_wchar); propPrintableBoundsX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPrintableBoundsX); // printableBoundsY(). double printableBoundsY = pInfo->printableBoundsY(); AcDMMEPlotProperty propPrintableBoundsY; propPrintableBoundsY.SetName(L"Printable Bounds Y"); m_cstr.Format("%g",printableBoundsY); m_wchar = A2W(m_cstr); propPrintableBoundsY.SetValue(m_wchar); propPrintableBoundsY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPrintableBoundsY); // maxBoundsX(). double maxBoundsX = pInfo->maxBoundsX(); AcDMMEPlotProperty propMaxBoundsX; propMaxBoundsX.SetName(L"Max Bounds X"); m_cstr.Format("%g",maxBoundsX); m_wchar = A2W(m_cstr); propMaxBoundsX.SetValue(m_wchar); propMaxBoundsX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propMaxBoundsX); // maxBoundsY(). double maxBoundsY = pInfo->maxBoundsY(); AcDMMEPlotProperty propMaxBoundsY; propMaxBoundsY.SetName(L"Max Bounds Y"); m_cstr.Format("%g",maxBoundsY); m_wchar = A2W(m_cstr); propMaxBoundsY.SetValue(m_wchar); propMaxBoundsY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propMaxBoundsY); // stepsPerInch(). double stepsPerInch = pInfo->stepsPerInch(); AcDMMEPlotProperty propStepsPerInch; propMaxBoundsY.SetName(L"Steps per Inch"); m_cstr.Format("%g",stepsPerInch); m_wchar = A2W(m_cstr); propMaxBoundsY.SetValue(m_wchar); propMaxBoundsY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propMaxBoundsY); //configuration() const TCHAR* configuration = pInfo->configuration(); AcDMMEPlotProperty propConfiguration; propConfiguration.SetName(L"Configuration"); if (strcmp(configuration, "") == 0) propConfiguration.SetValue(L"Configuration name not defined."); else { m_cstr.Format("%s",configuration); m_wchar = A2W(m_cstr); propConfiguration.SetValue(m_wchar); } propConfiguration.SetCategory(L"ParthaSheetProp"); propVec.push_back(propConfiguration); //plotToFilePath() const TCHAR* plotToFilePath = pInfo->plotToFilePath(); AcDMMEPlotProperty propPlotToFilePath; propPlotToFilePath.SetName(L"Plot To File Path"); if (strcmp(plotToFilePath, "") == 0) propPlotToFilePath.SetValue(L"Plot To File Path not defined."); else { m_cstr.Format("%s",plotToFilePath); m_wchar = A2W(m_cstr); propPlotToFilePath.SetValue(m_wchar); } propPlotToFilePath.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotToFilePath); //plotToFileName() const TCHAR* plotToFileName = pInfo->plotToFileName(); AcDMMEPlotProperty propPlotToFileName; propPlotToFileName.SetName(L"Plot To File Name"); if (strcmp(plotToFileName, "") == 0) propPlotToFileName.SetValue(L"Plot To File Name not defined."); else { m_cstr.Format("%s",plotToFileName); m_wchar = A2W(m_cstr); propPlotToFileName.SetValue(m_wchar); } propPlotToFileName.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotToFileName); //caninicalMediaName() const TCHAR* caninicalMediaName = pInfo->canonicalMediaName(); AcDMMEPlotProperty propCaninicalMediaName; propCaninicalMediaName.SetName(L"Caninical Media Name"); if (strcmp(caninicalMediaName, "") == 0) propCaninicalMediaName.SetValue(L"Caninical Media Name not defined."); else { m_cstr.Format("%s",caninicalMediaName); m_wchar = A2W(m_cstr); propCaninicalMediaName.SetValue(m_wchar); } propCaninicalMediaName.SetCategory(L"ParthaSheetProp"); propVec.push_back(propCaninicalMediaName); ///////////////// // plotBoundsMinX(). double plotBoundsMinX = pInfo->plotBoundsMinX(); AcDMMEPlotProperty propPlotBoundsMinX; propPlotBoundsMinX.SetName(L"Plot Bounds Min X"); m_cstr.Format("%g",plotBoundsMinX); m_wchar = A2W(m_cstr); propPlotBoundsMinX.SetValue(m_wchar); propPlotBoundsMinX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotBoundsMinX); // plotBoundsMinY(). double plotBoundsMinY = pInfo->plotBoundsMinY(); AcDMMEPlotProperty propPlotBoundsMinY; propPlotBoundsMinY.SetName(L"Plot Bounds Min Y"); m_cstr.Format("%g",plotBoundsMinY); m_wchar = A2W(m_cstr); propPlotBoundsMinY.SetValue(m_wchar); propPlotBoundsMinY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotBoundsMinY); // plotBoundsMaxX(). double plotBoundsMaxX = pInfo->plotBoundsMaxX(); AcDMMEPlotProperty propPlotBoundsMaxX; propPlotBoundsMaxX.SetName(L"Plot Bounds Max X"); m_cstr.Format("%g",plotBoundsMaxX); m_wchar = A2W(m_cstr); propPlotBoundsMaxX.SetValue(m_wchar); propPlotBoundsMaxX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotBoundsMaxX); // plotBoundsMaxY(). double plotBoundsMaxY = pInfo->plotBoundsMaxY(); AcDMMEPlotProperty propPlotBoundsMaxY; propPlotBoundsMaxY.SetName(L"Plot Bounds Max Y"); m_cstr.Format("%g",plotBoundsMaxY); m_wchar = A2W(m_cstr); propPlotBoundsMaxY.SetValue(m_wchar); propPlotBoundsMaxY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propPlotBoundsMaxY); // layoutBoundsMinX(). double layoutBoundsMinX = pInfo->layoutBoundsMinX(); AcDMMEPlotProperty propLayoutBoundsMinX; propLayoutBoundsMinX.SetName(L"Layout Bounds Min X"); m_cstr.Format("%g",layoutBoundsMinX); m_wchar = A2W(m_cstr); propLayoutBoundsMinX.SetValue(m_wchar); propLayoutBoundsMinX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propLayoutBoundsMinX); // layoutBoundsMinY(). double layoutBoundsMinY = pInfo->layoutBoundsMinY(); AcDMMEPlotProperty propLayoutBoundsMinY; propLayoutBoundsMinY.SetName(L"Layout Bounds Min Y"); m_cstr.Format("%g",layoutBoundsMinY); m_wchar = A2W(m_cstr); propLayoutBoundsMinY.SetValue(m_wchar); propLayoutBoundsMinY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propLayoutBoundsMinY); // layoutBoundsMaxX(). double layoutBoundsMaxX = pInfo->layoutBoundsMaxX(); AcDMMEPlotProperty propLayoutBoundsMaxX; propLayoutBoundsMaxX.SetName(L"Layout Bounds Max X"); m_cstr.Format("%g",layoutBoundsMaxX); m_wchar = A2W(m_cstr); propLayoutBoundsMaxX.SetValue(m_wchar); propLayoutBoundsMaxX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propLayoutBoundsMaxX); // plotBoundsMaxY(). double layoutBoundsMaxY = pInfo->layoutBoundsMaxY(); AcDMMEPlotProperty propLayoutBoundsMaxY; propLayoutBoundsMaxY.SetName(L"Layout Bounds Max Y"); m_cstr.Format("%g",layoutBoundsMaxY); m_wchar = A2W(m_cstr); propLayoutBoundsMaxY.SetValue(m_wchar); propLayoutBoundsMaxY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propLayoutBoundsMaxY); // effectivePlotOffsetX(). double effectivePlotOffsetX = pInfo->effectivePlotOffsetX(); AcDMMEPlotProperty propEffectivePlotOffsetX; propEffectivePlotOffsetX.SetName(L"Effective Plot Offset X"); m_cstr.Format("%g",effectivePlotOffsetX); m_wchar = A2W(m_cstr); propEffectivePlotOffsetX.SetValue(m_wchar); propEffectivePlotOffsetX.SetCategory(L"ParthaSheetProp"); propVec.push_back(propEffectivePlotOffsetX); // effectivePlotOffsetY(). double effectivePlotOffsetY = pInfo->effectivePlotOffsetY(); AcDMMEPlotProperty propEffectivePlotOffsetY; propEffectivePlotOffsetY.SetName(L"Effective Plot Offset Y"); m_cstr.Format("%g",effectivePlotOffsetY); m_wchar = A2W(m_cstr); propEffectivePlotOffsetY.SetValue(m_wchar); propEffectivePlotOffsetY.SetCategory(L"ParthaSheetProp"); propVec.push_back(propEffectivePlotOffsetY); // effectivePlotOffsetXdevice(). int effectivePlotOffsetXdevice = pInfo->effectivePlotOffsetXdevice(); AcDMMEPlotProperty propEffectivePlotOffsetXdevice; propEffectivePlotOffsetXdevice.SetName(L"Effective Plot Offset X Device"); m_cstr.Format("%d",effectivePlotOffsetXdevice); m_wchar = A2W(m_cstr); propEffectivePlotOffsetXdevice.SetValue(m_wchar); propEffectivePlotOffsetXdevice.SetCategory(L"ParthaSheetProp"); propVec.push_back(propEffectivePlotOffsetXdevice); // effectivePlotOffsetYdevice(). int effectivePlotOffsetYdevice = pInfo->effectivePlotOffsetYdevice(); AcDMMEPlotProperty propEffectivePlotOffsetYdevice; propEffectivePlotOffsetYdevice.SetName(L"Effective Plot Offset Y Device"); m_cstr.Format("%d",effectivePlotOffsetYdevice); m_wchar = A2W(m_cstr); propEffectivePlotOffsetYdevice.SetValue(m_wchar); propEffectivePlotOffsetYdevice.SetCategory(L"ParthaSheetProp"); propVec.push_back(propEffectivePlotOffsetYdevice); // Add all properties to the Sheet Info object. pInfo->AddPageProperties(propVec); // add props obj to cache // Invalid value test. if (invalidTest == true) { AcDMMEPlotPropertyVec pVec100; pInfo->AddPageProperties(pVec100); } } else // model Layout { // add a property AcDMMEPlotProperty prop(L"ParthaModelProperty", L"ParthaModelValue"); prop.SetCategory(L"ParthaModelProp"); AcDMMEPlotPropertyVec propVec; propVec.push_back(prop); pInfo->AddPageProperties(propVec); // add props obj to cache // Invalid value test. if (invalidTest == true) { AcDMMEPlotPropertyVec pVec100; pInfo->AddPageProperties(pVec100); } // add a resource AcDMMResourceInfo res(L"ParthaModelResource", L"text", L"C:\\Current Project\\DWFAPI\\DWFs\\Resource-zip.zip"); USES_CONVERSION; // SetRole() char* role = "Partha's role"; res.SetRole(A2W(role)); const char* outRole = OLE2A(res.GetRole()); if (strcmp(outRole, role) == 0) myPrintf("\nAcDMMResourceInfo::role(), getRole() worked fine.", OUTFILE); else myPrintf("\nAcDMMResourceInfo::role(), getRole() did not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMResourceInfo::role(), getRole()"); // SetMime() char* mime = "Partha's mime"; res.SetMime(A2W(mime)); const char* outMime = OLE2A(res.GetMime()); if (strcmp(outMime, mime) == 0) myPrintf("\nAcDMMResourceInfo::mime(), getMime() worked fine.", OUTFILE); else myPrintf("\nAcDMMResourceInfo::mime(), getMime() did not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMResourceInfo::mime(), getMime()"); // SetPath() char* path = "C:\\Partha's Path"; res.SetPath(A2W(path)); const char* outPath = OLE2A(res.GetPath()); if (strcmp(outPath, path) == 0) myPrintf("\nAcDMMResourceInfo::path(), getPath() worked fine.", OUTFILE); else myPrintf("\nAcDMMResourceInfo::path(), getPath() did not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMResourceInfo::path(), getPath()"); // = operator. AcDMMResourceInfo res1 = res; res1.SetRole(L"Bappa's role"); const char* outPath1 = OLE2A(res1.GetPath()); if (strcmp(outPath1, path) == 0) myPrintf("\nAcDMMResourceInfo::'=' operator worked fine.", OUTFILE); else myPrintf("\nAcDMMResourceInfo::'=' operator did not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMResourceInfo::'=' operator"); // other constructor; AcDMMResourceInfo res2(res1); res2.SetRole(L"Anit's role"); const char* outPath2 = OLE2A(res2.GetPath()); if (strcmp(outPath2, path) == 0) myPrintf("\nAcDMMResourceInfo::other constructor worked fine.", OUTFILE); else myPrintf("\nAcDMMResourceInfo::other constructor did not work fine.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcDMMResourceInfo::other constructor"); AcDMMResourceVec resVec; resVec.push_back(res); resVec.push_back(res1); resVec.push_back(res2); pInfo->AddPageResources(resVec); } } void TdDMMReactor::OnEndEntity(AcDMMEntityReactorInfo * pInfo) //#5 { if (A3 == false) { myPrintf("\nTdDMMReactor::OnEndEntity", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nTdDMMReactor::OnEndEntity"); A3 = true; } } void TdDMMReactor::OnEndSheet(AcDMMSheetReactorInfo * pInfo) //#6 { if (A4 == false) { myPrintf("\nTdDMMReactor::OnEndSheet", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nTdDMMReactor::OnEndSheet"); A4 = true; } } // TdPublishReactor class implementation. TdPublishReactor::TdPublishReactor() { B1=false; B2=false; B3=false; B4=false; B5=false; B6=false; B7=false; B8=false; } TdPublishReactor::~TdPublishReactor() { B1=false; B2=false; B3=false; B4=false; B5=false; B6=false; B7=false; B8=false; } void TdPublishReactor::OnAboutToBeginBackgroundPublishing(AcPublishBeforeJobInfo* pInfo) { if (B1 == false) { myPrintf("\nTdPublishReactor::OnAboutToBeginBackgroundPublishing", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); B1 = true; } // check to see if this job is publishing to DWF // GetDSDData(). if (pInfo->GetDSDData()->sheetType() == AcPlDSDEntry::SheetType::kOriginalDevice) // not a DWF job, nothing to do here return; else myPrintf("\n Passed: AcPublishBeforeJobInfo::GetDSDData", OUTFILE); // WritePrivateSection() AcNameValuePairVec valuePairVec; AcNameValuePair nameValuePair(_T("Partha_JobBefore_Private_Name"), _T("Partha_JobBefore_Private_Value")); // Invalid value test. if (invalidTest == true) { AcNameValuePair nameValuePair100(_T("!@#$^%^*&*&%&*%"), _T("^$$&*%%_*^&*%&$%^")); } // Invalid value test. if (invalidTest == true) { AcNameValuePair nameValuePair100(_T("!@#$^%^*&*&%&*%"), _T("^$$&*%%_*^&*%&$%^")); } valuePairVec.push_back(nameValuePair); pInfo->WritePrivateSection(_T("Partha JobBefore Private Data"), valuePairVec); // Invalid value test. if (invalidTest == true) { AcNameValuePairVec valuePairVec100; pInfo->WritePrivateSection(_T("^$$^^"), valuePairVec100); } //JobWillPublishInBackground bool ret = pInfo->JobWillPublishInBackground(); if (ret == true) myPrintf("\nPassed: AcPublishBeforeJobInfo::JobWillPublishInBackground(), publishing background.", OUTFILE); else myPrintf("\nPassed: AcPublishBeforeJobInfo::JobWillPublishInBackground(), publishing foreground.", OUTFILE); } void TdPublishReactor::OnAboutToBeginPublishing(AcPublishBeginJobInfo* pInfo) //#1 { if (B2 == false) { myPrintf("\nTdPublishReactor::OnAboutToBeginPublishing", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nTdPublishReactor::OnAboutToBeginPublishing"); B2 = true; } // check to see if this job is publishing to DWF // GetDSDData(). if (pInfo->GetDSDData()->sheetType() == AcPlDSDEntry::SheetType::kOriginalDevice) // not a DWF job, nothing to do here return; else myPrintf("\n Passed: AcPublishBeginJobInfo::GetDSDData", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcPublishBeginJobInfo::GetDSDData"); // make sure AcEplotX.arx is loaded if (!acrxServiceIsRegistered("AcEPlotX")) { acrxLoadModule("AcEPlotx.arx", false, false); } HINSTANCE hInst = NULL; hInst = ::GetModuleHandle("AcEPlotX.arx"); ASSERT(NULL != hInst); if ((hInst)) { ACGLOBADDDMMREACTOR pAcGlobalAddDMMReactor = NULL; pAcGlobalAddDMMReactor = (ACGLOBADDDMMREACTOR)GetProcAddress(hInst, _T("AcGlobAddDMMReactor")); ASSERT(NULL != pAcGlobalAddDMMReactor); if (NULL != pAcGlobalAddDMMReactor) { ASSERT(NULL == g_pDMMReactor); g_pDMMReactor = new TdDMMReactor(); pAcGlobalAddDMMReactor(g_pDMMReactor); } } // here is where we will load the BLK file (if one is configured) AcNameValuePairVec valuePairVec; // Invalid value test. if (invalidTest == true) { AcNameValuePair nameValuePair100(_T("!@#$^%^*&*&%&*%"), _T("^$$&*%%_*^&*%&$%^")); } bool bIncludeBlockInfo = false; CString csIncludeBlockInfo; CString csBlockTmplFilePath; valuePairVec = pInfo->GetPrivateData("AutoCAD Block Data"); AcNameValuePairVec::const_iterator iter = valuePairVec.begin(); while (iter != valuePairVec.end()) { AcNameValuePair pair = (*iter++); CString csName = pair.name(); CString csValue = pair.value(); if (csName == _T("IncludeBlockInfo")) if (csValue == "1") bIncludeBlockInfo = true; else bIncludeBlockInfo = false; if (csName == _T("BlockTmplFilePath")) csBlockTmplFilePath = csValue; } if (bIncludeBlockInfo && !csBlockTmplFilePath.IsEmpty()) { // verify that the file exists? g_pDxServices = new CCW_AcPublishMgdServices(csBlockTmplFilePath); g_bIncludeBlockInfo = true; } else g_bIncludeBlockInfo = false; // WritePrivateSection() AcNameValuePairVec valuePairVec1; //AcNameValuePair nameValuePair(_T("Partha_JobBegin_Private_Name"), _T("Partha_JobBegin_Private_Value")); AcNameValuePair nameValuePair; //AcNameValuePair::SetName() nameValuePair.setName(_T("Partha_JobBegin_Private_Name")); //AcNameValuePair::SetValue() nameValuePair.setValue(_T("Partha_JobBegin_Private_Value")); //AcNameValuePair::name() if (strcmp(nameValuePair.name(), _T("Partha_JobBegin_Private_Name")) == 0) myPrintf("\nPassed: AcNameValuePair::name() returned correct name", OUTFILE); else myPrintf("\nFailed: AcNameValuePair::name() did not return correct name", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcNameValuePair::name()"); //AcNameValuePair::value() if (strcmp(nameValuePair.name(), _T("Partha_JobBegin_Private_Name")) == 0) myPrintf("\nPassed: AcNameValuePair::name() returned correct name", OUTFILE); else myPrintf("\nFailed: AcNameValuePair::name() did not return correct name", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcNameValuePair::name()"); //AcNameValuePair::= operator AcNameValuePair nameValuePair1 = nameValuePair; //AcNameValuePair::AcNameValuePair(const AcNameValuePair &src) AcNameValuePair nameValuePair2(nameValuePair1); valuePairVec1.push_back(nameValuePair2); pInfo->WritePrivateSection(_T("Partha JobBegin Private Data"), valuePairVec1); // Invalid value test. if (invalidTest == true) { AcNameValuePairVec valuePairVec100; pInfo->WritePrivateSection(_T("^$$^^"), valuePairVec100); } //JobWillPublishInBackground bool ret = pInfo->JobWillPublishInBackground(); if (ret == true) myPrintf("\nPassed: AcPublishBeginJobInfo::JobWillPublishInBackground(), publishing background.", OUTFILE); else myPrintf("\nPassed: AcPublishBeginJobInfo::JobWillPublishInBackground(), publishing foreground.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcPublishBeginJobInfo::JobWillPublishInBackground()"); } void TdPublishReactor::OnAboutToEndPublishing(AcPublishReactorInfo *pInfo) //#9 { if (B3 == false) { myPrintf("\nTdPublishReactor::OnAboutToEndPublishing", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); B3 = true; } //cleaning up DMMReactor if (NULL != g_pDMMReactor) { HINSTANCE hInst0 = ::GetModuleHandle("AcEPlotX.arx"); if ((hInst0)) { ACGLOBREMOVEDMMREACTOR pAcGlobalRemoveDMMReactor = (ACGLOBREMOVEDMMREACTOR)GetProcAddress(hInst0, "AcGlobRemoveDMMReactor"); ASSERT(NULL != pAcGlobalRemoveDMMReactor); if (NULL != pAcGlobalRemoveDMMReactor) pAcGlobalRemoveDMMReactor(g_pDMMReactor); else AfxMessageBox("\nFailed to remove DMMReactor to the Manager."); g_pDMMReactor = NULL; } } // dwfFileName() const char* fileName = pInfo->dwfFileName(); if (strcmp(fileName, "") == 0) myPrintf("\nFailed: AcPublishReactorInfo::dwfFileName(), failed to get the DWF file name.", OUTFILE); else myPrintf("\nPassed: AcPublishReactorInfo::dwfFileName(), got the DWF file name.", OUTFILE); // tempDwfFileName() const char* tempFileName = pInfo->tempDwfFileName(); if (strcmp(tempFileName, "") == 0) myPrintf("\nFailed: AcPublishReactorInfo::tempDwfFileName(), failed to get the temporary DWF file name.", OUTFILE); else myPrintf("\nPassed: AcPublishReactorInfo::tempDwfFileName(), got the temporary DWF file name.", OUTFILE); // dwfPassword() const char* dwfPassword = pInfo->dwfPassword(); if (strcmp(dwfPassword, "") == 0) myPrintf("\nPassed: AcPublishReactorInfo::dwfPassword(), there is no password for this DWF file.", OUTFILE); else myPrintf("\nPassed: AcPublishReactorInfo::dwfPassword(), got the DWF file password.", OUTFILE); // getUnrecognizedDSDData() AcArray<char*>* urSectionArray; AcArray<char*>* urDataArray; pInfo->getUnrecognizedDSDData(urSectionArray, urDataArray); int len = urSectionArray->length(); char* section; char* data; CString str; myPrintf("\nPassed:UnRecognized DSD data:", OUTFILE); for (int i=0; i<len; i++) { section = urSectionArray->at(i); data = urDataArray->at(i); str.Format("\n\tSection = %s: Data = %s", section, data); myPrintf(str, OUTFILE); } if (pInfo->isMultiSheetDwf()) myPrintf("\nPassed: It's a Multisheet DWF file.", OUTFILE); else myPrintf("\nPassed: It's a Single DWF file.", OUTFILE); } void TdPublishReactor::OnAboutToMoveFile(AcPublishReactorInfo *pInfo) //#8 { if (B4 == false) { myPrintf("\nTdPublishReactor::OnAboutToMoveFile", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); B4 = true; } } void TdPublishReactor::OnBeginAggregation(AcPublishAggregationInfo *pInfo) //#7 { if (B5 == false) { myPrintf("\nTdPublishReactor::OnBeginAggregation", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nTdPublishReactor::OnBeginAggregation"); B5 = true; } // addGlobalProperties() AcDMMEPlotProperty prop(L"Partha_Global_Property", L"Partha_Global_Value"); AcDMMEPlotPropertyVec propVec; propVec.push_back(prop); pInfo->AddGlobalProperties(propVec); myPrintf("\nAcPublishAggregationInfo::AddGlobalProperties(), added global properties.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcPublishAggregationInfo::AddGlobalProperties()"); // Invalid value test. if (invalidTest == true) { AcDMMEPlotPropertyVec vec100; pInfo->AddGlobalProperties(vec100); } // addGlobalResources() AcDMMResourceInfo res(L"Partha_Global_Resource", L"Partha", L"C:\\Current Project\\DWFAPI\\DWFs\\Volcano_lava.JPG"); AcDMMResourceVec resVec; resVec.push_back(res); pInfo->AddGlobalResources(resVec); myPrintf("\nAcPublishAggregationInfo::AddGlobalResources(), added global resources.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcPublishAggregationInfo::AddGlobalResources()"); // Invalid value test. if (invalidTest == true) { AcDMMResourceVec res100; pInfo->AddGlobalResources(res100); } // dwfFileName() const char* fileName = pInfo->dwfFileName(); if (strcmp(fileName, "") == 0) myPrintf("\nFailed: AcPublishAggregationInfo::dwfFileName(), failed to get the DWF file name.", OUTFILE); else myPrintf("\nPassed: AcPublishAggregationInfo::dwfFileName(), got the DWF file name.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcPublishAggregationInfo::dwfFileName()"); // tempDwfFileName() const char* tempFileName = pInfo->tempDwfFileName(); // DID #605461: the call returns NULL and crash gere. // uncomment when the bug is fixed. //if (strcmp(tempFileName, "") == 0) // myPrintf("\nFailed: AcPublishAggregationInfo::tempDwfFileName(), failed to get the temporary DWF file name.", OUTFILE); //else // myPrintf("\nPassed: AcPublishAggregationInfo::tempDwfFileName(), got the temporary DWF file name.", OUTFILE); // dwfPassword() const char* dwfPassword = pInfo->dwfPassword(); if (strcmp(dwfPassword, "") == 0) myPrintf("\nPassed: AcPublishAggregationInfo::dwfPassword(), there is no password for this DWF file.", OUTFILE); else myPrintf("\nPassed: AcPublishAggregationInfo::dwfPassword(), got the DWF file password.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcPublishAggregationInfo::dwfPassword()"); } void TdPublishReactor::OnBeginPublishingSheet(AcPublishSheetInfo *pInfo) //#2 { if (B6 == false) { myPrintf("\nTdPublishReactor::OnBeginPublishingSheet", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nTdPublishReactor::OnBeginPublishingSheet"); B6 = true; } // check to see if this job is publishing to DWF // GetDSDEntity(). const AcPlDSDEntry* pEntity = pInfo->GetDSDEntry(); if (pEntity != NULL) if ((strcmp(pEntity->dwgName(), "") != 0) && (strcmp(pEntity->layout(), "") != 0)) myPrintf("\nPassed: AcPublishSheetInfo::GetDSDEntry(): return DSD entity /w valid DWG name and layout name.", OUTFILE); else myPrintf("\nFailed: AcPublishSheetInfo::GetDSDEntry(): return DSD entity but failed to return valid DWG name and layout name.", OUTFILE); else myPrintf("\nFailed: AcPublishSheetInfo::GetDSDEntry(): failed to return DSD entity for the sheet.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcPublishSheetInfo::GetDSDEntry()"); // GetUniqueId() const char* uniqueId = pInfo->GetUniqueId(); if (strcmp(uniqueId, "") == 0) myPrintf("\nFailed: AcPublishSheetInfo::GetUniqueId(), failed to get the unique ID.", OUTFILE); else myPrintf("\nPassed: AcPublishSheetInfo::GetUniqueId(), got the unique ID.", OUTFILE); pInfo->GetPlotLogger()->logMessage("\nAcPublishSheetInfo::GetUniqueId()"); } void TdPublishReactor::OnCancelledOrFailedPublishing(AcPublishReactorInfo *pInfo) { if (B7 == false) { myPrintf("\nTdPublishReactor::OnCancelledOrFailedPublishing", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); B7 = true; } // Cleaning up all reactors. //DMMReactor if (NULL != g_pDMMReactor) { HINSTANCE hInst0 = ::GetModuleHandle("AcEPlotX.arx"); if ((hInst0)) { ACGLOBREMOVEDMMREACTOR pAcGlobalRemoveDMMReactor = (ACGLOBREMOVEDMMREACTOR)GetProcAddress(hInst0, "AcGlobRemoveDMMReactor"); ASSERT(NULL != pAcGlobalRemoveDMMReactor); if (NULL != pAcGlobalRemoveDMMReactor) pAcGlobalRemoveDMMReactor(g_pDMMReactor); else AfxMessageBox("\nFailed to remove DMMReactor to the Manager."); g_pDMMReactor = NULL; } } } void TdPublishReactor::OnEndPublish(AcPublishReactorInfo *pInfo) //#10 { if (B8 == false) { myPrintf("\nTdPublishReactor::OnEndPublish", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); B8 = true; } } // TdPublishUIReactor class implementation TdPublishUIReactor::TdPublishUIReactor() { C1=false; } TdPublishUIReactor::~TdPublishUIReactor() { C1=false; } void TdPublishUIReactor::OnInitPublishOptionsDialog(IUnknown **pUnk, AcPublishUIReactorInfo *pInfo) { if (C1 == false) { myPrintf("\nTdPublishUIReactor::OnInitPublishOptionsDialog", OUTFILE); myPrintf("\n------------------------------------\n", OUTFILE); C1 = true; } // check to see if this job is publishing to DWF // GetDSDData(). if (pInfo->GetDSDData()->sheetType() == AcPlDSDEntry::SheetType::kOriginalDevice) // not a DWF job, nothing to do here return; // WritePrivateSection() AcNameValuePairVec valuePairVec1; AcNameValuePair nameValuePair1(_T("Partha_PublishOption_Private_Name1"), _T("Partha_PublishOption_Private_Value1")); // Invalid value test. if (invalidTest == true) { AcNameValuePair nameValuePair100(_T("!@#$^%^*&*&%&*%"), _T("^$$&*%%_*^&*%&$%^")); } valuePairVec1.push_back(nameValuePair1); pInfo->WritePrivateSection(_T("Partha PublishOption Private Data1"), valuePairVec1); AcNameValuePairVec valuePairVec2; AcNameValuePair nameValuePair2(_T("Partha_PublishOption_Private_Name2"), _T("Partha_PublishOption_Private_Value2")); valuePairVec2.push_back(nameValuePair2); pInfo->WritePrivateSection(_T("Partha PublishOption Private Data2"), valuePairVec2); AcNameValuePairVec valuePairVec3; AcNameValuePair nameValuePair3(_T("Partha_PublishOption_Private_Name3"), _T("Partha_PublishOption_Private_Value3")); valuePairVec3.push_back(nameValuePair3); pInfo->WritePrivateSection(_T("Partha PublishOption Private Data3"), valuePairVec3); // get the a specific data and change it. const AcNameValuePairVec pPairVec = pInfo->GetPrivateData(_T("Partha PublishOption Private Data2")); // Invalid value test. if (invalidTest == true) { AcNameValuePair nameValuePair100(_T("!@#$^%^*&*&%&*%"), _T("^$$&*%%_*^&*%&$%^")); } int size = pPairVec.size(); for (int i = 0; i < size; i++) { CString name, value, str; AcNameValuePair pPair = pPairVec.at(i); name = pPair.name(); value = pPair.value(); str = "\nPassed: Name-Value of the private 2nd private data written is " + name + "," + value; myPrintf(str, OUTFILE); } // add a new property in the publish-options dialog. //CComPtr<IPropertyManager2> pPropMan; //(*pUnk)->QueryInterface(IID_IPropertyManager2, (void **)&pPropMan); //JobWillPublishInBackground bool ret = pInfo->JobWillPublishInBackground(); if (ret == true) myPrintf("\nPassed: AcPublishUIReactorInfo::JobWillPublishInBackground(), publishing background.", OUTFILE); else myPrintf("\nPassed: AcPublishUIReactorInfo::JobWillPublishInBackground(), publishing foreground.", OUTFILE); } /* //prepared for DevDays PPT. At run time enable above code and disable following code void AcTestDMMEntReactor:: OnBeginEntity(AcDMMEntityReactorInfo * pInfo) { int nNodeId = 0; bool bRet = pInfo->GetEntityNode(pInfo->entity()->objectId(),0, nNodeId); if (!bRet) { //step1: Detect your entity AcDbEntity* pEntity = pInfo->entity(); //step2: container for object's metadata AcDMMEPlotProperties props; //step3: Assume we want to get the handle of object and publish same as metadata AcDMMEPlotProperty * entityProp1 = new AcDMMEPlotProperty(L"Handle", locale_to_wchar(m_EntGenralPorps.m_chHandle)); entityProp1->SetCategory(L"DMMAPI"); //step4:Add each of AcDMMEPlotProperty objects to the AcDMMEPlotProperties props.AddProperty(entityProp1); //step5:Generate a unique ID, Assign same ID to props const wchar_t * wsUnique = pInfo->UniqueEntityId(); AcDMMWideString wsPropId; // need a unique string id for properties wsPropId = L"ACAD"; //application name (optional) wsPropId += wsUnique; delete wsUnique; props.SetId(PCWIDESTR(wsPropId)); pInfo->AddProperties(&props); //step6:To associate the metadata to a graphic object we need NodeId: int nodeId = pInfo->GetNextAvailableNodeId(); // create a Node for this entity AcDMMNode node(nodeId, L"dummy"); AcDMMStringVec IdVec; IdVec.push_back(wsPropId); //step7: assign node to entity bRet = pInfo->AddNodeToMap(pEntity->objectId(), 0, nodeId); // step8: Now associate your properties with this node by calling AddPropertiesIds() pInfo->AddPropertiesIds(&IdVec, node); } } */ void AcTestDMMEntReactor::ProcessBlocks(AcDMMEntityReactorInfo * pInfo) { AcDbEntity* pEntity = pInfo->entity(); AcDbObjectId objId = pEntity->objectId(); long oldId = objId.asOldId(); bool bret; //unsigned long front = 0; AcDbObjectIdArray objectIds; if (pEntity->isKindOf(AcDbBlockReference::desc())) // block { pInfo->GetPlotLogger()->logMessage("\nBlock FOUND, assigning metadata properties to it"); // Add the object Id to the objectIds array. objectIds.append(objId); // get the block name. AcDbBlockReference* pBlkRef = 0; const char* blkName = 0; if(acdbOpenObject(pBlkRef, objId, AcDb::kForRead) == Acad::eOk) { AcDbBlockTableRecord* pTblRec = 0; if(acdbOpenObject(pTblRec, pBlkRef->blockTableRecord(), AcDb::kForRead) == Acad::eOk) { pTblRec->getName(blkName); pTblRec->close(); } pBlkRef->close(); } g_entIdVec.push_back(oldId); //front = g_entIdVec.front(); AcDMMEPlotPropertyVec propVec; // FIRST SET OF PROPERTIES. AcDMMEPlotProperties props; //add properties to prop objects. AcDMMEPlotPropertyVec::const_iterator iter = propVec.begin(); // get all the standard meta properties and write them in the new // property collection. while (iter != propVec.end()) { AcDMMEPlotProperty prop = (*iter++); props.AddProperty(&prop); } // write a custom property. AcDMMEPlotProperty prop1(L"TestProperty", L"TestValue"); prop1.SetType(L"string"); USES_CONVERSION; if (blkName != "") prop1.SetCategory(A2W(blkName)); else prop1.SetCategory(L"Custom Catagory1"); props.AddProperty(&prop1); const wchar_t* wsUnique = pInfo->UniqueEntityId(); //step5:Generate a unique ID, Assign same ID to props AcDMMWideString wsPropId; // need a unique string id for properties wsPropId = L"ACAD"; wsPropId += wsUnique; delete wsUnique; props.SetId(PCWIDESTR(wsPropId)); pInfo->AddProperties(&props); // add props obj to cache // string Vector AcDMMStringVec IdVec; IdVec.push_back(wsPropId); int nodeId = 0; const AcDMMNode* node; // check to see if this node already assigned if(!pInfo->GetEntityNode(objId, objectIds, nodeId)) { // create a node for this entity. nodeId = pInfo->GetNextAvailableNodeId(); node = new AcDMMNode(nodeId, L"PARTHA"); bret = pInfo->AddNodeToMap(objId, 0, nodeId); ASSERT(bret); g_NodeStack.push(nodeId); // associate the properties with the node. bret = pInfo->AddPropertiesIds(&IdVec, (AcDMMNode &)*node); } } }
34.436771
141
0.691821
kevinzhwl
03aa9ba8720287b2efda4aa8189528cca5319153
6,958
hpp
C++
ocs2_thirdparty/include/cppad/local/optimize/get_op_previous.hpp
grizzi/ocs2
4b78c4825deb8b2efc992fdbeef6fdb1fcca2345
[ "BSD-3-Clause" ]
126
2021-07-13T13:59:12.000Z
2022-03-31T02:52:18.000Z
ocs2_thirdparty/include/cppad/local/optimize/get_op_previous.hpp
grizzi/ocs2
4b78c4825deb8b2efc992fdbeef6fdb1fcca2345
[ "BSD-3-Clause" ]
27
2021-07-14T12:14:04.000Z
2022-03-30T16:27:52.000Z
ocs2_thirdparty/include/cppad/local/optimize/get_op_previous.hpp
grizzi/ocs2
4b78c4825deb8b2efc992fdbeef6fdb1fcca2345
[ "BSD-3-Clause" ]
55
2021-07-14T07:08:47.000Z
2022-03-31T15:54:30.000Z
# ifndef CPPAD_LOCAL_OPTIMIZE_GET_OP_PREVIOUS_HPP # define CPPAD_LOCAL_OPTIMIZE_GET_OP_PREVIOUS_HPP /* -------------------------------------------------------------------------- CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-18 Bradley M. Bell CppAD is distributed under the terms of the Eclipse Public License Version 2.0. This Source Code may also be made available under the following Secondary License when the conditions for such availability set forth in the Eclipse Public License, Version 2.0 are satisfied: GNU General Public License, Version 2.0 or later. ---------------------------------------------------------------------------- */ /*! \file get_cexp_info.hpp Create operator information tables */ # include <cppad/local/optimize/match_op.hpp> # include <cppad/local/optimize/usage.hpp> // BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE namespace CppAD { namespace local { namespace optimize { /*! Get mapping from each variable to a previous variable that can be used to replace it (if one exists). \tparam Base base type for the operator; i.e., this operation was recorded using AD< Base > and computations by this routine are done using type Base. \param play This is the old operation sequence. \param random_itr This is a random iterator for the old operation sequence. \param cexp_set set[i] is a set of elements for the i-th operator. Suppose that e is an element of set[i], j = e / 2, k = e % 2. If the comparision for the j-th conditional expression is equal to bool(k), the i-th operator can be skipped (is not used by any of the results). Note the the j indexs the CExpOp operators in the operation sequence. On input, cexp_set is does not count previous optimization. On output, it does count previous optimization. \param op_previous The input size of this vector must be zero. Upon return it has size equal to the number of operators in the operation sequence; i.e., num_op = play->nun_var_rec(). Let j = op_previous[i]. It j = 0, no replacement was found for i-th operator. Otherwise, j < i, op_previous[j] == 0, op_usage[j] == usage_t(yes_usage), i-th operator has NumArg(op) <= 3, 0 < NumRes(op), is not one of the following: - PriOp, ParOp, InvOp, EndOp, CexpOp, BeginOp. - it is not one of the load store op LtpvOp, LtvpOp, LtvvOp, StppOp, StpvOp, StvpOp, StvvOp. - it is not a atomic function fucntion op AFunOp, FunapOp, FunavOp, FunrpOp, FunrvOp. \param op_usage The size of this vector is the number of operators in the operation sequence.i.e., play->nun_var_rec(). On input, op_usage[i] is the usage for the i-th operator in the operation sequence not counting previous optimization. On output, it is the usage counting previous operator optimization. */ template <class Addr, class Base> void get_op_previous( const player<Base>* play , const play::const_random_iterator<Addr>& random_itr , sparse_list& cexp_set , pod_vector<addr_t>& op_previous , pod_vector<usage_t>& op_usage ) { // number of operators in the tape const size_t num_op = random_itr.num_op(); CPPAD_ASSERT_UNKNOWN( op_previous.size() == 0 ); CPPAD_ASSERT_UNKNOWN( op_usage.size() == num_op ); op_previous.resize( num_op ); // // number of conditional expressions in the tape // // initialize mapping from variable index to operator index CPPAD_ASSERT_UNKNOWN( size_t( std::numeric_limits<addr_t>::max() ) >= num_op ); // ---------------------------------------------------------------------- // compute op_previous // ---------------------------------------------------------------------- sparse_list hash_table_op; hash_table_op.resize(CPPAD_HASH_TABLE_SIZE, num_op); // pod_vector<bool> work_bool; pod_vector<addr_t> work_addr_t; for(size_t i_op = 0; i_op < num_op; ++i_op) { op_previous[i_op] = 0; if( op_usage[i_op] == usage_t(yes_usage) ) switch( random_itr.get_op(i_op) ) { // ---------------------------------------------------------------- // these operators never match pevious operators case BeginOp: case CExpOp: case CSkipOp: case CSumOp: case EndOp: case InvOp: case LdpOp: case LdvOp: case ParOp: case PriOp: case StppOp: case StpvOp: case StvpOp: case StvvOp: case AFunOp: case FunapOp: case FunavOp: case FunrpOp: case FunrvOp: break; // ---------------------------------------------------------------- // check for a previous match case AbsOp: case AcosOp: case AcoshOp: case AddpvOp: case AddvvOp: case AsinOp: case AsinhOp: case AtanOp: case AtanhOp: case CosOp: case CoshOp: case DisOp: case DivpvOp: case DivvpOp: case DivvvOp: case EqpvOp: case EqvvOp: case ErfOp: case ExpOp: case Expm1Op: case LepvOp: case LevpOp: case LevvOp: case LogOp: case Log1pOp: case LtpvOp: case LtvpOp: case LtvvOp: case MulpvOp: case MulvvOp: case NepvOp: case NevvOp: case PowpvOp: case PowvpOp: case PowvvOp: case SignOp: case SinOp: case SinhOp: case SqrtOp: case SubpvOp: case SubvpOp: case SubvvOp: case TanOp: case TanhOp: case ZmulpvOp: case ZmulvpOp: case ZmulvvOp: match_op( random_itr, op_previous, i_op, hash_table_op, work_bool, work_addr_t ); if( op_previous[i_op] != 0 ) { // like a unary operator that assigns i_op equal to previous. size_t previous = size_t( op_previous[i_op] ); bool sum_op = false; CPPAD_ASSERT_UNKNOWN( previous < i_op ); op_inc_arg_usage( play, sum_op, i_op, previous, op_usage, cexp_set ); } break; // ---------------------------------------------------------------- default: CPPAD_ASSERT_UNKNOWN(false); break; } } } } } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE # endif
33.291866
79
0.542828
grizzi
03aeca585a9a5164b117f7f9af56071cb43c1513
22,291
cpp
C++
agent/config.cpp
markovchainz/cppagent
97314ec43786a90697ca7fda15db13f2973aee3e
[ "Apache-2.0" ]
null
null
null
agent/config.cpp
markovchainz/cppagent
97314ec43786a90697ca7fda15db13f2973aee3e
[ "Apache-2.0" ]
null
null
null
agent/config.cpp
markovchainz/cppagent
97314ec43786a90697ca7fda15db13f2973aee3e
[ "Apache-2.0" ]
null
null
null
/* * Copyright Copyright 2012, System Insights, Inc. * * 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. */ #include "config.hpp" #include "agent.hpp" #include "options.hpp" #include "device.hpp" #include "xml_printer.hpp" #include <iostream> #include <sstream> #include <fstream> #include <vector> #include <dlib/config_reader.h> #include <dlib/logger.h> #include <stdexcept> #include <algorithm> #include <sys/stat.h> #include "rolling_file_logger.hpp" using namespace std; using namespace dlib; static logger sLogger("init.config"); static inline const char *get_with_default(const config_reader::kernel_1a &reader, const char *aKey, const char *aDefault) { if (reader.is_key_defined(aKey)) return reader[aKey].c_str(); else return aDefault; } static inline int get_with_default(const config_reader::kernel_1a &reader, const char *aKey, int aDefault) { if (reader.is_key_defined(aKey)) return atoi(reader[aKey].c_str()); else return aDefault; } static inline const string &get_with_default(const config_reader::kernel_1a &reader, const char *aKey, const string &aDefault) { if (reader.is_key_defined(aKey)) return reader[aKey]; else return aDefault; } static inline bool get_bool_with_default(const config_reader::kernel_1a &reader, const char *aKey, bool aDefault) { if (reader.is_key_defined(aKey)) return reader[aKey] == "true" || reader[aKey] == "yes"; else return aDefault; } AgentConfiguration::AgentConfiguration() : mAgent(NULL), mLoggerFile(NULL), mMonitorFiles(false), mRestart(false), mMinimumConfigReloadAge(15) { } void AgentConfiguration::initialize(int aArgc, const char *aArgv[]) { MTConnectService::initialize(aArgc, aArgv); const char *configFile = "agent.cfg"; OptionsList optionList; optionList.append(new Option(0, configFile, "The configuration file", "file", false)); optionList.parse(aArgc, (const char**) aArgv); mConfigFile = configFile; try { ifstream file(mConfigFile.c_str()); loadConfig(file); } catch (std::exception & e) { sLogger << LFATAL << "Agent failed to load: " << e.what(); cerr << "Agent failed to load: " << e.what() << std::endl; optionList.usage(); } } AgentConfiguration::~AgentConfiguration() { if (mAgent != NULL) delete mAgent; if (mLoggerFile != NULL) delete mLoggerFile; set_all_logging_output_streams(cout); } void AgentConfiguration::monitorThread() { struct stat devices_at_start, cfg_at_start; if (stat(mConfigFile.c_str(), &cfg_at_start) != 0) sLogger << LWARN << "Cannot stat config file: " << mConfigFile << ", exiting monitor"; if (stat(mDevicesFile.c_str(), &devices_at_start) != 0) sLogger << LWARN << "Cannot stat devices file: " << mDevicesFile << ", exiting monitor"; sLogger << LDEBUG << "Monitoring files: " << mConfigFile << " and " << mDevicesFile << ", will warm start if they change."; bool changed = false; // Check every 10 seconds do { dlib::sleep(10000); struct stat devices, cfg; bool check = true; if (stat(mConfigFile.c_str(), &cfg) != 0) { sLogger << LWARN << "Cannot stat config file: " << mConfigFile << ", retrying in 10 seconds"; check = false; } if (stat(mDevicesFile.c_str(), &devices) != 0) { sLogger << LWARN << "Cannot stat devices file: " << mDevicesFile << ", retrying in 10 seconds"; check = false; } // Check if the files have changed. if (check && (cfg_at_start.st_mtime != cfg.st_mtime || devices_at_start.st_mtime != devices.st_mtime)) { time_t now = time(NULL); sLogger << LWARN << "Dected change in configuarion files. Will reload when youngest file is at least " << mMinimumConfigReloadAge <<" seconds old"; sLogger << LWARN << " Devices.xml file modified " << (now - devices.st_mtime) << " seconds ago"; sLogger << LWARN << " ...cfg file modified " << (now - cfg.st_mtime) << " seconds ago"; changed = (now - cfg.st_mtime) > mMinimumConfigReloadAge && (now - devices.st_mtime) > mMinimumConfigReloadAge; } } while (!changed && mAgent->is_running()); // Restart agent if changed... // stop agent and signal to warm start if (mAgent->is_running() && changed) { sLogger << LWARN << "Monitor thread has detected change in configuration files, restarting agent."; mRestart = true; mAgent->clear(); delete mAgent; mAgent = NULL; sLogger << LWARN << "Monitor agent has completed shutdown, reinitializing agent."; // Re initialize const char *argv[] = { mConfigFile.c_str() }; initialize(1, argv); } sLogger << LDEBUG << "Monitor thread is exiting"; } void AgentConfiguration::start() { auto_ptr<dlib::thread_function> mon; do { mRestart = false; if (mMonitorFiles) { // Start the file monitor to check for changes to cfg or devices. sLogger << LDEBUG << "Waiting for monitor thread to exit to restart agent"; mon.reset(new dlib::thread_function(make_mfp(*this, &AgentConfiguration::monitorThread))); } mAgent->start(); if (mRestart && mMonitorFiles) { // Will destruct and wait to re-initialize. sLogger << LDEBUG << "Waiting for monitor thread to exit to restart agent"; mon.reset(0); sLogger << LDEBUG << "Monitor has exited"; } } while (mRestart); } void AgentConfiguration::stop() { mAgent->clear(); } Device *AgentConfiguration::defaultDevice() { const std::vector<Device*> &devices = mAgent->getDevices(); if (devices.size() == 1) return devices[0]; else return NULL; } static const char *timestamp(char *aBuffer) { #ifdef _WINDOWS SYSTEMTIME st; GetSystemTime(&st); sprintf(aBuffer, "%4d-%02d-%02dT%02d:%02d:%02d.%04dZ", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); #else struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz); strftime(aBuffer, 64, "%Y-%m-%dT%H:%M:%S", gmtime(&tv.tv_sec)); sprintf(aBuffer + strlen(aBuffer), ".%06dZ", (int) tv.tv_usec); #endif return aBuffer; } void AgentConfiguration::LoggerHook(const std::string& aLoggerName, const dlib::log_level& l, const dlib::uint64 aThreadId, const char* aMessage) { stringstream out; char buffer[64]; timestamp(buffer); out << buffer << ": " << l.name << " [" << aThreadId << "] " << aLoggerName << ": " << aMessage; #ifdef WIN32 out << "\r\n"; #else out << "\n"; #endif if (mLoggerFile != NULL) mLoggerFile->write(out.str().c_str()); else cout << out.str(); } static dlib::log_level string_to_log_level ( const std::string& level ) { using namespace std; if (level == "LALL" || level == "ALL" || level == "all") return LALL; else if (level == "LNONE" || level == "NONE" || level == "none") return LNONE; else if (level == "LTRACE" || level == "TRACE" || level == "trace") return LTRACE; else if (level == "LDEBUG" || level == "DEBUG" || level == "debug") return LDEBUG; else if (level == "LINFO" || level == "INFO" || level == "info") return LINFO; else if (level == "LWARN" || level == "WARN" || level == "warn") return LWARN; else if (level == "LERROR" || level == "ERROR" || level == "error") return LERROR; else if (level == "LFATAL" || level == "FATAL" || level == "fatal") return LFATAL; else { return LINFO; } } void AgentConfiguration::configureLogger(dlib::config_reader::kernel_1a &aReader) { if (mLoggerFile != NULL) delete mLoggerFile; if (mIsDebug) { set_all_logging_output_streams(cout); set_all_logging_levels(LDEBUG); } else { string name("agent.log"); RollingFileLogger::RollingSchedule sched = RollingFileLogger::NEVER; int maxSize = 10 * 1024 * 1024; int maxIndex = 9; if (aReader.is_block_defined("logger_config")) { const config_reader::kernel_1a& cr = aReader.block("logger_config"); if (cr.is_key_defined("logging_level")) set_all_logging_levels(string_to_log_level(cr["logging_level"])); else set_all_logging_levels(LINFO); if (cr.is_key_defined("output")) { string output = cr["output"]; if (output == "cout") set_all_logging_output_streams(cout); else if (output == "cerr") set_all_logging_output_streams(cerr); else { istringstream sin(output); string one, two, three; sin >> one; sin >> two; sin >> three; if (one == "file" && three.size() == 0) name = two; else name = one; } } string maxSizeStr = get_with_default(cr, "max_size", "10M"); stringstream ss(maxSizeStr); char mag = '\0'; ss >> maxSize >> mag; switch(mag) { case 'G': case 'g': maxSize *= 1024; case 'M': case 'm': maxSize *= 1024; case 'K': case 'k': maxSize *= 1024; case 'B': case 'b': case '\0': break; } maxIndex = get_with_default(cr, "max_index", maxIndex); string schedCfg = get_with_default(cr, "schedule", "NEVER"); if (schedCfg == "DAILY") sched = RollingFileLogger::DAILY; else if (schedCfg == "WEEKLY") sched = RollingFileLogger::WEEKLY; } mLoggerFile = new RollingFileLogger(name, maxIndex, maxSize, sched); set_all_logging_output_hooks<AgentConfiguration>(*this, &AgentConfiguration::LoggerHook); } } inline static void trim(std::string &str) { size_t index = str.find_first_not_of(" \r\t"); if (index != string::npos && index > 0) str.erase(0, index); index = str.find_last_not_of(" \r\t"); if (index != string::npos) str.erase(index + 1); } void AgentConfiguration::loadConfig(std::istream &aFile) { // Now get our configuration config_reader::kernel_1a reader(aFile); if (mLoggerFile == NULL) configureLogger(reader); bool defaultPreserve = get_bool_with_default(reader, "PreserveUUID", true); int port = get_with_default(reader, "Port", 5000); string serverIp = get_with_default(reader, "ServerIp", ""); int bufferSize = get_with_default(reader, "BufferSize", DEFAULT_SLIDING_BUFFER_EXP); int maxAssets = get_with_default(reader, "MaxAssets", DEFAULT_MAX_ASSETS); int checkpointFrequency = get_with_default(reader, "CheckpointFrequency", 1000); int legacyTimeout = get_with_default(reader, "LegacyTimeout", 600); int reconnectInterval = get_with_default(reader, "ReconnectInterval", 10 * 1000); bool ignoreTimestamps = get_bool_with_default(reader, "IgnoreTimestamps", false); bool conversionRequired = get_bool_with_default(reader, "ConversionRequired", true); bool upcaseValue = get_bool_with_default(reader, "UpcaseDataItemValue", true); mMonitorFiles = get_bool_with_default(reader, "MonitorConfigFiles", false); mMinimumConfigReloadAge = get_with_default(reader, "MinimumConfigReloadAge", 15); mPidFile = get_with_default(reader, "PidFile", "agent.pid"); const char *probe; struct stat buf; if (reader.is_key_defined("Devices")) { probe = reader["Devices"].c_str(); if (stat(probe, &buf) != 0) { throw runtime_error(((string) "Please make sure the Devices XML configuration " "file " + probe + " is in the current path ").c_str()); } } else { probe = "probe.xml"; if (stat(probe, &buf) != 0) probe = "Devices.xml"; if (stat(probe, &buf) != 0) { throw runtime_error(((string) "Please make sure the configuration " "file probe.xml or Devices.xml is in the current " "directory or specify the correct file " "in the configuration file " + mConfigFile + " using Devices = <file>").c_str()); } } mDevicesFile = probe; mName = get_with_default(reader, "ServiceName", "MTConnect Agent"); // Check for schema version string schemaVersion = get_with_default(reader, "SchemaVersion", ""); if (!schemaVersion.empty()) XmlPrinter::setSchemaVersion(schemaVersion); sLogger << LINFO << "Starting agent on port " << port; if (mAgent == NULL) mAgent = new Agent(probe, bufferSize, maxAssets, checkpointFrequency); mAgent->set_listening_port(port); mAgent->set_listening_ip(serverIp); mAgent->setLogStreamData(get_bool_with_default(reader, "LogStreams", false)); for (size_t i = 0; i < mAgent->getDevices().size(); i++) mAgent->getDevices()[i]->mPreserveUuid = defaultPreserve; if (XmlPrinter::getSchemaVersion().empty()) XmlPrinter::setSchemaVersion("1.3"); loadAllowPut(reader); loadAdapters(reader, defaultPreserve, legacyTimeout, reconnectInterval, ignoreTimestamps, conversionRequired, upcaseValue); // Files served by the Agent... allows schema files to be served by // agent. loadFiles(reader); // Load namespaces, allow for local file system serving as well. loadNamespace(reader, "DevicesNamespaces", &XmlPrinter::addDevicesNamespace); loadNamespace(reader, "StreamsNamespaces", &XmlPrinter::addStreamsNamespace); loadNamespace(reader, "AssetsNamespaces", &XmlPrinter::addAssetsNamespace); loadNamespace(reader, "ErrorNamespaces", &XmlPrinter::addErrorNamespace); loadStyle(reader, "DevicesStyle", &XmlPrinter::setDevicesStyle); loadStyle(reader, "StreamsStyle", &XmlPrinter::setStreamStyle); loadStyle(reader, "AssetsStyle", &XmlPrinter::setAssetsStyle); loadStyle(reader, "ErrorStyle", &XmlPrinter::setErrorStyle); loadTypes(reader); } void AgentConfiguration::loadAdapters(dlib::config_reader::kernel_1a &aReader, bool aDefaultPreserve, int aLegacyTimeout, int aReconnectInterval, bool aIgnoreTimestamps, bool aConversionRequired, bool aUpcaseValue) { Device *device; if (aReader.is_block_defined("Adapters")) { const config_reader::kernel_1a &adapters = aReader.block("Adapters"); std::vector<string> blocks; adapters.get_blocks(blocks); std::vector<string>::iterator block; for (block = blocks.begin(); block != blocks.end(); ++block) { const config_reader::kernel_1a &adapter = adapters.block(*block); string deviceName; if (adapter.is_key_defined("Device")) { deviceName = adapter["Device"].c_str(); } else { deviceName = *block; } device = mAgent->getDeviceByName(deviceName); if (device == NULL) { sLogger << LWARN << "Cannot locate device name '" << deviceName << "', trying default"; device = defaultDevice(); if (device != NULL) { deviceName = device->getName(); sLogger << LINFO << "Assigning default device " << deviceName << " to adapter"; } } if (device == NULL) { sLogger << LWARN << "Cannot locate device name '" << deviceName << "', assuming dynamic"; } const string host = get_with_default(adapter, "Host", (string)"localhost"); int port = get_with_default(adapter, "Port", 7878); int legacyTimeout = get_with_default(adapter, "LegacyTimeout", aLegacyTimeout); int reconnectInterval = get_with_default(adapter, "ReconnectInterval", aReconnectInterval); sLogger << LINFO << "Adding adapter for " << deviceName << " on " << host << ":" << port; Adapter *adp = mAgent->addAdapter(deviceName, host, port, false, legacyTimeout); device->mPreserveUuid = get_bool_with_default(adapter, "PreserveUUID", aDefaultPreserve); // Add additional device information if (adapter.is_key_defined("UUID")) device->setUuid(adapter["UUID"]); if (adapter.is_key_defined("Manufacturer")) device->setManufacturer(adapter["Manufacturer"]); if (adapter.is_key_defined("Station")) device->setStation(adapter["Station"]); if (adapter.is_key_defined("SerialNumber")) device->setSerialNumber(adapter["SerialNumber"]); adp->setDupCheck(get_bool_with_default(adapter, "FilterDuplicates", adp->isDupChecking())); adp->setAutoAvailable(get_bool_with_default(adapter, "AutoAvailable", adp->isAutoAvailable())); adp->setIgnoreTimestamps(get_bool_with_default(adapter, "IgnoreTimestamps", aIgnoreTimestamps || adp->isIgnoringTimestamps())); adp->setConversionRequired(get_bool_with_default(adapter, "ConversionRequired", aConversionRequired)); adp->setRealTime(get_bool_with_default(adapter, "RealTime", false)); adp->setRelativeTime(get_bool_with_default(adapter, "RelativeTime", false)); adp->setReconnectInterval(reconnectInterval); adp->setUpcaseValue(get_bool_with_default(adapter, "UpcaseDataItemValue", aUpcaseValue)); if (adapter.is_key_defined("AdditionalDevices")) { istringstream devices(adapter["AdditionalDevices"]); string name; while (getline(devices, name, ',')) { size_t index = name.find_first_not_of(" \r\t"); if (index != string::npos && index > 0) name.erase(0, index); index = name.find_last_not_of(" \r\t"); if (index != string::npos) name.erase(index + 1); adp->addDevice(name); } } } } else if ((device = defaultDevice()) != NULL) { sLogger << LINFO << "Adding default adapter for " << device->getName() << " on localhost:7878"; Adapter *adp = mAgent->addAdapter(device->getName(), "localhost", 7878, false, aLegacyTimeout); adp->setIgnoreTimestamps(aIgnoreTimestamps || adp->isIgnoringTimestamps()); adp->setReconnectInterval(aReconnectInterval); device->mPreserveUuid = aDefaultPreserve; } else { throw runtime_error("Adapters must be defined if more than one device is present"); } } void AgentConfiguration::loadAllowPut(dlib::config_reader::kernel_1a &aReader) { bool putEnabled = get_bool_with_default(aReader, "AllowPut", false); mAgent->enablePut(putEnabled); string putHosts = get_with_default(aReader, "AllowPutFrom", ""); if (!putHosts.empty()) { istringstream toParse(putHosts); string putHost; do { getline(toParse, putHost, ','); trim(putHost); if (!putHost.empty()) { string ip; int n; for (n = 0; dlib::hostname_to_ip(putHost, ip, n) == 0 && ip == "0.0.0.0"; n++) ip = ""; if (!ip.empty()) { mAgent->enablePut(); mAgent->allowPutFrom(ip); } } } while (!toParse.eof()); } } void AgentConfiguration::loadNamespace(dlib::config_reader::kernel_1a &aReader, const char *aNamespaceType, NamespaceFunction *aCallback) { // Load namespaces, allow for local file system serving as well. if (aReader.is_block_defined(aNamespaceType)) { const config_reader::kernel_1a &namespaces = aReader.block(aNamespaceType); std::vector<string> blocks; namespaces.get_blocks(blocks); std::vector<string>::iterator block; for (block = blocks.begin(); block != blocks.end(); ++block) { const config_reader::kernel_1a &ns = namespaces.block(*block); if (*block != "m" && !ns.is_key_defined("Urn")) { sLogger << LERROR << "Name space must have a Urn: " << *block; } else { string location, urn; if (ns.is_key_defined("Location")) location = ns["Location"]; if (ns.is_key_defined("Urn")) urn = ns["Urn"]; (*aCallback)(urn, location, *block); if (ns.is_key_defined("Path") && !location.empty()) mAgent->registerFile(location, ns["Path"]); } } } } void AgentConfiguration::loadFiles(dlib::config_reader::kernel_1a &aReader) { if (aReader.is_block_defined("Files")) { const config_reader::kernel_1a &files = aReader.block("Files"); std::vector<string> blocks; files.get_blocks(blocks); std::vector<string>::iterator block; for (block = blocks.begin(); block != blocks.end(); ++block) { const config_reader::kernel_1a &file = files.block(*block); if (!file.is_key_defined("Location") || !file.is_key_defined("Path")) { sLogger << LERROR << "Name space must have a Location (uri) or Directory and Path: " << *block; } else { mAgent->registerFile(file["Location"], file["Path"]); } } } } void AgentConfiguration::loadStyle(dlib::config_reader::kernel_1a &aReader, const char *aDoc, StyleFunction *aFunction) { if (aReader.is_block_defined(aDoc)) { const config_reader::kernel_1a &doc = aReader.block(aDoc); if (!doc.is_key_defined("Location")) { sLogger << LERROR << "A style must have a Location: " << aDoc; } else { string location = doc["Location"]; aFunction(location); if (doc.is_key_defined("Path")) mAgent->registerFile(location, doc["Path"]); } } } void AgentConfiguration::loadTypes(dlib::config_reader::kernel_1a &aReader) { if (aReader.is_block_defined("MimeTypes")) { const config_reader::kernel_1a &types = aReader.block("MimeTypes"); std::vector<string> keys; types.get_keys(keys); std::vector<string>::iterator key; for (key = keys.begin(); key != keys.end(); ++key) { mAgent->addMimeType(*key, types[*key]); } } }
33.928463
135
0.636759
markovchainz
03af014a9d8ef72ced695c343c136bd7c4e82d97
13,959
cpp
C++
src/systemfonts.cpp
kevinushey/systemfonts
597f94f1cb55ba7693c5534638978924fa6a6394
[ "MIT" ]
null
null
null
src/systemfonts.cpp
kevinushey/systemfonts
597f94f1cb55ba7693c5534638978924fa6a6394
[ "MIT" ]
null
null
null
src/systemfonts.cpp
kevinushey/systemfonts
597f94f1cb55ba7693c5534638978924fa6a6394
[ "MIT" ]
null
null
null
#include <string> #include <R.h> #include <Rinternals.h> #include <R_ext/GraphicsEngine.h> #include "systemfonts.h" #include "utils.h" #include "FontDescriptor.h" // these functions are implemented by the platform ResultSet *getAvailableFonts(); ResultSet *findFonts(FontDescriptor *); FontDescriptor *findFont(FontDescriptor *); FontDescriptor *substituteFont(char *, char *); void resetFontCache(); // Default fonts based on browser behaviour #if defined _WIN32 #define SANS "Arial" #define SERIF "Times New Roman" #define MONO "Courier New" #elif defined __APPLE__ #define SANS "Helvetica" #define SERIF "Times" #define MONO "Courier" #else #define SANS "sans" #define SERIF "serif" #define MONO "mono" #endif bool locate_in_registry(const char *family, int italic, int bold, FontLoc& res) { FontReg& registry = get_font_registry(); if (registry.empty()) return false; auto search = registry.find(std::string(family)); if (search == registry.end()) { return false; } int index = bold ? (italic ? 3 : 1) : (italic ? 2 : 0); res.first = search->second[index].first; res.second = search->second[index].second; return true; } int locate_font(const char *family, int italic, int bold, char *path, int max_path_length) { FontLoc registry_match; if (locate_in_registry(family, italic, bold, registry_match)) { strncpy(path, registry_match.first.c_str(), max_path_length); return registry_match.second; } const char* resolved_family = family; if (strcmp_no_case(family, "") || strcmp_no_case(family, "sans")) { resolved_family = SANS; } else if (strcmp_no_case(family, "serif")) { resolved_family = SERIF; } else if (strcmp_no_case(family, "mono")) { resolved_family = MONO; } FontDescriptor font_desc(resolved_family, italic, bold); FontDescriptor* font_loc = findFont(&font_desc); int index; if (font_loc == NULL) { SEXP fallback_call = PROTECT(Rf_lang1(Rf_install("get_fallback"))); SEXP fallback = PROTECT(Rf_eval(fallback_call, sf_ns_env)); SEXP fallback_path = VECTOR_ELT(fallback, 0); strncpy(path, CHAR(STRING_ELT(fallback_path, 0)), max_path_length); index = INTEGER(VECTOR_ELT(fallback, 1))[0]; UNPROTECT(2); } else { strncpy(path, font_loc->path, max_path_length); index = font_loc->index; } delete font_loc; return index; } SEXP match_font(SEXP family, SEXP italic, SEXP bold) { char *path = new char[PATH_MAX+1]; path[PATH_MAX] = '\0'; int index = locate_font(Rf_translateCharUTF8(STRING_ELT(family, 0)), LOGICAL(italic)[0], LOGICAL(bold)[0], path, PATH_MAX); SEXP font = PROTECT(Rf_allocVector(VECSXP, 2)); SET_VECTOR_ELT(font, 0, Rf_mkString(path)); SET_VECTOR_ELT(font, 1, Rf_ScalarInteger(index)); SEXP names = PROTECT(Rf_allocVector(STRSXP, 2)); SET_STRING_ELT(names, 0, Rf_mkChar("path")); SET_STRING_ELT(names, 1, Rf_mkChar("index")); Rf_setAttrib(font, Rf_install("names"), names); delete[] path; UNPROTECT(2); return font; } SEXP system_fonts() { SEXP res = PROTECT(Rf_allocVector(VECSXP, 9)); SEXP cl = PROTECT(Rf_allocVector(STRSXP, 3)); SET_STRING_ELT(cl, 0, Rf_mkChar("tbl_df")); SET_STRING_ELT(cl, 1, Rf_mkChar("tbl")); SET_STRING_ELT(cl, 2, Rf_mkChar("data.frame")); Rf_classgets(res, cl); SEXP names = PROTECT(Rf_allocVector(STRSXP, 9)); SET_STRING_ELT(names, 0, Rf_mkChar("path")); SET_STRING_ELT(names, 1, Rf_mkChar("index")); SET_STRING_ELT(names, 2, Rf_mkChar("name")); SET_STRING_ELT(names, 3, Rf_mkChar("family")); SET_STRING_ELT(names, 4, Rf_mkChar("style")); SET_STRING_ELT(names, 5, Rf_mkChar("weight")); SET_STRING_ELT(names, 6, Rf_mkChar("width")); SET_STRING_ELT(names, 7, Rf_mkChar("italic")); SET_STRING_ELT(names, 8, Rf_mkChar("monospace")); setAttrib(res, Rf_install("names"), names); ResultSet* all_fonts = getAvailableFonts(); int n = all_fonts->n_fonts(); SEXP path = PROTECT(Rf_allocVector(STRSXP, n)); SEXP index = PROTECT(Rf_allocVector(INTSXP, n)); SEXP name = PROTECT(Rf_allocVector(STRSXP, n)); SEXP family = PROTECT(Rf_allocVector(STRSXP, n)); SEXP style = PROTECT(Rf_allocVector(STRSXP, n)); SEXP fct_cl = PROTECT(Rf_allocVector(STRSXP, 2)); SET_STRING_ELT(fct_cl, 0, Rf_mkChar("ordered")); SET_STRING_ELT(fct_cl, 1, Rf_mkChar("factor")); SEXP weight = PROTECT(Rf_allocVector(INTSXP, n)); SEXP weight_lvl = PROTECT(Rf_allocVector(STRSXP, 9)); SET_STRING_ELT(weight_lvl, 0, Rf_mkChar("thin")); SET_STRING_ELT(weight_lvl, 1, Rf_mkChar("ultralight")); SET_STRING_ELT(weight_lvl, 2, Rf_mkChar("light")); SET_STRING_ELT(weight_lvl, 3, Rf_mkChar("normal")); SET_STRING_ELT(weight_lvl, 4, Rf_mkChar("medium")); SET_STRING_ELT(weight_lvl, 5, Rf_mkChar("semibold")); SET_STRING_ELT(weight_lvl, 6, Rf_mkChar("bold")); SET_STRING_ELT(weight_lvl, 7, Rf_mkChar("ultrabold")); SET_STRING_ELT(weight_lvl, 8, Rf_mkChar("heavy")); Rf_classgets(weight, fct_cl); Rf_setAttrib(weight, Rf_install("levels"), weight_lvl); SEXP width = PROTECT(Rf_allocVector(INTSXP, n)); SEXP width_lvl = PROTECT(Rf_allocVector(STRSXP, 9)); SET_STRING_ELT(width_lvl, 0, Rf_mkChar("ultracondensed")); SET_STRING_ELT(width_lvl, 1, Rf_mkChar("extracondensed")); SET_STRING_ELT(width_lvl, 2, Rf_mkChar("condensed")); SET_STRING_ELT(width_lvl, 3, Rf_mkChar("semicondensed")); SET_STRING_ELT(width_lvl, 4, Rf_mkChar("normal")); SET_STRING_ELT(width_lvl, 5, Rf_mkChar("semiexpanded")); SET_STRING_ELT(width_lvl, 6, Rf_mkChar("expanded")); SET_STRING_ELT(width_lvl, 7, Rf_mkChar("extraexpanded")); SET_STRING_ELT(width_lvl, 8, Rf_mkChar("ultraexpanded")); Rf_classgets(width, fct_cl); Rf_setAttrib(width, Rf_install("levels"), width_lvl); SEXP italic = PROTECT(Rf_allocVector(LGLSXP, n)); SEXP monospace = PROTECT(Rf_allocVector(LGLSXP, n)); SET_VECTOR_ELT(res, 0, path); SET_VECTOR_ELT(res, 1, index); SET_VECTOR_ELT(res, 2, name); SET_VECTOR_ELT(res, 3, family); SET_VECTOR_ELT(res, 4, style); SET_VECTOR_ELT(res, 5, weight); SET_VECTOR_ELT(res, 6, width); SET_VECTOR_ELT(res, 7, italic); SET_VECTOR_ELT(res, 8, monospace); int i = 0; for (ResultSet::iterator it = all_fonts->begin(); it != all_fonts->end(); it++) { SET_STRING_ELT(path, i, Rf_mkChar((*it)->path)); INTEGER(index)[i] = (*it)->index; SET_STRING_ELT(name, i, Rf_mkChar((*it)->postscriptName)); SET_STRING_ELT(family, i, Rf_mkChar((*it)->family)); SET_STRING_ELT(style, i, Rf_mkChar((*it)->style)); if ((*it)->weight == 0) { INTEGER(weight)[i] = NA_INTEGER; } else { INTEGER(weight)[i] = (*it)->weight / 100; } if ((*it)->width == 0) { INTEGER(width)[i] = NA_INTEGER; } else { INTEGER(width)[i] = (int) (*it)->width; } LOGICAL(italic)[i] = (int) (*it)->italic; LOGICAL(monospace)[i] = (int) (*it)->monospace; ++i; } delete all_fonts; SEXP row_names = PROTECT(Rf_allocVector(REALSXP, 2)); REAL(row_names)[0] = NA_REAL; REAL(row_names)[1] = -n; setAttrib(res, Rf_install("row.names"), row_names); UNPROTECT(16); return res; } SEXP reset_font_cache() { resetFontCache(); return R_NilValue; } SEXP dev_string_widths(SEXP strings, SEXP family, SEXP face, SEXP size, SEXP cex, SEXP unit) { GEUnit u = GE_INCHES; switch (INTEGER(unit)[0]) { case 0: u = GE_CM; break; case 1: u = GE_INCHES; break; case 2: u = GE_DEVICE; break; case 3: u = GE_NDC; break; } pGEDevDesc dev = GEcurrentDevice(); R_GE_gcontext gc; double width; int n_total = LENGTH(strings); int scalar_family = LENGTH(family) == 1; int scalar_rest = LENGTH(face) == 1; strcpy(gc.fontfamily, Rf_translateCharUTF8(STRING_ELT(family, 0))); gc.fontface = INTEGER(face)[0]; gc.ps = REAL(size)[0]; gc.cex = REAL(cex)[0]; SEXP res = PROTECT(allocVector(REALSXP, n_total)); for (int i = 0; i < n_total; ++i) { if (i > 0 && !scalar_family) { strcpy(gc.fontfamily, Rf_translateCharUTF8(STRING_ELT(family, i))); } if (i > 0 && !scalar_rest) { gc.fontface = INTEGER(face)[i]; gc.ps = REAL(size)[i]; gc.cex = REAL(cex)[i]; } width = GEStrWidth( CHAR(STRING_ELT(strings, i)), getCharCE(STRING_ELT(strings, i)), &gc, dev ); REAL(res)[i] = GEfromDeviceWidth(width, u, dev); } UNPROTECT(1); return res; } SEXP dev_string_metrics(SEXP strings, SEXP family, SEXP face, SEXP size, SEXP cex, SEXP unit) { GEUnit u = GE_INCHES; switch (INTEGER(unit)[0]) { case 0: u = GE_CM; break; case 1: u = GE_INCHES; break; case 2: u = GE_DEVICE; break; case 3: u = GE_NDC; break; } pGEDevDesc dev = GEcurrentDevice(); R_GE_gcontext gc; double width, ascent, descent; int n_total = LENGTH(strings); int scalar_family = LENGTH(family) == 1; int scalar_rest = LENGTH(face) == 1; strcpy(gc.fontfamily, Rf_translateCharUTF8(STRING_ELT(family, 0))); gc.fontface = INTEGER(face)[0]; gc.ps = REAL(size)[0]; gc.cex = REAL(cex)[0]; SEXP w = PROTECT(allocVector(REALSXP, n_total)); SEXP a = PROTECT(allocVector(REALSXP, n_total)); SEXP d = PROTECT(allocVector(REALSXP, n_total)); for (int i = 0; i < n_total; ++i) { if (i > 0 && !scalar_family) { strcpy(gc.fontfamily, Rf_translateCharUTF8(STRING_ELT(family, i))); } if (i > 0 && !scalar_rest) { gc.fontface = INTEGER(face)[i]; gc.ps = REAL(size)[i]; gc.cex = REAL(cex)[i]; } GEStrMetric( CHAR(STRING_ELT(strings, i)), getCharCE(STRING_ELT(strings, i)), &gc, &ascent, &descent, &width, dev ); REAL(w)[i] = GEfromDeviceWidth(width, u, dev); REAL(a)[i] = GEfromDeviceWidth(ascent, u, dev); REAL(d)[i] = GEfromDeviceWidth(descent, u, dev); } SEXP res = PROTECT(allocVector(VECSXP, 3)); SET_VECTOR_ELT(res, 0, w); SET_VECTOR_ELT(res, 1, a); SET_VECTOR_ELT(res, 2, d); SEXP row_names = PROTECT(Rf_allocVector(REALSXP, 2)); REAL(row_names)[0] = NA_REAL; REAL(row_names)[1] = -n_total; setAttrib(res, Rf_install("row.names"), row_names); SEXP names = PROTECT(Rf_allocVector(STRSXP, 3)); SET_STRING_ELT(names, 0, Rf_mkChar("width")); SET_STRING_ELT(names, 1, Rf_mkChar("ascent")); SET_STRING_ELT(names, 2, Rf_mkChar("descent")); setAttrib(res, Rf_install("names"), names); SEXP cl = PROTECT(Rf_allocVector(STRSXP, 3)); SET_STRING_ELT(cl, 0, Rf_mkChar("tbl_df")); SET_STRING_ELT(cl, 1, Rf_mkChar("tbl")); SET_STRING_ELT(cl, 2, Rf_mkChar("data.frame")); Rf_classgets(res, cl); UNPROTECT(7); return res; } SEXP register_font(SEXP family, SEXP paths, SEXP indices) { FontReg& registry = get_font_registry(); std::string name = Rf_translateCharUTF8(STRING_ELT(family, 0)); FontCollection col; for (int i = 0; i < LENGTH(paths); ++i) { std::string font_path = Rf_translateCharUTF8(STRING_ELT(paths, i)); FontLoc font(font_path, INTEGER(indices)[i]); col.push_back(font); } registry[name] = col; return R_NilValue; } SEXP clear_registry() { FontReg& registry = get_font_registry(); registry.clear(); return R_NilValue; } SEXP registry_fonts() { FontReg& registry = get_font_registry(); int n_reg = registry.size(); int n = n_reg * 4; SEXP res = PROTECT(Rf_allocVector(VECSXP, 6)); SEXP cl = PROTECT(Rf_allocVector(STRSXP, 3)); SET_STRING_ELT(cl, 0, Rf_mkChar("tbl_df")); SET_STRING_ELT(cl, 1, Rf_mkChar("tbl")); SET_STRING_ELT(cl, 2, Rf_mkChar("data.frame")); Rf_classgets(res, cl); SEXP names = PROTECT(Rf_allocVector(STRSXP, 6)); SET_STRING_ELT(names, 0, Rf_mkChar("path")); SET_STRING_ELT(names, 1, Rf_mkChar("index")); SET_STRING_ELT(names, 2, Rf_mkChar("family")); SET_STRING_ELT(names, 3, Rf_mkChar("style")); SET_STRING_ELT(names, 4, Rf_mkChar("weight")); SET_STRING_ELT(names, 5, Rf_mkChar("italic")); setAttrib(res, Rf_install("names"), names); SEXP path = PROTECT(Rf_allocVector(STRSXP, n)); SEXP index = PROTECT(Rf_allocVector(INTSXP, n)); SEXP family = PROTECT(Rf_allocVector(STRSXP, n)); SEXP style = PROTECT(Rf_allocVector(STRSXP, n)); SEXP fct_cl = PROTECT(Rf_allocVector(STRSXP, 2)); SET_STRING_ELT(fct_cl, 0, Rf_mkChar("ordered")); SET_STRING_ELT(fct_cl, 1, Rf_mkChar("factor")); SEXP weight = PROTECT(Rf_allocVector(INTSXP, n)); SEXP weight_lvl = PROTECT(Rf_allocVector(STRSXP, 2)); SET_STRING_ELT(weight_lvl, 0, Rf_mkChar("normal")); SET_STRING_ELT(weight_lvl, 1, Rf_mkChar("bold")); Rf_classgets(weight, fct_cl); Rf_setAttrib(weight, Rf_install("levels"), weight_lvl); SEXP italic = PROTECT(Rf_allocVector(LGLSXP, n)); SET_VECTOR_ELT(res, 0, path); SET_VECTOR_ELT(res, 1, index); SET_VECTOR_ELT(res, 2, family); SET_VECTOR_ELT(res, 3, style); SET_VECTOR_ELT(res, 4, weight); SET_VECTOR_ELT(res, 5, italic); int i = 0; for (auto it = registry.begin(); it != registry.end(); ++it) { for (int j = 0; j < 4; j++) { SET_STRING_ELT(path, i, Rf_mkChar(it->second[j].first.c_str())); INTEGER(index)[i] = it->second[j].second; SET_STRING_ELT(family, i, Rf_mkChar(it->first.c_str())); switch (j) { case 0: SET_STRING_ELT(style, i, Rf_mkChar("Regular")); break; case 1: SET_STRING_ELT(style, i, Rf_mkChar("Bold")); break; case 2: SET_STRING_ELT(style, i, Rf_mkChar("Italic")); break; case 3: SET_STRING_ELT(style, i, Rf_mkChar("Bold Italic")); break; } INTEGER(weight)[i] = 1 + (int) (j == 1 || j == 3); INTEGER(italic)[i] = (int) (j > 1); ++i; } } SEXP row_names = PROTECT(Rf_allocVector(REALSXP, 2)); REAL(row_names)[0] = NA_REAL; REAL(row_names)[1] = -n; setAttrib(res, Rf_install("row.names"), row_names); UNPROTECT(12); return res; } SEXP sf_ns_env = NULL; void sf_init(SEXP ns) { sf_ns_env = ns; }
31.368539
95
0.668243
kevinushey
03b29aeecb1a0a5698052e83864dbf845a4ecc47
230
cpp
C++
201-300/231-240/233-numberOfDigitOne/numberOfDigitOne.cpp
xuychen/Leetcode
c8bf33af30569177c5276ffcd72a8d93ba4c402a
[ "MIT" ]
null
null
null
201-300/231-240/233-numberOfDigitOne/numberOfDigitOne.cpp
xuychen/Leetcode
c8bf33af30569177c5276ffcd72a8d93ba4c402a
[ "MIT" ]
null
null
null
201-300/231-240/233-numberOfDigitOne/numberOfDigitOne.cpp
xuychen/Leetcode
c8bf33af30569177c5276ffcd72a8d93ba4c402a
[ "MIT" ]
null
null
null
class Solution { public: int countDigitOne(int n) { int ones = 0; for (long long m = 1; m <= n; m *= 10) ones += (n / m + 8) / 10 * m + (n / m % 10 == 1) * (n % m + 1); return ones; } };
25.555556
75
0.404348
xuychen
03b2d68381cf703fe34e113035b6220adb396936
4,754
cpp
C++
src/parseInput/parseTiledModel.cpp
daklinus/model-synthesis
1c2c0c18df72bba82e36c092fc639776dabd878c
[ "MIT" ]
47
2021-07-30T12:32:14.000Z
2022-03-20T22:02:46.000Z
src/parseInput/parseTiledModel.cpp
daklinus/model-synthesis
1c2c0c18df72bba82e36c092fc639776dabd878c
[ "MIT" ]
1
2021-11-29T18:26:53.000Z
2021-11-29T18:26:53.000Z
src/parseInput/parseTiledModel.cpp
daklinus/model-synthesis
1c2c0c18df72bba82e36c092fc639776dabd878c
[ "MIT" ]
3
2021-09-08T11:31:59.000Z
2022-01-05T14:33:07.000Z
// Copyright (c) 2021 Paul Merrell #include <iostream> #include <fstream> #include <sstream> #include "parseTiledModel.h" using namespace std; // Parse a <tiledmodel /> input. void parseTiledModel(InputSettings& settings) { string path = "samples/" + settings.name; ifstream modelFile(path, ios::in); if (!modelFile) { cout << "ERROR: The model file :" << path << " does not exist.\n" << endl; return; } char temp[1000]; modelFile.getline(temp, 1000); modelFile.getline(temp, 1000); modelFile.getline(temp, 1000); // Read in the size and create the example model. int xSize, ySize, zSize; modelFile >> xSize; modelFile >> ySize; modelFile >> zSize; int*** example = new int** [xSize]; for (int x = 0; x < xSize; x++) { example[x] = new int* [ySize]; for (int y = 0; y < ySize; y++) { example[x][y] = new int[zSize]; } } // Read in the labels in the example model. int buffer; modelFile >> buffer; for (int z = 0; z < zSize; z++) { for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { example[x][y][z] = buffer; modelFile >> buffer; } } } // Find the number of labels in the model. int numLabels = 0; for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { for (int z = 0; z < zSize; z++) { numLabels = max(numLabels, example[x][y][z]); } } } numLabels++; settings.numLabels = numLabels; // The transition describes which labels can be next to each other. // When transition[direction][labelA][labelB] is true that means labelA // can be just below labelB in the specified direction where x = 0, y = 1, z = 2. bool*** transition = createTransition(numLabels); settings.transition = transition; // Compute the transition. for (int x = 0; x < xSize - 1; x++) { for (int y = 0; y < ySize; y++) { for (int z = 0; z < zSize; z++) { int labelA = example[x][y][z]; int labelB = example[x + 1][y][z]; transition[0][labelA][labelB] = true; } } } for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize - 1; y++) { for (int z = 0; z < zSize; z++) { int labelA = example[x][y][z]; int labelB = example[x][y + 1][z]; transition[1][labelA][labelB] = true; } } } for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { for (int z = 0; z < zSize - 1; z++) { int labelA = example[x][y][z]; int labelB = example[x][y][z + 1]; transition[2][labelA][labelB] = true; } } } // The number of labels of each type in the model. int* labelCount = new int[numLabels]; for (int i = 0; i < numLabels; i++) { labelCount[i] = 0; } for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { for (int z = 0; z < zSize; z++) { labelCount[example[x][y][z]]++; } } } // We could use the label count, but equal weight also works. for (int i = 0; i < numLabels; i++) { settings.weights.push_back(1.0); } // Find the label that should initially appear at the very bottom. // And find the ground plane label. int bottomLabel = -1; int groundLabel = -1; int* onBottom = new int[numLabels]; for (int i = 0; i < numLabels; i++) { onBottom[i] = 0; } for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { onBottom[example[x][y][0]]++; } } // The bottom and ground labels should be tileable and appear frequently. int bottomCount = 0; for (int i = 0; i < numLabels; i++) { if (transition[0][i][i] && transition[1][i][i] && (onBottom[i] > bottomCount)) { bottomLabel = i; bottomCount = onBottom[i]; } } if (bottomLabel != -1) { int groundCount = 0; for (int i = 0; i < numLabels; i++) { if (transition[0][i][i] && transition[1][i][i] && transition[2][bottomLabel][i] && transition[2][i][0] && (labelCount[i] > groundCount)) { groundLabel = i; groundCount = labelCount[i]; } } } if (groundLabel == -1 || bottomLabel == -1) { bool modifyInBlocks = (settings.blockSize[0] < settings.size[0] || settings.blockSize[1] < settings.size[1]); if (modifyInBlocks) { cout << "The example model has no tileable ground plane. The new model can not be modified in blocks.\n" << endl; } } // Set the initial labels. settings.initialLabels = new int[settings.size[2]]; settings.initialLabels[0] = bottomLabel; settings.initialLabels[1] = groundLabel; for (int z = 0; z < settings.size[2]; z++) { if (z < zSize) { settings.initialLabels[z] = example[0][0][z]; } else { settings.initialLabels[z] = 0; } } // Delete the example model. for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { delete example[x][y]; } delete example[x]; } delete example; stringstream stream; stream << modelFile.rdbuf(); settings.tiledModelSuffix += stream.str(); }
26.858757
116
0.592133
daklinus
03b5370273740e53b66b1aecc114f74eb5db2b8a
512
hpp
C++
include/jln/mp/functional/flip.hpp
jonathanpoelen/jln.mp
e5f05fc4467f14ac0047e3bdc75a04076e689985
[ "MIT" ]
9
2020-07-04T16:46:13.000Z
2022-01-09T21:59:31.000Z
include/jln/mp/functional/flip.hpp
jonathanpoelen/jln.mp
e5f05fc4467f14ac0047e3bdc75a04076e689985
[ "MIT" ]
null
null
null
include/jln/mp/functional/flip.hpp
jonathanpoelen/jln.mp
e5f05fc4467f14ac0047e3bdc75a04076e689985
[ "MIT" ]
1
2021-05-23T13:37:40.000Z
2021-05-23T13:37:40.000Z
#pragma once #include <jln/mp/list/listify.hpp> #include <jln/mp/utility/unpack.hpp> #include <jln/mp/functional/call.hpp> namespace jln::mp { /// \ingroup functional /// Invokes a \function with its two first arguments reversed. /// \treturn \sequence template<class C = listify> struct flip { template<class x0, class x1, class... xs> using f = call<C, x1, x0, xs...>; }; namespace emp { template<class L, class C = mp::listify> using flip = unpack<L, mp::flip<C>>; } }
19.692308
64
0.640625
jonathanpoelen
03b65e98df5672597fafc9bb3f34b48f11ef1ba4
15,699
cpp
C++
sourcedata/jedit41source/jEdit/jeditshell/jeditlauncher/ScriptWriter.cpp
DXYyang/SDP
6ad0daf242d4062888ceca6d4a1bd4c41fd99b63
[ "Apache-2.0" ]
6
2020-10-27T06:11:59.000Z
2021-09-09T13:52:42.000Z
sourcedata/jedit41source/jEdit/jeditshell/jeditlauncher/ScriptWriter.cpp
DXYyang/SDP
6ad0daf242d4062888ceca6d4a1bd4c41fd99b63
[ "Apache-2.0" ]
8
2020-11-16T20:41:38.000Z
2022-02-01T01:05:45.000Z
sourcedata/jedit41source/jEdit/jeditshell/jeditlauncher/ScriptWriter.cpp
DXYyang/SDP
6ad0daf242d4062888ceca6d4a1bd4c41fd99b63
[ "Apache-2.0" ]
null
null
null
/* * ScriptWriter.cpp - part of jEditLauncher package * Copyright (C) 2001 John Gellene * jgellene@nyc.rr.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * Notwithstanding the terms of the General Public License, the author grants * permission to compile and link object code generated by the compilation of * this program with object code and libraries that are not subject to the * GNU General Public License, provided that the executable output of such * compilation shall be distributed with source code on substantially the * same basis as the jEditLauncher package of which this program is a part. * By way of example, a distribution would satisfy this condition if it * included a working makefile for any freely available make utility that * runs on the Windows family of operating systems. This condition does not * require a licensee of this software to distribute any proprietary software * (including header files and libraries) that is licensed under terms * prohibiting redistribution to third parties. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: ScriptWriter.cpp,v 1.11 2002/02/21 05:34:18 jgellene Exp $ */ #include "stdafx.h" #include "resource.h" #include "JELauncher.h" #include "ScriptWriter.h" #include "LauncherLog.h" #include <shlobj.h> // implementation of ScriptWriter class ScriptWriter::ScriptWriter() : pBuffer(0), pPathBuffer(0), bufferSize(0L) {} ScriptWriter::~ScriptWriter() { ReleaseBuffer(); } HRESULT ScriptWriter::WriteScript(VARIANTARG var, char** ppScript) { // LauncherLog::Log(Debug, // "[launcher] Calling ScriptWriter::WriteScript() passing variant.\n"); WritePrefix(); ProcessPathArray(var); WriteSuffix(); *ppScript = GetBuffer(); return S_OK; } HRESULT ScriptWriter::WriteScript(wchar_t* wargv[], int nArgs, char **ppScript) { // LauncherLog::Log(Debug, // "[launcher] Calling ScriptWriter::WriteScript() passing wide char array\n"); WritePrefix(); for(wchar_t **pp = wargv; nArgs > 0; --nArgs, ++pp) { ProcessPath(*pp); } WriteSuffix(); *ppScript = GetBuffer(); return S_OK; } HRESULT ScriptWriter::WriteScript(char* argv[], int nArgs, char **ppScript) { // LauncherLog::Log(Debug, // "[launcher] Calling ScriptWriter::WriteScript() passing char array\n"); WritePrefix(); for(char **pp = argv; nArgs > 0; --nArgs, ++pp) { ProcessPath(*pp); } WriteSuffix(); *ppScript = GetBuffer(); return S_OK; } HRESULT ScriptWriter::InitBuffer(size_t size) { if(pPathBuffer == 0 && (pPathBuffer = (char*)CoTaskMemAlloc(1024)) == 0) return E_FAIL; char *pBuf = pBuffer; pBuffer = (char*)CoTaskMemRealloc(pBuf, (ULONG)size); if(pBuffer == 0) { pBuffer = pBuf; return E_FAIL; } bufferSize = size; return S_OK; } void ScriptWriter::ReleaseBuffer() { CoTaskMemFree((LPVOID)pBuffer); CoTaskMemFree((LPVOID)pPathBuffer); pBuffer = 0; bufferSize = 0; pPathBuffer = 0; } void ScriptWriter::ClearBuffer() { ZeroMemory(pBuffer, bufferSize); } char* ScriptWriter::GetBuffer() { return pBuffer; } HRESULT ScriptWriter::CheckBuffer(size_t sizeCheck, size_t sizeIncr) { size_t needed = 0; size_t target = strlen(pBuffer) + sizeCheck; while(target + needed > bufferSize - 1) needed += sizeIncr; return needed != 0 ? InitBuffer(bufferSize + needed) : S_OK; } HRESULT ScriptWriter::ProcessPathArray(VARIANTARG arg) { // LauncherLog::Log(Debug, // "[launcher] Calling ScriptWriter::ProcessPathArray() passing variant\n"); HRESULT hr; VARIANT varPath; VariantInit(&varPath); switch(arg.vt) { case VT_BSTR: // single string in JScript or VBScript { hr = ProcessPath(arg.bstrVal); break; } case VT_DISPATCH: // JScript array { DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; hr = arg.pdispVal->Invoke( DISPID_NEWENUM, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &dispparamsNoArgs, &varPath, NULL, NULL); IEnumVARIANT *pEnum = 0; hr = varPath.punkVal->QueryInterface(__uuidof(IEnumVARIANT), (void**)&pEnum); VariantClear(&varPath); HRESULT loop_hr = pEnum->Next(1, &varPath, 0); while(loop_hr == S_OK) { ProcessPath(varPath.bstrVal); VariantClear(&varPath); loop_hr = pEnum->Next(1, &varPath, 0); } if(pEnum) pEnum->Release(); break; } case VT_ARRAY | VT_VARIANT: // VBScript array { LONG nIndex = 0; HRESULT loop_hr = SafeArrayGetElement(arg.parray, &nIndex, &varPath); while(loop_hr == S_OK) { // LauncherLog::Log(Debug, "Script is %s\n", GetBuffer()); ProcessPath(varPath.bstrVal); VariantClear(&varPath); loop_hr = SafeArrayGetElement(arg.parray, &(++nIndex), &varPath); } break; } default: hr = E_INVALIDARG; } VariantClear(&varPath); // LauncherLog::Log(Debug, "Script is %s\n", GetBuffer()); return hr; } HRESULT ScriptWriter::ProcessPath(wchar_t* pwszPath) { // LauncherLog::Log(Debug, // "[launcher] Calling ScriptWriter::ProcessPath with wide char parameter.\n"); if(pwszPath == 0 || wcslen(pwszPath) == 0) { CJEditLauncher::MakeErrorInfo(IDS_ERR_NO_FILENAME); return E_FAIL; } ::WideCharToMultiByte(CP_ACP, 0, pwszPath, -1, pPathBuffer, MAX_PATH * 2, 0, 0); return ProcessPath(pPathBuffer); } HRESULT ScriptWriter::ProcessPath(char* pszName) { // LauncherLog::Log(Debug, // "[launcher] Calling ScriptWriter::ProcessPath with char parameter %s\n", // pszName); CJEditLauncher::MakeErrorInfo((UINT)0); // new CHAR pszPath[MAX_PATH]; CHAR* pFileName = 0; GetFullPathName(pszName, MAX_PATH, pszPath, &pFileName); //OutputDebugString(pszPath); // wild card search and expansion if(strcspn(pszPath, "*?") != strlen(pszPath)) { LauncherLog::Log(Debug, "[launcher] ScriptWriter::ProcessPath() performing wild-card expansion\n"); CHAR* pSlash = strrchr(pszPath, '\\'); UINT pathLen = pSlash ? (UINT)(pSlash - pszPath) + 1 : 0; BOOL bDotNoStar = FALSE; CHAR* pDot = strrchr(pszPath, '.'); if(pDot != 0 && strchr(pDot, '*') == 0) bDotNoStar = TRUE; // LauncherLog::Log(Debug, bDotNoStar ? "bDotNoStar is TRUE" : "bDotNoStar is FALSE"); UINT maskExtLen = strlen(strrchr(pszPath, '.')); CHAR pszRecursivePath[MAX_PATH]; WIN32_FIND_DATA finddata; HANDLE findHandle = FindFirstFile(pszPath, &finddata); if(findHandle != INVALID_HANDLE_VALUE) { BOOL findResult = TRUE; while (findResult) { LauncherLog::Log(Debug, "FileFound: %s\n", finddata.cFileName); if((finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 && (!bDotNoStar || maskExtLen == strlen(strrchr(finddata.cFileName, '.')))) { strncpy(pszRecursivePath, pszPath, pathLen); pszRecursivePath[pathLen] = 0; strcat(pszRecursivePath, finddata.cFileName); MakeFullPath(pszRecursivePath); ProcessSinglePath(pszRecursivePath); } findResult = FindNextFile(findHandle, &finddata); } FindClose(findHandle); } else return E_FAIL; } else // non-recursive routine { MakeFullPath(pszPath); ProcessSinglePath(pszPath); } return S_OK; } void ScriptWriter::MakeFullPath(char* pszPath) { // LauncherLog::Log(Debug, // "[launcher] Calling ScriptWriter::MakeFullPath with char parameter %s\n", // pszPath); BOOL isMinLen = strlen(pszPath) > 1; BOOL isUNC = isMinLen && strncmp(pszPath, "\\\\", 2) == 0; if(isUNC) return; CHAR buf[MAX_PATH * 2]; CHAR *pFileName; GetFullPathName(pszPath, MAX_PATH * 2, buf, &pFileName); ResolveLink(buf, pszPath); // LauncherLog::Log(Debug, // "[launcher] After call to ScriptWriter::ResolveLink(), path is %s\n", // pszPath); } /* Resolve a Shortcut (ShellLink) * Put the resolved path into outPath * Copies path to outPath on failure so * outPath is always a useable path */ HRESULT ScriptWriter::ResolveLink(char* path, char* outPath) { // LauncherLog::Log(Debug, // "[launcher] Calling ScriptWriter::ResolveLink() with char parameters: %s, %s\n", // path, outPath); IShellLink *psl; HRESULT hres; hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&psl); if (SUCCEEDED(hres)) { IPersistFile *ppf; hres = psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf); if (SUCCEEDED(hres)) { WORD wsz[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, path, -1, wsz, MAX_PATH); hres = ppf->Load(wsz, STGM_READ); if (SUCCEEDED(hres)) { // LauncherLog::Log(Debug, "[launcher] IPersistFile::Load call succeeded.\n"); hres = psl->Resolve(0, SLR_ANY_MATCH | SLR_NO_UI); if (SUCCEEDED(hres)) { // LauncherLog::Log(Debug, // "[launcher] IShellLink::Resolve call succeeded.\n"); WIN32_FIND_DATA wfd; char szgotpath[MAX_PATH]; ZeroMemory(szgotpath, MAX_PATH); hres = psl->GetPath(szgotpath, MAX_PATH, &wfd, SLGP_SHORTPATH); if(SUCCEEDED(hres)) { // LauncherLog::Log(Debug, // "[launcher] IShellLink::GetPath() call succeeded; resolved path is %s\n", // ((szgotpath == 0 || strlen(szgotpath) == 0) // ? "<zero-length string>." : szgotpath)); if(szgotpath != 0 && strlen(szgotpath) != 0) strcpy(outPath, szgotpath); } else { LauncherLog::Log(Error, "[launcher] IShellLink::GetPath() call failed. Error code: 0x%08x\n", hres); } } else { LauncherLog::Log(Error, "[launcher] IShellLink::Resolve() call failed. Error code: 0x%08x\n", hres); } } else { // LauncherLog::Log(Debug, // "[launcher] IPersistFile::Load() call failed. Error code: 0x%08x\n", // hres); } ppf->Release(); } else { LauncherLog::Log(Error, "[launcher] Could not get pointer to IPersistFile object. Error code: 0x%08x\n", hres); } psl->Release(); } else { LauncherLog::Log(Error, "[launcher] Could not get pointer to IShellLink object. Error code: 0x%08x\n", hres); } if(!SUCCEEDED(hres)) { strcpy(outPath, path); } return hres; } void ScriptWriter::AppendPath(const char* path) { if(path == 0) return; const char* s = path; char *d = pBuffer + strlen(pBuffer); *d++ = '\"'; while(*s != 0) { if(*s == '\\') *d++ = '\\'; *d++ = *s++; } *d++ = '\"'; *d = 0; } void ScriptWriter::Append(const char* source) { strcat(pBuffer, source); } // Implementation of class OpenFileScript OpenFileScript::OpenFileScript() : ScriptWriter(), m_nFiles(0) { InitBuffer(0x2000); } OpenFileScript::~OpenFileScript() {} HRESULT OpenFileScript::WritePrefix() { // LauncherLog::Log(Debug,"[launcher] Calling OpenFileScript::WritePrefix()\n"); ClearBuffer(); Append("v = new java.util.Vector(8); "); return S_OK; } HRESULT OpenFileScript::ProcessSinglePath(const char* pszPath) { // LauncherLog::Log(Debug, // "[launcher] Calling OpenFileScript::ProcessSinglePath() with char parameter %s\n", // pszPath); if(m_nFiles < 128) { Append("v.addElement("); AppendPath(pszPath); Append("); "); ++m_nFiles; } return S_OK; } HRESULT OpenFileScript::WriteSuffix() { // LauncherLog::Log(Debug,"[launcher] Calling OpenFileScript::WriteSuffix()\n"); if(m_nFiles == 0) { ClearBuffer(); Append("Macros.error(jEdit.getFirstView(), "); Append("\"No files met the supplied wild-card specification.\");"); } else { Append("s = v.size(); args = new String[s]; v.copyInto(args); "); Append("EditServer.handleClient(true, null, args); "); Append("jEdit.openFile(jEdit.getLastView(), args[s - 1]);\n\n"); } return S_OK; } // Implementation of class OpenDiffScript /* Here is the script written by this object: It will work with jDiff version written for jEdit 3.2.2 and jEdit 4.0 // ----- prefix ----- v = jEdit.getFirstView(); jDiff40 = false; if(jEdit.getPlugin("JDiffPlugin") == null) { jDiff40 = true; } if(jEdit.getPlugin("jdiff.JDiffPlugin") == null) { Macros.error(v, "You must have the JDiff plugin " + "installed to use this jEditLauncher feature."); return; } if(jDiff40) { if(jdiff.DualDiff.isEnabledFor(v)) jdiff.DualDiff.toggleFor(v); } else if(DualDiff.isEnabledFor(v)) DualDiff.toggleFor(v); while(v.getEditPanes().length > 1) v.unsplit(); v.splitVertically(); if(jDiff40) jdiff.DualDiff.toggleFor(v); else DualDiff.toggleFor(v); openDiffFiles(vv) { v = vv; run() { buf1 = // ----- file 1 ----- jEdit.openFile(v, "<file 1>"); buf2 = // ----- file 2 ----- jEdit.openFile(v, "<file 2>"); // ----- suffix ----- VFSManager.waitForRequests(); editPanes = v.getEditPanes(); editPanes[0].setBuffer(buf1); editPanes[1].setBuffer(buf2); } return this; } SwingUtilities.invokeLater(openDiffFiles(v)); */ OpenDiffScript::OpenDiffScript() : ScriptWriter(), secondFile(false) { InitBuffer(1024); } OpenDiffScript::~OpenDiffScript() {} HRESULT OpenDiffScript::WritePrefix() { ClearBuffer(); Append("v = jEdit.getFirstView(); "); Append("jDiff40 = false;"); Append("if(jEdit.getPlugin(\"JDiffPlugin\") == null) {jDiff40 = true;} "); Append("if(jEdit.getPlugin(\"jdiff.JDiffPlugin\") == null) { "); Append("Macros.error(v, \"You must have the JDiff plugin "); Append("installed to use this jEditLauncher feature.\"); return; } "); Append("if(jDiff40) { if(jdiff.DualDiff.isEnabledFor(v)) "); Append("jdiff.DualDiff.toggleFor(v); } "); Append("else if(DualDiff.isEnabledFor(v)) DualDiff.toggleFor(v); "); Append("while(v.getEditPanes().length > 1) v.unsplit(); "); Append("v.splitVertically(); "); Append("if(jDiff40) jdiff.DualDiff.toggleFor(v); else "); Append("DualDiff.toggleFor(v); openDiffFiles(vv) { v = vv; run() { buf1 = "); return S_OK; } HRESULT OpenDiffScript::ProcessSinglePath(const char* pszPath) { Append("jEdit.openFile(v, "); AppendPath(pszPath); Append("); "); if(!secondFile) { Append("buf2 = "); secondFile = true; } return S_OK; } HRESULT OpenDiffScript::WriteSuffix() { Append("VFSManager.waitForRequests(); editPanes = v.getEditPanes(); "); Append("editPanes[0].setBuffer(buf1); "); Append("editPanes[1].setBuffer(buf2); } return this; } "); Append("SwingUtilities.invokeLater(openDiffFiles(v));"); return S_OK; } // Implementation of class StartAppScript StartAppScript::StartAppScript(LPCTSTR lpszCmdLine) : ScriptWriter(), bFirstFile(true), m_lpszCmdLine(lpszCmdLine) { InitBuffer(2048); } StartAppScript::~StartAppScript() {} HRESULT StartAppScript::WritePrefix() { ClearBuffer(); Append(m_lpszCmdLine); return S_OK; } HRESULT StartAppScript::ProcessSinglePath(const char* pszPath) { if(bFirstFile) { Append("-- "); bFirstFile = false; } AppendPath(pszPath); Append(" "); return S_OK; } HRESULT StartAppScript::WriteSuffix() { bFirstFile = true; // reset return S_OK; } // Implementation of class FileListScript FileListScript::FileListScript() : ScriptWriter() { InitBuffer(1024); } FileListScript::~FileListScript() {} HRESULT FileListScript::WritePrefix() { ClearBuffer(); Append("-- "); return S_OK; } HRESULT FileListScript::ProcessSinglePath(const char* pszPath) { AppendPath(pszPath); Append(" "); return S_OK; } HRESULT FileListScript::WriteSuffix() { return S_OK; }
24.339535
87
0.679661
DXYyang
03b7acf4293f327946ef2e921c4ebbaf9182fea7
3,384
hpp
C++
libs/Delphi/src/Syntax/DelphiParameterSyntax.hpp
henrikfroehling/interlinck
d9d947b890d9286c6596c687fcfcf016ef820d6b
[ "MIT" ]
null
null
null
libs/Delphi/src/Syntax/DelphiParameterSyntax.hpp
henrikfroehling/interlinck
d9d947b890d9286c6596c687fcfcf016ef820d6b
[ "MIT" ]
19
2021-12-01T20:37:23.000Z
2022-02-14T21:05:43.000Z
libs/Delphi/src/Syntax/DelphiParameterSyntax.hpp
henrikfroehling/interlinck
d9d947b890d9286c6596c687fcfcf016ef820d6b
[ "MIT" ]
null
null
null
#ifndef ARGOS_DELPHI_SYNTAX_DELPHIPARAMETERSYNTAX_H #define ARGOS_DELPHI_SYNTAX_DELPHIPARAMETERSYNTAX_H #include <string> #include <argos-Core/Syntax/SyntaxVariant.hpp> #include <argos-Core/Types.hpp> #include "Syntax/DelphiSyntaxNode.hpp" namespace argos::Core::Syntax { class ISyntaxToken; } namespace argos::Delphi::Syntax { class DelphiEqualsValueClauseSyntax; class DelphiTypeDeclarationSyntax; // ---------------------------------------------------------------------------- // DelphiParameterType // ---------------------------------------------------------------------------- class DelphiParameterType : public DelphiSyntaxNode { public: DelphiParameterType() = delete; explicit DelphiParameterType(const Core::Syntax::ISyntaxToken* colonToken, const DelphiTypeDeclarationSyntax* type) noexcept; ~DelphiParameterType() noexcept override = default; const Core::Syntax::ISyntaxToken* colonToken() const noexcept; const DelphiTypeDeclarationSyntax* type() const noexcept; argos_size childCount() const noexcept override; Core::Syntax::SyntaxVariant child(argos_size index) const noexcept override; Core::Syntax::SyntaxVariant first() const noexcept override; Core::Syntax::SyntaxVariant last() const noexcept override; std::string typeName() const noexcept override; private: const Core::Syntax::ISyntaxToken* _colonToken; const DelphiTypeDeclarationSyntax* _type; }; // ---------------------------------------------------------------------------- // DelphiParameterSyntax // ---------------------------------------------------------------------------- class DelphiParameterSyntax : public DelphiSyntaxNode { public: DelphiParameterSyntax() = delete; explicit DelphiParameterSyntax(Core::Syntax::SyntaxVariantList&& attributes, Core::Syntax::SyntaxVariantList&& parameterNames, const DelphiParameterType* parameterType = nullptr, const Core::Syntax::ISyntaxToken* parameterTypeKeyword = nullptr, const DelphiEqualsValueClauseSyntax* defaultExpression = nullptr) noexcept; ~DelphiParameterSyntax() noexcept override = default; const Core::Syntax::ISyntaxToken* parameterTypeKeyword() const noexcept; const Core::Syntax::SyntaxVariantList& attributes() const noexcept; const Core::Syntax::SyntaxVariantList& parameterNames() const noexcept; const DelphiParameterType* parameterType() const noexcept; const DelphiEqualsValueClauseSyntax* defaultExpression() const noexcept; argos_size childCount() const noexcept override; Core::Syntax::SyntaxVariant child(argos_size index) const noexcept override; Core::Syntax::SyntaxVariant first() const noexcept override; Core::Syntax::SyntaxVariant last() const noexcept override; std::string typeName() const noexcept override; protected: const Core::Syntax::ISyntaxToken* _parameterTypeKeyword; // optional Core::Syntax::SyntaxVariantList _attributes; Core::Syntax::SyntaxVariantList _parameterNames; const DelphiParameterType* _parameterType; // optional const DelphiEqualsValueClauseSyntax* _defaultExpression; // optional }; } // end namespace argos::Delphi::Syntax #endif // ARGOS_DELPHI_SYNTAX_DELPHIPARAMETERSYNTAX_H
38.022472
110
0.673168
henrikfroehling
03b7bf917ca67d53e4fa12a4cf339b65938c2a8d
8,035
cc
C++
L1TriggerConfig/L1ScalesProducers/src/L1JetEtScaleOnlineProd.cc
ckamtsikis/cmssw
ea19fe642bb7537cbf58451dcf73aa5fd1b66250
[ "Apache-2.0" ]
852
2015-01-11T21:03:51.000Z
2022-03-25T21:14:00.000Z
L1TriggerConfig/L1ScalesProducers/src/L1JetEtScaleOnlineProd.cc
ckamtsikis/cmssw
ea19fe642bb7537cbf58451dcf73aa5fd1b66250
[ "Apache-2.0" ]
30,371
2015-01-02T00:14:40.000Z
2022-03-31T23:26:05.000Z
L1TriggerConfig/L1ScalesProducers/src/L1JetEtScaleOnlineProd.cc
ckamtsikis/cmssw
ea19fe642bb7537cbf58451dcf73aa5fd1b66250
[ "Apache-2.0" ]
3,240
2015-01-02T05:53:18.000Z
2022-03-31T17:24:21.000Z
// -*- C++ -*- // // Package: L1JetEtScaleOnlineProd // Class: L1JetEtScaleOnlineProd // /**\class L1JetEtScaleOnlineProd L1JetEtScaleOnlineProd.h L1TriggerConfig/L1ScalesProducers/src/L1JetEtScaleOnlineProd.cc Description: Online producer for L1 jet Et scales Implementation: <Notes on implementation> */ // // Original Author: Werner Man-Li Sun // Created: Tue Sep 16 22:43:22 CEST 2008 // // // system include files // user include files #include "CondTools/L1Trigger/interface/L1ConfigOnlineProdBase.h" #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h" #include "CondFormats/DataRecord/interface/L1JetEtScaleRcd.h" // // class declaration // class L1JetEtScaleOnlineProd : public L1ConfigOnlineProdBase<L1JetEtScaleRcd, L1CaloEtScale> { public: L1JetEtScaleOnlineProd(const edm::ParameterSet&); ~L1JetEtScaleOnlineProd() override; std::unique_ptr<L1CaloEtScale> newObject(const std::string& objectKey) override; private: // ----------member data --------------------------- }; // // constants, enums and typedefs // // // static data member definitions // // // constructors and destructor // L1JetEtScaleOnlineProd::L1JetEtScaleOnlineProd(const edm::ParameterSet& iConfig) : L1ConfigOnlineProdBase<L1JetEtScaleRcd, L1CaloEtScale>(iConfig) { //the following line is needed to tell the framework what // data is being produced //now do what ever other initialization is needed } L1JetEtScaleOnlineProd::~L1JetEtScaleOnlineProd() { // do anything here that needs to be done at desctruction time // (e.g. close files, deallocate resources etc.) } std::unique_ptr<L1CaloEtScale> L1JetEtScaleOnlineProd::newObject(const std::string& objectKey) { // get scales keys l1t::OMDSReader::QueryResults scalesKeyResults = m_omdsReader.basicQuery("GCT_SCALES_KEY", "CMS_GCT", "GCT_PHYS_PARAMS", "GCT_PHYS_PARAMS.CONFIG_KEY", m_omdsReader.singleAttribute(objectKey)); std::string scalesKey; if (scalesKeyResults.queryFailed()) { edm::LogError("L1-O2O") << "Problem with key for L1JetEtScaleRcd : GCT scales key query failed "; } else if (scalesKeyResults.numberRows() != 1) { edm::LogError("L1-O2O") << "Problem with key for L1JetEtScaleRcd : " << (scalesKeyResults.numberRows()) << " rows were returned when getting GCT scales key"; } else { scalesKeyResults.fillVariable(scalesKey); } // get jet scale key l1t::OMDSReader::QueryResults jetScaleKeyResults = m_omdsReader.basicQuery("SC_CENJET_ET_THRESHOLD_FK", "CMS_GT", "L1T_SCALES", "L1T_SCALES.ID", scalesKeyResults); std::string jetScaleKey; if (jetScaleKeyResults.queryFailed()) { edm::LogError("L1-O2O") << "Problem with key for L1GctJetEtScaleRcd : jet scale key query failed "; } else if (jetScaleKeyResults.numberRows() != 1) { edm::LogError("L1-O2O") << "Problem with key for L1GctJetEtScaleRcd : " << (jetScaleKeyResults.numberRows()) << " rows were returned when getting jet Et scale key"; } else { jetScaleKeyResults.fillVariable(jetScaleKey); } // get thresholds std::vector<std::string> queryStrings; queryStrings.push_back("ET_GEV_BIN_LOW_0"); queryStrings.push_back("ET_GEV_BIN_LOW_1"); queryStrings.push_back("ET_GEV_BIN_LOW_2"); queryStrings.push_back("ET_GEV_BIN_LOW_3"); queryStrings.push_back("ET_GEV_BIN_LOW_4"); queryStrings.push_back("ET_GEV_BIN_LOW_5"); queryStrings.push_back("ET_GEV_BIN_LOW_6"); queryStrings.push_back("ET_GEV_BIN_LOW_7"); queryStrings.push_back("ET_GEV_BIN_LOW_8"); queryStrings.push_back("ET_GEV_BIN_LOW_9"); queryStrings.push_back("ET_GEV_BIN_LOW_10"); queryStrings.push_back("ET_GEV_BIN_LOW_11"); queryStrings.push_back("ET_GEV_BIN_LOW_12"); queryStrings.push_back("ET_GEV_BIN_LOW_13"); queryStrings.push_back("ET_GEV_BIN_LOW_14"); queryStrings.push_back("ET_GEV_BIN_LOW_15"); queryStrings.push_back("ET_GEV_BIN_LOW_16"); queryStrings.push_back("ET_GEV_BIN_LOW_17"); queryStrings.push_back("ET_GEV_BIN_LOW_18"); queryStrings.push_back("ET_GEV_BIN_LOW_19"); queryStrings.push_back("ET_GEV_BIN_LOW_20"); queryStrings.push_back("ET_GEV_BIN_LOW_21"); queryStrings.push_back("ET_GEV_BIN_LOW_22"); queryStrings.push_back("ET_GEV_BIN_LOW_23"); queryStrings.push_back("ET_GEV_BIN_LOW_24"); queryStrings.push_back("ET_GEV_BIN_LOW_25"); queryStrings.push_back("ET_GEV_BIN_LOW_26"); queryStrings.push_back("ET_GEV_BIN_LOW_27"); queryStrings.push_back("ET_GEV_BIN_LOW_28"); queryStrings.push_back("ET_GEV_BIN_LOW_29"); queryStrings.push_back("ET_GEV_BIN_LOW_30"); queryStrings.push_back("ET_GEV_BIN_LOW_31"); queryStrings.push_back("ET_GEV_BIN_LOW_32"); queryStrings.push_back("ET_GEV_BIN_LOW_33"); queryStrings.push_back("ET_GEV_BIN_LOW_34"); queryStrings.push_back("ET_GEV_BIN_LOW_35"); queryStrings.push_back("ET_GEV_BIN_LOW_36"); queryStrings.push_back("ET_GEV_BIN_LOW_37"); queryStrings.push_back("ET_GEV_BIN_LOW_38"); queryStrings.push_back("ET_GEV_BIN_LOW_39"); queryStrings.push_back("ET_GEV_BIN_LOW_40"); queryStrings.push_back("ET_GEV_BIN_LOW_41"); queryStrings.push_back("ET_GEV_BIN_LOW_42"); queryStrings.push_back("ET_GEV_BIN_LOW_43"); queryStrings.push_back("ET_GEV_BIN_LOW_44"); queryStrings.push_back("ET_GEV_BIN_LOW_45"); queryStrings.push_back("ET_GEV_BIN_LOW_46"); queryStrings.push_back("ET_GEV_BIN_LOW_47"); queryStrings.push_back("ET_GEV_BIN_LOW_48"); queryStrings.push_back("ET_GEV_BIN_LOW_49"); queryStrings.push_back("ET_GEV_BIN_LOW_50"); queryStrings.push_back("ET_GEV_BIN_LOW_51"); queryStrings.push_back("ET_GEV_BIN_LOW_52"); queryStrings.push_back("ET_GEV_BIN_LOW_53"); queryStrings.push_back("ET_GEV_BIN_LOW_54"); queryStrings.push_back("ET_GEV_BIN_LOW_55"); queryStrings.push_back("ET_GEV_BIN_LOW_56"); queryStrings.push_back("ET_GEV_BIN_LOW_57"); queryStrings.push_back("ET_GEV_BIN_LOW_58"); queryStrings.push_back("ET_GEV_BIN_LOW_59"); queryStrings.push_back("ET_GEV_BIN_LOW_60"); queryStrings.push_back("ET_GEV_BIN_LOW_61"); queryStrings.push_back("ET_GEV_BIN_LOW_62"); queryStrings.push_back("ET_GEV_BIN_LOW_63"); l1t::OMDSReader::QueryResults scaleResults = m_omdsReader.basicQuery( queryStrings, "CMS_GT", "L1T_SCALE_CALO_ET_THRESHOLD", "L1T_SCALE_CALO_ET_THRESHOLD.ID", jetScaleKeyResults); std::vector<double> thresholds; if (scaleResults.queryFailed() || scaleResults.numberRows() != 1) // check query successful { edm::LogError("L1-O2O") << "Problem with L1JetEtScale key : when reading scale."; } else { for (std::vector<std::string>::iterator thresh = queryStrings.begin(); thresh != queryStrings.end(); ++thresh) { float tempScale = 0.0; scaleResults.fillVariable(*thresh, tempScale); thresholds.push_back(tempScale); } } // get region LSB double rgnEtLsb = 0.; l1t::OMDSReader::QueryResults lsbResults = m_omdsReader.basicQuery("GCT_RGN_ET_LSB", "CMS_GCT", "GCT_PHYS_PARAMS", "GCT_PHYS_PARAMS.CONFIG_KEY", m_omdsReader.singleAttribute(objectKey)); if (lsbResults.queryFailed()) { edm::LogError("L1-O2O") << "Problem with L1JetEtScale key."; } else { lsbResults.fillVariable("GCT_RGN_ET_LSB", rgnEtLsb); } // return object return std::make_unique<L1CaloEtScale>(rgnEtLsb, thresholds); } // ------------ method called to produce the data ------------ //define this as a plug-in DEFINE_FWK_EVENTSETUP_MODULE(L1JetEtScaleOnlineProd);
39.004854
121
0.697822
ckamtsikis
03b8677a9dee93d9a96f67472fefc39dbe332750
4,681
cpp
C++
tests/symbols_tests.cpp
ruthenium96/july
62f93b33253cd7324b36c851afc58b6f80c00248
[ "Apache-2.0" ]
null
null
null
tests/symbols_tests.cpp
ruthenium96/july
62f93b33253cd7324b36c851afc58b6f80c00248
[ "Apache-2.0" ]
5
2021-11-28T14:29:35.000Z
2022-03-21T08:16:20.000Z
tests/symbols_tests.cpp
ruthenium96/july
62f93b33253cd7324b36c851afc58b6f80c00248
[ "Apache-2.0" ]
null
null
null
#include "gtest/gtest.h" #include "src/common/runner/Runner.h" TEST(symbols, throw_add_the_same_symbol_name) { model::symbols::Symbols symbols(2); symbols.addSymbol("same", 10); EXPECT_THROW(symbols.addSymbol("same", 10), std::invalid_argument); } TEST(symbols, throw_assign_the_same_exchange) { model::symbols::Symbols symbols(2); auto J = symbols.addSymbol("same", 10, model::symbols::J); symbols.assignSymbolToIsotropicExchange(J, 0, 1); EXPECT_THROW(symbols.assignSymbolToIsotropicExchange(J, 0, 1), std::invalid_argument); } // TODO: make these tests pass //TEST(symbols, throw_2222_gfactor_all_were_not_initialized) { // std::vector<int> mults = {2, 2, 2, 2}; // // runner::Runner runner(mults); // // runner.TzSort(); // // double J = 10; // double g = 2.0; // runner.modifySymbol().addSymbol("J", J); // runner.modifySymbol().addSymbol("g1", g); // runner.AddIsotropicExchange("J", 0, 1); // runner.AddIsotropicExchange("J", 1, 2); // runner.AddIsotropicExchange("J", 2, 3); // runner.AddIsotropicExchange("J", 3, 0); // // runner.FinalizeIsotropicInteraction(); // // EXPECT_THROW(runner.BuildMatrices(), std::length_error); //} // //TEST(symbols, throw_2222_gfactor_any_was_not_initialized) { // std::vector<int> mults = {2, 2, 2, 2}; // // runner::Runner runner(mults); // // runner.TzSort(); // // double J = 10; // double g = 2.0; // runner.modifySymbol().addSymbol("J", J); // runner.modifySymbol().addSymbol("g1", g); // runner.AddIsotropicExchange("J", 0, 1); // runner.AddIsotropicExchange("J", 1, 2); // runner.AddIsotropicExchange("J", 2, 3); // runner.AddIsotropicExchange("J", 3, 0); // runner.AddGFactor("g1", 0); // runner.AddGFactor("g1", 1); // runner.AddGFactor("g1", 2); // // runner.FinalizeIsotropicInteraction(); // // EXPECT_THROW(runner.BuildMatrices(), std::invalid_argument); //} TEST(symbols, throw_set_new_value_to_unchangeable_symbol) { model::symbols::Symbols symbols_(10); auto unchangeable = symbols_.addSymbol("Unchangeable", NAN, false, model::symbols::not_specified); EXPECT_THROW( symbols_.setNewValueToChangeableSymbol(unchangeable, INFINITY), std::invalid_argument); } TEST(symbols, throw_specified_not_as_J_symbol) { size_t number_of_spins = 10; model::symbols::Symbols symbols_(number_of_spins); double gChangeable = 2; auto not_specified = symbols_.addSymbol("not_specified", NAN, true, model::symbols::not_specified); symbols_.assignSymbolToIsotropicExchange(not_specified, 1, 3); auto g_changeable = symbols_.addSymbol("gChangeable", gChangeable, true, model::symbols::g_factor); EXPECT_THROW( symbols_.assignSymbolToIsotropicExchange(g_changeable, 2, 7), std::invalid_argument); } TEST(symbols, throw_specified_not_as_g_symbol) { size_t number_of_spins = 10; model::symbols::Symbols symbols_(number_of_spins); double JChangeable = 10; auto not_specified = symbols_.addSymbol("not_specified", NAN, true, model::symbols::not_specified); symbols_.assignSymbolToGFactor(not_specified, 1); auto J_changeable = symbols_.addSymbol("JChangeable", JChangeable, true, model::symbols::J); EXPECT_THROW(symbols_.assignSymbolToGFactor(J_changeable, 2), std::invalid_argument); } TEST(symbols, set_new_value_to_changeable_J_g) { size_t number_of_spins = 10; model::symbols::Symbols symbols_(number_of_spins); double JChangeable_value = 10; double gChangeable_value = 2; auto J_changeable = symbols_.addSymbol("JChangeable", JChangeable_value, true, model::symbols::J); auto g_changeable = symbols_.addSymbol("gChangeable", gChangeable_value, true, model::symbols::g_factor); symbols_.assignSymbolToIsotropicExchange(J_changeable, 2, 7); for (size_t i = 0; i < number_of_spins; ++i) { symbols_.assignSymbolToGFactor(g_changeable, i); } auto shared_ptr_J = symbols_.getIsotropicExchangeParameters(); auto shared_ptr_g = symbols_.getGFactorParameters(); EXPECT_EQ(JChangeable_value, shared_ptr_J->operator()(2, 7)); EXPECT_EQ(gChangeable_value, shared_ptr_g->operator()(7)); symbols_.setNewValueToChangeableSymbol(J_changeable, 2 * JChangeable_value); EXPECT_EQ(2 * JChangeable_value, shared_ptr_J->operator()(2, 7)); EXPECT_EQ(gChangeable_value, shared_ptr_g->operator()(7)); symbols_.setNewValueToChangeableSymbol(g_changeable, 2 * gChangeable_value); EXPECT_EQ(2 * JChangeable_value, shared_ptr_J->operator()(2, 7)); EXPECT_EQ(2 * gChangeable_value, shared_ptr_g->operator()(7)); }
36.570313
96
0.701346
ruthenium96
03b8d2a2b0475d08a3b099bb0f5ef1123d371739
458
cpp
C++
uva/c/10820.cpp
dk00/old-stuff
e1184684c85fe9bbd1ceba58b94d4da84c67784e
[ "Unlicense" ]
null
null
null
uva/c/10820.cpp
dk00/old-stuff
e1184684c85fe9bbd1ceba58b94d4da84c67784e
[ "Unlicense" ]
null
null
null
uva/c/10820.cpp
dk00/old-stuff
e1184684c85fe9bbd1ceba58b94d4da84c67784e
[ "Unlicense" ]
null
null
null
#include<stdio.h> #define MAX 50000 int notp[MAX+1]; long long t[MAX+1]; main(){ long i,j,p; for(i=4;i<=MAX;i++,i++)notp[i]=1; for(i=3;i<=MAX;i++,i++) if(!notp[i]) for(j=i*3;j<=MAX;j+=i*2)notp[j]=1; for(t[1]=1,i=2;i<=MAX;i++){ for(p=i,j=2;j*j<=i;j++) if(i%j==0){ if(!notp[j])p-=p/j; if(!notp[i/j] && j*j!=i)p-=p/(i/j); } t[i]=(p-(p==i))*2+t[i-1]; } while(scanf("%d",&i) && i)printf("%lld\n",t[i]); }
21.809524
48
0.445415
dk00
03ba5b61d4f0bc71fa878e44810db854ec2ecfce
5,639
cpp
C++
tc 160+/PizzaDelivery.cpp
ibudiselic/contest-problem-solutions
88082981b4d87da843472e3ca9ed5f4c42b3f0aa
[ "BSD-2-Clause" ]
3
2015-05-25T06:24:37.000Z
2016-09-10T07:58:00.000Z
tc 160+/PizzaDelivery.cpp
ibudiselic/contest-problem-solutions
88082981b4d87da843472e3ca9ed5f4c42b3f0aa
[ "BSD-2-Clause" ]
null
null
null
tc 160+/PizzaDelivery.cpp
ibudiselic/contest-problem-solutions
88082981b4d87da843472e3ca9ed5f4c42b3f0aa
[ "BSD-2-Clause" ]
5
2015-05-25T06:24:40.000Z
2021-08-19T19:22:29.000Z
#include <algorithm> #include <cassert> #include <cstdio> #include <iostream> #include <sstream> #include <string> #include <vector> #include <cstring> #include <queue> using namespace std; int T[20]; int dest[50][50]; int N; int best[50][50]; const int inf = (1<<29); struct state { int t, i, j; state(int t_, int i_, int j_): t(t_), i(i_), j(j_) {} }; bool operator<(const state &a, const state &b) { if (a.t != b.t) { return a.t > b.t; } else if (a.i != b.i) { return a.i < b.i; } else { return a.j < b.j; } } const int di[] = { -1, 0, 1, 0 }; const int dj[] = { 0, 1, 0, -1 }; class PizzaDelivery { public: int deliverAll(vector <string> terrain) { for (int i=0; i<20; ++i) { T[i] = inf; } int si, sj; const int m = terrain.size(); const int n = terrain[0].size(); memset(dest, 0xff, sizeof dest); N = 0; for (int i=0; i<m; ++i) { for (int j=0; j<n; ++j) { if (terrain[i][j] == 'X') { si = i; sj = j; } else if (terrain[i][j] == '$') { dest[i][j] = N++; } } } for (int i=0; i<m; ++i) { for (int j=0; j<n; ++j) { best[i][j] = inf; } } best[si][sj] = 0; priority_queue<state> PQ; PQ.push(state(0, si, sj)); while (!PQ.empty()) { const state temp = PQ.top(); PQ.pop(); const int i = temp.i; const int j = temp.j; const int t = temp.t; if (t > best[i][j]) { continue; } best[i][j] = t; if (dest[i][j] != -1) { T[dest[i][j]] = t; } for (int d=0; d<4; ++d) { const int ii = i + di[d]; const int jj = j + dj[d]; if (ii<0 || jj<0 || ii>=m || jj>=n) { continue; } int nt = t; if (terrain[ii][jj]=='X' || terrain[ii][jj]=='$' || terrain[i][j]=='X' || terrain[i][j]=='$') { nt += 2; } else { int diff = abs(terrain[i][j] - terrain[ii][jj]); if (diff > 1) { continue; } nt += 1 + (diff==1)*2; } if (nt < best[ii][jj]) { best[ii][jj] = nt; PQ.push(state(nt, ii, jj)); } } } for (int i=0; i<N; ++i) { if (T[i] == inf) { return -1; } } int sol = inf; for (int mask=0; mask<(1<<N); ++mask) { int farthest1 = 0; int farthest2 = 0; int one = 0; int two = 0; for (int i=0; i<N; ++i) { if ((mask>>i) & 1) { farthest1 = max(farthest1, T[i]); one += 2*T[i]; } else { farthest2 = max(farthest2, T[i]); two += 2*T[i]; } } sol = min(sol, max(one-farthest1, two-farthest2)); } return sol; } // BEGIN CUT HERE public: void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); } private: template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); } void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } void test_case_0() { string Arr0[] = {"3442211", "34$221X", "3442211"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 8; verify_case(0, Arg1, deliverAll(Arg0)); } void test_case_1() { string Arr0[] = {"001000$", "$010X0$", "0010000"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 13; verify_case(1, Arg1, deliverAll(Arg0)); } void test_case_2() { string Arr0[] = {"001000$", "$010X0$", "0010000", "2232222", "2222222", "111$111"} ; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = -1; verify_case(2, Arg1, deliverAll(Arg0)); } void test_case_3() { string Arr0[] = {"001000$", "$010X0$", "0010000", "1232222", "2222222", "111$111"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 28; verify_case(3, Arg1, deliverAll(Arg0)); } void test_case_4() { string Arr0[] = {"X$$", "$$$"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 14; verify_case(4, Arg1, deliverAll(Arg0)); } // END CUT HERE }; // BEGIN CUT HERE int main() { PizzaDelivery ___test; ___test.run_test(-1); } // END CUT HERE
32.408046
309
0.422238
ibudiselic
03bf5c479c5afaa1bdc0f1d097561f87fc0e61bf
15,049
cc
C++
file/list_file_reader.cc
dendisuhubdy/gaia
a988b7f08a4080a3209eba6cb378718486947a68
[ "BSD-2-Clause" ]
72
2019-01-25T09:03:41.000Z
2022-01-16T01:01:55.000Z
file/list_file_reader.cc
dendisuhubdy/gaia
a988b7f08a4080a3209eba6cb378718486947a68
[ "BSD-2-Clause" ]
35
2019-09-20T05:02:22.000Z
2022-02-14T17:28:58.000Z
file/list_file_reader.cc
dendisuhubdy/gaia
a988b7f08a4080a3209eba6cb378718486947a68
[ "BSD-2-Clause" ]
15
2018-08-12T13:43:31.000Z
2022-02-09T08:04:27.000Z
// Copyright 2019, Beeri 15. All rights reserved. // Author: Roman Gershman (romange@gmail.com) // // Based on LevelDB implementation. #include "file/list_file_reader.h" #include <cstdio> #include "base/flags.h" #include "base/varint.h" #include "base/crc32c.h" #include "base/fixed.h" #include "file/compressors.h" #include "file/lst2_impl.h" #include "absl/strings/match.h" namespace file { using file::ReadonlyFile; using std::string; using strings::AsString; using strings::FromBuf; using strings::u8ptr; using util::Status; using util::StatusCode; using namespace ::util; namespace { class Lst1Impl : public ListReader::FormatImpl { public: using FormatImpl::FormatImpl; bool ReadHeader(std::map<std::string, std::string>* dest) final; bool ReadRecord(StringPiece* record, std::string* scratch) final; private: // Return type, or one of the preceding special values unsigned int ReadPhysicalRecord(StringPiece* result); // 'size' is size of the compressed blob. // Returns true if succeeded. In that case uncompress_buf_ will contain the uncompressed data // and size will be updated to the uncompressed size. bool Uncompress(const uint8* data_ptr, uint32* size); // Extend record types with the following special values enum { kEof = list_file::kMaxRecordType + 1, // Returned whenever we find an invalid physical record. // Currently there are three situations in which this happens: // * The record has an invalid CRC (ReadPhysicalRecord reports a drop) // * The record is a 0-length record (No drop is reported) // * The record is below constructor's initial_offset (No drop is reported) kBadRecord = list_file::kMaxRecordType + 2 }; }; bool Lst1Impl::ReadHeader(std::map<std::string, std::string>* dest) { list_file::HeaderParser parser; Status status = parser.Parse(wrapper_->file, dest); if (!status.ok()) { wrapper_->BadHeader(status); return false; } file_offset_ = wrapper_->read_header_bytes = parser.offset(); wrapper_->block_size = parser.block_multiplier() * list_file::kBlockSizeFactor; CHECK_GT(wrapper_->block_size, 0); backing_store_.reset(new uint8[wrapper_->block_size]); uncompress_buf_.reset(new uint8[wrapper_->block_size]); if (file_offset_ >= wrapper_->file->Size()) { wrapper_->eof = true; } return true; } bool Lst1Impl::ReadRecord(StringPiece* record, std::string* scratch) { scratch->clear(); *record = StringPiece(); bool in_fragmented_record = false; StringPiece fragment; using namespace list_file; while (true) { if (array_records_ > 0) { uint32 item_size = 0; const uint8* aend = reinterpret_cast<const uint8*>(array_store_.end()); const uint8* item_ptr = Varint::Parse32WithLimit(u8ptr(array_store_), aend, &item_size); DVLOG(2) << "Array record with size: " << item_size; const uint8* next_rec_ptr = item_ptr + item_size; if (item_ptr == nullptr || next_rec_ptr > aend) { wrapper_->ReportCorruption(array_store_.size(), "invalid array record"); array_records_ = 0; } else { wrapper_->read_header_bytes += item_ptr - u8ptr(array_store_); array_store_.remove_prefix(next_rec_ptr - u8ptr(array_store_)); *record = StringPiece(strings::charptr(item_ptr), item_size); wrapper_->read_data_bytes += item_size; --array_records_; return true; } } const unsigned int record_type = ReadPhysicalRecord(&fragment); switch (record_type) { case kFullType: if (in_fragmented_record) { wrapper_->ReportCorruption(scratch->size(), "partial record without end(1)"); } else { scratch->clear(); *record = fragment; return true; } ABSL_FALLTHROUGH_INTENDED; case kFirstType: if (in_fragmented_record) { wrapper_->ReportCorruption(scratch->size(), "partial record without end(2)"); } *scratch = AsString(fragment); in_fragmented_record = true; break; case kMiddleType: if (!in_fragmented_record) { wrapper_->ReportCorruption(fragment.size(), "missing start of fragmented record(1)"); } else { scratch->append(fragment.data(), fragment.size()); } break; case kLastType: if (!in_fragmented_record) { wrapper_->ReportCorruption(fragment.size(), "missing start of fragmented record(2)"); } else { scratch->append(fragment.data(), fragment.size()); *record = StringPiece(*scratch); wrapper_->read_data_bytes += record->size(); // last_record_offset_ = prospective_record_offset; return true; } break; case kArrayType: { if (in_fragmented_record) { wrapper_->ReportCorruption(scratch->size(), "partial record without end(4)"); } uint32 array_records = 0; const uint8* array_ptr = Varint::Parse32WithLimit( u8ptr(fragment), u8ptr(fragment) + fragment.size(), &array_records); if (array_ptr == nullptr || array_records == 0) { wrapper_->ReportCorruption(fragment.size(), "invalid array record"); } else { wrapper_->read_header_bytes += array_ptr - u8ptr(fragment); array_records_ = array_records; array_store_ = FromBuf(array_ptr, fragment.end() - strings::charptr(array_ptr)); VLOG(2) << "Read array with count " << array_records; } } break; case kEof: if (in_fragmented_record) { wrapper_->ReportCorruption(scratch->size(), "partial record without end(3)"); scratch->clear(); } return false; case kBadRecord: if (in_fragmented_record) { wrapper_->ReportCorruption(scratch->size(), "error in middle of record"); in_fragmented_record = false; scratch->clear(); } break; default: { char buf[40]; snprintf(buf, sizeof(buf), "unknown record type %u", record_type); wrapper_->ReportCorruption((fragment.size() + (in_fragmented_record ? scratch->size() : 0)), buf); in_fragmented_record = false; scratch->clear(); } } } return true; } unsigned int Lst1Impl::ReadPhysicalRecord(StringPiece* result) { using list_file::kBlockHeaderSize; while (true) { if (block_buffer_.size() <= kBlockHeaderSize) { if (!wrapper_->eof) { size_t fsize = wrapper_->file->Size(); strings::MutableByteRange mbr(backing_store_.get(), wrapper_->block_size); auto res = wrapper_->file->Read(file_offset_, mbr); VLOG(2) << "read_size: " << res.obj << ", status: " << res.status; if (!res.ok()) { wrapper_->ReportDrop(res.obj, res.status); wrapper_->eof = true; return kEof; } block_buffer_.reset(backing_store_.get(), res.obj); file_offset_ += block_buffer_.size(); if (file_offset_ >= fsize) { wrapper_->eof = true; } continue; } else if (block_buffer_.empty()) { // End of file return kEof; } else { size_t drop_size = block_buffer_.size(); block_buffer_.clear(); wrapper_->ReportCorruption(drop_size, "truncated record at end of file"); return kEof; } } // Parse the header const uint8* header = block_buffer_.data(); const uint8 type = header[8]; uint32 length = coding::DecodeFixed32(header + 4); wrapper_->read_header_bytes += kBlockHeaderSize; if (length == 0 && type == list_file::kZeroType) { size_t bs = block_buffer_.size(); block_buffer_.clear(); // Handle the case of when mistakenly written last kBlockHeaderSize bytes as empty record. if (bs != kBlockHeaderSize) { LOG(ERROR) << "Bug reading list file " << bs; return kBadRecord; } continue; } if (length + kBlockHeaderSize > block_buffer_.size()) { VLOG(1) << "Invalid length " << length << " file offset " << file_offset_ << " block size " << block_buffer_.size() << " type " << int(type); size_t drop_size = block_buffer_.size(); block_buffer_.clear(); wrapper_->ReportCorruption(drop_size, "bad record length or truncated record at eof."); return kBadRecord; } const uint8* data_ptr = header + kBlockHeaderSize; // Check crc if (wrapper_->checksum) { uint32_t expected_crc = crc32c::Unmask(coding::DecodeFixed32(header)); // compute crc of the record and the type. uint32_t actual_crc = crc32c::Value(data_ptr - 1, 1 + length); if (actual_crc != expected_crc) { // Drop the rest of the buffer since "length" itself may have // been corrupted and if we trust it, we could find some // fragment of a real log record that just happens to look // like a valid log record. size_t drop_size = block_buffer_.size(); block_buffer_.clear(); wrapper_->ReportCorruption(drop_size, "checksum mismatch"); return kBadRecord; } } uint32 record_size = length + kBlockHeaderSize; block_buffer_.advance(record_size); if (type & list_file::kCompressedMask) { if (!Uncompress(data_ptr, &length)) { wrapper_->ReportCorruption(record_size, "Uncompress failed."); return kBadRecord; } data_ptr = uncompress_buf_.get(); } *result = FromBuf(data_ptr, length); return type & 0xF; } } bool Lst1Impl::Uncompress(const uint8* data_ptr, uint32* size) { uint8 method = *data_ptr++; VLOG(2) << "Uncompress " << int(method) << " with size " << *size; uint32 inp_sz = *size - 1; UncompressFunction uncompr_func = GetUncompress(list_file::CompressMethod(method)); if (!uncompr_func) { LOG(ERROR) << "Could not find uncompress method " << int(method); return false; } size_t uncompress_size = wrapper_->block_size; Status status = uncompr_func(data_ptr, inp_sz, uncompress_buf_.get(), &uncompress_size); if (!status.ok()) { VLOG(1) << "Uncompress error: " << status; return false; } *size = uncompress_size; return true; } const uint8* DecodeString(const uint8* ptr, const uint8* end, string* dest) { if (ptr == nullptr) return nullptr; uint32 string_sz = 0; ptr = Varint::Parse32WithLimit(ptr, end, &string_sz); if (ptr == nullptr || ptr + string_sz > end) return nullptr; const char* str = reinterpret_cast<const char*>(ptr); dest->assign(str, str + string_sz); return ptr + string_sz; } } // namespace ListReader::FormatImpl::~FormatImpl() {} ListReader::ReaderWrapper::~ReaderWrapper() { if (ownership == TAKE_OWNERSHIP) { auto st = file->Close(); if (!st.ok()) { LOG(WARNING) << "Error closing file, status " << st; } delete file; } } void ListReader::ReaderWrapper::BadHeader(const Status& st) { LOG(ERROR) << "Error reading header " << st; ReportDrop(file->Size(), st); eof = true; } void ListReader::ReaderWrapper::ReportDrop(size_t bytes, const Status& reason) { LOG(ERROR) << "ReportDrop: " << bytes << " " << ", reason: " << reason; if (reporter_ /*&& end_of_buffer_offset_ >= initial_offset_ + block_buffer_.size() + bytes*/) { reporter_(bytes, reason); } } ListReader::ListReader(file::ReadonlyFile* file, Ownership ownership, bool checksum, CorruptionReporter reporter) : wrapper_(new ReaderWrapper(file, ownership, checksum, reporter)) {} ListReader::ListReader(StringPiece filename, bool checksum, CorruptionReporter reporter) { auto res = ReadonlyFile::Open(filename); CHECK(res.ok()) << res.status << ", file name: " << filename; CHECK(res.obj) << filename; wrapper_.reset(new ReaderWrapper(res.obj, TAKE_OWNERSHIP, checksum, reporter)); } ListReader::~ListReader() {} bool ListReader::ReadHeader() { if (impl_) return true; if (wrapper_->eof) return false; static_assert(list_file::kMagicStringSize == lst2::kMagicStringSize, ""); uint8 buf[list_file::kMagicStringSize] = {0}; auto res = wrapper_->file->Read(0, strings::MutableByteRange(buf, sizeof(buf))); if (!res.ok()) { wrapper_->BadHeader(res.status); return false; } const auto read_buf = strings::FromBuf(buf, sizeof(buf)); const StringPiece kLst1Magic(list_file::kMagicString, list_file::kMagicStringSize); if (read_buf == kLst1Magic) { impl_.reset(new Lst1Impl(wrapper_.get())); return impl_->ReadHeader(&meta_); } const StringPiece kLst2Magic(lst2::kMagicString, lst2::kMagicStringSize); if (read_buf == kLst2Magic) { impl_.reset(new lst2::ReaderImpl(wrapper_.get())); return impl_->ReadHeader(&meta_); } wrapper_->BadHeader(Status(StatusCode::PARSE_ERROR, "Invalid header")); return false; } bool ListReader::GetMetaData(std::map<std::string, std::string>* meta) { if (!ReadHeader()) return false; *meta = meta_; return true; } bool ListReader::ReadRecord(StringPiece* record, std::string* scratch) { if (!ReadHeader()) return false; return impl_->ReadRecord(record, scratch); } void ListReader::Reset() { impl_.reset(); wrapper_->Reset(); } Status list_file::HeaderParser::Parse(file::ReadonlyFile* file, std::map<std::string, std::string>* meta) { uint8 buf[2]; auto res = file->Read(kMagicStringSize, strings::MutableByteRange(buf, 2)); if (!res.ok()) return res.status; offset_ = kListFileHeaderSize; if (buf[0] == 0 || buf[1] > 100) { return Status(StatusCode::IO_ERROR, "Invalid header"); } unsigned block_factor = buf[0]; if (buf[1] == kMetaExtension) { uint8 meta_header[8]; auto res = file->Read(offset_, strings::MutableByteRange(meta_header, sizeof meta_header)); if (!res.ok()) return res.status; offset_ += res.obj; uint32 length = coding::DecodeFixed32(meta_header + 4); uint32 crc = crc32c::Unmask(coding::DecodeFixed32(meta_header)); std::unique_ptr<uint8[]> meta_buf(new uint8[length]); res = file->Read(offset_, strings::MutableByteRange(meta_buf.get(), length)); if (!res.ok()) return res.status; CHECK_EQ(res.obj, length); offset_ += length; uint32 actual_crc = crc32c::Value(meta_buf.get(), length); if (crc != actual_crc) { LOG(ERROR) << "Corrupted meta data " << actual_crc << " vs2 " << crc; return Status("Bad meta crc"); } const uint8* end = meta_buf.get() + length; const uint8* ptr = Varint::Parse32WithLimit(meta_buf.get(), end, &length); for (uint32 i = 0; i < length; ++i) { string key, val; ptr = DecodeString(ptr, end, &key); ptr = DecodeString(ptr, end, &val); if (ptr == nullptr) { return Status("Bad meta crc"); } meta->emplace(std::move(key), std::move(val)); } } block_multiplier_ = block_factor; return Status::OK; } } // namespace file
32.573593
100
0.643498
dendisuhubdy
03bfdc806b7a67ddcc7cb79eda6d799c4d39601b
1,754
hpp
C++
modules/models/behavior/behavior_model.hpp
grzPat/bark
807092815c81eeb23defff473449a535a9c42f8b
[ "MIT" ]
null
null
null
modules/models/behavior/behavior_model.hpp
grzPat/bark
807092815c81eeb23defff473449a535a9c42f8b
[ "MIT" ]
null
null
null
modules/models/behavior/behavior_model.hpp
grzPat/bark
807092815c81eeb23defff473449a535a9c42f8b
[ "MIT" ]
null
null
null
// Copyright (c) 2019 fortiss GmbH, Julian Bernhard, Klemens Esterle, Patrick Hart, Tobias Kessler // // This work is licensed under the terms of the MIT license. // For a copy, see <https://opensource.org/licenses/MIT>. #ifndef MODULES_MODELS_BEHAVIOR_BEHAVIOR_MODEL_HPP_ #define MODULES_MODELS_BEHAVIOR_BEHAVIOR_MODEL_HPP_ #include <memory> #include "modules/commons/base_type.hpp" #include "modules/models/dynamic/dynamic_model.hpp" namespace modules { namespace world { namespace objects { class Agent; typedef std::shared_ptr<Agent> AgentPtr; typedef unsigned int AgentId; } // namespace objects class ObservedWorld; } // namespace world namespace models { namespace behavior { using dynamic::Trajectory; class BehaviorModel : public modules::commons::BaseType { public: explicit BehaviorModel(commons::Params *params) : commons::BaseType(params), last_trajectory_() {} BehaviorModel(const BehaviorModel &behavior_model) : commons::BaseType(behavior_model.get_params()), last_trajectory_(behavior_model.get_last_trajectory()) {} virtual ~BehaviorModel() {} dynamic::Trajectory get_last_trajectory() const { return last_trajectory_; } void set_last_trajectory(const dynamic::Trajectory &trajectory) { last_trajectory_ = trajectory; } virtual Trajectory Plan(float delta_time, const world::ObservedWorld& observed_world) = 0; virtual BehaviorModel *Clone() const = 0; private: dynamic::Trajectory last_trajectory_; }; typedef std::shared_ptr<BehaviorModel> BehaviorModelPtr; } // namespace behavior } // namespace models } // namespace modules #endif // MODULES_MODELS_BEHAVIOR_BEHAVIOR_MODEL_HPP_
28.754098
98
0.730901
grzPat
03c005a2358ecf9334359c7d3e0e25d87eb9189b
5,297
hpp
C++
cpp/include/cudf/strings/convert/convert_durations.hpp
Ahsantw/cudf
e099688d5ca7dd20104930485a829881a68c522a
[ "Apache-2.0" ]
4,012
2018-10-29T00:11:19.000Z
2022-03-31T19:20:19.000Z
cpp/include/cudf/strings/convert/convert_durations.hpp
Ahsantw/cudf
e099688d5ca7dd20104930485a829881a68c522a
[ "Apache-2.0" ]
9,865
2018-10-29T12:52:07.000Z
2022-03-31T23:09:21.000Z
cpp/include/cudf/strings/convert/convert_durations.hpp
Ahsantw/cudf
e099688d5ca7dd20104930485a829881a68c522a
[ "Apache-2.0" ]
588
2018-10-29T05:52:44.000Z
2022-03-28T06:13:09.000Z
/* * Copyright (c) 2020, NVIDIA 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 <cudf/column/column.hpp> #include <cudf/strings/strings_column_view.hpp> namespace cudf { namespace strings { /** * @addtogroup strings_convert * @{ * @file */ /** * @brief Returns a new duration column converting a strings column into * durations using the provided format pattern. * * The format pattern can include the following specifiers: * "%%,%n,%t,%D,%H,%I,%M,%S,%p,%R,%T,%r,%OH,%OI,%OM,%OS" * * | Specifier | Description | Range | * | :-------: | ----------- | ---------------- | * | %% | A literal % character | % | * | \%n | A newline character | \\n | * | \%t | A horizontal tab character | \\t | * | \%D | Days | -2,147,483,648 to 2,147,483,647 | * | \%H | 24-hour of the day | 00 to 23 | * | \%I | 12-hour of the day | 00 to 11 | * | \%M | Minute of the hour | 00 to 59 | * | \%S | Second of the minute | 00 to 59.999999999 | * | \%OH | same as %H but without sign | 00 to 23 | * | \%OI | same as %I but without sign | 00 to 11 | * | \%OM | same as %M but without sign | 00 to 59 | * | \%OS | same as %S but without sign | 00 to 59 | * | \%p | AM/PM designations associated with a 12-hour clock | 'AM' or 'PM' | * | \%R | Equivalent to "%H:%M" | | * | \%T | Equivalent to "%H:%M:%S" | | * | \%r | Equivalent to "%OI:%OM:%OS %p" | | * * Other specifiers are not currently supported. * * Invalid formats are not checked. If the string contains unexpected * or insufficient characters, that output row entry's duration value is undefined. * * Any null string entry will result in a corresponding null row in the output column. * * The resulting time units are specified by the `duration_type` parameter. * * @throw cudf::logic_error if duration_type is not a duration type. * * @param strings Strings instance for this operation. * @param duration_type The duration type used for creating the output column. * @param format String specifying the duration format in strings. * @param mr Device memory resource used to allocate the returned column's device memory. * @return New duration column. */ std::unique_ptr<column> to_durations( strings_column_view const& strings, data_type duration_type, std::string const& format, rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); /** * @brief Returns a new strings column converting a duration column into * strings using the provided format pattern. * * The format pattern can include the following specifiers: * "%%,%n,%t,%D,%H,%I,%M,%S,%p,%R,%T,%r,%OH,%OI,%OM,%OS" * * | Specifier | Description | Range | * | :-------: | ----------- | ---------------- | * | %% | A literal % character | % | * | \%n | A newline character | \\n | * | \%t | A horizontal tab character | \\t | * | \%D | Days | -2,147,483,648 to 2,147,483,647 | * | \%H | 24-hour of the day | 00 to 23 | * | \%I | 12-hour of the day | 00 to 11 | * | \%M | Minute of the hour | 00 to 59 | * | \%S | Second of the minute | 00 to 59.999999999 | * | \%OH | same as %H but without sign | 00 to 23 | * | \%OI | same as %I but without sign | 00 to 11 | * | \%OM | same as %M but without sign | 00 to 59 | * | \%OS | same as %S but without sign | 00 to 59 | * | \%p | AM/PM designations associated with a 12-hour clock | 'AM' or 'PM' | * | \%R | Equivalent to "%H:%M" | | * | \%T | Equivalent to "%H:%M:%S" | | * | \%r | Equivalent to "%OI:%OM:%OS %p" | | * * No checking is done for invalid formats or invalid duration values. Formatting sticks to * specifications of `std::formatter<std::chrono::duration>` as much as possible. * * Any null input entry will result in a corresponding null entry in the output column. * * The time units of the input column influence the number of digits in decimal of seconds. * It uses 3 digits for milliseconds, 6 digits for microseconds and 9 digits for nanoseconds. * If duration value is negative, only one negative sign is written to output string. The specifiers * with signs are "%H,%I,%M,%S,%R,%T". * * @throw cudf::logic_error if `durations` column parameter is not a duration type. * * @param durations Duration values to convert. * @param format The string specifying output format. * Default format is ""%d days %H:%M:%S". * @param mr Device memory resource used to allocate the returned column's device memory. * @return New strings column with formatted durations. */ std::unique_ptr<column> from_durations( column_view const& durations, std::string const& format = "%D days %H:%M:%S", rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); /** @} */ // end of doxygen group } // namespace strings } // namespace cudf
40.746154
100
0.649424
Ahsantw