Class Context
- java.lang.Object
-
- cc.redberry.core.context.Context
-
public final class Context extends java.lang.ObjectThis class represents Redberry context. It stores all Redberry session data (in some sense it stores static data).Management of current Redberry context is made through
ContextManagerclass. Context of Redberry is attached to the current thread, so that any thread created from the outside of Redebrry will hold a unique instance ofContextobject. In such a way tensors created in one thread can not be used in the other thread because they are in some sense "attached" to the initial thread. However, if thread is created through the executor service which is obtained fromContextManager.getExecutorService(), it will share the same context as initial thread (such threads could hold concurrent computations regarding single context, the appropriate synchronization is assumed). In order to create a new session of Redberry with a particular context, an instance of this class should be set as a current context viaContextManager.setCurrentContext(Context).- Since:
- 1.0
- See Also:
NameManager,IndexConverterManager,ParseManager,OutputFormat,ContextManager,ContextSettings
-
-
Constructor Summary
Constructors Constructor and Description Context(ContextSettings contextSettings)Creates context from the settings
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description SimpleTensorcreateKronecker(int index1, int index2)Returns Kronecker tensor with specified upper and lower indices.SimpleTensorcreateMetric(int index1, int index2)Returns metric tensor with specified indices.SimpleTensorcreateMetricOrKronecker(int index1, int index2)Returns metric tensor if specified indices have same states and Kronecker tensor if specified indices have different states.SimpleTensorgenerateNewSymbol()Generates a new symbol which never used before during current session.static Contextget()Returns the current context of Redberry session.OutputFormatgetDefaultOutputFormat()Returns current default output format.OutputPort<SimpleTensor>getDefaultParametersGenerator()Return output port which generates new symbol viagenerateNewSymbol()at eachtake()invocation.IndexConverterManagergetIndexConverterManager()Returns index converter manager of current session.java.lang.StringgetKroneckerName()Returns string representation of Kronecker delta namejava.util.Set<IndexType>getMatrixTypes()Returns all matrix types.java.lang.StringgetMetricName()Returns string representation of metric tensor namejava.util.Set<IndexType>getMetricTypes()Returns all metric types.NameDescriptorgetNameDescriptor(int nameId)ReturnsNameDescriptorcorresponding to the specifiedintnameId.NameManagergetNameManager()Returns the name manager (namespace) of current session.ParseManagergetParseManager()Returns parse manager of current sessionorg.apache.commons.math3.random.RandomGeneratorgetRandomGenerator()Returns random generator used by Redberry in current session.booleanisKronecker(SimpleTensor t)Returnstrueif specified tensor is a Kronecker tensorbooleanisKroneckerOrMetric(SimpleTensor t)Returnstrueif specified tensor is a metric or a Kronecker tensorbooleanisMetric(byte type)Returns true if metric is defined for the specified index type.booleanisMetric(SimpleTensor t)Returnstrueif specified tensor is a metric tensorvoidresetTensorNames()This method resets all tensor names in the namespace.voidresetTensorNames(long seed)This method resets all tensor names in the namespace and sets a specified seed to theNameManager.voidsetDefaultOutputFormat(OutputFormat defaultOutputFormat)Sets the default output format.voidsetKroneckerName(java.lang.String name)Sets the default Kronecker tensor name.voidsetMetricName(java.lang.String name)Sets the default metric tensor name.
-
-
-
Constructor Detail
-
Context
public Context(ContextSettings contextSettings)
Creates context from the settings- Parameters:
contextSettings- settings- See Also:
ContextSettings
-
-
Method Detail
-
getMetricTypes
public java.util.Set<IndexType> getMetricTypes()
Returns all metric types.- Returns:
- all metric types
-
getMatrixTypes
public java.util.Set<IndexType> getMatrixTypes()
Returns all matrix types.- Returns:
- all matrix types
-
resetTensorNames
public void resetTensorNames()
This method resets all tensor names in the namespace.Any tensor created before this method call becomes invalid, and must not be used! This method is mainly used in unit tests, so avoid invocations of this method in general computations.
-
resetTensorNames
public void resetTensorNames(long seed)
This method resets all tensor names in the namespace and sets a specified seed to theNameManager. If this method is invoked with constant seed before any interactions with Redberry, further behaviour of Redberry will be fully deterministic from run to run (order of summands and multipliers will be fixed, computation time will be pretty constant, hash codes will be the same).Any tensor created before this method call becomes invalid, and must not be used! This method is mainly used in unit tests, so avoid invocations of this method in general computations.
-
setDefaultOutputFormat
public void setDefaultOutputFormat(OutputFormat defaultOutputFormat)
Sets the default output format. After this step, all expressions will be printed according to the specified output format.- Parameters:
defaultOutputFormat- output format
-
getDefaultOutputFormat
public OutputFormat getDefaultOutputFormat()
Returns current default output format.- Returns:
- current default output format
-
getIndexConverterManager
public IndexConverterManager getIndexConverterManager()
Returns index converter manager of current session.- Returns:
- index converter manager of current session
-
getNameManager
public NameManager getNameManager()
Returns the name manager (namespace) of current session.- Returns:
- the name manager (namespace) of current session.
-
getNameDescriptor
public NameDescriptor getNameDescriptor(int nameId)
ReturnsNameDescriptorcorresponding to the specifiedintnameId.- Parameters:
nameId- integer name of tensor- Returns:
- corresponding
NameDescriptor
-
getKroneckerName
public java.lang.String getKroneckerName()
Returns string representation of Kronecker delta name- Returns:
- string representation of Kronecker delta name
-
getMetricName
public java.lang.String getMetricName()
Returns string representation of metric tensor name- Returns:
- string representation of metric tensor name
-
setMetricName
public void setMetricName(java.lang.String name)
Sets the default metric tensor name. After this step, metric tensor will be printed with the specified string name.- Parameters:
name- string representation of metric tensor name
-
setKroneckerName
public void setKroneckerName(java.lang.String name)
Sets the default Kronecker tensor name. After this step, Kronecker tensor will be printed with the specified string name.- Parameters:
name- string representation of Kronecker tensor name
-
isKronecker
public boolean isKronecker(SimpleTensor t)
Returnstrueif specified tensor is a Kronecker tensor- Parameters:
t- tensor- Returns:
trueif specified tensor is a Kronecker tensor
-
isMetric
public boolean isMetric(SimpleTensor t)
Returnstrueif specified tensor is a metric tensor- Parameters:
t- tensor- Returns:
trueif specified tensor is a metric tensor
-
isKroneckerOrMetric
public boolean isKroneckerOrMetric(SimpleTensor t)
Returnstrueif specified tensor is a metric or a Kronecker tensor- Parameters:
t- tensor- Returns:
trueif specified tensor is a metric or a Kronecker tensor
-
getParseManager
public ParseManager getParseManager()
Returns parse manager of current session- Returns:
- parse manager of current session
-
isMetric
public boolean isMetric(byte type)
Returns true if metric is defined for the specified index type.- Parameters:
type- index type- Returns:
- true if metric is defined for the specified index type
-
createKronecker
public SimpleTensor createKronecker(int index1, int index2)
Returns Kronecker tensor with specified upper and lower indices.- Parameters:
index1- first indexindex2- second index- Returns:
- Kronecker tensor with specified upper and lower indices
- Throws:
java.lang.IllegalArgumentException- if indices have same statesjava.lang.IllegalArgumentException- if indices have different types
-
createMetric
public SimpleTensor createMetric(int index1, int index2)
Returns metric tensor with specified indices.- Parameters:
index1- first indexindex2- second index- Returns:
- metric tensor with specified indices
- Throws:
java.lang.IllegalArgumentException- if indices have different statesjava.lang.IllegalArgumentException- if indices have different typesjava.lang.IllegalArgumentException- if indices have non metric types
-
createMetricOrKronecker
public SimpleTensor createMetricOrKronecker(int index1, int index2)
Returns metric tensor if specified indices have same states and Kronecker tensor if specified indices have different states.- Parameters:
index1- first indexindex2- second index- Returns:
- metric tensor if specified indices have same states and Kronecker tensor if specified indices have different states
- Throws:
java.lang.IllegalArgumentException- if indices have different typesjava.lang.IllegalArgumentException- if indices have same states and non metric types
-
generateNewSymbol
public SimpleTensor generateNewSymbol()
Generates a new symbol which never used before during current session.- Returns:
- new symbol which never used before during current session
-
getDefaultParametersGenerator
public OutputPort<SimpleTensor> getDefaultParametersGenerator()
Return output port which generates new symbol viagenerateNewSymbol()at eachtake()invocation.- Returns:
- output port which generates new symbol via
generateNewSymbol()at eachtake()invocation.
-
getRandomGenerator
public org.apache.commons.math3.random.RandomGenerator getRandomGenerator()
Returns random generator used by Redberry in current session.- Returns:
- random generator used by Redberry in current session
-
get
public static Context get()
Returns the current context of Redberry session.- Returns:
- the current context of Redberry session.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG