On Sat, Jun 11, 2022, 18:02 Gilles Sadowski <gillese...@gmail.com> wrote:
> I have a hard time figuring out whether these bits of code are > intended to become the application developer API... > What data-structure(s) will be visible (from the application)? > What will be hidden ("implementation details")? > Developer API will look something like this //1) Static methods to initialize array from external forms ComplexDoubleArray a = ComplexDoubleArray.fromBuffer(Double Buffer); ComplexDoubleArray b = ComplexDoubleArray.fromArray(double[]); ComplexDoubleArray c = ComplexDoubleArray.parseFile(File); //2) Methods on Array interface for complex operations. One for each functional interface type.. unary, binary, scalar operations @FunctionalInterface interface ComplexDoubleUnaryOperator { ComplexDoubleArray apply(ComplexDoubleArray input, ComplexDoubleArray result); } interface ComplexDoubleArray { int size(); //MutableComplexDoubleArray extends ComplexDoubleArray with setter, mutation and static methods to allocate capacity MutableComplexDoubleArray asMutable(); ComplexDoubleArray asImmutable(); default boolean isImmutable() { return true;} default ComplexDoubleArray apply(ComplexDoubleUnaryOperator op){ return op.apply(this, result); } . . . } //Function interfaces behavior - If output array is immutable, operations return a copy, else result is applied in place on the passed in output and returned //3 Developer API usage of complex operations on complex arrays ComplexDoubleArray a = init(); a = a.asImmutable(); ComplexDoubleArray r1 = a.apply(ComplexFunctions::exp); ComplexDoubleArray r2 = a.apply(ComplexParrallelStreamFunctions::exp); ComplexDoubleArray r3 = a.apply(ComplexVectorFunctions::exp); ComplexDoubleArray r4 = a.apply(ComplexJTransformFunctions::forward_fft); // 4 ComplexFunctions can provide commons C99 reference implementations for supported complex operations as static methods that match the functional interfaces. ( Refactored methods from existing Complex class). Third parties can provide alternate implementations such as parallel stream or vector based implementations and used by developers as above. //5 the above functions also reused with existing Complex class? Complex implements ComplexDouble, ComplexDoubleArray { @Override public int size() {return 1;} @Override double [] toDoubleArray() { . . . } . . . //Refactored instance methods of Complex class public Complex exp() { return apply(ComplexFunctions::exp); } . . . } Complex c = Complex.ofCartesian(r,i); //Backward compatible C99 implementation Complex expc = c.exp(); Complex thirdparty_exp = c.apply(SomeThirdPartyFunctions::exp); //Require Java16+ Complex vectorexp = c.apply(Complex VectorFunctions::exp) Thanks, Sumanth