2using System.Collections.Generic;
3using System.Reflection;
17 private double[] values;
18 private ICollection<IElement> elements;
19 private readonly
int dimension;
29 this.dimension =
Values.Length;
50 if (this.values is
null)
52 double[] v =
new double[this.dimension];
75 if (this.elements is
null)
80 for (i = 0; i < this.dimension; i++)
108 if (this.associatedVectorSpace is
null)
109 this.associatedVectorSpace =
new DoubleVectors(this.dimension);
111 return this.associatedVectorSpace;
134 double[] v =
new double[this.dimension];
136 for (i = 0; i < this.dimension; i++)
158 double[] v =
new double[this.dimension];
159 for (i = 0; i < this.dimension; i++)
160 v[i] =
Values[i] + Values2[i];
172 double[] v =
new double[this.dimension];
174 for (i = 0; i < this.dimension; i++)
196 for (i = 0; i < this.dimension; i++)
198 if (
Values[i] != Values2[i])
215 for (i = 0; i < this.dimension; i++)
226 get {
return false; }
252 if (this.zero is
null)
253 this.zero =
new DoubleVector(
new double[this.dimension]);
268 if (Index < 0 || Index >= this.dimension)
283 if (Index < 0 || Index >= this.dimension)
287 throw new ScriptException(
"Elements in a double vector are required to be double values.");
290 this.elements =
null;
303 if (DesiredType == typeof(
double[]))
308 else if (DesiredType.GetTypeInfo().IsAssignableFrom(typeof(
DoubleVector).GetTypeInfo()))
313 else if (DesiredType.IsArray)
315 Type ElementType = DesiredType.GetElementType();
318 if (ElementType == typeof(
byte))
320 byte[] ba =
new byte[this.dimension];
321 foreach (
double d
in this.
Values)
323 if (d >=
byte.MinValue && d <=
byte.MaxValue)
335 else if (ElementType == typeof(decimal))
337 decimal[] da =
new decimal[this.dimension];
338 foreach (
double d
in this.
Values)
339 da[i++] = (decimal)d;
344 else if (ElementType == typeof(
short))
346 short[] sa =
new short[this.dimension];
347 foreach (
double d
in this.
Values)
349 if (d >=
short.MinValue && d <=
short.MaxValue)
361 else if (ElementType == typeof(
int))
363 int[] ia =
new int[this.dimension];
364 foreach (
double d
in this.
Values)
366 if (d >=
int.MinValue && d <=
int.MaxValue)
378 else if (ElementType == typeof(
long))
380 long[] la =
new long[this.dimension];
381 foreach (
double d
in this.
Values)
383 if (d >=
long.MinValue && d <=
long.MaxValue)
395 else if (ElementType == typeof(sbyte))
397 sbyte[] sba =
new sbyte[this.dimension];
398 foreach (
double d
in this.
Values)
400 if (d >= sbyte.MinValue && d <= sbyte.MaxValue)
412 else if (ElementType == typeof(
float))
414 float[] fa =
new float[this.dimension];
415 foreach (
double d
in this.
Values)
421 else if (ElementType == typeof(ushort))
423 ushort[] usa =
new ushort[this.dimension];
424 foreach (
double d
in this.
Values)
426 if (d >= ushort.MinValue && d <= ushort.MaxValue)
427 usa[i++] = (ushort)d;
438 else if (ElementType == typeof(uint))
440 uint[] uia =
new uint[this.dimension];
441 foreach (
double d
in this.
Values)
443 if (d >= uint.MinValue && d <= uint.MaxValue)
455 else if (ElementType == typeof(ulong))
457 ulong[] ula =
new ulong[this.dimension];
458 foreach (
double d
in this.
Values)
460 if (d >= ulong.MinValue && d <= ulong.MaxValue)
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, 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.
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.