text:
#pragma once

#include <gsl.h>
#include <string>
#include <cstdarg>
#include <typeinfo>
#include <exception>

#include "HE_Assert.h"
#include "TMP_Helper.h"

// Utility function that calls the right variadic formatting functions and returns an RAII string
std::string CStringFormat(const char* sFormat, va_list args);
std::string CStringFormat(const char* sFormat, ...);

// Default to_string functions
using std::to_string;
using gsl::to_string;
std::string to_string(const std::exception& e);
std::string to_string(void* p);

inline std::string& to_string(std::string& s) { return s; }
inline std::string to_string(std::string&& s) { return s; }
inline const std::string& to_string(const std::string& s) { return s; }
inline std::string to_string(const char* s) { return{ s }; }

// Built-in type formats specifiers
// Can be used to format a built-in type to a string with a special format.
// Use HasFormatSpecifier<T> to test statically (ex: static_assert(...)) if a type supports
// a format specifier
// The format specifier is in the same format as printf (http://en.cppreference.com/w/cpp/io/c/fprintf),
// except that the conversion format specifier (aka the last letter[s]) can be ignored, in which case the
// default specifier for the type will be used (ex: d for int, u for unsigned, f for float, etc...)
// On top of that, for long sized types, only the conversion specifier without the argument type can be
// supplied. For example, for unsigned long, the format could be " .4o", which will be converted to
// " .4ol". Supplying " .4ol" itself would also work
std::string to_string(int val, const std::string& sFormat); // Defaults to %[sFormat]d
std::string to_string(unsigned int val, const std::string& sFormat); // Defaults to %[sFormat]u
std::string to_string(long val, const std::string& sFormat); // Defaults to %[sFormat]dl
std::string to_string(unsigned long val, const std::string& sFormat); // Defaults to %[sFormat]ul
std::string to_string(long long val, const std::string& sFormat); // Defaults to %[sFormat]dll
std::string to_string(unsigned long long val, const std::string& sFormat); // Defaults to %[sFormat]ull
std::string to_string(float val, const std::string& sFormat); // Defaults to %[sFormat]f
std::string to_string(double val, const std::string& sFormat); // Defaults to %[sFormat]f
std::string to_string(long double val, const std::string& sFormat); // Defaults to %[sFormat]fL
std::string to_string(void* val, const std::string& sFormat); // Defaults to %[sFormat]p

namespace HE
{
	namespace Private
	{
		template<class T>
		using try_format = decltype(to_string(std::declval<T>()));

		template<class T>
		using has_format = has_op < T, try_format >;

		template<class T>
		using try_format_specifier = decltype(to_string(std::declval<T>(), std::declval<std::string>()));

		template<class T>
		using has_format_specifier = has_op<T, try_format_specifier >;

		template< typename Arg >
		std::string FormatIthArgN(size_t i, size_t n, Arg&& arg)
		{
			ASSERT_MSG(i == n, "String format token number was higher than the number of arguments");
			return to_string(std::forward<Arg>(arg));
		}

		template< typename Arg1, typename... Args >
		std::string FormatIthArgN(size_t i, size_t n, Arg1&& arg, Args&&... args)
		{
			if (i == n)
			{
				return to_string(std::forward<Arg1>(arg));
			}
			else
			{
				return FormatIthArgN(i, n + 1, std::forward<Args>(args)...);
			}
		}

		template< typename Arg>
		auto FormatIthArgFN(size_t i, size_t n, const std::string& format, Arg&& arg)
			-> std::enable_if_t<has_format_specifier<Arg>::value, std::string>
		{
			ASSERT_MSG(i == n, "String format token number was higher than the number of arguments");
			return to_string(std::forward<Arg>(arg), format);
		}

		template< typename Arg >
		auto FormatIthArgFN(size_t i, size_t n, const std::string& format, Arg&& arg)
			-> std::enable_if_t<!has_format_specifier<Arg>::value, std::string>
		{
			ASSERT_MSG(false , "A format specifier was supplied with type "s + typeid(Arg).name() + " which that does not support it");
			return "";
		}

		template< typename Arg1, typename... Args >
		std::string FormatIthArgFN(size_t i, size_t n, const std::string& format, Arg1&& arg, Args&&... args)
		{
			if (i == n)
			{
				return FormatIthArgFN(i, n, format, std::forward<Arg1>(arg));
			}
			else
			{
				return FormatIthArgFN(i, n + 1, format, std::forward<Args>(args)...);
			}
		}

		template< typename... Args >
		std::string FormatIthArg(size_t i, Args&&... args)
		{
			return FormatIthArgN(i, 0, std::forward<Args>(args)...);
		}

		template< typename... Args >
		std::string FormatIthArgF(size_t i, const std::string& format, Args&&... args)
		{
			return FormatIthArgFN(i, 0, format, std::forward<Args>(args)...);
		}
	}

	// Can be used in statically evaluated context to test if the type can be formatted
	// to a string and formatted with a format specifier
	template< class... T >
	constexpr bool HasFormat()
	{
		return and_<Private::has_format<T>...>::value;
	}

	template< class... T >
	constexpr bool HasFormatSpecifier()
	{
		return and_<Private::has_format_specifier<T>...>::value;
	}

	// Form: Format(sFormat, args...) -> sFormatted
	// Formats the string according to format tokens and arguments
	// Format token have the format "{i}" or "{i:xxxx}", where i is a 0-based argument index to be
	// converted to string or the character '_', which means next argument (starting at 0)
	// "xxxx" is a format string to be passed to the argument
	//
	// In order to be featured in a format token, an argument must have a "to_string" function available
	// either in the global namespace or in the same scope as the type of the argument, which
	// will be found through ADL
	// To have a format specifier, the argument must have a "to_string" which takes a string as
	// second argument
	// You can test for both of these conditions statically with HasFormat<T>() and HasFormatSpecifier<T>()

    // Example: Format("{0:dd-mm-yyyy}", date) -> to_string(date, "dd-mm-yyyy")

	// Pre-condition: The biggest index in the format string must be smaller than
	// the number of arguments, and indices can't be negative
	inline std::string Format(const std::string& sFormat)
	{
		return sFormat;
	}

	template< typename... Args>
	std::string Format(const std::string& sFormat, Args&&... args)
	{
		static_assert(HasFormat<Args...>(), "An argument cannot be formatted (HasFormat returns false)");

		using namespace HE::Private;

		std::string sOutput;
		size_t nNextArg = 0;
		for (size_t i = 0; i < sFormat.size(); ++i)
		{
			// Find the next format token
			auto const posToken = sFormat.find_first_of('{', i);

			// Add to the output all the characters up until the next format token (or the end)
			// and process the format token if necessary
			if (posToken == std::string::npos)
			{
				sOutput += sFormat.substr(i);
				break;
			}
			// The sequence "\{" is not a token start, so we continue as if it was a normal character
			else if (posToken != 0 && sFormat[posToken - 1] == '\\')
			{
				sOutput += sFormat.substr(i, posToken - i);
				i = posToken;
				continue;
			}
			// Otherwise, we have a format token
			else
			{
				sOutput += sFormat.substr(i, posToken - i); // Add everything before the token

				auto const endToken = sFormat.find_first_of('}', posToken);
				i = endToken;
				ASSERT_MSG(endToken != std::string::npos, "Token error in string format \"" + sFormat + "\"");

				// Find the index token inside the whole token
				auto const sFormatToken = sFormat.substr(posToken + 1, (endToken - 1) - posToken);
				auto const nSpecifierSentinel = sFormatToken.find_first_of(':');
				auto const sIndexToken = [sFormatToken, nSpecifierSentinel]() {
					if (nSpecifierSentinel == std::string::npos)
					{
						return sFormatToken;
					}
					else
					{
						return sFormatToken.substr(0, nSpecifierSentinel);
					}
				}();

				// Find the index of the current arg for this token
				auto const argPos = [sIndexToken, nNextArg]() -> size_t {
					if (sIndexToken == "_")
					{
						return nNextArg;
					}
					else
					{
						return std::stoi(sIndexToken);
					}
				}();
				nNextArg = argPos + 1;

				// Add the formatted argument to the output
				if (nSpecifierSentinel == std::string::npos)
				{
					sOutput += FormatIthArg(argPos, std::forward<Args>(args)...);
				}
				else
				{
					auto const sSpecifierToken = sFormatToken.substr(nSpecifierSentinel + 1);
					sOutput += FormatIthArgF(argPos, sSpecifierToken, std::forward<Args>(args)...);
				}
			}
		}

		return sOutput;
	}

	// Thread-safe logging
	void Log(const char* psMsg) noexcept;
	inline void Log(const std::string& sMsg) noexcept { Log(sMsg.c_str()); }
	void LogError(const char* psMsg) noexcept;
	inline void LogError(const std::string& sMsg) noexcept { LogError(sMsg.c_str()); }

	template< typename... Args>
	void Log(const std::string& sFormat, Args&&... args)
	{
		Log(Format(sFormat, std::forward<Args>(args)...));
	}

	template< typename... Args>
	void LogError(const std::string& sFormat, Args&&... args)
	{
		LogError(Format(sFormat, std::forward<Args>(args)...));
	}

	// Constexpr-friendly string
	template<class Char = char>
	class basic_constexpr_string
	{
	public:
		template<size_t N>
		constexpr basic_constexpr_string(const char(&a)[N]) noexcept :
			m_pStr{ a }, m_nSize{ N - 1 } {}

		constexpr Char operator[](size_t n) const
		{
			return n < m_nSize ? m_pStr[n] : throw std::out_of_range("");
		}

		constexpr size_t size() const noexcept { return m_nSize; }

	private:
		const Char* const m_pStr;
		const size_t m_nSize;
	};

	using constexpr_string = basic_constexpr_string<char>;
	using constexpr_wstring = basic_constexpr_string<wchar_t>;
	using constexpr_u16string = basic_constexpr_string<char16_t>;
	using constexpr_u32string = basic_constexpr_string<char32_t>;
}


text:
#ifndef TRANS_MYFUNC
#define TRANS_MYFUNC

#include <stdarg.h>
#include <gsl/gsl_vector.h>
#include "../include/type.h"

void mle_result_set(mle_result* mle, double sum, gsl_vector* psi1, gsl_vector* psi2,
                    double beta0, double beta1, double var1, double var2);

void log_vector(gsl_vector *vec);

double myfunc_multivar(const double x[], va_list argv);

void myfunc_multivar_der(const double x[], double res[], va_list argv);

double myfunc_1_2(const double x[], va_list argv);

void myfunc_der_1_2(const double x[], double res[], va_list argv);

double myfunc_marginal_1_2(const double x[], va_list argv);

void myfunc_marginal_1_2_der(const double x[], double res[], va_list argv);

double myfunc_individual(const double x[], va_list argv);

void myfunc_individual_der(const double x[], double res[], va_list argv);

