text:
/*
    Copyright (c) 2013, Taiga Nomi and the respective contributors
    All rights reserved.

    Use of this source code is governed by a BSD-style license that can be found
    in the LICENSE file.
*/
#pragma once

#include "tiny_dnn/core/params/fully_params.h"

#ifdef CNN_USE_CBLAS
extern "C" {
#include <cblas.h>
}
#endif

namespace tiny_dnn {
namespace kernels {

inline void fully_connected_op_cblas(const tensor_t &in_data,
                                     const vec_t &W,
                                     const vec_t &bias,
                                     tensor_t &out_data,
                                     const core::fully_params &params,
                                     const bool layer_parallelize) {
#ifdef CNN_USE_CBLAS
  size_t out_size       = params.out_size_;
  size_t in_size        = params.in_size_;
  float_t alpha         = 1;
  float_t beta          = 1;
  const float_t *input  = in_data[0].data();
  const float_t *weight = W.data();
  float_t *output       = out_data[0].data();
  if (bias.empty())
    memset(output, 0, sizeof(float_t) * out_size);
  else
    memcpy(output, bias.data(), sizeof(float_t) * out_size);
#ifdef CNN_USE_DOUBLE
  cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 1, out_size, in_size,
              alpha, input, in_size, weight, out_size, beta, output, out_size);
#else
  cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 1, out_size, in_size,
              alpha, input, in_size, weight, out_size, beta, output, out_size);
#endif

#endif  // CNN_USE_CBLAS
}

}  // namespace kernels
}  // namespace tiny_dnn

max_issues_repo_name: stillwater-sc/tiny-dnn

max_forks_repo_name: stillwater-sc/tiny-dnn


text:
/* permutation/test.c
 *
 * Copyright (C) 2000 Brian Gough
 *
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_permutation.h>
#include <gsl/gsl_test.h>

unsigned int p5[120][5] = {
  {0, 1, 2, 3, 4}, {0, 1, 2, 4, 3}, {0, 1, 3, 2, 4}, {0, 1, 3, 4, 2},
  {0, 1, 4, 2, 3}, {0, 1, 4, 3, 2}, {0, 2, 1, 3, 4}, {0, 2, 1, 4, 3},
  {0, 2, 3, 1, 4}, {0, 2, 3, 4, 1}, {0, 2, 4, 1, 3}, {0, 2, 4, 3, 1},
  {0, 3, 1, 2, 4}, {0, 3, 1, 4, 2}, {0, 3, 2, 1, 4}, {0, 3, 2, 4, 1},
  {0, 3, 4, 1, 2}, {0, 3, 4, 2, 1}, {0, 4, 1, 2, 3}, {0, 4, 1, 3, 2},
  {0, 4, 2, 1, 3}, {0, 4, 2, 3, 1}, {0, 4, 3, 1, 2}, {0, 4, 3, 2, 1},
  {1, 0, 2, 3, 4}, {1, 0, 2, 4, 3}, {1, 0, 3, 2, 4}, {1, 0, 3, 4, 2},
  {1, 0, 4, 2, 3}, {1, 0, 4, 3, 2}, {1, 2, 0, 3, 4}, {1, 2, 0, 4, 3},
  {1, 2, 3, 0, 4}, {1, 2, 3, 4, 0}, {1, 2, 4, 0, 3}, {1, 2, 4, 3, 0},
  {1, 3, 0, 2, 4}, {1, 3, 0, 4, 2}, {1, 3, 2, 0, 4}, {1, 3, 2, 4, 0},
  {1, 3, 4, 0, 2}, {1, 3, 4, 2, 0}, {1, 4, 0, 2, 3}, {1, 4, 0, 3, 2},
  {1, 4, 2, 0, 3}, {1, 4, 2, 3, 0}, {1, 4, 3, 0, 2}, {1, 4, 3, 2, 0},
  {2, 0, 1, 3, 4}, {2, 0, 1, 4, 3}, {2, 0, 3, 1, 4}, {2, 0, 3, 4, 1},
  {2, 0, 4, 1, 3}, {2, 0, 4, 3, 1}, {2, 1, 0, 3, 4}, {2, 1, 0, 4, 3},
  {2, 1, 3, 0, 4},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;

int
main (void)
{
  int i = 0, j, status = 0;
  gsl_permutation * p ;

  p = gsl_permutation_alloc (5);

  gsl_permutation_init (p);

  do
    {
      for (j = 0; j < 5; j++)
        {
          status |= (p->data[j] != p5[i][j]);
        }

      i++;
    }
  while (gsl_permutation_next(p) == GSL_SUCCESS);

  gsl_test(status, "gsl_permutation_next, 5-th order permutation, 120 steps");

  do
    {
      i--;

      for (j = 0; j < 5; j++)
        {
          status |= (p->data[j] != p5[i][j]);
        }
    }
  while (gsl_permutation_prev(p) == GSL_SUCCESS);

  gsl_test(status, "gsl_permutation_prev, 5-th order permutation, 120 steps");

  gsl_permutation_free (p);

  exit (gsl_test_summary());
}

ext: c


text:
#ifndef __INCLUDE_EMUPLUSPLUS__
#define __INCLUDE_EMUPLUSPLUS__

#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <string>
#include <vector>

extern "C"{
 #include "multi_modelstruct.h"
 #include "multivar_support.h"
}

using namespace std;

/**
 * @file emuplusplus.h
 * \brief a simple c++ interface to a trained emulator
 *
 * Instance of the emulator class are built from a trained emulator,
 * the emulator can then be sampled at a point in the parameter space by the function QueryEmulator
 *
 * They must be initialized from an interactive_emulator statefile, this includes all the data for
 * a trained emulator
 *
 */

