fitbench.dhover×2432all
#!/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) fitbench

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.

fitbench
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.stdlib

D header file for C99.

pubs.opengroup.org/onlinepubs/009695399/basedefs/stdlib.h.html, stdlib.h

Source

core/stdc/stdlib.d

@copyrightCopyright Sean Kelly 2005 - 2014.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly@standardsISO/IEC 9899:1999 (E)
stdlib
:
(alias) fitbench.malloc = void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
,
(alias) fitbench.free = void core.stdc.stdlib.free(void* ptr) nothrow @nogc
free
,
(alias) fitbench.exit = noreturn core.stdc.stdlib.exit(int status) nothrow @nogc
exit
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.string

D header file for C99.

pubs.opengroup.org/onlinepubs/009695399/basedefs/string.h.html, string.h

Source

core/stdc/string.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly@standardsISO/IEC 9899:1999 (E)
string
:
(alias) fitbench.memset = void* core.stdc.string.memset(return scope void* s, int c, ulong n) pure nothrow @nogc
memset
;
import
(package) core
core
.
(module) core.time

Module 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

@copyrightCopyright 2010 - 2012@licenseBoost License 1.0.@authorsJonathan M Davis and Kato Shoichi
time
:
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
;
import
(package) std
std
.
(module) std.algorithm

This 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

@copyrightAndrei Alexandrescu 2008-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu
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.

@paramless The predicate to sort by.@paramss The swapping strategy to use.@paramr The range to sort.@returnsThe initial range wrapped as a SortedRange with the predicate binaryFun!less.@see

assumeSorted

SortedRange

SwapStrategy

binaryFun

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.

@paramargs The values to select the maximum from. At least two arguments must be passed, and they must be comparable with <.@returnsThe maximum of the passed-in values. The type of the returned value is the type among the passed arguments that is able to store the largest value. If at least one of the arguments is NaN, the result is an unspecified value. See maxElement for examples on how to cope with NaNs.@seemaxElement
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.

@paramargs The values to select the minimum from. At least two arguments must be passed, and they must be comparable with <.@returnsThe minimum of the passed-in values. The type of the returned value is the type among the passed arguments that is able to store the smallest value. If at least one of the arguments is NaN, the result is an unspecified value. See minElement for examples on how to cope with NaNs.@seeminElement
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.

@seeamong for checking a value against multiple arguments.
canFind
;
import
(package) std
std
.
(module) std.conv

A 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

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Shin Fujishiro, Adam D. Ruppe, Kenji Hara
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) std
std
.
(module) std.math

Contains 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

@copyrightCopyright The D Language Foundation 2000 - 2011. D implementations of tan, atan, atan2, exp, expm1, exp2, log, log10, log1p, log2, floor, ceil and lrint functions are based on the CEPHES math library, which is Copyright (C) 2001 Stephen L. Moshier <steve@moshier.net> and are incorporated herein by permission of the author. The author reserves the right to distribute this material elsewhere under different copying permissions. These modifications are distributed here under the following terms:@licenseBoost License 1.0.@authorsWalter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw and David Nadlinger
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 @trusted

Returns the value of x rounded upward to the next integer (toward positive infinity).

ceil
;
import
(package) std
std
.
(module) std.random

Facilities 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]));
@copyrightCopyright Andrei Alexandrescu 2008 - 2009, Joseph Rushton Wakeling 2012.@licenseBoost License 1.0.@authorsAndrei Alexandrescu Masahiro Nakagawa (Xorshift random generator) Joseph Rushton Wakeling (Algorithm D for random sampling) Ilya Yaroshenko (Mersenne Twister implementation, adapted from mir-random)
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.

@parama lower bound of the uniform distribution@paramb upper bound of the uniform distribution@paramurng (optional) random number generator to use; if not specified, defaults to rndGen@returnsA single random variate drawn from the uniform distribution between a and b, whose type is the common type of these parameters
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.

@paramrng (optional) random number generator to use; if not specified, defaults to rndGen@returnsFloating-point random variate of type T drawn from the uniform distribution across the half-open interval [0, 1).
uniform01
;
import
(package) std
std
.
(module) std.stdio
Category 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:

  1. The lowest layer is the operating system layer. The two main schemes are Windows and Posix.

  2. C's stdio.h which unifies the two operating system schemes.

  3. std.stdio, this module, unifies the various stdio.h implementations into a high level package for D programs.

Source

std/stdio.d

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Alex Rønne Petersen
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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
, stdout, stderr;
import
(package) std
std
.
(module) std.string

String 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

@seestd.algorithm and std.range for generic range algorithms , std.ascii for functions that work with ASCII strings , std.uni for functions that work with unicode strings@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis
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.

@params the string to split by word if no separator is given@paramrange the range to split@paramsep a value of the same type as the elements of range or another@paramisTerminator a predicate that splits the range when it returns true.@returnsAn array containing the divided parts of range (or the words of s).@see

splitter for a lazy version without allocating memory.

splitter for a version that splits using a regular expression defined separator.

split
;
version (
LDC
LDC
) import ldc.attributes : fastmath;
else struct
(struct) fitbench.fastmath
fastmath
{}
// --------------------------------------------------------------------------- // Event stream: what "user UI code" does, replayed identically by every variant // --------------------------------------------------------------------------- enum : ubyte {
(enum value) fitbench.OpOpen = cast(ubyte)0u
OpOpen
= 0,
(enum value) fitbench.OpLabel = cast(ubyte)1u
OpLabel
= 1,
(enum value) fitbench.OpClose = cast(ubyte)2u
OpClose
= 2 }
enum : ubyte {
(enum value) fitbench.GrowX = cast(ubyte)1u
GrowX
= 1,
(enum value) fitbench.GrowY = cast(ubyte)2u
GrowY
= 2 }
struct
(struct) fitbench.Ev
Ev
{ ubyte
(field) ubyte fitbench.Ev.op
op
,
(field) ubyte fitbench.Ev.axis
axis
,
(field) ubyte fitbench.Ev.grow
grow
,
(field) ubyte fitbench.Ev.pad
pad
; // pad: per side
ushort
(field) ushort fitbench.Ev.gap
gap
,
(field) ushort fitbench.Ev.textLen
textLen
;
uint
(field) uint fitbench.Ev.textOff
textOff
;
} static assert(
(struct) fitbench.Ev
Ev
.
(constant) ulong fitbench.Ev.sizeof = 12LU
sizeof
== 12);
enum
(constant) int fitbench.poolLen = 65536
poolLen
= 1 << 16;
enum
(constant) float fitbench.glyphW = 8.0F
glyphW
= 8.0f,
(constant) float fitbench.lineH = 16.0F
lineH
= 16.0f;
struct
(struct) fitbench.Gen
Gen
{
(struct) fitbench.Ev
Ev
[]
(field) fitbench.Ev[] fitbench.Gen.evs
evs
;
(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.rng
rng
;
int
(field) int fitbench.Gen.nodes
nodes
;
int
(field) int fitbench.Gen.maxDepth
maxDepth
;
int
(field) int fitbench.Gen.depth
depth
;
int
(field) int fitbench.Gen.maxFan
maxFan
;
void
void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)
open
(ubyte
(parameter) ubyte axis
axis
, ubyte
(parameter) ubyte grow
grow
, ubyte
(parameter) ubyte pad
pad
, ushort
(parameter) ushort gap
gap
)
{
(field) fitbench.Ev[] fitbench.Gen.evs
evs
~=
(struct) fitbench.Ev
Ev
(
(enum value) fitbench.OpOpen = cast(ubyte)0u
OpOpen
,
(parameter) ubyte axis
axis
,
(parameter) ubyte grow
grow
,
(parameter) ubyte pad
pad
,
(parameter) ushort gap
gap
, 0, 0);
++
(field) int fitbench.Gen.nodes
nodes
;
++
(field) int fitbench.Gen.depth
depth
;
(field) int fitbench.Gen.maxDepth
maxDepth
=
int std.algorithm.comparison.max!(int, int)(int a, int b) pure nothrow @nogc @safe

Iterates 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);
@paramargs The values to select the maximum from. At least two arguments must be passed, and they must be comparable with <.@returnsThe maximum of the passed-in values. The type of the returned value is the type among the passed arguments that is able to store the largest value. If at least one of the arguments is NaN, the result is an unspecified value. See maxElement for examples on how to cope with NaNs.@seemaxElement
max
(
(field) int fitbench.Gen.maxDepth
maxDepth
,
(field) int fitbench.Gen.depth
depth
);
} void
void fitbench.Gen.close()
close
()
{
(field) fitbench.Ev[] fitbench.Gen.evs
evs
~=
(struct) fitbench.Ev
Ev
(
(enum value) fitbench.OpClose = cast(ubyte)2u
OpClose
);
--
(field) int fitbench.Gen.depth
depth
;
} void
void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)
label
(ubyte
(parameter) ubyte grow
grow
= 0)
{ ushort
(local variable) ushort len
len
= 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 @safe

Create 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.rng
rng
);
(field) fitbench.Ev[] fitbench.Gen.evs
evs
~=
(struct) fitbench.Ev
Ev
(
(enum value) fitbench.OpLabel = cast(ubyte)1u
OpLabel
, 0,
(parameter) ubyte grow
grow
, 0, 0,
(local variable) ushort len
len
,
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 @safe

Create 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 = 65536
poolLen
- 32),
(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rng
rng
));
++
(field) int fitbench.Gen.nodes
nodes
;
(field) int fitbench.Gen.maxDepth
maxDepth
=
int std.algorithm.comparison.max!(int, int)(int a, int b) pure nothrow @nogc @safe

Iterates 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);
@paramargs The values to select the maximum from. At least two arguments must be passed, and they must be comparable with <.@returnsThe maximum of the passed-in values. The type of the returned value is the type among the passed arguments that is able to store the largest value. If at least one of the arguments is NaN, the result is an unspecified value. See maxElement for examples on how to cope with NaNs.@seemaxElement
max
(
(field) int fitbench.Gen.maxDepth
maxDepth
,
(field) int fitbench.Gen.depth
depth
+ 1);
} } /// root col > panel col > (header row(label,label), scroll col > rows(label, label*, label))
(struct) fitbench.Gen
Gen
fitbench.Gen fitbench.genList(int n)

root col > panel col > (header row(label,label), scroll col > rows(label, label*, label))

genList
(int
(parameter) int n
n
)
{
(struct) fitbench.Gen
Gen
(local variable) fitbench.Gen g
g
;
(local variable) fitbench.Gen g
g
.
(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rng
rng
=
(struct) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u)
Random
(42);
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)
open
(1, 0, 0, 0); // root column
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)
open
(1,
(enum value) fitbench.GrowX = cast(ubyte)1u
GrowX
|
(enum value) fitbench.GrowY = cast(ubyte)2u
GrowY
, 8, 4); // panel
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)
open
(0,
(enum value) fitbench.GrowX = cast(ubyte)1u
GrowX
, 4, 8); // header
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)
label
();
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)
label
(
(enum value) fitbench.GrowX = cast(ubyte)1u
GrowX
);
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.close()
close
();
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)
open
(1,
(enum value) fitbench.GrowX = cast(ubyte)1u
GrowX
|
(enum value) fitbench.GrowY = cast(ubyte)2u
GrowY
, 0, 2); // scroll column
int
(local variable) int rows
rows
= (
(parameter) int n
n
- 6) / 4;
(local variable) fitbench.Gen g
g
.
(field) int fitbench.Gen.maxFan
maxFan
=
(local variable) int rows
rows
;
foreach (
(local variable) int r
r
; 0 ..
(local variable) int rows
rows
)
{
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)
open
(0,
(enum value) fitbench.GrowX = cast(ubyte)1u
GrowX
, 4, 8);
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)
label
();
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)
label
(
(enum value) fitbench.GrowX = cast(ubyte)1u
GrowX
);
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.label(ubyte grow = cast(ubyte)0u)
label
();
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.close()
close
();
}
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.close()
close
();
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.close()
close
();
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.close()
close
();
return
(local variable) fitbench.Gen g
g
;
} /// Balanced-ish nested panels: fan-out mostly 2..8, sometimes a 50..1000 list, /// depth <= 12, exactly n nodes.
(struct) fitbench.Gen
Gen
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 n
n
)
{
(struct) fitbench.Gen
Gen
(local variable) fitbench.Gen g
g
;
(local variable) fitbench.Gen g
g
.
(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rng
rng
=
(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 = 12
maxD
= 12;
void
void fitbench.genPanels.node(int budget, int depth) @system
node
(int
(parameter) int budget
budget
, int
(parameter) int depth
depth
)
{ if (
(parameter) int budget
budget
== 1)
{
(local variable) fitbench.Gen g
g
.
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 @safe

Create 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 g
g
.
(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rng
rng
) == 0 ?
(enum value) fitbench.GrowX = cast(ubyte)1u
GrowX
: 0);
return; } ubyte
(local variable) ubyte axis
axis
= cast(ubyte)((
(parameter) int depth
depth
& 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 @safe

Create 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 g
g
.
(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rng
rng
) == 0));
ubyte
(local variable) ubyte grow
grow
= 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 @safe

Create 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 g
g
.
(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rng
rng
);
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.open(ubyte axis, ubyte grow, ubyte pad, ushort gap)
open
(
(local variable) ubyte axis
axis
,
(local variable) ubyte grow
grow
, 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 @safe

Create 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 g
g
.
(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rng
rng
), 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 @safe

Create 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 g
g
.
(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rng
rng
));
int
(local variable) int rem
rem
=
(parameter) int budget
budget
- 1;
int
(local variable) int f
f
;
if (
(local variable) int rem
rem
<= 8 ||
(parameter) int depth
depth
>=
(constant) int fitbench.genPanels.maxD = 12
maxD
- 2)
(local variable) int f
f
=
(local variable) int rem
rem
;
else {
(local variable) int f
f
=
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 @safe

Create 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 g
g
.
(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rng
rng
);
if (
(local variable) int rem
rem
>= 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 @safe

Create 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 g
g
.
(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rng
rng
) == 0)
(local variable) int f
f
=
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 @safe

Create 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 @safe

Iterates 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);
@paramargs The values to select the minimum from. At least two arguments must be passed, and they must be comparable with <.@returnsThe minimum of the passed-in values. The type of the returned value is the type among the passed arguments that is able to store the smallest value. If at least one of the arguments is NaN, the result is an unspecified value. See minElement for examples on how to cope with NaNs.@seeminElement
min
(1000,
(local variable) int rem
rem
) + 1,
(local variable) fitbench.Gen g
g
.
(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rng
rng
);
int
(local variable) int levels
levels
=
(constant) int fitbench.genPanels.maxD = 12
maxD
- 2 -
(parameter) int depth
depth
;
int
(local variable) int minF
minF
= cast(int)
double std.math.rounding.ceil(double x) pure nothrow @nogc @trusted
ceil
(
double std.math.exponential.pow!(double, double)(double x, double y) pure nothrow @nogc @trusted

Calculates 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 rem
rem
, 1.0 /
(local variable) int levels
levels
));
(local variable) int f
f
=
int std.algorithm.comparison.min!(int, int)(int a, int b) pure nothrow @nogc @safe

Iterates 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);
@paramargs The values to select the minimum from. At least two arguments must be passed, and they must be comparable with <.@returnsThe minimum of the passed-in values. The type of the returned value is the type among the passed arguments that is able to store the smallest value. If at least one of the arguments is NaN, the result is an unspecified value. See minElement for examples on how to cope with NaNs.@seeminElement
min
(
int std.algorithm.comparison.max!(int, int)(int a, int b) pure nothrow @nogc @safe

Iterates 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);
@paramargs The values to select the maximum from. At least two arguments must be passed, and they must be comparable with <.@returnsThe maximum of the passed-in values. The type of the returned value is the type among the passed arguments that is able to store the largest value. If at least one of the arguments is NaN, the result is an unspecified value. See maxElement for examples on how to cope with NaNs.@seemaxElement
max
(
(local variable) int f
f
,
(local variable) int minF
minF
),
(local variable) int rem
rem
);
}
(local variable) fitbench.Gen g
g
.
(field) int fitbench.Gen.maxFan
maxFan
=
int std.algorithm.comparison.max!(int, int)(int a, int b) pure nothrow @nogc @safe