double myfunc_marginal(const double x[], va_list argv);

void myfunc_marginal_der(const double x[], double res[], va_list argv);

int MLE_marginal_iteration(gsl_vector* i1, gsl_vector* i2,
                           gsl_vector* s1, gsl_vector* s2,
                           const int inclu_len, const int skip_len,
                           mle_result* mle);

int MLE_marginal_iteration_constrain(gsl_vector* i1, gsl_vector* i2,
                                     gsl_vector* s1, gsl_vector* s2,
                                     const int inclu_len, const int skip_len,
                                     mle_result* mle);

void* thread_wrapper_for_LT(void* arg);

void* batch_wrapper_for_LT(void* arg);

double likelihood_test(gsl_vector *i1, gsl_vector *i2, gsl_vector *s1, gsl_vector *s2,
                        int inclu_len, int skip_len, int flag, char* id);

int vec2psi(gsl_vector* psi, gsl_vector *inc, gsl_vector *skp,
            int inclu_len, int skip_len);

#endif

ext: h

max_stars_repo_name: chunjie-sam-liu/rmats-turbo

max_issues_repo_name: chunjie-sam-liu/rmats-turbo

max_forks_repo_name: chunjie-sam-liu/rmats-turbo


text:
/* Author: G. Jungman
 */
#include <config.h>
#include <stdlib.h>
#include <gsl/gsl_ieee_utils.h>

#include <gsl/gsl_qrng.h>
#include <gsl/gsl_test.h>

void test_sobol(void)
{
  int status = 0;
  double v[3];
  /* int i; */

  /* test in dimension 2 */
  gsl_qrng * g = gsl_qrng_alloc(gsl_qrng_sobol, 2);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.25 || v[1] != 0.75 );
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.375 || v[1] != 0.375 );
  gsl_qrng_free(g);

  gsl_test (status, "Sobol d=2");

  status = 0;
  /* test in dimension 3 */
  g = gsl_qrng_alloc(gsl_qrng_sobol, 3);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.25 || v[1] != 0.75 || v[2] != 0.25 );
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.375 || v[1] != 0.375 || v[2] != 0.625 );

  gsl_test (status, "Sobol d=3");

  status = 0;
  gsl_qrng_init(g);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.25 || v[1] != 0.75 || v[2] != 0.25 );
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.375 || v[1] != 0.375 || v[2] != 0.625 );
  gsl_qrng_free(g);

  gsl_test (status, "Sobol d=3 (reinitialized)");
}

void test_nied2(void)
{
  int status = 0;
  double v[3];
  /* int i; */

  /* test in dimension 2 */
  gsl_qrng * g = gsl_qrng_alloc(gsl_qrng_niederreiter_2, 2);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.75 || v[1] != 0.25 );
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.25 || v[1] != 0.75 );
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.625 || v[1] != 0.125 );
  gsl_qrng_free(g);

  gsl_test (status, "Niederreiter d=2");

  status = 0;

  /* test in dimension 3 */
  g = gsl_qrng_alloc(gsl_qrng_niederreiter_2, 3);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.75 || v[1] != 0.25 || v[2] != 0.3125 );
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.25 || v[1] != 0.75 || v[2] != 0.5625 );
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.625 || v[1] != 0.125 || v[2] != 0.6875 );

  gsl_test (status, "Niederreiter d=3");

  status = 0;

  gsl_qrng_init(g);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.75 || v[1] != 0.25 || v[2] != 0.3125 );
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.25 || v[1] != 0.75 || v[2] != 0.5625 );
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  gsl_qrng_get(g, v);
  status += ( v[0] != 0.625 || v[1] != 0.125 || v[2] != 0.6875 );
  gsl_qrng_free(g);

  gsl_test (status, "Niederreiter d=3 (reinitialized)");
}

int main()
{

  gsl_ieee_env_setup ();

  test_sobol();
  test_nied2();

  exit (gsl_test_summary ());
}

ext: c

max_stars_repo_name: manggoguy/parsec-modified

max_issues_repo_name: manggoguy/parsec-modified

max_forks_repo_name: manggoguy/parsec-modified


text:
/* wavelet/haar.c
 *
 * Copyright (C) 2004 Ivo Alxneit
 *
 * 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.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <config.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_wavelet.h>

static const double ch_2[2] = { M_SQRT1_2, M_SQRT1_2 };
static const double cg_2[2] = { M_SQRT1_2, -(M_SQRT1_2) };

static int
haar_init (const double **h1, const double **g1, const double **h2,
           const double **g2, size_t * nc, size_t * offset,
           const size_t member)
{
  if (member != 2)
    {
      return GSL_FAILURE;
    }

  *h1 = ch_2;
  *g1 = cg_2;
  *h2 = ch_2;
  *g2 = cg_2;

  *nc = 2;
  *offset = 0;

  return GSL_SUCCESS;
}

static int
haar_centered_init (const double **h1, const double **g1, const double **h2,
                    const double **g2, size_t * nc, size_t * offset,
                    const size_t member)
{
  if (member != 2)
    {
      return GSL_FAILURE;
    }

  *h1 = ch_2;
  *g1 = cg_2;
  *h2 = ch_2;
  *g2 = cg_2;

  *nc = 2;
  *offset = 1;

  return GSL_SUCCESS;
}

static const gsl_wavelet_type haar_type = {
  "haar",
  &haar_init
};

static const gsl_wavelet_type haar_centered_type = {
  "haar-centered",
  &haar_centered_init
};

const gsl_wavelet_type *gsl_wavelet_haar = &haar_type;
const gsl_wavelet_type *gsl_wavelet_haar_centered = &haar_centered_type;


text:
#ifndef PCH_H
#define PCH_H
#pragma once
// add tat ca cac cai thu vien, ham thuong xuyen dung trong suot chuong trinh
#include <fmt/format.h>
#include <QtCore/QObject>
#include <QtSql/QtSql>
#include <any>
#include <gsl/gsl>
#include <memory>
#include <optional>
#include "common.inl"
#include "database.inl"
#include "macros.inl"
#endif  // !PCH_H


text:
#pragma once

#include <optional>
#include <sam.h>
#include <gsl/span>
#include "clocks.h"
#include "utils.h"

namespace mcu {

class I2cMaster {
public:
	I2cMaster(Sercom* sercom, const mcu::ClockGenerator& clock, const mcu::ClockGenerator& slowClock, unsigned frequency = 100000)
		:port{sercom->I2CM}
	{
		int sercomIndex = mcu::util::getSercomIndex(sercom);
		PM->APBCMASK.reg |= 1 << (PM_APBCMASK_SERCOM0_Pos + sercomIndex);
		clock.routeToPeripheral(GCLK_CLKCTRL_ID_SERCOM0_CORE_Val + sercomIndex);
		slowClock.routeToPeripheral(GCLK_CLKCTRL_ID_SERCOMX_SLOW_Val);

		port.CTRLA.reg = SERCOM_I2CM_CTRLA_MODE_I2C_MASTER;
		(void)port.CTRLB.reg;
		volatile uint32_t ctrla = port.CTRLA.reg;
		port.CTRLB.reg = 0;
		port.BAUD.reg = computeBaud(frequency, clock.frequency);
		while (port.STATUS.bit.SYNCBUSY);
		port.CTRLA.bit.ENABLE = true;
		while (port.STATUS.bit.SYNCBUSY);
		port.STATUS.bit.BUSSTATE = BusstateIdle;
	}

	std::optional<std::byte> readReg(uint8_t slaveAddress, uint8_t reg)
	{
		port.ADDR.reg = (slaveAddress << 1) | 0;
		while (port.INTFLAG.reg == 0);
		port.INTFLAG.reg = SERCOM_I2CM_INTFLAG_MB | SERCOM_I2CM_INTFLAG_SB;
		if (port.STATUS.reg & (StatusErrorMask | SERCOM_I2CM_STATUS_RXNACK) != 0) {
			if (port.STATUS.bit.BUSSTATE == BusstateOwner)
				port.CTRLB.reg = SERCOM_I2CM_CTRLB_CMD(CommandStop);
			return std::nullopt;
		}

		port.DATA.reg = reg;
		while (port.INTFLAG.reg == 0);
		port.INTFLAG.reg = SERCOM_I2CM_INTFLAG_MB | SERCOM_I2CM_INTFLAG_SB;
		if (port.STATUS.reg & StatusErrorMask) {
			if (port.STATUS.bit.BUSSTATE == BusstateOwner)
				port.CTRLB.reg = SERCOM_I2CM_CTRLB_CMD(CommandStop);
			return std::nullopt;
		}

		port.ADDR.reg = (slaveAddress << 1) | 1;
		while (port.INTFLAG.reg == 0);
		port.INTFLAG.reg = SERCOM_I2CM_INTFLAG_MB | SERCOM_I2CM_INTFLAG_SB;
		if (port.STATUS.reg & (StatusErrorMask | SERCOM_I2CM_STATUS_RXNACK) != 0) {
			if (port.STATUS.bit.BUSSTATE == BusstateOwner)
				port.CTRLB.reg = SERCOM_I2CM_CTRLB_CMD(CommandStop);
			return std::nullopt;
		}

		std::byte result = static_cast<std::byte>(port.DATA.reg);
		port.CTRLB.reg = SERCOM_I2CM_CTRLB_ACKACT | SERCOM_I2CM_CTRLB_CMD(CommandStop);
		return result;
	}

	bool writeReg(uint8_t slaveAddress, uint8_t reg, std::byte data)
	{
		port.ADDR.reg = (slaveAddress << 1) | 0;
		while (port.INTFLAG.reg == 0);
		port.INTFLAG.reg = SERCOM_I2CM_INTFLAG_MB | SERCOM_I2CM_INTFLAG_SB;
		if (port.STATUS.reg & (StatusErrorMask | SERCOM_I2CM_STATUS_RXNACK) != 0) {
			if (port.STATUS.bit.BUSSTATE == BusstateOwner)
				port.CTRLB.reg = SERCOM_I2CM_CTRLB_CMD(CommandStop);
			return false;
		}

		port.DATA.reg = reg;
		while (port.INTFLAG.reg == 0);
		port.INTFLAG.reg = SERCOM_I2CM_INTFLAG_MB | SERCOM_I2CM_INTFLAG_SB;
		if (port.STATUS.reg & (StatusErrorMask | SERCOM_I2CM_STATUS_RXNACK) != 0) {
			if (port.STATUS.bit.BUSSTATE == BusstateOwner)
				port.CTRLB.reg = SERCOM_I2CM_CTRLB_CMD(CommandStop);
			return false;
		}

		port.DATA.reg = static_cast<uint8_t>(data);
		while (port.INTFLAG.reg == 0);
		port.INTFLAG.reg = SERCOM_I2CM_INTFLAG_MB | SERCOM_I2CM_INTFLAG_SB;
		if (port.STATUS.reg & (StatusErrorMask) != 0) {
			if (port.STATUS.bit.BUSSTATE == BusstateOwner)
				port.CTRLB.reg = SERCOM_I2CM_CTRLB_CMD(CommandStop);
			return false;
		}

		port.CTRLB.reg = SERCOM_I2CM_CTRLB_CMD(CommandStop);
		return true;
	}

private:
	SercomI2cm& port;

	static constexpr unsigned CommandRead = 0x2;
	static constexpr unsigned CommandStop = 0x3;
	static constexpr unsigned BusstateIdle = 0x1;
	static constexpr unsigned BusstateOwner = 0x2;
	static constexpr unsigned StatusErrorMask = SERCOM_I2CM_STATUS_ARBLOST;

	static constexpr unsigned i2cRise = 215;
	static constexpr uint16_t computeBaud(unsigned desiredFrequency, unsigned coreFrequency)
	{
		//                  coreFreq - (desiredFreq * 10) - (coreFreq * desiredFreq * i2cRise)
		// BAUD + BAUDLOW = ------------------------------------------------------------------
		//                  desiredFreq
		int baudSum = (((coreFrequency - (desiredFrequency * 10) - (i2cRise * (desiredFrequency / 100) * (coreFrequency / 1000) / 10000)) * 10 + 5) / (desiredFrequency * 10));
		assert(2 <= baudSum && baudSum <= 0xff*2);

		if (baudSum % 2 == 1)
			return (baudSum / 2) | ((baudSum / 2 + 1) << 8);
		else
			return baudSum / 2;
	}
};

}


text:
#pragma once

#include <glm/glm.hpp>
#include <gsl/span>

struct Bounds
{
   static Bounds fromPoints(gsl::span<glm::vec3> points);

   glm::vec3 getMin() const
   {
      return center - extent;
   }

   glm::vec3 getMax() const
   {
      return center + extent;
   }

   glm::vec3 center;
   glm::vec3 extent;
   float radius = 0.0f;
};

max_stars_repo_name: aaronmjacobs/Swap

max_issues_repo_name: aaronmjacobs/Swap

max_forks_repo_name: aaronmjacobs/Swap


text:
/* movstat/snacc.c
 *
 * Moving window S_n accumulator
 *
 * Copyright (C) 2018 Patrick Alken
 *
 * 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 3 of the License, or (at
 * your option) any later version.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <config.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_movstat.h>
#include <gsl/gsl_sort.h>
#include <gsl/gsl_statistics.h>

typedef double snacc_type_t;
typedef snacc_type_t ringbuf_type_t;

#include "ringbuf.c"

typedef struct
{
  snacc_type_t *window; /* linear array for current window */
  snacc_type_t *work;   /* workspace */
  ringbuf *rbuf;        /* ring buffer storing current window */
} snacc_state_t;

