inline bool op_unique::apply_helper(Mat<typename T1::elem_type>& out, const Proxy<T1>& P) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_elem = P.get_n_elem(); if(n_elem == 0) { out.set_size(n_rows, n_cols); return true; } if(n_elem == 1) { const eT tmp = (Proxy<T1>::use_at) ? P.at(0,0) : P[0]; out.set_size(n_rows, n_cols); out[0] = tmp; return true; } Mat<eT> X(n_elem,1); eT* X_mem = X.memptr(); if(Proxy<T1>::use_at == false) { typename Proxy<T1>::ea_type Pea = P.get_ea(); for(uword i=0; i<n_elem; ++i) { const eT val = Pea[i]; if(arma_isnan(val)) { out.reset(); return false; } X_mem[i] = val; } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT val = P.at(row,col); if(arma_isnan(val)) { out.reset(); return false; } (*X_mem) = val; X_mem++; } X_mem = X.memptr(); } arma_unique_comparator<eT> comparator; std::sort( X.begin(), X.end(), comparator ); uword N_unique = 1; for(uword i=1; i < n_elem; ++i) { const eT a = X_mem[i-1]; const eT b = X_mem[i ]; const eT diff = a - b; if(diff != eT(0)) { ++N_unique; } } uword out_n_rows; uword out_n_cols; if( (n_rows == 1) || (n_cols == 1) ) { if(n_rows == 1) { out_n_rows = 1; out_n_cols = N_unique; } else { out_n_rows = N_unique; out_n_cols = 1; } } else { out_n_rows = N_unique; out_n_cols = 1; } out.set_size(out_n_rows, out_n_cols); eT* out_mem = out.memptr(); if(n_elem > 0) { (*out_mem) = X_mem[0]; out_mem++; } for(uword i=1; i < n_elem; ++i) { const eT a = X_mem[i-1]; const eT b = X_mem[i ]; const eT diff = a - b; if(diff != eT(0)) { (*out_mem) = b; out_mem++; } } return true; }
void ListenersBase::remove_void (void* const listener) { ReadWriteMutex::ScopedWriteLockType lock (m_groups_mutex); // Make sure the listener exists #if VF_DEBUG { bool exists = false; for (Groups::iterator iter = m_groups.begin(); iter != m_groups.end();) { Group* group = &(*iter++); // this should never happen while we hold the mutex jassert (!group->empty ()); if (group->contains (listener)) { jassert (!exists); // added twice? exists = true; // keep going to make sure there are no empty groups } } jassert (exists); } #endif // Find the group and remove for (Groups::iterator iter = m_groups.begin(); iter != m_groups.end();) { Group::Ptr group = &(*iter++); // If the listener is in there, take it out. if (group->remove (listener)) { // Are we the last listener? if (group->empty ()) { // Tell proxies to remove the group { ReadWriteMutex::ScopedWriteLockType lock (m_proxies_mutex); for (Proxies::iterator iter = m_proxies.begin (); iter != m_proxies.end ();) { Proxy* proxy = &(*iter++); proxy->remove (group); } } // Remove it from the list and manually release // the reference since the list uses raw pointers. m_groups.erase (m_groups.iterator_to (*group.getObject ())); group->decReferenceCount(); // It is still possible for the group to exist at this // point in a thread queue but it will get processed, // do nothing, and release its own final reference. } break; } } }
inline bool arma_sort_index_helper(Mat<uword>& out, const Proxy<T1>& P, const uword sort_type, typename arma_not_cx<typename T1::elem_type>::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const uword n_elem = P.get_n_elem(); out.set_size(n_elem, 1); std::vector< arma_sort_index_packet<eT, uword> > packet_vec(n_elem); if(Proxy<T1>::prefer_at_accessor == false) { for(uword i=0; i<n_elem; ++i) { const eT val = P[i]; if(arma_isnan(val)) { out.reset(); return false; } packet_vec[i].val = val; packet_vec[i].index = i; } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); uword i = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT val = P.at(row,col); if(arma_isnan(val)) { out.reset(); return false; } packet_vec[i].val = val; packet_vec[i].index = i; ++i; } } if(sort_type == 0) { // ascend arma_sort_index_helper_ascend comparator; if(sort_stable == false) { std::sort( packet_vec.begin(), packet_vec.end(), comparator ); } else { std::stable_sort( packet_vec.begin(), packet_vec.end(), comparator ); } } else { // descend arma_sort_index_helper_descend comparator; if(sort_stable == false) { std::sort( packet_vec.begin(), packet_vec.end(), comparator ); } else { std::stable_sort( packet_vec.begin(), packet_vec.end(), comparator ); } } uword* out_mem = out.memptr(); for(uword i=0; i<n_elem; ++i) { out_mem[i] = packet_vec[i].index; } return true; }
int main() { Proxy p; p.f(); p.g(); p.h(); } ///:~
//------------------------------------------------------------------------------------- PyObject* Proxy::__py_pyStreamStringToClient(PyObject* self, PyObject* args) { uint16 currargsSize = PyTuple_Size(args); Proxy* pobj = static_cast<Proxy*>(self); if(pobj->clientMailbox() == NULL) { PyErr_Format(PyExc_AssertionError, "Proxy::streamStringToClient: has no client."); PyErr_PrintEx(0); return NULL; } if(currargsSize > 3 || currargsSize == 0) { PyErr_Format(PyExc_AssertionError, "Proxy::streamStringToClient: args max require 3, gived %d! is script[%s].\n", currargsSize, pobj->scriptName()); PyErr_PrintEx(0); return NULL; } PyObject* pyData = NULL; PyObject* pyDesc = NULL; int16 id = -1; if(currargsSize == 1) { if(PyArg_ParseTuple(args, "O", &pyData) == -1) { PyErr_Format(PyExc_TypeError, "Proxy::streamStringToClient: args is error!"); PyErr_PrintEx(0); return NULL; } } else if(currargsSize == 2) { if(PyArg_ParseTuple(args, "O|O", &pyData, &pyDesc) == -1) { PyErr_Format(PyExc_TypeError, "Proxy::streamStringToClient: args is error!"); PyErr_PrintEx(0); return NULL; } } else if(currargsSize == 3) { if(PyArg_ParseTuple(args, "O|O|H", &pyData, &pyDesc, &id) == -1) { PyErr_Format(PyExc_TypeError, "Proxy::streamStringToClient: args is error!"); PyErr_PrintEx(0); return NULL; } } char* pDescr = NULL; if(pDescr != NULL) { wchar_t* PyUnicode_AsWideCharStringRet1 = PyUnicode_AsWideCharString(pyDesc, NULL); pDescr = strutil::wchar2char(PyUnicode_AsWideCharStringRet1); PyMem_Free(PyUnicode_AsWideCharStringRet1); } if(pDescr && strlen(pDescr) > 255) { PyErr_Format(PyExc_TypeError, "Proxy::streamFileToClient: the descr-size(%d > 255)!", strlen(pDescr)); PyErr_PrintEx(0); free(pDescr); return NULL; } int16 rid = pobj->streamStringToClient(pyData, (pDescr == NULL ? "" : pDescr), id); if(pDescr) free(pDescr); return PyLong_FromLong(rid); }
inline typename arma_cx_only<typename T1::elem_type>::result op_max::max(const Base<typename T1::elem_type,T1>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type<eT>::result T; const Proxy<T1> P(X.get_ref()); const uword n_elem = P.get_n_elem(); arma_debug_check( (n_elem == 0), "max(): given object has no elements" ); T max_val = priv::most_neg<T>(); if(Proxy<T1>::prefer_at_accessor == false) { typedef typename Proxy<T1>::ea_type ea_type; ea_type A = P.get_ea(); uword index = 0; for(uword i=0; i<n_elem; ++i) { const T tmp = std::abs(A[i]); if(tmp > max_val) { max_val = tmp; index = i; } } return( A[index] ); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); uword best_row = 0; uword best_col = 0; if(n_rows == 1) { for(uword col=0; col < n_cols; ++col) { const T tmp = std::abs(P.at(0,col)); if(tmp > max_val) { max_val = tmp; best_col = col; } } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const T tmp = std::abs(P.at(row,col)); if(tmp > max_val) { max_val = tmp; best_row = row; best_col = col; } } } return P.at(best_row, best_col); } }
Handle<Value> Proxy::proxyConstructor(const Arguments& args) { HandleScope scope; JNIEnv *env = JNIScope::getEnv(); Local<Object> jsProxy = args.Holder(); Handle<Object> properties = Object::New(); jsProxy->Set(propertiesSymbol, properties, PropertyAttribute(DontEnum)); Handle<Object> prototype = jsProxy->GetPrototype()->ToObject(); Handle<Function> constructor = Handle<Function>::Cast(prototype->Get(constructorSymbol)); jclass javaClass = (jclass) External::Unwrap(constructor->Get(javaClassSymbol)); // If ProxyFactory::createV8Proxy invoked us, unwrap // the pre-created Java proxy it sent. jobject javaProxy = ProxyFactory::unwrapJavaProxy(args); bool deleteRef = false; if (!javaProxy) { javaProxy = ProxyFactory::createJavaProxy(javaClass, jsProxy, args); deleteRef = true; } JNIUtil::logClassName("Create proxy: %s", javaClass); Proxy *proxy = new Proxy(javaProxy); proxy->Wrap(jsProxy); int length = args.Length(); if (length > 0 && args[0]->IsObject()) { /* Handle<Value> argsStr = V8Util::jsonStringify(args[0]); String::Utf8Value str(argsStr); LOGV(TAG, " with args: %s", *str); */ bool extend = true; Handle<Object> createProperties = args[0]->ToObject(); Local<String> constructorName = createProperties->GetConstructorName(); if (strcmp(*String::Utf8Value(constructorName), "Arguments") == 0) { extend = false; int32_t argsLength = createProperties->Get(String::New("length"))->Int32Value(); if (argsLength > 1) { Handle<Value> properties = createProperties->Get(1); if (properties->IsObject()) { extend = true; createProperties = properties->ToObject(); } } } if (extend) { Handle<Array> names = createProperties->GetOwnPropertyNames(); int length = names->Length(); for (int i = 0; i < length; ++i) { Handle<Value> name = names->Get(i); Handle<Value> value = createProperties->Get(name); bool isProperty = true; if (name->IsString()) { Handle<String> nameString = name->ToString(); if (!jsProxy->HasRealNamedCallbackProperty(nameString) && !jsProxy->HasRealNamedProperty(nameString)) { jsProxy->Set(name, value); isProperty = false; } } if (isProperty) { properties->Set(name, value); } } } } if (!args.Data().IsEmpty() && args.Data()->IsFunction()) { Handle<Function> proxyFn = Handle<Function>::Cast(args.Data()); Handle<Value> *fnArgs = new Handle<Value>[length]; for (int i = 0; i < length; ++i) { fnArgs[i] = args[i]; } proxyFn->Call(jsProxy, length, fnArgs); } if (deleteRef) { JNIEnv *env = JNIScope::getEnv(); if (env) { env->DeleteLocalRef(javaProxy); } } return jsProxy; }
inline void op_any::apply_helper(Mat<uword>& out, const Proxy<T1>& P, const uword dim) { arma_extra_debug_sigprint(); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); typedef typename Proxy<T1>::elem_type eT; if(dim == 0) // traverse rows (ie. process each column) { out.zeros(1, n_cols); uword* out_mem = out.memptr(); if(is_Mat<typename Proxy<T1>::stored_type>::value == true) { const unwrap<typename Proxy<T1>::stored_type> U(P.Q); for(uword col=0; col < n_cols; ++col) { const eT* colmem = U.M.colptr(col); for(uword row=0; row < n_rows; ++row) { if(colmem[row] != eT(0)) { out_mem[col] = uword(1); break; } } } } else { for(uword col=0; col < n_cols; ++col) { for(uword row=0; row < n_rows; ++row) { if(P.at(row,col) != eT(0)) { out_mem[col] = uword(1); break; } } } } } else { out.zeros(n_rows, 1); uword* out_mem = out.memptr(); if(is_Mat<typename Proxy<T1>::stored_type>::value == true) { const unwrap<typename Proxy<T1>::stored_type> U(P.Q); for(uword col=0; col < n_cols; ++col) { const eT* colmem = U.M.colptr(col); for(uword row=0; row < n_rows; ++row) { if(colmem[row] != eT(0)) { out_mem[row] = uword(1); } } } } else { for(uword col=0; col < n_cols; ++col) { for(uword row=0; row < n_rows; ++row) { if(P.at(row,col) != eT(0)) { out_mem[row] = uword(1); } } } } } }
inline typename arma_not_cx<typename T1::elem_type>::result op_min::min_with_index(const Proxy<T1>& P, uword& index_of_min_val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum<eT>::nan; } eT best_val = priv::most_pos<eT>(); uword best_index = 0; if(Proxy<T1>::use_at == false) { typedef typename Proxy<T1>::ea_type ea_type; ea_type A = P.get_ea(); for(uword i=0; i<n_elem; ++i) { const eT tmp = A[i]; if(tmp < best_val) { best_val = tmp; best_index = i; } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { for(uword i=0; i < n_cols; ++i) { const eT tmp = P.at(0,i); if(tmp < best_val) { best_val = tmp; best_index = i; } } } else if(n_cols == 1) { for(uword i=0; i < n_rows; ++i) { const eT tmp = P.at(i,0); if(tmp < best_val) { best_val = tmp; best_index = i; } } } else { uword count = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT tmp = P.at(row,col); if(tmp < best_val) { best_val = tmp; best_index = count; } ++count; } } } index_of_min_val = best_index; return best_val; }
inline typename arma_cx_only<typename T1::elem_type>::result op_min::min(const Base<typename T1::elem_type,T1>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type<eT>::result T; const Proxy<T1> P(X.get_ref()); const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum<eT>::nan; } T min_val = priv::most_pos<T>(); if(Proxy<T1>::use_at == false) { typedef typename Proxy<T1>::ea_type ea_type; ea_type A = P.get_ea(); uword index = 0; for(uword i=0; i<n_elem; ++i) { const T tmp = std::abs(A[i]); if(tmp < min_val) { min_val = tmp; index = i; } } return( A[index] ); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); uword best_row = 0; uword best_col = 0; if(n_rows == 1) { for(uword col=0; col < n_cols; ++col) { const T tmp = std::abs(P.at(0,col)); if(tmp < min_val) { min_val = tmp; best_col = col; } } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const T tmp = std::abs(P.at(row,col)); if(tmp < min_val) { min_val = tmp; best_row = row; best_col = col; } } } return P.at(best_row, best_col); } }
inline typename arma_not_cx<typename T1::elem_type>::result op_min::min(const Base<typename T1::elem_type,T1>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy<T1> P(X.get_ref()); const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum<eT>::nan; } eT min_val = priv::most_pos<eT>(); if(Proxy<T1>::use_at == false) { typedef typename Proxy<T1>::ea_type ea_type; ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j<n_elem; i+=2, j+=2) { const eT tmp_i = A[i]; const eT tmp_j = A[j]; if(tmp_i < min_val) { min_val = tmp_i; } if(tmp_j < min_val) { min_val = tmp_j; } } if(i < n_elem) { const eT tmp_i = A[i]; if(tmp_i < min_val) { min_val = tmp_i; } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp_i = P.at(0,i); const eT tmp_j = P.at(0,j); if(tmp_i < min_val) { min_val = tmp_i; } if(tmp_j < min_val) { min_val = tmp_j; } } if(i < n_cols) { const eT tmp_i = P.at(0,i); if(tmp_i < min_val) { min_val = tmp_i; } } } else { for(uword col=0; col < n_cols; ++col) { uword i,j; for(i=0, j=1; j < n_rows; i+=2, j+=2) { const eT tmp_i = P.at(i,col); const eT tmp_j = P.at(j,col); if(tmp_i < min_val) { min_val = tmp_i; } if(tmp_j < min_val) { min_val = tmp_j; } } if(i < n_rows) { const eT tmp_i = P.at(i,col); if(tmp_i < min_val) { min_val = tmp_i; } } } } } return min_val; }
arma_hot inline void op_mean::apply_noalias_proxy(Mat<typename T1::elem_type>& out, const Proxy<T1>& P, const uword dim) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type<eT>::result T; const uword P_n_rows = P.get_n_rows(); const uword P_n_cols = P.get_n_cols(); if(dim == 0) { out.set_size((P_n_rows > 0) ? 1 : 0, P_n_cols); if(P_n_rows == 0) { return; } eT* out_mem = out.memptr(); for(uword col=0; col < P_n_cols; ++col) { eT val1 = eT(0); eT val2 = eT(0); uword i,j; for(i=0, j=1; j < P_n_rows; i+=2, j+=2) { val1 += P.at(i,col); val2 += P.at(j,col); } if(i < P_n_rows) { val1 += P.at(i,col); } out_mem[col] = (val1 + val2) / T(P_n_rows); } } else if(dim == 1) { out.zeros(P_n_rows, (P_n_cols > 0) ? 1 : 0); if(P_n_cols == 0) { return; } eT* out_mem = out.memptr(); for(uword col=0; col < P_n_cols; ++col) for(uword row=0; row < P_n_rows; ++row) { out_mem[row] += P.at(row,col); } out /= T(P_n_cols); } if(out.is_finite() == false) { // TODO: replace with dedicated handling to avoid unwrapping op_mean::apply_noalias_unwrap(out, P, dim); } }
inline void op_all::apply_helper(Mat<uword>& out, const Proxy<T1>& P, const uword dim) { arma_extra_debug_sigprint(); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); typedef typename Proxy<T1>::elem_type eT; if(dim == 0) // traverse rows (ie. process each column) { out.zeros(1, n_cols); if(out.n_elem == 0) { return; } uword* out_mem = out.memptr(); if(is_Mat<typename Proxy<T1>::stored_type>::value == true) { const unwrap<typename Proxy<T1>::stored_type> U(P.Q); for(uword col=0; col < n_cols; ++col) { const eT* colmem = U.M.colptr(col); uword count = 0; for(uword row=0; row < n_rows; ++row) { if(colmem[row] != eT(0)) { ++count; } } out_mem[col] = (n_rows == count) ? uword(1) : uword(0); } } else { for(uword col=0; col < n_cols; ++col) { uword count = 0; for(uword row=0; row < n_rows; ++row) { if(P.at(row,col) != eT(0)) { ++count; } } out_mem[col] = (n_rows == count) ? uword(1) : uword(0); } } } else { out.zeros(n_rows, 1); uword* out_mem = out.memptr(); // internal dual use of 'out': keep the counts for each row if(is_Mat<typename Proxy<T1>::stored_type>::value == true) { const unwrap<typename Proxy<T1>::stored_type> U(P.Q); for(uword col=0; col < n_cols; ++col) { const eT* colmem = U.M.colptr(col); for(uword row=0; row < n_rows; ++row) { if(colmem[row] != eT(0)) { ++out_mem[row]; } } } } else { for(uword col=0; col < n_cols; ++col) { for(uword row=0; row < n_rows; ++row) { if(P.at(row,col) != eT(0)) { ++out_mem[row]; } } } } // see what the counts tell us for(uword row=0; row < n_rows; ++row) { out_mem[row] = (n_cols == out_mem[row]) ? uword(1) : uword(0); } } }
inline void op_unique::apply(Mat<typename T1::elem_type>& out, const Op<T1, op_unique>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy<T1> P(X.m); const uword in_n_rows = P.get_n_rows(); const uword in_n_cols = P.get_n_cols(); const uword in_n_elem = P.get_n_elem(); if(in_n_elem <= 1) { if(in_n_elem == 1) { const eT tmp = P[0]; out.set_size(in_n_rows, in_n_cols); out[0] = tmp; } else { out.set_size(in_n_rows, in_n_cols); } return; } std::vector<eT> lvec(in_n_elem); if(Proxy<T1>::prefer_at_accessor == false) { typename Proxy<T1>::ea_type Pea = P.get_ea(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = Pea[i]; const eT tmp_j = Pea[j]; lvec[i] = tmp_i; lvec[j] = tmp_j; } if(i < in_n_elem) { lvec[i] = Pea[i]; } } else { uword i = 0; for(uword col=0; col < in_n_cols; ++col) for(uword row=0; row < in_n_rows; ++row, ++i) { lvec[i] = P.at(row,col); } } std::sort( lvec.begin(), lvec.end() ); uword N_unique = 1; for(uword i=1; i < in_n_elem; ++i) { const eT a = lvec[i-1]; const eT b = lvec[i ]; const eT diff = a - b; if(diff != eT(0)) { ++N_unique; } } uword out_n_rows; uword out_n_cols; if( (in_n_rows == 1) || (in_n_cols == 1) ) { if(in_n_rows == 1) { out_n_rows = 1; out_n_cols = N_unique; } else { out_n_rows = N_unique; out_n_cols = 1; } } else { out_n_rows = N_unique; out_n_cols = 1; } // we don't need to worry about aliasing at this stage, as all the data is stored in lvec out.set_size(out_n_rows, out_n_cols); eT* out_mem = out.memptr(); if(in_n_elem > 0) { out_mem[0] = lvec[0]; } N_unique = 1; for(uword i=1; i < in_n_elem; ++i) { const eT a = lvec[i-1]; const eT b = lvec[i ]; const eT diff = a - b; if(diff != eT(0)) { out_mem[N_unique] = b; ++N_unique; } } }
Handle<Value> Proxy::proxyOnPropertiesChanged(const Arguments& args) { HandleScope scope; Handle<Object> jsProxy = args.Holder(); if (args.Length() < 1 || !args[0]->IsArray()) { return JSException::Error("Proxy.propertiesChanged requires a list of lists of property name, the old value, and the new value"); } JNIEnv *env = JNIScope::getEnv(); if (!env) { return JSException::GetJNIEnvironmentError(); } Proxy *proxy = unwrap(jsProxy); if (!proxy) { return JSException::Error("Failed to unwrap Proxy instance"); } Local<Array> changes = Local<Array>::Cast(args[0]); uint32_t length = changes->Length(); jobjectArray jChanges = env->NewObjectArray(length, JNIUtil::objectClass, NULL); for (uint32_t i = 0; i < length; ++i) { Local<Array> change = Local<Array>::Cast(changes->Get(i)); Local<String> name = change->Get(INDEX_NAME)->ToString(); Local<Value> oldValue = change->Get(INDEX_OLD_VALUE); Local<Value> value = change->Get(INDEX_VALUE); jobjectArray jChange = env->NewObjectArray(3, JNIUtil::objectClass, NULL); jstring jName = TypeConverter::jsStringToJavaString(name); env->SetObjectArrayElement(jChange, INDEX_NAME, jName); env->DeleteLocalRef(jName); bool isNew; jobject jOldValue = TypeConverter::jsValueToJavaObject(oldValue, &isNew); env->SetObjectArrayElement(jChange, INDEX_OLD_VALUE, jOldValue); if (isNew) { env->DeleteLocalRef(jOldValue); } jobject jValue = TypeConverter::jsValueToJavaObject(value, &isNew); env->SetObjectArrayElement(jChange, INDEX_VALUE, jValue); if (isNew) { env->DeleteLocalRef(jValue); } env->SetObjectArrayElement(jChanges, i, jChange); env->DeleteLocalRef(jChange); } jobject javaProxy = proxy->getJavaObject(); env->CallVoidMethod(javaProxy, JNIUtil::krollProxyOnPropertiesChangedMethod, jChanges); env->DeleteLocalRef(jChanges); if (!JavaObject::useGlobalRefs) { env->DeleteLocalRef(javaProxy); } return Undefined(); }
inline bool op_any::any_vec_helper ( const mtGlue<uword, T1, T2, glue_type>& X, const typename arma_glue_rel_only<glue_type>::result junk1, const typename arma_not_cx<typename T1::elem_type>::result junk2, const typename arma_not_cx<typename T2::elem_type>::result junk3 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); arma_ignore(junk3); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename Proxy<T1>::ea_type ea_type1; typedef typename Proxy<T2>::ea_type ea_type2; const Proxy<T1> A(X.A); const Proxy<T2> B(X.B); arma_debug_assert_same_size(A, B, "relational operator"); const bool prefer_at_accessor = Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor; if(prefer_at_accessor == false) { ea_type1 PA = A.get_ea(); ea_type2 PB = B.get_ea(); const uword n_elem = A.get_n_elem(); for(uword i=0; i<n_elem; ++i) { const eT1 tmp1 = PA[i]; const eT2 tmp2 = PB[i]; if(is_same_type<glue_type, glue_rel_lt >::yes) { if(tmp1 < tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_gt >::yes) { if(tmp1 > tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_lteq >::yes) { if(tmp1 <= tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_gteq >::yes) { if(tmp1 >= tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_eq >::yes) { if(tmp1 == tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_noteq >::yes) { if(tmp1 != tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_and >::yes) { if(tmp1 && tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_or >::yes) { if(tmp1 || tmp2) { return true; } } } } else { const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT1 tmp1 = A.at(row,col); const eT2 tmp2 = B.at(row,col); if(is_same_type<glue_type, glue_rel_lt >::yes) { if(tmp1 < tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_gt >::yes) { if(tmp1 > tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_lteq >::yes) { if(tmp1 <= tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_gteq >::yes) { if(tmp1 >= tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_eq >::yes) { if(tmp1 == tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_noteq >::yes) { if(tmp1 != tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_and >::yes) { if(tmp1 && tmp2) { return true; } } else if(is_same_type<glue_type, glue_rel_or >::yes) { if(tmp1 || tmp2) { return true; } } } } return false; }
inline bool op_pinv::apply_direct(Mat<typename T1::elem_type>& out, const Base<typename T1::elem_type,T1>& expr, typename T1::pod_type tol, const bool use_divide_and_conquer) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; arma_debug_check((tol < T(0)), "pinv(): tolerance must be >= 0"); const Proxy<T1> P(expr.get_ref()); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if( (n_rows*n_cols) == 0 ) { out.set_size(n_cols,n_rows); return true; } // economical SVD decomposition Mat<eT> U; Col< T> s; Mat<eT> V; bool status = false; if(use_divide_and_conquer) { status = (n_cols > n_rows) ? auxlib::svd_dc_econ(U, s, V, trans(P.Q)) : auxlib::svd_dc_econ(U, s, V, P.Q); } else { status = (n_cols > n_rows) ? auxlib::svd_econ(U, s, V, trans(P.Q), 'b') : auxlib::svd_econ(U, s, V, P.Q, 'b'); } if(status == false) { out.soft_reset(); return false; } const uword s_n_elem = s.n_elem; const T* s_mem = s.memptr(); // set tolerance to default if it hasn't been specified if( (tol == T(0)) && (s_n_elem > 0) ) { tol = (std::max)(n_rows, n_cols) * s_mem[0] * std::numeric_limits<T>::epsilon(); } uword count = 0; for(uword i = 0; i < s_n_elem; ++i) { count += (s_mem[i] >= tol) ? uword(1) : uword(0); } if(count > 0) { Col<T> s2(count); T* s2_mem = s2.memptr(); uword count2 = 0; for(uword i=0; i < s_n_elem; ++i) { const T val = s_mem[i]; if(val >= tol) { s2_mem[count2] = T(1) / val; ++count2; } } if(n_rows >= n_cols) { out = ( (V.n_cols > count) ? V.cols(0,count-1) : V ) * diagmat(s2) * trans( (U.n_cols > count) ? U.cols(0,count-1) : U ); } else { out = ( (U.n_cols > count) ? U.cols(0,count-1) : U ) * diagmat(s2) * trans( (V.n_cols > count) ? V.cols(0,count-1) : V ); } } else { out.zeros(n_cols, n_rows); } return true; }
inline bool op_any::any_vec_helper ( const mtOp<uword, T1, op_type>& X, const typename arma_op_rel_only<op_type>::result junk1, const typename arma_not_cx<typename T1::elem_type>::result junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); typedef typename T1::elem_type eT; const eT val = X.aux; const Proxy<T1> P(X.m); if(Proxy<T1>::prefer_at_accessor == false) { typename Proxy<T1>::ea_type Pea = P.get_ea(); const uword n_elem = P.get_n_elem(); for(uword i=0; i < n_elem; ++i) { const eT tmp = Pea[i]; if(is_same_type<op_type, op_rel_lt_pre >::yes) { if(val < tmp) { return true; } } else if(is_same_type<op_type, op_rel_lt_post >::yes) { if(tmp < val) { return true; } } else if(is_same_type<op_type, op_rel_gt_pre >::yes) { if(val > tmp) { return true; } } else if(is_same_type<op_type, op_rel_gt_post >::yes) { if(tmp > val) { return true; } } else if(is_same_type<op_type, op_rel_lteq_pre >::yes) { if(val <= tmp) { return true; } } else if(is_same_type<op_type, op_rel_lteq_post>::yes) { if(tmp <= val) { return true; } } else if(is_same_type<op_type, op_rel_gteq_pre >::yes) { if(val >= tmp) { return true; } } else if(is_same_type<op_type, op_rel_gteq_post>::yes) { if(tmp >= val) { return true; } } else if(is_same_type<op_type, op_rel_eq >::yes) { if(tmp == val) { return true; } } else if(is_same_type<op_type, op_rel_noteq >::yes) { if(tmp != val) { return true; } } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT tmp = P.at(row,col); if(is_same_type<op_type, op_rel_lt_pre >::yes) { if(val < tmp) { return true; } } else if(is_same_type<op_type, op_rel_lt_post >::yes) { if(tmp < val) { return true; } } else if(is_same_type<op_type, op_rel_gt_pre >::yes) { if(val > tmp) { return true; } } else if(is_same_type<op_type, op_rel_gt_post >::yes) { if(tmp > val) { return true; } } else if(is_same_type<op_type, op_rel_lteq_pre >::yes) { if(val <= tmp) { return true; } } else if(is_same_type<op_type, op_rel_lteq_post>::yes) { if(tmp <= val) { return true; } } else if(is_same_type<op_type, op_rel_gteq_pre >::yes) { if(val >= tmp) { return true; } } else if(is_same_type<op_type, op_rel_gteq_post>::yes) { if(tmp >= val) { return true; } } else if(is_same_type<op_type, op_rel_eq >::yes) { if(tmp == val) { return true; } } else if(is_same_type<op_type, op_rel_noteq >::yes) { if(tmp != val) { return true; } } } } return false; }
arma_hot inline typename T1::pod_type arma_vec_norm_1(const Proxy<T1>& P) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; T acc = T(0); if(Proxy<T1>::prefer_at_accessor == false) { typename Proxy<T1>::ea_type A = P.get_ea(); const uword N = P.get_n_elem(); T acc1 = T(0); T acc2 = T(0); uword i,j; for(i=0, j=1; j<N; i+=2, j+=2) { acc1 += std::abs(A[i]); acc2 += std::abs(A[j]); } if(i < N) { acc1 += std::abs(A[i]); } acc = acc1 + acc2; } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { for(uword col=0; col<n_cols; ++col) { acc += std::abs(P.at(0,col)); } } else { for(uword col=0; col<n_cols; ++col) { uword i,j; for(i=0, j=1; j<n_rows; i+=2, j+=2) { acc += std::abs(P.at(i,col)); acc += std::abs(P.at(j,col)); } if(i < n_rows) { acc += std::abs(P.at(i,col)); } } } } return acc; }
inline typename arma_not_cx<typename T1::elem_type>::result op_max::max(const Base<typename T1::elem_type,T1>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy<T1> P(X.get_ref()); const uword n_elem = P.get_n_elem(); arma_debug_check( (n_elem == 0), "max(): given object has no elements" ); eT max_val = priv::most_neg<eT>(); if(Proxy<T1>::prefer_at_accessor == false) { typedef typename Proxy<T1>::ea_type ea_type; ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j<n_elem; i+=2, j+=2) { const eT tmp_i = A[i]; const eT tmp_j = A[j]; if(tmp_i > max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < n_elem) { const eT tmp_i = A[i]; if(tmp_i > max_val) { max_val = tmp_i; } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp_i = P.at(0,i); const eT tmp_j = P.at(0,j); if(tmp_i > max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < n_cols) { const eT tmp_i = P.at(0,i); if(tmp_i > max_val) { max_val = tmp_i; } } } else { for(uword col=0; col < n_cols; ++col) { uword i,j; for(i=0, j=1; j < n_rows; i+=2, j+=2) { const eT tmp_i = P.at(i,col); const eT tmp_j = P.at(j,col); if(tmp_i > max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < n_rows) { const eT tmp_i = P.at(i,col); if(tmp_i > max_val) { max_val = tmp_i; } } } } } return max_val; }
arma_hot inline typename T1::pod_type arma_vec_norm_min(const Proxy<T1>& P) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const uword N = P.get_n_elem(); T min_val = (N != 1) ? priv::most_pos<T>() : std::abs(P[0]); if(Proxy<T1>::prefer_at_accessor == false) { typename Proxy<T1>::ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j<N; i+=2, j+=2) { const T tmp_i = std::abs(A[i]); const T tmp_j = std::abs(A[j]); if(min_val > tmp_i) { min_val = tmp_i; } if(min_val > tmp_j) { min_val = tmp_j; } } if(i < N) { const T tmp_i = std::abs(A[i]); if(min_val > tmp_i) { min_val = tmp_i; } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows != 1) { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const T tmp = std::abs(P.at(row,col)); if(min_val > tmp) { min_val = tmp; } } } else { for(uword col=0; col < n_cols; ++col) { const T tmp = std::abs(P.at(0,col)); if(min_val > tmp) { min_val = tmp; } } } } return min_val; }
inline void subview_elem1<eT,T1>::inplace_op(const Base<eT,T2>& x) { arma_extra_debug_sigprint(); Mat<eT>& m_local = *m_ptr; eT* m_mem = m_local.memptr(); const u32 m_n_elem = m_local.n_elem; const unwrap_check_mixed<T1> tmp(a.get_ref(), m_local); const umat& aa = tmp.M; arma_debug_check ( ( aa.is_vec() == false ), "Mat::elem(): given object is not a vector" ); const u32* aa_mem = aa.memptr(); const u32 aa_n_elem = aa.n_elem; const Proxy<T2> P(x.get_ref()); arma_debug_check( (aa_n_elem != P.get_n_elem()), "Mat::elem(): size mismatch" ); if(P.is_alias(m) == false) { typename Proxy<T2>::ea_type X = P.get_ea(); u32 i,j; for(i=0, j=1; j<aa_n_elem; i+=2, j+=2) { const u32 ii = aa_mem[i]; const u32 jj = aa_mem[j]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); if(is_same_type<op_type, op_subview_elem_equ >::value == true) { m_mem[ii] = X[i]; m_mem[jj] = X[j]; } else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += X[i]; m_mem[jj] += X[j]; } else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= X[i]; m_mem[jj] -= X[j]; } else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= X[i]; m_mem[jj] *= X[j]; } else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { m_mem[ii] /= X[i]; m_mem[jj] /= X[j]; } } if(i < aa_n_elem) { const u32 ii = aa_mem[i]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); if(is_same_type<op_type, op_subview_elem_equ >::value == true) { m_mem[ii] = X[i]; } else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += X[i]; } else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= X[i]; } else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= X[i]; } else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { m_mem[ii] /= X[i]; } } } else { arma_extra_debug_print("subview_elem1::inplace_op(): aliasing detected"); const unwrap_check<typename Proxy<T2>::stored_type> tmp(P.Q, m_local); const Mat<eT>& M = tmp.M; const eT* X = M.memptr(); u32 i,j; for(i=0, j=1; j<aa_n_elem; i+=2, j+=2) { const u32 ii = aa_mem[i]; const u32 jj = aa_mem[j]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); if(is_same_type<op_type, op_subview_elem_equ >::value == true) { m_mem[ii] = X[i]; m_mem[jj] = X[j]; } else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += X[i]; m_mem[jj] += X[j]; } else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= X[i]; m_mem[jj] -= X[j]; } else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= X[i]; m_mem[jj] *= X[j]; } else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { m_mem[ii] /= X[i]; m_mem[jj] /= X[j]; } } if(i < aa_n_elem) { const u32 ii = aa_mem[i]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); if(is_same_type<op_type, op_subview_elem_equ >::value == true) { m_mem[ii] = X[i]; } else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += X[i]; } else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= X[i]; } else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= X[i]; } else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { m_mem[ii] /= X[i]; } } } }
arma_hot inline typename T1::pod_type arma_vec_norm_2 ( const Proxy<T1>& P, const typename arma_not_cx<typename T1::elem_type>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; T acc = T(0); if(Proxy<T1>::prefer_at_accessor == false) { typename Proxy<T1>::ea_type A = P.get_ea(); const uword N = P.get_n_elem(); T acc1 = T(0); T acc2 = T(0); uword i,j; for(i=0, j=1; j<N; i+=2, j+=2) { const T tmp_i = A[i]; const T tmp_j = A[j]; acc1 += tmp_i * tmp_i; acc2 += tmp_j * tmp_j; } if(i < N) { const T tmp_i = A[i]; acc1 += tmp_i * tmp_i; } acc = acc1 + acc2; } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { for(uword col=0; col<n_cols; ++col) { const T tmp = P.at(0,col); acc += tmp * tmp; } } else { for(uword col=0; col<n_cols; ++col) { uword i,j; for(i=0, j=1; j<n_rows; i+=2, j+=2) { const T tmp_i = P.at(i,col); const T tmp_j = P.at(j,col); acc += tmp_i * tmp_i; acc += tmp_j * tmp_j; } if(i < n_rows) { const T tmp_i = P.at(i,col); acc += tmp_i * tmp_i; } } } } return std::sqrt(acc); }
Proxy* WinHttpIO::getautoproxy() { Proxy* proxy = new Proxy(); proxy->setProxyType(Proxy::NONE); WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig = { 0 }; if (WinHttpGetIEProxyConfigForCurrentUser(&ieProxyConfig) == TRUE) { if (ieProxyConfig.lpszProxy) { string proxyURL; proxy->setProxyType(Proxy::CUSTOM); int len = wcslen(ieProxyConfig.lpszProxy); proxyURL.assign((const char*)ieProxyConfig.lpszProxy, len * sizeof(wchar_t) + 1); // only save one proxy for (int i = 0; i < len; i++) { wchar_t* character = (wchar_t*)(proxyURL.data() + i * sizeof(wchar_t)); if (*character == ' ' || *character == ';') { proxyURL.resize(i*sizeof(wchar_t)); len = i; break; } } // remove protocol prefix, if any for (int i = len - 1; i >= 0; i--) { wchar_t* character = (wchar_t*)(proxyURL.data() + i * sizeof(wchar_t)); if (*character == '/') { proxyURL = proxyURL.substr((i + 1) * sizeof(wchar_t)); break; } } proxy->setProxyURL(&proxyURL); } else if (ieProxyConfig.lpszAutoConfigUrl || ieProxyConfig.fAutoDetect == TRUE) { WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions; if (ieProxyConfig.lpszAutoConfigUrl) { autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; autoProxyOptions.lpszAutoConfigUrl = ieProxyConfig.lpszAutoConfigUrl; autoProxyOptions.dwAutoDetectFlags = 0; } else { autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT; autoProxyOptions.lpszAutoConfigUrl = NULL; autoProxyOptions.dwAutoDetectFlags = WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A; } autoProxyOptions.fAutoLogonIfChallenged = TRUE; autoProxyOptions.lpvReserved = NULL; autoProxyOptions.dwReserved = 0; WINHTTP_PROXY_INFO proxyInfo; if (WinHttpGetProxyForUrl(hSession, L"https://g.api.mega.co.nz/", &autoProxyOptions, &proxyInfo)) { if (proxyInfo.lpszProxy) { string proxyURL; proxy->setProxyType(Proxy::CUSTOM); proxyURL.assign((const char*)proxyInfo.lpszProxy, wcslen(proxyInfo.lpszProxy) * sizeof(wchar_t)); proxy->setProxyURL(&proxyURL); } } } } if (ieProxyConfig.lpszProxy) { GlobalFree(ieProxyConfig.lpszProxy); } if (ieProxyConfig.lpszProxyBypass) { GlobalFree(ieProxyConfig.lpszProxyBypass); } if (ieProxyConfig.lpszAutoConfigUrl) { GlobalFree(ieProxyConfig.lpszAutoConfigUrl); } return proxy; }
inline void op_diagmat::apply(Mat<typename T1::elem_type>& out, const Op<T1, op_diagmat>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy<T1> P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const bool P_is_vec = (n_rows == 1) || (n_cols == 1); if(P.is_alias(out) == false) { if(P_is_vec) // generate a diagonal matrix out of a vector { const uword N = (n_rows == 1) ? n_cols : n_rows; out.zeros(N, N); if(Proxy<T1>::prefer_at_accessor == false) { typename Proxy<T1>::ea_type P_ea = P.get_ea(); for(uword i=0; i < N; ++i) { out.at(i,i) = P_ea[i]; } } else { if(n_rows == 1) { for(uword i=0; i < N; ++i) { out.at(i,i) = P.at(0,i); } } else { for(uword i=0; i < N; ++i) { out.at(i,i) = P.at(i,0); } } } } else // generate a diagonal matrix out of a matrix { out.zeros(n_rows, n_cols); const uword N = (std::min)(n_rows, n_cols); for(uword i=0; i < N; ++i) { out.at(i,i) = P.at(i,i); } } } else // we have aliasing { if(P_is_vec) // generate a diagonal matrix out of a vector { const uword N = (n_rows == 1) ? n_cols : n_rows; podarray<eT> tmp(N); eT* tmp_mem = tmp.memptr(); if(Proxy<T1>::prefer_at_accessor == false) { typename Proxy<T1>::ea_type P_ea = P.get_ea(); for(uword i=0; i < N; ++i) { tmp_mem[i] = P_ea[i]; } } else { if(n_rows == 1) { for(uword i=0; i < N; ++i) { tmp_mem[i] = P.at(0,i); } } else { for(uword i=0; i < N; ++i) { tmp_mem[i] = P.at(i,0); } } } out.zeros(N, N); for(uword i=0; i < N; ++i) { out.at(i,i) = tmp_mem[i]; } } else // generate a diagonal matrix out of a matrix { const uword N = (std::min)(n_rows, n_cols); if( (Proxy<T1>::has_subview == false) && (Proxy<T1>::fake_mat == false) ) { // NOTE: we have aliasing and it's not due to a subview, hence we're assuming that the output matrix already has the correct size for(uword i=0; i < n_cols; ++i) { if(i < N) { const eT val = P.at(i,i); arrayops::fill_zeros(out.colptr(i), n_rows); out.at(i,i) = val; } else { arrayops::fill_zeros(out.colptr(i), n_rows); } } } else { podarray<eT> tmp(N); eT* tmp_mem = tmp.memptr(); for(uword i=0; i < N; ++i) { tmp_mem[i] = P.at(i,i); } out.zeros(n_rows, n_cols); for(uword i=0; i < N; ++i) { out.at(i,i) = tmp_mem[i]; } } } } }
inline void glue_mixed_plus::apply(Mat<typename eT_promoter<T1,T2>::eT>& out, const mtGlue<typename eT_promoter<T1,T2>::eT, T1, T2, glue_mixed_plus>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type<eT1,eT2>::result out_eT; promote_type<eT1,eT2>::check(); const Proxy<T1> A(X.A); const Proxy<T2> B(X.B); arma_debug_assert_same_size(A, B, "addition"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T2>::prefer_at_accessor); if(prefer_at_accessor == false) { typename Proxy<T1>::ea_type AA = A.get_ea(); typename Proxy<T2>::ea_type BB = B.get_ea(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); for(uword i=0; i<n_elem; ++i) { out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) + upgrade_val<eT1,eT2>::apply(BB[i]); } } else { for(uword i=0; i<n_elem; ++i) { out_mem[i] = upgrade_val<eT1,eT2>::apply(AA[i]) + upgrade_val<eT1,eT2>::apply(BB[i]); } } } else { uword i = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { out_mem[i] = upgrade_val<eT1,eT2>::apply(A.at(row,col)) + upgrade_val<eT1,eT2>::apply(B.at(row,col)); ++i; } } }
inline typename enable_if2 < (is_arma_sparse_type<T1>::value && is_arma_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value), SpMat<typename T1::elem_type> >::result operator/ ( const SpBase<typename T1::elem_type, T1>& x, const Base<typename T2::elem_type, T2>& y ) { arma_extra_debug_sigprint(); const SpProxy<T1> pa(x.get_ref()); const Proxy<T2> pb(y.get_ref()); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "element-wise division"); SpMat<typename T1::elem_type> result(pa.get_n_rows(), pa.get_n_cols()); // The compiler should be smart enough to optimize out the inner if/else statement entirely typename SpProxy<T1>::const_iterator_type it = pa.begin(); uword new_n_nonzero; while(it.pos() < pa.get_n_nonzero()) { if(Proxy<T2>::prefer_at_accessor == false) { const typename T1::elem_type val = (*it) / pb[(it.col() * pb.get_n_rows()) + it.row()]; if(val != 0) { ++new_n_nonzero; } } else { const typename T1::elem_type val = (*it) / pb.at(it.row(), it.col()); if(val != 0) { ++new_n_nonzero; } } ++it; } result.mem_resize(new_n_nonzero); typename SpProxy<T1>::const_iterator_type it2 = pa.begin(); uword cur_pos = 0; while(it2.pos() < pa.get_n_nonzero()) { if(Proxy<T2>::prefer_at_accessor == false) { const typename T1::elem_type val = (*it2) / pb[(it2.col() * pb.get_n_rows()) + it2.row()]; if(val != 0) { access::rw(result.values[cur_pos]) = val; access::rw(result.row_indices[cur_pos]) = it2.row(); ++access::rw(result.col_ptrs[it2.col() + 1]); ++cur_pos; } } else { const typename T1::elem_type val = (*it2) / pb.at(it2.row(), it2.col()); if(val != 0) { access::rw(result.values[cur_pos]) = val; access::rw(result.row_indices[cur_pos]) = it2.row(); ++access::rw(result.col_ptrs[it2.col() + 1]); ++cur_pos; } } ++it2; } // Fix column pointers for(uword col = 1; col <= result.n_cols; ++col) { access::rw(result.col_ptrs[col]) += result.col_ptrs[col - 1]; } return result; }