Iterates 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);
@paramargs The values to select the maximum from. At least two arguments must be passed, and they must be comparable with <.@returnsThe maximum of the passed-in values. The type of the returned value is the type among the passed arguments that is able to store the largest value. If at least one of the arguments is NaN, the result is an unspecified value. See maxElement for examples on how to cope with NaNs.@seemaxElement
max
(
(local variable) fitbench.Gen g
g
.
(field) int fitbench.Gen.maxFan
maxFan
,
(local variable) int f
f
);
// split rem into f positive parts with skewed random weights auto
(local variable) double[] w
w
= new double[
(local variable) int f
f
];
double
(local variable) double W
W
= 0;
foreach (ref
(parameter) double x
x
;
(local variable) double[] w
w
)
{ double
(local variable) double u
u
=
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 @safe

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.

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);
@paramrng (optional) random number generator to use; if not specified, defaults to rndGen@returnsFloating-point random variate of type T drawn from the uniform distribution across the half-open interval [0, 1).
uniform01
(
(local variable) fitbench.Gen g
g
.
(field) std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u) fitbench.Gen.rng
rng
);
(local variable) double x
x
=
(local variable) double u
u
*
(local variable) double u
u
*
(local variable) double u
u
;
(local variable) double W
W
+=
(local variable) double x
x
;
} int
(local variable) int left
left
=
(local variable) int rem
rem
-
(local variable) int f
f
;
foreach (
(local variable) int k
k
; 0 ..
(local variable) int f
f
)
{ int
(local variable) int extra
extra
=
(local variable) int k
k
+ 1 ==
(local variable) int f
f
?
(local variable) int left
left
: cast(int)((
(local variable) int rem
rem
-
(local variable) int f
f
) *
(local variable) double[] w
w
[
(local variable) int k
k
] /
(local variable) double W
W
);
(local variable) int extra
extra
=
int std.algorithm.comparison.min!(int, int)(int a, int b) pure nothrow @nogc @safe

Iterates 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);
@paramargs The values to select the minimum from. At least two arguments must be passed, and they must be comparable with <.@returnsThe minimum of the passed-in values. The type of the returned value is the type among the passed arguments that is able to store the smallest value. If at least one of the arguments is NaN, the result is an unspecified value. See minElement for examples on how to cope with NaNs.@seeminElement
min
(
(local variable) int extra
extra
,
(local variable) int left
left
);
(local variable) int left
left
-=
(local variable) int extra
extra
;
void fitbench.genPanels.node(int budget, int depth) @system
node
(1 +
(local variable) int extra
extra
,
(parameter) int depth
depth
+ 1);
}
(local variable) fitbench.Gen g
g
.
void fitbench.Gen.close()
close
();
}
void fitbench.genPanels.node(int budget, int depth) @system
node
(
(parameter) int n
n
, 0);
return
(local variable) fitbench.Gen g
g
;
} // --------------------------------------------------------------------------- // Storage // --------------------------------------------------------------------------- /// The fat AoS widget record; the first 64 bytes are the layout-relevant head. struct
(struct) fitbench.Node!328LU

The fat AoS widget record; the first 64 bytes are the layout-relevant head.

Node
(size_t SIZE)
{ int
(field) int fitbench.Node!328LU.parent
parent
;
ubyte
(field) ubyte fitbench.Node!328LU.kind
kind
,
(field) ubyte fitbench.Node!328LU.axis
axis
,
(field) ubyte fitbench.Node!328LU.grow
grow
,
(field) ubyte fitbench.Node!328LU._r
_r
;
int
(field) int fitbench.Node!328LU.childCount
childCount
;
int
(field) int fitbench.Node!328LU.growCount
growCount
;
float
(field) float fitbench.Node!328LU.gap
gap
= 0;
float[2]
(field) float[2] fitbench.Node!328LU.pad
pad
= 0; // total padding per axis (left+right, top+bottom)
uint
(field) uint fitbench.Node!328LU.textLen
textLen
;
float[2]
(field) float[2] fitbench.Node!328LU.sz
sz
= 0;
float[2]
(field) float[2] fitbench.Node!328LU.fit
fit
= 0;
float[2]
(field) float[2] fitbench.Node!328LU.pos
pos
= 0;
const(char)*
(field) const(char)* fitbench.Node!328LU.text
text
;
static if (
(constant) ulong fitbench.SIZE = 328LU
SIZE
> 64)
ubyte[
(constant) ulong fitbench.SIZE = 328LU
SIZE
- 64]
(field) ubyte[264] fitbench.Node!328LU.payload
payload
;
} static assert(
(template instance) fitbench.Node!64LU
Node
!64.
(constant) ulong fitbench.Node!64LU.sizeof = 64LU
sizeof
== 64 &&
(template instance) fitbench.Node!128LU
Node
!128.
(constant) ulong fitbench.Node!128LU.sizeof = 128LU
sizeof
== 128 &&
(template instance) fitbench.Node!328LU
Node
!328.
(constant) ulong fitbench.Node!328LU.sizeof = 328LU
sizeof
== 328);
/// SoA variant's cold payload: text slice + id + the same fat payload. struct
(struct) fitbench.Cold!328LU

SoA variant's cold payload: text slice + id + the same fat payload.

Cold
(size_t SIZE)
{ const(char)*
(field) const(char)* fitbench.Cold!328LU.text
text
;
uint
(field) uint fitbench.Cold!328LU.textLen
textLen
;
uint
(field) uint fitbench.Cold!328LU.id
id
;
static if (
(constant) ulong fitbench.SIZE = 328LU
SIZE
> 64)
ubyte[SIZE - 64]
(field) ubyte[264] fitbench.Cold!328LU.payload
payload
;
} struct
(struct) fitbench.Soa!328LU
Soa
(size_t SIZE)
{ int*
(field) int* fitbench.Soa!328LU.parent
parent
;
ubyte*
(field) ubyte* fitbench.Soa!328LU.flags
flags
; // axis | grow << 1
int*
(field) int* fitbench.Soa!328LU.childCount
childCount
;
int*
(field) int* fitbench.Soa!328LU.growCount
growCount
;
float*
(field) float* fitbench.Soa!328LU.gap
gap
;
float[2]*
(field) float[2]* fitbench.Soa!328LU.pad
pad
;
float[2]*
(field) float[2]* fitbench.Soa!328LU.sz
sz
;
float[2]*
(field) float[2]* fitbench.Soa!328LU.fit
fit
;
float[2]*
(field) float[2]* fitbench.Soa!328LU.pos
pos
;
ubyte*
(field) ubyte* fitbench.Soa!328LU.depth
depth
;
(constant) ulong fitbench.SIZE = 328LU
Cold
!
(constant) ulong fitbench.SIZE = 328LU
SIZE
*
(field) fitbench.Cold!328LU* fitbench.Soa!328LU.cold
cold
;
void
void fitbench.Soa!328LU.alloc(ulong n) nothrow @nogc @system
alloc
(
(alias) object.size_t = ulong
size_t
(parameter) ulong n
n
)
{
(field) int* fitbench.Soa!328LU.parent
parent
= cast(int*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 4);
(field) ubyte* fitbench.Soa!328LU.flags
flags
= cast(ubyte*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
);
(field) int* fitbench.Soa!328LU.childCount
childCount
= cast(int*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 4);
(field) int* fitbench.Soa!328LU.growCount
growCount
= cast(int*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 4);
(field) float* fitbench.Soa!328LU.gap
gap
= cast(float*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 4);
(field) float[2]* fitbench.Soa!328LU.pad
pad
= cast(float[2]*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 8);
(field) float[2]* fitbench.Soa!328LU.sz
sz
= cast(float[2]*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 8);
(field) float[2]* fitbench.Soa!328LU.fit
fit
= cast(float[2]*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 8);
(field) float[2]* fitbench.Soa!328LU.pos
pos
= cast(float[2]*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 8);
(field) ubyte* fitbench.Soa!328LU.depth
depth
= cast(ubyte*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
);
(field) fitbench.Cold!328LU* fitbench.Soa!328LU.cold
cold
= cast(
(constant) ulong fitbench.SIZE = 128LU
Cold
!
(constant) ulong fitbench.SIZE = 328LU
SIZE
*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
*
(constant) ulong fitbench.SIZE = 128LU
Cold
!
(constant) ulong fitbench.SIZE = 328LU
SIZE
.
(constant) ulong fitbench.Cold!328LU.sizeof = 280LU
sizeof
);
} void
void fitbench.Soa!328LU.release() nothrow @nogc @system
release
()
{ foreach (
(parameter) void* p
p
; [cast(void*)
(field) int* fitbench.Soa!328LU.parent
parent
,
(field) ubyte* fitbench.Soa!328LU.flags
flags
,
(field) int* fitbench.Soa!328LU.childCount
childCount
,
(field) int* fitbench.Soa!328LU.growCount
growCount
,
(field) float* fitbench.Soa!328LU.gap
gap
,
(field) float[2]* fitbench.Soa!328LU.pad
pad
,
(field) float[2]* fitbench.Soa!328LU.sz
sz
,
(field) float[2]* fitbench.Soa!328LU.fit
fit
,
(field) float[2]* fitbench.Soa!328LU.pos
pos
,
(field) ubyte* fitbench.Soa!328LU.depth
depth
,
(field) fitbench.Cold!328LU* fitbench.Soa!328LU.cold
cold
])
void core.stdc.stdlib.free(void* ptr) nothrow @nogc
free
(
(local variable) void* p
p
);
} } /// Scratch for the level-order variant. struct
(struct) fitbench.LevelScratch

Scratch for the level-order variant.