static size_t
snacc_size(const size_t n)
{
  size_t size = 0;

  size += sizeof(snacc_state_t);
  size += 2 * n * sizeof(snacc_type_t);
  size += ringbuf_size(n);

  return size;
}

static int
snacc_init(const size_t n, void * vstate)
{
  snacc_state_t * state = (snacc_state_t *) vstate;

  state->window = (snacc_type_t *) ((unsigned char *) vstate + sizeof(snacc_state_t));
  state->work = (snacc_type_t *) ((unsigned char *) state->window + n * sizeof(snacc_type_t));
  state->rbuf = (ringbuf *) ((unsigned char *) state->work + n * sizeof(snacc_type_t));

  ringbuf_init(n, state->rbuf);

  return GSL_SUCCESS;
}

static int
snacc_insert(const snacc_type_t x, void * vstate)
{
  snacc_state_t * state = (snacc_state_t *) vstate;

  /* add new element to ring buffer */
  ringbuf_insert(x, state->rbuf);

  return GSL_SUCCESS;
}

static int
snacc_delete(void * vstate)
{
  snacc_state_t * state = (snacc_state_t *) vstate;

  if (!ringbuf_is_empty(state->rbuf))
    ringbuf_pop_back(state->rbuf);

  return GSL_SUCCESS;
}

/* FIXME XXX: this is inefficient - could be improved by maintaining a sorted ring buffer */
static int
snacc_get(void * params, snacc_type_t * result, const void * vstate)
{
  const snacc_state_t * state = (const snacc_state_t *) vstate;
  size_t n = ringbuf_copy(state->window, state->rbuf);

  (void) params;

  gsl_sort(state->window, 1, n);
  *result = gsl_stats_Sn_from_sorted_data(state->window, 1, n, state->work);

  return GSL_SUCCESS;
}

static const gsl_movstat_accum sn_accum_type =
{
  snacc_size,
  snacc_init,
  snacc_insert,
  snacc_delete,
  snacc_get
};

const gsl_movstat_accum *gsl_movstat_accum_Sn = &sn_accum_type;

max_stars_repo_name: ielomariala/Hex-Game

max_issues_repo_name: ielomariala/Hex-Game

max_forks_repo_name: karanbirsandhu/nu-sense


text:
/***************************************************************************
 * data_cf.h is part of Math Graphic Library
 * Copyright (C) 2007-2016 Alexey Balakin <mathgl.abalakin@gmail.ru>       *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 3 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   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 Library 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.             *
 ***************************************************************************/
#ifndef _MGL_DATA_CF_H_
#define _MGL_DATA_CF_H_
//-----------------------------------------------------------------------------
#include "mgl2/abstract.h"
//-----------------------------------------------------------------------------
#if MGL_HAVE_GSL
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#else
#ifdef __cplusplus
struct gsl_vector;
struct gsl_matrix;
#else
typedef void gsl_vector;
typedef void gsl_matrix;
#endif
#endif
//-----------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif
/// Get integer power of x
double MGL_EXPORT_CONST mgl_ipow(double x,int n);
double MGL_EXPORT_PURE mgl_ipow_(mreal *x,int *n);
/// Get number of seconds since 1970 for given string
double MGL_EXPORT mgl_get_time(const char *time, const char *fmt);
double MGL_EXPORT mgl_get_time_(const char *time, const char *fmt,int,int);

/// Create HMDT object
HMDT MGL_EXPORT mgl_create_data();
uintptr_t MGL_EXPORT mgl_create_data_();
/// Create HMDT object with specified sizes
HMDT MGL_EXPORT mgl_create_data_size(long nx, long ny, long nz);
uintptr_t MGL_EXPORT mgl_create_data_size_(int *nx, int *ny, int *nz);
/// Create HMDT object with data from file
HMDT MGL_EXPORT mgl_create_data_file(const char *fname);
uintptr_t MGL_EXPORT mgl_create_data_file_(const char *fname, int len);
/// Delete HMDT object
void MGL_EXPORT mgl_delete_data(HMDT dat);
void MGL_EXPORT mgl_delete_data_(uintptr_t *dat);

/// Rearange data dimensions
void MGL_EXPORT mgl_data_rearrange(HMDT dat, long mx,long my,long mz);
void MGL_EXPORT mgl_data_rearrange_(uintptr_t *dat, int *mx, int *my, int *mz);
/// Link external data array (don't delete it at exit)
void MGL_EXPORT mgl_data_link(HMDT dat, mreal *A,long mx,long my,long mz);
void MGL_EXPORT mgl_data_link_(uintptr_t *d, mreal *A, int *nx,int *ny,int *nz);
/// Allocate memory and copy the data from the (float *) array
void MGL_EXPORT mgl_data_set_float(HMDT dat, const float *A,long mx,long my,long mz);
void MGL_EXPORT mgl_data_set_float_(uintptr_t *dat, const float *A,int *NX,int *NY,int *NZ);
void MGL_EXPORT mgl_data_set_float1_(uintptr_t *d, const float *A,int *N1);
/// Allocate memory and copy the data from the (double *) array
void MGL_EXPORT mgl_data_set_double(HMDT dat, const double *A,long mx,long my,long mz);
void MGL_EXPORT mgl_data_set_double_(uintptr_t *dat, const double *A,int *NX,int *NY,int *NZ);
void MGL_EXPORT mgl_data_set_double1_(uintptr_t *d, const double *A,int *N1);
/// Allocate memory and copy the data from the (float **) array
void MGL_EXPORT mgl_data_set_float2(HMDT d, float const * const *A,long N1,long N2);
void MGL_EXPORT mgl_data_set_float2_(uintptr_t *d, const float *A,int *N1,int *N2);
/// Allocate memory and copy the data from the (double **) array
void MGL_EXPORT mgl_data_set_double2(HMDT d, double const * const *A,long N1,long N2);
void MGL_EXPORT mgl_data_set_double2_(uintptr_t *d, const double *A,int *N1,int *N2);
/// Allocate memory and copy the data from the (float ***) array
void MGL_EXPORT mgl_data_set_float3(HMDT d, float const * const * const *A,long N1,long N2,long N3);
void MGL_EXPORT mgl_data_set_float3_(uintptr_t *d, const float *A,int *N1,int *N2,int *N3);
/// Allocate memory and copy the data from the (double ***) array
void MGL_EXPORT mgl_data_set_double3(HMDT d, double const * const * const *A,long N1,long N2,long N3);
void MGL_EXPORT mgl_data_set_double3_(uintptr_t *d, const double *A,int *N1,int *N2,int *N3);
/// Import data from abstract type
void MGL_EXPORT mgl_data_set(HMDT dat, HCDT a);
void MGL_EXPORT mgl_data_set_(uintptr_t *dat, uintptr_t *a);
/// Allocate memory and copy the data from the gsl_vector
void MGL_EXPORT mgl_data_set_vector(HMDT dat, gsl_vector *v);
/// Allocate memory and copy the data from the gsl_matrix
void MGL_EXPORT mgl_data_set_matrix(HMDT dat, gsl_matrix *m);
/// Set value of data element [i,j,k]
void MGL_EXPORT mgl_data_set_value(HMDT dat, mreal v, long i, long j, long k);
void MGL_EXPORT mgl_data_set_value_(uintptr_t *d, mreal *v, int *i, int *j, int *k);
/// Get value of data element [i,j,k]
mreal MGL_EXPORT mgl_data_get_value(HCDT dat, long i, long j, long k);
mreal MGL_EXPORT mgl_data_get_value_(uintptr_t *d, int *i, int *j, int *k);
/// Allocate memory and scanf the data from the string
void MGL_EXPORT mgl_data_set_values(HMDT dat, const char *val, long nx, long ny, long nz);
void MGL_EXPORT mgl_data_set_values_(uintptr_t *d, const char *val, int *nx, int *ny, int *nz, int l);

