Micah Weston
commited on
Commit
·
c659828
1
Parent(s):
041a94e
Removes loading script.
Browse files- README.md +7 -0
- data/genericify_cpp.jsonl +1 -1
- dataset_genericify_cpp.py +0 -67
- temp.jsonl +0 -0
README.md
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
configs:
|
3 |
+
- config_name: default
|
4 |
+
data_files:
|
5 |
+
- split: test
|
6 |
+
path: "data/genericify_cpp.jsonl"
|
7 |
+
---
|
data/genericify_cpp.jsonl
CHANGED
@@ -20,4 +20,4 @@
|
|
20 |
{"base_canonical_solution": "template <typename T>\nstd::vector<T> rescale_to_unit(std::vector<T> numbers) {\n T min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "base_prompt": "Make the following function generic for the value type of the vector parameter and vector return value.", "concepts_canonical_solution": "template <std::floating_point T>\nstd::vector<T> rescale_to_unit(std::vector<T> numbers) {\n T min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a floating point type.", "invalids": "int main() { rescale_to_unit(std::vector<int>{1, 2, 3}); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>\nstd::vector<T> rescale_to_unit(std::vector<T> numbers) {\n T min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a floating point type.", "starter_code": "std::vector<float> rescale_to_unit(std::vector<float> numbers) {\n float min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "task_id": "HEP/21", "tests": "template <typename T>\nbool issame(std::vector<T> a, std::vector<T> b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (std::abs(a[i] - b[i]) > 1e-4) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(rescale_to_unit(_type_{2.0, 49.9}), _type_{0.0, 1.0})); \\\n ASSERT(issame(rescale_to_unit(_type_{100.0, 49.9}), _type_{1.0, 0.0})); \\\n ASSERT(issame(rescale_to_unit(_type_{1.0, 2.0, 3.0, 4.0, 5.0}), \\\n _type_{0.0, 0.25, 0.5, 0.75, 1.0})); \\\n ASSERT(issame(rescale_to_unit(_type_{2.0, 1.0, 5.0, 3.0, 4.0}), \\\n _type_{0.25, 0.0, 1.0, 0.5, 0.75})); \\\n ASSERT(issame(rescale_to_unit(_type_{12.0, 11.0, 15.0, 13.0, 14.0}), \\\n _type_{0.25, 0.0, 1.0, 0.5, 0.75})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::vector<float>);\n TEST_ON_TYPE(std::vector<double>);\n}\n"}
|
21 |
{"base_canonical_solution": "template <typename T>\nT largest_divisor(T n) {\n for (T i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}\n", "base_prompt": "Replace these functions with a single generic function preserving the original behaviors.", "concepts_canonical_solution": "template <std::integral T>\nT largest_divisor(T n) {\n for (T i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}\n", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that it only accepts integer types.", "invalids": "int main() { largest_divisor((float)3.5); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>\nT largest_divisor(T n) {\n for (T i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}\n", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that it only accepts integer types.", "starter_code": "int largest_divisor(int n) {\n for (int i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}\nunsigned largest_divisor(unsigned n) {\n for (unsigned i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}\nlong largest_divisor(long n) {\n for (long i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}\nunsigned short largest_divisor(unsigned short n) {\n for (unsigned short i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}", "task_id": "HEP/24", "tests": "#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(largest_divisor((_type_)3) == (_type_)1); \\\n ASSERT(largest_divisor((_type_)7) == (_type_)1); \\\n ASSERT(largest_divisor((_type_)10) == (_type_)5); \\\n ASSERT(largest_divisor((_type_)100) == (_type_)50); \\\n ASSERT(largest_divisor((_type_)49) == (_type_)7); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(int);\n TEST_ON_TYPE(long);\n TEST_ON_TYPE(unsigned);\n TEST_ON_TYPE(unsigned short);\n TEST_ON_TYPE(unsigned long long);\n}\n"}
|
22 |
{"base_canonical_solution": "template <typename T>\nstd::vector<T> factorize(T n) {\n std::vector<T> out = {};\n for (T i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n = n / i;\n out.push_back(i);\n i -= 1;\n }\n }\n out.push_back(n);\n return out;\n}\n", "base_prompt": "Replace these functions with a single generic function preserving the original behaviors.", "concepts_canonical_solution": "template <std::integral T>\nstd::vector<T> factorize(T n) {\n std::vector<T> out = {};\n for (T i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n = n / i;\n out.push_back(i);\n i -= 1;\n }\n }\n out.push_back(n);\n return out;\n}\n", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that it only accepts integer types.", "invalids": "int main() { factorize((float)3.5); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>\nstd::vector<T> factorize(T n) {\n std::vector<T> out = {};\n for (T i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n = n / i;\n out.push_back(i);\n i -= 1;\n }\n }\n out.push_back(n);\n return out;\n}\n", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that it only accepts integer types.", "starter_code": "std::vector<int> factorize(int n) {\n std::vector<int> out = {};\n for (int i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n = n / i;\n out.push_back(i);\n i -= 1;\n }\n }\n out.push_back(n);\n return out;\n}\nstd::vector<unsigned> factorize(unsigned n) {\n std::vector<unsigned> out = {};\n for (unsigned i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n = n / i;\n out.push_back(i);\n i -= 1;\n }\n }\n out.push_back(n);\n return out;\n}\nstd::vector<long> factorize(long n) {\n std::vector<long> out = {};\n for (long i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n = n / i;\n out.push_back(i);\n i -= 1;\n }\n }\n out.push_back(n);\n return out;\n}", "task_id": "HEP/25", "tests": "template <typename T>\nbool issame(std::vector<T> a, std::vector<T> b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] != b[i]) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(factorize((_type_)2), std::vector<_type_>{2})); \\\n ASSERT(issame(factorize((_type_)4), std::vector<_type_>{2, 2})); \\\n ASSERT(issame(factorize((_type_)8), std::vector<_type_>{2, 2, 2})); \\\n ASSERT(issame(factorize((_type_)(3 * 19)), std::vector<_type_>{3, 19})); \\\n ASSERT(issame(factorize((_type_)(3 * 19 * 3 * 19)), \\\n std::vector<_type_>{3, 3, 19, 19})); \\\n ASSERT(issame(factorize((_type_)(3 * 19 * 3 * 19 * 3 * 19)), \\\n std::vector<_type_>{3, 3, 3, 19, 19, 19})); \\\n ASSERT(issame(factorize((_type_)(3 * 19 * 19 * 19)), \\\n std::vector<_type_>{3, 19, 19, 19})); \\\n ASSERT( \\\n issame(factorize((_type_)(3 * 2 * 3)), std::vector<_type_>{2, 3, 3})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(int);\n TEST_ON_TYPE(unsigned);\n TEST_ON_TYPE(long);\n TEST_ON_TYPE(unsigned long long);\n}\n"}
|
23 |
-
{"base_canonical_solution": "template <typename T>\nT remove_duplicates(T numbers) {\n T out = {};\n T has1 = {};\n T has2 = {};\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) != has2.end()) continue;\n if (std::find(has1.begin(), has1.end(), numbers[i]) != has1.end()) {\n has2.push_back(numbers[i]);\n } else {\n has1.push_back(numbers[i]);\n }\n }\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) == has2.end()) {\n out.push_back(numbers[i]);\n }\n }\n return out;\n}\n", "base_prompt": "Replace these functions with a single generic function preserving the original behaviors.", "concepts_canonical_solution": "template <typename T>\n requires requires(const T &container, std::size_t idx, std::size_t oidx) {\n { container[idx] } -> std::same_as<typename T::const_reference>;\n { container[idx] == container[oidx] } -> std::convertible_to<bool>;\n }\nT remove_duplicates(T numbers) {\n T out = {};\n T has1 = {};\n T has2 = {};\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) != has2.end()) continue;\n if (std::find(has1.begin(), has1.end(), numbers[i]) != has1.end()) {\n has2.push_back(numbers[i]);\n } else {\n has1.push_back(numbers[i]);\n }\n }\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) == has2.end()) {\n out.push_back(numbers[i]);\n }\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that it only accepts sequenced containers with comparable elements.", "invalids": "int main() { remove_duplicates(3); }", "sfinae_canonical_solution": "template <\n typename T,\n std::enable_if_t<\n std::conjunction_v<\n std::is_same<typename T::const_reference,\n decltype(std::declval<\n const T &>()[std::declval<std::size_t>()])>,\n std::is_convertible<decltype(std::declval<const T &>()\n [std::declval<std::size_t>()] ==\n std::declval<const T &>()\n [std::declval<std::size_t>()]),\n bool>>,\n int> = 0>\nT remove_duplicates(T numbers) {\n T out = {};\n T has1 = {};\n T has2 = {};\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) != has2.end()) continue;\n if (std::find(has1.begin(), has1.end(), numbers[i]) != has1.end()) {\n has2.push_back(numbers[i]);\n } else {\n has1.push_back(numbers[i]);\n }\n }\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) == has2.end()) {\n out.push_back(numbers[i]);\n }\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that it only accepts sequenced containers with comparable elements.", "starter_code": "std::vector<int> remove_duplicates(std::vector<int> numbers) {\n std::vector<int> out = {};\n std::vector<int> has1 = {};\n std::vector<int> has2 = {};\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) != has2.end()) continue;\n if (std::find(has1.begin(), has1.end(), numbers[i]) != has1.end()) {\n has2.push_back(numbers[i]);\n } else {\n has1.push_back(numbers[i]);\n }\n }\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) == has2.end()) {\n out.push_back(numbers[i]);\n }\n }\n return out;\n}\nstd::deque<std::string> remove_duplicates(std::deque<std::string> numbers) {\n std::deque<std::string> out = {};\n std::deque<std::string> has1 = {};\n std::deque<std::string> has2 = {};\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) != has2.end()) continue;\n if (std::find(has1.begin(), has1.end(), numbers[i]) != has1.end()) {\n has2.push_back(numbers[i]);\n } else {\n has1.push_back(numbers[i]);\n }\n }\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) == has2.end()) {\n out.push_back(numbers[i]);\n }\n }\n return out;\n}", "task_id": "HEP/26", "tests": "template <typename T>\nbool issame(T a, T b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] != b[i]) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\nint main() {\n ASSERT(issame(remove_duplicates(std::vector<int>{}), std::vector<int>{}));\n ASSERT(issame(remove_duplicates(std::vector<int>{1, 2, 3, 4}),\n std::vector<int>{1, 2, 3, 4}));\n ASSERT(issame(remove_duplicates(std::vector<int>{1, 2, 3, 2, 4, 3, 5}),\n std::vector<int>{1, 4, 5}));\n\n ASSERT(issame(remove_duplicates(std::vector<char>{}), std::vector<char>{}));\n ASSERT(issame(remove_duplicates(std::vector<char>{1, 2, 3, 4}),\n std::vector<char>{1, 2, 3, 4}));\n ASSERT(issame(remove_duplicates(std::vector<char>{1, 2, 3, 2, 4, 3, 5}),\n std::vector<char>{1, 4, 5}));\n\n ASSERT(issame(remove_duplicates(std::deque<std::string>{}),\n std::deque<std::string>{}));\n ASSERT(issame(remove_duplicates(std::deque<std::string>{\"1\", \"2\", \"3\", \"4\"}),\n std::deque<std::string>{\"1\", \"2\", \"3\", \"4\"}));\n ASSERT(issame(remove_duplicates(\n std::deque<std::string>{\"1\", \"2\", \"3\", \"2\", \"4\", \"3\", \"5\"}),\n std::deque<std::string>{\"1\", \"4\", \"5\"}));\n}\n"}
|
|
|
20 |
{"base_canonical_solution": "template <typename T>\nstd::vector<T> rescale_to_unit(std::vector<T> numbers) {\n T min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "base_prompt": "Make the following function generic for the value type of the vector parameter and vector return value.", "concepts_canonical_solution": "template <std::floating_point T>\nstd::vector<T> rescale_to_unit(std::vector<T> numbers) {\n T min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that the generic parameter is a floating point type.", "invalids": "int main() { rescale_to_unit(std::vector<int>{1, 2, 3}); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>\nstd::vector<T> rescale_to_unit(std::vector<T> numbers) {\n T min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that the generic parameter is a floating point type.", "starter_code": "std::vector<float> rescale_to_unit(std::vector<float> numbers) {\n float min = 100000, max = -100000;\n for (int i = 0; i < numbers.size(); i++) {\n if (numbers[i] < min) min = numbers[i];\n if (numbers[i] > max) max = numbers[i];\n }\n for (int i = 0; i < numbers.size(); i++)\n numbers[i] = (numbers[i] - min) / (max - min);\n return numbers;\n}", "task_id": "HEP/21", "tests": "template <typename T>\nbool issame(std::vector<T> a, std::vector<T> b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (std::abs(a[i] - b[i]) > 1e-4) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(rescale_to_unit(_type_{2.0, 49.9}), _type_{0.0, 1.0})); \\\n ASSERT(issame(rescale_to_unit(_type_{100.0, 49.9}), _type_{1.0, 0.0})); \\\n ASSERT(issame(rescale_to_unit(_type_{1.0, 2.0, 3.0, 4.0, 5.0}), \\\n _type_{0.0, 0.25, 0.5, 0.75, 1.0})); \\\n ASSERT(issame(rescale_to_unit(_type_{2.0, 1.0, 5.0, 3.0, 4.0}), \\\n _type_{0.25, 0.0, 1.0, 0.5, 0.75})); \\\n ASSERT(issame(rescale_to_unit(_type_{12.0, 11.0, 15.0, 13.0, 14.0}), \\\n _type_{0.25, 0.0, 1.0, 0.5, 0.75})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(std::vector<float>);\n TEST_ON_TYPE(std::vector<double>);\n}\n"}
|
21 |
{"base_canonical_solution": "template <typename T>\nT largest_divisor(T n) {\n for (T i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}\n", "base_prompt": "Replace these functions with a single generic function preserving the original behaviors.", "concepts_canonical_solution": "template <std::integral T>\nT largest_divisor(T n) {\n for (T i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}\n", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that it only accepts integer types.", "invalids": "int main() { largest_divisor((float)3.5); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>\nT largest_divisor(T n) {\n for (T i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}\n", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that it only accepts integer types.", "starter_code": "int largest_divisor(int n) {\n for (int i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}\nunsigned largest_divisor(unsigned n) {\n for (unsigned i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}\nlong largest_divisor(long n) {\n for (long i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}\nunsigned short largest_divisor(unsigned short n) {\n for (unsigned short i = 2; i * i <= n; i++)\n if (n % i == 0) return n / i;\n return 1;\n}", "task_id": "HEP/24", "tests": "#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(largest_divisor((_type_)3) == (_type_)1); \\\n ASSERT(largest_divisor((_type_)7) == (_type_)1); \\\n ASSERT(largest_divisor((_type_)10) == (_type_)5); \\\n ASSERT(largest_divisor((_type_)100) == (_type_)50); \\\n ASSERT(largest_divisor((_type_)49) == (_type_)7); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(int);\n TEST_ON_TYPE(long);\n TEST_ON_TYPE(unsigned);\n TEST_ON_TYPE(unsigned short);\n TEST_ON_TYPE(unsigned long long);\n}\n"}
|
22 |
{"base_canonical_solution": "template <typename T>\nstd::vector<T> factorize(T n) {\n std::vector<T> out = {};\n for (T i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n = n / i;\n out.push_back(i);\n i -= 1;\n }\n }\n out.push_back(n);\n return out;\n}\n", "base_prompt": "Replace these functions with a single generic function preserving the original behaviors.", "concepts_canonical_solution": "template <std::integral T>\nstd::vector<T> factorize(T n) {\n std::vector<T> out = {};\n for (T i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n = n / i;\n out.push_back(i);\n i -= 1;\n }\n }\n out.push_back(n);\n return out;\n}\n", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that it only accepts integer types.", "invalids": "int main() { factorize((float)3.5); }", "sfinae_canonical_solution": "template <typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>\nstd::vector<T> factorize(T n) {\n std::vector<T> out = {};\n for (T i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n = n / i;\n out.push_back(i);\n i -= 1;\n }\n }\n out.push_back(n);\n return out;\n}\n", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that it only accepts integer types.", "starter_code": "std::vector<int> factorize(int n) {\n std::vector<int> out = {};\n for (int i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n = n / i;\n out.push_back(i);\n i -= 1;\n }\n }\n out.push_back(n);\n return out;\n}\nstd::vector<unsigned> factorize(unsigned n) {\n std::vector<unsigned> out = {};\n for (unsigned i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n = n / i;\n out.push_back(i);\n i -= 1;\n }\n }\n out.push_back(n);\n return out;\n}\nstd::vector<long> factorize(long n) {\n std::vector<long> out = {};\n for (long i = 2; i * i <= n; i++) {\n if (n % i == 0) {\n n = n / i;\n out.push_back(i);\n i -= 1;\n }\n }\n out.push_back(n);\n return out;\n}", "task_id": "HEP/25", "tests": "template <typename T>\nbool issame(std::vector<T> a, std::vector<T> b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] != b[i]) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\n#define TEST_ON_TYPE(_type_) \\\n do { \\\n ASSERT(issame(factorize((_type_)2), std::vector<_type_>{2})); \\\n ASSERT(issame(factorize((_type_)4), std::vector<_type_>{2, 2})); \\\n ASSERT(issame(factorize((_type_)8), std::vector<_type_>{2, 2, 2})); \\\n ASSERT(issame(factorize((_type_)(3 * 19)), std::vector<_type_>{3, 19})); \\\n ASSERT(issame(factorize((_type_)(3 * 19 * 3 * 19)), \\\n std::vector<_type_>{3, 3, 19, 19})); \\\n ASSERT(issame(factorize((_type_)(3 * 19 * 3 * 19 * 3 * 19)), \\\n std::vector<_type_>{3, 3, 3, 19, 19, 19})); \\\n ASSERT(issame(factorize((_type_)(3 * 19 * 19 * 19)), \\\n std::vector<_type_>{3, 19, 19, 19})); \\\n ASSERT( \\\n issame(factorize((_type_)(3 * 2 * 3)), std::vector<_type_>{2, 3, 3})); \\\n } while (false)\n\nint main() {\n TEST_ON_TYPE(int);\n TEST_ON_TYPE(unsigned);\n TEST_ON_TYPE(long);\n TEST_ON_TYPE(unsigned long long);\n}\n"}
|
23 |
+
{"base_canonical_solution": "template <typename T>\nT remove_duplicates(T numbers) {\n T out = {};\n T has1 = {};\n T has2 = {};\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) != has2.end()) continue;\n if (std::find(has1.begin(), has1.end(), numbers[i]) != has1.end()) {\n has2.push_back(numbers[i]);\n } else {\n has1.push_back(numbers[i]);\n }\n }\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) == has2.end()) {\n out.push_back(numbers[i]);\n }\n }\n return out;\n}\n", "base_prompt": "Replace these functions with a single generic function preserving the original behaviors.", "concepts_canonical_solution": "template <typename T>\n requires requires(const T &container, std::size_t idx, std::size_t oidx) {\n { container[idx] } -> std::same_as<typename T::const_reference>;\n { container[idx] == container[oidx] } -> std::convertible_to<bool>;\n }\nT remove_duplicates(T numbers) {\n T out = {};\n T has1 = {};\n T has2 = {};\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) != has2.end()) continue;\n if (std::find(has1.begin(), has1.end(), numbers[i]) != has1.end()) {\n has2.push_back(numbers[i]);\n } else {\n has1.push_back(numbers[i]);\n }\n }\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) == has2.end()) {\n out.push_back(numbers[i]);\n }\n }\n return out;\n}", "concepts_prompt": "Constrain the generic code using C++20 Concepts so that it only accepts sequenced containers with comparable elements.", "invalids": "int main() { remove_duplicates(3); }", "sfinae_canonical_solution": "template <\n typename T,\n std::enable_if_t<\n std::conjunction_v<\n std::is_same<typename T::const_reference,\n decltype(std::declval<\n const T &>()[std::declval<std::size_t>()])>,\n std::is_convertible<decltype(std::declval<const T &>()\n [std::declval<std::size_t>()] ==\n std::declval<const T &>()\n [std::declval<std::size_t>()]),\n bool>>,\n int> = 0>\nT remove_duplicates(T numbers) {\n T out = {};\n T has1 = {};\n T has2 = {};\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) != has2.end()) continue;\n if (std::find(has1.begin(), has1.end(), numbers[i]) != has1.end()) {\n has2.push_back(numbers[i]);\n } else {\n has1.push_back(numbers[i]);\n }\n }\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) == has2.end()) {\n out.push_back(numbers[i]);\n }\n }\n return out;\n}", "sfinae_prompt": "Constrain the generic code using C++17 SFINAE so that it only accepts sequenced containers with comparable elements.", "starter_code": "std::vector<int> remove_duplicates(std::vector<int> numbers) {\n std::vector<int> out = {};\n std::vector<int> has1 = {};\n std::vector<int> has2 = {};\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) != has2.end()) continue;\n if (std::find(has1.begin(), has1.end(), numbers[i]) != has1.end()) {\n has2.push_back(numbers[i]);\n } else {\n has1.push_back(numbers[i]);\n }\n }\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) == has2.end()) {\n out.push_back(numbers[i]);\n }\n }\n return out;\n}\nstd::deque<std::string> remove_duplicates(std::deque<std::string> numbers) {\n std::deque<std::string> out = {};\n std::deque<std::string> has1 = {};\n std::deque<std::string> has2 = {};\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) != has2.end()) continue;\n if (std::find(has1.begin(), has1.end(), numbers[i]) != has1.end()) {\n has2.push_back(numbers[i]);\n } else {\n has1.push_back(numbers[i]);\n }\n }\n for (int i = 0; i < numbers.size(); i++) {\n if (std::find(has2.begin(), has2.end(), numbers[i]) == has2.end()) {\n out.push_back(numbers[i]);\n }\n }\n return out;\n}", "task_id": "HEP/26", "tests": "template <typename T>\nbool issame(T a, T b) {\n if (a.size() != b.size()) return false;\n for (int i = 0; i < a.size(); i++) {\n if (a[i] != b[i]) return false;\n }\n return true;\n}\n\n#define ASSERT(...) \\\n do { \\\n if (!(__VA_ARGS__)) { \\\n std::exit(-1); \\\n } \\\n } while (false)\n\nint main() {\n ASSERT(issame(remove_duplicates(std::vector<int>{}), std::vector<int>{}));\n ASSERT(issame(remove_duplicates(std::vector<int>{1, 2, 3, 4}),\n std::vector<int>{1, 2, 3, 4}));\n ASSERT(issame(remove_duplicates(std::vector<int>{1, 2, 3, 2, 4, 3, 5}),\n std::vector<int>{1, 4, 5}));\n\n ASSERT(issame(remove_duplicates(std::vector<char>{}), std::vector<char>{}));\n ASSERT(issame(remove_duplicates(std::vector<char>{1, 2, 3, 4}),\n std::vector<char>{1, 2, 3, 4}));\n ASSERT(issame(remove_duplicates(std::vector<char>{1, 2, 3, 2, 4, 3, 5}),\n std::vector<char>{1, 4, 5}));\n\n ASSERT(issame(remove_duplicates(std::deque<std::string>{}),\n std::deque<std::string>{}));\n ASSERT(issame(remove_duplicates(std::deque<std::string>{\"1\", \"2\", \"3\", \"4\"}),\n std::deque<std::string>{\"1\", \"2\", \"3\", \"4\"}));\n ASSERT(issame(remove_duplicates(\n std::deque<std::string>{\"1\", \"2\", \"3\", \"2\", \"4\", \"3\", \"5\"}),\n std::deque<std::string>{\"1\", \"4\", \"5\"}));\n}\n"}
|
dataset_genericify_cpp.py
DELETED
@@ -1,67 +0,0 @@
|
|
1 |
-
"""Genericify C++ Dataset for CS7470"""
|
2 |
-
|
3 |
-
|
4 |
-
import json
|
5 |
-
|
6 |
-
import datasets
|
7 |
-
|
8 |
-
|
9 |
-
# You can copy an official description
|
10 |
-
_DESCRIPTION = """\
|
11 |
-
Genericify C++ Dataset
|
12 |
-
"""
|
13 |
-
|
14 |
-
|
15 |
-
class DatasetGenericifyCpp(datasets.GeneratorBasedBuilder):
|
16 |
-
"""Genericify C++ Dataset for CS7470"""
|
17 |
-
|
18 |
-
VERSION = datasets.Version("1.1.0")
|
19 |
-
|
20 |
-
def _info(self):
|
21 |
-
return datasets.DatasetInfo(
|
22 |
-
description=_DESCRIPTION,
|
23 |
-
features=datasets.Features(
|
24 |
-
{
|
25 |
-
"task_id": datasets.Value("string"),
|
26 |
-
"base_prompt": datasets.Value("string"),
|
27 |
-
"sfinae_prompt": datasets.Value("string"),
|
28 |
-
"concepts_prompt": datasets.Value("string"),
|
29 |
-
"starter_code": datasets.Value("string"),
|
30 |
-
"base_canonical_solution": datasets.Value("string"),
|
31 |
-
"sfinae_canonical_solution": datasets.Value("string"),
|
32 |
-
"concepts_canonical_solution": datasets.Value("string"),
|
33 |
-
"tests": datasets.Value("string"),
|
34 |
-
"invalids": datasets.Value("string"),
|
35 |
-
}
|
36 |
-
),
|
37 |
-
)
|
38 |
-
|
39 |
-
def _split_generators(self, dl_manager):
|
40 |
-
downloaded_files = dl_manager.download_and_extract(
|
41 |
-
"data/genericify_cpp.jsonl"
|
42 |
-
)
|
43 |
-
return [
|
44 |
-
datasets.SplitGenerator(
|
45 |
-
name=datasets.Split.TEST,
|
46 |
-
gen_kwargs={
|
47 |
-
"filepath": downloaded_files,
|
48 |
-
},
|
49 |
-
),
|
50 |
-
]
|
51 |
-
|
52 |
-
def _generate_examples(self, filepath):
|
53 |
-
with open(filepath, encoding="utf-8") as f:
|
54 |
-
for key, line in enumerate(f):
|
55 |
-
row = json.loads(line)
|
56 |
-
yield key, {
|
57 |
-
"task_id": row["task_id"],
|
58 |
-
"base_prompt": row["base_prompt"],
|
59 |
-
"sfinae_prompt": row["sfinae_prompt"],
|
60 |
-
"concepts_prompt": row["concepts_prompt"],
|
61 |
-
"starter_code": row["starter_code"],
|
62 |
-
"base_canonical_solution": row["base_canonical_solution"],
|
63 |
-
"sfinae_canonical_solution": row["sfinae_canonical_solution"],
|
64 |
-
"concepts_canonical_solution": row["concepts_canonical_solution"],
|
65 |
-
"tests": row["tests"],
|
66 |
-
"invalids": row["invalids"],
|
67 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
temp.jsonl
DELETED
File without changes
|