LevelScratch
{ int*
(field) int* fitbench.LevelScratch.ord
ord
;
float*
(field) float* fitbench.LevelScratch.w
w
,
(field) float* fitbench.LevelScratch.h
h
;
float*
(field) float* fitbench.LevelScratch.padM
padM
,
(field) float* fitbench.LevelScratch.padC
padC
; // main/cross padding of the node itself
float*
(field) float* fitbench.LevelScratch.gap
gap
;
int*
(field) int* fitbench.LevelScratch.cnt
cnt
;
ubyte*
(field) ubyte* fitbench.LevelScratch.axis
axis
;
void
void fitbench.LevelScratch.alloc(ulong n)
alloc
(
(alias) object.size_t = ulong
size_t
(parameter) ulong n
n
)
{
(field) int* fitbench.LevelScratch.ord
ord
= cast(int*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 4);
(field) float* fitbench.LevelScratch.w
w
= cast(float*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 4);
(field) float* fitbench.LevelScratch.h
h
= cast(float*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 4);
(field) float* fitbench.LevelScratch.padM
padM
= cast(float*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 4);
(field) float* fitbench.LevelScratch.padC
padC
= cast(float*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 4);
(field) float* fitbench.LevelScratch.gap
gap
= cast(float*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 4);
(field) int* fitbench.LevelScratch.cnt
cnt
= cast(int*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
* 4);
(field) ubyte* fitbench.LevelScratch.axis
axis
= cast(ubyte*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) ulong n
n
);
} void
void fitbench.LevelScratch.release()
release
()
{ foreach (
(parameter) void* p
p
; [cast(void*)
(field) int* fitbench.LevelScratch.ord
ord
,
(field) float* fitbench.LevelScratch.w
w
,
(field) float* fitbench.LevelScratch.h
h
,
(field) float* fitbench.LevelScratch.padM
padM
,
(field) float* fitbench.LevelScratch.padC
padC
,
(field) float* fitbench.LevelScratch.gap
gap
,
(field) int* fitbench.LevelScratch.cnt
cnt
,
(field) ubyte* fitbench.LevelScratch.axis
axis
])
void core.stdc.stdlib.free(void* ptr) nothrow @nogc
free
(
(local variable) void* p
p
);
} } // --------------------------------------------------------------------------- // Build (+ fused fit) // --------------------------------------------------------------------------- struct
(struct) fitbench.Frame
Frame
{ int
(field) int fitbench.Frame.idx
idx
;
int
(field) int fitbench.Frame.count
count
;
int
(field) int fitbench.Frame.growCount
growCount
;
int
(field) int fitbench.Frame.axis
axis
;
float
(field) float fitbench.Frame.sum
sum
= 0; // main-axis sum of children
float
(field) float fitbench.Frame.mx
mx
= 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.Frame
Frame
(parameter) fitbench.Frame f
f
, float
(parameter) float w
w
, float
(parameter) float h
h
)
{ float
(local variable) float m
m
=
(parameter) fitbench.Frame f
f
.
(field) int fitbench.Frame.axis
axis
?
(parameter) float h
h
:
(parameter) float w
w
;
float
(local variable) float c
c
=
(parameter) fitbench.Frame f
f
.
(field) int fitbench.Frame.axis
axis
?
(parameter) float w
w
:
(parameter) float h
h
;
(parameter) fitbench.Frame f
f
.
(field) float fitbench.Frame.sum
sum
+=
(local variable) float m
m
;
(parameter) fitbench.Frame f
f
.
(field) float fitbench.Frame.mx
mx
=
(local variable) float c
c
>
(parameter) fitbench.Frame f
f
.
(field) float fitbench.Frame.mx
mx
?
(local variable) float c
c
:
(parameter) fitbench.Frame f
f
.
(field) float fitbench.Frame.mx
mx
;
} pragma(inline, true) void
void fitbench.writePayload!(ubyte[64])(ref ubyte[64] payload, int i) pure nothrow @nogc @system
writePayload
(P)(ref
(alias) P = ubyte[64]
P
(parameter) ubyte[64] payload
payload
, int
(parameter) int i
i
)
{ // 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 = 64LU
sizeof
>= 16)
{ ulong
(local variable) ulong id
id
= (cast(ulong)
(parameter) int i
i
* 0x9E3779B97F4A7C15UL) ^ 0xABCDEF;
*cast(ulong*)&
(parameter) ubyte[64] payload
payload
[0] =
(local variable) ulong id
id
;
*cast(uint*)&
(parameter) ubyte[64] payload
payload
[8] = 0xFF336699;
*cast(uint*)&
(parameter) ubyte[64] payload
payload
[12] = cast(uint)
(parameter) int i
i
;
} } int
int fitbench.buildAos!(false, 128LU)(const(fitbench.Ev)[] evs, const(char)* pool, fitbench.Node!128LU* nodes) pure nothrow @nogc @system
buildAos
(bool fused, size_t S)(const(
(struct) fitbench.Ev
Ev
)[]
(parameter) const(fitbench.Ev)[] evs
evs
, const(char)*
(parameter) const(char)* pool
pool
,
(constant) ulong fitbench.S = 128LU
Node
!
(constant) ulong fitbench.S = 128LU
S
*
(parameter) fitbench.Node!128LU* nodes
nodes
)
{
(struct) fitbench.Frame
Frame
[64]
(local variable) fitbench.Frame[64] st
st
= void;
int
(local variable) int sp
sp
= 0,
(local variable) int n
n
= 0;
foreach (ref const
(parameter) const(fitbench.Ev) e
e
;
(parameter) const(fitbench.Ev)[] evs
evs
)
{ if (
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.op
op
==
(enum value) fitbench.OpClose = cast(ubyte)2u
OpClose
)
{
(struct) fitbench.Frame
Frame
(local variable) fitbench.Frame f
f
=
(local variable) fitbench.Frame[64] st
st
[--
(local variable) int sp
sp
];
auto
(local variable) fitbench.Node!128LU* nd
nd
= &
(parameter) fitbench.Node!128LU* nodes
nodes
[
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.idx
idx
];
(local variable) fitbench.Node!128LU* nd
nd
.
(field) int fitbench.Node!128LU.childCount
childCount
=
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.count
count
;
(local variable) fitbench.Node!128LU* nd
nd
.
(field) int fitbench.Node!128LU.growCount
growCount
=
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.growCount
growCount
;
static if (fused) { int
(local variable) int a
a
=
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.axis
axis
;
float
(local variable) float m
m
=
(local variable) fitbench.Frame f
f
.
(field) float fitbench.Frame.sum
sum
+
(local variable) fitbench.Node!128LU* nd
nd
.
(field) float[2] fitbench.Node!128LU.pad
pad
[
(local variable) int a
a
] +
(local variable) fitbench.Node!128LU* nd
nd
.
(field) float fitbench.Node!128LU.gap
gap
* (
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.count
count
> 0 ?
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.count
count
- 1 : 0);
float
(local variable) float c
c
=
(local variable) fitbench.Frame f
f
.
(field) float fitbench.Frame.mx
mx
+
(local variable) fitbench.Node!128LU* nd
nd
.
(field) float[2] fitbench.Node!128LU.pad
pad
[1 -
(local variable) int a
a
];
float
(local variable) float w
w
=
(local variable) int a
a
?
(local variable) float c
c
:
(local variable) float m
m
,
(local variable) float h
h
=
(local variable) int a
a
?
(local variable) float m
m
:
(local variable) float c
c
;
(local variable) fitbench.Node!128LU* nd
nd
.
(field) float[2] fitbench.Node!128LU.sz
sz
[0] =
(local variable) float w
w
;
(local variable) fitbench.Node!128LU* nd
nd
.
(field) float[2] fitbench.Node!128LU.sz
sz
[1] =
(local variable) float h
h
;
if (
(local variable) int sp
sp
)
void fitbench.contribute(ref fitbench.Frame f, float w, float h)
contribute
(
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
- 1],
(local variable) float w
w
,
(local variable) float h
h
);
} } else { int
(local variable) int i
i
=
(local variable) int n
n
++;
auto
(local variable) fitbench.Node!128LU* nd
nd
= &
(parameter) fitbench.Node!128LU* nodes
nodes
[
(local variable) int i
i
];
*
(local variable) fitbench.Node!128LU* nd
nd
=
(constant) ulong fitbench.S = 128LU
Node
!
(constant) ulong fitbench.S = 128LU
S
.
(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* nd
nd
.
(field) int fitbench.Node!128LU.parent
parent
=
(local variable) int sp
sp
?
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
- 1].
(field) int fitbench.Frame.idx
idx
: -1;
(local variable) fitbench.Node!128LU* nd
nd
.
(field) ubyte fitbench.Node!128LU.kind
kind
=
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.op
op
;
(local variable) fitbench.Node!128LU* nd
nd
.
(field) ubyte fitbench.Node!128LU.axis
axis
=
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.axis
axis
;
(local variable) fitbench.Node!128LU* nd
nd
.
(field) ubyte fitbench.Node!128LU.grow
grow
=
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.grow
grow
;
(local variable) fitbench.Node!128LU* nd
nd
.
(field) float fitbench.Node!128LU.gap
gap
=
(local variable) const(fitbench.Ev) e
e
.
(field) ushort fitbench.Ev.gap
gap
;
(local variable) fitbench.Node!128LU* nd
nd
.
(field) float[2] fitbench.Node!128LU.pad
pad
[0] =
(local variable) fitbench.Node!128LU* nd
nd
.
(field) float[2] fitbench.Node!128LU.pad
pad
[1] = 2.0f *
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.pad
pad
;
(local variable) fitbench.Node!128LU* nd
nd
.
(field) const(char)* fitbench.Node!128LU.text
text
=
(parameter) const(char)* pool
pool
+
(local variable) const(fitbench.Ev) e
e
.
(field) uint fitbench.Ev.textOff
textOff
;
(local variable) fitbench.Node!128LU* nd
nd
.
(field) uint fitbench.Node!128LU.textLen
textLen
=
(local variable) const(fitbench.Ev) e
e
.
(field) ushort fitbench.Ev.textLen
textLen
;
static if (
(constant) ulong fitbench.S = 128LU
S
> 64)
void fitbench.writePayload!(ubyte[64])(ref ubyte[64] payload, int i) pure nothrow @nogc @system
writePayload
(
(local variable) fitbench.Node!128LU* nd
nd
.
(field) ubyte[64] fitbench.Node!128LU.payload
payload
,
(local variable) int i
i
);
if (
(local variable) int sp
sp
)
{
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
- 1].
(field) int fitbench.Frame.count
count
++;
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
- 1].
(field) int fitbench.Frame.growCount
growCount
+= (
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.grow
grow
>>
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
- 1].
(field) int fitbench.Frame.axis
axis
) & 1;
} if (
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.op
op
==
(enum value) fitbench.OpLabel = cast(ubyte)1u
OpLabel
)
{ float
(local variable) float w
w
=
(local variable) const(fitbench.Ev) e
e
.
(field) ushort fitbench.Ev.textLen
textLen
*
(constant) float fitbench.glyphW = 8.0F
glyphW
; // cached measure
(local variable) fitbench.Node!128LU* nd
nd
.
(field) float[2] fitbench.Node!128LU.sz
sz
[0] =
(local variable) float w
w
;
(local variable) fitbench.Node!128LU* nd
nd
.
(field) float[2] fitbench.Node!128LU.sz
sz
[1] =
(constant) float fitbench.lineH = 16.0F
lineH
;
static if (fused)
void fitbench.contribute(ref fitbench.Frame f, float w, float h)
contribute
(
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
- 1],
(local variable) float w
w
,
(constant) float fitbench.lineH = 16.0F
lineH
);
} else
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
++] =
(struct) fitbench.Frame
Frame
(
(local variable) int i
i
, 0, 0,
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.axis
axis
);
} } return
(local variable) int n
n
;
} int
int fitbench.buildSoa!(false, false, 64LU)(const(fitbench.Ev)[] evs, const(char)* pool, ref fitbench.Soa!64LU s) pure nothrow @nogc @system
buildSoa
(bool fused, bool withDepth, size_t S)(const(
(struct) fitbench.Ev
Ev
)[]
(parameter) const(fitbench.Ev)[] evs
evs
, const(char)*
(parameter) const(char)* pool
pool
, ref
(constant) ulong fitbench.S = 64LU
Soa
!
(constant) ulong fitbench.S = 64LU
S
(parameter) fitbench.Soa!64LU s
s
)
{
(struct) fitbench.Frame
Frame
[64]
(local variable) fitbench.Frame[64] st
st
= void;
int
(local variable) int sp
sp
= 0,
(local variable) int n
n
= 0;
foreach (ref const
(parameter) const(fitbench.Ev) e
e
;
(parameter) const(fitbench.Ev)[] evs
evs
)
{ if (
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.op
op
==
(enum value) fitbench.OpClose = cast(ubyte)2u
OpClose
)
{
(struct) fitbench.Frame
Frame
(local variable) fitbench.Frame f
f
=
(local variable) fitbench.Frame[64] st
st
[--
(local variable) int sp
sp
];
(parameter) fitbench.Soa!64LU s
s
.
(field) int* fitbench.Soa!64LU.childCount
childCount
[
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.idx
idx
] =
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.count
count
;
(parameter) fitbench.Soa!64LU s
s
.
(field) int* fitbench.Soa!64LU.growCount
growCount
[
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.idx
idx
] =
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.growCount
growCount
;
static if (fused) { int
(local variable) int a
a
=
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.axis
axis
;
auto
(local variable) float[2] pd
pd
=
(parameter) fitbench.Soa!64LU s
s
.
(field) float[2]* fitbench.Soa!64LU.pad
pad
[
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.idx
idx
];
float
(local variable) float m
m
=
(local variable) fitbench.Frame f
f
.
(field) float fitbench.Frame.sum
sum
+
(local variable) float[2] pd
pd
[
(local variable) int a
a
] +
(parameter) fitbench.Soa!64LU s
s
.
(field) float* fitbench.Soa!64LU.gap
gap
[
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.idx
idx
] * (
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.count
count
> 0 ?
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.count
count
- 1 : 0);
float
(local variable) float c
c
=
(local variable) fitbench.Frame f
f
.
(field) float fitbench.Frame.mx
mx
+
(local variable) float[2] pd
pd
[1 -
(local variable) int a
a
];
float
(local variable) float w
w
=
(local variable) int a
a
?
(local variable) float c
c
:
(local variable) float m
m
,
(local variable) float h
h
=
(local variable) int a
a
?
(local variable) float m
m
:
(local variable) float c
c
;
(parameter) fitbench.Soa!64LU s
s
.
(field) float[2]* fitbench.Soa!64LU.sz
sz
[
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.idx
idx
][0] =
(local variable) float w
w
;
(parameter) fitbench.Soa!64LU s
s
.
(field) float[2]* fitbench.Soa!64LU.sz
sz
[
(local variable) fitbench.Frame f
f
.
(field) int fitbench.Frame.idx
idx
][1] =
(local variable) float h
h
;
if (
(local variable) int sp
sp
)
void fitbench.contribute(ref fitbench.Frame f, float w, float h)
contribute
(
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
- 1],
(local variable) float w
w
,
(local variable) float h
h
);
} } else { int
(local variable) int i
i
=
(local variable) int n
n
++;
(parameter) fitbench.Soa!64LU s
s
.
(field) int* fitbench.Soa!64LU.parent
parent
[
(local variable) int i
i
] =
(local variable) int sp
sp
?
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
- 1].
(field) int fitbench.Frame.idx
idx
: -1;
(parameter) fitbench.Soa!64LU s
s
.
(field) ubyte* fitbench.Soa!64LU.flags
flags
[
(local variable) int i
i
] = cast(ubyte)(
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.axis
axis
| (
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.grow
grow
<< 1));
(parameter) fitbench.Soa!64LU s
s
.
(field) float* fitbench.Soa!64LU.gap
gap
[
(local variable) int i
i
] =
(local variable) const(fitbench.Ev) e
e
.
(field) ushort fitbench.Ev.gap
gap
;
(parameter) fitbench.Soa!64LU s
s
.
(field) float[2]* fitbench.Soa!64LU.pad
pad
[
(local variable) int i
i
][0] =
(parameter) fitbench.Soa!64LU s
s
.
(field) float[2]* fitbench.Soa!64LU.pad
pad
[
(local variable) int i
i
][1] = 2.0f *
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.pad
pad
;
(parameter) fitbench.Soa!64LU s
s
.
(field) int* fitbench.Soa!64LU.childCount
childCount
[
(local variable) int i
i
] = 0;
(parameter) fitbench.Soa!64LU s
s
.
(field) int* fitbench.Soa!64LU.growCount
growCount
[
(local variable) int i
i
] = 0;
static if (withDepth)
(parameter) fitbench.Soa!64LU s
s
.
(field) ubyte* fitbench.Soa!64LU.depth
depth
[
(local variable) int i
i
] = cast(ubyte)
(local variable) int sp
sp
;
auto
(local variable) fitbench.Cold!64LU* c
c
= &
(parameter) fitbench.Soa!64LU s
s
.
(field) fitbench.Cold!64LU* fitbench.Soa!64LU.cold
cold
[
(local variable) int i
i
];
*
(local variable) fitbench.Cold!64LU* c
c
=
(constant) ulong fitbench.S = 64LU
Cold
!
(constant) ulong fitbench.S = 64LU
S
.
(constant) fitbench.Cold!64LU fitbench.Cold!64LU.init = Cold(null, 0u, 0u)
init
;
(local variable) fitbench.Cold!64LU* c
c
.
(field) const(char)* fitbench.Cold!64LU.text
text
=
(parameter) const(char)* pool
pool
+
(local variable) const(fitbench.Ev) e
e
.
(field) uint fitbench.Ev.textOff
textOff
;
(local variable) fitbench.Cold!64LU* c
c
.
(field) uint fitbench.Cold!64LU.textLen
textLen
=
(local variable) const(fitbench.Ev) e
e
.
(field) ushort fitbench.Ev.textLen
textLen
;
(local variable) fitbench.Cold!64LU* c
c
.
(field) uint fitbench.Cold!64LU.id
id
=
(local variable) int i
i
;
static if (
(constant) ulong fitbench.S = 64LU
S
> 64)
void fitbench.writePayload!(ubyte[264])(ref ubyte[264] payload, int i) pure nothrow @nogc @system
writePayload
(
(local variable) fitbench.Cold!328LU* c
c
.
(field) ubyte[264] fitbench.Cold!328LU.payload
payload
,
(local variable) int i
i
);
if (
(local variable) int sp
sp
)
{
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
- 1].
(field) int fitbench.Frame.count
count
++;
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
- 1].
(field) int fitbench.Frame.growCount
growCount
+= (
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.grow
grow
>>
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
- 1].
(field) int fitbench.Frame.axis
axis
) & 1;
} if (
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.op
op
==
(enum value) fitbench.OpLabel = cast(ubyte)1u
OpLabel
)
{ float
(local variable) float w
w
=
(local variable) const(fitbench.Ev) e
e
.
(field) ushort fitbench.Ev.textLen
textLen
*
(constant) float fitbench.glyphW = 8.0F
glyphW
;
(parameter) fitbench.Soa!64LU s
s
.
(field) float[2]* fitbench.Soa!64LU.sz
sz
[
(local variable) int i
i
][0] =
(local variable) float w
w
;
(parameter) fitbench.Soa!64LU s
s
.
(field) float[2]* fitbench.Soa!64LU.sz
sz
[
(local variable) int i
i
][1] =
(constant) float fitbench.lineH = 16.0F
lineH
;
static if (fused)
void fitbench.contribute(ref fitbench.Frame f, float w, float h)
contribute
(
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
- 1],
(local variable) float w
w
,
(constant) float fitbench.lineH = 16.0F
lineH
);
} else {
(parameter) fitbench.Soa!64LU s
s
.
(field) float[2]* fitbench.Soa!64LU.sz
sz
[
(local variable) int i
i
][0] =
(parameter) fitbench.Soa!64LU s
s
.
(field) float[2]* fitbench.Soa!64LU.sz
sz
[
(local variable) int i
i
][1] = 0;
(local variable) fitbench.Frame[64] st
st
[
(local variable) int sp
sp
++] =
(struct) fitbench.Frame
Frame
(
(local variable) int i
i
, 0, 0,
(local variable) const(fitbench.Ev) e
e
.
(field) ubyte fitbench.Ev.axis
axis
);
} } } return
(local variable) int n
n
;
} // --------------------------------------------------------------------------- // Separate fit passes // --------------------------------------------------------------------------- void
void fitbench.fitSweepAos!328LU(fitbench.Node!328LU* nodes, int n) pure nothrow @nogc @system
fitSweepAos
(size_t S)(
(struct) fitbench.Node!328LU

The fat AoS widget record; the first 64 bytes are the layout-relevant head.

Node
!
(constant) ulong fitbench.S = 328LU
S
*
(parameter) fitbench.Node!328LU* nodes
nodes
, int
(parameter) int n
n
)
{ for (int
(local variable) int i
i
=
(parameter) int n
n
- 1; i >= 0; --i)
{ auto
(local variable) fitbench.Node!328LU* nd
nd
= &
(parameter) fitbench.Node!328LU* nodes
nodes
[
(local variable) int i
i
];
int
(local variable) int a
a
=
(local variable) fitbench.Node!328LU* nd
nd
.
(field) ubyte fitbench.Node!328LU.axis
axis
;
int
(local variable) int c
c
=
(local variable) fitbench.Node!328LU* nd
nd
.
(field) int fitbench.Node!328LU.childCount
childCount
;
float
(local variable) float w
w
=
(local variable) fitbench.Node!328LU* nd
nd
.
(field) float[2] fitbench.Node!328LU.sz
sz
[0],
(local variable) float h
h
=
(local variable) fitbench.Node!328LU* nd
nd
.
(field) float[2] fitbench.Node!328LU.sz
sz
[1];
float
(local variable) float m
m
= (
(local variable) int a
a
?
(local variable) float h
h
:
(local variable) float w
w
) +
(local variable) fitbench.Node!328LU* nd
nd
.
(field) float[2] fitbench.Node!328LU.pad
pad
[
(local variable) int a
a
] +
(local variable) fitbench.Node!328LU* nd
nd
.
(field) float fitbench.Node!328LU.gap
gap
* (
(local variable) int c
c
> 0 ?
(local variable) int c
c
- 1 : 0);
float
(local variable) float x
x
= (
(local variable) int a
a
?
(local variable) float w
w
:
(local variable) float h
h
) +
(local variable) fitbench.Node!328LU* nd
nd
.
(field) float[2] fitbench.Node!328LU.pad
pad
[1 -
(local variable) int a
a
];
(local variable) float w
w
=
(local variable) int a
a
?
(local variable) float x
x
:
(local variable) float m
m
;
(local variable) float h
h
=
(local variable) int a
a
?
(local variable) float m
m
:
(local variable) float x
x
;
(local variable) fitbench.Node!328LU* nd
nd
.
(field) float[2] fitbench.Node!328LU.sz
sz
[0] =
(local variable) float w
w
;
(local variable) fitbench.Node!328LU* nd
nd
.
(field) float[2] fitbench.Node!328LU.sz
sz
[1] =
(local variable) float h
h
;
int
(local variable) int p
p
=
(local variable) fitbench.Node!328LU* nd
nd
.
(field) int fitbench.Node!328LU.parent
parent
;
if (
(local variable) int p
p
>= 0)
{ auto
(local variable) fitbench.Node!328LU* pn
pn
= &
(parameter) fitbench.Node!328LU* nodes
nodes
[
(local variable) int p
p
];
if (
(local variable) fitbench.Node!328LU* pn
pn
.
(field) ubyte fitbench.Node!328LU.axis
axis
== 0)
{
(local variable) fitbench.Node!328LU* pn
pn
.
(field) float[2] fitbench.Node!328LU.sz
sz
[0] +=
(local variable) float w
w
;
(local variable) fitbench.Node!328LU* pn
pn
.
(field) float[2] fitbench.Node!328LU.sz
sz
[1] =
(local variable) float h
h
>
(local variable) fitbench.Node!328LU* pn
pn
.
(field) float[2] fitbench.Node!328LU.sz
sz
[1] ?
(local variable) float h
h
:
(local variable) fitbench.Node!328LU* pn
pn
.
(field) float[2] fitbench.Node!328LU.sz
sz
[1];
} else {
(local variable) fitbench.Node!328LU* pn
pn
.
(field) float[2] fitbench.Node!328LU.sz
sz
[1] +=
(local variable) float h
h
;
(local variable) fitbench.Node!328LU* pn
pn
.
(field) float[2] fitbench.Node!328LU.sz
sz
[0] =
(local variable) float w
w
>
(local variable) fitbench.Node!328LU* pn
pn
.
(field) float[2] fitbench.Node!328LU.sz
sz
[0] ?
(local variable) float w
w
:
(local variable) fitbench.Node!328LU* pn
pn
.
(field) float[2] fitbench.Node!328LU.sz
sz
[0];
} } } } void
void fitbench.fitSweepSoa!328LU(ref fitbench.Soa!328LU s, int n) pure nothrow @nogc @system
fitSweepSoa
(size_t S)(ref
(constant) ulong fitbench.S = 64LU
Soa
!
(constant) ulong fitbench.S = 328LU
S
(parameter) fitbench.Soa!328LU s
s
, int
(parameter) int n
n
)
{ auto
(local variable) float[2]* sz
sz
=
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.sz
sz
,
(local variable) float[2]* pad
pad
=
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.pad
pad
,
(local variable) float* gap
gap
=
(parameter) fitbench.Soa!328LU s
s
.
(field) float* fitbench.Soa!328LU.gap
gap
,
(local variable) int* cc
cc
=
(parameter) fitbench.Soa!328LU s
s
.
(field) int* fitbench.Soa!328LU.childCount
childCount
,
(local variable) ubyte* fl
fl
=
(parameter) fitbench.Soa!328LU s
s
.
(field) ubyte* fitbench.Soa!328LU.flags
flags
,
(local variable) int* par
par
=
(parameter) fitbench.Soa!328LU s
s
.
(field) int* fitbench.Soa!328LU.parent
parent
;
for (int
(local variable) int i
i
=
(parameter) int n
n
- 1; i >= 0; --i)
{ int
(local variable) int a
a
=
(local variable) ubyte* fl
fl
[
(local variable) int i
i
] & 1;
int
(local variable) int c
c
=
(local variable) int* cc
cc
[
(local variable) int i
i
];
float
(local variable) float w
w
=
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][0],
(local variable) float h
h
=
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][1];
float
(local variable) float m
m
= (
(local variable) int a
a
?
(local variable) float h
h
:
(local variable) float w
w
) +
(local variable) float[2]* pad
pad
[
(local variable) int i
i
][
(local variable) int a
a
] +
(local variable) float* gap
gap
[
(local variable) int i
i
] * (
(local variable) int c
c
> 0 ?
(local variable) int c
c
- 1 : 0);
float
(local variable) float x
x
= (
(local variable) int a
a
?
(local variable) float w
w
:
(local variable) float h
h
) +
(local variable) float[2]* pad
pad
[
(local variable) int i
i
][1 -
(local variable) int a
a
];
(local variable) float w
w
=
(local variable) int a
a
?
(local variable) float x
x
:
(local variable) float m
m
;
(local variable) float h
h
=
(local variable) int a
a
?
(local variable) float m
m
:
(local variable) float x
x
;
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][0] =
(local variable) float w
w
;
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][1] =
(local variable) float h
h
;
int
(local variable) int p
p
=
(local variable) int* par
par
[
(local variable) int i
i
];
if (
(local variable) int p
p
>= 0)
{ if ((
(local variable) ubyte* fl
fl
[
(local variable) int p
p
] & 1) == 0)
{
(local variable) float[2]* sz
sz
[
(local variable) int p
p
][0] +=
(local variable) float w
w
;
(local variable) float[2]* sz
sz
[
(local variable) int p
p
][1] =
(local variable) float h
h
>
(local variable) float[2]* sz
sz
[
(local variable) int p
p
][1] ?
(local variable) float h
h
:
(local variable) float[2]* sz
sz
[
(local variable) int p
p
][1];
} else {
(local variable) float[2]* sz
sz
[
(local variable) int p
p
][1] +=
(local variable) float h
h
;
(local variable) float[2]* sz
sz
[
(local variable) int p
p
][0] =
(local variable) float w
w
>
(local variable) float[2]* sz
sz
[
(local variable) int p
p
][0] ?
(local variable) float w
w
:
(local variable) float[2]* sz
sz
[
(local variable) int p
p
][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 @system

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.

fitSweepSoaRc
(size_t S)(ref
(constant) ulong fitbench.S = 64LU
Soa
!
(constant) ulong fitbench.S = 328LU
S
(parameter) fitbench.Soa!328LU s
s
, int
(parameter) int n
n
)
{ auto
(local variable) float[2]* sz
sz
=
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.sz
sz
,
(local variable) float[2]* pad
pad
=
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.pad
pad
,
(local variable) float* gap
gap
=
(parameter) fitbench.Soa!328LU s
s
.
(field) float* fitbench.Soa!328LU.gap
gap
,
(local variable) int* cc
cc
=
(parameter) fitbench.Soa!328LU s
s
.
(field) int* fitbench.Soa!328LU.childCount
childCount
,
(local variable) ubyte* fl
fl
=
(parameter) fitbench.Soa!328LU s
s
.
(field) ubyte* fitbench.Soa!328LU.flags
flags
,
(local variable) int* par
par
=
(parameter) fitbench.Soa!328LU s
s
.
(field) int* fitbench.Soa!328LU.parent
parent
;
int
(local variable) int cur
cur
= -1,
(local variable) int ca
ca
= 0;
float
(local variable) float am
am
= 0,
(local variable) float ac
ac
= 0;
for (int
(local variable) int i
i
=
(parameter) int n
n
- 1; i >= 0; --i)
{ if (
(local variable) int i
i
==
(local variable) int cur
cur
) // about to finalise the parent held in registers
{
(local variable) float[2]* sz
sz
[
(local variable) int cur
cur
][
(local variable) int ca
ca
] =
(local variable) float am
am
;
(local variable) float[2]* sz
sz
[
(local variable) int cur
cur
][1 -
(local variable) int ca
ca
] =
(local variable) float ac
ac
;
(local variable) int cur
cur
= -1;
} int
(local variable) int a
a
=
(local variable) ubyte* fl
fl
[
(local variable) int i
i
] & 1;
int
(local variable) int c
c
=
(local variable) int* cc
cc
[
(local variable) int i
i
];
float
(local variable) float w
w
=
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][0],
(local variable) float h
h
=
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][1];
float
(local variable) float m
m
= (
(local variable) int a
a
?
(local variable) float h
h
:
(local variable) float w
w
) +
(local variable) float[2]* pad
pad
[
(local variable) int i
i
][
(local variable) int a
a
] +
(local variable) float* gap
gap
[
(local variable) int i
i
] * (
(local variable) int c
c
> 0 ?
(local variable) int c
c
- 1 : 0);
float
(local variable) float x
x
= (
(local variable) int a
a
?
(local variable) float w
w
:
(local variable) float h
h
) +
(local variable) float[2]* pad
pad
[
(local variable) int i
i
][1 -
(local variable) int a
a
];
(local variable) float w
w
=
(local variable) int a
a
?
(local variable) float x
x
:
(local variable) float m
m
;
(local variable) float h
h
=
(local variable) int a
a
?
(local variable) float m
m
:
(local variable) float x
x
;
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][0] =
(local variable) float w
w
;
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][1] =
(local variable) float h
h
;
int
(local variable) int p
p
=
(local variable) int* par
par
[
(local variable) int i
i
];
if (
(local variable) int p
p
< 0)
continue; if (
(local variable) int p
p
!=
(local variable) int cur
cur
)
{ if (
(local variable) int cur
cur
>= 0)
{
(local variable) float[2]* sz
sz
[
(local variable) int cur
cur
][
(local variable) int ca
ca
] =
(local variable) float am
am
;
(local variable) float[2]* sz
sz
[
(local variable) int cur
cur
][1 -
(local variable) int ca
ca
] =
(local variable) float ac
ac
;
}
(local variable) int cur
cur
=
(local variable) int p
p
;
(local variable) int ca
ca
=
(local variable) ubyte* fl
fl
[
(local variable) int p
p
] & 1;
(local variable) float am
am
=
(local variable) float[2]* sz
sz
[
(local variable) int p
p
][
(local variable) int ca
ca
];
(local variable) float ac
ac
=
(local variable) float[2]* sz
sz
[
(local variable) int p
p
][1 -
(local variable) int ca
ca
];
} float
(local variable) float pm
pm
=
(local variable) int ca
ca
?
(local variable) float h
h
:
(local variable) float w
w
,
(local variable) float pc
pc
=
(local variable) int ca
ca
?
(local variable) float w
w
:
(local variable) float h
h
;
(local variable) float am
am
+=
(local variable) float pm
pm
;
(local variable) float ac
ac
=
(local variable) float pc
pc
>
(local variable) float ac
ac
?
(local variable) float pc
pc
:
(local variable) float ac
ac
;
} if (
(local variable) int cur
cur
>= 0)
{
(local variable) float[2]* sz
sz
[
(local variable) int cur
cur
][
(local variable) int ca
ca
] =
(local variable) float am
am
;
(local variable) float[2]* sz
sz
[
(local variable) int cur
cur
][1 -
(local variable) int ca
ca
] =
(local variable) float ac
ac
;
} } @
(struct) fitbench.fastmath
fastmath
float
float fitbench.sumRange(const(float)* p, int k)
sumRange
(const(float)*
(parameter) const(float)* p
p
, int
(parameter) int k
k
)
{ float
(local variable) float s
s
= 0;
foreach (
(local variable) int j
j
; 0 ..
(parameter) int k
k
)
(local variable) float s
s
+=
(parameter) const(float)* p
p
[
(local variable) int j
j
];
return
(local variable) float s
s
;
} @
(struct) fitbench.fastmath
fastmath
float
float fitbench.maxRange(const(float)* p, int k)
maxRange
(const(float)*
(parameter) const(float)* p
p
, int
(parameter) int k
k
)
{ float
(local variable) float m
m
= 0;
foreach (
(local variable) int j
j
; 0 ..
(parameter) int k
k
)
(local variable) float m
m
=
(parameter) const(float)* p
p
[
(local variable) int j
j
] >
(local variable) float m
m
?
(parameter) const(float)* p
p
[
(local variable) int j
j
] :
(local variable) float m
m
;
return
(local variable) float m
m
;
} /// 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) @system

Returns ns spent in the pure level reduction (for the breakdown).

fitLevel
(size_t S)(ref
(struct) fitbench.Soa!328LU
Soa
!
(constant) ulong fitbench.S = 328LU
S
(parameter) fitbench.Soa!328LU s
s
, ref
(struct) fitbench.LevelScratch

Scratch for the level-order variant.

LevelScratch
(parameter) fitbench.LevelScratch L
L
, int
(parameter) int n
n
)
{ // 1. counting sort by depth (stable => siblings contiguous within a level) int[66]
(local variable) int[66] start
start
= 0;
foreach (
(local variable) int i
i
; 0 ..
(parameter) int n
n
)
(local variable) int[66] start
start
[
(parameter) fitbench.Soa!328LU s
s
.
(field) ubyte* fitbench.Soa!328LU.depth
depth
[
(local variable) int i
i
] + 1]++;
int
(local variable) int maxD
maxD
= 0;
foreach (
(local variable) int d
d
; 1 .. 65)
{ if (
(local variable) int[66] start
start
[
(local variable) int d
d
])
(local variable) int maxD
maxD
=
(local variable) int d
d
;
(local variable) int[66] start
start
[
(local variable) int d
d
] +=
(local variable) int[66] start
start
[
(local variable) int d
d
- 1];
} int[65]
(local variable) int[65] cur
cur
=
(local variable) int[66] start
start
[0 .. 65];
foreach (
(local variable) int i
i
; 0 ..
(parameter) int n
n
)
{ int
(local variable) int j
j
=
(local variable) int[65] cur
cur
[
(parameter) fitbench.Soa!328LU s
s
.
(field) ubyte* fitbench.Soa!328LU.depth
depth
[
(local variable) int i
i
]]++;
(parameter) fitbench.LevelScratch L
L
.
(field) int* fitbench.LevelScratch.ord
ord
[
(local variable) int j
j
] =
(local variable) int i
i
;
int
(local variable) int a
a
=
(parameter) fitbench.Soa!328LU s
s
.
(field) ubyte* fitbench.Soa!328LU.flags
flags
[
(local variable) int i
i
] & 1;
(parameter) fitbench.LevelScratch L
L
.
(field) ubyte* fitbench.LevelScratch.axis
axis
[
(local variable) int j
j
] = cast(ubyte)
(local variable) int a
a
;
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.w
w
[
(local variable) int j
j
] =
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.sz
sz
[
(local variable) int i
i
][0];
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.h
h
[
(local variable) int j
j
] =
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.sz
sz
[
(local variable) int i
i
][1];
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.padM
padM
[
(local variable) int j
j
] =
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.pad
pad
[
(local variable) int i
i
][
(local variable) int a
a
];
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.padC
padC
[
(local variable) int j
j
] =
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.pad
pad
[
(local variable) int i
i
][1 -
(local variable) int a
a
];
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.gap
gap
[
(local variable) int j
j
] =
(parameter) fitbench.Soa!328LU s
s
.
(field) float* fitbench.Soa!328LU.gap
gap
[
(local variable) int i
i
];
(parameter) fitbench.LevelScratch L
L
.
(field) int* fitbench.LevelScratch.cnt
cnt
[
(local variable) int j
j
] =
(parameter) fitbench.Soa!328LU s
s
.
(field) int* fitbench.Soa!328LU.childCount
childCount
[
(local variable) int i
i
];
} auto
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t0
t0
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 d
d
=
(local variable) int maxD
maxD
- 1; d >= 0; --d)
{ int
(local variable) int c
c
=
(local variable) int[66] start
start
[
(local variable) int d
d
+ 1];
foreach (
(local variable) int j
j
;
(local variable) int[66] start
start
[
(local variable) int d
d
] ..
(local variable) int[66] start
start
[
(local variable) int d
d
+ 1])
{ int
(local variable) int k
k
=
(parameter) fitbench.LevelScratch L
L
.
(field) int* fitbench.LevelScratch.cnt
cnt
[
(local variable) int j
j
];
if (
(local variable) int k
k
== 0)
continue; float
(local variable) float sw
sw
=
(parameter) fitbench.LevelScratch L
L
.
(field) ubyte* fitbench.LevelScratch.axis
axis
[
(local variable) int j
j
] ?
float fitbench.maxRange(const(float)* p, int k)
maxRange
(
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.w
w
+
(local variable) int c
c
,
(local variable) int k
k
) :
float fitbench.sumRange(const(float)* p, int k)
sumRange
(
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.w
w
+
(local variable) int c
c
,
(local variable) int k
k
);
float
(local variable) float sh
sh
=
(parameter) fitbench.LevelScratch L
L
.
(field) ubyte* fitbench.LevelScratch.axis
axis
[
(local variable) int j
j
] ?
float fitbench.sumRange(const(float)* p, int k)
sumRange
(
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.h
h
+
(local variable) int c
c
,
(local variable) int k
k
) :
float fitbench.maxRange(const(float)* p, int k)
maxRange
(
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.h
h
+
(local variable) int c
c
,
(local variable) int k
k
);
float
(local variable) float g
g
=
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.gap
gap
[
(local variable) int j
j
] * (
(local variable) int k
k
- 1);
if (
(parameter) fitbench.LevelScratch L
L
.
(field) ubyte* fitbench.LevelScratch.axis
axis
[
(local variable) int j
j
])
{
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.w
w
[
(local variable) int j
j
] =
(local variable) float sw
sw
+
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.padC
padC
[
(local variable) int j
j
];
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.h
h
[
(local variable) int j
j
] =
(local variable) float sh
sh
+
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.padM
padM
[
(local variable) int j
j
] +
(local variable) float g
g
;
} else {
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.w
w
[
(local variable) int j
j
] =
(local variable) float sw
sw
+
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.padM
padM
[
(local variable) int j
j
] +
(local variable) float g
g
;
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.h
h
[
(local variable) int j
j
] =
(local variable) float sh
sh
+
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.padC
padC
[
(local variable) int j
j
];
}
(local variable) int c
c
+=
(local variable) int k
k
;
} } auto
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t1
t1
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 j
j
; 0 ..
(parameter) int n
n
)
{ int
(local variable) int i
i
=
(parameter) fitbench.LevelScratch L
L
.
(field) int* fitbench.LevelScratch.ord
ord
[
(local variable) int j
j
];
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.sz
sz
[
(local variable) int i
i
][0] =
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.w
w
[
(local variable) int j
j
];
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.sz
sz
[
(local variable) int i
i
][1] =
(parameter) fitbench.LevelScratch L
L
.
(field) float* fitbench.LevelScratch.h
h
[
(local variable) int j
j
];
} return (
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t1
t1
-
core.time.Duration core.time.MonoTimeImpl!(ClockType.normal).opBinary!"-"(core.time.MonoTimeImpl!(ClockType.normal) rhs) const pure nothrow @nogc @safe

Subtracting 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 @safe

Subtracting 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 @system
growAos
(int ax, size_t S)(
(struct) fitbench.Node!128LU

The fat AoS widget record; the first 64 bytes are the layout-relevant head.

Node
!
(constant) ulong fitbench.S = 128LU
S
*
(parameter) fitbench.Node!128LU* nd
nd
, int
(parameter) int n
n
)
{
(parameter) fitbench.Node!128LU* nd
nd
[0].
(field) float[2] fitbench.Node!128LU.fit
fit
[
(constant) int fitbench.ax = 0
ax
] =
(parameter) fitbench.Node!128LU* nd
nd
[0].
(field) float[2] fitbench.Node!128LU.sz
sz
[
(constant) int fitbench.ax = 0
ax
];
(parameter) fitbench.Node!128LU* nd
nd
[0].
(field) float[2] fitbench.Node!128LU.sz
sz
[
(constant) int fitbench.ax = 0
ax
] =
(constant) float[2] fitbench.rootSize = [1920.0F, 1080.0F]
rootSize
[
(constant) int fitbench.ax = 0
ax
];
foreach (
(local variable) int i
i
; 1 ..
(parameter) int n
n
)
{ auto
(local variable) fitbench.Node!128LU* c
c
= &
(parameter) fitbench.Node!128LU* nd
nd
[
(local variable) int i
i
];
auto
(local variable) fitbench.Node!128LU* p
p
= &
(parameter) fitbench.Node!128LU* nd
nd
[
(local variable) fitbench.Node!128LU* c
c
.
(field) int fitbench.Node!128LU.parent
parent
];
(local variable) fitbench.Node!128LU* c
c
.
(field) float[2] fitbench.Node!128LU.fit
fit
[
(constant) int fitbench.ax = 0
ax
] =
(local variable) fitbench.Node!128LU* c
c
.
(field) float[2] fitbench.Node!128LU.sz
sz
[
(constant) int fitbench.ax = 0
ax
];
if ((
(local variable) fitbench.Node!128LU* c
c
.
(field) ubyte fitbench.Node!128LU.grow
grow
>>
(constant) int fitbench.ax = 0
ax
) & 1)
{ if (
(local variable) fitbench.Node!128LU* p
p
.
(field) ubyte fitbench.Node!128LU.axis
axis
==
(constant) int fitbench.ax = 0
ax
)
{ float
(local variable) float extra
extra
= (
(local variable) fitbench.Node!128LU* p
p
.
(field) float[2] fitbench.Node!128LU.sz
sz
[
(constant) int fitbench.ax = 0
ax
] -
(local variable) fitbench.Node!128LU* p
p
.
(field) float[2] fitbench.Node!128LU.fit
fit
[
(constant) int fitbench.ax = 0
ax
]) /
(local variable) fitbench.Node!128LU* p
p
.
(field) int fitbench.Node!128LU.growCount
growCount
;
float
(local variable) float v
v
=
(local variable) fitbench.Node!128LU* c
c
.
(field) float[2] fitbench.Node!128LU.sz
sz
[
(constant) int fitbench.ax = 0
ax
] +
(local variable) float extra
extra
;
(local variable) fitbench.Node!128LU* c
c
.
(field) float[2] fitbench.Node!128LU.sz
sz
[
(constant) int fitbench.ax = 0
ax
] =
(local variable) float v
v
> 0 ?
(local variable) float v
v
: 0;
} else
(local variable) fitbench.Node!128LU* c
c
.
(field) float[2] fitbench.Node!128LU.sz
sz
[
(constant) int fitbench.ax = 0
ax
] =
(local variable) fitbench.Node!128LU* p
p
.
(field) float[2] fitbench.Node!128LU.sz
sz
[
(constant) int fitbench.ax = 0
ax
] -
(local variable) fitbench.Node!128LU* p
p
.
(field) float[2] fitbench.Node!128LU.pad
pad
[
(constant) int fitbench.ax = 0
ax
];
} } } void
void fitbench.positionsAos!328LU(fitbench.Node!328LU* nd, int n, float* cursor) pure nothrow @nogc @system
positionsAos
(size_t S)(
(struct) fitbench.Node!328LU

The fat AoS widget record; the first 64 bytes are the layout-relevant head.

Node
!
(constant) ulong fitbench.S = 328LU
S
*
(parameter) fitbench.Node!328LU* nd
nd
, int
(parameter) int n
n
, float*
(parameter) float* cursor
cursor
)
{
(parameter) fitbench.Node!328LU* nd
nd
[0].
(field) float[2] fitbench.Node!328LU.pos
pos
[0] =
(parameter) fitbench.Node!328LU* nd
nd
[0].
(field) float[2] fitbench.Node!328LU.pos
pos
[1] = 0;
(parameter) float* cursor
cursor
[0] = 0;
foreach (
(local variable) int i
i
; 1 ..
(parameter) int n
n
)
{ auto
(local variable) fitbench.Node!328LU* c
c
= &
(parameter) fitbench.Node!328LU* nd
nd
[
(local variable) int i
i
];
int
(local variable) int pi
pi
=
(local variable) fitbench.Node!328LU* c
c
.
(field) int fitbench.Node!328LU.parent
parent
;
auto
(local variable) fitbench.Node!328LU* p
p
= &
(parameter) fitbench.Node!328LU* nd
nd
[
(local variable) int pi
pi
];
int
(local variable) int a
a
=
(local variable) fitbench.Node!328LU* p
p
.
(field) ubyte fitbench.Node!328LU.axis
axis
;
(local variable) fitbench.Node!328LU* c
c
.
(field) float[2] fitbench.Node!328LU.pos
pos
[
(local variable) int a
a
] =
(local variable) fitbench.Node!328LU* p
p
.
(field) float[2] fitbench.Node!328LU.pos
pos
[
(local variable) int a
a
] +
(local variable) fitbench.Node!328LU* p
p
.
(field) float[2] fitbench.Node!328LU.pad
pad
[
(local variable) int a
a
] * 0.5f +
(parameter) float* cursor
cursor
[
(local variable) int pi
pi
];
(local variable) fitbench.Node!328LU* c
c
.
(field) float[2] fitbench.Node!328LU.pos
pos
[1 -
(local variable) int a
a
] =
(local variable) fitbench.Node!328LU* p
p
.
(field) float[2] fitbench.Node!328LU.pos
pos
[1 -
(local variable) int a
a
] +
(local variable) fitbench.Node!328LU* p
p
.
(field) float[2] fitbench.Node!328LU.pad
pad
[1 -
(local variable) int a
a
] * 0.5f;
(parameter) float* cursor
cursor
[
(local variable) int pi
pi
] +=
(local variable) fitbench.Node!328LU* c
c
.
(field) float[2] fitbench.Node!328LU.sz
sz
[
(local variable) int a
a
] +
(local variable) fitbench.Node!328LU* p
p
.
(field) float fitbench.Node!328LU.gap
gap
;
(parameter) float* cursor
cursor
[
(local variable) int i
i
] = 0;
} } void
void fitbench.growSoa!(0, 128LU)(ref fitbench.Soa!128LU s, int n) pure nothrow @nogc @system
growSoa
(int ax, size_t S)(ref
(struct) fitbench.Soa!128LU
Soa
!
(constant) ulong fitbench.S = 128LU
S
(parameter) fitbench.Soa!128LU s
s
, int
(parameter) int n
n
)
{ auto
(local variable) float[2]* sz
sz
=
(parameter) fitbench.Soa!128LU s
s
.
(field) float[2]* fitbench.Soa!128LU.sz
sz
,
(local variable) float[2]* fit
fit
=
(parameter) fitbench.Soa!128LU s
s
.
(field) float[2]* fitbench.Soa!128LU.fit
fit
,
(local variable) ubyte* fl
fl
=
(parameter) fitbench.Soa!128LU s
s
.
(field) ubyte* fitbench.Soa!128LU.flags
flags
,
(local variable) int* par
par
=
(parameter) fitbench.Soa!128LU s
s
.
(field) int* fitbench.Soa!128LU.parent
parent
,
(local variable) int* gc
gc
=
(parameter) fitbench.Soa!128LU s
s
.
(field) int* fitbench.Soa!128LU.growCount
growCount
,
(local variable) float[2]* pad
pad
=
(parameter) fitbench.Soa!128LU s
s
.
(field) float[2]* fitbench.Soa!128LU.pad
pad
;
(local variable) float[2]* fit
fit
[0][
(constant) int fitbench.ax = 0
ax
] =
(local variable) float[2]* sz
sz
[0][
(constant) int fitbench.ax = 0
ax
];
(local variable) float[2]* sz
sz
[0][
(constant) int fitbench.ax = 0
ax
] =
(constant) float[2] fitbench.rootSize = [1920.0F, 1080.0F]
rootSize
[
(constant) int fitbench.ax = 0
ax
];
foreach (
(local variable) int i
i
; 1 ..
(parameter) int n
n
)
{ int
(local variable) int p
p
=
(local variable) int* par
par
[
(local variable) int i
i
];
(local variable) float[2]* fit
fit
[
(local variable) int i
i
][
(constant) int fitbench.ax = 0
ax
] =
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][
(constant) int fitbench.ax = 0
ax
];
if ((
(local variable) ubyte* fl
fl
[
(local variable) int i
i
] >> (1 +
(constant) int fitbench.ax = 0
ax
)) & 1)
{ if ((
(local variable) ubyte* fl
fl
[
(local variable) int p
p
] & 1) ==
(constant) int fitbench.ax = 0
ax
)
{ float
(local variable) float extra
extra
= (
(local variable) float[2]* sz
sz
[
(local variable) int p
p
][
(constant) int fitbench.ax = 0
ax
] -
(local variable) float[2]* fit
fit
[
(local variable) int p
p
][
(constant) int fitbench.ax = 0
ax
]) /
(local variable) int* gc
gc
[
(local variable) int p
p
];
float
(local variable) float v
v
=
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][
(constant) int fitbench.ax = 0
ax
] +
(local variable) float extra
extra
;
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][
(constant) int fitbench.ax = 0
ax
] =
(local variable) float v
v
> 0 ?
(local variable) float v
v
: 0;
} else
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][
(constant) int fitbench.ax = 0
ax
] =
(local variable) float[2]* sz
sz
[
(local variable) int p
p
][
(constant) int fitbench.ax = 0
ax
] -
(local variable) float[2]* pad
pad
[
(local variable) int p
p
][
(constant) int fitbench.ax = 0
ax
];
} } } void
void fitbench.positionsSoa!328LU(ref fitbench.Soa!328LU s, int n, float* cursor) pure nothrow @nogc @system
positionsSoa
(size_t S)(ref
(struct) fitbench.Soa!328LU
Soa
!
(constant) ulong fitbench.S = 328LU
S
(parameter) fitbench.Soa!328LU s
s
, int
(parameter) int n
n
, float*
(parameter) float* cursor
cursor
)
{ auto
(local variable) float[2]* sz
sz
=
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.sz
sz
,
(local variable) float[2]* pos
pos
=
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.pos
pos
,
(local variable) ubyte* fl
fl
=
(parameter) fitbench.Soa!328LU s
s
.
(field) ubyte* fitbench.Soa!328LU.flags
flags
,
(local variable) int* par
par
=
(parameter) fitbench.Soa!328LU s
s
.
(field) int* fitbench.Soa!328LU.parent
parent
,
(local variable) float[2]* pad
pad
=
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.pad
pad
,
(local variable) float* gap
gap
=
(parameter) fitbench.Soa!328LU s
s
.
(field) float* fitbench.Soa!328LU.gap
gap
;
(local variable) float[2]* pos
pos
[0][0] =
(local variable) float[2]* pos
pos
[0][1] = 0;
(parameter) float* cursor
cursor
[0] = 0;
foreach (
(local variable) int i
i
; 1 ..
(parameter) int n
n
)
{ int
(local variable) int p
p
=
(local variable) int* par
par
[
(local variable) int i
i
];
int
(local variable) int a
a
=
(local variable) ubyte* fl
fl
[
(local variable) int p
p
] & 1;
(local variable) float[2]* pos
pos
[
(local variable) int i
i
][
(local variable) int a
a
] =
(local variable) float[2]* pos
pos
[
(local variable) int p
p
][
(local variable) int a
a
] +
(local variable) float[2]* pad
pad
[
(local variable) int p
p
][
(local variable) int a
a
] * 0.5f +
(parameter) float* cursor
cursor
[
(local variable) int p
p
];
(local variable) float[2]* pos
pos
[
(local variable) int i
i
][1 -
(local variable) int a
a
] =
(local variable) float[2]* pos
pos
[
(local variable) int p
p
][1 -
(local variable) int a
a
] +
(local variable) float[2]* pad
pad
[
(local variable) int p
p
][1 -
(local variable) int a
a
] * 0.5f;
(parameter) float* cursor
cursor
[
(local variable) int p
p
] +=
(local variable) float[2]* sz
sz
[
(local variable) int i
i
][
(local variable) int a
a
] +
(local variable) float* gap
gap
[
(local variable) int p
p
];
(parameter) float* cursor
cursor
[
(local variable) int i
i
] = 0;
} } // --------------------------------------------------------------------------- // Checksums // --------------------------------------------------------------------------- ulong
ulong fitbench.mix(ulong h, float f)
mix
(ulong
(parameter) ulong h
h
, float
(parameter) float f
f
) => (
(parameter) ulong h
h
^ *cast(uint*)&
(parameter) float f
f
) * 0x100000001b3UL;
ulong
ulong fitbench.sumAos!328LU(fitbench.Node!328LU* nd, int n, bool withPos) @system
sumAos
(size_t S)(
(struct) fitbench.Node!328LU

The fat AoS widget record; the first 64 bytes are the layout-relevant head.

Node
!
(constant) ulong fitbench.S = 328LU
S
*
(parameter) fitbench.Node!328LU* nd
nd
, int
(parameter) int n
n
, bool
(parameter) bool withPos
withPos
)
{ ulong
(local variable) ulong h
h
= 0xcbf29ce484222325UL;
foreach (
(local variable) int i
i
; 0 ..
(parameter) int n
n
)
{
(local variable) ulong h
h
=
ulong fitbench.mix(ulong h, float f)
mix
(
ulong fitbench.mix(ulong h, float f)
mix
(
(local variable) ulong h
h
,
(parameter) fitbench.Node!328LU* nd
nd
[
(local variable) int i
i
].
(field) float[2] fitbench.Node!328LU.sz
sz
[0]),
(parameter) fitbench.Node!328LU* nd
nd
[
(local variable) int i
i
].
(field) float[2] fitbench.Node!328LU.sz
sz
[1]);
if (
(parameter) bool withPos
withPos
)
(local variable) ulong h
h
=
ulong fitbench.mix(ulong h, float f)
mix
(
ulong fitbench.mix(ulong h, float f)
mix
(
(local variable) ulong h
h
,
(parameter) fitbench.Node!328LU* nd
nd
[
(local variable) int i
i
].
(field) float[2] fitbench.Node!328LU.pos
pos
[0]),
(parameter) fitbench.Node!328LU* nd
nd
[
(local variable) int i
i
].
(field) float[2] fitbench.Node!328LU.pos
pos
[1]);
} return
(local variable) ulong h
h
;
} ulong
ulong fitbench.sumSoa!328LU(ref fitbench.Soa!328LU s, int n, bool withPos) @system
sumSoa
(size_t S)(ref
(constant) ulong fitbench.S = 64LU
Soa
!
(constant) ulong fitbench.S = 328LU
S
(parameter) fitbench.Soa!328LU s
s
, int
(parameter) int n
n
, bool
(parameter) bool withPos
withPos
)
{ ulong
(local variable) ulong h
h
= 0xcbf29ce484222325UL;
foreach (
(local variable) int i
i
; 0 ..
(parameter) int n
n
)
{
(local variable) ulong h
h
=
ulong fitbench.mix(ulong h, float f)
mix
(
ulong fitbench.mix(ulong h, float f)
mix
(
(local variable) ulong h
h
,
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.sz
sz
[
(local variable) int i
i
][0]),
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.sz
sz
[
(local variable) int i
i
][1]);
if (
(parameter) bool withPos
withPos
)
(local variable) ulong h
h
=
ulong fitbench.mix(ulong h, float f)
mix
(
ulong fitbench.mix(ulong h, float f)
mix
(
(local variable) ulong h
h
,
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.pos
pos
[
(local variable) int i
i
][0]),
(parameter) fitbench.Soa!328LU s
s
.
(field) float[2]* fitbench.Soa!328LU.pos
pos
[
(local variable) int i
i
][1]);
} return
(local variable) ulong h
h
;
} // --------------------------------------------------------------------------- // perf_event_open counters (in-process, around the timed region only) // --------------------------------------------------------------------------- extern (C) long
long fitbench.syscall(long, ...) nothrow @nogc
syscall
(long, ...) nothrow @nogc;
extern (C) int
int fitbench.ioctl(int, ulong, ...) nothrow @nogc
ioctl
(int, ulong, ...) nothrow @nogc;
import
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(module) core.sys.posix.unistd

D header file for POSIX.

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0.@authorsSean Kelly@standardsThe Open Group Base Specifications Issue 8, IEEE Std 1003.1, 2024 Edition
unistd
:
(alias) fitbench.read = long core.sys.posix.unistd.read(int, void*, ulong) nothrow @nogc
read
,
(alias) fitbench.close = int core.sys.posix.unistd.close(int) nothrow @nogc @trusted
close
;
struct
(struct) fitbench.PerfAttr
PerfAttr
{ uint
(field) uint fitbench.PerfAttr.type
type
,
(field) uint fitbench.PerfAttr.size
size
;
ulong
(field) ulong fitbench.PerfAttr.config
config
,
(field) ulong fitbench.PerfAttr.samplePeriod
samplePeriod
,
(field) ulong fitbench.PerfAttr.sampleType
sampleType
,
(field) ulong fitbench.PerfAttr.readFormat
readFormat
,
(field) ulong fitbench.PerfAttr.flags
flags
;
uint
(field) uint fitbench.PerfAttr.wakeup
wakeup
,
(field) uint fitbench.PerfAttr.bpType
bpType
;
ulong
(field) ulong fitbench.PerfAttr.config1
config1
;
} static assert(
(struct) fitbench.PerfAttr
PerfAttr
.
(constant) ulong fitbench.PerfAttr.sizeof = 64LU
sizeof
== 64);
enum
(constant) int fitbench.nCtr = 5
nCtr
= 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 = 5
nCtr
]
(immutable global) immutable(uint[5]) fitbench.ctrTypes
ctrTypes
= [0, 0, 3, 0, 4];
immutable ulong[
(constant) int fitbench.nCtr = 5
nCtr
]
(immutable global) immutable(ulong[5]) fitbench.ctrCfgs
ctrCfgs
= [0, 1, 0 | (0 << 8) | (1 << 16), 3, 0x4844];
struct
(struct) fitbench.Perf
Perf
{ int
(field) int fitbench.Perf.leader
leader
= -1;
int[
(constant) int fitbench.nCtr = 5
nCtr
]
(field) int[5] fitbench.Perf.slot
slot
= -1; // position in group read
int
(field) int fitbench.Perf.nOpen
nOpen
;
void
void fitbench.Perf.open()
open
()
{ foreach (
(local variable) int k
k
; 0 ..
(constant) int fitbench.nCtr = 5
nCtr
)
{
(struct) fitbench.PerfAttr
PerfAttr
(local variable) fitbench.PerfAttr a
a
;
(local variable) fitbench.PerfAttr a
a
.
(field) uint fitbench.PerfAttr.type
type
=
(immutable global) immutable(uint[5]) fitbench.ctrTypes
ctrTypes
[
(local variable) int k
k
];
(local variable) fitbench.PerfAttr a
a
.
(field) uint fitbench.PerfAttr.size
size
=
(struct) fitbench.PerfAttr
PerfAttr
.
(constant) ulong fitbench.PerfAttr.sizeof = 64LU
sizeof
;
(local variable) fitbench.PerfAttr a
a
.
(field) ulong fitbench.PerfAttr.config
config
=
(immutable global) immutable(ulong[5]) fitbench.ctrCfgs
ctrCfgs
[
(local variable) int k
k
];
(local variable) fitbench.PerfAttr a
a
.
(field) ulong fitbench.PerfAttr.readFormat
readFormat
= 8 | 1 | 2; // GROUP | TIME_ENABLED | TIME_RUNNING
(local variable) fitbench.PerfAttr a
a
.
(field) ulong fitbench.PerfAttr.flags
flags
= (
(field) int fitbench.Perf.leader
leader
< 0 ? 1 : 0) | (1 << 5) | (1 << 6); // disabled(leader), excl kernel, hv
int
(local variable) int f
f
= cast(int)
long fitbench.syscall(long, ...) nothrow @nogc
syscall
(298, &
(local variable) fitbench.PerfAttr a
a
, 0, -1,
(field) int fitbench.Perf.leader
leader
, 0UL);
if (
(local variable) int f
f
< 0)
continue; if (
(field) int fitbench.Perf.leader
leader
< 0)
(field) int fitbench.Perf.leader
leader
=
(local variable) int f
f
;
(field) int[5] fitbench.Perf.slot
slot
[
(local variable) int k
k
] =
(field) int fitbench.Perf.nOpen
nOpen
++;
} } void
void fitbench.Perf.start()
start
()
{ if (
(field) int fitbench.Perf.leader
leader
< 0)
return;
int fitbench.ioctl(int, ulong, ...) nothrow @nogc
ioctl
(
(field) int fitbench.Perf.leader
leader
, 0x2403, 1); // RESET, group
int fitbench.ioctl(int, ulong, ...) nothrow @nogc
ioctl
(
(field) int fitbench.Perf.leader
leader
, 0x2400, 1); // ENABLE, group
} void
void fitbench.Perf.stop()
stop
()
{ if (
(field) int fitbench.Perf.leader
leader
>= 0)
int fitbench.ioctl(int, ulong, ...) nothrow @nogc
ioctl
(
(field) int fitbench.Perf.leader
leader
, 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 = 5
nCtr
]
(parameter) ulong[5] out_
out_
)
{
(parameter) ulong[5] out_
out_
[] = 0;
if (
(field) int fitbench.Perf.leader
leader
< 0)
return false; ulong[3 +
(constant) int fitbench.nCtr = 5
nCtr
]
(local variable) ulong[8] buf
buf
;
if (
long core.sys.posix.unistd.read(int, void*, ulong) nothrow @nogc
read
(
(field) int fitbench.Perf.leader
leader
,
(local variable) ulong[8] buf
buf
.
(constant) ulong* ulong[8].ptr = &buf
ptr
,
(local variable) ulong[8] buf
buf
.
(constant) ulong ulong[8].sizeof = 64LU
sizeof
) <= 0)
return false; foreach (
(local variable) int k
k
; 0 ..
(constant) int fitbench.nCtr = 5
nCtr
)
if (
(field) int[5] fitbench.Perf.slot
slot
[
(local variable) int k
k
] >= 0)
(parameter) ulong[5] out_
out_
[
(local variable) int k
k
] =
(local variable) ulong[8] buf
buf
[3 +
(field) int[5] fitbench.Perf.slot
slot
[
(local variable) int k
k
]];
return
(local variable) ulong[8] buf
buf
[1] ==
(local variable) ulong[8] buf
buf
[2];
} } // --------------------------------------------------------------------------- // Harness // --------------------------------------------------------------------------- struct
(struct) fitbench.Result
Result
{
(alias) object.string = string
string
(field) string fitbench.Result.variant
variant
;
double
(field) double fitbench.Result.total
total
,
(field) double fitbench.Result.build
build
,
(field) double fitbench.Result.pass
pass
,
(field) double fitbench.Result.aux
aux
; // medians, ns/node
double[
(constant) int fitbench.nCtr = 5
nCtr
]
(field) double[5] fitbench.Result.ctr
ctr
; // medians, per node, whole timed region
double[
(constant) int fitbench.nCtr = 5
nCtr
]
(field) double[5] fitbench.Result.passCtr
passCtr
; // medians, per node, pass only
ulong
(field) ulong fitbench.Result.checksum
checksum
;
} double
double fitbench.median(double[] xs)
median
(double[]
(parameter) double[] xs
xs
)
{
std.range.SortedRange!(double[], "a < b", SortedRangeOptions.assumeSorted) std.algorithm.sorting.sort!("a < b", SwapStrategy.unstable, double[])(double[] r) pure nothrow @nogc @safe

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.

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));
@paramless The predicate to sort by.@paramss The swapping strategy to use.@paramr The range to sort.@returnsThe initial range wrapped as a SortedRange with the predicate binaryFun!less.@see

assumeSorted

SortedRange

SwapStrategy

binaryFun

sort
(
(parameter) double[] xs
xs
);
return
(parameter) double[] xs
xs
.
(field) ulong double[].length
length
% 2 ?
(parameter) double[] xs
xs
[$ / 2] : (
(parameter) double[] xs
xs
[$ / 2 - 1] +
(parameter) double[] xs
xs
[$ / 2]) / 2;
} int
(thread local global) int fitbench.reps
reps
= 21;
enum
(constant) int fitbench.warmup = 3
warmup
= 3;
(struct) fitbench.Perf
Perf
(thread local global) fitbench.Perf fitbench.perf
perf
;
ulong[
(constant) int fitbench.nCtr = 5
nCtr
][3]
(constant) int fitbench.nCtr = 5
snaps
;
bool[3]
(thread local global) bool[3] fitbench.marked
marked
;
bool
(thread local global) bool fitbench.multiplexed
multiplexed
;
/// 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 k
k
)
{ if (!
(thread local global) fitbench.Perf fitbench.perf
perf
.
bool fitbench.Perf.snap(ref ulong[5] out_)

Reads the running group; returns false if multiplexed.

snap
(
(thread local global) ulong[5][3] fitbench.snaps
snaps
[
(parameter) int k
k
]))
(thread local global) bool fitbench.multiplexed
multiplexed
=
(thread local global) fitbench.Perf fitbench.perf
perf
.
(field) int fitbench.Perf.leader
leader
>= 0;
(thread local global) bool[3] fitbench.marked
marked
[
(parameter) int k
k
] = true;
}
(struct) fitbench.Result
Result
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 = string
string
(parameter) string name
name
, int
(parameter) int n
n
, scope void delegate(out long, out long, out long)
(parameter) void delegate(out long, out long, out long) run
run
, scope ulong delegate()
(parameter) ulong delegate() check
check
)
{ double[]
(local variable) double[] tot
tot
,
(local variable) double[] bld
bld
,
(local variable) double[] pas
pas
,
(local variable) double[] aux
aux
;
double[][
(constant) int fitbench.nCtr = 5
nCtr
]
(local variable) double[][5] cs
cs
,
(local variable) double[][5] ps
ps
;
foreach (
(local variable) int r
r
; 0 ..
(constant) int fitbench.warmup = 3
warmup
+
(thread local global) int fitbench.reps
reps
)
{ long
(local variable) long b
b
,
(local variable) long p
p
,
(local variable) long x
x
;
(thread local global) bool[3] fitbench.marked
marked
[] = false;
(thread local global) fitbench.Perf fitbench.perf
perf
.
void fitbench.Perf.start()
start
();
(parameter) void delegate(out long, out long, out long) run
run
(
(local variable) long b
b
,
(local variable) long p
p
,
(local variable) long x
x
);
(thread local global) fitbench.Perf fitbench.perf
perf
.
void fitbench.Perf.stop()
stop
();
if (!
(thread local global) bool[3] fitbench.marked
marked
[2])
(thread local global) ulong[5][3] fitbench.snaps
snaps
[2] =
(thread local global) ulong[5][3] fitbench.snaps
snaps
[1];
if (
(local variable) int r
r
<
(constant) int fitbench.warmup = 3
warmup
)
continue;
(local variable) double[] tot
tot
~= cast(double)(
(local variable) long b
b
+
(local variable) long p
p
) /
(parameter) int n
n
;
(local variable) double[] bld
bld
~= cast(double)
(local variable) long b
b
/
(parameter) int n
n
;
(local variable) double[] pas
pas
~= cast(double)
(local variable) long p
p
/
(parameter) int n
n
;
(local variable) double[] aux
aux
~= cast(double)
(local variable) long x
x
/
(parameter) int n
n
;
foreach (
(local variable) int k
k
; 0 ..
(constant) int fitbench.nCtr = 5
nCtr
)
{
(local variable) double[][5] cs
cs
[
(local variable) int k
k
] ~= cast(double)(
(thread local global) ulong[5][3] fitbench.snaps
snaps
[2][
(local variable) int k
k
] -
(thread local global) ulong[5][3] fitbench.snaps
snaps
[0][
(local variable) int k
k
]) /
(parameter) int n
n
;
(local variable) double[][5] ps
ps
[
(local variable) int k
k
] ~= cast(double)(
(thread local global) ulong[5][3] fitbench.snaps
snaps
[2][
(local variable) int k
k
] -
(thread local global) ulong[5][3] fitbench.snaps
snaps
[1][
(local variable) int k
k
]) /
(parameter) int n
n
;
} }
(struct) fitbench.Result
Result
(local variable) fitbench.Result res
res
;
(local variable) fitbench.Result res
res
.
(field) string fitbench.Result.variant
variant
=
(parameter) string name
name
;
(local variable) fitbench.Result res
res
.
(field) double fitbench.Result.total
total
=
double fitbench.median(double[] xs)
median
(
(local variable) double[] tot
tot
);
(local variable) fitbench.Result res
res
.
(field) double fitbench.Result.build
build
=
double fitbench.median(double[] xs)
median
(
(local variable) double[] bld
bld
);
(local variable) fitbench.Result res
res
.
(field) double fitbench.Result.pass
pass
=
double fitbench.median(double[] xs)
median
(
(local variable) double[] pas
pas
);
(local variable) fitbench.Result res
res
.
(field) double fitbench.Result.aux
aux
=
double fitbench.median(double[] xs)
median
(
(local variable) double[] aux
aux
);
foreach (
(local variable) int k
k
; 0 ..
(constant) int fitbench.nCtr = 5
nCtr
)
{
(local variable) fitbench.Result res
res
.
(field) double[5] fitbench.Result.ctr
ctr
[
(local variable) int k
k
] =
(thread local global) fitbench.Perf fitbench.perf
perf
.
(field) int[5] fitbench.Perf.slot
slot
[
(local variable) int k
k
] >= 0 ?
double fitbench.median(double[] xs)
median
(
(local variable) double[][5] cs
cs
[
(local variable) int k
k
]) : double.
(constant) double double.nan = nan
nan
;
(local variable) fitbench.Result res
res
.
(field) double[5] fitbench.Result.passCtr
passCtr
[
(local variable) int k
k
] =
(thread local global) fitbench.Perf fitbench.perf
perf
.
(field) int[5] fitbench.Perf.slot
slot
[
(local variable) int k
k
] >= 0 ?
double fitbench.median(double[] xs)
median
(
(local variable) double[][5] ps
ps
[
(local variable) int k
k
]) : double.
(constant) double double.nan = nan
nan
;
}
(local variable) fitbench.Result res
res
.
(field) ulong fitbench.Result.checksum
checksum
=
(parameter) ulong delegate() check
check
();
return
(local variable) fitbench.Result res
res
;
} long
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
(parameter) core.time.MonoTimeImpl!(ClockType.normal) t
t
) => (
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 @safe

Subtracting 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 @safe

Subtracting 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.Result
Result
[]
fitbench.Result[] fitbench.runConfig!328LU(const(fitbench.Ev)[] evs, const(char)* pool, int n, string[] only) @system
runConfig
(size_t S)(const(
(struct) fitbench.Ev
Ev
)[]
(parameter) const(fitbench.Ev)[] evs
evs
, const(char)*
(parameter) const(char)* pool
pool
, int
(parameter) int n
n
,
(alias) object.string = string
string
[]
(parameter) string[] only
only
)
{
(struct) fitbench.Result
Result
[]
(local variable) fitbench.Result[] out_
out_
;
bool
bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safe
want
(
(alias) object.string = string
string
(parameter) string v
v
) =>
(parameter) string[] only
only
.
(field) ulong string[].length
length
== 0 ||
(parameter) string[] only
only
.
bool std.algorithm.searching.canFind!().canFind!(string[], string)(string[] haystack, scope string needle) pure nothrow @nogc @safe

Convenience 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")));
@see

among for checking a value against multiple arguments.

Returns true if and only if needle can be found in range. Performs O(haystack.length) evaluations of pred.

canFind
(
(parameter) string v
v
);
auto
(local variable) fitbench.Node!328LU* aos
aos
= cast(
(constant) ulong fitbench.S = 328LU
Node
!
(constant) ulong fitbench.S = 328LU
S
*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(cast(
(alias) object.size_t = ulong
size_t
)
(parameter) int n
n
*
(constant) ulong fitbench.S = 328LU
Node
!
(constant) ulong fitbench.S = 328LU
S
.
(constant) ulong fitbench.Node!328LU.sizeof = 328LU
sizeof
);
(constant) ulong fitbench.S = 328LU
Soa
!
(constant) ulong fitbench.S = 328LU
S
(local variable) fitbench.Soa!328LU soa
soa
;
(local variable) fitbench.Soa!328LU soa
soa
.
void fitbench.Soa!328LU.alloc(ulong n) nothrow @nogc @system
alloc
(
(parameter) int n
n
);
(struct) fitbench.LevelScratch

Scratch for the level-order variant.

LevelScratch
(local variable) fitbench.LevelScratch L
L
;
(local variable) fitbench.LevelScratch L
L
.
void fitbench.LevelScratch.alloc(ulong n)
alloc
(
(parameter) int n
n
);
auto
(local variable) float* cursor
cursor
= cast(float*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(parameter) int n
n
* 4);
scope (exit) {
void core.stdc.stdlib.free(void* ptr) nothrow @nogc
free
(
(local variable) fitbench.Node!328LU* aos
aos
);
(local variable) fitbench.Soa!328LU soa
soa
.
void fitbench.Soa!328LU.release() nothrow @nogc @system
release
();
(local variable) fitbench.LevelScratch L
L
.
void fitbench.LevelScratch.release()
release
();
void core.stdc.stdlib.free(void* ptr) nothrow @nogc
free
(
(local variable) float* cursor
cursor
);
} if (
bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safe
want
("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 n
n
, (out long
(parameter) long b
b
, out long
(parameter) long p
p
, out long
(parameter) long x
x
) {
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) t
t
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 = 128LU
buildAos
!(true,
(constant) ulong fitbench.S = 328LU
S
)(
(parameter) const(fitbench.Ev)[] evs
evs
,
(parameter) const(char)* pool
pool
,
(local variable) fitbench.Node!328LU* aos
aos
);
(parameter) long b
b
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
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) @system
sumAos
(
(local variable) fitbench.Node!328LU* aos
aos
,
(parameter) int n
n
, false));
if (
bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safe
want
("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 n
n
, (out long
(parameter) long b
b
, out long
(parameter) long p
p
, out long
(parameter) long x
x
) {
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) t
t
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 = 128LU
buildAos
!(false,
(constant) ulong fitbench.S = 328LU
S
)(
(parameter) const(fitbench.Ev)[] evs
evs
,
(parameter) const(char)* pool
pool
,
(local variable) fitbench.Node!328LU* aos
aos
);
(parameter) long b
b
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
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) t
t
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 @system
fitSweepAos
(
(local variable) fitbench.Node!328LU* aos
aos
,
(parameter) int n
n
);
(parameter) long p
p
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
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) @system
sumAos
(
(local variable) fitbench.Node!328LU* aos
aos
,
(parameter) int n
n
, false));
if (
bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safe
want
("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 n
n
, (out long
(parameter) long b
b
, out long
(parameter) long p
p
, out long
(parameter) long x
x
) {
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) t
t
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 = 64LU
buildSoa
!(true, false,
(constant) ulong fitbench.S = 328LU
S
)(
(parameter) const(fitbench.Ev)[] evs
evs
,
(parameter) const(char)* pool
pool
,
(local variable) fitbench.Soa!328LU soa
soa
);
(parameter) long b
b
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
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) @system
sumSoa
(
(local variable) fitbench.Soa!328LU soa
soa
,
(parameter) int n
n
, false));
if (
bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safe
want
("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 n
n
, (out long
(parameter) long b
b
, out long
(parameter) long p
p
, out long
(parameter) long x
x
) {
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) t
t
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 = 64LU
buildSoa
!(false, false,
(constant) ulong fitbench.S = 328LU
S
)(
(parameter) const(fitbench.Ev)[] evs
evs
,
(parameter) const(char)* pool
pool
,
(local variable) fitbench.Soa!328LU soa
soa
);
(parameter) long b
b
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
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) t
t
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 @system
fitSweepSoa
(
(local variable) fitbench.Soa!328LU soa
soa
,
(parameter) int n
n
);
(parameter) long p
p
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
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) @system
sumSoa
(
(local variable) fitbench.Soa!328LU soa
soa
,
(parameter) int n
n
, false));
if (
bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safe
want
("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 n
n
, (out long
(parameter) long b
b
, out long
(parameter) long p
p
, out long
(parameter) long x
x
) {
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) t
t
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 = 64LU
buildSoa
!(false, false,
(constant) ulong fitbench.S = 328LU
S
)(
(parameter) const(fitbench.Ev)[] evs
evs
,
(parameter) const(char)* pool
pool
,
(local variable) fitbench.Soa!328LU soa
soa
);
(parameter) long b
b
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
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) t
t
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 @system

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.

fitSweepSoaRc
(
(local variable) fitbench.Soa!328LU soa
soa
,
(parameter) int n
n
);
(parameter) long p
p
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
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) @system
sumSoa
(
(local variable) fitbench.Soa!328LU soa
soa
,
(parameter) int n
n
, false));
if (
bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safe
want
("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 n
n
, (out long
(parameter) long b
b
, out long
(parameter) long p
p
, out long
(parameter) long x
x
) {
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) t
t
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 = 64LU
buildSoa
!(false, true,
(constant) ulong fitbench.S = 328LU
S
)(
(parameter) const(fitbench.Ev)[] evs
evs
,
(parameter) const(char)* pool
pool
,
(local variable) fitbench.Soa!328LU soa
soa
);
(parameter) long b
b
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
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) t
t
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 x
x
=
long fitbench.fitLevel!328LU(ref fitbench.Soa!328LU s, ref fitbench.LevelScratch L, int n) @system

Returns ns spent in the pure level reduction (for the breakdown).

fitLevel
(
(local variable) fitbench.Soa!328LU soa
soa
,
(local variable) fitbench.LevelScratch L
L
,
(parameter) int n
n
);
(parameter) long p
p
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
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) @system
sumSoa
(
(local variable) fitbench.Soa!328LU soa
soa
,
(parameter) int n
n
, 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 @safe
want
("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 n
n
, (out long
(parameter) long b
b
, out long
(parameter) long p
p
, out long
(parameter) long x
x
) {
int fitbench.buildAos!(true, 328LU)(const(fitbench.Ev)[] evs, const(char)* pool, fitbench.Node!328LU* nodes) @system
buildAos
!(true,
(constant) ulong fitbench.S = 328LU
S
)(
(parameter) const(fitbench.Ev)[] evs
evs
,
(parameter) const(char)* pool
pool
,
(local variable) fitbench.Node!328LU* aos
aos
);
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) t
t
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 @system
growAos
!(0,
(constant) ulong fitbench.S = 328LU
S
)(
(local variable) fitbench.Node!328LU* aos
aos
,
(parameter) int n
n
);
void fitbench.growAos!(1, 328LU)(fitbench.Node!328LU* nd, int n) pure nothrow @nogc @system
growAos
!(1,
(constant) ulong fitbench.S = 328LU
S
)(
(local variable) fitbench.Node!328LU* aos
aos
,
(parameter) int n
n
);
(parameter) long x
x
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
); // grow x+y
void fitbench.positionsAos!328LU(fitbench.Node!328LU* nd, int n, float* cursor) pure nothrow @nogc @system
positionsAos
(
(local variable) fitbench.Node!328LU* aos
aos
,
(parameter) int n
n
,
(local variable) float* cursor
cursor
);
(parameter) long p
p
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
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) @system
sumAos
(
(local variable) fitbench.Node!328LU* aos
aos
,
(parameter) int n
n
, true));
if (
bool fitbench.runConfig!328LU.want(string v) pure nothrow @nogc @safe
want
("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 n
n
, (out long
(parameter) long b
b
, out long
(parameter) long p
p
, out long
(parameter) long x
x
) {
int fitbench.buildSoa!(true, false, 328LU)(const(fitbench.Ev)[] evs, const(char)* pool, ref fitbench.Soa!328LU s) @system
buildSoa
!(true, false,
(constant) ulong fitbench.S = 328LU
S
)(
(parameter) const(fitbench.Ev)[] evs
evs
,
(parameter) const(char)* pool
pool
,
(local variable) fitbench.Soa!328LU soa
soa
);
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) t
t
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The 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 @system
growSoa
!(0,
(constant) ulong fitbench.S = 328LU
S
)(
(local variable) fitbench.Soa!328LU soa
soa
,
(parameter) int n
n
);
void fitbench.growSoa!(1, 328LU)(ref fitbench.Soa!328LU s, int n) pure nothrow @nogc @system
growSoa
!(1,
(constant) ulong fitbench.S = 328LU
S
)(
(local variable) fitbench.Soa!328LU soa
soa
,
(parameter) int n
n
);
(parameter) long x
x
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
void fitbench.positionsSoa!328LU(ref fitbench.Soa!328LU s, int n, float* cursor) pure nothrow @nogc @system
positionsSoa
(
(local variable) fitbench.Soa!328LU soa
soa
,
(parameter) int n
n
,
(local variable) float* cursor
cursor
);
(parameter) long p
p
=
long fitbench.since(core.time.MonoTimeImpl!(ClockType.normal) t)
since
(
(local variable) core.time.MonoTimeImpl!(ClockType.normal) t
t
);
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) @system
sumSoa
(
(local variable) fitbench.Soa!328LU soa
soa
,
(parameter) int n
n
, true));
return
(local variable) fitbench.Result[] out_
out_
;
} void
void D main(string[] args)
main
(
(alias) object.string = string
string
[]
(parameter) string[] args
args
)
{
(alias) object.string = string
string
[]
(local variable) string[] shapes
shapes
= ["list", "panels"];
int[]
(local variable) int[] ns
ns
= [1_000, 10_000, 100_000, 1_000_000];
int[]
(local variable) int[] fats
fats
= [64, 128, 328];
(alias) object.string = string
string
[]
(local variable) string[] only
only
;
for (
(alias) object.size_t = ulong
size_t
(local variable) ulong i
i
= 1; i < args.length; ++i)
{ auto
(local variable) string v
v
=
(local variable) ulong i
i
+ 1 <
(parameter) string[] args
args
.
(field) ulong string[].length
length
?
(parameter) string[] args
args
[
(local variable) ulong i
i
+ 1] : "";
switch (
(parameter) string[] args
args
[
(local variable) ulong i
i
])
{ case "--shape":
(local variable) string[] shapes
shapes
=
(local variable) string v
v
.
string[] std.array.split!(string, string)(string range, string sep) pure nothrow @safe
split
(","); ++
(local variable) ulong i
i
; break;
case "--n":
(local variable) int[] ns
ns
=
(local variable) string v
v
.
string[] std.array.split!(string, string)(string range, string sep) pure nothrow @safe
split
(",").
int[] std.conv.to!(int[]).to!(string[])(string[] __param_0) pure @safe

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

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 i
i
; break;
case "--fat":
(local variable) int[] fats
fats
=
(local variable) string v
v
.
string[] std.array.split!(string, string)(string range, string sep) pure nothrow @safe
split
(",").
int[] std.conv.to!(int[]).to!(string[])(string[] __param_0) pure @safe

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

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 i
i
; break;
case "--variant":
(local variable) string[] only
only
=
(local variable) string v
v
.
string[] std.array.split!(string, string)(string range, string sep) pure nothrow @safe
split
(","); ++
(local variable) ulong i
i
; break;
case "--reps":
(thread local global) int fitbench.reps
reps
=
(local variable) string v
v
.
int std.conv.to!int.to!string(string __param_0) pure @safe

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

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 i
i
; break;
default: stderr.
std.stdio.File std.stdio.makeGlobal!"core.stdc.stdio.stderr"() nothrow @nogc @property ref @system
writeln
("unknown arg ",
(parameter) string[] args
args
[
(local variable) ulong i
i
]);
noreturn core.stdc.stdlib.exit(int status) nothrow @nogc
exit
(2);
} }
(thread local global) fitbench.Perf fitbench.perf
perf
.
void fitbench.Perf.open()
open
();
stderr.
std.stdio.File std.stdio.makeGlobal!"core.stdc.stdio.stderr"() nothrow @nogc @property ref @system
writefln
("perf counters open: %s",
(thread local global) fitbench.Perf fitbench.perf
perf
.
(field) int fitbench.Perf.nOpen
nOpen
);
auto
(local variable) char* pool
pool
= cast(char*)
void* core.stdc.stdlib.malloc(ulong size) nothrow @nogc
malloc
(
(constant) int fitbench.poolLen = 65536
poolLen
);
foreach (
(local variable) int k
k
; 0 ..
(constant) int fitbench.poolLen = 65536
poolLen
)
(local variable) char* pool
pool
[
(local variable) int k
k
] = cast(char)('a' +
(local variable) int k
k
% 26);
void std.stdio.writeln!string(string __param_0) @safe

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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
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) @safe

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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
("|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|");
foreach (
(parameter) string shape
shape
;
(local variable) string[] shapes
shapes
)
foreach (
(parameter) int n0
n0
;
(local variable) int[] ns
ns
)
{
(struct) fitbench.Gen
Gen
(local variable) fitbench.Gen g
g
=
(local variable) string shape
shape
== "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 n0
n0
) :
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 n0
n0
);
int
(local variable) int n
n
=
(local variable) fitbench.Gen g
g
.
(field) int fitbench.Gen.nodes
nodes
;
stderr.
std.stdio.File std.stdio.makeGlobal!"core.stdc.stdio.stderr"() nothrow @nogc @property ref @system
writefln
("# %s N=%s depth=%s maxFan=%s events=%s",
(local variable) string shape
shape
,
(local variable) int n
n
,
(local variable) fitbench.Gen g
g
.
(field) int fitbench.Gen.maxDepth
maxDepth
,
(local variable) fitbench.Gen g
g
.
(field) int fitbench.Gen.maxFan
maxFan
,
(local variable) fitbench.Gen g
g
.
(field) fitbench.Ev[] fitbench.Gen.evs
evs
.
(field) ulong fitbench.Ev[].length
length
);
foreach (
(parameter) int fat
fat
;
(local variable) int[] fats
fats
)
{
(struct) fitbench.Result
Result
[]
(local variable) fitbench.Result[] rs
rs
;
if (
(local variable) int fat
fat
== 64)
(local variable) fitbench.Result[] rs
rs
=
fitbench.Result[] fitbench.runConfig!64LU(const(fitbench.Ev)[] evs, const(char)* pool, int n, string[] only) @system
runConfig
!64(
(local variable) fitbench.Gen g
g
.
(field) fitbench.Ev[] fitbench.Gen.evs
evs
,
(local variable) char* pool
pool
,
(local variable) int n
n
,
(local variable) string[] only
only
);
else if (
(local variable) int fat
fat
== 128)
(local variable) fitbench.Result[] rs
rs
=
fitbench.Result[] fitbench.runConfig!128LU(const(fitbench.Ev)[] evs, const(char)* pool, int n, string[] only) @system
runConfig
!128(
(local variable) fitbench.Gen g
g
.
(field) fitbench.Ev[] fitbench.Gen.evs
evs
,
(local variable) char* pool
pool
,
(local variable) int n
n
,
(local variable) string[] only
only
);
else if (
(local variable) int fat
fat
== 328)
(local variable) fitbench.Result[] rs
rs
=
fitbench.Result[] fitbench.runConfig!328LU(const(fitbench.Ev)[] evs, const(char)* pool, int n, string[] only) @system
runConfig
!328(
(local variable) fitbench.Gen g
g
.
(field) fitbench.Ev[] fitbench.Gen.evs
evs
,
(local variable) char* pool
pool
,
(local variable) int n
n
,
(local variable) string[] only
only
);
else { stderr.
std.stdio.File std.stdio.makeGlobal!"core.stdc.stdio.stderr"() nothrow @nogc @property ref @system
writeln
("fat must be 64,128,328");
noreturn core.stdc.stdlib.exit(int status) nothrow @nogc
exit
(2);
} ulong
(local variable) ulong ref_
ref_
= 0;
foreach (
(parameter) fitbench.Result r
r
;
(local variable) fitbench.Result[] rs
rs
)
{
(alias) object.string = string
string
(local variable) string ok
ok
;
if (
(local variable) fitbench.Result r
r
.
(field) string fitbench.Result.variant
variant
.
(field) ulong string.length
length
>= 4 &&
(local variable) fitbench.Result r
r
.
(field) string fitbench.Result.variant
variant
[0 .. 4] == "rest")
(local variable) string ok
ok
=
(local variable) fitbench.Result[] rs
rs
[$ - 1].
(field) ulong fitbench.Result.checksum
checksum
==
(local variable) fitbench.Result r
r
.
(field) ulong fitbench.Result.checksum
checksum
? "ok" : "MISMATCH";
else { if (
(local variable) ulong ref_
ref_
== 0)
(local variable) ulong ref_
ref_
=
(local variable) fitbench.Result r
r
.
(field) ulong fitbench.Result.checksum
checksum
;
(local variable) string ok
ok
=
(local variable) fitbench.Result r
r
.
(field) ulong fitbench.Result.checksum
checksum
==
(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) @safe

Equivalent 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 shape
shape
,
(local variable) int n
n
,
(local variable) int fat
fat
,
(local variable) fitbench.Result r
r
.
(field) string fitbench.Result.variant
variant
,
(local variable) fitbench.Result r
r
.
(field) double fitbench.Result.total
total
,
(local variable) fitbench.Result r
r
.
(field) double fitbench.Result.build
build
,
(local variable) fitbench.Result r
r
.
(field) double fitbench.Result.pass
pass
,
(local variable) fitbench.Result r
r
.
(field) double fitbench.Result.aux
aux
,
(local variable) fitbench.Result r
r
.
(field) double[5] fitbench.Result.ctr
ctr
[0],
(local variable) fitbench.Result r
r
.
(field) double[5] fitbench.Result.ctr
ctr
[1],
(local variable) fitbench.Result r
r
.
(field) double[5] fitbench.Result.ctr
ctr
[2],
(local variable) fitbench.Result r
r
.
(field) double[5] fitbench.Result.ctr
ctr
[3],
(local variable) fitbench.Result r
r
.
(field) double[5] fitbench.Result.ctr
ctr
[4],
(local variable) fitbench.Result r
r
.
(field) double[5] fitbench.Result.passCtr
passCtr
[0],
(local variable) fitbench.Result r
r
.
(field) double[5] fitbench.Result.passCtr
passCtr
[2],
(local variable) fitbench.Result r
r
.
(field) double[5] fitbench.Result.passCtr
passCtr
[4],
(local variable) string ok
ok
,
(local variable) fitbench.Result r
r
.
(field) ulong fitbench.Result.checksum
checksum
);
stdout.
std.stdio.File std.stdio.makeGlobal!"core.stdc.stdio.stdout"() nothrow @nogc @property ref @system
flush
();
} } } if (
(thread local global) bool fitbench.multiplexed
multiplexed
)
stderr.
std.stdio.File std.stdio.makeGlobal!"core.stdc.stdio.stderr"() nothrow @nogc @property ref @system
writeln
("WARNING: counters were multiplexed");
}