Example #1
0
 public void DenseVectorStorageBuilderMethods_ZeroLength_DoNotThrowException()
 {
     Assert.DoesNotThrow(() => new DenseVectorStorage <double>(0));
     Assert.DoesNotThrow(() => new DenseVectorStorage <double>(0, Array.Empty <double>()));
     Assert.DoesNotThrow(() => DenseVectorStorage <double> .OfValue(0, 42));
     Assert.DoesNotThrow(() => DenseVectorStorage <double> .OfInit(0, index => 42));
 }
Example #2
0
        public void Reshape(int num, int channels, int height, int width)
        {
            Guard.That(() => num).IsNatural();
            Guard.That(() => channels).IsNatural();
            Guard.That(() => height).IsNatural();
            Guard.That(() => width).IsNatural();

            this.Num      = num;
            this.Channels = channels;
            this.Height   = height;
            this.Width    = width;

            if (this.Count != 0)
            {
                switch (this.Location)
                {
                case TensorLocation.Cpu:     // TODO We can do better here and do not reshape if the size is the same.
                    this._data = DenseVectorStorage <double> .OfValue(this.Count, 0.0f);

                    this._diff = DenseVectorStorage <double> .OfValue(this.Count, 0.0f);

                    break;

                case TensorLocation.Gpu:
                    throw new NotImplementedException();
                }
            }
            else
            {
                this._data = null;
                this._diff = null;
            }
        }
Example #3
0
 /// <summary>
 /// Create a new dense vector and initialize each value using the provided value.
 /// </summary>
 public static DenseVector Create(int length, float value)
 {
     if (value == 0f)
     {
         return(new DenseVector(length));
     }
     return(new DenseVector(DenseVectorStorage <float> .OfValue(length, value)));
 }
Example #4
0
 /// <summary>
 /// Create a new dense vector and initialize each value using the provided value.
 /// </summary>
 public static DenseVector Create(int length, double value)
 {
     if (value == 0d)
     {
         return(new DenseVector(length));
     }
     return(new DenseVector(DenseVectorStorage <double> .OfValue(length, value)));
 }
Example #5
0
 /// <summary>
 /// Create a new dense vector and initialize each value using the provided value.
 /// </summary>
 public static DenseVector Create(int length, Complex32 value)
 {
     if (value == Complex32.Zero)
     {
         return(new DenseVector(length));
     }
     return(new DenseVector(DenseVectorStorage <Complex32> .OfValue(length, value)));
 }
 /// <summary>
 ///     Create a new dense vector and initialize each value using the provided value.
 /// </summary>
 public Vector <T> Dense(int length, T value)
 {
     if (Zero.Equals(value))
     {
         return(Dense(length));
     }
     return(Dense(DenseVectorStorage <T> .OfValue(length, value)));
 }
Example #7
0
        public Vector <Complex32> GetComplex32Vector(int length)
        {
            lock (_lock)
            {
                var storage = _complex32VectorStoragePool.Find(s => s.Length == length);
                if (storage == null)
                {
                    storage = DenseVectorStorage <Complex32> .OfValue(length, Complex32.Zero);

                    _complex32VectorStoragePoolMaster.Add(storage);
                }
                else
                {
                    _complex32VectorStoragePool.Remove(storage);
                    storage.Clear();
                }
                return(Vector <Complex32> .Build.Dense(storage));
            }
        }
Example #8
0
        public Vector <float> GetFloatVector(int length)
        {
            lock (_lock)
            {
                var storage = _floatVectorStoragePool.Find(s => s.Length == length);
                if (storage == null)
                {
                    storage = DenseVectorStorage <float> .OfValue(length, 0.0f);

                    _floatVectorStoragePoolMaster.Add(storage);
                }
                else
                {
                    _floatVectorStoragePool.Remove(storage);
                    storage.Clear();
                }
                return(Vector <float> .Build.Dense(storage));
            }
        }
Example #9
0
 public void DenseVectorStorageOfValue_NegativeLength_ThrowsArgumentException()
 {
     Assert.That(() => DenseVectorStorage <double> .OfValue(-1, 42),
                 Throws.TypeOf <ArgumentOutOfRangeException>()
                 .With.Message.Contains("Value must not be negative (zero is ok)."));
 }