Single Vector Summation using Einsum
This is an example of how to properly use the einsum function to compute the summation of a single vector.
from csdl_om import Simulatorimport numpy as npfrom csdl import Modelimport csdl
class ExampleVectorSummation(Model):
def define(self): a = np.arange(4) vec = self.declare_variable('a', val=a)
# Summation of all the entries of a vector self.register_output( 'einsum_summ1', csdl.einsum_new_api(vec, operation=[(33, )]))
sim = Simulator(ExampleVectorSummation())sim.run()
print('a', sim['a'].shape)print(sim['a'])print('einsum_summ1', sim['einsum_summ1'].shape)print(sim['einsum_summ1'])
[0. 1. 2. 3.]einsum_summ1 (1,)[6.]