< Summary - ReFlex - Library

Information
Class: PointCloud.Benchmark.Common.ArrayUtils
Assembly: ReFlex.PointCloud.Benchmark
File(s): D:\a\reflex\reflex\test\Library\Performance\PointCloud.Benchmark\Common\ArrayUtils.cs
Line coverage
26%
Covered lines: 22
Uncovered lines: 61
Coverable lines: 83
Total lines: 203
Line coverage: 26.5%
Branch coverage
22%
Covered branches: 11
Total branches: 48
Branch coverage: 22.9%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
InitializeArray(...)100%22100%
InitializeSpan(...)100%210%
InitializeArray(...)0%2040%
InitializeArray(...)100%44100%
InitializeSpan(...)0%620%
ReferencingArrays(...)0%2040%
ReferencingArrays(...)0%4260%
ReferencingArrays(...)83.33%6688.88%
ReferencingArrays(...)0%4260%
ReferencingArrays(...)0%7280%
ReferencingArrays(...)0%4260%

File(s)

D:\a\reflex\reflex\test\Library\Performance\PointCloud.Benchmark\Common\ArrayUtils.cs

#LineLine coverage
 1using ReFlex.Core.Common.Exceptions;
 2
 3namespace PointCloud.Benchmark.Common
 4{
 5    /// <summary>
 6    /// Helps to initialize and referencing arrays.
 7    /// </summary>
 8    public static class ArrayUtils
 9    {
 10        /// <summary>
 11        /// Initializes the array.
 12        /// </summary>
 13        /// <typeparam name="T"></typeparam>
 14        /// <param name="array">The array.</param>
 15        /// <param name="size">The size.</param>
 16        public static void InitializeArray<T>(out T[] array, int size)
 17            where T : new()
 1218        {
 1219            array = new T[size];
 879343220            for (var i = 0; i < array.Length; i++)
 439670421                array[i] = new T();
 1222        }
 23
 24        /// <summary>
 25        /// Initializes the span with default values.
 26        /// </summary>
 27        /// <typeparam name="T"></typeparam>
 28        /// <param name="span">The resulting span.</param>
 29        /// <param name="size">The size.</param>
 30        public static void InitializeSpan<T>(out Span<T> span, int size)
 31            where T : new()
 032        {
 033            span = new T[size];
 034            span.Fill(new T());
 35            // for (var i = 0; i < array.Length; i++)
 36            //     array[i] = new T();
 037        }
 38
 39        /// <summary>
 40        /// Initializes a multidimensional array.
 41        /// </summary>
 42        /// <typeparam name="T">The inner value type of the array.</typeparam>
 43        /// <param name="array">The array.</param>
 44        /// <param name="width">The width.</param>
 45        /// <param name="height">The height.</param>
 46        public static void InitializeArray<T>(out T[,] array, int width, int height)
 47            where T : new()
 048        {
 049            array = new T[width, height];
 050            for (var i = 0; i < array.GetLength(0); i++)
 051                for (var j = 0; j < array.GetLength(1); j++)
 052                    array[i, j] = new T();
 053        }
 54
 55        /// <summary>
 56        /// Initializes a jagged array.
 57        /// </summary>
 58        /// <typeparam name="T">The inner value type of the array.</typeparam>
 59        /// <param name="array">The array.</param>
 60        /// <param name="width">The width.</param>
 61        /// <param name="height">The height.</param>
 62        public static void InitializeArray<T>(out T[][] array, int width, int height)
 63            where T : new()
 1264        {
 1265            array = new T[width][];
 997666            for (var i = 0; i < array.Length; i++)
 497667            {
 497668                array[i] = new T[height];
 880336069                for (var j = 0; j < array[i].Length; j++)
 439670470                    array[i][j] = new T();
 497671            }
 1272        }
 73
 74        /// <summary>
 75        /// Initializes a jagged array.
 76        /// </summary>
 77        /// <typeparam name="T">The inner value type of the array.</typeparam>
 78        /// <param name="array">The array.</param>
 79        /// <param name="width">The width.</param>
 80        /// <param name="height">The height.</param>
 81        public static void InitializeSpan<T>(out Span<T[]> array, int width, int height)
 82            where T : new()
 083        {
 084            array = new Span<T[]>(new T[width][]);
 085            for (var i = 0; i < array.Length; i++)
 086            {
 087                var innerSpan = new T[height].AsSpan();
 088                innerSpan.Fill(new T());
 089                array[i] = innerSpan.ToArray();
 090            }
 091        }
 92
 93        /// <summary>
 94        /// Referencing the inner values in the arrays.
 95        /// </summary>
 96        /// <typeparam name="T">The inner value type of both arrays.</typeparam>
 97        /// <param name="source">The source.</param>
 98        /// <param name="target">The target.</param>
 99        /// <exception cref="ArraysWithDifferentSizesException"></exception>
 100        public static void ReferencingArrays<T>(T[] source, T[] target)
 0101        {
 0102            if (source.Length != target.Length)
 0103                throw new ArraysWithDifferentSizesException();
 104
 0105            for (var i = 0; i < target.Length; i++)
 0106                target[i] = source[i];
 0107        }
 108
 109        /// <summary>
 110        /// Referencing the inner values in the arrays.
 111        /// </summary>
 112        /// <typeparam name="T">The inner value type of both arrays.</typeparam>
 113        /// <param name="source">The source.</param>
 114        /// <param name="target">The target.</param>
 115        /// <exception cref="ArraysWithDifferentSizesException"></exception>
 116        public static void ReferencingArrays<T>(T[] source, T[,] target)
 0117        {
 0118            if (source.Length != target.GetLength(1) * target.GetLength(0))
 0119                throw new ArraysWithDifferentSizesException();
 120
 0121            for (var x = 0; x < target.GetLength(0); x++)
 0122                for (var y = 0; y < target.GetLength(1); y++)
 0123                    target[x, y] = source[y * target.GetLength(0) + x];
 0124        }
 125
 126        /// <summary>
 127        /// Referencing the inner values in the arrays.
 128        /// </summary>
 129        /// <typeparam name="T">The inner value type of both arrays.</typeparam>
 130        /// <param name="source">The one dimensional array.</param>
 131        /// <param name="target">The two dimensional array.</param>
 132        /// <exception cref="ArraysWithDifferentSizesException"></exception>
 133        public static void ReferencingArrays<T>(T[] source, T[][] target)
 12134        {
 9976135            for (var i = 0; i < target.Length; i++)
 4976136            {
 4976137                if (source.Length != target.Length * target[i].Length)
 0138                    throw new ArraysWithDifferentSizesException();
 139
 8803360140                for (var j = 0; j < target[i].Length; j++)
 4396704141                    target[i][j] = source[j * target.Length + i];
 4976142            }
 12143        }
 144
 145        /// <summary>
 146        /// Referencing the inner values in the arrays.
 147        /// </summary>
 148        /// <typeparam name="T">The inner value type of both arrays.</typeparam>
 149        /// <param name="source">The one dimensional array.</param>
 150        /// <param name="target">The two dimensional array.</param>
 151        /// <exception cref="ArraysWithDifferentSizesException"></exception>
 152        public static void ReferencingArrays<T>(ReadOnlySpan<T> source, Span<T[]> target)
 0153        {
 0154            for (var i = 0; i < target.Length; i++)
 0155            {
 0156                if (source.Length != target.Length * target[i].Length)
 0157                    throw new ArraysWithDifferentSizesException();
 158
 0159                for (var j = 0; j < target[i].Length; j++)
 0160                    target[i][j] = source[j * target.Length + i];
 0161            }
 0162        }
 163
 164        /// <summary>
 165        /// RReferencing the inner values in the arrays.
 166        /// </summary>
 167        /// <typeparam name="T">The inner value type of both arrays.</typeparam>
 168        /// <param name="source">The source.</param>
 169        /// <param name="target">The target.</param>
 170        /// <exception cref="ArraysWithDifferentSizesException"></exception>
 171        public static void ReferencingArrays<T>(T[,] source, T[,] target)
 0172        {
 0173            for (var i = 0; i < target.Length; i++)
 0174            {
 0175                if (source.GetLength(0) * source.GetLength(1) != target.GetLength(0) * target.GetLength(1))
 0176                    throw new ArraysWithDifferentSizesException();
 177
 0178                for (var x = 0; x < target.GetLength(0); x++)
 0179                    for (var y = 0; y < target.GetLength(1); y++)
 0180                        target[x, y] = source[x, y];
 0181            }
 0182        }
 183
 184        /// <summary>
 185        /// RReferencing the inner values in the arrays.
 186        /// </summary>
 187        /// <typeparam name="T">The inner value type of both arrays.</typeparam>
 188        /// <param name="source">The source.</param>
 189        /// <param name="target">The target.</param>
 190        /// <exception cref="ArraysWithDifferentSizesException"></exception>
 191        public static void ReferencingArrays<T>(T[][] source, T[][] target)
 0192        {
 0193            for (var i = 0; i < target.Length; i++)
 0194            {
 0195                if (source.Length * source[i].Length != target.Length * target[i].Length)
 0196                    throw new ArraysWithDifferentSizesException();
 197
 0198                for (var j = 0; j < target[i].Length; j++)
 0199                    target[i][j] = source[i][j];
 0200            }
 0201        }
 202    }
 203}