Browse Source

LA: Regroup Vector IList implemenation, fix portable build

v2
Christoph Ruegg 14 years ago
parent
commit
6c3f2b7184
  1. 140
      src/Numerics/LinearAlgebra/Generic/Vector.cs

140
src/Numerics/LinearAlgebra/Generic/Vector.cs

@ -31,7 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using Distributions;
using Numerics;
using Properties;
using Storage;
@ -44,11 +43,11 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
[Serializable]
public abstract class Vector<T> :
#if PORTABLE
IFormattable, IEnumerable<T>, IEquatable<Vector<T>>
IFormattable, IEnumerable<T>, IEquatable<Vector<T>>, IList, IList<T>
#else
IFormattable, IEnumerable<T>, IEquatable<Vector<T>>, ICloneable, IList, IList<T>
IFormattable, IEnumerable<T>, IEquatable<Vector<T>>, IList, IList<T>, ICloneable
#endif
where T : struct, IEquatable<T>, IFormattable
where T : struct, IEquatable<T>, IFormattable
{
/// <summary>
/// The zero value for type T.
@ -1514,29 +1513,41 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
#endregion
#region IList
int IList.Add(object value)
bool IList.IsReadOnly
{
throw new NotSupportedException();
get { return false; }
}
bool IList.Contains(object value)
bool IList.IsFixedSize
{
get { return true; }
}
object IList.this[int index]
{
get { return Storage[index]; }
set { Storage[index] = (T)value; }
}
int IList.IndexOf(object value)
{
if (!(value is T))
return false;
else
{
return ((IList<T>)this).Contains((T)value);
return -1;
}
return ((IList<T>)this).IndexOf((T)value);
}
int IList.IndexOf(object value)
bool IList.Contains(object value)
{
if (!(value is T))
return -1;
else
{
return ((IList<T>)this).IndexOf((T)value);
return false;
}
return ((ICollection<T>)this).Contains((T)value);
}
void IList.Insert(int index, object value)
@ -1544,14 +1555,9 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new NotSupportedException();
}
bool IList.IsFixedSize
{
get { return true; }
}
bool IList.IsReadOnly
int IList.Add(object value)
{
get { return false; }
throw new NotSupportedException();
}
void IList.Remove(object value)
@ -1564,77 +1570,54 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new NotSupportedException();
}
object IList.this[int index]
#endregion
#region ICollection
bool ICollection.IsSynchronized
{
get
{
return this[index];
}
set
{
this[index] = (T)value;
}
get { return false; }
}
object ICollection.SyncRoot
{
get { return null; }
}
void ICollection.CopyTo(Array array, int index)
{
if (array == null)
throw new ArgumentNullException("array");
if (index < 0)
throw new ArgumentOutOfRangeException("index");
if (array.Rank > 1)
throw new ArgumentException("Only accept one dimensional arrays.", "array");
if (array.LongLength < index + this.Count)
throw new ArgumentException("Destination array not large enough to store elements requested to copy.");
try
{
this.Storage.CopySubVectorTo(new DenseVectorStorage<T>(array.Length, (T[])array), 0, index, this.Count, skipClearing: true);
throw new ArgumentNullException("array");
}
catch (InvalidCastException)
if (array.Rank != 1)
{
throw new ArgumentException("Input type does not match type of Vector", "array");
throw new ArgumentException(Resources.ArgumentSingleDimensionArray, "array");
}
}
bool ICollection.IsSynchronized
{
get { return false; }
Storage.CopySubVectorTo(new DenseVectorStorage<T>(array.Length, (T[])array), 0, index, Count);
}
object ICollection.SyncRoot
{
get { return null; }
}
#endregion
#region ICollection<T>
#region IList<T>
void ICollection<T>.Add(T item)
{
throw new NotSupportedException();
}
int IList<T>.IndexOf(T item)
bool ICollection<T>.IsReadOnly
{
for (int ii = 0; ii < this.Count; ++ii)
{
if (this[ii].Equals(item))
return ii;
}
return -1;
get { return false; }
}
void IList<T>.Insert(int index, T item)
void ICollection<T>.Add(T item)
{
throw new NotSupportedException();
}
void IList<T>.RemoveAt(int index)
bool ICollection<T>.Remove(T item)
{
throw new NotSupportedException();
}
bool ICollection<T>.Contains(T item)
{
// Do NOT convert this loop to LINQ (since LINQ would redirect to this very method)!
foreach (var x in this)
{
if (x.Equals(item))
@ -1646,27 +1629,36 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
{
if (array == null)
{
throw new ArgumentNullException("array");
if (arrayIndex < 0)
throw new ArgumentOutOfRangeException("arrayIndex");
if (array.Rank > 1)
throw new ArgumentException("Only accept one dimensional arrays.", "array");
if (array.LongLength < arrayIndex + this.Count)
throw new ArgumentException("Destination array not large enough to store elements requested to copy.");
}
Storage.CopySubVectorTo(new DenseVectorStorage<T>(array.Length, array), 0, arrayIndex, Count);
}
this.Storage.CopySubVectorTo(new DenseVectorStorage<T>(array.Length, array), 0, arrayIndex, this.Count, skipClearing: true);
#endregion
#region IList<T>
int IList<T>.IndexOf(T item)
{
for (int i = 0; i < Count; ++i)
{
if (this[i].Equals(item))
return i;
}
return -1;
}
bool ICollection<T>.IsReadOnly
void IList<T>.Insert(int index, T item)
{
get { return false; }
throw new NotSupportedException();
}
bool ICollection<T>.Remove(T item)
void IList<T>.RemoveAt(int index)
{
throw new NotSupportedException();
}
#endregion
#endregion

Loading…
Cancel
Save