3using System.Reflection;
18 private double[] values;
19 private ICollection<IElement> elements;
20 private readonly
int dimension;
30 this.dimension =
Values.Length;
51 if (this.values is
null)
53 double[] v =
new double[this.dimension];
61 while (!(Loop is
null))
63 for (j = Loop.
Start, c = Loop.
Pos; j < c; j++)
99 if (this.elements is
null)
104 for (i = 0; i < this.dimension; i++)
110 return this.elements;
132 if (this.associatedVectorSpace is
null)
133 this.associatedVectorSpace =
new DoubleVectors(this.dimension);
135 return this.associatedVectorSpace;
158 double[] v =
new double[this.dimension];
160 for (i = 0; i < this.dimension; i++)
182 double[] v =
new double[this.dimension];
183 for (i = 0; i < this.dimension; i++)
184 v[i] =
Values[i] + Values2[i];
196 double[] v =
new double[this.dimension];
198 for (i = 0; i < this.dimension; i++)
220 for (i = 0; i < this.dimension; i++)
222 if (
Values[i] != Values2[i])
239 for (i = 0; i < this.dimension; i++)
250 get {
return false; }
287 if (this.zero is
null)
288 this.zero =
new DoubleVector(
new double[this.dimension]);
303 if (Index < 0 || Index >= this.dimension)
318 if (Index < 0 || Index >= this.dimension)
322 throw new ScriptException(
"Elements in a double vector are required to be double values.");
325 this.elements =
null;
338 if (DesiredType == typeof(
double[]))
343 else if (DesiredType.IsAssignableFrom(typeof(
DoubleVector).GetTypeInfo()))
348 else if (DesiredType.IsArray)
350 Type ElementType = DesiredType.GetElementType();
353 if (ElementType == typeof(
byte))
355 byte[] ba =
new byte[this.dimension];
356 foreach (
double d
in this.
Values)
358 if (d >=
byte.MinValue && d <=
byte.MaxValue)
370 else if (ElementType == typeof(decimal))
372 decimal[] da =
new decimal[this.dimension];
373 foreach (
double d
in this.
Values)
374 da[i++] = (decimal)d;
379 else if (ElementType == typeof(
short))
381 short[] sa =
new short[this.dimension];
382 foreach (
double d
in this.
Values)
384 if (d >=
short.MinValue && d <=
short.MaxValue)
396 else if (ElementType == typeof(
int))
398 int[] ia =
new int[this.dimension];
399 foreach (
double d
in this.
Values)
401 if (d >=
int.MinValue && d <=
int.MaxValue)
413 else if (ElementType == typeof(
long))
415 long[] la =
new long[this.dimension];
416 foreach (
double d
in this.
Values)
418 if (d >=
long.MinValue && d <=
long.MaxValue)
430 else if (ElementType == typeof(sbyte))
432 sbyte[] sba =
new sbyte[this.dimension];
433 foreach (
double d
in this.
Values)
435 if (d >= sbyte.MinValue && d <= sbyte.MaxValue)
447 else if (ElementType == typeof(
float))
449 float[] fa =
new float[this.dimension];
450 foreach (
double d
in this.
Values)
456 else if (ElementType == typeof(ushort))
458 ushort[] usa =
new ushort[this.dimension];
459 foreach (
double d
in this.
Values)
461 if (d >= ushort.MinValue && d <= ushort.MaxValue)
462 usa[i++] = (ushort)d;
473 else if (ElementType == typeof(uint))
475 uint[] uia =
new uint[this.dimension];
476 foreach (
double d
in this.
Values)
478 if (d >= uint.MinValue && d <= uint.MaxValue)
490 else if (ElementType == typeof(ulong))
492 ulong[] ula =
new ulong[this.dimension];
493 foreach (
double d
in this.
Values)
495 if (d >= ulong.MinValue && d <= ulong.MaxValue)
Node referencing a chunk in a ChunkedList<T>
ChunkNode< T > Next
Next chunk
int Pos
Index after the last element in chunk.
int Start
Index of first element in chunk.
A chunked list is a linked list of chunks of objects of type T .
Base class for all types of elements.
abstract object AssociatedObjectValue
Associated object value.
Base class for all types of vector space elements (vectors).
Base class for script exceptions.
Class managing a script expression.
static bool TryConvert(object Value, Type DesiredType, bool AcceptInformationLoss, out object Result)
Tries to convert an object Value to an object of type DesiredType .
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Base class for all nodes in a parsed script tree.
override object AssociatedObjectValue
Associated object value.
override bool TryConvertTo(Type DesiredType, out object Value)
Converts the value to a .NET type.
double[] Values
Vector element values.
override IGroupElement Negate()
Negates the element.
override IAbelianGroupElement Zero
Returns the zero element of the group.
override IVectorSpace AssociatedVectorSpace
Associated Right-VectorSpace.
override bool Equals(object obj)
Compares the element to another.
override IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
override IVectorSpaceElement MultiplyScalar(IFieldElement Scalar)
Tries to multiply a scalar to the current element.
override string ToString()
override void SetElement(int Index, IElement Value)
Sets an element in the vector.
DoubleVector(params double[] Values)
Double-valued vector.
override IAbelianGroupElement Add(IAbelianGroupElement Element)
Tries to add an element to the current element.
DoubleVector(ICollection< IElement > Elements)
Double-valued vector.
override bool IsScalar
If the element represents a scalar value.
override int Dimension
Dimension of vector.
override int GetHashCode()
Calculates a hash code of the element.
override IElement GetElement(int Index)
Gets an element of the vector.
ICollection< IElement > Elements
Vector elements.
override ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
override IElement Encapsulate(ChunkedList< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
Pseudo-vector space of Double-valued vectors.
static IElement Encapsulate(Array Elements, bool CanEncapsulateAsMatrix, ScriptNode Node)
Encapsulates the elements of a vector.
Basic interface for all types of abelian group elements.
Basic interface for all types of elements.
object AssociatedObjectValue
Associated object value.
Basic interface for all types of field elements.
Basic interface for all types of group elements.
Basic interface for all types of module elements.
Basic interface for all types of modules.