/// Read data array from HDF file (parse HDF4 and HDF5 files)
int MGL_EXPORT mgl_data_read_hdf(HMDT d,const char *fname,const char *data);
int MGL_EXPORT mgl_data_read_hdf_(uintptr_t *d, const char *fname, const char *data,int l,int n);
/// Read data from tab-separated text file with auto determining size
int MGL_EXPORT mgl_data_read(HMDT dat, const char *fname);
int MGL_EXPORT mgl_data_read_(uintptr_t *d, const char *fname,int l);
/// Read data from text file with size specified at beginning of the file
int MGL_EXPORT mgl_data_read_mat(HMDT dat, const char *fname, long dim);
int MGL_EXPORT mgl_data_read_mat_(uintptr_t *dat, const char *fname, int *dim, int);
/// Read data from text file with specifeid size
int MGL_EXPORT mgl_data_read_dim(HMDT dat, const char *fname,long mx,long my,long mz);
int MGL_EXPORT mgl_data_read_dim_(uintptr_t *dat, const char *fname,int *mx,int *my,int *mz,int);
/// Read data from tab-separated text files with auto determining size which filenames are result of sprintf(fname,templ,t) where t=from:step:to
int MGL_EXPORT mgl_data_read_range(HMDT d, const char *templ, double n1, double n2, double step, int as_slice);
int MGL_EXPORT mgl_data_read_range_(uintptr_t *d, const char *fname, mreal *n1, mreal *n2, mreal *step, int *as_slice,int l);
/// Read data from tab-separated text files with auto determining size which filenames are satisfied to template (like "t_*.dat")
int MGL_EXPORT mgl_data_read_all(HMDT dat, const char *templ, int as_slice);
int MGL_EXPORT mgl_data_read_all_(uintptr_t *d, const char *fname, int *as_slice,int l);
/// Import data array from PNG file according color scheme
void MGL_EXPORT mgl_data_import(HMDT dat, const char *fname, const char *scheme,mreal v1,mreal v2);
void MGL_EXPORT mgl_data_import_(uintptr_t *dat, const char *fname, const char *scheme,mreal *v1,mreal *v2,int,int);
/// Scan textual file for template and fill data array
int MGL_EXPORT mgl_data_scan_file(HMDT dat,const char *fname, const char *templ);
int MGL_EXPORT mgl_data_scan_file_(uintptr_t *dat,const char *fname, const char *templ,int,int);
/// Read data array from Tektronix WFM file
/** Parse Tektronix TDS5000/B, TDS6000/B/C, TDS/CSA7000/B, MSO70000/C, DSA70000/B/C DPO70000/B/C DPO7000/ MSO/DPO5000. */
int MGL_EXPORT mgl_data_read_wfm(HMDT d,const char *fname, long num, long step, long start);
int MGL_EXPORT mgl_data_read_wfm_(uintptr_t *d, const char *fname, long *num, long *step, long *start,int l);
/// Read data array from Matlab MAT file (parse versions 4 and 5)
int MGL_EXPORT mgl_data_read_matlab(HMDT d,const char *fname,const char *data);
int MGL_EXPORT mgl_data_read_matlab_(uintptr_t *d, const char *fname, const char *data,int l,int n);

/// Create or recreate the array with specified size and fill it by zero
void MGL_EXPORT mgl_data_create(HMDT dat, long nx,long ny,long nz);
void MGL_EXPORT mgl_data_create_(uintptr_t *dat, int *nx,int *ny,int *nz);
/// Transpose dimensions of the data (generalization of Transpose)
void MGL_EXPORT mgl_data_transpose(HMDT dat, const char *dim);
void MGL_EXPORT mgl_data_transpose_(uintptr_t *dat, const char *dim,int);
/// Normalize the data to range [v1,v2]
void MGL_EXPORT mgl_data_norm(HMDT dat, mreal v1,mreal v2,int sym,long dim);
void MGL_EXPORT mgl_data_norm_(uintptr_t *dat, mreal *v1,mreal *v2,int *sym,int *dim);
/// Normalize the data to range [v1,v2] slice by slice
void MGL_EXPORT mgl_data_norm_slice(HMDT dat, mreal v1,mreal v2,char dir,long keep_en,long sym);
void MGL_EXPORT mgl_data_norm_slice_(uintptr_t *dat, mreal *v1,mreal *v2,char *dir,int *keep_en,int *sym,int l);
/// Limit the data to be inside [-v,v], keeping the original sign
void MGL_EXPORT mgl_data_limit(HMDT dat, mreal v);
void MGL_EXPORT mgl_data_limit_(uintptr_t *dat, mreal *v);
/// Project the periodical data to range [v1,v2] (like mod() function). Separate branches by NAN if sep=true.
void MGL_EXPORT mgl_data_coil(HMDT dat, mreal v1, mreal v2, int sep);
void MGL_EXPORT mgl_data_coil_(uintptr_t *dat, mreal *v1, mreal *v2, int *sep);

/// Get sub-array of the data with given fixed indexes
HMDT MGL_EXPORT mgl_data_subdata(HCDT dat, long xx,long yy,long zz);
uintptr_t MGL_EXPORT mgl_data_subdata_(uintptr_t *dat, int *xx,int *yy,int *zz);
/// Get sub-array of the data with given fixed indexes (like indirect access)
HMDT MGL_EXPORT mgl_data_subdata_ext(HCDT dat, HCDT xx, HCDT yy, HCDT zz);
uintptr_t MGL_EXPORT mgl_data_subdata_ext_(uintptr_t *dat, uintptr_t *xx,uintptr_t *yy,uintptr_t *zz);
/// Get column (or slice) of the data filled by formulas of named columns
HMDT MGL_EXPORT mgl_data_column(HCDT dat, const char *eq);
uintptr_t MGL_EXPORT mgl_data_column_(uintptr_t *dat, const char *eq,int l);
/// Get data from sections ids, separated by value val along specified direction.
/** If section id is negative then reverse order is used (i.e. -1 give last section). */
HMDT MGL_EXPORT mgl_data_section(HCDT dat, HCDT ids, char dir, mreal val);
uintptr_t MGL_EXPORT mgl_data_section_(uintptr_t *d, uintptr_t *ids, const char *dir, mreal *val,int);
/// Get data from section id, separated by value val along specified direction.
/** If section id is negative then reverse order is used (i.e. -1 give last section). */
HMDT MGL_EXPORT mgl_data_section_val(HCDT dat, long id, char dir, mreal val);
uintptr_t MGL_EXPORT mgl_data_section_val_(uintptr_t *d, int *id, const char *dir, mreal *val,int);
/// Get contour lines for dat[i,j]=val. NAN values separate the the curves
HMDT mgl_data_conts(mreal val, HCDT dat);

/// Equidistantly fill the data to range [x1,x2] in direction dir
void MGL_EXPORT mgl_data_fill(HMDT dat, mreal x1,mreal x2,char dir);
void MGL_EXPORT mgl_data_fill_(uintptr_t *dat, mreal *x1,mreal *x2,const char *dir,int);
/// Modify the data by specified formula assuming x,y,z in range [r1,r2]
void MGL_EXPORT mgl_data_fill_eq(HMGL gr, HMDT dat, const char *eq, HCDT vdat, HCDT wdat,const char *opt);
void MGL_EXPORT mgl_data_fill_eq_(uintptr_t *gr, uintptr_t *dat, const char *eq, uintptr_t *vdat, uintptr_t *wdat,const char *opt, int, int);
/// Fill dat by interpolated values of vdat parametrically depended on xdat for x in range [x1,x2] using global spline
void MGL_EXPORT mgl_data_refill_gs(HMDT dat, HCDT xdat, HCDT vdat, mreal x1, mreal x2, long sl);
void MGL_EXPORT mgl_data_refill_gs_(uintptr_t *dat, uintptr_t *xdat, uintptr_t *vdat, mreal *x1, mreal *x2, long *sl);
/// Fill dat by interpolated values of vdat parametrically depended on xdat for x in range [x1,x2]
void MGL_EXPORT mgl_data_refill_x(HMDT dat, HCDT xdat, HCDT vdat, mreal x1, mreal x2, long sl);
void MGL_EXPORT mgl_data_refill_x_(uintptr_t *dat, uintptr_t *xdat, uintptr_t *vdat, mreal *x1, mreal *x2, long *sl);
/// Fill dat by interpolated values of vdat parametrically depended on xdat,ydat for x,y in range [x1,x2]*[y1,y2]
void MGL_EXPORT mgl_data_refill_xy(HMDT dat, HCDT xdat, HCDT ydat, HCDT vdat, mreal x1, mreal x2, mreal y1, mreal y2, long sl);
void MGL_EXPORT mgl_data_refill_xy_(uintptr_t *dat, uintptr_t *xdat, uintptr_t *ydat, uintptr_t *vdat, mreal *x1, mreal *x2, mreal *y1, mreal *y2, long *sl);
/// Fill dat by interpolated values of vdat parametrically depended on xdat,ydat,zdat for x,y,z in range [x1,x2]*[y1,y2]*[z1,z2]
void MGL_EXPORT mgl_data_refill_xyz(HMDT dat, HCDT xdat, HCDT ydat, HCDT zdat, HCDT vdat, mreal x1, mreal x2, mreal y1, mreal y2, mreal z1, mreal z2);
void MGL_EXPORT mgl_data_refill_xyz_(uintptr_t *dat, uintptr_t *xdat, uintptr_t *ydat, uintptr_t *zdat, uintptr_t *vdat, mreal *x1, mreal *x2, mreal *y1, mreal *y2, mreal *z1, mreal *z2);
/// Fill dat by interpolated values of vdat parametrically depended on xdat,ydat,zdat for x,y,z in axis range
void MGL_EXPORT mgl_data_refill_gr(HMGL gr, HMDT dat, HCDT xdat, HCDT ydat, HCDT zdat, HCDT vdat, long sl, const char *opt);
void MGL_EXPORT mgl_data_refill_gr_(uintptr_t *gr, uintptr_t *dat, uintptr_t *xdat, uintptr_t *ydat, uintptr_t *zdat, uintptr_t *vdat, long *sl, const char *opt,int);
/// Set the data by triangulated surface values assuming x,y,z in range [r1,r2]
void MGL_EXPORT mgl_data_grid(HMGL gr, HMDT d, HCDT xdat, HCDT ydat, HCDT zdat,const char *opt);
void MGL_EXPORT mgl_data_grid_(uintptr_t *gr, uintptr_t *dat, uintptr_t *xdat, uintptr_t *ydat, uintptr_t *zdat, const char *opt,int);
/// Set the data by triangulated surface values assuming x,y,z in range [x1,x2]*[y1,y2]
void MGL_EXPORT mgl_data_grid_xy(HMDT d, HCDT xdat, HCDT ydat, HCDT zdat, mreal x1, mreal x2, mreal y1, mreal y2);
void MGL_EXPORT mgl_data_grid_xy_(uintptr_t *dat, uintptr_t *xdat, uintptr_t *ydat, uintptr_t *zdat, mreal *x1, mreal *x2, mreal *y1, mreal *y2);
/// Put value to data element(s)
void MGL_EXPORT mgl_data_put_val(HMDT dat, mreal val, long i, long j, long k);
void MGL_EXPORT mgl_data_put_val_(uintptr_t *dat, mreal *val, int *i, int *j, int *k);
/// Put array to data element(s)
void MGL_EXPORT mgl_data_put_dat(HMDT dat, HCDT val, long i, long j, long k);
void MGL_EXPORT mgl_data_put_dat_(uintptr_t *dat, uintptr_t *val, int *i, int *j, int *k);
/// Modify the data by specified formula
void MGL_EXPORT mgl_data_modify(HMDT dat, const char *eq,long dim);
void MGL_EXPORT mgl_data_modify_(uintptr_t *dat, const char *eq,int *dim,int);
/// Modify the data by specified formula
void MGL_EXPORT mgl_data_modify_vw(HMDT dat, const char *eq,HCDT vdat,HCDT wdat);
void MGL_EXPORT mgl_data_modify_vw_(uintptr_t *dat, const char *eq, uintptr_t *vdat, uintptr_t *wdat,int);
/// Reduce size of the data
void MGL_EXPORT mgl_data_squeeze(HMDT dat, long rx,long ry,long rz,long smooth);
void MGL_EXPORT mgl_data_squeeze_(uintptr_t *dat, int *rx,int *ry,int *rz,int *smooth);

