Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
|
|
@ -0,0 +1,5 @@
|
|||
NEW
|
||||
DIM A%(1,1)
|
||||
A%(0,0)=1
|
||||
A%(0,1)=2
|
||||
CALL-151 : REM enter the machine language monitor to inspect memory
|
||||
|
|
@ -0,0 +1 @@
|
|||
800.817 E000G dump the array memory and cold start BASIC
|
||||
|
|
@ -0,0 +1 @@
|
|||
DIM A(4,3,2,1)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
0 DATA3
|
||||
1 DIM A(4,3,2,1)
|
||||
2 GET A(4,3,2,1)
|
||||
3 INPUT A(4,3,2,1)
|
||||
4 READ A(4,3,2,1)
|
||||
|
|
@ -0,0 +1 @@
|
|||
RUN
|
||||
|
|
@ -0,0 +1 @@
|
|||
LET A(4,3,2,1) = 1 : REM the LET keyword is optional
|
||||
|
|
@ -0,0 +1 @@
|
|||
PRINT A(4,3,2,1) : REM arrays can be accessed in expressions
|
||||
|
|
@ -0,0 +1 @@
|
|||
A(4,3,2,1) = 2
|
||||
|
|
@ -0,0 +1 @@
|
|||
PRINT A(4,3,2,1)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
// convienince for printing the contents of a collection
|
||||
// convenience for printing the contents of a collection
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const std::vector<T>& c) {
|
||||
auto it = c.cbegin();
|
||||
|
|
@ -57,9 +57,9 @@ void fourDim() {
|
|||
}
|
||||
|
||||
int main() {
|
||||
/* C++ does not have native support for multi-dimensional arrays,
|
||||
/* C++ hasn't had native support for multi-dimensional arrays,
|
||||
* but classes could be written to make things easier to work with.
|
||||
* There are standard library classes which can be used for single dimension arrays.
|
||||
* std::vector<>, std::array<> and even int[] can be composed to create multidimensional arrays.
|
||||
* Also raw access is supported through pointers as in C.
|
||||
*/
|
||||
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
#include <array> // array
|
||||
#include <mdspan> // mdspan
|
||||
#include <numeric> // ranges::iota
|
||||
#include <print> // println
|
||||
#include <ranges> // views::{cartesian_product, iota, take, transform}
|
||||
#include <tuple> // apply
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <size_t... Extents>
|
||||
requires((Extents != dynamic_extent) && ...) && (sizeof...(Extents) < 10)
|
||||
static consteval auto generate_array(extents<size_t, Extents...>) -> array<int, (Extents * ...)> {
|
||||
|
||||
// Generate a sequence of numbers (0..size) to fit into the array
|
||||
auto ret = array<int, (Extents * ...)>{};
|
||||
ranges::iota(ret, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Given extents of size i, create right-index arrays of size i
|
||||
// That is, a combination of indices that increment from the right-side first
|
||||
template <size_t... Extents>
|
||||
requires((Extents != dynamic_extent) && ...)
|
||||
static consteval auto right_indices(extents<size_t, Extents...>) {
|
||||
|
||||
// Generate all combinations of (0..2, 0..3, 0..4, 0..5)
|
||||
constexpr auto index_ranges = views::cartesian_product(views::iota(size_t{}, Extents)...);
|
||||
|
||||
// Convert tuple of numbers (a, b, c, d) to array of numbers [a, b, c, d]
|
||||
constexpr auto tuple_to_array = [](auto &&tuple) {
|
||||
return apply([](auto... elems) { return array{elems...}; }, tuple);
|
||||
};
|
||||
|
||||
return index_ranges | views::transform(tuple_to_array);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// This type models the size of our backing array and the shape of the mdspan
|
||||
using exts = extents<size_t, 2, 3, 4, 5>;
|
||||
|
||||
auto backing_array = generate_array(exts{});
|
||||
constexpr auto array_indices = right_indices(exts{});
|
||||
|
||||
// mdspan accesses the underlying array in row-major ordering (std::layout_right) by default
|
||||
auto row_span = mdspan{backing_array.data(), exts{}};
|
||||
auto col_span = mdspan{backing_array.data(), layout_left::mapping{exts{}}};
|
||||
|
||||
// print out the rank count and size of the underlying data structure
|
||||
println("row_span.rank() = {}", row_span.rank());
|
||||
println("row_span.size() = {}", row_span.size());
|
||||
|
||||
// Display the size of each dimension
|
||||
for (auto &&i : views::iota(size_t{}, row_span.rank())) {
|
||||
println("row_span.extent({}) = {}, ", i, row_span.extent(i));
|
||||
}
|
||||
|
||||
/// Add-assign a value using the multidimensional subscript operator
|
||||
row_span[0, 0, 0, 0] += 999;
|
||||
|
||||
// We can't iterate through our dim_span directly, so we have to index through it instead
|
||||
// Here we demonstrate the ability to index into an mdspan with an array
|
||||
//
|
||||
// indexing out of bounds with [] is still undefined behavior
|
||||
// There is no .at() equivalent for throwing access
|
||||
|
||||
println("\n======================== Row-major =======================\n");
|
||||
|
||||
println("First 30 elements:\n{}",
|
||||
array_indices | views::take(30) |
|
||||
views::transform(
|
||||
[&]<class T, size_t N>(array<T, N> &&idc) -> int { return row_span[idc]; }));
|
||||
|
||||
println("\n=========== Column-major (right_array_indices) ===========\n");
|
||||
|
||||
println("First 30 elements:\n{}",
|
||||
array_indices | views::take(30) |
|
||||
views::transform(
|
||||
[&]<class T, size_t N>(array<T, N> &&idc) -> int { return col_span[idc]; }));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue