Skip to content

Commit

Permalink
issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed May 8, 2020
1 parent 2f4f357 commit 25f1a3f
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 55 deletions.
67 changes: 67 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (C) 2015 Free Software Foundation, Inc.
#
# 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, see <http://www.gnu.org/licenses/>.

# clang-format 7.0.1 is required
#
# To utilize the tool to lines just touched by a patch, use
# clang-format-diff script that is usually also packaged with clang-format.
#
# Example of usage:
# git diff -U0 --no-color | clang-format-diff -p1
# (here the tool will generate a patch)
# git diff -U0 --no-color | clang-format-diff -p1 -i
# (modifications are applied)

---
Language: Cpp
AccessModifierOffset: -2
AlwaysBreakAfterReturnType: TopLevel
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: true
SplitEmptyFunction: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
ColumnLimit: 80
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
ForEachMacros: []
IndentCaseLabels: false
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 100
PointerAlignment: Right
SortIncludes: false
SpaceAfterCStyleCast: true
SpaceBeforeParens: Always
SpacesBeforeTrailingComments: 1
UseTab: Always
AlignEscapedNewlines: Right
AlignTrailingComments: true
AllowShortFunctionsOnASingleLine: All
AlwaysBreakTemplateDeclarations: MultiLine
KeepEmptyLinesAtTheStartOfBlocks: false
Standard: c++14
20 changes: 18 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
*~
#*

*.o
*.dylib
*.so
*.obj
*.exe
Makefile
build/
CMakeFiles/

CMakeCache.txt
CMakeFiles/
CMakeScripts
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

# Jetbrains
.idea/
out/
cmake-build-*/

# VSCode
.vscode/
18 changes: 18 additions & 0 deletions include/goptical/core/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@
#include <vector>
#include <deque>
#include <functional>
#include <algorithm>
#include <memory>

#include "goptical/core/vector_pool"
#include "goptical/core/ref" /* mkdoc:skip */
#include "goptical/core/fstring" /* mkdoc:skip */
#include "goptical/core/vlarray" /* mkdoc:skip */

#include <gsl/gsl_math.h>

#include <math.h>

#include <limits>
Expand Down Expand Up @@ -624,7 +628,21 @@ namespace _goptical {
class RayFan;
}

namespace util {
class ArrayIndex2D {
public:
unsigned rowSize;
unsigned colSize;
unsigned operator()(unsigned row, unsigned col) {
return colSize * row + col;
}
};
}

}

extern "C" int find_first_bit_set (int i);
extern double drand48();

#endif

2 changes: 1 addition & 1 deletion include/goptical/core/fstring
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

/** @file @module{Formatted string} */