/// Get array which is n-th pairs {x[i],y[i]} for iterated function system (fractal) generated by A
/** NOTE: A.nx must be >= 7. */
HMDT MGL_EXPORT mgl_data_ifs_2d(HCDT A, long n, long skip);
uintptr_t MGL_EXPORT mgl_data_ifs_2d_(uintptr_t *A, long *n, long *skip);
/// Get array which is n-th points {x[i],y[i],z[i]} for iterated function system (fractal) generated by A
/** NOTE: A.nx must be >= 13. */
HMDT MGL_EXPORT mgl_data_ifs_3d(HCDT A, long n, long skip);
uintptr_t MGL_EXPORT mgl_data_ifs_3d_(uintptr_t *A, long *n, long *skip);
/// Get array which is n-th points {x[i],y[i],z[i]} for iterated function system (fractal) defined in *.ifs file 'fname' and named as 'name'
HMDT MGL_EXPORT mgl_data_ifs_file(const char *fname, const char *name, long n, long skip);
uintptr_t mgl_data_ifs_file_(const char *fname, const char *name, long *n, long *skip,int l,int m);
/// Codes for flame fractal functions
enum {
	mglFlame2d_linear=0,	mglFlame2d_sinusoidal,	mglFlame2d_spherical,	mglFlame2d_swirl,		mglFlame2d_horseshoe,
	mglFlame2d_polar,		mglFlame2d_handkerchief,mglFlame2d_heart,		mglFlame2d_disc,		mglFlame2d_spiral,
	mglFlame2d_hyperbolic,	mglFlame2d_diamond,		mglFlame2d_ex,			mglFlame2d_julia,		mglFlame2d_bent,
	mglFlame2d_waves,		mglFlame2d_fisheye,		mglFlame2d_popcorn,		mglFlame2d_exponential,	mglFlame2d_power,
	mglFlame2d_cosine,		mglFlame2d_rings,		mglFlame2d_fan,			mglFlame2d_blob,		mglFlame2d_pdj,
	mglFlame2d_fan2,		mglFlame2d_rings2,		mglFlame2d_eyefish,		mglFlame2d_bubble,		mglFlame2d_cylinder,
	mglFlame2d_perspective,	mglFlame2d_noise,		mglFlame2d_juliaN,		mglFlame2d_juliaScope,	mglFlame2d_blur,
	mglFlame2d_gaussian,	mglFlame2d_radialBlur,	mglFlame2d_pie,			mglFlame2d_ngon,		mglFlame2d_curl,
	mglFlame2d_rectangles,	mglFlame2d_arch,		mglFlame2d_tangent,		mglFlame2d_square,		mglFlame2d_blade,
	mglFlame2d_secant,		mglFlame2d_rays,		mglFlame2d_twintrian,	mglFlame2d_cross,		mglFlame2d_disc2,
	mglFlame2d_supershape,	mglFlame2d_flower,		mglFlame2d_conic,		mglFlame2d_parabola,	mglFlame2d_bent2,
	mglFlame2d_bipolar,		mglFlame2d_boarders,	mglFlame2d_butterfly,	mglFlame2d_cell,		mglFlame2d_cpow,
	mglFlame2d_curve,		mglFlame2d_edisc,		mglFlame2d_elliptic,	mglFlame2d_escher,		mglFlame2d_foci,
	mglFlame2d_lazySusan,	mglFlame2d_loonie,		mglFlame2d_preBlur,		mglFlame2d_modulus,		mglFlame2d_oscope,
	mglFlame2d_polar2,		mglFlame2d_popcorn2,	mglFlame2d_scry,		mglFlame2d_separation,	mglFlame2d_split,
	mglFlame2d_splits,		mglFlame2d_stripes,		mglFlame2d_wedge,		mglFlame2d_wedgeJulia,	mglFlame2d_wedgeSph,
	mglFlame2d_whorl,		mglFlame2d_waves2,		mglFlame2d_exp,			mglFlame2d_log,			mglFlame2d_sin,
	mglFlame2d_cos,			mglFlame2d_tan,			mglFlame2d_sec,			mglFlame2d_csc,			mglFlame2d_cot,
	mglFlame2d_sinh,		mglFlame2d_cosh,		mglFlame2d_tanh,		mglFlame2d_sech,		mglFlame2d_csch,
	mglFlame2d_coth,		mglFlame2d_auger,		mglFlame2d_flux,		mglFlame2dLAST
};
/// Get array which is n-th pairs {x[i],y[i]} for Flame fractal generated by A with functions F
/** NOTE: A.nx must be >= 7 and F.nx >= 2 and F.nz=A.ny.
 * F[0,i,j] denote function id. F[1,i,j] give function weight. F(2:5,i,j) provide function parameters.
 * Resulting point is {xnew,ynew} = sum_i F[1,i,j]*F[0,i,j]{IFS2d(A[j]){x,y}}. */
HMDT MGL_EXPORT mgl_data_flame_2d(HCDT A, HCDT F, long n, long skip);
uintptr_t MGL_EXPORT mgl_data_flame_2d_(uintptr_t *A, uintptr_t *F, long *n, long *skip);

/// Get curves, separated by NAN, for maximal values of array d as function of x coordinate.
/** Noises below lvl amplitude are ignored.
  * Parameter dy \in [0,ny] set the "attraction" distance of points to curve. */
HMDT MGL_EXPORT mgl_data_detect(HCDT d, mreal lvl, mreal dj, mreal di, mreal min_len);
uintptr_t MGL_EXPORT mgl_data_detect_(uintptr_t *d, mreal *lvl, mreal *dj, mreal *di, mreal *min_len);

/// Get array as solution of tridiagonal matrix solution a[i]*x[i-1]+b[i]*x[i]+c[i]*x[i+1]=d[i]
/** String \a how may contain:
 * 'x', 'y', 'z' for solving along x-,y-,z-directions, or
 * 'h' for solving along hexagonal direction at x-y plain (need nx=ny),
 * 'c' for using periodical boundary conditions,
 * 'd' for diffraction/diffuse calculation.
 * NOTE: It work for flat data model only (i.e. for a[i,j]==a[i+nx*j]) */
HMDT MGL_EXPORT mgl_data_tridmat(HCDT A, HCDT B, HCDT C, HCDT D, const char *how);
uintptr_t MGL_EXPORT mgl_data_tridmat_(uintptr_t *A, uintptr_t *B, uintptr_t *C, uintptr_t *D, const char *how, int);

/// Returns pointer to data element [i,j,k]
MGL_EXPORT mreal *mgl_data_value(HMDT dat, long i,long j,long k);
/// Returns pointer to internal data array
MGL_EXPORT_PURE mreal *mgl_data_data(HMDT dat);

/// Gets the x-size of the data.
long MGL_EXPORT mgl_data_get_nx(HCDT d);
long MGL_EXPORT mgl_data_get_nx_(uintptr_t *d);
/// Gets the y-size of the data.
long MGL_EXPORT mgl_data_get_ny(HCDT d);
long MGL_EXPORT mgl_data_get_ny_(uintptr_t *d);
/// Gets the z-size of the data.
long MGL_EXPORT mgl_data_get_nz(HCDT d);
long MGL_EXPORT mgl_data_get_nz_(uintptr_t *d);

/// Get the data which is direct multiplication (like, d[i,j] = this[i]*a[j] and so on)
HMDT MGL_EXPORT mgl_data_combine(HCDT dat1, HCDT dat2);
uintptr_t MGL_EXPORT mgl_data_combine_(uintptr_t *dat1, uintptr_t *dat2);
/// Extend data dimensions
void MGL_EXPORT mgl_data_extend(HMDT dat, long n1, long n2);
void MGL_EXPORT mgl_data_extend_(uintptr_t *dat, int *n1, int *n2);
/// Insert data rows/columns/slices
void MGL_EXPORT mgl_data_insert(HMDT dat, char dir, long at, long num);
void MGL_EXPORT mgl_data_insert_(uintptr_t *dat, const char *dir, int *at, int *num, int);
/// Delete data rows/columns/slices
void MGL_EXPORT mgl_data_delete(HMDT dat, char dir, long at, long num);
void MGL_EXPORT mgl_data_delete_(uintptr_t *dat, const char *dir, int *at, int *num, int);
/// Joind another data array
void MGL_EXPORT mgl_data_join(HMDT dat, HCDT d);
void MGL_EXPORT mgl_data_join_(uintptr_t *dat, uintptr_t *d);

/// Smooth the data on specified direction or directions
/** String \a dir may contain:
 *  ‘x’, ‘y’, ‘z’ for 1st, 2nd or 3d dimension;
 *  ‘dN’ for linear averaging over N points;
 *  ‘3’ for linear averaging over 3 points;
 *  ‘5’ for linear averaging over 5 points.
 *  By default quadratic averaging over 5 points is used. */
