2using System.Collections.Generic;
4using System.Reflection;
18 private Complex[] values;
19 private ICollection<IElement> elements;
20 private readonly
int dimension;
30 this.dimension =
Values.Length;
51 if (this.values is
null)
53 Complex[] v =
new Complex[this.dimension];
78 if (this.elements is
null)
83 for (i = 0; i < this.dimension; i++)
111 if (this.associatedVectorSpace is
null)
114 return this.associatedVectorSpace;
147 Complex[] v =
new Complex[this.dimension];
149 for (i = 0; i < this.dimension; i++)
172 Complex[] v =
new Complex[this.dimension];
173 for (i = 0; i < this.dimension; i++)
174 v[i] =
Values[i] + Values2[i];
186 Complex[] v =
new Complex[this.dimension];
188 for (i = 0; i < this.dimension; i++)
211 for (i = 0; i < this.dimension; i++)
213 if (
Values[i] != Values2[i])
230 for (i = 0; i < this.dimension; i++)
241 get {
return false; }
267 if (this.zero is
null)
283 if (Index < 0 || Index >= this.dimension)
286 Complex[] V = this.
Values;
298 if (Index < 0 || Index >= this.dimension)
302 throw new ScriptException(
"Elements in a complex vector are required to be complex values.");
305 this.elements =
null;
318 if (DesiredType == typeof(Complex[]))
323 else if (DesiredType.GetTypeInfo().IsAssignableFrom(typeof(
ComplexVector).GetTypeInfo()))
328 else if (DesiredType.IsArray)
330 Type ElementType = DesiredType.GetElementType();
335 if (ElementType == typeof(
byte))
337 byte[] ba =
new byte[this.dimension];
339 foreach (Complex c
in this.
Values)
341 if (c.Imaginary == 0 && (d = c.Real) >=
byte.MinValue && d <=
byte.MaxValue)
353 else if (ElementType == typeof(decimal))
355 decimal[] da =
new decimal[this.dimension];
356 foreach (Complex c
in this.
Values)
358 if (c.Imaginary == 0)
359 da[i++] = (decimal)c.Real;
370 else if (ElementType == typeof(
double))
372 double[] da2 =
new double[this.dimension];
373 foreach (Complex c
in this.
Values)
375 if (c.Imaginary == 0)
376 da2[i++] = (double)c.Real;
387 else if (ElementType == typeof(
short))
389 short[] sa =
new short[this.dimension];
390 foreach (Complex c
in this.
Values)
392 if (c.Imaginary == 0 && (d = c.Real) >= short.MinValue && d <=
short.MaxValue)
404 else if (ElementType == typeof(
int))
406 int[] ia =
new int[this.dimension];
407 foreach (Complex c
in this.Values)
409 if (c.Imaginary == 0 && (d = c.Real) >= int.MinValue && d <=
int.MaxValue)
421 else if (ElementType == typeof(
long))
423 long[] la =
new long[this.dimension];
424 foreach (Complex c
in this.Values)
426 if (c.Imaginary == 0 && (d = c.Real) >= long.MinValue && d <=
long.MaxValue)
438 else if (ElementType == typeof(sbyte))
440 sbyte[] sba =
new sbyte[this.dimension];
441 foreach (Complex c
in this.Values)
443 if (c.Imaginary == 0 && (d = c.Real) >= sbyte.MinValue && d <= sbyte.MaxValue)
455 else if (ElementType == typeof(
float))
457 float[] fa =
new float[this.dimension];
458 foreach (Complex c
in this.Values)
460 if (c.Imaginary == 0)
461 fa[i++] = (float)c.Real;
472 else if (ElementType == typeof(ushort))
474 ushort[] usa =
new ushort[this.dimension];
475 foreach (Complex c
in this.Values)
477 if (c.Imaginary == 0 && (d = c.Real) >= ushort.MinValue && d <= ushort.MaxValue)
478 usa[i++] = (ushort)d;
489 else if (ElementType == typeof(uint))
491 uint[] uia =
new uint[this.dimension];
492 foreach (Complex c
in this.Values)
494 if (c.Imaginary == 0 && (d = c.Real) >= uint.MinValue && d <= uint.MaxValue)
506 else if (ElementType == typeof(ulong))
508 ulong[] ula =
new ulong[this.dimension];
509 foreach (Complex c
in this.Values)
511 if (c.Imaginary == 0 && (d = c.Real) >= 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.
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 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.