forked from GalSim-developers/GalSim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cd4cdc
commit a360402
Showing
9 changed files
with
683 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* -*- c++ -*- | ||
* Copyright (c) 2012-2018 by the GalSim developers team on GitHub | ||
* https://github.com/GalSim-developers | ||
* | ||
* This file is part of GalSim: The modular galaxy image simulation toolkit. | ||
* https://github.com/GalSim-developers/GalSim | ||
* | ||
* GalSim is free software: 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 disclaimer given in the accompanying LICENSE | ||
* file. | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions, and the disclaimer given in the documentation | ||
* and/or other materials provided with the distribution. | ||
*/ | ||
|
||
#ifndef GalSim_TableOld_H | ||
#define GalSim_TableOld_H | ||
|
||
#include <vector> | ||
#include <algorithm> | ||
#include <string> | ||
#include <sstream> | ||
#include <stdexcept> | ||
#include <iostream> | ||
#include <functional> | ||
|
||
#include "Std.h" | ||
#include "OneDimensionalDeviate.h" | ||
|
||
namespace galsim { | ||
|
||
/** | ||
* @brief A class to represent lookup tables for a function z = f(x, y). | ||
*/ | ||
class Table2DOld | ||
{ | ||
public: | ||
enum interpolant { linear, floor, ceil, nearest }; | ||
|
||
/// Table from xargs, yargs, vals | ||
Table2DOld(const double* xargs, const double* yargs, const double* vals, | ||
int Nx, int Ny, interpolant in); | ||
|
||
/// interp, but exception if beyond bounds | ||
double lookup(double x, double y) const; | ||
|
||
/// interp many values at once | ||
void interpMany(const double* xvec, const double* yvec, double* valvec, int N) const; | ||
void interpManyMesh(const double* xvec, const double* yvec, double* valvec, | ||
int outNx, int outNy) const; | ||
|
||
/// Estimate df/dx, df/dy at a single location | ||
void gradient(double x, double y, double& dfdxvec, double& dfdyvec) const; | ||
|
||
/// Estimate many df/dx and df/dy values | ||
void gradientMany(const double* xvec, const double* yvec, | ||
double* dfdxvec, double* dfdyvec, int N) const; | ||
|
||
protected: | ||
class Table2DOldImpl; | ||
shared_ptr<Table2DOldImpl> _pimpl; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* -*- c++ -*- | ||
* Copyright (c) 2012-2018 by the GalSim developers team on GitHub | ||
* https://github.com/GalSim-developers | ||
* | ||
* This file is part of GalSim: The modular galaxy image simulation toolkit. | ||
* https://github.com/GalSim-developers/GalSim | ||
* | ||
* GalSim is free software: 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 disclaimer given in the accompanying LICENSE | ||
* file. | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions, and the disclaimer given in the documentation | ||
* and/or other materials provided with the distribution. | ||
*/ | ||
|
||
#include "PyBind11Helper.h" | ||
#include "TableOld.h" | ||
|
||
namespace galsim { | ||
|
||
static Table2DOld* MakeTable2DOld(size_t ix, size_t iy, size_t ivals, int Nx, int Ny, | ||
const char* interp_c) | ||
{ | ||
const double* x = reinterpret_cast<const double*>(ix); | ||
const double* y = reinterpret_cast<const double*>(iy); | ||
const double* vals = reinterpret_cast<const double*>(ivals); | ||
std::string interp(interp_c); | ||
|
||
Table2DOld::interpolant i = Table2DOld::linear; | ||
if (interp == "floor") i = Table2DOld::floor; | ||
else if (interp == "ceil") i = Table2DOld::ceil; | ||
else if (interp == "nearest") i = Table2DOld::nearest; | ||
|
||
return new Table2DOld(x, y, vals, Nx, Ny, i); | ||
} | ||
|
||
static void InterpMany2D(const Table2DOld& Table2DOld, size_t ix, size_t iy, size_t ivals, int N) | ||
{ | ||
const double* x = reinterpret_cast<const double*>(ix); | ||
const double* y = reinterpret_cast<const double*>(iy); | ||
double* vals = reinterpret_cast<double*>(ivals); | ||
Table2DOld.interpMany(x, y, vals, N); | ||
} | ||
|
||
static void Gradient(const Table2DOld& Table2DOld, double x, double y, size_t igrad) | ||
{ | ||
double* grad = reinterpret_cast<double*>(igrad); | ||
Table2DOld.gradient(x, y, grad[0], grad[1]); | ||
} | ||
|
||
static void GradientMany(const Table2DOld& Table2DOld, | ||
size_t ix, size_t iy, size_t idfdx, size_t idfdy, int N) | ||
{ | ||
const double* x = reinterpret_cast<const double*>(ix); | ||
const double* y = reinterpret_cast<const double*>(iy); | ||
double* dfdx = reinterpret_cast<double*>(idfdx); | ||
double* dfdy = reinterpret_cast<double*>(idfdy); | ||
Table2DOld.gradientMany(x, y, dfdx, dfdy, N); | ||
} | ||
|
||
void pyExportTableOld(PY_MODULE& _galsim) | ||
{ | ||
py::class_<Table2DOld>(GALSIM_COMMA "_LookupTable2DOld" BP_NOINIT) | ||
.def(PY_INIT(&MakeTable2DOld)) | ||
.def("interp", &Table2DOld::lookup) | ||
.def("interpMany", &InterpMany2D) | ||
.def("gradient", &Gradient) | ||
.def("gradientMany", &GradientMany); | ||
} | ||
|
||
} // namespace galsim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ Random.cpp | |
HSM.cpp | ||
Integ.cpp | ||
Table.cpp | ||
TableOld.cpp | ||
Interpolant.cpp | ||
Bessel.cpp | ||
CDModel.cpp | ||
|
Oops, something went wrong.