class emulator{
 public:
	emulator(string StateFilePath); // default constructor will return Y values
	emulator(string StateFilePath, bool PcaOnly);
	~emulator();

	/** query the emulator with a vector xpoint in the parameter space
	 * could add a method to output the means, errors and a covaraince matrix */
		void QueryEmulator(const vector<double> &xpoint, vector<double> &Means, vector<double> &Errors);

	/**
	 * get the emulator pca decomp
	 */
	void getEmulatorPCA(vector<double> *pca_evals, vector< vector<double> > *pca_evecs, vector<double> *pca_mean);

	int getRegressionOrder(void){return(the_model->regression_order);};
	int getCovFnIndex(void){return(the_model->cov_fn_index);};

	int number_params;
	int number_outputs;

 private:

	// if true the values are output in the pca space, otherwise they're in the real space
	bool outputPCAValues;
	string StateFilePath;
	multi_modelstruct *the_model;  // the c structure which defines the model
	multi_emulator *the_emulator; // the c structure which defines the emulator

	gsl_vector *the_emulate_point;
	gsl_vector *the_emulate_mean;
	gsl_vector *the_emulate_var;

};

#endif

ext: h

max_stars_repo_name: jackdawjackdaw/emulator

max_issues_repo_name: MADAI/MADAIEmulator

max_forks_repo_name: MADAI/MADAIEmulator


text:
/*
 * Copyright 2020 Makani Technologies LLC
 *
 * 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.
 */

#ifndef SIM_MODELS_SENSORS_LOADCELL_H_
#define SIM_MODELS_SENSORS_LOADCELL_H_

#include <gsl/gsl_vector.h>
#include <stdint.h>
#include <functional>
#include <vector>

#include "common/c_math/vec2.h"
#include "common/c_math/vec3.h"
#include "common/macros.h"
#include "control/system_types.h"
#include "sim/faults/faults.h"
#include "sim/models/sensors/sensor.h"
#include "sim/models/signals/measurement.h"
#include "sim/sim_messages.h"

namespace sim {

void TetherForceToLoadcells(const WingParams &wing_params,
                            const LoadcellParams loadcell_params[],
                            const Vec3 &tether_force_b,
                            double loadcell_forces[]);

}  // namespace sim

class Loadcell : public Sensor {
  friend class LoadcellTest;

 public:
  Loadcell(const LoadcellParams *loadcell_params,
           const LoadcellSimParams &loadcell_sim_params,
           const WingParams &wing_params, FaultSchedule *faults);
  ~Loadcell() {}

