/** * Creates a given number of deep or shallow (if the kernel implements * Copyable) copies of the given kernel using serialization. * * @param model the kernel to copy * @param num the number of kernel copies to create. * @return an array of kernels. * @throws Exception if an error occurs */ public static Kernel[] makeCopies(Kernel model, int num) throws Exception { if (model == null) { throw new Exception("No model kernel set"); } Kernel[] kernels = new Kernel[num]; if (model instanceof Copyable) { for (int i = 0; i < kernels.length; i++) { kernels[i] = (Kernel) ((Copyable) model).copy(); } } else { SerializedObject so = new SerializedObject(model); for (int i = 0; i < kernels.length; i++) { kernels[i] = (Kernel) so.getObject(); } } return kernels; }
/** * Creates a given number of deep or shallow (if the kernel implements Copyable) * copies of the given kernel using serialization. * * @param model the kernel to copy * @param num the number of kernel copies to create. * @return an array of kernels. * @throws Exception if an error occurs */ public static Kernel[] makeCopies(Kernel model, int num) throws Exception { if (model == null) throw new Exception("No model kernel set"); Kernel[] kernels = new Kernel[num]; if (model instanceof Copyable) { for (int i = 0; i < kernels.length; i++) { kernels[i] = (Kernel) ((Copyable) model).copy(); } } else { SerializedObject so = new SerializedObject(model); for (int i = 0; i < kernels.length; i++) kernels[i] = (Kernel) so.getObject(); } return kernels; }
/** * Creates a shallow copy of the kernel (if it implements Copyable) otherwise * a deep copy using serialization. * * @param kernel the kernel to copy * @return a shallow or deep copy of the kernel * @throws Exception if an error occurs */ public static Kernel makeCopy(Kernel kernel) throws Exception { if (kernel instanceof Copyable) { return (Kernel) ((Copyable) kernel).copy(); } return (Kernel) new SerializedObject(kernel).getObject(); }
/** * Creates a shallow copy of the kernel (if it implements Copyable) * otherwise a deep copy using serialization. * * @param kernel the kernel to copy * @return a shallow or deep copy of the kernel * @throws Exception if an error occurs */ public static Kernel makeCopy(Kernel kernel) throws Exception { if (kernel instanceof Copyable) { return (Kernel) ((Copyable) kernel).copy(); } return (Kernel) new SerializedObject(kernel).getObject(); }