void MGL_EXPORT mgl_data_smooth(HMDT d, const char *dirs, mreal delta);
void MGL_EXPORT mgl_data_smooth_(uintptr_t *dat, const char *dirs, mreal *delta,int);
/// Get array which is result of summation in given direction or directions
HMDT MGL_EXPORT mgl_data_sum(HCDT dat, const char *dir);
uintptr_t MGL_EXPORT mgl_data_sum_(uintptr_t *dat, const char *dir,int);
/// Get array which is result of maximal values in given direction or directions
HMDT MGL_EXPORT mgl_data_max_dir(HCDT dat, const char *dir);
uintptr_t MGL_EXPORT mgl_data_max_dir_(uintptr_t *dat, const char *dir,int);
/// Get array which is result of minimal values in given direction or directions
HMDT MGL_EXPORT mgl_data_min_dir(HCDT dat, const char *dir);
uintptr_t MGL_EXPORT mgl_data_min_dir_(uintptr_t *dat, const char *dir,int);
/// Get positions of local maximums and minimums
HMDT MGL_EXPORT mgl_data_minmax(HCDT dat);
uintptr_t MGL_EXPORT mgl_data_minmax_(uintptr_t *dat);
/// Get indexes of a set of connected surfaces for set of values {a_ijk,b_ijk} as dependent on j,k
/** NOTE: not optimized for general case!!! */
HMDT MGL_EXPORT mgl_data_connect(HCDT a, HCDT b);
uintptr_t MGL_EXPORT mgl_data_connect_(uintptr_t *a, uintptr_t *b);
/// Resort data values according found connected surfaces for set of values {a_ijk,b_ijk} as dependent on j,k
/** NOTE: not optimized for general case!!! */
void MGL_EXPORT mgl_data_connect_r(HMDT a, HMDT b);
void MGL_EXPORT mgl_data_connect_r_(uintptr_t *a, uintptr_t *b);

/// Cumulative summation the data in given direction or directions
void MGL_EXPORT mgl_data_cumsum(HMDT dat, const char *dir);
void MGL_EXPORT mgl_data_cumsum_(uintptr_t *dat, const char *dir,int);
/// Integrate (cumulative summation) the data in given direction or directions
void MGL_EXPORT mgl_data_integral(HMDT dat, const char *dir);
void MGL_EXPORT mgl_data_integral_(uintptr_t *dat, const char *dir,int);
/// Differentiate the data in given direction or directions
void MGL_EXPORT mgl_data_diff(HMDT dat, const char *dir);
void MGL_EXPORT mgl_data_diff_(uintptr_t *dat, const char *dir,int);
/// Differentiate the parametrically specified data along direction v1 with v2,v3=const (v3 can be NULL)
void MGL_EXPORT mgl_data_diff_par(HMDT dat, HCDT v1, HCDT v2, HCDT v3);
void MGL_EXPORT mgl_data_diff_par_(uintptr_t *dat, uintptr_t *v1, uintptr_t *v2, uintptr_t *v3);
/// Double-differentiate (like Laplace operator) the data in given direction
void MGL_EXPORT mgl_data_diff2(HMDT dat, const char *dir);
void MGL_EXPORT mgl_data_diff2_(uintptr_t *dat, const char *dir,int);
/// Swap left and right part of the data in given direction (useful for Fourier spectrum)
void MGL_EXPORT mgl_data_swap(HMDT dat, const char *dir);
void MGL_EXPORT mgl_data_swap_(uintptr_t *dat, const char *dir,int);
/// Roll data along direction dir by num slices
void MGL_EXPORT mgl_data_roll(HMDT dat, char dir, long num);
void MGL_EXPORT mgl_data_roll_(uintptr_t *dat, const char *dir, int *num, int);
/// Mirror the data in given direction (useful for Fourier spectrum)
void MGL_EXPORT mgl_data_mirror(HMDT dat, const char *dir);
void MGL_EXPORT mgl_data_mirror_(uintptr_t *dat, const char *dir,int);
/// Sort rows (or slices) by values of specified column
void MGL_EXPORT mgl_data_sort(HMDT dat, long idx, long idy);
void MGL_EXPORT mgl_data_sort_(uintptr_t *dat, int *idx, int *idy);
/// Return dilated array of 0 or 1 for data values larger val
void MGL_EXPORT mgl_data_dilate(HMDT dat, mreal val, long step);
void MGL_EXPORT mgl_data_dilate_(uintptr_t *dat, mreal *val, int *step);
/// Return eroded array of 0 or 1 for data values larger val
void MGL_EXPORT mgl_data_erode(HMDT dat, mreal val, long step);
void MGL_EXPORT mgl_data_erode_(uintptr_t *dat, mreal *val, int *step);

/// Apply Hankel transform
void MGL_EXPORT mgl_data_hankel(HMDT dat, const char *dir);
void MGL_EXPORT mgl_data_hankel_(uintptr_t *dat, const char *dir,int);
/// Apply Sin-Fourier transform
void MGL_EXPORT mgl_data_sinfft(HMDT dat, const char *dir);
void MGL_EXPORT mgl_data_sinfft_(uintptr_t *dat, const char *dir,int);
/// Apply Cos-Fourier transform
void MGL_EXPORT mgl_data_cosfft(HMDT dat, const char *dir);
void MGL_EXPORT mgl_data_cosfft_(uintptr_t *dat, const char *dir,int);
/// Fill data by coordinates/momenta samples for Hankel ('h') or Fourier ('f') transform
/** Parameter \a how may contain:
 * ‘x‘,‘y‘,‘z‘ for direction (only one will be used),
 * ‘k‘ for momenta samples,
 * ‘h‘ for Hankel samples,
 * ‘f‘ for Cartesian/Fourier samples (default). */
void MGL_EXPORT mgl_data_fill_sample(HMDT dat, const char *how);
void MGL_EXPORT mgl_data_fill_sample_(uintptr_t *dat, const char *how,int);
/// Find correlation between 2 data arrays
HMDT MGL_EXPORT mgl_data_correl(HCDT dat1, HCDT dat2, const char *dir);
uintptr_t MGL_EXPORT mgl_data_correl_(uintptr_t *dat1, uintptr_t *dat2, const char *dir,int);
/// Apply wavelet transform
/** Parameter \a dir may contain:
 * ‘x‘,‘y‘,‘z‘ for directions,
 * ‘d‘ for daubechies, ‘D‘ for centered daubechies,
 * ‘h‘ for haar, ‘H‘ for centered haar,
 * ‘b‘ for bspline, ‘B‘ for centered bspline,
 * ‘i‘ for applying inverse transform. */
void MGL_EXPORT mgl_data_wavelet(HMDT dat, const char *how, int k);
void MGL_EXPORT mgl_data_wavelet_(uintptr_t *d, const char *dir, int *k,int);

/// Allocate and prepare data for Fourier transform by nthr threads
MGL_EXPORT void *mgl_fft_alloc(long n, void **space, long nthr);
MGL_EXPORT void *mgl_fft_alloc_thr(long n);
/// Free data for Fourier transform
void MGL_EXPORT mgl_fft_free(void *wt, void **ws, long nthr);
void MGL_EXPORT mgl_fft_free_thr(void *wt);
/// Make Fourier transform of data x of size n and step s between points
void MGL_EXPORT mgl_fft(double *x, long s, long n, const void *wt, void *ws, int inv);
/// Clear internal data for speeding up FFT and Hankel transforms
void MGL_EXPORT mgl_clear_fft();

/// Interpolate by cubic spline the data to given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1]
mreal MGL_EXPORT mgl_data_spline(HCDT dat, mreal x,mreal y,mreal z);
mreal MGL_EXPORT mgl_data_spline_(uintptr_t *dat, mreal *x,mreal *y,mreal *z);
/// Interpolate by cubic spline the data and return its derivatives at given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1]
mreal MGL_EXPORT mgl_data_spline_ext(HCDT dat, mreal x,mreal y,mreal z, mreal *dx,mreal *dy,mreal *dz);
mreal MGL_EXPORT mgl_data_spline_ext_(uintptr_t *dat, mreal *x,mreal *y,mreal *z, mreal *dx,mreal *dy,mreal *dz);
/// Prepare coefficients for global spline interpolation
HMDT MGL_EXPORT mgl_gspline_init(HCDT x, HCDT v);
uintptr_t MGL_EXPORT mgl_gspline_init_(uintptr_t *x, uintptr_t *v);
/// Evaluate global spline (and its derivatives d1, d2 if not NULL) using prepared coefficients \a coef
mreal MGL_EXPORT mgl_gspline(HCDT coef, mreal dx, mreal *d1, mreal *d2);
mreal MGL_EXPORT mgl_gspline_(uintptr_t *c, mreal *dx, mreal *d1, mreal *d2);
/// Return an approximated x-value (root) when dat(x) = val
mreal MGL_EXPORT mgl_data_solve_1d(HCDT dat, mreal val, int spl, long i0);
mreal MGL_EXPORT mgl_data_solve_1d_(uintptr_t *dat, mreal *val, int *spl, int *i0);
/// Return an approximated value (root) when dat(x) = val
HMDT MGL_EXPORT mgl_data_solve(HCDT dat, mreal val, char dir, HCDT i0, int norm);
uintptr_t MGL_EXPORT mgl_data_solve_(uintptr_t *dat, mreal *val, const char *dir, uintptr_t *i0, int *norm,int);

/// Get trace of the data array
HMDT MGL_EXPORT mgl_data_trace(HCDT d);
uintptr_t MGL_EXPORT mgl_data_trace_(uintptr_t *d);
/// Resize the data to new sizes
HMDT MGL_EXPORT mgl_data_resize(HCDT dat, long mx,long my,long mz);
uintptr_t MGL_EXPORT mgl_data_resize_(uintptr_t *dat, int *mx,int *my,int *mz);
/// Resize the data to new sizes of box [x1,x2]*[y1,y2]*[z1,z2]
HMDT MGL_EXPORT mgl_data_resize_box(HCDT dat, long mx,long my,long mz,mreal x1,mreal x2,mreal y1,mreal y2,mreal z1,mreal z2);
uintptr_t MGL_EXPORT mgl_data_resize_box_(uintptr_t *dat, int *mx,int *my,int *mz,mreal *x1,mreal *x2,mreal *y1,mreal *y2,mreal *z1,mreal *z2);
/// Create n-th points distribution of this data values in range [v1, v2]
HMDT MGL_EXPORT mgl_data_hist(HCDT dat, long n, mreal v1, mreal v2, long nsub);
uintptr_t MGL_EXPORT mgl_data_hist_(uintptr_t *dat, int *n, mreal *v1, mreal *v2, int *nsub);
/// Create n-th points distribution of this data values in range [v1, v2] with weight w
HMDT MGL_EXPORT mgl_data_hist_w(HCDT dat, HCDT weight, long n, mreal v1, mreal v2, long nsub);
uintptr_t MGL_EXPORT mgl_data_hist_w_(uintptr_t *dat, uintptr_t *weight, int *n, mreal *v1, mreal *v2, int *nsub);
/// Get momentum (1D-array) of data along direction 'dir'. String looks like "x1" for median in x-direction, "x2" for width in x-dir and so on.
HMDT MGL_EXPORT mgl_data_momentum(HCDT dat, char dir, const char *how);
uintptr_t MGL_EXPORT mgl_data_momentum_(uintptr_t *dat, char *dir, const char *how, int,int);
/// Get pulse properties: pulse maximum and its position, pulse duration near maximum and by half height.
HMDT MGL_EXPORT mgl_data_pulse(HCDT dat, char dir);
uintptr_t MGL_EXPORT mgl_data_pulse_(uintptr_t *dat, char *dir,int);
/// Get array which values is result of interpolation this for coordinates from other arrays
HMDT MGL_EXPORT mgl_data_evaluate(HCDT dat, HCDT idat, HCDT jdat, HCDT kdat, int norm);
uintptr_t MGL_EXPORT mgl_data_evaluate_(uintptr_t *dat, uintptr_t *idat, uintptr_t *jdat, uintptr_t *kdat, int *norm);
/// Set as the data envelop
void MGL_EXPORT mgl_data_envelop(HMDT dat, char dir);
void MGL_EXPORT mgl_data_envelop_(uintptr_t *dat, const char *dir, int);
/// Remove phase jump
void MGL_EXPORT mgl_data_sew(HMDT dat, const char *dirs, mreal da);
void MGL_EXPORT mgl_data_sew_(uintptr_t *dat, const char *dirs, mreal *da, int);
/// Crop the data
void MGL_EXPORT mgl_data_crop(HMDT dat, long n1, long n2, char dir);
void MGL_EXPORT mgl_data_crop_(uintptr_t *dat, int *n1, int *n2, const char *dir,int);
/// Crop the data to be most optimal for FFT (i.e. to closest value of 2^n*3^m*5^l)
void MGL_EXPORT mgl_data_crop_opt(HMDT dat, const char *how);
void MGL_EXPORT mgl_data_crop_opt_(uintptr_t *dat, const char *how,int);
/// Remove rows with duplicate values in column id
void MGL_EXPORT mgl_data_clean(HMDT dat, long id);
void MGL_EXPORT mgl_data_clean_(uintptr_t *dat, int *id);

