summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/arrayop.h
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/utils/asymptote/arrayop.h')
-rw-r--r--Build/source/utils/asymptote/arrayop.h112
1 files changed, 90 insertions, 22 deletions
diff --git a/Build/source/utils/asymptote/arrayop.h b/Build/source/utils/asymptote/arrayop.h
index 435c00926c0..7832c1f64dc 100644
--- a/Build/source/utils/asymptote/arrayop.h
+++ b/Build/source/utils/asymptote/arrayop.h
@@ -64,28 +64,6 @@ void arrayArrayOp(vm::stack *s)
}
template<class T>
-inline void arrayNegate(vm::stack *s)
-{
- array *a=pop<array*>(s);
- size_t size=checkArray(a);
- array *c=new array(size);
- for(size_t i=0; i < size; i++)
- (*c)[i]=-read<T>(a,i);
- s->push(c);
-}
-
-template<>
-inline void arrayNegate<Int>(vm::stack *s)
-{
- array *a=pop<array*>(s);
- size_t size=checkArray(a);
- array *c=new array(size);
- for(size_t i=0; i < size; i++)
- (*c)[i]=Negate(read<Int>(a,i),i);
- s->push(c);
-}
-
-template<class T>
void sumArray(vm::stack *s)
{
array *a=pop<array*>(s);
@@ -161,6 +139,61 @@ void binopArray3(vm::stack *s)
s->push(m);
}
+template<class T, class U, template <class S> class op>
+void array2Op(vm::stack *s)
+{
+ U b=pop<U>(s);
+ array *a=pop<array*>(s);
+ size_t size=checkArray(a);
+ array *c=new array(size);
+ for(size_t i=0; i < size; ++i) {
+ array *ai=read<array*>(a,i);
+ size_t aisize=checkArray(ai);
+ array *ci=new array(aisize);
+ (*c)[i]=ci;
+ for(size_t j=0; j < aisize; j++)
+ (*ci)[j]=op<T>()(read<T>(ai,j),b,0);
+ }
+ s->push(c);
+}
+
+template<class T, class U, template <class S> class op>
+void opArray2(vm::stack *s)
+{
+ array *a=pop<array*>(s);
+ T b=pop<T>(s);
+ size_t size=checkArray(a);
+ array *c=new array(size);
+ for(size_t i=0; i < size; ++i) {
+ array *ai=read<array*>(a,i);
+ size_t aisize=checkArray(ai);
+ array *ci=new array(aisize);
+ (*c)[i]=ci;
+ for(size_t j=0; j < aisize; j++)
+ (*ci)[j]=op<U>()(read<U>(ai,j),b,0);
+ }
+ s->push(c);
+}
+
+template<class T, template <class S> class op>
+void array2Array2Op(vm::stack *s)
+{
+ array *b=pop<array*>(s);
+ array *a=pop<array*>(s);
+ size_t size=checkArrays(a,b);
+ array *c=new array(size);
+ for(size_t i=0; i < size; ++i) {
+ array *ai=read<array*>(a,i);
+ array *bi=read<array*>(b,i);
+ size_t aisize=checkArrays(ai,bi);
+ array *ci=new array(aisize);
+ (*c)[i]=ci;
+ for(size_t j=0; j < aisize; j++)
+ (*ci)[j]=op<T>()(read<T>(ai,j),read<T>(bi,j),0);
+ }
+ s->push(c);
+}
+
template<class T>
bool Array2Equals(vm::stack *s)
{
@@ -196,6 +229,24 @@ void array2NotEquals(vm::stack *s)
}
template<class T>
+void diagonal(vm::stack *s)
+{
+ array *a=pop<array*>(s);
+ size_t n=checkArray(a);
+ array *c=new array(n);
+ for(size_t i=0; i < n; ++i) {
+ array *ci=new array(n);
+ (*c)[i]=ci;
+ for(size_t j=0; j < i; ++j)
+ (*ci)[j]=T();
+ (*ci)[i]=read<T>(a,i);
+ for(size_t j=i+1; j < n; ++j)
+ (*ci)[j]=T();
+ }
+ s->push(c);
+}
+
+template<class T>
struct compare {
bool operator() (const vm::item& a, const vm::item& b)
{
@@ -435,6 +486,23 @@ void arrayFunc(vm::stack *s)
s->push(c);
}
+template <class T, class S, T (*func)(S)>
+void arrayFunc2(vm::stack *s)
+{
+ array *a=pop<array*>(s);
+ size_t size=checkArray(a);
+ array *c=new array(size);
+ for(size_t i=0; i < size; ++i) {
+ array *ai=read<array*>(a,i);
+ size_t aisize=checkArray(ai);
+ array *ci=new array(aisize);
+ (*c)[i]=ci;
+ for(size_t j=0; j < aisize; j++)
+ (*ci)[j]=func(read<S>(ai,j));
+ }
+ s->push(c);
+}
+
vm::array *Identity(Int n);
camp::triple operator *(const vm::array& a, const camp::triple& v);
camp::triple multshiftless(const vm::array& t, const camp::triple& v);