#ifdef __GNUC__
#ifndef __GNUC__
# define _DPP_FORMAT_CHK(archetype, string_index, first_to_check)
#else
# define _DPP_FORMAT_CHK(archetype, string_index, first_to_check) \
Expand Down
2 changes: 1 addition & 1 deletion include/goptical/core/math/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace _goptical {
*/
template <int N, typename T> struct VectorBase
{
template <int, typename> friend class VectorBase;
template <int, typename> friend struct VectorBase;

/** Set the whole vector to the specified value */
inline void set(T value);
Expand Down
7 changes: 7 additions & 0 deletions include/goptical/core/vlarray
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,16 @@ namespace dpp {
buffer array of integers along with a @ref vlarray object and
pass the buffer array as storage space to the @ref vlarray
constructor. @hidecontent */
#ifndef _MSC_VER
#define DPP_VLARRAY(type, size, name) \
uint64_t _##name[sizeof(type) * size / 8 + 1]; \
::dpp::vlarray<type> name(_##name, size); /* FIXME size alignment */
#else
#define DPP_VLARRAY(type, size, name) \
auto _##name_ptr = std::unique_ptr<uint64_t>(new uint64_t[sizeof(type) * size / 8 + 1]); \
uint64_t *_##name = _##name_ptr.get(); \
::dpp::vlarray<type> name(_##name, size); /* FIXME size alignment */
#endif

typedef X value_type;
typedef X & reference;
Expand Down
8 changes: 7 additions & 1 deletion src/core/curve_conic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ namespace _goptical {

double Conic::fit(const Rotational &c, double radius, unsigned int count)
{
double X[count], Y[count];
// double X[count], Y[count];
double *X, *Y;
X = (double *) calloc(count, sizeof(double));
Y = (double *) calloc(count, sizeof(double));

double step = radius / (double)count;
double y = step / 2.0;
Expand All @@ -185,6 +188,9 @@ namespace _goptical {
_sh = -c1;
_roc = c0 / 2.0;

free(X);
free(Y);

return sqrt(chisq / count); // FIXME bad rms error
}

Expand Down
7 changes: 6 additions & 1 deletion src/core/curve_conic_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ namespace _goptical {

double ConicBase::fit_roc(const Rotational &c, double radius, unsigned int count)
{
double X[count], Y[count];
//double X[count], Y[count];
double *X, *Y;
X = (double *) calloc(count, sizeof(double));
Y = (double *) calloc(count, sizeof(double));

double step = radius / (double)count;
double y = step / 2.0;
Expand Down Expand Up @@ -133,6 +136,8 @@ namespace _goptical {
_roc = 2.0 * c1;
}

free(X);
free(Y);
return sqrt(chisq / count); // FIXME bad rms error
}

Expand Down
47 changes: 30 additions & 17 deletions src/core/data_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,23 +325,27 @@ namespace _goptical {
{
unsigned int n = _size[v];

double eq[n][3];
double dd[n];
//double eq[n][3];
double *eq = (double*)calloc(n * 3, sizeof(double));
_goptical::util::ArrayIndex2D _ = { n, 3 };

//double dd[n];
double* dd = (double*)calloc(n, sizeof(double));

// tridiag system equations
dd[0 ] = dd[n-1] = 0.0;
eq[0 ][1] = eq[n-1][1] = 1.0;
eq[1 ][0] = eq[n-2][2] = -1.0;
eq[_(0,1)] = eq[_(n-1,1)] = 1.0;
eq[_(1,0)] = eq[_(n-2,2)] = -1.0;

int i, j = 0;

for (i = 1; i < (int)n - 1; i++)
{
j = o + i * w;

eq[i-1][2] = _step[v] / 6.0;
eq[i ][1] = _step[v] * 2.0 / 3.0;
eq[i+1][0] = _step[v] / 6.0;
eq[_(i-1,2)] = _step[v] / 6.0;
eq[_(i,1)] = _step[v] * 2.0 / 3.0;
eq[_(i+1,0)] = _step[v] / 6.0;
dd[i] = (_y_data[j+w] - _y_data[j]) / _step[v]
- (_y_data[j] - _y_data[j-w]) / _step[v];
}
Expand All @@ -350,20 +354,22 @@ namespace _goptical {
// forward substitution
for (i = 1; i < (int)n; i++)
{
double f = eq[i-1][2] / eq[i-1][1];
eq[i][1] -= f * eq[i][0];
double f = eq[_(i-1,2)] / eq[_(i-1,1)];
eq[_(i,1)] -= f * eq[_(i,0)];
dd[i] -= f * dd[i-1];
}

// backward substitution
double k = 0;
for (i = n - 1; i >= 0; i--)
{
double ddi = (dd[i] - k) / eq[i][1];
double ddi = (dd[i] - k) / eq[_(i,1)];
dd[i] = ddi;
k = eq[i][0] * ddi;
k = eq[_(i,0)] * ddi;
}

free(eq);

// here with have the continuous second derivative in dd[],
// compute smooth 1st derivative
double dt = _step[v];
Expand All @@ -379,6 +385,8 @@ namespace _goptical {
d[j + w][v] =
+ (_y_data[j+w] - _y_data[j])
+ (dt * dt) * ((dd[i] + dt * (0.5 * (dd[i+1] - dd[i]) / dt)) - (dd[i+1] / 6.0 + dd[i] / 3.0));

free(dd);
}

void Grid::update_bicubic(unsigned int x[2], const math::Vector2 & v) const
Expand All @@ -391,7 +399,8 @@ namespace _goptical {
const unsigned int s0 = _size[0] - 1;
this_->_poly.resize(s0 * (_size[1] - 1));

double cd[_size[0] * _size[1]];
//double cd[_size[0] * _size[1]];
double *cd = (double *)calloc(_size[0] * _size[1], sizeof(double));
get_cross_deriv_diff(cd);

const unsigned int w = _size[0];
Expand Down Expand Up @@ -436,7 +445,7 @@ namespace _goptical {
this_->_lookup = &Grid::lookup_interval;
this_->_interpolate_y = &Grid::interpolate_bicubic_y;
this_->_interpolate_d = &Grid::interpolate_bicubic_d;

free(cd);
return lookup_interval(x, v);
}

Expand All @@ -450,7 +459,9 @@ namespace _goptical {
const unsigned int s0 = _size[0] - 1;
this_->_poly.resize(s0 * (_size[1] - 1));

double cd[_size[0] * _size[1]];
//double cd[_size[0] * _size[1]];
double *cd = (double *)calloc(_size[0] * _size[1], sizeof(double));

get_cross_deriv_diff(cd);

DPP_VLARRAY(math::Vector2, _size[0] * _size[1], d);
Expand Down Expand Up @@ -489,7 +500,7 @@ namespace _goptical {
this_->_lookup = &Grid::lookup_interval;
this_->_interpolate_y = &Grid::interpolate_bicubic_y;
this_->_interpolate_d = &Grid::interpolate_bicubic_d;

free(cd);
return lookup_interval(x, v);
}

Expand All @@ -503,7 +514,9 @@ namespace _goptical {
const unsigned int s0 = _size[0] - 1;
this_->_poly.resize(s0 * (_size[1] - 1));

double cd[_size[0] * _size[1]];
//double cd[_size[0] * _size[1]];
double *cd = (double *)calloc(_size[0] * _size[1], sizeof(double));

get_cross_deriv_diff(cd);

const unsigned int w = _size[0];
Expand Down Expand Up @@ -539,7 +552,7 @@ namespace _goptical {
this_->_lookup = &Grid::lookup_interval;
this_->_interpolate_y = &Grid::interpolate_bicubic_y;
this_->_interpolate_d = &Grid::interpolate_bicubic_d;

free(cd);
return lookup_interval(x, v);
}

Expand Down
Loading

0 comments on commit 25f1a3f

Please sign in to comment.