///
/// This file is part of ILNumerics Community Edition.
///
/// ILNumerics Community Edition - high performance computing for applications.
/// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
///
/// ILNumerics Community Edition is free software: you can redistribute it and/or modify
/// it under the terms of the GNU General Public License version 3 as published by
/// the Free Software Foundation.
///
/// ILNumerics Community Edition is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with ILNumerics Community Edition. See the file License.txt in the root
/// of your distribution package. If not, see .
///
/// In addition this software uses the following components and/or licenses:
///
/// =================================================================================
/// The Open Toolkit Library License
///
/// Copyright (c) 2006 - 2009 the Open Toolkit library.
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights to
/// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
/// the Software, and to permit persons to whom the Software is furnished to do
/// so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all
/// copies or substantial portions of the Software.
///
/// =================================================================================
///
using System;
using ILNumerics;
using ILNumerics.Misc;
using ILNumerics.Storage;
using ILNumerics.Exceptions;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Collections;
namespace ILNumerics {
///
/// Typed base class for all ILNumerics data storage classes for any storage type.
///
/// You should not use this type directly. It serves as a base class
/// for all typed storages only and will be used by derived classes like ILArray]]>.
/// If you are looking for an (untyped) base class to be used as generic class for any ILArray types, you should use ILBaseArray instead!
///
[Serializable]
public abstract partial class ILBaseArray
: ILBaseArray, IEnumerable {
internal ILBaseArray(ILStorage storage, bool isTempArray) : base(storage, isTempArray) { }
#region attributes
#endregion
#region properties
///
/// Determine if this array has complex elements.
///
public override bool IsComplex {
get {
return (this is ILBaseArray
|| this is ILBaseArray);
}
}
///
/// Determine if this array holds numeric values.
///
/// An ILArray is numeric as long as its elements are one of the
/// following types:
///
///
/// inner type
///
/// -
/// System.double
/// floating point, real, 8 bytes
///
/// -
/// System.float
/// floating point real, 4 bytes
///
/// -
/// ILNumerics.complex
/// floating point complex, 16 bytes
///
/// -
/// ILNumerics.fcomplex
/// floating point complex, 8 bytes
///
/// -
/// System.char
/// integer, real, 1 byte
///
/// -
/// System.byte
/// integer, real, 1 byte
///
/// -
/// System.Int16
/// integer, real, 2 byte
///
/// -
/// System.Int32
/// integer, real, 4 byte
///
/// -
/// System.Int64
/// integer, real, 8 byte
///
/// -
/// System.UInt16
/// unsigned integer, real, 2 byte
///
/// -
/// System.UInt32
/// unsigned integer, real, 4 byte
///
/// -
/// System.UInt64
/// unsigned integer, real, 8 byte
///
///
///
public override bool IsNumeric {
get {
if (this is ILBaseArray ||
this is ILBaseArray ||
this is ILBaseArray ||
this is ILBaseArray ||
this is ILBaseArray ||
this is ILBaseArray ||
this is ILBaseArray ||
this is ILBaseArray ||
this is ILBaseArray ||
this is ILBaseArray ||
this is ILBaseArray ||
this is ILBaseArray)
return true;
return false;
}
}
///
/// Access to internal typed storage
///
internal new ILStorage Storage {
get { return (m_storage as ILStorage); }
}
#endregion
#region public interface
///
/// Serialize this array into a binary stream.
///
/// System.IO.Stream to receive the byte stream
/// for this ILBaseArray
/// True on success, false on error.
public virtual bool Serialize(Stream outStream) {
try {
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(outStream, this);
return true;
} catch (Exception) {
return false;
}
}
///
/// Deserialize / restore array from binary stream 'inStream'
///
/// System.IO.Stream to reconstruct the
/// array from
/// Array reconstructed from stream.
/// If the array could not get restored
public static ILBaseArray Deserialize(Stream inStream) {
try {
BinaryFormatter bf = new BinaryFormatter();
ILBaseArray ret = (ILBaseArray)bf.Deserialize(inStream);
return ret;
} catch (Exception e) {
throw e;
}
}
///
/// Get single element from this array
///
/// Indices, location of element
/// The selected value
public virtual ElementType GetValue(params int[] idx) {
return Storage.GetValueTyped(idx);
}
///
/// Get minimum and maximum value of all elements - if any
///
/// [Output] Minimum value
/// [Output] Maximum value
/// true if the limits exists and could be computed, false otherwise
/// Empty arrays will return false. In this case the output parameter will be: default(ElementType).
///
public virtual bool GetLimits(out ElementType min, out ElementType max) {
return Storage.GetLimits(out min, out max);
}
///
/// Get minimum and maximum value of all elements - if any
///
/// [Output] Minimum value
/// [Output] Maximum value
/// true: recognize Inf, NaN values; false: ignore those values
/// true if the limits exists and could be computed, false otherwise
/// Empty arrays will return false. In this case the output parameter will be: default(ElementType).
internal bool GetLimits(out ElementType min, out ElementType max, bool includeInfNaNs) {
return Storage.GetLimits(out min, out max, includeInfNaNs);
}
#endregion
#region IEnumerable> Member
///
/// Enumerator returning elements as ElementType
///
/// Enumerator
/// This method enables the us of ILNumerics arrays in foreach loops.
/// This iterator implements IEnumerable<ElementType> explicitely and is used in situations,
/// where instances of ILNumerics arrays are casted to instances of the IEnumerable interface. This iterator
/// is not integrated into the ILNumerics memory management.
/// ILDenseStorage<T> A = ILMath.rand(5,4,6);
/// foreach (double element in A) {
/// // all elements are scalar double values
/// String.Format("Element: {0} ",element);
/// // Note: 'element' cannot be used to alter the collection!
/// }
///
IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() {
return Storage.GetEnumerator();
}
///
/// Enumerator returning elements as ElementType
///
/// Enumerator
/// This method enables the use of ILNumerics arrays in foreach loops directly.
IEnumerator System.Collections.IEnumerable.GetEnumerator() {
return GetEnumerator();
}
///
/// Enumerator returning elements as ElementType
///
/// Enumerator
/// This method enables the use of ILNumerics arrays in foreach loops directly.
public abstract IEnumerator GetEnumerator();
#endregion
#region public interface
#endregion
}
}