Skip to content

Commit 5115b40

Browse files
authored
Merge branch 'master' into attributes/fix_compile_errors_from_fix_integer_conversion_errors
2 parents fe13aef + f149040 commit 5115b40

File tree

18 files changed

+156
-84
lines changed

18 files changed

+156
-84
lines changed

examples/base/array.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
// This file is part of Empirical, https://github.com/devosoft/Empirical
2-
// Copyright (C) Michigan State University, 2016-2017.
2+
// Copyright (C) Michigan State University, 2016-2018.
33
// Released under the MIT Software license; see doc/LICENSE
44

55
#include "base/array.h"
66

77
#define A_SIZE 50
88

9+
// Function to print an std::array; will it work with emp::array?
10+
template <size_t N>
11+
void ArrayPrint(const std::array<int,N> & ar) {
12+
for (int x : ar) std::cout << x << " ";
13+
std::cout << std::endl;
14+
}
15+
916
int main()
1017
{
1118
emp::array<int, A_SIZE> test_array;
@@ -14,6 +21,9 @@ int main()
1421
test_array[i] = (int) (i * i);
1522
}
1623

24+
std::cout << "First array: " << std::endl;
25+
ArrayPrint<A_SIZE>(test_array);
26+
1727
int sum = 0;
1828
for (size_t i = 0; i < A_SIZE; i++) {
1929
sum += test_array[i];

examples/data/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CFLAGS_version := -std=c++14
55
# Emscripten compiler information
66
CXX_web := emcc
77
CXX_native := g++
8+
#CXX_native := clang++
89

910
OFLAGS_native_debug := -g -pedantic -DEMP_TRACK_MEM -Wnon-virtual-dtor -Wcast-align -Woverloaded-virtual -Wconversion -Weffc++
1011
OFLAGS_native_opt := -O3 -DNDEBUG

examples/timing/pointers.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main()
2525
std::clock_t base_start_time = std::clock();
2626

2727
std::vector<int *> v_base(N);
28-
for (size_t i = 0; i < N; i++) v_base[i] = new int((i*7)%N);
28+
for (size_t i = 0; i < N; i++) v_base[i] = new int((int)((i*7)%N));
2929
std::vector<int *> v_base2(v_base);
3030
std::sort( v_base2.begin(), v_base2.end(), [](int *p1,int *p2){ return *p1 < *p2; } );
3131
v_base.resize(0);
@@ -43,7 +43,7 @@ int main()
4343
std::clock_t std_start_time = std::clock();
4444

4545
std::vector<std::shared_ptr<int>> v_std(N);
46-
for (size_t i = 0; i < N; i++) v_std[i] = std::make_shared<int>( (i*7)%N );
46+
for (size_t i = 0; i < N; i++) v_std[i] = std::make_shared<int>( (int)((i*7)%N) );
4747
std::vector<std::shared_ptr<int>> v_std2(v_std);
4848
std::sort( v_std2.begin(), v_std2.end(),
4949
[](std::shared_ptr<int> p1, std::shared_ptr<int> p2){ return *p1 < *p2; } );
@@ -61,7 +61,7 @@ int main()
6161
std::clock_t emp_start_time = std::clock();
6262

6363
std::vector<emp::Ptr<int>> v_emp(N);
64-
for (size_t i = 0; i < N; i++) v_emp[i] = emp::NewPtr<int>((i*7)%N);
64+
for (size_t i = 0; i < N; i++) v_emp[i] = emp::NewPtr<int>((int)((i*7)%N));
6565
std::vector<emp::Ptr<int>> v_emp2(v_emp);
6666
std::sort( v_emp2.begin(), v_emp2.end(),
6767
[](emp::Ptr<int> p1, emp::Ptr<int> p2){ return *p1 < *p2; } );

source/base/array.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ namespace emp {
128128
array(InputIt first, InputIt last) : base_t(first, last), valid(true) { emp_assert(size() == N); }
129129
~array() { valid=false; } // No longer valid when array is deleted.
130130

131+
operator std::array<T,N>() {
132+
std::array<T,N> ar;
133+
for (size_t i = 0; i < N; i++) ar[i] = base_t::operator[](i);
134+
return ar;
135+
}
136+
131137
constexpr size_t size() const { return N; }
132138

133139
iterator begin() noexcept { return iterator(base_t::begin(), this); }

source/base/vector.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* This class is a drop-in wrapper for std::vector, adding on bounds checking.
1111
* If EMP_NDEBUG is set then it reverts back to std::vector.
1212
*
13-
* @todo Need an automatic conversion from emp::vector to std::vector and back to interface with
14-
* non-empirical code.
13+
* @todo Debug code: member functions that take iterators should also take emp iterators that verify
14+
* whether those iterators are valid.
1515
*/
1616

1717

@@ -62,6 +62,7 @@ namespace emp {
6262
const vec_t * v_ptr;
6363
int revision;
6464

65+
// @CAO: For the moment cannot create an emp iterator from a base since we don't know vector to use.
6566
// iterator_wrapper(const ITERATOR_T & _in)
6667
// : ITERATOR_T(_in), v_ptr(nullptr), revision(0) { ; }
6768
iterator_wrapper(const ITERATOR_T & _in, const vec_t * _v)

source/meta/type_traits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This file is part of Empirical, https://github.com/devosoft/Empirical
2-
// Copyright (C) Michigan State University, 2016-2017.
2+
// Copyright (C) Michigan State University, 2016-2018.
33
// Released under the MIT Software license; see doc/LICENSE
44
//
55
// Extensions on the standard library type traits to handle Empirical classes

source/tools/set_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
33
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
4-
* @date 2016-2017
4+
* @date 2016-2018
55
*
66
* @file set_utils.h
77
* @brief Tools to save and load data from classes.
@@ -68,7 +68,7 @@ namespace emp {
6868
return result;
6969
}
7070

71-
/// Compute the set difference of @param s1 and @param s2 (elements that are in S1 but no S2)
71+
/// Compute the set difference of @param s1 and @param s2 (elements that are in S1 but not S2)
7272
template <typename T>
7373
std::set<T> difference(std::set<T> & s1, emp::vector<T> s2) {
7474
// Based on PierreBdR's answer to https://stackoverflow.com/questions/283977/c-stl-set-difference

source/web/JSWrap.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
33
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
4-
* @date 2015-2017
4+
* @date 2015-2018
55
*
66
* @file JSWrap.h
77
* @brief Wrap a C++ function and convert it to an integer that can be called from Javascript
@@ -116,7 +116,7 @@ namespace emp {
116116
arg_var = tmp_var; // @CAO Do we need to free the memory in tmp_var?
117117
}
118118

119-
template <int ARG_ID, size_t SIZE, typename T> static void LoadArg(std::array<T, SIZE> & arg_var){
119+
template <int ARG_ID, size_t SIZE, typename T> static void LoadArg(emp::array<T, SIZE> & arg_var){
120120
EM_ASM_ARGS({emp_i.__outgoing_array = emp_i.cb_args[$0];}, ARG_ID);
121121
pass_array_to_cpp(arg_var);
122122
}
@@ -265,7 +265,7 @@ namespace emp {
265265
}
266266

267267
template <typename T, size_t N>
268-
static void StoreReturn(const std::array<T, N> & ret_var) {
268+
static void StoreReturn(const emp::array<T, N> & ret_var) {
269269
pass_array_to_javascript(ret_var);
270270
EM_ASM({ emp_i.cb_return = emp_i.__incoming_array; });
271271
}
@@ -292,7 +292,7 @@ namespace emp {
292292
}
293293

294294
template <typename T, size_t N>
295-
static void StoreReturn(const std::array<T, N> & ret_var, std::string var) {
295+
static void StoreReturn(const emp::array<T, N> & ret_var, std::string var) {
296296
pass_array_to_javascript(ret_var);
297297
EM_ASM_ARGS({ emp_i.curr_obj[Pointer_stringify($0)] = emp_i.__incoming_array;}, var.c_str());
298298
}

source/web/d3/axis.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
#ifndef __AXIS_H__
2-
#define __AXIS_H__
1+
/**
2+
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
3+
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
4+
* @date 2017-2018
5+
*
6+
* @file axis.h
7+
* @brief Handle drawing of axes on D3 graphts.
8+
*/
9+
10+
#ifndef EMP_D3_AXIS_H
11+
#define EMP_D3_AXIS_H
312

413
#include "../js_utils.h"
514
#include "../../tools/string_utils.h"
@@ -171,7 +180,7 @@ namespace D3 {
171180
}
172181

173182
template <typename T, std::size_t SIZE>
174-
Axis& SetTickValues(std::array<T, SIZE> values) {
183+
Axis& SetTickValues(emp::array<T, SIZE> values) {
175184
emp::pass_array_to_javascript(values);
176185

177186
EM_ASM_ARGS({
@@ -231,7 +240,7 @@ namespace D3 {
231240
/// transition, then the rescaling will be animated.
232241
template <typename T>
233242
Axis& Rescale(double new_min, double new_max, const D3::SelectionOrTransition<T> & svg){
234-
this->scale.SetDomain(std::array<double, 2>({{new_min, new_max}}));
243+
this->scale.SetDomain(emp::array<double, 2>{{new_min, new_max}});
235244
ApplyAxis(svg.Select("#"+dom_id));
236245
return *this;
237246
}

source/web/d3/dataset.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
#ifndef __LOAD_DATA_H__
2-
#define __LOAD_DATA_H__
1+
/**
2+
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
3+
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
4+
* @date 2016-2018
5+
*
6+
* @file dataset.h
7+
* @brief Tools to maintain data in D3.
8+
*/
9+
10+
#ifndef EMP_D3_LOAD_DATA_H
11+
#define EMP_D3_LOAD_DATA_H
312

413
#include <functional>
514

@@ -225,7 +234,7 @@ namespace D3 {
225234

226235
/// Put the last row of the array into arr
227236
template <std::size_t N, typename T>
228-
void GetLastRow(std::array<T, N> & arr) {
237+
void GetLastRow(emp::array<T, N> & arr) {
229238
EM_ASM_ARGS({
230239
emp_i.__outgoing_array = js.objects[$0][js.objects[$0].length - 1];
231240
}, GetID());

0 commit comments

Comments
 (0)