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.Collections.Generic;
using System.Numerics; using System.Numerics;
using System.Text; using System.Text;
using Distributions;
using Numerics; using Numerics;
using Properties; using Properties;
using Storage; using Storage;
@ -44,11 +43,11 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
[Serializable] [Serializable]
public abstract class Vector<T> : public abstract class Vector<T> :
#if PORTABLE #if PORTABLE
IFormattable, IEnumerable<T>, IEquatable<Vector<T>> IFormattable, IEnumerable<T>, IEquatable<Vector<T>>, IList, IList<T>
#else #else
IFormattable, IEnumerable<T>, IEquatable<Vector<T>>, ICloneable, IList, IList<T> IFormattable, IEnumerable<T>, IEquatable<Vector<T>>, IList, IList<T>, ICloneable
#endif #endif
where T : struct, IEquatable<T>, IFormattable where T : struct, IEquatable<T>, IFormattable
{ {
/// <summary> /// <summary>
/// The zero value for type T. /// The zero value for type T.
@ -1514,29 +1513,41 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
#endregion #endregion
#region IList #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)) 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)) 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) void IList.Insert(int index, object value)
@ -1544,14 +1555,9 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new NotSupportedException(); throw new NotSupportedException();
} }
bool IList.IsFixedSize int IList.Add(object value)
{
get { return true; }
}
bool IList.IsReadOnly
{ {
get { return false; } throw new NotSupportedException();
} }
void IList.Remove(object value) void IList.Remove(object value)
@ -1564,77 +1570,54 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new NotSupportedException(); throw new NotSupportedException();
} }
object IList.this[int index] #endregion
#region ICollection
bool ICollection.IsSynchronized
{ {
get get { return false; }
{ }
return this[index];
} object ICollection.SyncRoot
set {
{ get { return null; }
this[index] = (T)value;
}
} }
void ICollection.CopyTo(Array array, int index) void ICollection.CopyTo(Array array, int index)
{ {
if (array == null) 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 Storage.CopySubVectorTo(new DenseVectorStorage<T>(array.Length, (T[])array), 0, index, Count);
{
get { return false; }
} }
object ICollection.SyncRoot
{
get { return null; }
}
#endregion #endregion
#region ICollection<T>
#region IList<T> bool ICollection<T>.IsReadOnly
void ICollection<T>.Add(T item)
{
throw new NotSupportedException();
}
int IList<T>.IndexOf(T item)
{ {
for (int ii = 0; ii < this.Count; ++ii) get { return false; }
{
if (this[ii].Equals(item))
return ii;
}
return -1;
} }
void IList<T>.Insert(int index, T item) void ICollection<T>.Add(T item)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
void IList<T>.RemoveAt(int index) bool ICollection<T>.Remove(T item)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
bool ICollection<T>.Contains(T item) 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) foreach (var x in this)
{ {
if (x.Equals(item)) if (x.Equals(item))
@ -1646,27 +1629,36 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
void ICollection<T>.CopyTo(T[] array, int arrayIndex) void ICollection<T>.CopyTo(T[] array, int arrayIndex)
{ {
if (array == null) if (array == null)
{
throw new ArgumentNullException("array"); throw new ArgumentNullException("array");
if (arrayIndex < 0) }
throw new ArgumentOutOfRangeException("arrayIndex");
if (array.Rank > 1) Storage.CopySubVectorTo(new DenseVectorStorage<T>(array.Length, array), 0, arrayIndex, Count);
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.");
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(); throw new NotSupportedException();
} }
#endregion #endregion
#endregion #endregion

Loading…
Cancel
Save