#!/usr/bin/env dub
/+ dub.sdl:
name "fitbench"
buildType "checked" {
buildOptions "optimize" "inline" "debugInfo"
}
buildType "bench" {
buildOptions "releaseMode" "optimize" "inline" "noBoundsCheck"
dflags "-O3" "-mcpu=native" platform="ldc"
}
+/
/**
* Fused vs separate intrinsic ("fit") sizing for an immediate-mode UI
* layout, Clay-style. See README.md.
*
* Variants (all end-to-end: build + fit):
* fused-aos fit accumulated on a stack while building, written at close
* sep-aos build, then reverse pre-order sweep over the fat records
* sep-soa build into hot SoA arrays + cold payload, reverse sweep on SoA
* fused-soa fused accumulation, writes into SoA arrays
* level-soa sep-soa build (+depth byte), then counting-sort by depth so
* siblings are contiguous, vectorised per-parent sum/max,
* bottom-up by level, scatter back
* Plus rest-aos / rest-soa: Clay-style grow along x, grow along y, positions.
*/
module (module) fitbenchFused vs separate intrinsic ("fit") sizing for an immediate-mode UI
layout, Clay-style. See README.md.
Variants (all end-to-end: build + fit):
fused-aos fit accumulated on a stack while building, written at close
sep-aos build, then reverse pre-order sweep over the fat records
sep-soa build into hot SoA arrays + cold payload, reverse sweep on SoA
fused-soa fused accumulation, writes into SoA arrays
level-soa sep-soa build (+depth byte), then counting-sort by depth so
siblings are contiguous, vectorised per-parent sum/max,
bottom-up by level, scatter back
Plus rest-aos / rest-soa: Clay-style grow along x, grow along y, positions.
fitbench;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.stdlibD header file for C99.
pubs.opengroup.org/onlinepubs/009695399/basedefs/stdlib.h.html, stdlib.h
Source
core/stdc/stdlib.d
stdlib : (alias) fitbench.malloc = void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc, (alias) fitbench.free = void core.stdc.stdlib.free(void* ptr) nothrow @nogcfree, (alias) fitbench.exit = noreturn core.stdc.stdlib.exit(int status) nothrow @nogcexit;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.stringD header file for C99.
pubs.opengroup.org/onlinepubs/009695399/basedefs/string.h.html, string.h
Source
core/stdc/string.d
string : (alias) fitbench.memset = void* core.stdc.string.memset(return scope void* s, int c, ulong n) pure nothrow @nogcmemset;
import (package) corecore.(module) core.timeModule containing core time functionality, such as Duration (which
represents a duration of time) or MonoTime (which represents a
timestamp of the system's monotonic clock).
Various functions take a string (or strings) to represent a unit of time
(e.g. convert!("days", "hours")(numDays)). The valid strings to use
with such functions are "years", "months", "weeks", "days", "hours",
"minutes", "seconds", "msecs" (milliseconds), "usecs" (microseconds),
"hnsecs" (hecto-nanoseconds - i.e. 100 ns) or some subset thereof. There
are a few functions that also allow "nsecs", but very little actually
has precision greater than hnsecs.
Symbol Description Types Duration Represents a duration of time of weeks or less (kept internally as hnsecs). (e.g. 22 days or 700 seconds). TickDuration DEPRECATED Represents a duration of time in system clock ticks, using the highest precision that the system provides. MonoTime Represents a monotonic timestamp in system clock ticks, using the highest precision that the system provides. Functions convert Generic way of converting between two time units. dur Allows constructing a Duration from the given time units with the given length. weeks days hours
minutes seconds msecs
usecs hnsecs nsecs |
Convenience aliases for dur. |
| abs | Returns the absolute value of a duration. |
From Duration
From TickDuration
From units
To Duration tickDuration.to, std,conv!Duration() dur!"msecs"(5) or 5.msecs()
| To TickDuration |
duration.to, std,conv!TickDuration() |
|
TickDuration.from!"msecs"(msecs) |
| To units |
duration.total!"days" |
tickDuration.msecs |
convert!("days", "msecs")(msecs) |
Source
core/time.d
time : (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime;
import (package) stdstd.(module) std.algorithmThis package implements generic algorithms oriented towards the processing of
sequences. Sequences processed by these functions define range-based
interfaces. See also Reference on ranges and
tutorial on ranges.
Algorithms are categorized into the following submodules:
Submodule Functions
| Searching |
all
any
balancedParens
boyerMooreFinder
canFind
commonPrefix
count
countUntil
endsWith
find
findAdjacent
findAmong
findSkip
findSplit
findSplitAfter
findSplitBefore
minCount
maxCount
minElement
maxElement
minIndex
maxIndex
minPos
maxPos
skipOver
startsWith
until
|
| Comparison |
among
castSwitch
clamp
cmp
either
equal
isPermutation
isSameLength
levenshteinDistance
levenshteinDistanceAndPath
max
min
mismatch
predSwitch
|
| Iteration |
cache
cacheBidirectional
chunkBy
cumulativeFold
each
filter
filterBidirectional
fold
group
joiner
map
mean
permutations
reduce
splitWhen
splitter
substitute
sum
uniq
|
| Sorting |
completeSort
isPartitioned
isSorted
isStrictlyMonotonic
ordered
strictlyOrdered
makeIndex
merge
multiSort
nextEvenPermutation
nextPermutation
nthPermutation
partialSort
partition
partition3
schwartzSort
sort
topN
topNCopy
topNIndex
|
| Set operations (setops) |
cartesianProduct
largestPartialIntersection
largestPartialIntersectionWeighted
multiwayMerge
multiwayUnion
setDifference
setIntersection
setSymmetricDifference
|
| Mutation |
bringToFront
copy
fill
initializeAll
move
moveAll
moveSome
moveEmplace
moveEmplaceAll
moveEmplaceSome
remove
reverse
strip
stripLeft
stripRight
swap
swapRanges
uninitializedFill
|
Many functions in this package are parameterized with a predicate.
The predicate may be any suitable callable type
(a function, a delegate, a functor, or a lambda), or a
compile-time string. The string may consist of any legal D
expression that uses the symbol a (for unary functions) or the
symbols a and b (for binary functions). These names will NOT
interfere with other homonym symbols in user code because they are
evaluated in a different context. The default for all binary
comparison predicates is "a == b" for unordered operations and
"a < b" for ordered operations.
Example
int[] a = ...;
static bool greater(int a, int b)
{
return a > b;
}
sort!greater(a); // predicate as alias
sort!((a, b) => a > b)(a); // predicate as a lambda.
sort!"a > b"(a); // predicate as string
// (no ambiguity with array name)
sort(a); // no predicate, "a < b" is implicit
Source
std/algorithm/package.d
algorithm : (alias template) fitbench.sort = std.algorithm.sorting.sort(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable, Range)(Range r)Sorts a random-access range according to the predicate less.
Performs O(r.length * log(r.length)) evaluations of less. If less involves
expensive computations on the sort key, it may be worthwhile to use
schwartzSort instead.
Stable sorting requires hasAssignableElements!Range to be true.
sort returns a SortedRange over the original range,
allowing functions that can take advantage of sorted data to know that the
range is sorted and adjust accordingly. The SortedRange is a
wrapper around the original range, so both it and the original range are sorted.
Other functions can't know that the original range has been sorted, but
they can know that SortedRange has been sorted.
Preconditions
The predicate is expected to satisfy certain rules in order for sort to
behave as expected - otherwise, the program may fail on certain inputs (but not
others) when not compiled in release mode, due to the cursory assumeSorted
check. Specifically, sort expects less(a,b) && less(b,c) to imply
less(a,c) (transitivity), and, conversely, !less(a,b) && !less(b,c) to
imply !less(a,c). Note that the default predicate ("a < b") does not
always satisfy these conditions for floating point types, because the expression
will always be false when either a or b is NaN.
Use cmp instead.
Algorithms
Introsort is used for unstable sorting and
Timsort is used for stable sorting.
Each algorithm has benefits beyond stability. Introsort is generally faster but
Timsort may achieve greater speeds on data with low entropy or if predicate calls
are expensive. Introsort performs no allocations whereas Timsort will perform one
or more allocations per call. Both algorithms have O(n log n) worst-case
time complexity.
sort, (alias template) fitbench.max = std.algorithm.comparison.max(T...)(T args) if (T.length >= 2 && !is(CommonType!T == void))Iterates the passed arguments and returns the maximum value.
max, (alias template) fitbench.min = std.algorithm.comparison.min(T...)(T args) if (T.length >= 2 && !is(CommonType!T == void))Iterates the passed arguments and returns the minimum value.
min, (alias template) fitbench.canFind = std.algorithm.searching.canFind(alias pred = "a == b")Convenience function. Like find, but only returns whether or not the search
was successful.
For more information about pred see find.
canFind;
import (package) stdstd.(module) std.convA one-stop shop for converting values from one type to another.
Category Functions Generic asOriginalType castFrom parse to toChars bitCast Strings text wtext dtext writeText writeWText writeDText hexString Numeric octal roundTo signed unsigned Exceptions ConvException ConvOverflowException
Source
std/conv.d
conv : (alias template) fitbench.to = std.conv.to(T)The to template converts a value from one type to another.
The source type is deduced and the target type must be specified, for example the
expression to`!int(42.0)` converts the number 42 from
`double` to `int`. The conversion is "safe", i.e.,
it checks for overflow; to!int(4.2e10) would throw the
ConvOverflowException exception. Overflow checks are only
inserted when necessary, e.g., ``to!double(42) does not do
any checking because any int fits in a double.
Conversions from string to numeric types differ from the C equivalents
atoi() and atol() by checking for overflow and not allowing whitespace.
For conversion of strings to signed types, the grammar recognized is:
Integer:
Sign UnsignedInteger
UnsignedInteger
Sign:
+
-
For conversion to unsigned types, the grammar recognized is:
UnsignedInteger:
DecimalDigit
DecimalDigit UnsignedInteger
to;
import (package) stdstd.(module) std.mathContains the elementary mathematical functions (powers, roots,
and trigonometric functions), and low-level floating-point operations.
Mathematical special functions are available in std.mathspecial.
Category Members Constants E PI PI_2 PI4 M1_PI M2_PI M2_SQRTPI LN10 LN2 LOG2 LOG2E LOG2T LOG10E SQRT2 SQRT1_2 Algebraic abs fabs sqrt cbrt hypot poly nextPow2 truncPow2 Trigonometry sin cos tan asin acos atan atan2 sinh cosh tanh asinh acosh atanh Rounding ceil floor round lround trunc rint lrint nearbyint rndtol quantize Exponentiation & Logarithms pow powmod exp exp2 expm1 ldexp frexp log log2 log10 logb ilogb log1p scalbn Remainder fmod modf remainder remquo Floating-point operations approxEqual feqrel fdim fmax fmin fma isClose nextDown nextUp nextafter NaN getNaNPayload cmp Introspection isFinite isIdentical isInfinity isNaN isNormal isSubnormal signbit sgn copysign isPowerOf2 Hardware Control IeeeFlags ieeeFlags resetIeeeFlags FloatingPointControl
The functionality closely follows the IEEE754-2008 standard for
floating-point arithmetic, including the use of camelCase names rather
than C99-style lower case names. All of these functions behave correctly
when presented with an infinity or NaN.
The following IEEE 'real' formats are currently supported:
64 bit Big-endian 'double' (eg PowerPC)
128 bit Big-endian 'quadruple' (eg SPARC)
64 bit Little-endian 'double' (eg x86-SSE2)
80 bit Little-endian, with implied bit 'real80' (eg x87, Itanium)
128 bit Little-endian 'quadruple' (not implemented on any known processor!)
Non-IEEE 128 bit Big-endian 'doubledouble' (eg PowerPC) has partial support
Unlike C, there is no global 'errno' variable. Consequently, almost all of
these functions are pure nothrow.
Source
std/math/package.d
math : (alias template) fitbench.pow = std.math.exponential.pow(F, G)(F x, G n) if (isFloatingPoint!F && isIntegral!G)Compute the value of x n, where n is an integer
pow, (alias) fitbench.ceil = real std.math.rounding.ceil(real x) pure nothrow @nogc @trustedReturns the value of x rounded upward to the next integer
(toward positive infinity).
ceil;
import (package) stdstd.(module) std.randomFacilities for random number generation.
Category Functions Uniform sampling uniform uniform01 uniformDistribution Element sampling choice dice Range sampling randomCover randomSample Default Random Engines rndGen Random unpredictableSeed Linear Congruential Engines MinstdRand MinstdRand0 LinearCongruentialEngine Mersenne Twister Engines Mt19937 Mt19937_64 MersenneTwisterEngine Xorshift Engines Xorshift XorshiftEngine Xorshift32 Xorshift64 Xorshift96 Xorshift128 Xorshift160 Xorshift192 Shuffle partialShuffle randomShuffle Traits isSeedable isUniformRNG
Disclaimer: The random number generators and API provided in this
module are not designed to be cryptographically secure, and are therefore
unsuitable for cryptographic or security-related purposes such as generating
authentication tokens or network sequence numbers. For such needs, please use a
reputable cryptographic library instead.
The new-style generator objects hold their own state so they are
immune of threading issues. The generators feature a number of
well-known and well-documented methods of generating random
numbers. An overall fast and reliable means to generate random numbers
is the Mt19937 generator, which derives its name from
"Mersenne Twister
with a period of 2 to the power of
19937". In memory-constrained situations,
linear congruential generators such as MinstdRand0 and MinstdRand might be
useful. The standard library provides an alias Random for
whichever generator it considers the most fit for the target
environment.
In addition to random number generators, this module features
distributions, which skew a generator's output statistical
distribution in various ways. So far the uniform distribution for
integers and real numbers have been implemented.
Source
std/random.d
Credits
The entire random number library architecture is derived from the
excellent C++0X
random number facility proposed by Jens Maurer and contributed to by
researchers at the Fermi laboratory (excluding Xorshift).
Examples
import std.algorithm.comparison : among, equal;
import std.range : iota;
// seed a random generator with a constant
auto rnd = Random(42);
// Generate a uniformly-distributed integer in the range [0, 14]
// If no random generator is passed, the global `rndGen` would be used
auto i = uniform(0, 15, rnd);
assert(i >= 0 && i < 15);
// Generate a uniformly-distributed real in the range [0, 100)
auto r = uniform(0.0L, 100.0L, rnd);
assert(r >= 0 && r < 100);
// Sample from a custom type
enum Fruit { apple, mango, pear }
auto f = rnd.uniform!Fruit;
with(Fruit)
assert(f.among(apple, mango, pear));
// Generate a 32-bit random number
auto u = uniform!uint(rnd);
static assert(is(typeof(u) == uint));
// Generate a random number in the range in the range [0, 1)
auto u2 = uniform01(rnd);
assert(u2 >= 0 && u2 < 1);
// Select an element randomly
auto el = 10.iota.choice(rnd);
assert(0 <= el && el < 10);
// Throw a dice with custom proportions
// 0: 20%, 1: 10%, 2: 60%
auto val = rnd.dice(0.2, 0.1, 0.6);
assert(0 <= val && val <= 2);
auto rnd2 = MinstdRand0(42);
// Select a random subsample from a range
assert(10.iota.randomSample(3, rnd2).equal([7, 8, 9]));
// Cover all elements in an array in random order
version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147
assert(10.iota.randomCover(rnd2).equal([7, 4, 2, 0, 1, 6, 8, 3, 9, 5]));
else
assert(10.iota.randomCover(rnd2).equal([4, 8, 7, 3, 5, 9, 2, 6, 0, 1]));
// Shuffle an array
version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147
assert([0, 1, 2, 4, 5].randomShuffle(rnd2).equal([2, 0, 4, 5, 1]));
else
assert([0, 1, 2, 4, 5].randomShuffle(rnd2).equal([4, 2, 5, 0, 1]));
random : (struct) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u)Random, (alias template) fitbench.uniform = std.random.uniform(string boundaries = "[)", T1, T2)(T1 a, T2 b) if (!is(CommonType!(T1, T2) == void))Generates a number between a and b. The boundaries
parameter controls the shape of the interval (open vs. closed on
either side). Valid values for boundaries are "[]", "(]", "[)", and "()". The default interval
is closed to the left and open to the right. The version that does not
take urng uses the default generator rndGen.
uniform, (alias template) fitbench.uniform01 = std.random.uniform01(T = double)() if (isFloatingPoint!T)Generates a uniformly-distributed floating point number of type
T in the range [0, 1). If no random number generator is
specified, the default RNG rndGen will be used as the source
of randomness.
uniform01 offers a faster generation of random variates than
the equivalent uniform!"[)"(0.0, 1.0) and so may be preferred
for some applications.
uniform01;
import (package) stdstd.(module) std.stdioCategory Symbols File handles _popen File isFileHandle openNetwork stderr stdin stdout Reading chunks lines readf readfln readln Writing toFile write writef writefln writeln Misc KeepTerminator LockType StdioException
Standard I/O functions that extend core.stdc.stdio. core.stdc.stdio
is publically imported when importing std.stdio.
There are three layers of I/O:
The lowest layer is the operating system layer. The two main schemes are Windows and Posix.
C's stdio.h which unifies the two operating system schemes.
std.stdio, this module, unifies the various stdio.h implementations into
a high level package for D programs.
Source
std/stdio.d
stdio : (alias template) fitbench.writefln = std.stdio.writefln(alias fmt, A...)(A args) if (isSomeString!(typeof(fmt)))Equivalent to writef(fmt, args, '\n').
writefln, (alias template) fitbench.writeln = std.stdio.writeln(T...)(T args)Equivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln, stdout, stderr;
import (package) stdstd.(module) std.stringString handling functions.
Category Functions Searching column indexOf indexOfAny indexOfNeither lastIndexOf lastIndexOfAny lastIndexOfNeither Comparison isNumeric Mutation capitalize Pruning and Filling center chomp chompPrefix chop detabber detab entab entabber leftJustify outdent rightJustify strip stripLeft stripRight wrap Substitution abbrev soundex soundexer succ tr translate Miscellaneous assumeUTF fromStringz lineSplitter representation splitLines toStringz Objects of types string, wstring, and dstring are value types and cannot be mutated element-by-element. For using mutation during building strings, use char[], wchar[], or dchar[]. The xxxstring types are preferable because they don't exhibit undesired aliasing, thus making code more robust.
The following functions are publicly imported:
Module Functions Publicly imported functions std.algorithm cmp, std,algorithm,comparison count, std,algorithm,searching endsWith, std,algorithm,searching startsWith, std,algorithm,searching std.array join, std,array replace, std,array replaceInPlace, std,array split, std,array empty, std,array std.format format, std,format sformat, std,format std.uni icmp, std,uni toLower, std,uni toLowerInPlace, std,uni toUpper, std,uni toUpperInPlace, std,uni There is a rich set of functions for string handling defined in other modules. Functions related to Unicode and ASCII are found in std.uni and std.ascii, respectively. Other functions that have a wider generality than just strings can be found in std.algorithm and std.range.
Source
std/string.d
string : (alias template) fitbench.split = std.array.split(S)(S s) if (isSomeString!S)Eagerly splits range into an array, using sep as the delimiter.
When no delimiter is provided, strings are split into an array of words,
using whitespace as delimiter.
Runs of whitespace are merged together (no empty words are produced).
The range must be a forward range.
The separator can be a value of the same type as the elements in range
or it can be another forward range.
split;
version (LDCLDC) import ldc.attributes : fastmath;
else struct (struct) fitbench.fastmathfastmath {}
// ---------------------------------------------------------------------------
// Event stream: what "user UI code" does, replayed identically by every variant
// ---------------------------------------------------------------------------
enum : ubyte { (enum value) fitbench.OpOpen = cast(ubyte)0uOpOpen = 0, (enum value) fitbench.OpLabel = cast(ubyte)1uOpLabel = 1, (enum value) fitbench.OpClose = cast(ubyte)2uOpClose = 2 }
enum : ubyte { (enum value) fitbench.GrowX = cast(ubyte)1uGrowX = 1, (enum value) fitbench.GrowY = cast(ubyte)2uGrowY = 2 }
struct (struct) fitbench.EvEv
{
ubyte (field) ubyte fitbench.Ev.opop, (field) ubyte fitbench.Ev.axisaxis, (field) ubyte fitbench.Ev.growgrow, (field) ubyte fitbench.Ev.padpad; // pad: per side
ushort (field) ushort fitbench.Ev.gapgap, (field) ushort fitbench.Ev.textLentextLen;
uint (field) uint fitbench.Ev.textOfftextOff;
}
static assert((struct) fitbench.EvEv.(constant) ulong fitbench.Ev.sizeof = 12LUsizeof == 12);
enum (constant) int fitbench.poolLen = 65536poolLen = 1 << 16;
enum (constant) float fitbench.glyphW = 8.0FglyphW = 8.0f, (constant) float fitbench.lineH = 16.0FlineH = 16.0f;
struct (struct) fitbench.GenGen
{
(struct) fitbench.EvEv[] (field) fitbench.Ev[] fitbench.Gen.evsevs;
(struct) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u)Random (field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng;
int (field) int fitbench.Gen.nodesnodes;
int (field) int fitbench.Gen.maxDepthmaxDepth;
int (field) int fitbench.Gen.depthdepth;
int (field) int fitbench.Gen.maxFanmaxFan;
void void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)open(ubyte (parameter) ubyte axisaxis, ubyte (parameter) ubyte growgrow, ubyte (parameter) ubyte padpad, ushort (parameter) ushort gapgap)
{
(field) fitbench.Ev[] fitbench.Gen.evsevs ~= (struct) fitbench.EvEv((enum value) fitbench.OpOpen = cast(ubyte)0uOpOpen, (parameter) ubyte axisaxis, (parameter) ubyte growgrow, (parameter) ubyte padpad, (parameter) ushort gapgap, 0, 0);
++(field) int fitbench.Gen.nodesnodes;
++(field) int fitbench.Gen.depthdepth;
(field) int fitbench.Gen.maxDepthmaxDepth = int std.algorithm.comparison.max!(int, int)(int a, int b) pure nothrow @nogc @safeIterates the passed arguments and returns the maximum value.
Examples
int a = 5;
short b = 6;
double c = 2;
auto d = max(a, b);
assert(is(typeof(d) == int));
assert(d == 6);
auto e = min(a, b, c);
assert(is(typeof(e) == double));
assert(e == 2);
max((field) int fitbench.Gen.maxDepthmaxDepth, (field) int fitbench.Gen.depthdepth);
}
void void fitbench.Gen.close()close()
{
(field) fitbench.Ev[] fitbench.Gen.evsevs ~= (struct) fitbench.EvEv((enum value) fitbench.OpClose = cast(ubyte)2uOpClose);
--(field) int fitbench.Gen.depthdepth;
}
void void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)label(ubyte (parameter) ubyte growgrow = 0)
{
ushort (local variable) ushort lenlen = cast(ushort) int std.random.uniform!("[)", int, int, std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u))(int a, int b, ref std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) rng) pure @safeCreate an array of random numbers using range functions and UFCS
Examples
import std.conv : to;
import std.meta : AliasSeq;
import std.range.primitives : isForwardRange;
import std.traits : isIntegral, isSomeChar;
auto gen = Mt19937(123_456_789);
static assert(isForwardRange!(typeof(gen)));
auto a = uniform(0, 1024, gen);
assert(0 <= a && a <= 1024);
auto b = uniform(0.0f, 1.0f, gen);
assert(0 <= b && b < 1, to!string(b));
auto c = uniform(0.0, 1.0);
assert(0 <= c && c < 1);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short, ushort,
int, uint, long, ulong, float, double, real))
{{
T lo = 0, hi = 100;
// Try tests with each of the possible bounds
{
T init = uniform(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[)"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"(]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"()"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
/* Test case with closed boundaries covering whole range
* of integral type
*/
static if (isIntegral!T || isSomeChar!T)
{
foreach (immutable _; 0 .. 100)
{
auto u = uniform!"[]"(T.min, T.max);
static assert(is(typeof(u) == T));
assert(T.min <= u, "Lower bound violation for uniform!\"[]\" with " ~ T.stringof);
assert(u <= T.max, "Upper bound violation for uniform!\"[]\" with " ~ T.stringof);
}
}
}}
auto reproRng = Xorshift(239842);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short,
ushort, int, uint, long, ulong))
{{
T lo = T.min + 10, hi = T.max - 10;
T init = uniform(lo, hi, reproRng);
size_t i = 50;
while (--i && uniform(lo, hi, reproRng) == init) {}
assert(i > 0);
}}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform!"[]"('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'd') sawUB = true;
assert('a' <= x && x <= 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'c') sawUB = true;
assert('a' <= x && x < 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable int lo = -2, hi = 2;
auto x = uniform!"()"(lo, hi, reproRng);
if (x == (lo+1)) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo < x && x < hi);
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable ubyte lo = 0, hi = 5;
auto x = uniform(lo, hi, reproRng);
if (x == lo) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo <= x && x < hi);
}
assert(sawLB && sawUB);
}
{
foreach (i; 0 .. 30)
{
assert(i == uniform(i, i+1, reproRng));
}
}
uniform(3, 31, (field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng);
(field) fitbench.Ev[] fitbench.Gen.evsevs ~= (struct) fitbench.EvEv((enum value) fitbench.OpLabel = cast(ubyte)1uOpLabel, 0, (parameter) ubyte growgrow, 0, 0, (local variable) ushort lenlen, uint std.random.uniform!("[)", uint, uint, std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u))(uint a, uint b, ref std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) rng) pure @safeCreate an array of random numbers using range functions and UFCS
Examples
import std.conv : to;
import std.meta : AliasSeq;
import std.range.primitives : isForwardRange;
import std.traits : isIntegral, isSomeChar;
auto gen = Mt19937(123_456_789);
static assert(isForwardRange!(typeof(gen)));
auto a = uniform(0, 1024, gen);
assert(0 <= a && a <= 1024);
auto b = uniform(0.0f, 1.0f, gen);
assert(0 <= b && b < 1, to!string(b));
auto c = uniform(0.0, 1.0);
assert(0 <= c && c < 1);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short, ushort,
int, uint, long, ulong, float, double, real))
{{
T lo = 0, hi = 100;
// Try tests with each of the possible bounds
{
T init = uniform(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[)"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"(]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"()"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
/* Test case with closed boundaries covering whole range
* of integral type
*/
static if (isIntegral!T || isSomeChar!T)
{
foreach (immutable _; 0 .. 100)
{
auto u = uniform!"[]"(T.min, T.max);
static assert(is(typeof(u) == T));
assert(T.min <= u, "Lower bound violation for uniform!\"[]\" with " ~ T.stringof);
assert(u <= T.max, "Upper bound violation for uniform!\"[]\" with " ~ T.stringof);
}
}
}}
auto reproRng = Xorshift(239842);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short,
ushort, int, uint, long, ulong))
{{
T lo = T.min + 10, hi = T.max - 10;
T init = uniform(lo, hi, reproRng);
size_t i = 50;
while (--i && uniform(lo, hi, reproRng) == init) {}
assert(i > 0);
}}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform!"[]"('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'd') sawUB = true;
assert('a' <= x && x <= 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'c') sawUB = true;
assert('a' <= x && x < 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable int lo = -2, hi = 2;
auto x = uniform!"()"(lo, hi, reproRng);
if (x == (lo+1)) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo < x && x < hi);
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable ubyte lo = 0, hi = 5;
auto x = uniform(lo, hi, reproRng);
if (x == lo) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo <= x && x < hi);
}
assert(sawLB && sawUB);
}
{
foreach (i; 0 .. 30)
{
assert(i == uniform(i, i+1, reproRng));
}
}
uniform(0u, cast(uint)((constant) int fitbench.poolLen = 65536poolLen - 32), (field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng));
++(field) int fitbench.Gen.nodesnodes;
(field) int fitbench.Gen.maxDepthmaxDepth = int std.algorithm.comparison.max!(int, int)(int a, int b) pure nothrow @nogc @safeIterates the passed arguments and returns the maximum value.
Examples
int a = 5;
short b = 6;
double c = 2;
auto d = max(a, b);
assert(is(typeof(d) == int));
assert(d == 6);
auto e = min(a, b, c);
assert(is(typeof(e) == double));
assert(e == 2);
max((field) int fitbench.Gen.maxDepthmaxDepth, (field) int fitbench.Gen.depthdepth + 1);
}
}
/// root col > panel col > (header row(label,label), scroll col > rows(label, label*, label))
(struct) fitbench.GenGen fitbench.Gen fitbench.genList(int n)root col > panel col > (header row(label,label), scroll col > rows(label, label*, label))
genList(int (parameter) int nn)
{
(struct) fitbench.GenGen (local variable) fitbench.Gen gg;
(local variable) fitbench.Gen gg.(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng = (struct) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u)Random(42);
(local variable) fitbench.Gen gg.void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)open(1, 0, 0, 0); // root column
(local variable) fitbench.Gen gg.void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)open(1, (enum value) fitbench.GrowX = cast(ubyte)1uGrowX | (enum value) fitbench.GrowY = cast(ubyte)2uGrowY, 8, 4); // panel
(local variable) fitbench.Gen gg.void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)open(0, (enum value) fitbench.GrowX = cast(ubyte)1uGrowX, 4, 8); // header
(local variable) fitbench.Gen gg.void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)label();
(local variable) fitbench.Gen gg.void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)label((enum value) fitbench.GrowX = cast(ubyte)1uGrowX);
(local variable) fitbench.Gen gg.void fitbench.Gen.close()close();
(local variable) fitbench.Gen gg.void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)open(1, (enum value) fitbench.GrowX = cast(ubyte)1uGrowX | (enum value) fitbench.GrowY = cast(ubyte)2uGrowY, 0, 2); // scroll column
int (local variable) int rowsrows = ((parameter) int nn - 6) / 4;
(local variable) fitbench.Gen gg.(field) int fitbench.Gen.maxFanmaxFan = (local variable) int rowsrows;
foreach ((local variable) int rr; 0 .. (local variable) int rowsrows)
{
(local variable) fitbench.Gen gg.void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)open(0, (enum value) fitbench.GrowX = cast(ubyte)1uGrowX, 4, 8);
(local variable) fitbench.Gen gg.void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)label();
(local variable) fitbench.Gen gg.void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)label((enum value) fitbench.GrowX = cast(ubyte)1uGrowX);
(local variable) fitbench.Gen gg.void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)label();
(local variable) fitbench.Gen gg.void fitbench.Gen.close()close();
}
(local variable) fitbench.Gen gg.void fitbench.Gen.close()close();
(local variable) fitbench.Gen gg.void fitbench.Gen.close()close();
(local variable) fitbench.Gen gg.void fitbench.Gen.close()close();
return (local variable) fitbench.Gen gg;
}
/// Balanced-ish nested panels: fan-out mostly 2..8, sometimes a 50..1000 list,
/// depth <= 12, exactly n nodes.
(struct) fitbench.GenGen fitbench.Gen fitbench.genPanels(int n)Balanced-ish nested panels: fan-out mostly 2..8, sometimes a 50..1000 list,
depth <= 12, exactly n nodes.
genPanels(int (parameter) int nn)
{
(struct) fitbench.GenGen (local variable) fitbench.Gen gg;
(local variable) fitbench.Gen gg.(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng = (struct) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u)Random(7);
enum (constant) int fitbench.genPanels.maxD = 12maxD = 12;
void void fitbench.genPanels.node(int budget, int depth) @systemnode(int (parameter) int budgetbudget, int (parameter) int depthdepth)
{
if ((parameter) int budgetbudget == 1)
{
(local variable) fitbench.Gen gg.void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)label(int std.random.uniform!("[)", int, int, std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u))(int a, int b, ref std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) rng) pure @safeCreate an array of random numbers using range functions and UFCS
Examples
import std.conv : to;
import std.meta : AliasSeq;
import std.range.primitives : isForwardRange;
import std.traits : isIntegral, isSomeChar;
auto gen = Mt19937(123_456_789);
static assert(isForwardRange!(typeof(gen)));
auto a = uniform(0, 1024, gen);
assert(0 <= a && a <= 1024);
auto b = uniform(0.0f, 1.0f, gen);
assert(0 <= b && b < 1, to!string(b));
auto c = uniform(0.0, 1.0);
assert(0 <= c && c < 1);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short, ushort,
int, uint, long, ulong, float, double, real))
{{
T lo = 0, hi = 100;
// Try tests with each of the possible bounds
{
T init = uniform(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[)"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"(]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"()"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
/* Test case with closed boundaries covering whole range
* of integral type
*/
static if (isIntegral!T || isSomeChar!T)
{
foreach (immutable _; 0 .. 100)
{
auto u = uniform!"[]"(T.min, T.max);
static assert(is(typeof(u) == T));
assert(T.min <= u, "Lower bound violation for uniform!\"[]\" with " ~ T.stringof);
assert(u <= T.max, "Upper bound violation for uniform!\"[]\" with " ~ T.stringof);
}
}
}}
auto reproRng = Xorshift(239842);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short,
ushort, int, uint, long, ulong))
{{
T lo = T.min + 10, hi = T.max - 10;
T init = uniform(lo, hi, reproRng);
size_t i = 50;
while (--i && uniform(lo, hi, reproRng) == init) {}
assert(i > 0);
}}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform!"[]"('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'd') sawUB = true;
assert('a' <= x && x <= 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'c') sawUB = true;
assert('a' <= x && x < 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable int lo = -2, hi = 2;
auto x = uniform!"()"(lo, hi, reproRng);
if (x == (lo+1)) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo < x && x < hi);
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable ubyte lo = 0, hi = 5;
auto x = uniform(lo, hi, reproRng);
if (x == lo) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo <= x && x < hi);
}
assert(sawLB && sawUB);
}
{
foreach (i; 0 .. 30)
{
assert(i == uniform(i, i+1, reproRng));
}
}
uniform(0, 8, (local variable) fitbench.Gen gg.(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng) == 0 ? (enum value) fitbench.GrowX = cast(ubyte)1uGrowX : 0);
return;
}
ubyte (local variable) ubyte axisaxis = cast(ubyte)(((parameter) int depthdepth & 1) ^ (int std.random.uniform!("[)", int, int, std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u))(int a, int b, ref std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) rng) pure @safeCreate an array of random numbers using range functions and UFCS
Examples
import std.conv : to;
import std.meta : AliasSeq;
import std.range.primitives : isForwardRange;
import std.traits : isIntegral, isSomeChar;
auto gen = Mt19937(123_456_789);
static assert(isForwardRange!(typeof(gen)));
auto a = uniform(0, 1024, gen);
assert(0 <= a && a <= 1024);
auto b = uniform(0.0f, 1.0f, gen);
assert(0 <= b && b < 1, to!string(b));
auto c = uniform(0.0, 1.0);
assert(0 <= c && c < 1);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short, ushort,
int, uint, long, ulong, float, double, real))
{{
T lo = 0, hi = 100;
// Try tests with each of the possible bounds
{
T init = uniform(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[)"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"(]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"()"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
/* Test case with closed boundaries covering whole range
* of integral type
*/
static if (isIntegral!T || isSomeChar!T)
{
foreach (immutable _; 0 .. 100)
{
auto u = uniform!"[]"(T.min, T.max);
static assert(is(typeof(u) == T));
assert(T.min <= u, "Lower bound violation for uniform!\"[]\" with " ~ T.stringof);
assert(u <= T.max, "Upper bound violation for uniform!\"[]\" with " ~ T.stringof);
}
}
}}
auto reproRng = Xorshift(239842);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short,
ushort, int, uint, long, ulong))
{{
T lo = T.min + 10, hi = T.max - 10;
T init = uniform(lo, hi, reproRng);
size_t i = 50;
while (--i && uniform(lo, hi, reproRng) == init) {}
assert(i > 0);
}}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform!"[]"('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'd') sawUB = true;
assert('a' <= x && x <= 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'c') sawUB = true;
assert('a' <= x && x < 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable int lo = -2, hi = 2;
auto x = uniform!"()"(lo, hi, reproRng);
if (x == (lo+1)) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo < x && x < hi);
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable ubyte lo = 0, hi = 5;
auto x = uniform(lo, hi, reproRng);
if (x == lo) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo <= x && x < hi);
}
assert(sawLB && sawUB);
}
{
foreach (i; 0 .. 30)
{
assert(i == uniform(i, i+1, reproRng));
}
}
uniform(0, 4, (local variable) fitbench.Gen gg.(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng) == 0));
ubyte (local variable) ubyte growgrow = cast(ubyte) int std.random.uniform!("[)", int, int, std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u))(int a, int b, ref std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) rng) pure @safeCreate an array of random numbers using range functions and UFCS
Examples
import std.conv : to;
import std.meta : AliasSeq;
import std.range.primitives : isForwardRange;
import std.traits : isIntegral, isSomeChar;
auto gen = Mt19937(123_456_789);
static assert(isForwardRange!(typeof(gen)));
auto a = uniform(0, 1024, gen);
assert(0 <= a && a <= 1024);
auto b = uniform(0.0f, 1.0f, gen);
assert(0 <= b && b < 1, to!string(b));
auto c = uniform(0.0, 1.0);
assert(0 <= c && c < 1);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short, ushort,
int, uint, long, ulong, float, double, real))
{{
T lo = 0, hi = 100;
// Try tests with each of the possible bounds
{
T init = uniform(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[)"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"(]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"()"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
/* Test case with closed boundaries covering whole range
* of integral type
*/
static if (isIntegral!T || isSomeChar!T)
{
foreach (immutable _; 0 .. 100)
{
auto u = uniform!"[]"(T.min, T.max);
static assert(is(typeof(u) == T));
assert(T.min <= u, "Lower bound violation for uniform!\"[]\" with " ~ T.stringof);
assert(u <= T.max, "Upper bound violation for uniform!\"[]\" with " ~ T.stringof);
}
}
}}
auto reproRng = Xorshift(239842);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short,
ushort, int, uint, long, ulong))
{{
T lo = T.min + 10, hi = T.max - 10;
T init = uniform(lo, hi, reproRng);
size_t i = 50;
while (--i && uniform(lo, hi, reproRng) == init) {}
assert(i > 0);
}}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform!"[]"('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'd') sawUB = true;
assert('a' <= x && x <= 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'c') sawUB = true;
assert('a' <= x && x < 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable int lo = -2, hi = 2;
auto x = uniform!"()"(lo, hi, reproRng);
if (x == (lo+1)) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo < x && x < hi);
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable ubyte lo = 0, hi = 5;
auto x = uniform(lo, hi, reproRng);
if (x == lo) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo <= x && x < hi);
}
assert(sawLB && sawUB);
}
{
foreach (i; 0 .. 30)
{
assert(i == uniform(i, i+1, reproRng));
}
}
uniform(0, 4, (local variable) fitbench.Gen gg.(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng);
(local variable) fitbench.Gen gg.void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)open((local variable) ubyte axisaxis, (local variable) ubyte growgrow, cast(ubyte) int std.random.uniform!("[)", int, int, std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u))(int a, int b, ref std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) rng) pure @safeCreate an array of random numbers using range functions and UFCS
Examples
import std.conv : to;
import std.meta : AliasSeq;
import std.range.primitives : isForwardRange;
import std.traits : isIntegral, isSomeChar;
auto gen = Mt19937(123_456_789);
static assert(isForwardRange!(typeof(gen)));
auto a = uniform(0, 1024, gen);
assert(0 <= a && a <= 1024);
auto b = uniform(0.0f, 1.0f, gen);
assert(0 <= b && b < 1, to!string(b));
auto c = uniform(0.0, 1.0);
assert(0 <= c && c < 1);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short, ushort,
int, uint, long, ulong, float, double, real))
{{
T lo = 0, hi = 100;
// Try tests with each of the possible bounds
{
T init = uniform(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[)"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"(]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"()"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
/* Test case with closed boundaries covering whole range
* of integral type
*/
static if (isIntegral!T || isSomeChar!T)
{
foreach (immutable _; 0 .. 100)
{
auto u = uniform!"[]"(T.min, T.max);
static assert(is(typeof(u) == T));
assert(T.min <= u, "Lower bound violation for uniform!\"[]\" with " ~ T.stringof);
assert(u <= T.max, "Upper bound violation for uniform!\"[]\" with " ~ T.stringof);
}
}
}}
auto reproRng = Xorshift(239842);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short,
ushort, int, uint, long, ulong))
{{
T lo = T.min + 10, hi = T.max - 10;
T init = uniform(lo, hi, reproRng);
size_t i = 50;
while (--i && uniform(lo, hi, reproRng) == init) {}
assert(i > 0);
}}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform!"[]"('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'd') sawUB = true;
assert('a' <= x && x <= 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'c') sawUB = true;
assert('a' <= x && x < 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable int lo = -2, hi = 2;
auto x = uniform!"()"(lo, hi, reproRng);
if (x == (lo+1)) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo < x && x < hi);
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable ubyte lo = 0, hi = 5;
auto x = uniform(lo, hi, reproRng);
if (x == lo) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo <= x && x < hi);
}
assert(sawLB && sawUB);
}
{
foreach (i; 0 .. 30)
{
assert(i == uniform(i, i+1, reproRng));
}
}
uniform(0, 9, (local variable) fitbench.Gen gg.(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng), cast(ushort) int std.random.uniform!("[)", int, int, std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u))(int a, int b, ref std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) rng) pure @safeCreate an array of random numbers using range functions and UFCS
Examples
import std.conv : to;
import std.meta : AliasSeq;
import std.range.primitives : isForwardRange;
import std.traits : isIntegral, isSomeChar;
auto gen = Mt19937(123_456_789);
static assert(isForwardRange!(typeof(gen)));
auto a = uniform(0, 1024, gen);
assert(0 <= a && a <= 1024);
auto b = uniform(0.0f, 1.0f, gen);
assert(0 <= b && b < 1, to!string(b));
auto c = uniform(0.0, 1.0);
assert(0 <= c && c < 1);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short, ushort,
int, uint, long, ulong, float, double, real))
{{
T lo = 0, hi = 100;
// Try tests with each of the possible bounds
{
T init = uniform(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[)"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"(]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"()"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
/* Test case with closed boundaries covering whole range
* of integral type
*/
static if (isIntegral!T || isSomeChar!T)
{
foreach (immutable _; 0 .. 100)
{
auto u = uniform!"[]"(T.min, T.max);
static assert(is(typeof(u) == T));
assert(T.min <= u, "Lower bound violation for uniform!\"[]\" with " ~ T.stringof);
assert(u <= T.max, "Upper bound violation for uniform!\"[]\" with " ~ T.stringof);
}
}
}}
auto reproRng = Xorshift(239842);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short,
ushort, int, uint, long, ulong))
{{
T lo = T.min + 10, hi = T.max - 10;
T init = uniform(lo, hi, reproRng);
size_t i = 50;
while (--i && uniform(lo, hi, reproRng) == init) {}
assert(i > 0);
}}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform!"[]"('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'd') sawUB = true;
assert('a' <= x && x <= 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'c') sawUB = true;
assert('a' <= x && x < 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable int lo = -2, hi = 2;
auto x = uniform!"()"(lo, hi, reproRng);
if (x == (lo+1)) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo < x && x < hi);
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable ubyte lo = 0, hi = 5;
auto x = uniform(lo, hi, reproRng);
if (x == lo) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo <= x && x < hi);
}
assert(sawLB && sawUB);
}
{
foreach (i; 0 .. 30)
{
assert(i == uniform(i, i+1, reproRng));
}
}
uniform(0, 9, (local variable) fitbench.Gen gg.(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng));
int (local variable) int remrem = (parameter) int budgetbudget - 1;
int (local variable) int ff;
if ((local variable) int remrem <= 8 || (parameter) int depthdepth >= (constant) int fitbench.genPanels.maxD = 12maxD - 2)
(local variable) int ff = (local variable) int remrem;
else
{
(local variable) int ff = int std.random.uniform!("[)", int, int, std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u))(int a, int b, ref std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) rng) pure @safeCreate an array of random numbers using range functions and UFCS
Examples
import std.conv : to;
import std.meta : AliasSeq;
import std.range.primitives : isForwardRange;
import std.traits : isIntegral, isSomeChar;
auto gen = Mt19937(123_456_789);
static assert(isForwardRange!(typeof(gen)));
auto a = uniform(0, 1024, gen);
assert(0 <= a && a <= 1024);
auto b = uniform(0.0f, 1.0f, gen);
assert(0 <= b && b < 1, to!string(b));
auto c = uniform(0.0, 1.0);
assert(0 <= c && c < 1);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short, ushort,
int, uint, long, ulong, float, double, real))
{{
T lo = 0, hi = 100;
// Try tests with each of the possible bounds
{
T init = uniform(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[)"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"(]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"()"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
/* Test case with closed boundaries covering whole range
* of integral type
*/
static if (isIntegral!T || isSomeChar!T)
{
foreach (immutable _; 0 .. 100)
{
auto u = uniform!"[]"(T.min, T.max);
static assert(is(typeof(u) == T));
assert(T.min <= u, "Lower bound violation for uniform!\"[]\" with " ~ T.stringof);
assert(u <= T.max, "Upper bound violation for uniform!\"[]\" with " ~ T.stringof);
}
}
}}
auto reproRng = Xorshift(239842);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short,
ushort, int, uint, long, ulong))
{{
T lo = T.min + 10, hi = T.max - 10;
T init = uniform(lo, hi, reproRng);
size_t i = 50;
while (--i && uniform(lo, hi, reproRng) == init) {}
assert(i > 0);
}}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform!"[]"('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'd') sawUB = true;
assert('a' <= x && x <= 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'c') sawUB = true;
assert('a' <= x && x < 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable int lo = -2, hi = 2;
auto x = uniform!"()"(lo, hi, reproRng);
if (x == (lo+1)) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo < x && x < hi);
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable ubyte lo = 0, hi = 5;
auto x = uniform(lo, hi, reproRng);
if (x == lo) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo <= x && x < hi);
}
assert(sawLB && sawUB);
}
{
foreach (i; 0 .. 30)
{
assert(i == uniform(i, i+1, reproRng));
}
}
uniform(2, 9, (local variable) fitbench.Gen gg.(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng);
if ((local variable) int remrem >= 100 && int std.random.uniform!("[)", int, int, std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u))(int a, int b, ref std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) rng) pure @safeCreate an array of random numbers using range functions and UFCS
Examples
import std.conv : to;
import std.meta : AliasSeq;
import std.range.primitives : isForwardRange;
import std.traits : isIntegral, isSomeChar;
auto gen = Mt19937(123_456_789);
static assert(isForwardRange!(typeof(gen)));
auto a = uniform(0, 1024, gen);
assert(0 <= a && a <= 1024);
auto b = uniform(0.0f, 1.0f, gen);
assert(0 <= b && b < 1, to!string(b));
auto c = uniform(0.0, 1.0);
assert(0 <= c && c < 1);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short, ushort,
int, uint, long, ulong, float, double, real))
{{
T lo = 0, hi = 100;
// Try tests with each of the possible bounds
{
T init = uniform(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[)"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"(]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"()"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
/* Test case with closed boundaries covering whole range
* of integral type
*/
static if (isIntegral!T || isSomeChar!T)
{
foreach (immutable _; 0 .. 100)
{
auto u = uniform!"[]"(T.min, T.max);
static assert(is(typeof(u) == T));
assert(T.min <= u, "Lower bound violation for uniform!\"[]\" with " ~ T.stringof);
assert(u <= T.max, "Upper bound violation for uniform!\"[]\" with " ~ T.stringof);
}
}
}}
auto reproRng = Xorshift(239842);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short,
ushort, int, uint, long, ulong))
{{
T lo = T.min + 10, hi = T.max - 10;
T init = uniform(lo, hi, reproRng);
size_t i = 50;
while (--i && uniform(lo, hi, reproRng) == init) {}
assert(i > 0);
}}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform!"[]"('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'd') sawUB = true;
assert('a' <= x && x <= 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'c') sawUB = true;
assert('a' <= x && x < 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable int lo = -2, hi = 2;
auto x = uniform!"()"(lo, hi, reproRng);
if (x == (lo+1)) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo < x && x < hi);
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable ubyte lo = 0, hi = 5;
auto x = uniform(lo, hi, reproRng);
if (x == lo) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo <= x && x < hi);
}
assert(sawLB && sawUB);
}
{
foreach (i; 0 .. 30)
{
assert(i == uniform(i, i+1, reproRng));
}
}
uniform(0, 10, (local variable) fitbench.Gen gg.(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng) == 0)
(local variable) int ff = int std.random.uniform!("[)", int, int, std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u))(int a, int b, ref std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) rng) pure @safeCreate an array of random numbers using range functions and UFCS
Examples
import std.conv : to;
import std.meta : AliasSeq;
import std.range.primitives : isForwardRange;
import std.traits : isIntegral, isSomeChar;
auto gen = Mt19937(123_456_789);
static assert(isForwardRange!(typeof(gen)));
auto a = uniform(0, 1024, gen);
assert(0 <= a && a <= 1024);
auto b = uniform(0.0f, 1.0f, gen);
assert(0 <= b && b < 1, to!string(b));
auto c = uniform(0.0, 1.0);
assert(0 <= c && c < 1);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short, ushort,
int, uint, long, ulong, float, double, real))
{{
T lo = 0, hi = 100;
// Try tests with each of the possible bounds
{
T init = uniform(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[)"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"(]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"()"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
{
T init = uniform!"[]"(lo, hi);
size_t i = 50;
while (--i && uniform(lo, hi) == init) {}
assert(i > 0);
}
/* Test case with closed boundaries covering whole range
* of integral type
*/
static if (isIntegral!T || isSomeChar!T)
{
foreach (immutable _; 0 .. 100)
{
auto u = uniform!"[]"(T.min, T.max);
static assert(is(typeof(u) == T));
assert(T.min <= u, "Lower bound violation for uniform!\"[]\" with " ~ T.stringof);
assert(u <= T.max, "Upper bound violation for uniform!\"[]\" with " ~ T.stringof);
}
}
}}
auto reproRng = Xorshift(239842);
static foreach (T; AliasSeq!(char, wchar, dchar, byte, ubyte, short,
ushort, int, uint, long, ulong))
{{
T lo = T.min + 10, hi = T.max - 10;
T init = uniform(lo, hi, reproRng);
size_t i = 50;
while (--i && uniform(lo, hi, reproRng) == init) {}
assert(i > 0);
}}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform!"[]"('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'd') sawUB = true;
assert('a' <= x && x <= 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
auto x = uniform('a', 'd', reproRng);
if (x == 'a') sawLB = true;
if (x == 'c') sawUB = true;
assert('a' <= x && x < 'd');
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable int lo = -2, hi = 2;
auto x = uniform!"()"(lo, hi, reproRng);
if (x == (lo+1)) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo < x && x < hi);
}
assert(sawLB && sawUB);
}
{
bool sawLB = false, sawUB = false;
foreach (i; 0 .. 50)
{
immutable ubyte lo = 0, hi = 5;
auto x = uniform(lo, hi, reproRng);
if (x == lo) sawLB = true;
if (x == (hi-1)) sawUB = true;
assert(lo <= x && x < hi);
}
assert(sawLB && sawUB);
}
{
foreach (i; 0 .. 30)
{
assert(i == uniform(i, i+1, reproRng));
}
}
uniform(50, int std.algorithm.comparison.min!(int, int)(int a, int b) pure nothrow @nogc @safeIterates the passed arguments and returns the minimum value.
Examples
int a = 5;
short b = 6;
double c = 2;
auto d = min(a, b);
static assert(is(typeof(d) == int));
assert(d == 5);
auto e = min(a, b, c);
static assert(is(typeof(e) == double));
assert(e == 2);
ulong f = 0xffff_ffff_ffff;
const uint g = min(f, 0xffff_0000);
assert(g == 0xffff_0000);
dchar h = 100;
uint i = 101;
static assert(is(typeof(min(h, i)) == dchar));
static assert(is(typeof(min(i, h)) == uint));
assert(min(h, i) == 100);
With arguments of mixed signedness, the return type is the one that can
store the lowest values.
int a = -10;
uint f = 10;
static assert(is(typeof(min(a, f)) == int));
assert(min(a, f) == -10);
User-defined types that support comparison with < are supported.
import std.datetime;
assert(min(Date(2012, 12, 21), Date(1982, 1, 4)) == Date(1982, 1, 4));
assert(min(Date(1982, 1, 4), Date(2012, 12, 21)) == Date(1982, 1, 4));
assert(min(Date(1982, 1, 4), Date.min) == Date.min);
assert(min(Date.min, Date(1982, 1, 4)) == Date.min);
assert(min(Date(1982, 1, 4), Date.max) == Date(1982, 1, 4));
assert(min(Date.max, Date(1982, 1, 4)) == Date(1982, 1, 4));
assert(min(Date.min, Date.max) == Date.min);
assert(min(Date.max, Date.min) == Date.min);
min(1000, (local variable) int remrem) + 1, (local variable) fitbench.Gen gg.(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng);
int (local variable) int levelslevels = (constant) int fitbench.genPanels.maxD = 12maxD - 2 - (parameter) int depthdepth;
int (local variable) int minFminF = cast(int) double std.math.rounding.ceil(double x) pure nothrow @nogc @trustedceil(double std.math.exponential.pow!(double, double)(double x, double y) pure nothrow @nogc @trustedCalculates x`y`.
x y pow(x, y)
div 0 invalid? anything 0.0 1.0 no no x> 1 + + no no x< 1 + +0.0 no no x> 1 - +0.0 no no x< 1 - + no no + > 0.0 + no no + < 0.0 +0.0 no no - odd integer > 0.0 - no no - > 0.0, not odd integer + no no - odd integer < 0.0 -0.0 no no - < 0.0, not odd integer +0.0 no no 1.0 - no yes < 0.0 finite, nonintegral no yes 0.0 odd integer < 0.0 yes no 0.0 < 0.0, not odd integer + yes no 0.0 odd integer > 0.0 0.0 no no 0.0 > 0.0, not odd integer +0.0 no no
Examples
import std.math.operations : isClose;
assert(isClose(pow(2.0, 3.0), 8.0));
assert(isClose(pow(1.5, 10.0), 57.6650390625));
// square root of 9
assert(isClose(pow(9.0, 0.5), 3.0));
// 10th root of 1024
assert(isClose(pow(1024.0, 0.1), 2.0));
assert(isClose(pow(-4.0, 3.0), -64.0));
// reciprocal of 4 ^^ 2
assert(isClose(pow(4.0, -2.0), 0.0625));
// reciprocal of (-2) ^^ 3
assert(isClose(pow(-2.0, -3.0), -0.125));
assert(isClose(pow(-2.5, 3.0), -15.625));
// reciprocal of 2.5 ^^ 3
assert(isClose(pow(2.5, -3.0), 0.064));
// reciprocal of (-2.5) ^^ 3
assert(isClose(pow(-2.5, -3.0), -0.064));
// reciprocal of square root of 4
assert(isClose(pow(4.0, -0.5), 0.5));
// per definition
assert(isClose(pow(0.0, 0.0), 1.0));
import std.math.operations : isClose;
// the result is a complex number
// which cannot be represented as floating point number
import std.math.traits : isNaN;
assert(isNaN(pow(-2.5, -1.5)));
// use the ^^-operator of std.complex instead
import std.complex : complex;
auto c1 = complex(-2.5, 0.0);
auto c2 = complex(-1.5, 0.0);
auto result = c1 ^^ c2;
// exact result apparently depends on `real` precision => increased tolerance
assert(isClose(result.re, -4.64705438e-17, 2e-4));
assert(isClose(result.im, 2.52982e-1, 2e-4));
pow(cast(double) (local variable) int remrem, 1.0 / (local variable) int levelslevels));
(local variable) int ff = int std.algorithm.comparison.min!(int, int)(int a, int b) pure nothrow @nogc @safeIterates the passed arguments and returns the minimum value.
Examples
int a = 5;
short b = 6;
double c = 2;
auto d = min(a, b);
static assert(is(typeof(d) == int));
assert(d == 5);
auto e = min(a, b, c);
static assert(is(typeof(e) == double));
assert(e == 2);
ulong f = 0xffff_ffff_ffff;
const uint g = min(f, 0xffff_0000);
assert(g == 0xffff_0000);
dchar h = 100;
uint i = 101;
static assert(is(typeof(min(h, i)) == dchar));
static assert(is(typeof(min(i, h)) == uint));
assert(min(h, i) == 100);
With arguments of mixed signedness, the return type is the one that can
store the lowest values.
int a = -10;
uint f = 10;
static assert(is(typeof(min(a, f)) == int));
assert(min(a, f) == -10);
User-defined types that support comparison with < are supported.
import std.datetime;
assert(min(Date(2012, 12, 21), Date(1982, 1, 4)) == Date(1982, 1, 4));
assert(min(Date(1982, 1, 4), Date(2012, 12, 21)) == Date(1982, 1, 4));
assert(min(Date(1982, 1, 4), Date.min) == Date.min);
assert(min(Date.min, Date(1982, 1, 4)) == Date.min);
assert(min(Date(1982, 1, 4), Date.max) == Date(1982, 1, 4));
assert(min(Date.max, Date(1982, 1, 4)) == Date(1982, 1, 4));
assert(min(Date.min, Date.max) == Date.min);
assert(min(Date.max, Date.min) == Date.min);
min(int std.algorithm.comparison.max!(int, int)(int a, int b) pure nothrow @nogc @safeIterates the passed arguments and returns the maximum value.
Examples
int a = 5;
short b = 6;
double c = 2;
auto d = max(a, b);
assert(is(typeof(d) == int));
assert(d == 6);
auto e = min(a, b, c);
assert(is(typeof(e) == double));
assert(e == 2);
max((local variable) int ff, (local variable) int minFminF), (local variable) int remrem);
}
(local variable) fitbench.Gen gg.(field) int fitbench.Gen.maxFanmaxFan = int std.algorithm.comparison.max!(int, int)(int a, int b) pure nothrow @nogc @safeIterates the passed arguments and returns the maximum value.
Examples
int a = 5;
short b = 6;
double c = 2;
auto d = max(a, b);
assert(is(typeof(d) == int));
assert(d == 6);
auto e = min(a, b, c);
assert(is(typeof(e) == double));
assert(e == 2);
max((local variable) fitbench.Gen gg.(field) int fitbench.Gen.maxFanmaxFan, (local variable) int ff);
// split rem into f positive parts with skewed random weights
auto (local variable) double[] ww = new double[(local variable) int ff];
double (local variable) double WW = 0;
foreach (ref (parameter) double xx; (local variable) double[] ww)
{
double (local variable) double uu = double std.random.uniform01!(double, std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u))(ref std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) rng) pure nothrow @nogc @safeGenerates a uniformly-distributed floating point number of type
T in the range [0, 1). If no random number generator is
specified, the default RNG rndGen will be used as the source
of randomness.
uniform01 offers a faster generation of random variates than
the equivalent uniform!"[)"(0.0, 1.0) and so may be preferred
for some applications.
Examples
import std.math.operations : feqrel;
auto rnd = MinstdRand0(42);
// Generate random numbers in the range in the range [0, 1)
auto u1 = uniform01(rnd);
assert(u1 >= 0 && u1 < 1);
auto u2 = rnd.uniform01!float;
assert(u2 >= 0 && u2 < 1);
// Confirm that the random values with the initial seed 42 are 0.000328707 and 0.524587
assert(u1.feqrel(0.000328707) > 20);
assert(u2.feqrel(0.524587) > 20);
uniform01((local variable) fitbench.Gen gg.(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rngrng);
(local variable) double xx = (local variable) double uu * (local variable) double uu * (local variable) double uu;
(local variable) double WW += (local variable) double xx;
}
int (local variable) int leftleft = (local variable) int remrem - (local variable) int ff;
foreach ((local variable) int kk; 0 .. (local variable) int ff)
{
int (local variable) int extraextra = (local variable) int kk + 1 == (local variable) int ff ? (local variable) int leftleft : cast(int)(((local variable) int remrem - (local variable) int ff) * (local variable) double[] ww[(local variable) int kk] / (local variable) double WW);
(local variable) int extraextra = int std.algorithm.comparison.min!(int, int)(int a, int b) pure nothrow @nogc @safeIterates the passed arguments and returns the minimum value.
Examples
int a = 5;
short b = 6;
double c = 2;
auto d = min(a, b);
static assert(is(typeof(d) == int));
assert(d == 5);
auto e = min(a, b, c);
static assert(is(typeof(e) == double));
assert(e == 2);
ulong f = 0xffff_ffff_ffff;
const uint g = min(f, 0xffff_0000);
assert(g == 0xffff_0000);
dchar h = 100;
uint i = 101;
static assert(is(typeof(min(h, i)) == dchar));
static assert(is(typeof(min(i, h)) == uint));
assert(min(h, i) == 100);
With arguments of mixed signedness, the return type is the one that can
store the lowest values.
int a = -10;
uint f = 10;
static assert(is(typeof(min(a, f)) == int));
assert(min(a, f) == -10);
User-defined types that support comparison with < are supported.
import std.datetime;
assert(min(Date(2012, 12, 21), Date(1982, 1, 4)) == Date(1982, 1, 4));
assert(min(Date(1982, 1, 4), Date(2012, 12, 21)) == Date(1982, 1, 4));
assert(min(Date(1982, 1, 4), Date.min) == Date.min);
assert(min(Date.min, Date(1982, 1, 4)) == Date.min);
assert(min(Date(1982, 1, 4), Date.max) == Date(1982, 1, 4));
assert(min(Date.max, Date(1982, 1, 4)) == Date(1982, 1, 4));
assert(min(Date.min, Date.max) == Date.min);
assert(min(Date.max, Date.min) == Date.min);
min((local variable) int extraextra, (local variable) int leftleft);
(local variable) int leftleft -= (local variable) int extraextra;
void fitbench.genPanels.node(int budget, int depth) @systemnode(1 + (local variable) int extraextra, (parameter) int depthdepth + 1);
}
(local variable) fitbench.Gen gg.void fitbench.Gen.close()close();
}
void fitbench.genPanels.node(int budget, int depth) @systemnode((parameter) int nn, 0);
return (local variable) fitbench.Gen gg;
}
// ---------------------------------------------------------------------------
// Storage
// ---------------------------------------------------------------------------
/// The fat AoS widget record; the first 64 bytes are the layout-relevant head.
struct (struct) fitbench.Node!328LUThe fat AoS widget record; the first 64 bytes are the layout-relevant head.
Node(size_t SIZE)
{
int (field) int fitbench.Node!328LU.parentparent;
ubyte (field) ubyte fitbench.Node!328LU.kindkind, (field) ubyte fitbench.Node!328LU.axisaxis, (field) ubyte fitbench.Node!328LU.growgrow, (field) ubyte fitbench.Node!328LU._r_r;
int (field) int fitbench.Node!328LU.childCountchildCount;
int (field) int fitbench.Node!328LU.growCountgrowCount;
float (field) float fitbench.Node!328LU.gapgap = 0;
float[2] (field) float[2] fitbench.Node!328LU.padpad = 0; // total padding per axis (left+right, top+bottom)
uint (field) uint fitbench.Node!328LU.textLentextLen;
float[2] (field) float[2] fitbench.Node!328LU.szsz = 0;
float[2] (field) float[2] fitbench.Node!328LU.fitfit = 0;
float[2] (field) float[2] fitbench.Node!328LU.pospos = 0;
const(char)* (field) const(char)* fitbench.Node!328LU.texttext;
static if ((constant) ulong fitbench.SIZE = 328LUSIZE > 64)
ubyte[(constant) ulong fitbench.SIZE = 328LUSIZE - 64] (field) ubyte[264] fitbench.Node!328LU.payloadpayload;
}
static assert((template instance) fitbench.Node!64LUNode!64.(constant) ulong fitbench.Node!64LU.sizeof = 64LUsizeof == 64 && (template instance) fitbench.Node!128LUNode!128.(constant) ulong fitbench.Node!128LU.sizeof = 128LUsizeof == 128 && (template instance) fitbench.Node!328LUNode!328.(constant) ulong fitbench.Node!328LU.sizeof = 328LUsizeof == 328);
/// SoA variant's cold payload: text slice + id + the same fat payload.
struct (struct) fitbench.Cold!328LUSoA variant's cold payload: text slice + id + the same fat payload.
Cold(size_t SIZE)
{
const(char)* (field) const(char)* fitbench.Cold!328LU.texttext;
uint (field) uint fitbench.Cold!328LU.textLentextLen;
uint (field) uint fitbench.Cold!328LU.idid;
static if ((constant) ulong fitbench.SIZE = 328LUSIZE > 64)
ubyte[SIZE - 64] (field) ubyte[264] fitbench.Cold!328LU.payloadpayload;
}
struct (struct) fitbench.Soa!328LUSoa(size_t SIZE)
{
int* (field) int* fitbench.Soa!328LU.parentparent;
ubyte* (field) ubyte* fitbench.Soa!328LU.flagsflags; // axis | grow << 1
int* (field) int* fitbench.Soa!328LU.childCountchildCount;
int* (field) int* fitbench.Soa!328LU.growCountgrowCount;
float* (field) float* fitbench.Soa!328LU.gapgap;
float[2]* (field) float[2]* fitbench.Soa!328LU.padpad;
float[2]* (field) float[2]* fitbench.Soa!328LU.szsz;
float[2]* (field) float[2]* fitbench.Soa!328LU.fitfit;
float[2]* (field) float[2]* fitbench.Soa!328LU.pospos;
ubyte* (field) ubyte* fitbench.Soa!328LU.depthdepth;
(constant) ulong fitbench.SIZE = 328LUCold!(constant) ulong fitbench.SIZE = 328LUSIZE* (field) fitbench.Cold!328LU* fitbench.Soa!328LU.coldcold;
void void fitbench.Soa!328LU.alloc(ulong n) nothrow @nogc @systemalloc((alias) object.size_t = ulongsize_t (parameter) ulong nn)
{
(field) int* fitbench.Soa!328LU.parentparent = cast(int*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 4);
(field) ubyte* fitbench.Soa!328LU.flagsflags = cast(ubyte*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn);
(field) int* fitbench.Soa!328LU.childCountchildCount = cast(int*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 4);
(field) int* fitbench.Soa!328LU.growCountgrowCount = cast(int*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 4);
(field) float* fitbench.Soa!328LU.gapgap = cast(float*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 4);
(field) float[2]* fitbench.Soa!328LU.padpad = cast(float[2]*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 8);
(field) float[2]* fitbench.Soa!328LU.szsz = cast(float[2]*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 8);
(field) float[2]* fitbench.Soa!328LU.fitfit = cast(float[2]*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 8);
(field) float[2]* fitbench.Soa!328LU.pospos = cast(float[2]*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 8);
(field) ubyte* fitbench.Soa!328LU.depthdepth = cast(ubyte*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn);
(field) fitbench.Cold!328LU* fitbench.Soa!328LU.coldcold = cast((constant) ulong fitbench.SIZE = 128LUCold!(constant) ulong fitbench.SIZE = 328LUSIZE*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * (constant) ulong fitbench.SIZE = 128LUCold!(constant) ulong fitbench.SIZE = 328LUSIZE.(constant) ulong fitbench.Cold!328LU.sizeof = 280LUsizeof);
}
void void fitbench.Soa!328LU.release() nothrow @nogc @systemrelease()
{
foreach ((parameter) void* pp; [cast(void*) (field) int* fitbench.Soa!328LU.parentparent, (field) ubyte* fitbench.Soa!328LU.flagsflags, (field) int* fitbench.Soa!328LU.childCountchildCount, (field) int* fitbench.Soa!328LU.growCountgrowCount, (field) float* fitbench.Soa!328LU.gapgap, (field) float[2]* fitbench.Soa!328LU.padpad, (field) float[2]* fitbench.Soa!328LU.szsz, (field) float[2]* fitbench.Soa!328LU.fitfit, (field) float[2]* fitbench.Soa!328LU.pospos, (field) ubyte* fitbench.Soa!328LU.depthdepth, (field) fitbench.Cold!328LU* fitbench.Soa!328LU.coldcold])
void core.stdc.stdlib.free(void* ptr) nothrow @nogcfree((local variable) void* pp);
}
}
/// Scratch for the level-order variant.
struct (struct) fitbench.LevelScratchScratch for the level-order variant.
LevelScratch
{
int* (field) int* fitbench.LevelScratch.ordord;
float* (field) float* fitbench.LevelScratch.ww, (field) float* fitbench.LevelScratch.hh;
float* (field) float* fitbench.LevelScratch.padMpadM, (field) float* fitbench.LevelScratch.padCpadC; // main/cross padding of the node itself
float* (field) float* fitbench.LevelScratch.gapgap;
int* (field) int* fitbench.LevelScratch.cntcnt;
ubyte* (field) ubyte* fitbench.LevelScratch.axisaxis;
void void fitbench.LevelScratch.alloc(ulong n)alloc((alias) object.size_t = ulongsize_t (parameter) ulong nn)
{
(field) int* fitbench.LevelScratch.ordord = cast(int*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 4);
(field) float* fitbench.LevelScratch.ww = cast(float*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 4);
(field) float* fitbench.LevelScratch.hh = cast(float*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 4);
(field) float* fitbench.LevelScratch.padMpadM = cast(float*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 4);
(field) float* fitbench.LevelScratch.padCpadC = cast(float*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 4);
(field) float* fitbench.LevelScratch.gapgap = cast(float*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 4);
(field) int* fitbench.LevelScratch.cntcnt = cast(int*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn * 4);
(field) ubyte* fitbench.LevelScratch.axisaxis = cast(ubyte*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) ulong nn);
}
void void fitbench.LevelScratch.release()release()
{
foreach ((parameter) void* pp; [cast(void*) (field) int* fitbench.LevelScratch.ordord, (field) float* fitbench.LevelScratch.ww, (field) float* fitbench.LevelScratch.hh, (field) float* fitbench.LevelScratch.padMpadM, (field) float* fitbench.LevelScratch.padCpadC, (field) float* fitbench.LevelScratch.gapgap, (field) int* fitbench.LevelScratch.cntcnt, (field) ubyte* fitbench.LevelScratch.axisaxis])
void core.stdc.stdlib.free(void* ptr) nothrow @nogcfree((local variable) void* pp);
}
}
// ---------------------------------------------------------------------------
// Build (+ fused fit)
// ---------------------------------------------------------------------------
struct (struct) fitbench.FrameFrame
{
int (field) int fitbench.Frame.idxidx;
int (field) int fitbench.Frame.countcount;
int (field) int fitbench.Frame.growCountgrowCount;
int (field) int fitbench.Frame.axisaxis;
float (field) float fitbench.Frame.sumsum = 0; // main-axis sum of children
float (field) float fitbench.Frame.mxmx = 0; // cross-axis max of children
}
pragma(inline, true) void void fitbench.contribute(ref fitbench.Frame f, float w, float h)contribute(ref (struct) fitbench.FrameFrame (parameter) fitbench.Frame ff, float (parameter) float ww, float (parameter) float hh)
{
float (local variable) float mm = (parameter) fitbench.Frame ff.(field) int fitbench.Frame.axisaxis ? (parameter) float hh : (parameter) float ww;
float (local variable) float cc = (parameter) fitbench.Frame ff.(field) int fitbench.Frame.axisaxis ? (parameter) float ww : (parameter) float hh;
(parameter) fitbench.Frame ff.(field) float fitbench.Frame.sumsum += (local variable) float mm;
(parameter) fitbench.Frame ff.(field) float fitbench.Frame.mxmx = (local variable) float cc > (parameter) fitbench.Frame ff.(field) float fitbench.Frame.mxmx ? (local variable) float cc : (parameter) fitbench.Frame ff.(field) float fitbench.Frame.mxmx;
}
pragma(inline, true) void void fitbench.writePayload!(ubyte[64])(ref ubyte[64] payload, int i) pure nothrow @nogc @systemwritePayload(P)(ref (alias) P = ubyte[64]P (parameter) ubyte[64] payloadpayload, int (parameter) int ii)
{
// a few non-zero fields a widget would set: id hash, style ref, colour
static if ((sarray) ubyte[64]P.(constant) ulong ubyte[64].sizeof = 64LUsizeof >= 16)
{
ulong (local variable) ulong idid = (cast(ulong) (parameter) int ii * 0x9E3779B97F4A7C15UL) ^ 0xABCDEF;
*cast(ulong*)&(parameter) ubyte[64] payloadpayload[0] = (local variable) ulong idid;
*cast(uint*)&(parameter) ubyte[64] payloadpayload[8] = 0xFF336699;
*cast(uint*)&(parameter) ubyte[64] payloadpayload[12] = cast(uint) (parameter) int ii;
}
}
int int fitbench.buildAos!(false, 128LU)(const(fitbench.Ev)[] evs, const(char)* pool, fitbench.Node!128LU* nodes) pure nothrow @nogc @systembuildAos(bool fused, size_t S)(const((struct) fitbench.EvEv)[] (parameter) const(fitbench.Ev)[] evsevs, const(char)* (parameter) const(char)* poolpool, (constant) ulong fitbench.S = 128LUNode!(constant) ulong fitbench.S = 128LUS* (parameter) fitbench.Node!128LU* nodesnodes)
{
(struct) fitbench.FrameFrame[64] (local variable) fitbench.Frame[64] stst = void;
int (local variable) int spsp = 0, (local variable) int nn = 0;
foreach (ref const (parameter) const(fitbench.Ev) ee; (parameter) const(fitbench.Ev)[] evsevs)
{
if ((local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.opop == (enum value) fitbench.OpClose = cast(ubyte)2uOpClose)
{
(struct) fitbench.FrameFrame (local variable) fitbench.Frame ff = (local variable) fitbench.Frame[64] stst[--(local variable) int spsp];
auto (local variable) fitbench.Node!128LU* ndnd = &(parameter) fitbench.Node!128LU* nodesnodes[(local variable) fitbench.Frame ff.(field) int fitbench.Frame.idxidx];
(local variable) fitbench.Node!128LU* ndnd.(field) int fitbench.Node!128LU.childCountchildCount = (local variable) fitbench.Frame ff.(field) int fitbench.Frame.countcount;
(local variable) fitbench.Node!128LU* ndnd.(field) int fitbench.Node!128LU.growCountgrowCount = (local variable) fitbench.Frame ff.(field) int fitbench.Frame.growCountgrowCount;
static if (fused)
{
int (local variable) int aa = (local variable) fitbench.Frame ff.(field) int fitbench.Frame.axisaxis;
float (local variable) float mm = (local variable) fitbench.Frame ff.(field) float fitbench.Frame.sumsum + (local variable) fitbench.Node!128LU* ndnd.(field) float[2] fitbench.Node!128LU.padpad[(local variable) int aa] + (local variable) fitbench.Node!128LU* ndnd.(field) float fitbench.Node!128LU.gapgap * ((local variable) fitbench.Frame ff.(field) int fitbench.Frame.countcount > 0 ? (local variable) fitbench.Frame ff.(field) int fitbench.Frame.countcount - 1 : 0);
float (local variable) float cc = (local variable) fitbench.Frame ff.(field) float fitbench.Frame.mxmx + (local variable) fitbench.Node!128LU* ndnd.(field) float[2] fitbench.Node!128LU.padpad[1 - (local variable) int aa];
float (local variable) float ww = (local variable) int aa ? (local variable) float cc : (local variable) float mm, (local variable) float hh = (local variable) int aa ? (local variable) float mm : (local variable) float cc;
(local variable) fitbench.Node!128LU* ndnd.(field) float[2] fitbench.Node!128LU.szsz[0] = (local variable) float ww;
(local variable) fitbench.Node!128LU* ndnd.(field) float[2] fitbench.Node!128LU.szsz[1] = (local variable) float hh;
if ((local variable) int spsp)
void fitbench.contribute(ref fitbench.Frame f, float w, float h)contribute((local variable) fitbench.Frame[64] stst[(local variable) int spsp - 1], (local variable) float ww, (local variable) float hh);
}
}
else
{
int (local variable) int ii = (local variable) int nn++;
auto (local variable) fitbench.Node!128LU* ndnd = &(parameter) fitbench.Node!128LU* nodesnodes[(local variable) int ii];
*(local variable) fitbench.Node!128LU* ndnd = (constant) ulong fitbench.S = 128LUNode!(constant) ulong fitbench.S = 128LUS.(constant) fitbench.Node!128LU fitbench.Node!128LU.init = Node(0, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, 0, 0, 0.0F, [0.0F, 0.0F], 0u, [0.0F, 0.0F], [0.0F, 0.0F], [0.0F, 0.0F], null, [cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u])init;
(local variable) fitbench.Node!128LU* ndnd.(field) int fitbench.Node!128LU.parentparent = (local variable) int spsp ? (local variable) fitbench.Frame[64] stst[(local variable) int spsp - 1].(field) int fitbench.Frame.idxidx : -1;
(local variable) fitbench.Node!128LU* ndnd.(field) ubyte fitbench.Node!128LU.kindkind = (local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.opop;
(local variable) fitbench.Node!128LU* ndnd.(field) ubyte fitbench.Node!128LU.axisaxis = (local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.axisaxis;
(local variable) fitbench.Node!128LU* ndnd.(field) ubyte fitbench.Node!128LU.growgrow = (local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.growgrow;
(local variable) fitbench.Node!128LU* ndnd.(field) float fitbench.Node!128LU.gapgap = (local variable) const(fitbench.Ev) ee.(field) ushort fitbench.Ev.gapgap;
(local variable) fitbench.Node!128LU* ndnd.(field) float[2] fitbench.Node!128LU.padpad[0] = (local variable) fitbench.Node!128LU* ndnd.(field) float[2] fitbench.Node!128LU.padpad[1] = 2.0f * (local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.padpad;
(local variable) fitbench.Node!128LU* ndnd.(field) const(char)* fitbench.Node!128LU.texttext = (parameter) const(char)* poolpool + (local variable) const(fitbench.Ev) ee.(field) uint fitbench.Ev.textOfftextOff;
(local variable) fitbench.Node!128LU* ndnd.(field) uint fitbench.Node!128LU.textLentextLen = (local variable) const(fitbench.Ev) ee.(field) ushort fitbench.Ev.textLentextLen;
static if ((constant) ulong fitbench.S = 128LUS > 64)
void fitbench.writePayload!(ubyte[64])(ref ubyte[64] payload, int i) pure nothrow @nogc @systemwritePayload((local variable) fitbench.Node!128LU* ndnd.(field) ubyte[64] fitbench.Node!128LU.payloadpayload, (local variable) int ii);
if ((local variable) int spsp)
{
(local variable) fitbench.Frame[64] stst[(local variable) int spsp - 1].(field) int fitbench.Frame.countcount++;
(local variable) fitbench.Frame[64] stst[(local variable) int spsp - 1].(field) int fitbench.Frame.growCountgrowCount += ((local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.growgrow >> (local variable) fitbench.Frame[64] stst[(local variable) int spsp - 1].(field) int fitbench.Frame.axisaxis) & 1;
}
if ((local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.opop == (enum value) fitbench.OpLabel = cast(ubyte)1uOpLabel)
{
float (local variable) float ww = (local variable) const(fitbench.Ev) ee.(field) ushort fitbench.Ev.textLentextLen * (constant) float fitbench.glyphW = 8.0FglyphW; // cached measure
(local variable) fitbench.Node!128LU* ndnd.(field) float[2] fitbench.Node!128LU.szsz[0] = (local variable) float ww;
(local variable) fitbench.Node!128LU* ndnd.(field) float[2] fitbench.Node!128LU.szsz[1] = (constant) float fitbench.lineH = 16.0FlineH;
static if (fused)
void fitbench.contribute(ref fitbench.Frame f, float w, float h)contribute((local variable) fitbench.Frame[64] stst[(local variable) int spsp - 1], (local variable) float ww, (constant) float fitbench.lineH = 16.0FlineH);
}
else
(local variable) fitbench.Frame[64] stst[(local variable) int spsp++] = (struct) fitbench.FrameFrame((local variable) int ii, 0, 0, (local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.axisaxis);
}
}
return (local variable) int nn;
}
int int fitbench.buildSoa!(false, false, 64LU)(const(fitbench.Ev)[] evs, const(char)* pool, ref fitbench.Soa!64LU s) pure nothrow @nogc @systembuildSoa(bool fused, bool withDepth, size_t S)(const((struct) fitbench.EvEv)[] (parameter) const(fitbench.Ev)[] evsevs, const(char)* (parameter) const(char)* poolpool, ref (constant) ulong fitbench.S = 64LUSoa!(constant) ulong fitbench.S = 64LUS (parameter) fitbench.Soa!64LU ss)
{
(struct) fitbench.FrameFrame[64] (local variable) fitbench.Frame[64] stst = void;
int (local variable) int spsp = 0, (local variable) int nn = 0;
foreach (ref const (parameter) const(fitbench.Ev) ee; (parameter) const(fitbench.Ev)[] evsevs)
{
if ((local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.opop == (enum value) fitbench.OpClose = cast(ubyte)2uOpClose)
{
(struct) fitbench.FrameFrame (local variable) fitbench.Frame ff = (local variable) fitbench.Frame[64] stst[--(local variable) int spsp];
(parameter) fitbench.Soa!64LU ss.(field) int* fitbench.Soa!64LU.childCountchildCount[(local variable) fitbench.Frame ff.(field) int fitbench.Frame.idxidx] = (local variable) fitbench.Frame ff.(field) int fitbench.Frame.countcount;
(parameter) fitbench.Soa!64LU ss.(field) int* fitbench.Soa!64LU.growCountgrowCount[(local variable) fitbench.Frame ff.(field) int fitbench.Frame.idxidx] = (local variable) fitbench.Frame ff.(field) int fitbench.Frame.growCountgrowCount;
static if (fused)
{
int (local variable) int aa = (local variable) fitbench.Frame ff.(field) int fitbench.Frame.axisaxis;
auto (local variable) float[2] pdpd = (parameter) fitbench.Soa!64LU ss.(field) float[2]* fitbench.Soa!64LU.padpad[(local variable) fitbench.Frame ff.(field) int fitbench.Frame.idxidx];
float (local variable) float mm = (local variable) fitbench.Frame ff.(field) float fitbench.Frame.sumsum + (local variable) float[2] pdpd[(local variable) int aa] + (parameter) fitbench.Soa!64LU ss.(field) float* fitbench.Soa!64LU.gapgap[(local variable) fitbench.Frame ff.(field) int fitbench.Frame.idxidx] * ((local variable) fitbench.Frame ff.(field) int fitbench.Frame.countcount > 0 ? (local variable) fitbench.Frame ff.(field) int fitbench.Frame.countcount - 1 : 0);
float (local variable) float cc = (local variable) fitbench.Frame ff.(field) float fitbench.Frame.mxmx + (local variable) float[2] pdpd[1 - (local variable) int aa];
float (local variable) float ww = (local variable) int aa ? (local variable) float cc : (local variable) float mm, (local variable) float hh = (local variable) int aa ? (local variable) float mm : (local variable) float cc;
(parameter) fitbench.Soa!64LU ss.(field) float[2]* fitbench.Soa!64LU.szsz[(local variable) fitbench.Frame ff.(field) int fitbench.Frame.idxidx][0] = (local variable) float ww;
(parameter) fitbench.Soa!64LU ss.(field) float[2]* fitbench.Soa!64LU.szsz[(local variable) fitbench.Frame ff.(field) int fitbench.Frame.idxidx][1] = (local variable) float hh;
if ((local variable) int spsp)
void fitbench.contribute(ref fitbench.Frame f, float w, float h)contribute((local variable) fitbench.Frame[64] stst[(local variable) int spsp - 1], (local variable) float ww, (local variable) float hh);
}
}
else
{
int (local variable) int ii = (local variable) int nn++;
(parameter) fitbench.Soa!64LU ss.(field) int* fitbench.Soa!64LU.parentparent[(local variable) int ii] = (local variable) int spsp ? (local variable) fitbench.Frame[64] stst[(local variable) int spsp - 1].(field) int fitbench.Frame.idxidx : -1;
(parameter) fitbench.Soa!64LU ss.(field) ubyte* fitbench.Soa!64LU.flagsflags[(local variable) int ii] = cast(ubyte)((local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.axisaxis | ((local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.growgrow << 1));
(parameter) fitbench.Soa!64LU ss.(field) float* fitbench.Soa!64LU.gapgap[(local variable) int ii] = (local variable) const(fitbench.Ev) ee.(field) ushort fitbench.Ev.gapgap;
(parameter) fitbench.Soa!64LU ss.(field) float[2]* fitbench.Soa!64LU.padpad[(local variable) int ii][0] = (parameter) fitbench.Soa!64LU ss.(field) float[2]* fitbench.Soa!64LU.padpad[(local variable) int ii][1] = 2.0f * (local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.padpad;
(parameter) fitbench.Soa!64LU ss.(field) int* fitbench.Soa!64LU.childCountchildCount[(local variable) int ii] = 0;
(parameter) fitbench.Soa!64LU ss.(field) int* fitbench.Soa!64LU.growCountgrowCount[(local variable) int ii] = 0;
static if (withDepth)
(parameter) fitbench.Soa!64LU ss.(field) ubyte* fitbench.Soa!64LU.depthdepth[(local variable) int ii] = cast(ubyte) (local variable) int spsp;
auto (local variable) fitbench.Cold!64LU* cc = &(parameter) fitbench.Soa!64LU ss.(field) fitbench.Cold!64LU* fitbench.Soa!64LU.coldcold[(local variable) int ii];
*(local variable) fitbench.Cold!64LU* cc = (constant) ulong fitbench.S = 64LUCold!(constant) ulong fitbench.S = 64LUS.(constant) fitbench.Cold!64LU fitbench.Cold!64LU.init = Cold(null, 0u, 0u)init;
(local variable) fitbench.Cold!64LU* cc.(field) const(char)* fitbench.Cold!64LU.texttext = (parameter) const(char)* poolpool + (local variable) const(fitbench.Ev) ee.(field) uint fitbench.Ev.textOfftextOff;
(local variable) fitbench.Cold!64LU* cc.(field) uint fitbench.Cold!64LU.textLentextLen = (local variable) const(fitbench.Ev) ee.(field) ushort fitbench.Ev.textLentextLen;
(local variable) fitbench.Cold!64LU* cc.(field) uint fitbench.Cold!64LU.idid = (local variable) int ii;
static if ((constant) ulong fitbench.S = 64LUS > 64)
void fitbench.writePayload!(ubyte[264])(ref ubyte[264] payload, int i) pure nothrow @nogc @systemwritePayload((local variable) fitbench.Cold!328LU* cc.(field) ubyte[264] fitbench.Cold!328LU.payloadpayload, (local variable) int ii);
if ((local variable) int spsp)
{
(local variable) fitbench.Frame[64] stst[(local variable) int spsp - 1].(field) int fitbench.Frame.countcount++;
(local variable) fitbench.Frame[64] stst[(local variable) int spsp - 1].(field) int fitbench.Frame.growCountgrowCount += ((local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.growgrow >> (local variable) fitbench.Frame[64] stst[(local variable) int spsp - 1].(field) int fitbench.Frame.axisaxis) & 1;
}
if ((local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.opop == (enum value) fitbench.OpLabel = cast(ubyte)1uOpLabel)
{
float (local variable) float ww = (local variable) const(fitbench.Ev) ee.(field) ushort fitbench.Ev.textLentextLen * (constant) float fitbench.glyphW = 8.0FglyphW;
(parameter) fitbench.Soa!64LU ss.(field) float[2]* fitbench.Soa!64LU.szsz[(local variable) int ii][0] = (local variable) float ww;
(parameter) fitbench.Soa!64LU ss.(field) float[2]* fitbench.Soa!64LU.szsz[(local variable) int ii][1] = (constant) float fitbench.lineH = 16.0FlineH;
static if (fused)
void fitbench.contribute(ref fitbench.Frame f, float w, float h)contribute((local variable) fitbench.Frame[64] stst[(local variable) int spsp - 1], (local variable) float ww, (constant) float fitbench.lineH = 16.0FlineH);
}
else
{
(parameter) fitbench.Soa!64LU ss.(field) float[2]* fitbench.Soa!64LU.szsz[(local variable) int ii][0] = (parameter) fitbench.Soa!64LU ss.(field) float[2]* fitbench.Soa!64LU.szsz[(local variable) int ii][1] = 0;
(local variable) fitbench.Frame[64] stst[(local variable) int spsp++] = (struct) fitbench.FrameFrame((local variable) int ii, 0, 0, (local variable) const(fitbench.Ev) ee.(field) ubyte fitbench.Ev.axisaxis);
}
}
}
return (local variable) int nn;
}
// ---------------------------------------------------------------------------
// Separate fit passes
// ---------------------------------------------------------------------------
void void fitbench.fitSweepAos!328LU(fitbench.Node!328LU* nodes, int n) pure nothrow @nogc @systemfitSweepAos(size_t S)((struct) fitbench.Node!328LUThe fat AoS widget record; the first 64 bytes are the layout-relevant head.
Node!(constant) ulong fitbench.S = 328LUS* (parameter) fitbench.Node!328LU* nodesnodes, int (parameter) int nn)
{
for (int (local variable) int ii = (parameter) int nn - 1; i >= 0; --i)
{
auto (local variable) fitbench.Node!328LU* ndnd = &(parameter) fitbench.Node!328LU* nodesnodes[(local variable) int ii];
int (local variable) int aa = (local variable) fitbench.Node!328LU* ndnd.(field) ubyte fitbench.Node!328LU.axisaxis;
int (local variable) int cc = (local variable) fitbench.Node!328LU* ndnd.(field) int fitbench.Node!328LU.childCountchildCount;
float (local variable) float ww = (local variable) fitbench.Node!328LU* ndnd.(field) float[2] fitbench.Node!328LU.szsz[0], (local variable) float hh = (local variable) fitbench.Node!328LU* ndnd.(field) float[2] fitbench.Node!328LU.szsz[1];
float (local variable) float mm = ((local variable) int aa ? (local variable) float hh : (local variable) float ww) + (local variable) fitbench.Node!328LU* ndnd.(field) float[2] fitbench.Node!328LU.padpad[(local variable) int aa] + (local variable) fitbench.Node!328LU* ndnd.(field) float fitbench.Node!328LU.gapgap * ((local variable) int cc > 0 ? (local variable) int cc - 1 : 0);
float (local variable) float xx = ((local variable) int aa ? (local variable) float ww : (local variable) float hh) + (local variable) fitbench.Node!328LU* ndnd.(field) float[2] fitbench.Node!328LU.padpad[1 - (local variable) int aa];
(local variable) float ww = (local variable) int aa ? (local variable) float xx : (local variable) float mm;
(local variable) float hh = (local variable) int aa ? (local variable) float mm : (local variable) float xx;
(local variable) fitbench.Node!328LU* ndnd.(field) float[2] fitbench.Node!328LU.szsz[0] = (local variable) float ww;
(local variable) fitbench.Node!328LU* ndnd.(field) float[2] fitbench.Node!328LU.szsz[1] = (local variable) float hh;
int (local variable) int pp = (local variable) fitbench.Node!328LU* ndnd.(field) int fitbench.Node!328LU.parentparent;
if ((local variable) int pp >= 0)
{
auto (local variable) fitbench.Node!328LU* pnpn = &(parameter) fitbench.Node!328LU* nodesnodes[(local variable) int pp];
if ((local variable) fitbench.Node!328LU* pnpn.(field) ubyte fitbench.Node!328LU.axisaxis == 0)
{
(local variable) fitbench.Node!328LU* pnpn.(field) float[2] fitbench.Node!328LU.szsz[0] += (local variable) float ww;
(local variable) fitbench.Node!328LU* pnpn.(field) float[2] fitbench.Node!328LU.szsz[1] = (local variable) float hh > (local variable) fitbench.Node!328LU* pnpn.(field) float[2] fitbench.Node!328LU.szsz[1] ? (local variable) float hh : (local variable) fitbench.Node!328LU* pnpn.(field) float[2] fitbench.Node!328LU.szsz[1];
}
else
{
(local variable) fitbench.Node!328LU* pnpn.(field) float[2] fitbench.Node!328LU.szsz[1] += (local variable) float hh;
(local variable) fitbench.Node!328LU* pnpn.(field) float[2] fitbench.Node!328LU.szsz[0] = (local variable) float ww > (local variable) fitbench.Node!328LU* pnpn.(field) float[2] fitbench.Node!328LU.szsz[0] ? (local variable) float ww : (local variable) fitbench.Node!328LU* pnpn.(field) float[2] fitbench.Node!328LU.szsz[0];
}
}
}
}
void void fitbench.fitSweepSoa!328LU(ref fitbench.Soa!328LU s, int n) pure nothrow @nogc @systemfitSweepSoa(size_t S)(ref (constant) ulong fitbench.S = 64LUSoa!(constant) ulong fitbench.S = 328LUS (parameter) fitbench.Soa!328LU ss, int (parameter) int nn)
{
auto (local variable) float[2]* szsz = (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.szsz, (local variable) float[2]* padpad = (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.padpad, (local variable) float* gapgap = (parameter) fitbench.Soa!328LU ss.(field) float* fitbench.Soa!328LU.gapgap, (local variable) int* cccc = (parameter) fitbench.Soa!328LU ss.(field) int* fitbench.Soa!328LU.childCountchildCount, (local variable) ubyte* flfl = (parameter) fitbench.Soa!328LU ss.(field) ubyte* fitbench.Soa!328LU.flagsflags, (local variable) int* parpar = (parameter) fitbench.Soa!328LU ss.(field) int* fitbench.Soa!328LU.parentparent;
for (int (local variable) int ii = (parameter) int nn - 1; i >= 0; --i)
{
int (local variable) int aa = (local variable) ubyte* flfl[(local variable) int ii] & 1;
int (local variable) int cc = (local variable) int* cccc[(local variable) int ii];
float (local variable) float ww = (local variable) float[2]* szsz[(local variable) int ii][0], (local variable) float hh = (local variable) float[2]* szsz[(local variable) int ii][1];
float (local variable) float mm = ((local variable) int aa ? (local variable) float hh : (local variable) float ww) + (local variable) float[2]* padpad[(local variable) int ii][(local variable) int aa] + (local variable) float* gapgap[(local variable) int ii] * ((local variable) int cc > 0 ? (local variable) int cc - 1 : 0);
float (local variable) float xx = ((local variable) int aa ? (local variable) float ww : (local variable) float hh) + (local variable) float[2]* padpad[(local variable) int ii][1 - (local variable) int aa];
(local variable) float ww = (local variable) int aa ? (local variable) float xx : (local variable) float mm;
(local variable) float hh = (local variable) int aa ? (local variable) float mm : (local variable) float xx;
(local variable) float[2]* szsz[(local variable) int ii][0] = (local variable) float ww;
(local variable) float[2]* szsz[(local variable) int ii][1] = (local variable) float hh;
int (local variable) int pp = (local variable) int* parpar[(local variable) int ii];
if ((local variable) int pp >= 0)
{
if (((local variable) ubyte* flfl[(local variable) int pp] & 1) == 0)
{
(local variable) float[2]* szsz[(local variable) int pp][0] += (local variable) float ww;
(local variable) float[2]* szsz[(local variable) int pp][1] = (local variable) float hh > (local variable) float[2]* szsz[(local variable) int pp][1] ? (local variable) float hh : (local variable) float[2]* szsz[(local variable) int pp][1];
}
else
{
(local variable) float[2]* szsz[(local variable) int pp][1] += (local variable) float hh;
(local variable) float[2]* szsz[(local variable) int pp][0] = (local variable) float ww > (local variable) float[2]* szsz[(local variable) int pp][0] ? (local variable) float ww : (local variable) float[2]* szsz[(local variable) int pp][0];
}
}
}
}
/// sep-soa with the current parent's accumulator carried in registers while
/// consecutive (reverse pre-order) nodes share a parent, so sibling runs do
/// not form a store->load chain through sz[p]. Same op order => same bits.
void void fitbench.fitSweepSoaRc!328LU(ref fitbench.Soa!328LU s, int n) pure nothrow @nogc @systemsep-soa with the current parent's accumulator carried in registers while
consecutive (reverse pre-order) nodes share a parent, so sibling runs do
not form a store->load chain through sz[p]. Same op order => same bits.
fitSweepSoaRc(size_t S)(ref (constant) ulong fitbench.S = 64LUSoa!(constant) ulong fitbench.S = 328LUS (parameter) fitbench.Soa!328LU ss, int (parameter) int nn)
{
auto (local variable) float[2]* szsz = (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.szsz, (local variable) float[2]* padpad = (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.padpad, (local variable) float* gapgap = (parameter) fitbench.Soa!328LU ss.(field) float* fitbench.Soa!328LU.gapgap, (local variable) int* cccc = (parameter) fitbench.Soa!328LU ss.(field) int* fitbench.Soa!328LU.childCountchildCount, (local variable) ubyte* flfl = (parameter) fitbench.Soa!328LU ss.(field) ubyte* fitbench.Soa!328LU.flagsflags, (local variable) int* parpar = (parameter) fitbench.Soa!328LU ss.(field) int* fitbench.Soa!328LU.parentparent;
int (local variable) int curcur = -1, (local variable) int caca = 0;
float (local variable) float amam = 0, (local variable) float acac = 0;
for (int (local variable) int ii = (parameter) int nn - 1; i >= 0; --i)
{
if ((local variable) int ii == (local variable) int curcur) // about to finalise the parent held in registers
{
(local variable) float[2]* szsz[(local variable) int curcur][(local variable) int caca] = (local variable) float amam;
(local variable) float[2]* szsz[(local variable) int curcur][1 - (local variable) int caca] = (local variable) float acac;
(local variable) int curcur = -1;
}
int (local variable) int aa = (local variable) ubyte* flfl[(local variable) int ii] & 1;
int (local variable) int cc = (local variable) int* cccc[(local variable) int ii];
float (local variable) float ww = (local variable) float[2]* szsz[(local variable) int ii][0], (local variable) float hh = (local variable) float[2]* szsz[(local variable) int ii][1];
float (local variable) float mm = ((local variable) int aa ? (local variable) float hh : (local variable) float ww) + (local variable) float[2]* padpad[(local variable) int ii][(local variable) int aa] + (local variable) float* gapgap[(local variable) int ii] * ((local variable) int cc > 0 ? (local variable) int cc - 1 : 0);
float (local variable) float xx = ((local variable) int aa ? (local variable) float ww : (local variable) float hh) + (local variable) float[2]* padpad[(local variable) int ii][1 - (local variable) int aa];
(local variable) float ww = (local variable) int aa ? (local variable) float xx : (local variable) float mm;
(local variable) float hh = (local variable) int aa ? (local variable) float mm : (local variable) float xx;
(local variable) float[2]* szsz[(local variable) int ii][0] = (local variable) float ww;
(local variable) float[2]* szsz[(local variable) int ii][1] = (local variable) float hh;
int (local variable) int pp = (local variable) int* parpar[(local variable) int ii];
if ((local variable) int pp < 0)
continue;
if ((local variable) int pp != (local variable) int curcur)
{
if ((local variable) int curcur >= 0)
{
(local variable) float[2]* szsz[(local variable) int curcur][(local variable) int caca] = (local variable) float amam;
(local variable) float[2]* szsz[(local variable) int curcur][1 - (local variable) int caca] = (local variable) float acac;
}
(local variable) int curcur = (local variable) int pp;
(local variable) int caca = (local variable) ubyte* flfl[(local variable) int pp] & 1;
(local variable) float amam = (local variable) float[2]* szsz[(local variable) int pp][(local variable) int caca];
(local variable) float acac = (local variable) float[2]* szsz[(local variable) int pp][1 - (local variable) int caca];
}
float (local variable) float pmpm = (local variable) int caca ? (local variable) float hh : (local variable) float ww, (local variable) float pcpc = (local variable) int caca ? (local variable) float ww : (local variable) float hh;
(local variable) float amam += (local variable) float pmpm;
(local variable) float acac = (local variable) float pcpc > (local variable) float acac ? (local variable) float pcpc : (local variable) float acac;
}
if ((local variable) int curcur >= 0)
{
(local variable) float[2]* szsz[(local variable) int curcur][(local variable) int caca] = (local variable) float amam;
(local variable) float[2]* szsz[(local variable) int curcur][1 - (local variable) int caca] = (local variable) float acac;
}
}
@(struct) fitbench.fastmathfastmath float float fitbench.sumRange(const(float)* p, int k)sumRange(const(float)* (parameter) const(float)* pp, int (parameter) int kk)
{
float (local variable) float ss = 0;
foreach ((local variable) int jj; 0 .. (parameter) int kk)
(local variable) float ss += (parameter) const(float)* pp[(local variable) int jj];
return (local variable) float ss;
}
@(struct) fitbench.fastmathfastmath float float fitbench.maxRange(const(float)* p, int k)maxRange(const(float)* (parameter) const(float)* pp, int (parameter) int kk)
{
float (local variable) float mm = 0;
foreach ((local variable) int jj; 0 .. (parameter) int kk)
(local variable) float mm = (parameter) const(float)* pp[(local variable) int jj] > (local variable) float mm ? (parameter) const(float)* pp[(local variable) int jj] : (local variable) float mm;
return (local variable) float mm;
}
/// Returns ns spent in the pure level reduction (for the breakdown).
long long fitbench.fitLevel!328LU(ref fitbench.Soa!328LU s, ref fitbench.LevelScratch L, int n) @systemReturns ns spent in the pure level reduction (for the breakdown).
fitLevel(size_t S)(ref (struct) fitbench.Soa!328LUSoa!(constant) ulong fitbench.S = 328LUS (parameter) fitbench.Soa!328LU ss, ref (struct) fitbench.LevelScratchScratch for the level-order variant.
LevelScratch (parameter) fitbench.LevelScratch LL, int (parameter) int nn)
{
// 1. counting sort by depth (stable => siblings contiguous within a level)
int[66] (local variable) int[66] startstart = 0;
foreach ((local variable) int ii; 0 .. (parameter) int nn)
(local variable) int[66] startstart[(parameter) fitbench.Soa!328LU ss.(field) ubyte* fitbench.Soa!328LU.depthdepth[(local variable) int ii] + 1]++;
int (local variable) int maxDmaxD = 0;
foreach ((local variable) int dd; 1 .. 65)
{
if ((local variable) int[66] startstart[(local variable) int dd])
(local variable) int maxDmaxD = (local variable) int dd;
(local variable) int[66] startstart[(local variable) int dd] += (local variable) int[66] startstart[(local variable) int dd - 1];
}
int[65] (local variable) int[65] curcur = (local variable) int[66] startstart[0 .. 65];
foreach ((local variable) int ii; 0 .. (parameter) int nn)
{
int (local variable) int jj = (local variable) int[65] curcur[(parameter) fitbench.Soa!328LU ss.(field) ubyte* fitbench.Soa!328LU.depthdepth[(local variable) int ii]]++;
(parameter) fitbench.LevelScratch LL.(field) int* fitbench.LevelScratch.ordord[(local variable) int jj] = (local variable) int ii;
int (local variable) int aa = (parameter) fitbench.Soa!328LU ss.(field) ubyte* fitbench.Soa!328LU.flagsflags[(local variable) int ii] & 1;
(parameter) fitbench.LevelScratch LL.(field) ubyte* fitbench.LevelScratch.axisaxis[(local variable) int jj] = cast(ubyte) (local variable) int aa;
(parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.ww[(local variable) int jj] = (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.szsz[(local variable) int ii][0];
(parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.hh[(local variable) int jj] = (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.szsz[(local variable) int ii][1];
(parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.padMpadM[(local variable) int jj] = (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.padpad[(local variable) int ii][(local variable) int aa];
(parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.padCpadC[(local variable) int jj] = (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.padpad[(local variable) int ii][1 - (local variable) int aa];
(parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.gapgap[(local variable) int jj] = (parameter) fitbench.Soa!328LU ss.(field) float* fitbench.Soa!328LU.gapgap[(local variable) int ii];
(parameter) fitbench.LevelScratch LL.(field) int* fitbench.LevelScratch.cntcnt[(local variable) int jj] = (parameter) fitbench.Soa!328LU ss.(field) int* fitbench.Soa!328LU.childCountchildCount[(local variable) int ii];
}
auto (local variable) core.time.MonoTimeImpl!(ClockType.normal) t0t0 = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
// 2. bottom-up, one level at a time; each parent's children are a contiguous run
for (int (local variable) int dd = (local variable) int maxDmaxD - 1; d >= 0; --d)
{
int (local variable) int cc = (local variable) int[66] startstart[(local variable) int dd + 1];
foreach ((local variable) int jj; (local variable) int[66] startstart[(local variable) int dd] .. (local variable) int[66] startstart[(local variable) int dd + 1])
{
int (local variable) int kk = (parameter) fitbench.LevelScratch LL.(field) int* fitbench.LevelScratch.cntcnt[(local variable) int jj];
if ((local variable) int kk == 0)
continue;
float (local variable) float swsw = (parameter) fitbench.LevelScratch LL.(field) ubyte* fitbench.LevelScratch.axisaxis[(local variable) int jj] ? float fitbench.maxRange(const(float)* p, int k)maxRange((parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.ww + (local variable) int cc, (local variable) int kk) : float fitbench.sumRange(const(float)* p, int k)sumRange((parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.ww + (local variable) int cc, (local variable) int kk);
float (local variable) float shsh = (parameter) fitbench.LevelScratch LL.(field) ubyte* fitbench.LevelScratch.axisaxis[(local variable) int jj] ? float fitbench.sumRange(const(float)* p, int k)sumRange((parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.hh + (local variable) int cc, (local variable) int kk) : float fitbench.maxRange(const(float)* p, int k)maxRange((parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.hh + (local variable) int cc, (local variable) int kk);
float (local variable) float gg = (parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.gapgap[(local variable) int jj] * ((local variable) int kk - 1);
if ((parameter) fitbench.LevelScratch LL.(field) ubyte* fitbench.LevelScratch.axisaxis[(local variable) int jj])
{
(parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.ww[(local variable) int jj] = (local variable) float swsw + (parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.padCpadC[(local variable) int jj];
(parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.hh[(local variable) int jj] = (local variable) float shsh + (parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.padMpadM[(local variable) int jj] + (local variable) float gg;
}
else
{
(parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.ww[(local variable) int jj] = (local variable) float swsw + (parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.padMpadM[(local variable) int jj] + (local variable) float gg;
(parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.hh[(local variable) int jj] = (local variable) float shsh + (parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.padCpadC[(local variable) int jj];
}
(local variable) int cc += (local variable) int kk;
}
}
auto (local variable) core.time.MonoTimeImpl!(ClockType.normal) t1t1 = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
// 3. scatter back into pre-order
foreach ((local variable) int jj; 0 .. (parameter) int nn)
{
int (local variable) int ii = (parameter) fitbench.LevelScratch LL.(field) int* fitbench.LevelScratch.ordord[(local variable) int jj];
(parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.szsz[(local variable) int ii][0] = (parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.ww[(local variable) int jj];
(parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.szsz[(local variable) int ii][1] = (parameter) fitbench.LevelScratch LL.(field) float* fitbench.LevelScratch.hh[(local variable) int jj];
}
return ((local variable) core.time.MonoTimeImpl!(ClockType.normal) t1t1 - core.time.Duration core.time.MonoTimeImpl!(ClockType.normal).opBinary!"-"(core.time.MonoTimeImpl!(ClockType.normal) rhs) const pure nothrow @nogc @safeSubtracting two MonoTimes results in a Duration representing
the amount of time which elapsed between them.
The primary way that programs should time how long something takes is to
do
MonoTime before = MonoTime.currTime;
// do stuff
MonoTime after = MonoTime.currTime;
// How long it took.
Duration timeElapsed = after - before;
or to use a wrapper (such as a stop watch type) which does that.
Warning:
Because Duration is in hnsecs, whereas MonoTime is in system
ticks, it's usually the case that this assertion will fail
auto before = MonoTime.currTime;
// do stuff
auto after = MonoTime.currTime;
auto timeElapsed = after - before;
assert(before + timeElapsed == after);
This is generally fine, and by its very nature, converting from
system ticks to any type of seconds (hnsecs, nsecs, etc.) will
introduce rounding errors, but if code needs to avoid any of the
small rounding errors introduced by conversion, then it needs to use
MonoTime's ticks property and keep all calculations in ticks
rather than using Duration.
t0).core.time.Duration core.time.MonoTimeImpl!(ClockType.normal).opBinary!"-"(core.time.MonoTimeImpl!(ClockType.normal) rhs) const pure nothrow @nogc @safeSubtracting two MonoTimes results in a Duration representing
the amount of time which elapsed between them.
The primary way that programs should time how long something takes is to
do
MonoTime before = MonoTime.currTime;
// do stuff
MonoTime after = MonoTime.currTime;
// How long it took.
Duration timeElapsed = after - before;
or to use a wrapper (such as a stop watch type) which does that.
Warning:
Because Duration is in hnsecs, whereas MonoTime is in system
ticks, it's usually the case that this assertion will fail
auto before = MonoTime.currTime;
// do stuff
auto after = MonoTime.currTime;
auto timeElapsed = after - before;
assert(before + timeElapsed == after);
This is generally fine, and by its very nature, converting from
system ticks to any type of seconds (hnsecs, nsecs, etc.) will
introduce rounding errors, but if code needs to avoid any of the
small rounding errors introduced by conversion, then it needs to use
MonoTime's ticks property and keep all calculations in ticks
rather than using Duration.
total!"nsecs";
}
// ---------------------------------------------------------------------------
// Rest of a Clay-style layout (simplified): grow x, grow y, positions
// ---------------------------------------------------------------------------
enum float[2] (constant) float[2] fitbench.rootSize = [1920.0F, 1080.0F]rootSize = [1920.0f, 1080.0f];
void void fitbench.growAos!(0, 128LU)(fitbench.Node!128LU* nd, int n) pure nothrow @nogc @systemgrowAos(int ax, size_t S)((struct) fitbench.Node!128LUThe fat AoS widget record; the first 64 bytes are the layout-relevant head.
Node!(constant) ulong fitbench.S = 128LUS* (parameter) fitbench.Node!128LU* ndnd, int (parameter) int nn)
{
(parameter) fitbench.Node!128LU* ndnd[0].(field) float[2] fitbench.Node!128LU.fitfit[(constant) int fitbench.ax = 0ax] = (parameter) fitbench.Node!128LU* ndnd[0].(field) float[2] fitbench.Node!128LU.szsz[(constant) int fitbench.ax = 0ax];
(parameter) fitbench.Node!128LU* ndnd[0].(field) float[2] fitbench.Node!128LU.szsz[(constant) int fitbench.ax = 0ax] = (constant) float[2] fitbench.rootSize = [1920.0F, 1080.0F]rootSize[(constant) int fitbench.ax = 0ax];
foreach ((local variable) int ii; 1 .. (parameter) int nn)
{
auto (local variable) fitbench.Node!128LU* cc = &(parameter) fitbench.Node!128LU* ndnd[(local variable) int ii];
auto (local variable) fitbench.Node!128LU* pp = &(parameter) fitbench.Node!128LU* ndnd[(local variable) fitbench.Node!128LU* cc.(field) int fitbench.Node!128LU.parentparent];
(local variable) fitbench.Node!128LU* cc.(field) float[2] fitbench.Node!128LU.fitfit[(constant) int fitbench.ax = 0ax] = (local variable) fitbench.Node!128LU* cc.(field) float[2] fitbench.Node!128LU.szsz[(constant) int fitbench.ax = 0ax];
if (((local variable) fitbench.Node!128LU* cc.(field) ubyte fitbench.Node!128LU.growgrow >> (constant) int fitbench.ax = 0ax) & 1)
{
if ((local variable) fitbench.Node!128LU* pp.(field) ubyte fitbench.Node!128LU.axisaxis == (constant) int fitbench.ax = 0ax)
{
float (local variable) float extraextra = ((local variable) fitbench.Node!128LU* pp.(field) float[2] fitbench.Node!128LU.szsz[(constant) int fitbench.ax = 0ax] - (local variable) fitbench.Node!128LU* pp.(field) float[2] fitbench.Node!128LU.fitfit[(constant) int fitbench.ax = 0ax]) / (local variable) fitbench.Node!128LU* pp.(field) int fitbench.Node!128LU.growCountgrowCount;
float (local variable) float vv = (local variable) fitbench.Node!128LU* cc.(field) float[2] fitbench.Node!128LU.szsz[(constant) int fitbench.ax = 0ax] + (local variable) float extraextra;
(local variable) fitbench.Node!128LU* cc.(field) float[2] fitbench.Node!128LU.szsz[(constant) int fitbench.ax = 0ax] = (local variable) float vv > 0 ? (local variable) float vv : 0;
}
else
(local variable) fitbench.Node!128LU* cc.(field) float[2] fitbench.Node!128LU.szsz[(constant) int fitbench.ax = 0ax] = (local variable) fitbench.Node!128LU* pp.(field) float[2] fitbench.Node!128LU.szsz[(constant) int fitbench.ax = 0ax] - (local variable) fitbench.Node!128LU* pp.(field) float[2] fitbench.Node!128LU.padpad[(constant) int fitbench.ax = 0ax];
}
}
}
void void fitbench.positionsAos!328LU(fitbench.Node!328LU* nd, int n, float* cursor) pure nothrow @nogc @systempositionsAos(size_t S)((struct) fitbench.Node!328LUThe fat AoS widget record; the first 64 bytes are the layout-relevant head.
Node!(constant) ulong fitbench.S = 328LUS* (parameter) fitbench.Node!328LU* ndnd, int (parameter) int nn, float* (parameter) float* cursorcursor)
{
(parameter) fitbench.Node!328LU* ndnd[0].(field) float[2] fitbench.Node!328LU.pospos[0] = (parameter) fitbench.Node!328LU* ndnd[0].(field) float[2] fitbench.Node!328LU.pospos[1] = 0;
(parameter) float* cursorcursor[0] = 0;
foreach ((local variable) int ii; 1 .. (parameter) int nn)
{
auto (local variable) fitbench.Node!328LU* cc = &(parameter) fitbench.Node!328LU* ndnd[(local variable) int ii];
int (local variable) int pipi = (local variable) fitbench.Node!328LU* cc.(field) int fitbench.Node!328LU.parentparent;
auto (local variable) fitbench.Node!328LU* pp = &(parameter) fitbench.Node!328LU* ndnd[(local variable) int pipi];
int (local variable) int aa = (local variable) fitbench.Node!328LU* pp.(field) ubyte fitbench.Node!328LU.axisaxis;
(local variable) fitbench.Node!328LU* cc.(field) float[2] fitbench.Node!328LU.pospos[(local variable) int aa] = (local variable) fitbench.Node!328LU* pp.(field) float[2] fitbench.Node!328LU.pospos[(local variable) int aa] + (local variable) fitbench.Node!328LU* pp.(field) float[2] fitbench.Node!328LU.padpad[(local variable) int aa] * 0.5f + (parameter) float* cursorcursor[(local variable) int pipi];
(local variable) fitbench.Node!328LU* cc.(field) float[2] fitbench.Node!328LU.pospos[1 - (local variable) int aa] = (local variable) fitbench.Node!328LU* pp.(field) float[2] fitbench.Node!328LU.pospos[1 - (local variable) int aa] + (local variable) fitbench.Node!328LU* pp.(field) float[2] fitbench.Node!328LU.padpad[1 - (local variable) int aa] * 0.5f;
(parameter) float* cursorcursor[(local variable) int pipi] += (local variable) fitbench.Node!328LU* cc.(field) float[2] fitbench.Node!328LU.szsz[(local variable) int aa] + (local variable) fitbench.Node!328LU* pp.(field) float fitbench.Node!328LU.gapgap;
(parameter) float* cursorcursor[(local variable) int ii] = 0;
}
}
void void fitbench.growSoa!(0, 128LU)(ref fitbench.Soa!128LU s, int n) pure nothrow @nogc @systemgrowSoa(int ax, size_t S)(ref (struct) fitbench.Soa!128LUSoa!(constant) ulong fitbench.S = 128LUS (parameter) fitbench.Soa!128LU ss, int (parameter) int nn)
{
auto (local variable) float[2]* szsz = (parameter) fitbench.Soa!128LU ss.(field) float[2]* fitbench.Soa!128LU.szsz, (local variable) float[2]* fitfit = (parameter) fitbench.Soa!128LU ss.(field) float[2]* fitbench.Soa!128LU.fitfit, (local variable) ubyte* flfl = (parameter) fitbench.Soa!128LU ss.(field) ubyte* fitbench.Soa!128LU.flagsflags, (local variable) int* parpar = (parameter) fitbench.Soa!128LU ss.(field) int* fitbench.Soa!128LU.parentparent, (local variable) int* gcgc = (parameter) fitbench.Soa!128LU ss.(field) int* fitbench.Soa!128LU.growCountgrowCount, (local variable) float[2]* padpad = (parameter) fitbench.Soa!128LU ss.(field) float[2]* fitbench.Soa!128LU.padpad;
(local variable) float[2]* fitfit[0][(constant) int fitbench.ax = 0ax] = (local variable) float[2]* szsz[0][(constant) int fitbench.ax = 0ax];
(local variable) float[2]* szsz[0][(constant) int fitbench.ax = 0ax] = (constant) float[2] fitbench.rootSize = [1920.0F, 1080.0F]rootSize[(constant) int fitbench.ax = 0ax];
foreach ((local variable) int ii; 1 .. (parameter) int nn)
{
int (local variable) int pp = (local variable) int* parpar[(local variable) int ii];
(local variable) float[2]* fitfit[(local variable) int ii][(constant) int fitbench.ax = 0ax] = (local variable) float[2]* szsz[(local variable) int ii][(constant) int fitbench.ax = 0ax];
if (((local variable) ubyte* flfl[(local variable) int ii] >> (1 + (constant) int fitbench.ax = 0ax)) & 1)
{
if (((local variable) ubyte* flfl[(local variable) int pp] & 1) == (constant) int fitbench.ax = 0ax)
{
float (local variable) float extraextra = ((local variable) float[2]* szsz[(local variable) int pp][(constant) int fitbench.ax = 0ax] - (local variable) float[2]* fitfit[(local variable) int pp][(constant) int fitbench.ax = 0ax]) / (local variable) int* gcgc[(local variable) int pp];
float (local variable) float vv = (local variable) float[2]* szsz[(local variable) int ii][(constant) int fitbench.ax = 0ax] + (local variable) float extraextra;
(local variable) float[2]* szsz[(local variable) int ii][(constant) int fitbench.ax = 0ax] = (local variable) float vv > 0 ? (local variable) float vv : 0;
}
else
(local variable) float[2]* szsz[(local variable) int ii][(constant) int fitbench.ax = 0ax] = (local variable) float[2]* szsz[(local variable) int pp][(constant) int fitbench.ax = 0ax] - (local variable) float[2]* padpad[(local variable) int pp][(constant) int fitbench.ax = 0ax];
}
}
}
void void fitbench.positionsSoa!328LU(ref fitbench.Soa!328LU s, int n, float* cursor) pure nothrow @nogc @systempositionsSoa(size_t S)(ref (struct) fitbench.Soa!328LUSoa!(constant) ulong fitbench.S = 328LUS (parameter) fitbench.Soa!328LU ss, int (parameter) int nn, float* (parameter) float* cursorcursor)
{
auto (local variable) float[2]* szsz = (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.szsz, (local variable) float[2]* pospos = (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.pospos, (local variable) ubyte* flfl = (parameter) fitbench.Soa!328LU ss.(field) ubyte* fitbench.Soa!328LU.flagsflags, (local variable) int* parpar = (parameter) fitbench.Soa!328LU ss.(field) int* fitbench.Soa!328LU.parentparent, (local variable) float[2]* padpad = (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.padpad, (local variable) float* gapgap = (parameter) fitbench.Soa!328LU ss.(field) float* fitbench.Soa!328LU.gapgap;
(local variable) float[2]* pospos[0][0] = (local variable) float[2]* pospos[0][1] = 0;
(parameter) float* cursorcursor[0] = 0;
foreach ((local variable) int ii; 1 .. (parameter) int nn)
{
int (local variable) int pp = (local variable) int* parpar[(local variable) int ii];
int (local variable) int aa = (local variable) ubyte* flfl[(local variable) int pp] & 1;
(local variable) float[2]* pospos[(local variable) int ii][(local variable) int aa] = (local variable) float[2]* pospos[(local variable) int pp][(local variable) int aa] + (local variable) float[2]* padpad[(local variable) int pp][(local variable) int aa] * 0.5f + (parameter) float* cursorcursor[(local variable) int pp];
(local variable) float[2]* pospos[(local variable) int ii][1 - (local variable) int aa] = (local variable) float[2]* pospos[(local variable) int pp][1 - (local variable) int aa] + (local variable) float[2]* padpad[(local variable) int pp][1 - (local variable) int aa] * 0.5f;
(parameter) float* cursorcursor[(local variable) int pp] += (local variable) float[2]* szsz[(local variable) int ii][(local variable) int aa] + (local variable) float* gapgap[(local variable) int pp];
(parameter) float* cursorcursor[(local variable) int ii] = 0;
}
}
// ---------------------------------------------------------------------------
// Checksums
// ---------------------------------------------------------------------------
ulong ulong fitbench.mix(ulong h, float f)mix(ulong (parameter) ulong hh, float (parameter) float ff) => ((parameter) ulong hh ^ *cast(uint*)&(parameter) float ff) * 0x100000001b3UL;
ulong ulong fitbench.sumAos!328LU(fitbench.Node!328LU* nd, int n, bool withPos) @systemsumAos(size_t S)((struct) fitbench.Node!328LUThe fat AoS widget record; the first 64 bytes are the layout-relevant head.
Node!(constant) ulong fitbench.S = 328LUS* (parameter) fitbench.Node!328LU* ndnd, int (parameter) int nn, bool (parameter) bool withPoswithPos)
{
ulong (local variable) ulong hh = 0xcbf29ce484222325UL;
foreach ((local variable) int ii; 0 .. (parameter) int nn)
{
(local variable) ulong hh = ulong fitbench.mix(ulong h, float f)mix(ulong fitbench.mix(ulong h, float f)mix((local variable) ulong hh, (parameter) fitbench.Node!328LU* ndnd[(local variable) int ii].(field) float[2] fitbench.Node!328LU.szsz[0]), (parameter) fitbench.Node!328LU* ndnd[(local variable) int ii].(field) float[2] fitbench.Node!328LU.szsz[1]);
if ((parameter) bool withPoswithPos)
(local variable) ulong hh = ulong fitbench.mix(ulong h, float f)mix(ulong fitbench.mix(ulong h, float f)mix((local variable) ulong hh, (parameter) fitbench.Node!328LU* ndnd[(local variable) int ii].(field) float[2] fitbench.Node!328LU.pospos[0]), (parameter) fitbench.Node!328LU* ndnd[(local variable) int ii].(field) float[2] fitbench.Node!328LU.pospos[1]);
}
return (local variable) ulong hh;
}
ulong ulong fitbench.sumSoa!328LU(ref fitbench.Soa!328LU s, int n, bool withPos) @systemsumSoa(size_t S)(ref (constant) ulong fitbench.S = 64LUSoa!(constant) ulong fitbench.S = 328LUS (parameter) fitbench.Soa!328LU ss, int (parameter) int nn, bool (parameter) bool withPoswithPos)
{
ulong (local variable) ulong hh = 0xcbf29ce484222325UL;
foreach ((local variable) int ii; 0 .. (parameter) int nn)
{
(local variable) ulong hh = ulong fitbench.mix(ulong h, float f)mix(ulong fitbench.mix(ulong h, float f)mix((local variable) ulong hh, (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.szsz[(local variable) int ii][0]), (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.szsz[(local variable) int ii][1]);
if ((parameter) bool withPoswithPos)
(local variable) ulong hh = ulong fitbench.mix(ulong h, float f)mix(ulong fitbench.mix(ulong h, float f)mix((local variable) ulong hh, (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.pospos[(local variable) int ii][0]), (parameter) fitbench.Soa!328LU ss.(field) float[2]* fitbench.Soa!328LU.pospos[(local variable) int ii][1]);
}
return (local variable) ulong hh;
}
// ---------------------------------------------------------------------------
// perf_event_open counters (in-process, around the timed region only)
// ---------------------------------------------------------------------------
extern (C) long long fitbench.syscall(long, ...) nothrow @nogcsyscall(long, ...) nothrow @nogc;
extern (C) int int fitbench.ioctl(int, ulong, ...) nothrow @nogcioctl(int, ulong, ...) nothrow @nogc;
import (package) corecore.(package) core.syssys.(package) core.sys.posixposix.(module) core.sys.posix.unistdD header file for POSIX.
unistd : (alias) fitbench.read = long core.sys.posix.unistd.read(int, void*, ulong) nothrow @nogcread, (alias) fitbench.close = int core.sys.posix.unistd.close(int) nothrow @nogc @trustedclose;
struct (struct) fitbench.PerfAttrPerfAttr
{
uint (field) uint fitbench.PerfAttr.typetype, (field) uint fitbench.PerfAttr.sizesize;
ulong (field) ulong fitbench.PerfAttr.configconfig, (field) ulong fitbench.PerfAttr.samplePeriodsamplePeriod, (field) ulong fitbench.PerfAttr.sampleTypesampleType, (field) ulong fitbench.PerfAttr.readFormatreadFormat, (field) ulong fitbench.PerfAttr.flagsflags;
uint (field) uint fitbench.PerfAttr.wakeupwakeup, (field) uint fitbench.PerfAttr.bpTypebpType;
ulong (field) ulong fitbench.PerfAttr.config1config1;
}
static assert((struct) fitbench.PerfAttrPerfAttr.(constant) ulong fitbench.PerfAttr.sizeof = 64LUsizeof == 64);
enum (constant) int fitbench.nCtr = 5nCtr = 5;
// cycles, instructions, L1D read misses, L2 misses (generic cache-misses; on
// Zen = l2_cache_req_stat.ic_dc_miss_in_l2), DRAM fills (raw
// ls_any_fills_from_sys.dram_io_all, event 0x44 umask 0x48; includes prefetch fills)
immutable uint[(constant) int fitbench.nCtr = 5nCtr] (immutable global) immutable(uint[5]) fitbench.ctrTypesctrTypes = [0, 0, 3, 0, 4];
immutable ulong[(constant) int fitbench.nCtr = 5nCtr] (immutable global) immutable(ulong[5]) fitbench.ctrCfgsctrCfgs = [0, 1, 0 | (0 << 8) | (1 << 16), 3, 0x4844];
struct (struct) fitbench.PerfPerf
{
int (field) int fitbench.Perf.leaderleader = -1;
int[(constant) int fitbench.nCtr = 5nCtr] (field) int[5] fitbench.Perf.slotslot = -1; // position in group read
int (field) int fitbench.Perf.nOpennOpen;
void void fitbench.Perf.open()open()
{
foreach ((local variable) int kk; 0 .. (constant) int fitbench.nCtr = 5nCtr)
{
(struct) fitbench.PerfAttrPerfAttr (local variable) fitbench.PerfAttr aa;
(local variable) fitbench.PerfAttr aa.(field) uint fitbench.PerfAttr.typetype = (immutable global) immutable(uint[5]) fitbench.ctrTypesctrTypes[(local variable) int kk];
(local variable) fitbench.PerfAttr aa.(field) uint fitbench.PerfAttr.sizesize = (struct) fitbench.PerfAttrPerfAttr.(constant) ulong fitbench.PerfAttr.sizeof = 64LUsizeof;
(local variable) fitbench.PerfAttr aa.(field) ulong fitbench.PerfAttr.configconfig = (immutable global) immutable(ulong[5]) fitbench.ctrCfgsctrCfgs[(local variable) int kk];
(local variable) fitbench.PerfAttr aa.(field) ulong fitbench.PerfAttr.readFormatreadFormat = 8 | 1 | 2; // GROUP | TIME_ENABLED | TIME_RUNNING
(local variable) fitbench.PerfAttr aa.(field) ulong fitbench.PerfAttr.flagsflags = ((field) int fitbench.Perf.leaderleader < 0 ? 1 : 0) | (1 << 5) | (1 << 6); // disabled(leader), excl kernel, hv
int (local variable) int ff = cast(int) long fitbench.syscall(long, ...) nothrow @nogcsyscall(298, &(local variable) fitbench.PerfAttr aa, 0, -1, (field) int fitbench.Perf.leaderleader, 0UL);
if ((local variable) int ff < 0)
continue;
if ((field) int fitbench.Perf.leaderleader < 0)
(field) int fitbench.Perf.leaderleader = (local variable) int ff;
(field) int[5] fitbench.Perf.slotslot[(local variable) int kk] = (field) int fitbench.Perf.nOpennOpen++;
}
}
void void fitbench.Perf.start()start()
{
if ((field) int fitbench.Perf.leaderleader < 0)
return;
int fitbench.ioctl(int, ulong, ...) nothrow @nogcioctl((field) int fitbench.Perf.leaderleader, 0x2403, 1); // RESET, group
int fitbench.ioctl(int, ulong, ...) nothrow @nogcioctl((field) int fitbench.Perf.leaderleader, 0x2400, 1); // ENABLE, group
}
void void fitbench.Perf.stop()stop()
{
if ((field) int fitbench.Perf.leaderleader >= 0)
int fitbench.ioctl(int, ulong, ...) nothrow @nogcioctl((field) int fitbench.Perf.leaderleader, 0x2401, 1);
}
/// Reads the running group; returns false if multiplexed.
bool bool fitbench.Perf.snap(ref ulong[5] out_)Reads the running group; returns false if multiplexed.
snap(ref ulong[(constant) int fitbench.nCtr = 5nCtr] (parameter) ulong[5] out_out_)
{
(parameter) ulong[5] out_out_[] = 0;
if ((field) int fitbench.Perf.leaderleader < 0)
return false;
ulong[3 + (constant) int fitbench.nCtr = 5nCtr] (local variable) ulong[8] bufbuf;
if (long core.sys.posix.unistd.read(int, void*, ulong) nothrow @nogcread((field) int fitbench.Perf.leaderleader, (local variable) ulong[8] bufbuf.(constant) ulong* ulong[8].ptr = &bufptr, (local variable) ulong[8] bufbuf.(constant) ulong ulong[8].sizeof = 64LUsizeof) <= 0)
return false;
foreach ((local variable) int kk; 0 .. (constant) int fitbench.nCtr = 5nCtr)
if ((field) int[5] fitbench.Perf.slotslot[(local variable) int kk] >= 0)
(parameter) ulong[5] out_out_[(local variable) int kk] = (local variable) ulong[8] bufbuf[3 + (field) int[5] fitbench.Perf.slotslot[(local variable) int kk]];
return (local variable) ulong[8] bufbuf[1] == (local variable) ulong[8] bufbuf[2];
}
}
// ---------------------------------------------------------------------------
// Harness
// ---------------------------------------------------------------------------
struct (struct) fitbench.ResultResult
{
(alias) object.string = stringstring (field) string fitbench.Result.variantvariant;
double (field) double fitbench.Result.totaltotal, (field) double fitbench.Result.buildbuild, (field) double fitbench.Result.passpass, (field) double fitbench.Result.auxaux; // medians, ns/node
double[(constant) int fitbench.nCtr = 5nCtr] (field) double[5] fitbench.Result.ctrctr; // medians, per node, whole timed region
double[(constant) int fitbench.nCtr = 5nCtr] (field) double[5] fitbench.Result.passCtrpassCtr; // medians, per node, pass only
ulong (field) ulong fitbench.Result.checksumchecksum;
}
double double fitbench.median(double[] xs)median(double[] (parameter) double[] xsxs)
{
std.range.SortedRange!(double[], "a < b", SortedRangeOptions.assumeSorted) std.algorithm.sorting.sort!("a < b", SwapStrategy.unstable, double[])(double[] r) pure nothrow @nogc @safeSorts a random-access range according to the predicate less.
Performs O(r.length * log(r.length)) evaluations of less. If less involves
expensive computations on the sort key, it may be worthwhile to use
schwartzSort instead.
Stable sorting requires hasAssignableElements!Range to be true.
sort returns a SortedRange over the original range,
allowing functions that can take advantage of sorted data to know that the
range is sorted and adjust accordingly. The SortedRange is a
wrapper around the original range, so both it and the original range are sorted.
Other functions can't know that the original range has been sorted, but
they can know that SortedRange has been sorted.
Preconditions
The predicate is expected to satisfy certain rules in order for sort to
behave as expected - otherwise, the program may fail on certain inputs (but not
others) when not compiled in release mode, due to the cursory assumeSorted
check. Specifically, sort expects less(a,b) && less(b,c) to imply
less(a,c) (transitivity), and, conversely, !less(a,b) && !less(b,c) to
imply !less(a,c). Note that the default predicate ("a < b") does not
always satisfy these conditions for floating point types, because the expression
will always be false when either a or b is NaN.
Use cmp instead.
Algorithms
Introsort is used for unstable sorting and
Timsort is used for stable sorting.
Each algorithm has benefits beyond stability. Introsort is generally faster but
Timsort may achieve greater speeds on data with low entropy or if predicate calls
are expensive. Introsort performs no allocations whereas Timsort will perform one
or more allocations per call. Both algorithms have O(n log n) worst-case
time complexity.
Examples
int[] array = [ 1, 2, 3, 4 ];
// sort in descending order
array.sort!("a > b");
assert(array == [ 4, 3, 2, 1 ]);
// sort in ascending order
array.sort();
assert(array == [ 1, 2, 3, 4 ]);
// sort with reusable comparator and chain
alias myComp = (x, y) => x > y;
assert(array.sort!(myComp).release == [ 4, 3, 2, 1 ]);
// Showcase stable sorting
import std.algorithm.mutation : SwapStrategy;
string[] words = [ "aBc", "a", "abc", "b", "ABC", "c" ];
sort!("toUpper(a) < toUpper(b)", SwapStrategy.stable)(words);
assert(words == [ "a", "aBc", "abc", "ABC", "b", "c" ]);
// Sorting floating-point numbers in presence of NaN
double[] numbers = [-0.0, 3.0, -2.0, double.nan, 0.0, -double.nan];
import std.algorithm.comparison : equal;
import std.math.operations : cmp;
import std.math.traits : isIdentical;
sort!((a, b) => cmp(a, b) < 0)(numbers);
double[] sorted = [-double.nan, -2.0, -0.0, 0.0, 3.0, double.nan];
assert(numbers.equal!isIdentical(sorted));
sort((parameter) double[] xsxs);
return (parameter) double[] xsxs.(field) ulong double[].lengthlength % 2 ? (parameter) double[] xsxs[$ / 2] : ((parameter) double[] xsxs[$ / 2 - 1] + (parameter) double[] xsxs[$ / 2]) / 2;
}
int (thread local global) int fitbench.repsreps = 21;
enum (constant) int fitbench.warmup = 3warmup = 3;
(struct) fitbench.PerfPerf (thread local global) fitbench.Perf fitbench.perfperf;
ulong[(constant) int fitbench.nCtr = 5nCtr][3] (constant) int fitbench.nCtr = 5snaps;
bool[3] (thread local global) bool[3] fitbench.markedmarked;
bool (thread local global) bool fitbench.multiplexedmultiplexed;
/// Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
/// Called outside the MonoTime-timed intervals.
void void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(int (parameter) int kk)
{
if (!(thread local global) fitbench.Perf fitbench.perfperf.bool fitbench.Perf.snap(ref ulong[5] out_)Reads the running group; returns false if multiplexed.
snap((thread local global) ulong[5][3] fitbench.snapssnaps[(parameter) int kk]))
(thread local global) bool fitbench.multiplexedmultiplexed = (thread local global) fitbench.Perf fitbench.perfperf.(field) int fitbench.Perf.leaderleader >= 0;
(thread local global) bool[3] fitbench.markedmarked[(parameter) int kk] = true;
}
(struct) fitbench.ResultResult fitbench.Result fitbench.measure(string name, int n, scope void delegate(out long, out long, out long) run, scope ulong delegate() check)measure((alias) object.string = stringstring (parameter) string namename, int (parameter) int nn, scope void delegate(out long, out long, out long) (parameter) void delegate(out long, out long, out long) runrun, scope ulong delegate() (parameter) ulong delegate() checkcheck)
{
double[] (local variable) double[] tottot, (local variable) double[] bldbld, (local variable) double[] paspas, (local variable) double[] auxaux;
double[][(constant) int fitbench.nCtr = 5nCtr] (local variable) double[][5] cscs, (local variable) double[][5] psps;
foreach ((local variable) int rr; 0 .. (constant) int fitbench.warmup = 3warmup + (thread local global) int fitbench.repsreps)
{
long (local variable) long bb, (local variable) long pp, (local variable) long xx;
(thread local global) bool[3] fitbench.markedmarked[] = false;
(thread local global) fitbench.Perf fitbench.perfperf.void fitbench.Perf.start()start();
(parameter) void delegate(out long, out long, out long) runrun((local variable) long bb, (local variable) long pp, (local variable) long xx);
(thread local global) fitbench.Perf fitbench.perfperf.void fitbench.Perf.stop()stop();
if (!(thread local global) bool[3] fitbench.markedmarked[2])
(thread local global) ulong[5][3] fitbench.snapssnaps[2] = (thread local global) ulong[5][3] fitbench.snapssnaps[1];
if ((local variable) int rr < (constant) int fitbench.warmup = 3warmup)
continue;
(local variable) double[] tottot ~= cast(double)((local variable) long bb + (local variable) long pp) / (parameter) int nn;
(local variable) double[] bldbld ~= cast(double) (local variable) long bb / (parameter) int nn;
(local variable) double[] paspas ~= cast(double) (local variable) long pp / (parameter) int nn;
(local variable) double[] auxaux ~= cast(double) (local variable) long xx / (parameter) int nn;
foreach ((local variable) int kk; 0 .. (constant) int fitbench.nCtr = 5nCtr)
{
(local variable) double[][5] cscs[(local variable) int kk] ~= cast(double)((thread local global) ulong[5][3] fitbench.snapssnaps[2][(local variable) int kk] - (thread local global) ulong[5][3] fitbench.snapssnaps[0][(local variable) int kk]) / (parameter) int nn;
(local variable) double[][5] psps[(local variable) int kk] ~= cast(double)((thread local global) ulong[5][3] fitbench.snapssnaps[2][(local variable) int kk] - (thread local global) ulong[5][3] fitbench.snapssnaps[1][(local variable) int kk]) / (parameter) int nn;
}
}
(struct) fitbench.ResultResult (local variable) fitbench.Result resres;
(local variable) fitbench.Result resres.(field) string fitbench.Result.variantvariant = (parameter) string namename;
(local variable) fitbench.Result resres.(field) double fitbench.Result.totaltotal = double fitbench.median(double[] xs)median((local variable) double[] tottot);
(local variable) fitbench.Result resres.(field) double fitbench.Result.buildbuild = double fitbench.median(double[] xs)median((local variable) double[] bldbld);
(local variable) fitbench.Result resres.(field) double fitbench.Result.passpass = double fitbench.median(double[] xs)median((local variable) double[] paspas);
(local variable) fitbench.Result resres.(field) double fitbench.Result.auxaux = double fitbench.median(double[] xs)median((local variable) double[] auxaux);
foreach ((local variable) int kk; 0 .. (constant) int fitbench.nCtr = 5nCtr)
{
(local variable) fitbench.Result resres.(field) double[5] fitbench.Result.ctrctr[(local variable) int kk] = (thread local global) fitbench.Perf fitbench.perfperf.(field) int[5] fitbench.Perf.slotslot[(local variable) int kk] >= 0 ? double fitbench.median(double[] xs)median((local variable) double[][5] cscs[(local variable) int kk]) : double.(constant) double double.nan = nannan;
(local variable) fitbench.Result resres.(field) double[5] fitbench.Result.passCtrpassCtr[(local variable) int kk] = (thread local global) fitbench.Perf fitbench.perfperf.(field) int[5] fitbench.Perf.slotslot[(local variable) int kk] >= 0 ? double fitbench.median(double[] xs)median((local variable) double[][5] psps[(local variable) int kk]) : double.(constant) double double.nan = nannan;
}
(local variable) fitbench.Result resres.(field) ulong fitbench.Result.checksumchecksum = (parameter) ulong delegate() checkcheck();
return (local variable) fitbench.Result resres;
}
long long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime (parameter) core.time.MonoTimeImpl!(ClockType.normal) tt) => ((struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime - core.time.Duration core.time.MonoTimeImpl!(ClockType.normal).opBinary!"-"(core.time.MonoTimeImpl!(ClockType.normal) rhs) const pure nothrow @nogc @safeSubtracting two MonoTimes results in a Duration representing
the amount of time which elapsed between them.
The primary way that programs should time how long something takes is to
do
MonoTime before = MonoTime.currTime;
// do stuff
MonoTime after = MonoTime.currTime;
// How long it took.
Duration timeElapsed = after - before;
or to use a wrapper (such as a stop watch type) which does that.
Warning:
Because Duration is in hnsecs, whereas MonoTime is in system
ticks, it's usually the case that this assertion will fail
auto before = MonoTime.currTime;
// do stuff
auto after = MonoTime.currTime;
auto timeElapsed = after - before;
assert(before + timeElapsed == after);
This is generally fine, and by its very nature, converting from
system ticks to any type of seconds (hnsecs, nsecs, etc.) will
introduce rounding errors, but if code needs to avoid any of the
small rounding errors introduced by conversion, then it needs to use
MonoTime's ticks property and keep all calculations in ticks
rather than using Duration.
t).core.time.Duration core.time.MonoTimeImpl!(ClockType.normal).opBinary!"-"(core.time.MonoTimeImpl!(ClockType.normal) rhs) const pure nothrow @nogc @safeSubtracting two MonoTimes results in a Duration representing
the amount of time which elapsed between them.
The primary way that programs should time how long something takes is to
do
MonoTime before = MonoTime.currTime;
// do stuff
MonoTime after = MonoTime.currTime;
// How long it took.
Duration timeElapsed = after - before;
or to use a wrapper (such as a stop watch type) which does that.
Warning:
Because Duration is in hnsecs, whereas MonoTime is in system
ticks, it's usually the case that this assertion will fail
auto before = MonoTime.currTime;
// do stuff
auto after = MonoTime.currTime;
auto timeElapsed = after - before;
assert(before + timeElapsed == after);
This is generally fine, and by its very nature, converting from
system ticks to any type of seconds (hnsecs, nsecs, etc.) will
introduce rounding errors, but if code needs to avoid any of the
small rounding errors introduced by conversion, then it needs to use
MonoTime's ticks property and keep all calculations in ticks
rather than using Duration.
total!"nsecs";
(struct) fitbench.ResultResult[] fitbench.Result[] fitbench.runConfig!328LU(const(fitbench.Ev)[] evs, const(char)* pool, int n, string[] only) @systemrunConfig(size_t S)(const((struct) fitbench.EvEv)[] (parameter) const(fitbench.Ev)[] evsevs, const(char)* (parameter) const(char)* poolpool, int (parameter) int nn, (alias) object.string = stringstring[] (parameter) string[] onlyonly)
{
(struct) fitbench.ResultResult[] (local variable) fitbench.Result[] out_out_;
bool bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safewant((alias) object.string = stringstring (parameter) string vv) => (parameter) string[] onlyonly.(field) ulong string[].lengthlength == 0 || (parameter) string[] onlyonly.bool std.algorithm.searching.canFind!().canFind!(string[], string)(string[] haystack, scope string needle) pure nothrow @nogc @safeConvenience function. Like find, but only returns whether or not the search
was successful.
For more information about pred see find.
Examples
const arr = [0, 1, 2, 3];
assert(canFind(arr, 2));
assert(!canFind(arr, 4));
// find one of several needles
assert(arr.canFind(3, 2));
assert(arr.canFind(3, 2) == 2); // second needle found
assert(arr.canFind([1, 3], 2) == 2);
assert(canFind(arr, [1, 2], [2, 3]));
assert(canFind(arr, [1, 2], [2, 3]) == 1);
assert(canFind(arr, [1, 7], [2, 3]));
assert(canFind(arr, [1, 7], [2, 3]) == 2);
assert(!canFind(arr, [1, 3], [2, 4]));
assert(canFind(arr, [1, 3], [2, 4]) == 0);
Example using a custom predicate.
Note that the needle appears as the second argument of the predicate.
auto words = [
"apple",
"beeswax",
"cardboard"
];
assert(!canFind(words, "bees"));
assert( canFind!((string elem, string needle) => elem.startsWith(needle))(words, "bees"));
Search for multiple items in an array of items (search for needles in an array of haystacks)
string s1 = "aaa111aaa";
string s2 = "aaa222aaa";
string s3 = "aaa333aaa";
string s4 = "aaa444aaa";
const hay = [s1, s2, s3, s4];
assert(hay.canFind!(e => e.canFind("111", "222")));
canFind((parameter) string vv);
auto (local variable) fitbench.Node!328LU* aosaos = cast((constant) ulong fitbench.S = 328LUNode!(constant) ulong fitbench.S = 328LUS*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc(cast((alias) object.size_t = ulongsize_t) (parameter) int nn * (constant) ulong fitbench.S = 328LUNode!(constant) ulong fitbench.S = 328LUS.(constant) ulong fitbench.Node!328LU.sizeof = 328LUsizeof);
(constant) ulong fitbench.S = 328LUSoa!(constant) ulong fitbench.S = 328LUS (local variable) fitbench.Soa!328LU soasoa;
(local variable) fitbench.Soa!328LU soasoa.void fitbench.Soa!328LU.alloc(ulong n) nothrow @nogc @systemalloc((parameter) int nn);
(struct) fitbench.LevelScratchScratch for the level-order variant.
LevelScratch (local variable) fitbench.LevelScratch LL;
(local variable) fitbench.LevelScratch LL.void fitbench.LevelScratch.alloc(ulong n)alloc((parameter) int nn);
auto (local variable) float* cursorcursor = cast(float*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((parameter) int nn * 4);
scope (exit)
{
void core.stdc.stdlib.free(void* ptr) nothrow @nogcfree((local variable) fitbench.Node!328LU* aosaos);
(local variable) fitbench.Soa!328LU soasoa.void fitbench.Soa!328LU.release() nothrow @nogc @systemrelease();
(local variable) fitbench.LevelScratch LL.void fitbench.LevelScratch.release()release();
void core.stdc.stdlib.free(void* ptr) nothrow @nogcfree((local variable) float* cursorcursor);
}
if (bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safewant("fused-aos"))
(local variable) fitbench.Result[] out_out_ ~= fitbench.Result fitbench.measure(string name, int n, scope void delegate(out long, out long, out long) run, scope ulong delegate() check)measure("fused-aos", (parameter) int nn, (out long (parameter) long bb, out long (parameter) long pp, out long (parameter) long xx) {
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(0);
auto (local variable) core.time.MonoTimeImpl!(ClockType.normal) tt = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
(constant) ulong fitbench.S = 128LUbuildAos!(true, (constant) ulong fitbench.S = 328LUS)((parameter) const(fitbench.Ev)[] evsevs, (parameter) const(char)* poolpool, (local variable) fitbench.Node!328LU* aosaos);
(parameter) long bb = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(1);
}, () => ulong fitbench.sumAos!328LU(fitbench.Node!328LU* nd, int n, bool withPos) @systemsumAos((local variable) fitbench.Node!328LU* aosaos, (parameter) int nn, false));
if (bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safewant("sep-aos"))
(local variable) fitbench.Result[] out_out_ ~= fitbench.Result fitbench.measure(string name, int n, scope void delegate(out long, out long, out long) run, scope ulong delegate() check)measure("sep-aos", (parameter) int nn, (out long (parameter) long bb, out long (parameter) long pp, out long (parameter) long xx) {
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(0);
auto (local variable) core.time.MonoTimeImpl!(ClockType.normal) tt = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
(constant) ulong fitbench.S = 128LUbuildAos!(false, (constant) ulong fitbench.S = 328LUS)((parameter) const(fitbench.Ev)[] evsevs, (parameter) const(char)* poolpool, (local variable) fitbench.Node!328LU* aosaos);
(parameter) long bb = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(1);
(local variable) core.time.MonoTimeImpl!(ClockType.normal) tt = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
void fitbench.fitSweepAos!328LU(fitbench.Node!328LU* nodes, int n) pure nothrow @nogc @systemfitSweepAos((local variable) fitbench.Node!328LU* aosaos, (parameter) int nn);
(parameter) long pp = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(2);
}, () => ulong fitbench.sumAos!328LU(fitbench.Node!328LU* nd, int n, bool withPos) @systemsumAos((local variable) fitbench.Node!328LU* aosaos, (parameter) int nn, false));
if (bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safewant("fused-soa"))
(local variable) fitbench.Result[] out_out_ ~= fitbench.Result fitbench.measure(string name, int n, scope void delegate(out long, out long, out long) run, scope ulong delegate() check)measure("fused-soa", (parameter) int nn, (out long (parameter) long bb, out long (parameter) long pp, out long (parameter) long xx) {
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(0);
auto (local variable) core.time.MonoTimeImpl!(ClockType.normal) tt = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
(constant) ulong fitbench.S = 64LUbuildSoa!(true, false, (constant) ulong fitbench.S = 328LUS)((parameter) const(fitbench.Ev)[] evsevs, (parameter) const(char)* poolpool, (local variable) fitbench.Soa!328LU soasoa);
(parameter) long bb = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(1);
}, () => ulong fitbench.sumSoa!328LU(ref fitbench.Soa!328LU s, int n, bool withPos) @systemsumSoa((local variable) fitbench.Soa!328LU soasoa, (parameter) int nn, false));
if (bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safewant("sep-soa"))
(local variable) fitbench.Result[] out_out_ ~= fitbench.Result fitbench.measure(string name, int n, scope void delegate(out long, out long, out long) run, scope ulong delegate() check)measure("sep-soa", (parameter) int nn, (out long (parameter) long bb, out long (parameter) long pp, out long (parameter) long xx) {
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(0);
auto (local variable) core.time.MonoTimeImpl!(ClockType.normal) tt = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
(constant) ulong fitbench.S = 64LUbuildSoa!(false, false, (constant) ulong fitbench.S = 328LUS)((parameter) const(fitbench.Ev)[] evsevs, (parameter) const(char)* poolpool, (local variable) fitbench.Soa!328LU soasoa);
(parameter) long bb = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(1);
(local variable) core.time.MonoTimeImpl!(ClockType.normal) tt = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
void fitbench.fitSweepSoa!328LU(ref fitbench.Soa!328LU s, int n) pure nothrow @nogc @systemfitSweepSoa((local variable) fitbench.Soa!328LU soasoa, (parameter) int nn);
(parameter) long pp = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(2);
}, () => ulong fitbench.sumSoa!328LU(ref fitbench.Soa!328LU s, int n, bool withPos) @systemsumSoa((local variable) fitbench.Soa!328LU soasoa, (parameter) int nn, false));
if (bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safewant("sep-soa-rc"))
(local variable) fitbench.Result[] out_out_ ~= fitbench.Result fitbench.measure(string name, int n, scope void delegate(out long, out long, out long) run, scope ulong delegate() check)measure("sep-soa-rc", (parameter) int nn, (out long (parameter) long bb, out long (parameter) long pp, out long (parameter) long xx) {
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(0);
auto (local variable) core.time.MonoTimeImpl!(ClockType.normal) tt = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
(constant) ulong fitbench.S = 64LUbuildSoa!(false, false, (constant) ulong fitbench.S = 328LUS)((parameter) const(fitbench.Ev)[] evsevs, (parameter) const(char)* poolpool, (local variable) fitbench.Soa!328LU soasoa);
(parameter) long bb = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(1);
(local variable) core.time.MonoTimeImpl!(ClockType.normal) tt = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
void fitbench.fitSweepSoaRc!328LU(ref fitbench.Soa!328LU s, int n) pure nothrow @nogc @systemsep-soa with the current parent's accumulator carried in registers while
consecutive (reverse pre-order) nodes share a parent, so sibling runs do
not form a store->load chain through sz[p]. Same op order => same bits.
fitSweepSoaRc((local variable) fitbench.Soa!328LU soasoa, (parameter) int nn);
(parameter) long pp = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(2);
}, () => ulong fitbench.sumSoa!328LU(ref fitbench.Soa!328LU s, int n, bool withPos) @systemsumSoa((local variable) fitbench.Soa!328LU soasoa, (parameter) int nn, false));
if (bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safewant("level-soa"))
(local variable) fitbench.Result[] out_out_ ~= fitbench.Result fitbench.measure(string name, int n, scope void delegate(out long, out long, out long) run, scope ulong delegate() check)measure("level-soa", (parameter) int nn, (out long (parameter) long bb, out long (parameter) long pp, out long (parameter) long xx) {
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(0);
auto (local variable) core.time.MonoTimeImpl!(ClockType.normal) tt = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
(constant) ulong fitbench.S = 64LUbuildSoa!(false, true, (constant) ulong fitbench.S = 328LUS)((parameter) const(fitbench.Ev)[] evsevs, (parameter) const(char)* poolpool, (local variable) fitbench.Soa!328LU soasoa);
(parameter) long bb = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(1);
(local variable) core.time.MonoTimeImpl!(ClockType.normal) tt = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
(parameter) long xx = long fitbench.fitLevel!328LU(ref fitbench.Soa!328LU s, ref fitbench.LevelScratch L, int n) @systemReturns ns spent in the pure level reduction (for the breakdown).
fitLevel((local variable) fitbench.Soa!328LU soasoa, (local variable) fitbench.LevelScratch LL, (parameter) int nn);
(parameter) long pp = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(2);
}, () => ulong fitbench.sumSoa!328LU(ref fitbench.Soa!328LU s, int n, bool withPos) @systemsumSoa((local variable) fitbench.Soa!328LU soasoa, (parameter) int nn, false));
// rest of layout: timed part is the three passes only (build+fit untimed)
if (bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safewant("rest-aos"))
(local variable) fitbench.Result[] out_out_ ~= fitbench.Result fitbench.measure(string name, int n, scope void delegate(out long, out long, out long) run, scope ulong delegate() check)measure("rest-aos", (parameter) int nn, (out long (parameter) long bb, out long (parameter) long pp, out long (parameter) long xx) {
int fitbench.buildAos!(true, 328LU)(const(fitbench.Ev)[] evs, const(char)* pool, fitbench.Node!328LU* nodes) @systembuildAos!(true, (constant) ulong fitbench.S = 328LUS)((parameter) const(fitbench.Ev)[] evsevs, (parameter) const(char)* poolpool, (local variable) fitbench.Node!328LU* aosaos);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(0);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(1);
auto (local variable) core.time.MonoTimeImpl!(ClockType.normal) tt = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
void fitbench.growAos!(0, 328LU)(fitbench.Node!328LU* nd, int n) pure nothrow @nogc @systemgrowAos!(0, (constant) ulong fitbench.S = 328LUS)((local variable) fitbench.Node!328LU* aosaos, (parameter) int nn);
void fitbench.growAos!(1, 328LU)(fitbench.Node!328LU* nd, int n) pure nothrow @nogc @systemgrowAos!(1, (constant) ulong fitbench.S = 328LUS)((local variable) fitbench.Node!328LU* aosaos, (parameter) int nn);
(parameter) long xx = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt); // grow x+y
void fitbench.positionsAos!328LU(fitbench.Node!328LU* nd, int n, float* cursor) pure nothrow @nogc @systempositionsAos((local variable) fitbench.Node!328LU* aosaos, (parameter) int nn, (local variable) float* cursorcursor);
(parameter) long pp = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(2);
}, () => ulong fitbench.sumAos!328LU(fitbench.Node!328LU* nd, int n, bool withPos) @systemsumAos((local variable) fitbench.Node!328LU* aosaos, (parameter) int nn, true));
if (bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safewant("rest-soa"))
(local variable) fitbench.Result[] out_out_ ~= fitbench.Result fitbench.measure(string name, int n, scope void delegate(out long, out long, out long) run, scope ulong delegate() check)measure("rest-soa", (parameter) int nn, (out long (parameter) long bb, out long (parameter) long pp, out long (parameter) long xx) {
int fitbench.buildSoa!(true, false, 328LU)(const(fitbench.Ev)[] evs, const(char)* pool, ref fitbench.Soa!328LU s) @systembuildSoa!(true, false, (constant) ulong fitbench.S = 328LUS)((parameter) const(fitbench.Ev)[] evsevs, (parameter) const(char)* poolpool, (local variable) fitbench.Soa!328LU soasoa);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(0);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(1);
auto (local variable) core.time.MonoTimeImpl!(ClockType.normal) tt = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe current time of the system's monotonic clock. This has no relation
to the wall clock time, as the wall clock time can be adjusted (e.g.
by NTP), whereas the monotonic clock always moves forward. The source
of the monotonic time is system-specific.
On Windows, QueryPerformanceCounter is used. On Mac OS X,
mach_absolute_time is used, while on other POSIX systems,
clock_gettime is used.
Warning: On some systems, the monotonic clock may stop counting
when the computer goes to sleep or hibernates. So, the
monotonic clock may indicate less time than has actually
passed if that occurs. This is known to happen on
Mac OS X. It has not been tested whether it occurs on
either Windows or Linux.
currTime;
void fitbench.growSoa!(0, 328LU)(ref fitbench.Soa!328LU s, int n) pure nothrow @nogc @systemgrowSoa!(0, (constant) ulong fitbench.S = 328LUS)((local variable) fitbench.Soa!328LU soasoa, (parameter) int nn);
void fitbench.growSoa!(1, 328LU)(ref fitbench.Soa!328LU s, int n) pure nothrow @nogc @systemgrowSoa!(1, (constant) ulong fitbench.S = 328LUS)((local variable) fitbench.Soa!328LU soasoa, (parameter) int nn);
(parameter) long xx = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.positionsSoa!328LU(ref fitbench.Soa!328LU s, int n, float* cursor) pure nothrow @nogc @systempositionsSoa((local variable) fitbench.Soa!328LU soasoa, (parameter) int nn, (local variable) float* cursorcursor);
(parameter) long pp = long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)since((local variable) core.time.MonoTimeImpl!(ClockType.normal) tt);
void fitbench.mark(int k)Snapshot counters at phase boundary k (0 = start, 1 = build done, 2 = pass done).
Called outside the MonoTime-timed intervals.
mark(2);
}, () => ulong fitbench.sumSoa!328LU(ref fitbench.Soa!328LU s, int n, bool withPos) @systemsumSoa((local variable) fitbench.Soa!328LU soasoa, (parameter) int nn, true));
return (local variable) fitbench.Result[] out_out_;
}
void void D main(string[] args)main((alias) object.string = stringstring[] (parameter) string[] argsargs)
{
(alias) object.string = stringstring[] (local variable) string[] shapesshapes = ["list", "panels"];
int[] (local variable) int[] nsns = [1_000, 10_000, 100_000, 1_000_000];
int[] (local variable) int[] fatsfats = [64, 128, 328];
(alias) object.string = stringstring[] (local variable) string[] onlyonly;
for ((alias) object.size_t = ulongsize_t (local variable) ulong ii = 1; i < args.length; ++i)
{
auto (local variable) string vv = (local variable) ulong ii + 1 < (parameter) string[] argsargs.(field) ulong string[].lengthlength ? (parameter) string[] argsargs[(local variable) ulong ii + 1] : "";
switch ((parameter) string[] argsargs[(local variable) ulong ii])
{
case "--shape": (local variable) string[] shapesshapes = (local variable) string vv.string[] std.array.split!(string, string)(string range, string sep) pure nothrow @safesplit(","); ++(local variable) ulong ii; break;
case "--n": (local variable) int[] nsns = (local variable) string vv.string[] std.array.split!(string, string)(string range, string sep) pure nothrow @safesplit(",").int[] std.conv.to!(int[]).to!(string[])(string[] __param_0) pure @safeThe to template converts a value from one type to another.
The source type is deduced and the target type must be specified, for example the
expression to`!int(42.0)` converts the number 42 from
`double` to `int`. The conversion is "safe", i.e.,
it checks for overflow; to!int(4.2e10) would throw the
ConvOverflowException exception. Overflow checks are only
inserted when necessary, e.g., ``to!double(42) does not do
any checking because any int fits in a double.
Conversions from string to numeric types differ from the C equivalents
atoi() and atol() by checking for overflow and not allowing whitespace.
For conversion of strings to signed types, the grammar recognized is:
Integer:
Sign UnsignedInteger
UnsignedInteger
Sign:
+
-
For conversion to unsigned types, the grammar recognized is:
UnsignedInteger:
DecimalDigit
DecimalDigit UnsignedInteger
Examples
Converting a value to its own type (useful mostly for generic code)
simply returns its argument.
int a = 42;
int b = to!int(a);
double c = to!double(3.14); // c is double with value 3.14
Converting among numeric types is a safe way to cast them around.
Conversions from floating-point types to integral types allow loss of
precision (the fractional part of a floating-point number). The
conversion is truncating towards zero, the same way a cast would
truncate. (To round a floating point value when casting to an
integral, use roundTo.)
import std.exception : assertThrown;
int a = 420;
assert(to!long(a) == a);
assertThrown!ConvOverflowException(to!byte(a));
assert(to!int(4.2e6) == 4200000);
assertThrown!ConvOverflowException(to!uint(-3.14));
assert(to!uint(3.14) == 3);
assert(to!uint(3.99) == 3);
assert(to!int(-3.99) == -3);
When converting strings to numeric types, note that D hexadecimal and binary
literals are not handled. Neither the prefixes that indicate the base, nor the
horizontal bar used to separate groups of digits are recognized. This also
applies to the suffixes that indicate the type.
To work around this, you can specify a radix for conversions involving numbers.
auto str = to!string(42, 16);
assert(str == "2A");
auto i = to!int(str, 16);
assert(i == 42);
Conversions from integral types to floating-point types always
succeed, but might lose accuracy. The largest integers with a
predecessor representable in floating-point format are 2^24-1 for
float, 2^53-1 for double, and 2^64-1 for real (when
real is 80-bit, e.g. on Intel machines).
// 2^24 - 1, largest proper integer representable as float
int a = 16_777_215;
assert(to!int(to!float(a)) == a);
assert(to!int(to!float(-a)) == -a);
Conversion from string types to char types enforces the input
to consist of a single code point, and said code point must
fit in the target type. Otherwise, ConvException is thrown.
import std.exception : assertThrown;
assert(to!char("a") == 'a');
assertThrown(to!char("ñ")); // 'ñ' does not fit into a char
assert(to!wchar("ñ") == 'ñ');
assertThrown(to!wchar("😃")); // '😃' does not fit into a wchar
assert(to!dchar("😃") == '😃');
// Using wstring or dstring as source type does not affect the result
assert(to!char("a"w) == 'a');
assert(to!char("a"d) == 'a');
// Two code points cannot be converted to a single one
assertThrown(to!char("ab"));
Converting an array to another array type works by converting each
element in turn. Associative arrays can be converted to associative
arrays as long as keys and values can in turn be converted.
import std.string : split;
int[] a = [1, 2, 3];
auto b = to!(float[])(a);
assert(b == [1.0f, 2, 3]);
string str = "1 2 3 4 5 6";
auto numbers = to!(double[])(split(str));
assert(numbers == [1.0, 2, 3, 4, 5, 6]);
int[string] c;
c["a"] = 1;
c["b"] = 2;
auto d = to!(double[wstring])(c);
assert(d["a"w] == 1 && d["b"w] == 2);
Conversions operate transitively, meaning that they work on arrays and
associative arrays of any complexity.
This conversion works because to`!short` applies to an `int`, to!wstring
applies to a string, to`!string` applies to a `double`, and
to!(double[]) applies to an int[]. The conversion might throw an
exception because ``to!short might fail the range check.
int[string][double[int[]]] a;
auto b = to!(short[wstring][string[double[]]])(a);
Object-to-object conversions by dynamic casting throw exception when
the source is non-null and the target is null.
import std.exception : assertThrown;
// Testing object conversions
class A {}
class B : A {}
class C : A {}
A a1 = new A, a2 = new B, a3 = new C;
assert(to!B(a2) is a2);
assert(to!C(a3) is a3);
assertThrown!ConvException(to!B(a3));
Stringize conversion from all types is supported.
String to string conversion works for any two string types having
(char, wchar, dchar) character widths and any
combination of qualifiers (mutable, const, or immutable).
Converts array (other than strings) to string.
Each element is converted by calling ``to!T.
Associative array to string conversion.
Each element is converted by calling ``to!T.
Object to string conversion calls toString against the object or
returns "null" if the object is null.
Struct to string conversion calls toString against the struct if
it is defined.
For structs that do not define toString, the conversion to string
produces the list of fields.
Enumerated types are converted to strings as their symbolic names.
Boolean values are converted to "true" or "false".
char, wchar, dchar to a string type.
Unsigned or signed integers to strings.
[special case]
: Convert integral value to string in radix radix.
radix must be a value from 2 to 36.
value is treated as a signed value only if radix is 10.
The characters A through Z are used to represent values 10 through 36
and their case is determined by the letterCase parameter.
All floating point types to all string types.
Pointer to string conversions convert the pointer to a size_t value.
If pointer is char*, treat it as C-style strings.
In that case, this function is @system.
See formatValue on how toString should be defined.
// Conversion representing dynamic/static array with string
long[] a = [ 1, 3, 5 ];
assert(to!string(a) == "[1, 3, 5]");
// Conversion representing associative array with string
int[string] associativeArray = ["0":1, "1":2];
assert(to!string(associativeArray) == `["0":1, "1":2]` ||
to!string(associativeArray) == `["1":2, "0":1]`);
// char* to string conversion
assert(to!string(cast(char*) null) == "");
assert(to!string("foo\0".ptr) == "foo");
// Conversion reinterpreting void array to string
auto w = "abcx"w;
const(void)[] b = w;
assert(b.length == 8);
auto c = to!(wchar[])(b);
assert(c == "abcx");
Strings can be converted to enum types. The enum member with the same name as the
input string is returned. The comparison is case-sensitive.
A ConvException is thrown if the enum does not have the specified member.
import std.exception : assertThrown;
enum E { a, b, c }
assert(to!E("a") == E.a);
assert(to!E("b") == E.b);
assertThrown!ConvException(to!E("A"));
to!(int[]); ++(local variable) ulong ii; break;
case "--fat": (local variable) int[] fatsfats = (local variable) string vv.string[] std.array.split!(string, string)(string range, string sep) pure nothrow @safesplit(",").int[] std.conv.to!(int[]).to!(string[])(string[] __param_0) pure @safeThe to template converts a value from one type to another.
The source type is deduced and the target type must be specified, for example the
expression to`!int(42.0)` converts the number 42 from
`double` to `int`. The conversion is "safe", i.e.,
it checks for overflow; to!int(4.2e10) would throw the
ConvOverflowException exception. Overflow checks are only
inserted when necessary, e.g., ``to!double(42) does not do
any checking because any int fits in a double.
Conversions from string to numeric types differ from the C equivalents
atoi() and atol() by checking for overflow and not allowing whitespace.
For conversion of strings to signed types, the grammar recognized is:
Integer:
Sign UnsignedInteger
UnsignedInteger
Sign:
+
-
For conversion to unsigned types, the grammar recognized is:
UnsignedInteger:
DecimalDigit
DecimalDigit UnsignedInteger
Examples
Converting a value to its own type (useful mostly for generic code)
simply returns its argument.
int a = 42;
int b = to!int(a);
double c = to!double(3.14); // c is double with value 3.14
Converting among numeric types is a safe way to cast them around.
Conversions from floating-point types to integral types allow loss of
precision (the fractional part of a floating-point number). The
conversion is truncating towards zero, the same way a cast would
truncate. (To round a floating point value when casting to an
integral, use roundTo.)
import std.exception : assertThrown;
int a = 420;
assert(to!long(a) == a);
assertThrown!ConvOverflowException(to!byte(a));
assert(to!int(4.2e6) == 4200000);
assertThrown!ConvOverflowException(to!uint(-3.14));
assert(to!uint(3.14) == 3);
assert(to!uint(3.99) == 3);
assert(to!int(-3.99) == -3);
When converting strings to numeric types, note that D hexadecimal and binary
literals are not handled. Neither the prefixes that indicate the base, nor the
horizontal bar used to separate groups of digits are recognized. This also
applies to the suffixes that indicate the type.
To work around this, you can specify a radix for conversions involving numbers.
auto str = to!string(42, 16);
assert(str == "2A");
auto i = to!int(str, 16);
assert(i == 42);
Conversions from integral types to floating-point types always
succeed, but might lose accuracy. The largest integers with a
predecessor representable in floating-point format are 2^24-1 for
float, 2^53-1 for double, and 2^64-1 for real (when
real is 80-bit, e.g. on Intel machines).
// 2^24 - 1, largest proper integer representable as float
int a = 16_777_215;
assert(to!int(to!float(a)) == a);
assert(to!int(to!float(-a)) == -a);
Conversion from string types to char types enforces the input
to consist of a single code point, and said code point must
fit in the target type. Otherwise, ConvException is thrown.
import std.exception : assertThrown;
assert(to!char("a") == 'a');
assertThrown(to!char("ñ")); // 'ñ' does not fit into a char
assert(to!wchar("ñ") == 'ñ');
assertThrown(to!wchar("😃")); // '😃' does not fit into a wchar
assert(to!dchar("😃") == '😃');
// Using wstring or dstring as source type does not affect the result
assert(to!char("a"w) == 'a');
assert(to!char("a"d) == 'a');
// Two code points cannot be converted to a single one
assertThrown(to!char("ab"));
Converting an array to another array type works by converting each
element in turn. Associative arrays can be converted to associative
arrays as long as keys and values can in turn be converted.
import std.string : split;
int[] a = [1, 2, 3];
auto b = to!(float[])(a);
assert(b == [1.0f, 2, 3]);
string str = "1 2 3 4 5 6";
auto numbers = to!(double[])(split(str));
assert(numbers == [1.0, 2, 3, 4, 5, 6]);
int[string] c;
c["a"] = 1;
c["b"] = 2;
auto d = to!(double[wstring])(c);
assert(d["a"w] == 1 && d["b"w] == 2);
Conversions operate transitively, meaning that they work on arrays and
associative arrays of any complexity.
This conversion works because to`!short` applies to an `int`, to!wstring
applies to a string, to`!string` applies to a `double`, and
to!(double[]) applies to an int[]. The conversion might throw an
exception because ``to!short might fail the range check.
int[string][double[int[]]] a;
auto b = to!(short[wstring][string[double[]]])(a);
Object-to-object conversions by dynamic casting throw exception when
the source is non-null and the target is null.
import std.exception : assertThrown;
// Testing object conversions
class A {}
class B : A {}
class C : A {}
A a1 = new A, a2 = new B, a3 = new C;
assert(to!B(a2) is a2);
assert(to!C(a3) is a3);
assertThrown!ConvException(to!B(a3));
Stringize conversion from all types is supported.
String to string conversion works for any two string types having
(char, wchar, dchar) character widths and any
combination of qualifiers (mutable, const, or immutable).
Converts array (other than strings) to string.
Each element is converted by calling ``to!T.
Associative array to string conversion.
Each element is converted by calling ``to!T.
Object to string conversion calls toString against the object or
returns "null" if the object is null.
Struct to string conversion calls toString against the struct if
it is defined.
For structs that do not define toString, the conversion to string
produces the list of fields.
Enumerated types are converted to strings as their symbolic names.
Boolean values are converted to "true" or "false".
char, wchar, dchar to a string type.
Unsigned or signed integers to strings.
[special case]
: Convert integral value to string in radix radix.
radix must be a value from 2 to 36.
value is treated as a signed value only if radix is 10.
The characters A through Z are used to represent values 10 through 36
and their case is determined by the letterCase parameter.
All floating point types to all string types.
Pointer to string conversions convert the pointer to a size_t value.
If pointer is char*, treat it as C-style strings.
In that case, this function is @system.
See formatValue on how toString should be defined.
// Conversion representing dynamic/static array with string
long[] a = [ 1, 3, 5 ];
assert(to!string(a) == "[1, 3, 5]");
// Conversion representing associative array with string
int[string] associativeArray = ["0":1, "1":2];
assert(to!string(associativeArray) == `["0":1, "1":2]` ||
to!string(associativeArray) == `["1":2, "0":1]`);
// char* to string conversion
assert(to!string(cast(char*) null) == "");
assert(to!string("foo\0".ptr) == "foo");
// Conversion reinterpreting void array to string
auto w = "abcx"w;
const(void)[] b = w;
assert(b.length == 8);
auto c = to!(wchar[])(b);
assert(c == "abcx");
Strings can be converted to enum types. The enum member with the same name as the
input string is returned. The comparison is case-sensitive.
A ConvException is thrown if the enum does not have the specified member.
import std.exception : assertThrown;
enum E { a, b, c }
assert(to!E("a") == E.a);
assert(to!E("b") == E.b);
assertThrown!ConvException(to!E("A"));
to!(int[]); ++(local variable) ulong ii; break;
case "--variant": (local variable) string[] onlyonly = (local variable) string vv.string[] std.array.split!(string, string)(string range, string sep) pure nothrow @safesplit(","); ++(local variable) ulong ii; break;
case "--reps": (thread local global) int fitbench.repsreps = (local variable) string vv.int std.conv.to!int.to!string(string __param_0) pure @safeThe to template converts a value from one type to another.
The source type is deduced and the target type must be specified, for example the
expression to`!int(42.0)` converts the number 42 from
`double` to `int`. The conversion is "safe", i.e.,
it checks for overflow; to!int(4.2e10) would throw the
ConvOverflowException exception. Overflow checks are only
inserted when necessary, e.g., ``to!double(42) does not do
any checking because any int fits in a double.
Conversions from string to numeric types differ from the C equivalents
atoi() and atol() by checking for overflow and not allowing whitespace.
For conversion of strings to signed types, the grammar recognized is:
Integer:
Sign UnsignedInteger
UnsignedInteger
Sign:
+
-
For conversion to unsigned types, the grammar recognized is:
UnsignedInteger:
DecimalDigit
DecimalDigit UnsignedInteger
Examples
Converting a value to its own type (useful mostly for generic code)
simply returns its argument.
int a = 42;
int b = to!int(a);
double c = to!double(3.14); // c is double with value 3.14
Converting among numeric types is a safe way to cast them around.
Conversions from floating-point types to integral types allow loss of
precision (the fractional part of a floating-point number). The
conversion is truncating towards zero, the same way a cast would
truncate. (To round a floating point value when casting to an
integral, use roundTo.)
import std.exception : assertThrown;
int a = 420;
assert(to!long(a) == a);
assertThrown!ConvOverflowException(to!byte(a));
assert(to!int(4.2e6) == 4200000);
assertThrown!ConvOverflowException(to!uint(-3.14));
assert(to!uint(3.14) == 3);
assert(to!uint(3.99) == 3);
assert(to!int(-3.99) == -3);
When converting strings to numeric types, note that D hexadecimal and binary
literals are not handled. Neither the prefixes that indicate the base, nor the
horizontal bar used to separate groups of digits are recognized. This also
applies to the suffixes that indicate the type.
To work around this, you can specify a radix for conversions involving numbers.
auto str = to!string(42, 16);
assert(str == "2A");
auto i = to!int(str, 16);
assert(i == 42);
Conversions from integral types to floating-point types always
succeed, but might lose accuracy. The largest integers with a
predecessor representable in floating-point format are 2^24-1 for
float, 2^53-1 for double, and 2^64-1 for real (when
real is 80-bit, e.g. on Intel machines).
// 2^24 - 1, largest proper integer representable as float
int a = 16_777_215;
assert(to!int(to!float(a)) == a);
assert(to!int(to!float(-a)) == -a);
Conversion from string types to char types enforces the input
to consist of a single code point, and said code point must
fit in the target type. Otherwise, ConvException is thrown.
import std.exception : assertThrown;
assert(to!char("a") == 'a');
assertThrown(to!char("ñ")); // 'ñ' does not fit into a char
assert(to!wchar("ñ") == 'ñ');
assertThrown(to!wchar("😃")); // '😃' does not fit into a wchar
assert(to!dchar("😃") == '😃');
// Using wstring or dstring as source type does not affect the result
assert(to!char("a"w) == 'a');
assert(to!char("a"d) == 'a');
// Two code points cannot be converted to a single one
assertThrown(to!char("ab"));
Converting an array to another array type works by converting each
element in turn. Associative arrays can be converted to associative
arrays as long as keys and values can in turn be converted.
import std.string : split;
int[] a = [1, 2, 3];
auto b = to!(float[])(a);
assert(b == [1.0f, 2, 3]);
string str = "1 2 3 4 5 6";
auto numbers = to!(double[])(split(str));
assert(numbers == [1.0, 2, 3, 4, 5, 6]);
int[string] c;
c["a"] = 1;
c["b"] = 2;
auto d = to!(double[wstring])(c);
assert(d["a"w] == 1 && d["b"w] == 2);
Conversions operate transitively, meaning that they work on arrays and
associative arrays of any complexity.
This conversion works because to`!short` applies to an `int`, to!wstring
applies to a string, to`!string` applies to a `double`, and
to!(double[]) applies to an int[]. The conversion might throw an
exception because ``to!short might fail the range check.
int[string][double[int[]]] a;
auto b = to!(short[wstring][string[double[]]])(a);
Object-to-object conversions by dynamic casting throw exception when
the source is non-null and the target is null.
import std.exception : assertThrown;
// Testing object conversions
class A {}
class B : A {}
class C : A {}
A a1 = new A, a2 = new B, a3 = new C;
assert(to!B(a2) is a2);
assert(to!C(a3) is a3);
assertThrown!ConvException(to!B(a3));
Stringize conversion from all types is supported.
String to string conversion works for any two string types having
(char, wchar, dchar) character widths and any
combination of qualifiers (mutable, const, or immutable).
Converts array (other than strings) to string.
Each element is converted by calling ``to!T.
Associative array to string conversion.
Each element is converted by calling ``to!T.
Object to string conversion calls toString against the object or
returns "null" if the object is null.
Struct to string conversion calls toString against the struct if
it is defined.
For structs that do not define toString, the conversion to string
produces the list of fields.
Enumerated types are converted to strings as their symbolic names.
Boolean values are converted to "true" or "false".
char, wchar, dchar to a string type.
Unsigned or signed integers to strings.
[special case]
: Convert integral value to string in radix radix.
radix must be a value from 2 to 36.
value is treated as a signed value only if radix is 10.
The characters A through Z are used to represent values 10 through 36
and their case is determined by the letterCase parameter.
All floating point types to all string types.
Pointer to string conversions convert the pointer to a size_t value.
If pointer is char*, treat it as C-style strings.
In that case, this function is @system.
See formatValue on how toString should be defined.
// Conversion representing dynamic/static array with string
long[] a = [ 1, 3, 5 ];
assert(to!string(a) == "[1, 3, 5]");
// Conversion representing associative array with string
int[string] associativeArray = ["0":1, "1":2];
assert(to!string(associativeArray) == `["0":1, "1":2]` ||
to!string(associativeArray) == `["1":2, "0":1]`);
// char* to string conversion
assert(to!string(cast(char*) null) == "");
assert(to!string("foo\0".ptr) == "foo");
// Conversion reinterpreting void array to string
auto w = "abcx"w;
const(void)[] b = w;
assert(b.length == 8);
auto c = to!(wchar[])(b);
assert(c == "abcx");
Strings can be converted to enum types. The enum member with the same name as the
input string is returned. The comparison is case-sensitive.
A ConvException is thrown if the enum does not have the specified member.
import std.exception : assertThrown;
enum E { a, b, c }
assert(to!E("a") == E.a);
assert(to!E("b") == E.b);
assertThrown!ConvException(to!E("A"));
to!int; ++(local variable) ulong ii; break;
default: stderr.std.stdio.File std.stdio.makeGlobal!"core.stdc.stdio.stderr"() nothrow @nogc @property ref @systemwriteln("unknown arg ", (parameter) string[] argsargs[(local variable) ulong ii]); noreturn core.stdc.stdlib.exit(int status) nothrow @nogcexit(2);
}
}
(thread local global) fitbench.Perf fitbench.perfperf.void fitbench.Perf.open()open();
stderr.std.stdio.File std.stdio.makeGlobal!"core.stdc.stdio.stderr"() nothrow @nogc @property ref @systemwritefln("perf counters open: %s", (thread local global) fitbench.Perf fitbench.perfperf.(field) int fitbench.Perf.nOpennOpen);
auto (local variable) char* poolpool = cast(char*) void* core.stdc.stdlib.malloc(ulong size) nothrow @nogcmalloc((constant) int fitbench.poolLen = 65536poolLen);
foreach ((local variable) int kk; 0 .. (constant) int fitbench.poolLen = 65536poolLen)
(local variable) char* poolpool[(local variable) int kk] = cast(char)('a' + (local variable) int kk % 26);
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("| shape | N | fat B | variant | total ns/node | build | pass | aux | cyc | ins | L1D miss | L2 miss | DRAM fill | pass cyc | pass L1D | pass DRAM | checksum |");
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|");
foreach ((parameter) string shapeshape; (local variable) string[] shapesshapes)
foreach ((parameter) int n0n0; (local variable) int[] nsns)
{
(struct) fitbench.GenGen (local variable) fitbench.Gen gg = (local variable) string shapeshape == "list" ? fitbench.Gen fitbench.genList(int n)root col > panel col > (header row(label,label), scroll col > rows(label, label*, label))
genList((local variable) int n0n0) : fitbench.Gen fitbench.genPanels(int n)Balanced-ish nested panels: fan-out mostly 2..8, sometimes a 50..1000 list,
depth <= 12, exactly n nodes.
genPanels((local variable) int n0n0);
int (local variable) int nn = (local variable) fitbench.Gen gg.(field) int fitbench.Gen.nodesnodes;
stderr.std.stdio.File std.stdio.makeGlobal!"core.stdc.stdio.stderr"() nothrow @nogc @property ref @systemwritefln("# %s N=%s depth=%s maxFan=%s events=%s", (local variable) string shapeshape, (local variable) int nn, (local variable) fitbench.Gen gg.(field) int fitbench.Gen.maxDepthmaxDepth, (local variable) fitbench.Gen gg.(field) int fitbench.Gen.maxFanmaxFan, (local variable) fitbench.Gen gg.(field) fitbench.Ev[] fitbench.Gen.evsevs.(field) ulong fitbench.Ev[].lengthlength);
foreach ((parameter) int fatfat; (local variable) int[] fatsfats)
{
(struct) fitbench.ResultResult[] (local variable) fitbench.Result[] rsrs;
if ((local variable) int fatfat == 64)
(local variable) fitbench.Result[] rsrs = fitbench.Result[] fitbench.runConfig!64LU(const(fitbench.Ev)[] evs, const(char)* pool, int n, string[] only) @systemrunConfig!64((local variable) fitbench.Gen gg.(field) fitbench.Ev[] fitbench.Gen.evsevs, (local variable) char* poolpool, (local variable) int nn, (local variable) string[] onlyonly);
else if ((local variable) int fatfat == 128)
(local variable) fitbench.Result[] rsrs = fitbench.Result[] fitbench.runConfig!128LU(const(fitbench.Ev)[] evs, const(char)* pool, int n, string[] only) @systemrunConfig!128((local variable) fitbench.Gen gg.(field) fitbench.Ev[] fitbench.Gen.evsevs, (local variable) char* poolpool, (local variable) int nn, (local variable) string[] onlyonly);
else if ((local variable) int fatfat == 328)
(local variable) fitbench.Result[] rsrs = fitbench.Result[] fitbench.runConfig!328LU(const(fitbench.Ev)[] evs, const(char)* pool, int n, string[] only) @systemrunConfig!328((local variable) fitbench.Gen gg.(field) fitbench.Ev[] fitbench.Gen.evsevs, (local variable) char* poolpool, (local variable) int nn, (local variable) string[] onlyonly);
else
{
stderr.std.stdio.File std.stdio.makeGlobal!"core.stdc.stdio.stderr"() nothrow @nogc @property ref @systemwriteln("fat must be 64,128,328");
noreturn core.stdc.stdlib.exit(int status) nothrow @nogcexit(2);
}
ulong (local variable) ulong ref_ref_ = 0;
foreach ((parameter) fitbench.Result rr; (local variable) fitbench.Result[] rsrs)
{
(alias) object.string = stringstring (local variable) string okok;
if ((local variable) fitbench.Result rr.(field) string fitbench.Result.variantvariant.(field) ulong string.lengthlength >= 4 && (local variable) fitbench.Result rr.(field) string fitbench.Result.variantvariant[0 .. 4] == "rest")
(local variable) string okok = (local variable) fitbench.Result[] rsrs[$ - 1].(field) ulong fitbench.Result.checksumchecksum == (local variable) fitbench.Result rr.(field) ulong fitbench.Result.checksumchecksum ? "ok" : "MISMATCH";
else
{
if ((local variable) ulong ref_ref_ == 0)
(local variable) ulong ref_ref_ = (local variable) fitbench.Result rr.(field) ulong fitbench.Result.checksumchecksum;
(local variable) string okok = (local variable) fitbench.Result rr.(field) ulong fitbench.Result.checksumchecksum == (local variable) ulong ref_ref_ ? "ok" : "MISMATCH";
}
void std.stdio.writefln!(char, string, int, int, string, double, double, double, double, double, double, double, double, double, double, double, double, string, ulong)(in char[] fmt, string __param_1, int __param_2, int __param_3, string __param_4, double __param_5, double __param_6, double __param_7, double __param_8, double __param_9, double __param_10, double __param_11, double __param_12, double __param_13, double __param_14, double __param_15, double __param_16, string __param_17, ulong __param_18) @safeEquivalent to writef(fmt, args, '\n').
writefln("| %s | %s | %s | %s | %.2f | %.2f | %.2f | %.2f | %.1f | %.1f | %.2f | %.3f | %.3f | %.1f | %.2f | %.3f | %s %016x |",
(local variable) string shapeshape, (local variable) int nn, (local variable) int fatfat, (local variable) fitbench.Result rr.(field) string fitbench.Result.variantvariant, (local variable) fitbench.Result rr.(field) double fitbench.Result.totaltotal, (local variable) fitbench.Result rr.(field) double fitbench.Result.buildbuild, (local variable) fitbench.Result rr.(field) double fitbench.Result.passpass, (local variable) fitbench.Result rr.(field) double fitbench.Result.auxaux,
(local variable) fitbench.Result rr.(field) double[5] fitbench.Result.ctrctr[0], (local variable) fitbench.Result rr.(field) double[5] fitbench.Result.ctrctr[1], (local variable) fitbench.Result rr.(field) double[5] fitbench.Result.ctrctr[2], (local variable) fitbench.Result rr.(field) double[5] fitbench.Result.ctrctr[3], (local variable) fitbench.Result rr.(field) double[5] fitbench.Result.ctrctr[4],
(local variable) fitbench.Result rr.(field) double[5] fitbench.Result.passCtrpassCtr[0], (local variable) fitbench.Result rr.(field) double[5] fitbench.Result.passCtrpassCtr[2], (local variable) fitbench.Result rr.(field) double[5] fitbench.Result.passCtrpassCtr[4], (local variable) string okok, (local variable) fitbench.Result rr.(field) ulong fitbench.Result.checksumchecksum);
stdout.std.stdio.File std.stdio.makeGlobal!"core.stdc.stdio.stdout"() nothrow @nogc @property ref @systemflush();
}
}
}
if ((thread local global) bool fitbench.multiplexedmultiplexed)
stderr.std.stdio.File std.stdio.makeGlobal!"core.stdc.stdio.stderr"() nothrow @nogc @property ref @systemwriteln("WARNING: counters were multiplexed");
}