/// Multiply the data by other one for each element
void MGL_EXPORT mgl_data_mul_dat(HMDT dat, HCDT d);
void MGL_EXPORT mgl_data_mul_dat_(uintptr_t *dat, uintptr_t *d);
/// Divide the data by other one for each element
void MGL_EXPORT mgl_data_div_dat(HMDT dat, HCDT d);
void MGL_EXPORT mgl_data_div_dat_(uintptr_t *dat, uintptr_t *d);
/// Add the other data
void MGL_EXPORT mgl_data_add_dat(HMDT dat, HCDT d);
void MGL_EXPORT mgl_data_add_dat_(uintptr_t *dat, uintptr_t *d);
/// Subtract the other data
void MGL_EXPORT mgl_data_sub_dat(HMDT dat, HCDT d);
void MGL_EXPORT mgl_data_sub_dat_(uintptr_t *dat, uintptr_t *d);
/// Multiply each element by the number
void MGL_EXPORT mgl_data_mul_num(HMDT dat, mreal d);
void MGL_EXPORT mgl_data_mul_num_(uintptr_t *dat, mreal *d);
/// Divide each element by the number
void MGL_EXPORT mgl_data_div_num(HMDT dat, mreal d);
void MGL_EXPORT mgl_data_div_num_(uintptr_t *dat, mreal *d);
/// Add the number
void MGL_EXPORT mgl_data_add_num(HMDT dat, mreal d);
void MGL_EXPORT mgl_data_add_num_(uintptr_t *dat, mreal *d);
/// Subtract the number
void MGL_EXPORT mgl_data_sub_num(HMDT dat, mreal d);
void MGL_EXPORT mgl_data_sub_num_(uintptr_t *dat, mreal *d);

/// Integral data transformation (like Fourier 'f' or 'i', Hankel 'h' or None 'n') for amplitude and phase
HMDT MGL_EXPORT mgl_transform_a(HCDT am, HCDT ph, const char *tr);
uintptr_t MGL_EXPORT mgl_transform_a_(uintptr_t *am, uintptr_t *ph, const char *tr, int);
/// Integral data transformation (like Fourier 'f' or 'i', Hankel 'h' or None 'n') for real and imaginary parts
HMDT MGL_EXPORT mgl_transform(HCDT re, HCDT im, const char *tr);
uintptr_t MGL_EXPORT mgl_transform_(uintptr_t *re, uintptr_t *im, const char *tr, int);
/// Apply Fourier transform for the data and save result into it
void MGL_EXPORT mgl_data_fourier(HMDT re, HMDT im, const char *dir);
void MGL_EXPORT mgl_data_fourier_(uintptr_t *re, uintptr_t *im, const char *dir, int l);
/// Short time Fourier analysis for real and imaginary parts. Output is amplitude of partial Fourier (result will have size {dn, floor(nx/dn), ny} for dir='x'
HMDT MGL_EXPORT mgl_data_stfa(HCDT re, HCDT im, long dn, char dir);
uintptr_t MGL_EXPORT mgl_data_stfa_(uintptr_t *re, uintptr_t *im, int *dn, char *dir, int);

/// Do something like Delone triangulation for 3d points
HMDT MGL_EXPORT mgl_triangulation_3d(HCDT x, HCDT y, HCDT z);
uintptr_t MGL_EXPORT mgl_triangulation_3d_(uintptr_t *x, uintptr_t *y, uintptr_t *z);
/// Do Delone triangulation for 2d points
HMDT MGL_EXPORT mgl_triangulation_2d(HCDT x, HCDT y);
uintptr_t MGL_EXPORT mgl_triangulation_2d_(uintptr_t *x, uintptr_t *y);

/// Find root for nonlinear equation
mreal MGL_EXPORT mgl_find_root(mreal (*func)(mreal val, void *par), mreal ini, void *par);
/// Find root for nonlinear equation defined by textual formula
mreal MGL_EXPORT mgl_find_root_txt(const char *func, mreal ini, char var_id);
mreal MGL_EXPORT mgl_find_root_txt_(const char *func, mreal *ini, const char *var_id,int,int);
/// Find roots for nonlinear equation defined by textual formula
HMDT MGL_EXPORT mgl_data_roots(const char *func, HCDT ini, char var_id);
uintptr_t MGL_EXPORT mgl_data_roots_(const char *func, uintptr_t *ini, const char *var_id,int,int);
/// Find roots for set of nonlinear equations defined by textual formulas
HMDT MGL_EXPORT mgl_find_roots_txt(const char *func, const char *vars, HCDT ini);
uintptr_t MGL_EXPORT mgl_find_roots_txt_(const char *func, const char *vars, uintptr_t *ini,int,int);
/// Find roots for set of nonlinear equations defined by function
int MGL_EXPORT mgl_find_roots(size_t n, void (*func)(const mreal *x, mreal *f, void *par), mreal *x0, void *par);
//-----------------------------------------------------------------------------
#ifdef __cplusplus
}
#endif
#endif
//-----------------------------------------------------------------------------

max_stars_repo_name: dickensas/kotlin-gradle-templates

max_issues_repo_name: dickensas/kotlin-gradle-templates

max_forks_repo_name: dickensas/kotlin-gradle-templates


text:
/**
 *  Copyright (C) 2021 FISCO BCOS.
 *  SPDX-License-Identifier: Apache-2.0
 *  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.
 *
 * @brief implementation for BlockHeader
 * @file BlockHeaderImpl.h
 * @author: ancelmo
 * @date 2021-04-20
 */

#pragma once
#include "bcos-tars-protocol/Common.h"
#include "bcos-tars-protocol/tars/Block.h"
#include <bcos-framework/interfaces/crypto/CommonType.h>
#include <bcos-framework/interfaces/crypto/CryptoSuite.h>
#include <bcos-framework/interfaces/protocol/BlockHeader.h>
#include <bcos-framework/interfaces/protocol/ProtocolTypeDef.h>
#include <gsl/span>

namespace bcostars
{
namespace protocol
{
class BlockHeaderImpl : public bcos::protocol::BlockHeader
{
public:
    virtual ~BlockHeaderImpl() {}

    BlockHeaderImpl() = delete;

    BlockHeaderImpl(
        bcos::crypto::CryptoSuite::Ptr cryptoSuite, std::function<bcostars::BlockHeader*()> inner)
      : bcos::protocol::BlockHeader(cryptoSuite), m_inner(inner)
    {}

    void decode(bcos::bytesConstRef _data) override;
    void encode(bcos::bytes& _encodeData) const override;
    bcos::crypto::HashType hash() const override;

    void clear() override;

    int32_t version() const override { return m_inner()->data.version; }
    gsl::span<const bcos::protocol::ParentInfo> parentInfo() const override;

    bcos::crypto::HashType txsRoot() const override;
    bcos::crypto::HashType stateRoot() const override;
    bcos::crypto::HashType receiptsRoot() const override;
    bcos::protocol::BlockNumber number() const override { return m_inner()->data.blockNumber; }
    bcos::u256 gasUsed() const override;
    int64_t timestamp() const override { return m_inner()->data.timestamp; }
    int64_t sealer() const override { return m_inner()->data.sealer; }

    gsl::span<const bcos::bytes> sealerList() const override
    {
        return gsl::span(reinterpret_cast<const bcos::bytes*>(m_inner()->data.sealerList.data()),
            m_inner()->data.sealerList.size());
    }
    bcos::bytesConstRef extraData() const override
    {
        return bcos::bytesConstRef(
            reinterpret_cast<const bcos::byte*>(m_inner()->data.extraData.data()),
            m_inner()->data.extraData.size());
    }
    gsl::span<const bcos::protocol::Signature> signatureList() const override
    {
        return gsl::span(
            reinterpret_cast<const bcos::protocol::Signature*>(m_inner()->signatureList.data()),
            m_inner()->signatureList.size());
    }

    gsl::span<const uint64_t> consensusWeights() const override
    {
        return gsl::span(reinterpret_cast<const uint64_t*>(m_inner()->data.consensusWeights.data()),
            m_inner()->data.consensusWeights.size());
    }

    void setVersion(int32_t _version) override { m_inner()->data.version = _version; }

    void setParentInfo(gsl::span<const bcos::protocol::ParentInfo> const& _parentInfo) override;

    void setParentInfo(bcos::protocol::ParentInfoList&& _parentInfo) override
    {
        setParentInfo(gsl::span(_parentInfo.data(), _parentInfo.size()));
    }

