4using System.Reflection;
19 private Complex[] values;
20 private ICollection<IElement> elements;
21 private readonly
int dimension;
31 this.dimension =
Values.Length;
52 if (this.values is
null)
54 Complex[] v =
new Complex[this.dimension];
62 while (!(Loop is
null))
64 for (j = Loop.
Start, c = Loop.
Pos; j < c; j++)
100 if (this.elements is
null)
105 for (i = 0; i < this.dimension; i++)
111 return this.elements;
133 if (this.associatedVectorSpace is
null)
136 return this.associatedVectorSpace;
169 Complex[] v =
new Complex[this.dimension];
171 for (i = 0; i < this.dimension; i++)
194 Complex[] v =
new Complex[this.dimension];
195 for (i = 0; i < this.dimension; i++)
196 v[i] =
Values[i] + Values2[i];
208 Complex[] v =
new Complex[this.dimension];
210 for (i = 0; i < this.dimension; i++)
233 for (i = 0; i < this.dimension; i++)
235 if (
Values[i] != Values2[i])
252 for (i = 0; i < this.dimension; i++)
263 get {
return false; }
300 if (this.zero is
null)
316 if (Index < 0 || Index >= this.dimension)
319 Complex[] V = this.
Values;
331 if (Index < 0 || Index >= this.dimension)
335 throw new ScriptException(
"Elements in a complex vector are required to be complex values.");
338 this.elements =
null;
351 if (DesiredType == typeof(Complex[]))
356 else if (DesiredType.IsAssignableFrom(typeof(
ComplexVector).GetTypeInfo()))
361 else if (DesiredType.IsArray)
363 Type ElementType = DesiredType.GetElementType();
368 if (ElementType == typeof(
byte))
370 byte[] ba =
new byte[this.dimension];
372 foreach (Complex c
in this.
Values)
374 if (c.Imaginary == 0 && (d = c.Real) >=
byte.MinValue && d <=
byte.MaxValue)
386 else if (ElementType == typeof(decimal))
388 decimal[] da =
new decimal[this.dimension];
389 foreach (Complex c
in this.
Values)
391 if (c.Imaginary == 0)
392 da[i++] = (decimal)c.Real;
403 else if (ElementType == typeof(
double))
405 double[] da2 =
new double[this.dimension];
406 foreach (Complex c
in this.
Values)
408 if (c.Imaginary == 0)
409 da2[i++] = (double)c.Real;
420 else if (ElementType == typeof(
short))
422 short[] sa =
new short[this.dimension];
423 foreach (Complex c
in this.
Values)
425 if (c.Imaginary == 0 && (d = c.Real) >= short.MinValue && d <=
short.MaxValue)
437 else if (ElementType == typeof(
int))
439 int[] ia =
new int[this.dimension];
440 foreach (Complex c
in this.Values)
442 if (c.Imaginary == 0 && (d = c.Real) >= int.MinValue && d <=
int.MaxValue)
454 else if (ElementType == typeof(
long))
456 long[] la =
new long[this.dimension];
457 foreach (Complex c
in this.Values)
459 if (c.Imaginary == 0 && (d = c.Real) >= long.MinValue && d <=
long.MaxValue)
471 else if (ElementType == typeof(sbyte))
473 sbyte[] sba =
new sbyte[this.dimension];
474 foreach (Complex c
in this.Values)
476 if (c.Imaginary == 0 && (d = c.Real) >= sbyte.MinValue && d <= sbyte.MaxValue)
488 else if (ElementType == typeof(
float))
490 float[] fa =
new float[this.dimension];
491 foreach (Complex c
in this.Values)
493 if (c.Imaginary == 0)
494 fa[i++] = (float)c.Real;
505 else if (ElementType == typeof(ushort))
507 ushort[] usa =
new ushort[this.dimension];
508 foreach (Complex c
in this.Values)
510 if (c.Imaginary == 0 && (d = c.Real) >= ushort.MinValue && d <= ushort.MaxValue)
511 usa[i++] = (ushort)d;
522 else if (ElementType == typeof(uint))
524 uint[] uia =
new uint[this.dimension];
525 foreach (Complex c
in this.Values)
527 if (c.Imaginary == 0 && (d = c.Real) >= uint.MinValue && d <= uint.MaxValue)
539 else if (ElementType == typeof(ulong))
541 ulong[] ula =
new ulong[this.dimension];
542 foreach (Complex c
in this.Values)
544 if (c.Imaginary == 0 && (d = c.Real) >= 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.
Complex Value
Complex value.
double Value
Double value.
ComplexVector(ICollection< IElement > Elements)
Complex-valued vector.
override IGroupElement Negate()
Negates the element.
override bool TryConvertTo(Type DesiredType, out object Value)
Converts the value to a .NET type.
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 bool IsScalar
If the element represents a scalar value.
override int Dimension
Dimension of vector.
ComplexVector(params Complex[] Values)
Complex-valued vector.
override IElement Encapsulate(ChunkedList< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
override int GetHashCode()
Calculates a hash code of the element.
override IAbelianGroupElement Add(IAbelianGroupElement Element)
Tries to add an element to the current element.
override IAbelianGroupElement Zero
Returns the zero element of the group.
override IVectorSpace AssociatedVectorSpace
Associated Right-VectorSpace.
override object AssociatedObjectValue
Associated object value.
Complex[] Values
Vector element values.
ICollection< IElement > Elements
Vector elements.
override bool Equals(object obj)
Compares the element to another.
override string ToString()
override void SetElement(int Index, IElement Value)
Sets an element in the vector.
override IElement GetElement(int Index)
Gets an element of the vector.
override IVectorSpaceElement MultiplyScalar(IFieldElement Scalar)
Tries to multiply a scalar to the current element.
override ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Pseudo-vector space of Complex-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.