Skip to content

Commit

Permalink
Minor scalar adjustments for scipy.odr
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason McCampbell (Enthought, Inc) committed Apr 12, 2011
1 parent 4587d2c commit 6bd7e31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion numpy/NumpyDotNet/Scalar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,21 @@ public ScalarFloat64(Double value) {
}

public ScalarFloat64(IConvertible value) {
this.value = Convert.ToSingle(value);
this.value = Convert.ToDouble(value);
}

public ScalarFloat64(ndarray value) {
if (value.ndim == 0) {
object v = ((dtype)dtype).ToScalar(value);
if (v is IConvertible) {
this.value = Convert.ToDouble((IConvertible)v);
} else {
throw new ArgumentTypeException(
String.Format("Unable to convert array of {0} to double", value.Dtype.ToString()));
}
} else {
throw new ArgumentTypeException("Only 0-d arrays can be converted to scalars");
}
}

public override object dtype {
Expand Down
2 changes: 1 addition & 1 deletion numpy/NumpyDotNet/ndarray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ internal long Length {
}
}

internal static object ArrayReturn(ndarray a) {
public static object ArrayReturn(ndarray a) {
if (a.ndim == 0) {
return a.Dtype.ToScalar(a);
} else {
Expand Down

0 comments on commit 6bd7e31

Please sign in to comment.