    void setTxsRoot(bcos::crypto::HashType _txsRoot) override
    {
        m_inner()->data.txsRoot.assign(_txsRoot.begin(), _txsRoot.end());
    }
    void setReceiptsRoot(bcos::crypto::HashType _receiptsRoot) override
    {
        m_inner()->data.receiptRoot.assign(_receiptsRoot.begin(), _receiptsRoot.end());
    }
    void setStateRoot(bcos::crypto::HashType _stateRoot) override
    {
        m_inner()->data.stateRoot.assign(_stateRoot.begin(), _stateRoot.end());
    }
    void setNumber(bcos::protocol::BlockNumber _blockNumber) override
    {
        m_inner()->data.blockNumber = _blockNumber;
    }
    void setGasUsed(bcos::u256 _gasUsed) override
    {
        m_inner()->data.gasUsed = boost::lexical_cast<std::string>(_gasUsed);
    }
    void setTimestamp(int64_t _timestamp) override { m_inner()->data.timestamp = _timestamp; }
    void setSealer(int64_t _sealerId) override { m_inner()->data.sealer = _sealerId; }
    void setSealerList(gsl::span<const bcos::bytes> const& _sealerList) override;
    void setSealerList(std::vector<bcos::bytes>&& _sealerList) override
    {
        setSealerList(gsl::span(_sealerList.data(), _sealerList.size()));
    }

    void setConsensusWeights(gsl::span<const uint64_t> const& _weightList) override
    {
        m_inner()->data.consensusWeights.assign(_weightList.begin(), _weightList.end());
    }

    void setConsensusWeights(std::vector<uint64_t>&& _weightList) override
    {
        setConsensusWeights(gsl::span(_weightList.data(), _weightList.size()));
    }

    void setExtraData(bcos::bytes const& _extraData) override
    {
        m_inner()->data.extraData.assign(_extraData.begin(), _extraData.end());
    }
    void setExtraData(bcos::bytes&& _extraData) override
    {
        m_inner()->data.extraData.assign(_extraData.begin(), _extraData.end());
    }
    void setSignatureList(
        gsl::span<const bcos::protocol::Signature> const& _signatureList) override;

    void setSignatureList(bcos::protocol::SignatureList&& _signatureList) override
    {
        setSignatureList(gsl::span(_signatureList.data(), _signatureList.size()));
    }

    const bcostars::BlockHeader& inner() const { return *m_inner(); }

    void setInner(const bcostars::BlockHeader& blockHeader) { *m_inner() = blockHeader; }
    void setInner(bcostars::BlockHeader&& blockHeader) { *m_inner() = std::move(blockHeader); }

private:
    std::function<bcostars::BlockHeader*()> m_inner;
    mutable std::vector<bcos::protocol::ParentInfo> m_parentInfo;
};
}  // namespace protocol
}  // namespace bcostars


text:
/*
 * Copyright (c) 2016-2021 lymastee, All rights reserved.
 * Contact: lymastee@hotmail.com
 *
 * This file is part of the gslib project.
 *
 * 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

#ifndef typeof_027722a0_eb51_4e04_8f59_b9299ee17be6_h
#define typeof_027722a0_eb51_4e04_8f59_b9299ee17be6_h

#include <gslib/type.h>

__gslib_begin__

#define gs_register_typeof_bs(t) \
    template<> \
    struct typeof<t*> { typedef t type; }; \
    template<> \
    struct typeof<const t*> { typedef t type; };

#define gs_register_typeof(q, t) \
    q t; /* for announcement. */ \
    gs_register_typeof_bs(t);

#define gs_register_typeof_ns(ns, q, t) \
    namespace ns { \
        q t; /* for announcement. */ \
    }; \
    gs_register_typeof_bs(ns::t);

/* all pointer typeof operator should be registered here. */
gs_register_typeof_bs(int8);
gs_register_typeof_bs(int16);
gs_register_typeof_bs(int);
gs_register_typeof_bs(int64);
gs_register_typeof_bs(wchar);
gs_register_typeof_bs(real32);
gs_register_typeof_bs(real);
gs_register_typeof_bs(byte);
gs_register_typeof_bs(word);
gs_register_typeof_bs(dword);
gs_register_typeof_bs(qword);
gs_register_typeof_ns(rathen, struct, ps_data);
gs_register_typeof_ns(rathen, struct, ps_ref);
gs_register_typeof_ns(rathen, struct, ps_stdata);
gs_register_typeof_ns(rathen, struct, ps_stref);
gs_register_typeof_ns(ariel, class, button);
/* more to come ... */

__gslib_end__

#endif

max_stars_repo_name: lymastee/gslib

max_issues_repo_name: lymastee/gslib

max_forks_repo_name: lymastee/gslib


text:
// Copyright 2011-2021 GameParadiso, Inc. All Rights Reserved.

#pragma once

#include <conio.h>

#include <map>
#include <unordered_set>
#include <unordered_map>
#include <ranges>
#include <iostream>
#include <sstream>
#include <chrono>
#include <random>
#include <thread>

#define FMT_HEADER_ONLY
#include <fmt/format.h>

#define GLM_FORCE_MESSAGES
#define GLM_FORCE_INLINE
#define GLM_FORCE_EXPLICIT_CTOR
#define GLM_FORCE_ALIGNED_GENTYPES
#define GLM_FORCE_INTRINSICS
#include <glm/glm.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/ext/matrix_transform.hpp>
#include <glm/ext/matrix_clip_space.hpp>
#include <glm/gtx/matrix_decompose.hpp>
#include <glm/ext/scalar_constants.hpp>
#include <glm/gtc/type_aligned.hpp>

#include <gsl/gsl>

#include "Mathmatics.h"
#include "Util.h"

constexpr uint32_t NumEntities = 50000;

max_stars_repo_name: noirhero/MemoryChunkProfile

max_issues_repo_name: noirhero/MemoryChunkProfile

max_forks_repo_name: noirhero/MemoryChunkProfile


text:
/* spoper.c
 *
 * Copyright (C) 2012 Patrick Alken
 *
 * 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 3 of the License, or (at
 * your option) any later version.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <config.h>
#include <stdlib.h>
#include <math.h>

#include <gsl/gsl_math.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_spmatrix.h>
#include <gsl/gsl_spblas.h>

int
gsl_spmatrix_scale(gsl_spmatrix *m, const double x)
{
  size_t i;

  for (i = 0; i < m->nz; ++i)
    m->data[i] *= x;

  return GSL_SUCCESS;
} /* gsl_spmatrix_scale() */

int
gsl_spmatrix_minmax(const gsl_spmatrix *m, double *min_out, double *max_out)
{
  double min, max;
  size_t n;

  if (m->nz == 0)
    {
      GSL_ERROR("matrix is empty", GSL_EINVAL);
    }

  min = m->data[0];
  max = m->data[0];

  for (n = 1; n < m->nz; ++n)
    {
      double x = m->data[n];

      if (x < min)
        min = x;

      if (x > max)
        max = x;
    }

  *min_out = min;
  *max_out = max;

  return GSL_SUCCESS;
} /* gsl_spmatrix_minmax() */

/*
gsl_spmatrix_add()
  Add two sparse matrices

Inputs: c - (output) a + b
        a - (input) sparse matrix
        b - (input) sparse matrix

Return: success or error
*/

int
gsl_spmatrix_add(gsl_spmatrix *c, const gsl_spmatrix *a,
                 const gsl_spmatrix *b)
{
  const size_t M = a->size1;
  const size_t N = a->size2;

  if (b->size1 != M || b->size2 != N || c->size1 != M || c->size2 != N)
    {
      GSL_ERROR("matrices must have same dimensions", GSL_EBADLEN);
    }
  else if (a->sptype != b->sptype || a->sptype != c->sptype)
    {
      GSL_ERROR("matrices must have same sparse storage format",
                GSL_EINVAL);
    }
  else if (GSL_SPMATRIX_ISTRIPLET(a))
    {
      GSL_ERROR("triplet format not yet supported", GSL_EINVAL);
    }
  else
    {
      int status = GSL_SUCCESS;
      size_t *w = (size_t *) a->work;
      double *x = (double *) b->work;
      size_t *Cp, *Ci;
      double *Cd;
      size_t j, p;
      size_t nz = 0; /* number of non-zeros in c */
      size_t inner_size, outer_size;

      if (GSL_SPMATRIX_ISCCS(a))
        {
          inner_size = M;
          outer_size = N;
        }
      else if (GSL_SPMATRIX_ISCRS(a))
        {
          inner_size = N;
          outer_size = M;
        }
      else
        {
          GSL_ERROR("unknown sparse matrix type", GSL_EINVAL);
        }

      if (c->nzmax < a->nz + b->nz)
        {
          status = gsl_spmatrix_realloc(a->nz + b->nz, c);
          if (status)
            return status;
        }

      /* initialize w = 0 */
      for (j = 0; j < inner_size; ++j)
        w[j] = 0;

      Ci = c->i;
      Cp = c->p;
      Cd = c->data;

      for (j = 0; j < outer_size; ++j)
        {
          Cp[j] = nz;

          /* CCS: x += A(:,j); CRS: x += A(j,:) */
          nz = gsl_spblas_scatter(a, j, 1.0, w, x, j + 1, c, nz);

          /* CCS: x += B(:,j); CRS: x += B(j,:) */
          nz = gsl_spblas_scatter(b, j, 1.0, w, x, j + 1, c, nz);

          for (p = Cp[j]; p < nz; ++p)
            Cd[p] = x[Ci[p]];
        }

      /* finalize last column of c */
      Cp[j] = nz;
      c->nz = nz;

      return status;
    }
} /* gsl_spmatrix_add() */

/*
gsl_spmatrix_d2sp()
  Convert a dense gsl_matrix to sparse (triplet) format

Inputs: S - (output) sparse matrix in triplet format
        A - (input) dense matrix to convert
*/

int
gsl_spmatrix_d2sp(gsl_spmatrix *S, const gsl_matrix *A)
{
  int s = GSL_SUCCESS;
  size_t i, j;

  gsl_spmatrix_set_zero(S);
  S->size1 = A->size1;
  S->size2 = A->size2;

  for (i = 0; i < A->size1; ++i)
    {
      for (j = 0; j < A->size2; ++j)
        {
          double x = gsl_matrix_get(A, i, j);

          if (x != 0.0)
            gsl_spmatrix_set(S, i, j, x);
        }
    }

  return s;
} /* gsl_spmatrix_d2sp() */

/*
gsl_spmatrix_sp2d()
  Convert a sparse matrix to dense format
*/

int
gsl_spmatrix_sp2d(gsl_matrix *A, const gsl_spmatrix *S)
{
  if (A->size1 != S->size1 || A->size2 != S->size2)
    {
      GSL_ERROR("matrix sizes do not match", GSL_EBADLEN);
    }
  else
    {
      gsl_matrix_set_zero(A);

      if (GSL_SPMATRIX_ISTRIPLET(S))
        {
          size_t n;

          for (n = 0; n < S->nz; ++n)
            {
              size_t i = S->i[n];
              size_t j = S->p[n];
              double x = S->data[n];

              gsl_matrix_set(A, i, j, x);
            }
        }
      else
        {
          GSL_ERROR("non-triplet formats not yet supported", GSL_EINVAL);
        }

      return GSL_SUCCESS;
    }
} /* gsl_spmatrix_sp2d() */

max_issues_repo_name: Brian-ning/HMNE

max_forks_repo_name: Brian-ning/HMNE