  void UpdateSensorOutputs(SimSensorMessage *sensor_message,
                           TetherUpMessage * /*tether_up*/) const override;
  void Publish() const override;

  void set_Fb_tether(const Vec3 &val) { Fb_tether_.set_val(val); }
  void set_tether_released(bool val) { tether_released_.set_val(val); }

 private:
  void DiscreteStepHelper(double t) override;

  double tensions(int32_t i) const { return tensions_[i].recorded(); }
  const Vec3 &Fb_tether() const { return Fb_tether_.val(); }

  // Loadcell parameters.
  const LoadcellParams *loadcell_params_;
  const LoadcellSimParams &loadcell_sim_params_;
  const WingParams &wing_params_;

  // Input states.
  State<Vec3> Fb_tether_;
  State<bool> tether_released_;

  // Discrete state.
  std::vector<DiscreteState<double>> actual_tensions_;

  // Sub-models.
  std::vector<Measurement<double>> tensions_;

  DISALLOW_COPY_AND_ASSIGN(Loadcell);
};

#endif  // SIM_MODELS_SENSORS_LOADCELL_H_


text:
#include <stdio.h>
#include <gsl/gsl_spline.h>
#include <gsl/gsl_const_cgsm.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_math.h>
#include "global.h"
#include "eos_pres.h"
#include "eos_rho.h"
#include "param.h"

// the system of ODEs to be integrated
int
func (double r, const double y[], double f[], void *params)
{
  struct param *myparams = (struct param *) params;
  double (*pres) (double, void *);	// EOS pressure pointer
  double (*rho) (double, void *);	// EOS density pointer
  pres = &eos_pres;
  rho = &eos_rho;

// set a minimum pressure cutoff. if we don't, the ODE solver will wobble all
// over the surface and crash, or if you make the error tolerance really strict
// it'll integrate forever
  if (y[1] < 1.0e-9 * myparams->pinit)
    {
      if (myparams->single_star == 0)
	{
	  printf ("surface reached!\n");
	  printf ("%12s %12s %12s\n", "R (km)", "M (M_sun)",
		  "rho(0) (g/cm^3)");
	}
      printf ("%12le %12le %12le\n", r / 1.0e+5,
	      y[0] / GSL_CONST_CGSM_SOLAR_MASS, myparams->rho_init);
      return GSL_EBADFUNC;	// this flag tells GSL integrator to quit
    }
  // for a single star we can print M, P and rho as functions of r

  if (myparams->single_star == 0)
    {
      printf ("%12le %12le %12le %12le\n", r / 1.0e+5,
	      y[0] / GSL_CONST_CGSM_SOLAR_MASS, y[1], rho (y[1], myparams));
    }

  // mass conservation equation
  f[0] = 4.0 * M_PI * pow (r, 2.0) * rho (y[1], myparams);

  // TOV equation
  f[1] = -(GSL_CONST_CGSM_GRAVITATIONAL_CONSTANT / pow (r, 2.0))
    * (rho (y[1], myparams)
       + (y[1] / pow (GSL_CONST_CGSM_SPEED_OF_LIGHT, 2.0)))
    * (y[0] + 4 * M_PI * pow (r, 3.0)
       * y[1] / pow (GSL_CONST_CGSM_SPEED_OF_LIGHT, 2.0))
    / (1.0 - (2.0 * GSL_CONST_CGSM_GRAVITATIONAL_CONSTANT * y[0]
	      / (pow (GSL_CONST_CGSM_SPEED_OF_LIGHT, 2.0) * r)));

  // ODEs tend to return NaNs at the same radius where P < 0
  if ((gsl_isnan (f[0]) || gsl_isnan (f[1])))
    {
      /* print values at the radius where ODEs diverge. this is almost
         always at the surface */
      printf ("%12f %12f %12f\n", r / 1.0e+5,
	      y[0] / GSL_CONST_CGSM_SOLAR_MASS, myparams->rho_init);
      return GSL_EBADFUNC;
    }

  return GSL_SUCCESS;
}