You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why this constructor stuff was implemented in this matter?
First: this is OK, but expensive, both .Count() and .ToArray() do copy twice ore once, if vector not inherited from ICollection
///
/// Creates a new vector with the specified values.
///
/// The handling this instance.
/// The element type.
/// The elements of vector.
protected Vector(REngine engine, SymbolicExpressionType type, IEnumerable vector)
: base(engine, engine.GetFunction<Rf_allocVector>()(type, vector.Count()))
{
SetVector(vector.ToArray());
}
But here: the base constructor is called and this creates an empty double array of length and why the SetVector is not used? instead the array is copied unprotected? (see next protected base constructor)
///
/// Creates a new NumericVector with the specified values.
///
/// The handling this instance.
/// The values.
///
public NumericVector(REngine engine, double[] vector)
: base(engine, SymbolicExpressionType.NumericVector, vector.Length)
{
Marshal.Copy(vector, 0, DataPointer, vector.Length);
}
/// <summary>
/// Creates a new vector with the specified size.
/// </summary>
/// <param name="engine">The <see cref="REngine"/> handling this instance.</param>
/// <param name="type">The element type.</param>
/// <param name="length">The length of vector.</param>
protected Vector(REngine engine, SymbolicExpressionType type, int length)
: base(engine, engine.GetFunction<Rf_allocVector>()(type, length))
{
if (length <= 0)
{
throw new ArgumentOutOfRangeException("length");
}
var empty = new byte[length * DataSize];
Marshal.Copy(empty, 0, DataPointer, empty.Length);
}
Same "problem" for all Vector subclasses
Roman
The text was updated successfully, but these errors were encountered:
Why this constructor stuff was implemented in this matter?
First: this is OK, but expensive, both .Count() and .ToArray() do copy twice ore once, if vector not inherited from ICollection
///
/// Creates a new vector with the specified values.
///
/// The handling this instance.
/// The element type.
/// The elements of vector.
protected Vector(REngine engine, SymbolicExpressionType type, IEnumerable vector)
: base(engine, engine.GetFunction<Rf_allocVector>()(type, vector.Count()))
{
SetVector(vector.ToArray());
}
But here: the base constructor is called and this creates an empty double array of length and why the SetVector is not used? instead the array is copied unprotected? (see next protected base constructor)
///
/// Creates a new NumericVector with the specified values.
///
/// The handling this instance.
/// The values.
///
public NumericVector(REngine engine, double[] vector)
: base(engine, SymbolicExpressionType.NumericVector, vector.Length)
{
Marshal.Copy(vector, 0, DataPointer, vector.Length);
}
Same "problem" for all Vector subclasses
Roman
The text was updated successfully, but these errors were encountered: